blob: a1c09136dcaf6ac466a76201943d4a426e8ecc75 [file] [log] [blame]
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +00001//===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file was developed by Chris Lattner and is distributed under
6// the University of Illinois Open Source License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file defines the interfaces that X86 uses to lower LLVM code into a
11// selection DAG.
12//
13//===----------------------------------------------------------------------===//
14
15#ifndef X86ISELLOWERING_H
16#define X86ISELLOWERING_H
17
18#include "llvm/Target/TargetLowering.h"
19#include "llvm/CodeGen/SelectionDAG.h"
20
21namespace llvm {
22 // X86 Specific DAG Nodes
23 namespace X86ISD {
24 enum NodeType {
25 // Start the numbering where the builtin ops leave off.
Evan Cheng7df96d62005-12-17 01:21:05 +000026 FIRST_NUMBER = ISD::BUILTIN_OP_END+X86::INSTRUCTION_LIST_END,
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000027
28 /// FILD64m - This instruction implements SINT_TO_FP with a
29 /// 64-bit source in memory and a FP reg result. This corresponds to
30 /// the X86::FILD64m instruction. It has two inputs (token chain and
31 /// address) and two outputs (FP value and token chain).
32 FILD64m,
33
34 /// FP_TO_INT*_IN_MEM - This instruction implements FP_TO_SINT with the
35 /// integer destination in memory and a FP reg source. This corresponds
36 /// to the X86::FIST*m instructions and the rounding mode change stuff. It
37 /// has two inputs (token chain and address) and two outputs (FP value and
38 /// token chain).
39 FP_TO_INT16_IN_MEM,
40 FP_TO_INT32_IN_MEM,
41 FP_TO_INT64_IN_MEM,
42
Evan Chengb077b842005-12-21 02:39:21 +000043 /// FLD - This instruction implements an extending load to FP stack slots.
44 /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain
45 /// operand, ptr to load from, and a VALUETYPE node indicating the type
46 /// to load.
47 FLD,
48
49 /// FP_SET_RESULT - This corresponds to FpSETRESULT pseudo instrcuction
50 /// which copies the source operand to ST(0). It takes a chain and writes
51 /// a chain and a flag.
52 FP_SET_RESULT,
53
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000054 /// CALL/TAILCALL - These operations represent an abstract X86 call
55 /// instruction, which includes a bunch of information. In particular the
56 /// operands of these node are:
57 ///
58 /// #0 - The incoming token chain
59 /// #1 - The callee
60 /// #2 - The number of arg bytes the caller pushes on the stack.
61 /// #3 - The number of arg bytes the callee pops off the stack.
62 /// #4 - The value to pass in AL/AX/EAX (optional)
63 /// #5 - The value to pass in DL/DX/EDX (optional)
64 ///
65 /// The result values of these nodes are:
66 ///
67 /// #0 - The outgoing token chain
68 /// #1 - The first register result value (optional)
69 /// #2 - The second register result value (optional)
70 ///
71 /// The CALL vs TAILCALL distinction boils down to whether the callee is
72 /// known not to modify the caller's stack frame, as is standard with
73 /// LLVM.
74 CALL,
75 TAILCALL,
Andrew Lenharthb873ff32005-11-20 21:41:10 +000076
77 /// RDTSC_DAG - This operation implements the lowering for
78 /// readcyclecounter
79 RDTSC_DAG,
Evan Cheng7df96d62005-12-17 01:21:05 +000080
81 /// X86 compare and logical compare instructions.
82 CMP, TEST,
83
84 /// X86 conditional moves.
85 CMOV,
Evan Cheng898101c2005-12-19 23:12:38 +000086
87 /// X86 conditional branches.
88 BRCOND,
Evan Chengb077b842005-12-21 02:39:21 +000089
90 // Return with a flag operand.
91 RET_FLAG,
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000092 };
93 }
94
95 //===----------------------------------------------------------------------===//
96 // X86TargetLowering - X86 Implementation of the TargetLowering interface
97 class X86TargetLowering : public TargetLowering {
98 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
99 int ReturnAddrIndex; // FrameIndex for return slot.
100 int BytesToPopOnReturn; // Number of arg bytes ret should pop.
101 int BytesCallerReserves; // Number of arg bytes caller makes.
102 public:
103 X86TargetLowering(TargetMachine &TM);
104
105 // Return the number of bytes that a function should pop when it returns (in
106 // addition to the space used by the return address).
107 //
108 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
109
110 // Return the number of bytes that the caller reserves for arguments passed
111 // to this function.
112 unsigned getBytesCallerReserves() const { return BytesCallerReserves; }
113
114 /// LowerOperation - Provide custom lowering hooks for some operations.
115 ///
116 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
117
118 /// LowerArguments - This hook must be implemented to indicate how we should
119 /// lower the arguments for the specified function, into the specified DAG.
120 virtual std::vector<SDOperand>
121 LowerArguments(Function &F, SelectionDAG &DAG);
122
123 /// LowerCallTo - This hook lowers an abstract call to a function into an
124 /// actual call.
125 virtual std::pair<SDOperand, SDOperand>
126 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
127 bool isTailCall, SDOperand Callee, ArgListTy &Args,
128 SelectionDAG &DAG);
129
Evan Chengb077b842005-12-21 02:39:21 +0000130 virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op,
131 SelectionDAG &DAG);
132
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000133 virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
134 Value *VAListV, SelectionDAG &DAG);
135 virtual std::pair<SDOperand,SDOperand>
136 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
137 const Type *ArgTy, SelectionDAG &DAG);
138
139 virtual std::pair<SDOperand, SDOperand>
140 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
141 SelectionDAG &DAG);
142
Evan Cheng72261582005-12-20 06:22:03 +0000143 /// getTargetNodeName - This method returns the name of a target specific
144 /// DAG node.
145 virtual const char *getTargetNodeName(unsigned Opcode) const;
146
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000147 SDOperand getReturnAddressFrameIndex(SelectionDAG &DAG);
148
149 private:
150 // C Calling Convention implementation.
151 std::vector<SDOperand> LowerCCCArguments(Function &F, SelectionDAG &DAG);
152 std::pair<SDOperand, SDOperand>
153 LowerCCCCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
154 bool isTailCall,
155 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
156
157 // Fast Calling Convention implementation.
158 std::vector<SDOperand> LowerFastCCArguments(Function &F, SelectionDAG &DAG);
159 std::pair<SDOperand, SDOperand>
160 LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, bool isTailCall,
161 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
162 };
163}
164
165#endif // X86ISELLOWERING_H