blob: c8d2dab663e118acd3b886416403d330932cbf47 [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
Evan Cheng38bcbaf2005-12-23 07:31:11 +000045 /// operand, ptr to load from, and a ValueType node indicating the type
46 /// to load to.
Evan Chengb077b842005-12-21 02:39:21 +000047 FLD,
48
Evan Chengd90eb7f2006-01-05 00:27:02 +000049 /// FST - This instruction implements a truncating store to FP stack
50 /// slots. This corresponds to the X86::FST32m / X86::FST64m. It takes a
51 /// chain operand, value to store, address, and a ValueType to store it
52 /// as.
53 FST,
54
55 /// FP_SET_RESULT - This corresponds to FpGETRESULT pseudo instrcuction
56 /// which copies from ST(0) to the destination. It takes a chain and writes
57 /// a RFP result and a chain.
58 FP_GET_RESULT,
59
Evan Chengb077b842005-12-21 02:39:21 +000060 /// FP_SET_RESULT - This corresponds to FpSETRESULT pseudo instrcuction
61 /// which copies the source operand to ST(0). It takes a chain and writes
62 /// a chain and a flag.
63 FP_SET_RESULT,
64
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +000065 /// CALL/TAILCALL - These operations represent an abstract X86 call
66 /// instruction, which includes a bunch of information. In particular the
67 /// operands of these node are:
68 ///
69 /// #0 - The incoming token chain
70 /// #1 - The callee
71 /// #2 - The number of arg bytes the caller pushes on the stack.
72 /// #3 - The number of arg bytes the callee pops off the stack.
73 /// #4 - The value to pass in AL/AX/EAX (optional)
74 /// #5 - The value to pass in DL/DX/EDX (optional)
75 ///
76 /// The result values of these nodes are:
77 ///
78 /// #0 - The outgoing token chain
79 /// #1 - The first register result value (optional)
80 /// #2 - The second register result value (optional)
81 ///
82 /// The CALL vs TAILCALL distinction boils down to whether the callee is
83 /// known not to modify the caller's stack frame, as is standard with
84 /// LLVM.
85 CALL,
86 TAILCALL,
Andrew Lenharthb873ff32005-11-20 21:41:10 +000087
88 /// RDTSC_DAG - This operation implements the lowering for
89 /// readcyclecounter
90 RDTSC_DAG,
Evan Cheng7df96d62005-12-17 01:21:05 +000091
92 /// X86 compare and logical compare instructions.
93 CMP, TEST,
94
Evan Chengd5781fc2005-12-21 20:21:51 +000095 /// X86 SetCC. Operand 1 is condition code, and operand 2 is the flag
96 /// operand produced by a CMP instruction.
97 SETCC,
98
99 /// X86 conditional moves. Operand 1 and operand 2 are the two values
100 /// to select from (operand 1 is a R/W operand). Operand 3 is the condition
101 /// code, and operand 4 is the flag operand produced by a CMP or TEST
102 /// instruction.
Evan Cheng7df96d62005-12-17 01:21:05 +0000103 CMOV,
Evan Cheng898101c2005-12-19 23:12:38 +0000104
Evan Chengd5781fc2005-12-21 20:21:51 +0000105 /// X86 conditional branches. Operand 1 is the chain operand, operand 2
106 /// is the block to branch if condition is true, operand 3 is the
107 /// condition code, and operand 4 is the flag operand produced by a CMP
108 /// or TEST instruction.
Evan Cheng898101c2005-12-19 23:12:38 +0000109 BRCOND,
Evan Chengb077b842005-12-21 02:39:21 +0000110
Evan Chengd5781fc2005-12-21 20:21:51 +0000111 /// Return with a flag operand. Operand 1 is the number of bytes of stack
112 /// to pop, operand 2 is the chain and operand 3 is a flag operand.
Evan Chengb077b842005-12-21 02:39:21 +0000113 RET_FLAG,
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000114 };
115 }
116
117 //===----------------------------------------------------------------------===//
118 // X86TargetLowering - X86 Implementation of the TargetLowering interface
119 class X86TargetLowering : public TargetLowering {
120 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
121 int ReturnAddrIndex; // FrameIndex for return slot.
122 int BytesToPopOnReturn; // Number of arg bytes ret should pop.
123 int BytesCallerReserves; // Number of arg bytes caller makes.
124 public:
125 X86TargetLowering(TargetMachine &TM);
126
127 // Return the number of bytes that a function should pop when it returns (in
128 // addition to the space used by the return address).
129 //
130 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
131
132 // Return the number of bytes that the caller reserves for arguments passed
133 // to this function.
134 unsigned getBytesCallerReserves() const { return BytesCallerReserves; }
135
136 /// LowerOperation - Provide custom lowering hooks for some operations.
137 ///
138 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
139
140 /// LowerArguments - This hook must be implemented to indicate how we should
141 /// lower the arguments for the specified function, into the specified DAG.
142 virtual std::vector<SDOperand>
143 LowerArguments(Function &F, SelectionDAG &DAG);
144
145 /// LowerCallTo - This hook lowers an abstract call to a function into an
146 /// actual call.
147 virtual std::pair<SDOperand, SDOperand>
148 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
149 bool isTailCall, SDOperand Callee, ArgListTy &Args,
150 SelectionDAG &DAG);
151
Evan Chengb077b842005-12-21 02:39:21 +0000152 virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op,
153 SelectionDAG &DAG);
154
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000155 virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
156 Value *VAListV, SelectionDAG &DAG);
157 virtual std::pair<SDOperand,SDOperand>
158 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
159 const Type *ArgTy, SelectionDAG &DAG);
160
161 virtual std::pair<SDOperand, SDOperand>
162 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
163 SelectionDAG &DAG);
164
Evan Cheng72261582005-12-20 06:22:03 +0000165 /// getTargetNodeName - This method returns the name of a target specific
166 /// DAG node.
167 virtual const char *getTargetNodeName(unsigned Opcode) const;
168
Evan Cheng3a03ebb2005-12-21 23:05:39 +0000169 /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
170 /// be zero. Op is expected to be a target specific node. Used by DAG
171 /// combiner.
172 virtual bool isMaskedValueZeroForTargetNode(const SDOperand &Op,
173 uint64_t Mask) const;
174
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000175 SDOperand getReturnAddressFrameIndex(SelectionDAG &DAG);
176
177 private:
178 // C Calling Convention implementation.
179 std::vector<SDOperand> LowerCCCArguments(Function &F, SelectionDAG &DAG);
180 std::pair<SDOperand, SDOperand>
181 LowerCCCCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
182 bool isTailCall,
183 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
184
185 // Fast Calling Convention implementation.
186 std::vector<SDOperand> LowerFastCCArguments(Function &F, SelectionDAG &DAG);
187 std::pair<SDOperand, SDOperand>
188 LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, bool isTailCall,
189 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
190 };
191}
192
193#endif // X86ISELLOWERING_H