Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 1 | //===-- 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 | |
| 21 | namespace llvm { |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 22 | namespace X86ISD { |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame^] | 23 | // X86 Specific DAG Nodes |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 24 | enum NodeType { |
| 25 | // Start the numbering where the builtin ops leave off. |
Evan Cheng | 7df96d6 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 26 | FIRST_NUMBER = ISD::BUILTIN_OP_END+X86::INSTRUCTION_LIST_END, |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 27 | |
| 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 Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 43 | /// 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 Cheng | 38bcbaf | 2005-12-23 07:31:11 +0000 | [diff] [blame] | 45 | /// operand, ptr to load from, and a ValueType node indicating the type |
| 46 | /// to load to. |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 47 | FLD, |
| 48 | |
Evan Cheng | d90eb7f | 2006-01-05 00:27:02 +0000 | [diff] [blame] | 49 | /// 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 Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 60 | /// 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 Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 65 | /// 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 Lenharth | b873ff3 | 2005-11-20 21:41:10 +0000 | [diff] [blame] | 87 | |
| 88 | /// RDTSC_DAG - This operation implements the lowering for |
| 89 | /// readcyclecounter |
| 90 | RDTSC_DAG, |
Evan Cheng | 7df96d6 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 91 | |
| 92 | /// X86 compare and logical compare instructions. |
| 93 | CMP, TEST, |
| 94 | |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 95 | /// 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 Cheng | 7df96d6 | 2005-12-17 01:21:05 +0000 | [diff] [blame] | 103 | CMOV, |
Evan Cheng | 898101c | 2005-12-19 23:12:38 +0000 | [diff] [blame] | 104 | |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 105 | /// 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 Cheng | 898101c | 2005-12-19 23:12:38 +0000 | [diff] [blame] | 109 | BRCOND, |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 110 | |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame^] | 111 | /// Return without a flag operand. Operand 1 is the number of bytes of |
| 112 | /// stack to pop, and operand 2 is the chain. |
| 113 | RET, |
| 114 | |
Evan Cheng | d5781fc | 2005-12-21 20:21:51 +0000 | [diff] [blame] | 115 | /// Return with a flag operand. Operand 1 is the number of bytes of stack |
| 116 | /// to pop, operand 2 is the chain and operand 3 is a flag operand. |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 117 | RET_FLAG, |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 118 | }; |
Evan Cheng | d9558e0 | 2006-01-06 00:43:03 +0000 | [diff] [blame^] | 119 | |
| 120 | // X86 specific condition code. These correspond to X86_*_COND in |
| 121 | // X86InstrInfo.td. They must be kept in synch. |
| 122 | enum CondCode { |
| 123 | COND_A = 0, |
| 124 | COND_AE = 1, |
| 125 | COND_B = 2, |
| 126 | COND_BE = 3, |
| 127 | COND_E = 4, |
| 128 | COND_G = 5, |
| 129 | COND_GE = 6, |
| 130 | COND_L = 7, |
| 131 | COND_LE = 8, |
| 132 | COND_NE = 9, |
| 133 | COND_NO = 10, |
| 134 | COND_NP = 11, |
| 135 | COND_NS = 12, |
| 136 | COND_O = 13, |
| 137 | COND_P = 14, |
| 138 | COND_S = 15, |
| 139 | COND_INVALID |
| 140 | }; |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | //===----------------------------------------------------------------------===// |
| 144 | // X86TargetLowering - X86 Implementation of the TargetLowering interface |
| 145 | class X86TargetLowering : public TargetLowering { |
| 146 | int VarArgsFrameIndex; // FrameIndex for start of varargs area. |
| 147 | int ReturnAddrIndex; // FrameIndex for return slot. |
| 148 | int BytesToPopOnReturn; // Number of arg bytes ret should pop. |
| 149 | int BytesCallerReserves; // Number of arg bytes caller makes. |
| 150 | public: |
| 151 | X86TargetLowering(TargetMachine &TM); |
| 152 | |
| 153 | // Return the number of bytes that a function should pop when it returns (in |
| 154 | // addition to the space used by the return address). |
| 155 | // |
| 156 | unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; } |
| 157 | |
| 158 | // Return the number of bytes that the caller reserves for arguments passed |
| 159 | // to this function. |
| 160 | unsigned getBytesCallerReserves() const { return BytesCallerReserves; } |
| 161 | |
| 162 | /// LowerOperation - Provide custom lowering hooks for some operations. |
| 163 | /// |
| 164 | virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG); |
| 165 | |
| 166 | /// LowerArguments - This hook must be implemented to indicate how we should |
| 167 | /// lower the arguments for the specified function, into the specified DAG. |
| 168 | virtual std::vector<SDOperand> |
| 169 | LowerArguments(Function &F, SelectionDAG &DAG); |
| 170 | |
| 171 | /// LowerCallTo - This hook lowers an abstract call to a function into an |
| 172 | /// actual call. |
| 173 | virtual std::pair<SDOperand, SDOperand> |
| 174 | LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, |
| 175 | bool isTailCall, SDOperand Callee, ArgListTy &Args, |
| 176 | SelectionDAG &DAG); |
| 177 | |
Evan Cheng | b077b84 | 2005-12-21 02:39:21 +0000 | [diff] [blame] | 178 | virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op, |
| 179 | SelectionDAG &DAG); |
| 180 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 181 | virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP, |
| 182 | Value *VAListV, SelectionDAG &DAG); |
| 183 | virtual std::pair<SDOperand,SDOperand> |
| 184 | LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV, |
| 185 | const Type *ArgTy, SelectionDAG &DAG); |
| 186 | |
| 187 | virtual std::pair<SDOperand, SDOperand> |
| 188 | LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, |
| 189 | SelectionDAG &DAG); |
| 190 | |
Evan Cheng | 7226158 | 2005-12-20 06:22:03 +0000 | [diff] [blame] | 191 | /// getTargetNodeName - This method returns the name of a target specific |
| 192 | /// DAG node. |
| 193 | virtual const char *getTargetNodeName(unsigned Opcode) const; |
| 194 | |
Evan Cheng | 3a03ebb | 2005-12-21 23:05:39 +0000 | [diff] [blame] | 195 | /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to |
| 196 | /// be zero. Op is expected to be a target specific node. Used by DAG |
| 197 | /// combiner. |
| 198 | virtual bool isMaskedValueZeroForTargetNode(const SDOperand &Op, |
| 199 | uint64_t Mask) const; |
| 200 | |
Chris Lattner | dbdbf0c | 2005-11-15 00:40:23 +0000 | [diff] [blame] | 201 | SDOperand getReturnAddressFrameIndex(SelectionDAG &DAG); |
| 202 | |
| 203 | private: |
| 204 | // C Calling Convention implementation. |
| 205 | std::vector<SDOperand> LowerCCCArguments(Function &F, SelectionDAG &DAG); |
| 206 | std::pair<SDOperand, SDOperand> |
| 207 | LowerCCCCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, |
| 208 | bool isTailCall, |
| 209 | SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG); |
| 210 | |
| 211 | // Fast Calling Convention implementation. |
| 212 | std::vector<SDOperand> LowerFastCCArguments(Function &F, SelectionDAG &DAG); |
| 213 | std::pair<SDOperand, SDOperand> |
| 214 | LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, bool isTailCall, |
| 215 | SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG); |
| 216 | }; |
| 217 | } |
| 218 | |
| 219 | #endif // X86ISELLOWERING_H |