X86ISelLowering.h revision 3a03ebb37747c2b3fd9b4f8b44f1124f53727894
1dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner//===-- X86ISelLowering.h - X86 DAG Lowering Interface ----------*- C++ -*-===// 2dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// 3dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// The LLVM Compiler Infrastructure 4dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// 5dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// This file was developed by Chris Lattner and is distributed under 6dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// the University of Illinois Open Source License. See LICENSE.TXT for details. 7dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// 8dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner//===----------------------------------------------------------------------===// 9dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// 10dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// This file defines the interfaces that X86 uses to lower LLVM code into a 11dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// selection DAG. 12dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner// 13dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner//===----------------------------------------------------------------------===// 14dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 15dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner#ifndef X86ISELLOWERING_H 16dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner#define X86ISELLOWERING_H 17dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 18dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner#include "llvm/Target/TargetLowering.h" 19dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner#include "llvm/CodeGen/SelectionDAG.h" 20dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 21dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattnernamespace llvm { 22dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // X86 Specific DAG Nodes 23dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner namespace X86ISD { 24dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner enum NodeType { 25dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // Start the numbering where the builtin ops leave off. 267df96d66729d1f33934de7b52553e5f071686041Evan Cheng FIRST_NUMBER = ISD::BUILTIN_OP_END+X86::INSTRUCTION_LIST_END, 27dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 28dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// FILD64m - This instruction implements SINT_TO_FP with a 29dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 64-bit source in memory and a FP reg result. This corresponds to 30dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// the X86::FILD64m instruction. It has two inputs (token chain and 31dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// address) and two outputs (FP value and token chain). 32dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner FILD64m, 33dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 34dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// FP_TO_INT*_IN_MEM - This instruction implements FP_TO_SINT with the 35dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// integer destination in memory and a FP reg source. This corresponds 36dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// to the X86::FIST*m instructions and the rounding mode change stuff. It 37dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// has two inputs (token chain and address) and two outputs (FP value and 38dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// token chain). 39dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner FP_TO_INT16_IN_MEM, 40dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner FP_TO_INT32_IN_MEM, 41dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner FP_TO_INT64_IN_MEM, 42dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 43b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// FLD - This instruction implements an extending load to FP stack slots. 44b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// This corresponds to the X86::FLD32m / X86::FLD64m. It takes a chain 45b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// operand, ptr to load from, and a VALUETYPE node indicating the type 46b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// to load. 47b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng FLD, 48b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng 49b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// FP_SET_RESULT - This corresponds to FpSETRESULT pseudo instrcuction 50b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// which copies the source operand to ST(0). It takes a chain and writes 51b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng /// a chain and a flag. 52b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng FP_SET_RESULT, 53b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng 54dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// CALL/TAILCALL - These operations represent an abstract X86 call 55dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// instruction, which includes a bunch of information. In particular the 56dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// operands of these node are: 57dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 58dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #0 - The incoming token chain 59dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #1 - The callee 60dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #2 - The number of arg bytes the caller pushes on the stack. 61dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #3 - The number of arg bytes the callee pops off the stack. 62dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #4 - The value to pass in AL/AX/EAX (optional) 63dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #5 - The value to pass in DL/DX/EDX (optional) 64dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 65dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// The result values of these nodes are: 66dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 67dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #0 - The outgoing token chain 68dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #1 - The first register result value (optional) 69dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// #2 - The second register result value (optional) 70dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 71dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// The CALL vs TAILCALL distinction boils down to whether the callee is 72dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// known not to modify the caller's stack frame, as is standard with 73dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// LLVM. 74dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner CALL, 75dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner TAILCALL, 76b873ff322c28ce097762355921100b677c71238dAndrew Lenharth 77b873ff322c28ce097762355921100b677c71238dAndrew Lenharth /// RDTSC_DAG - This operation implements the lowering for 78b873ff322c28ce097762355921100b677c71238dAndrew Lenharth /// readcyclecounter 79b873ff322c28ce097762355921100b677c71238dAndrew Lenharth RDTSC_DAG, 807df96d66729d1f33934de7b52553e5f071686041Evan Cheng 817df96d66729d1f33934de7b52553e5f071686041Evan Cheng /// X86 compare and logical compare instructions. 827df96d66729d1f33934de7b52553e5f071686041Evan Cheng CMP, TEST, 837df96d66729d1f33934de7b52553e5f071686041Evan Cheng 84d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// X86 SetCC. Operand 1 is condition code, and operand 2 is the flag 85d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// operand produced by a CMP instruction. 86d5781fca4f8f98863560338d4f8d017389428119Evan Cheng SETCC, 87d5781fca4f8f98863560338d4f8d017389428119Evan Cheng 88d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// X86 conditional moves. Operand 1 and operand 2 are the two values 89d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// to select from (operand 1 is a R/W operand). Operand 3 is the condition 90d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// code, and operand 4 is the flag operand produced by a CMP or TEST 91d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// instruction. 927df96d66729d1f33934de7b52553e5f071686041Evan Cheng CMOV, 93898101c15fa11a896deb4e2fcb73b4727e1dcc1fEvan Cheng 94d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// X86 conditional branches. Operand 1 is the chain operand, operand 2 95d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// is the block to branch if condition is true, operand 3 is the 96d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// condition code, and operand 4 is the flag operand produced by a CMP 97d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// or TEST instruction. 98898101c15fa11a896deb4e2fcb73b4727e1dcc1fEvan Cheng BRCOND, 99b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng 100d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// Return with a flag operand. Operand 1 is the number of bytes of stack 101d5781fca4f8f98863560338d4f8d017389428119Evan Cheng /// to pop, operand 2 is the chain and operand 3 is a flag operand. 102b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng RET_FLAG, 103dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner }; 104dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner } 105dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 106dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner //===----------------------------------------------------------------------===// 107dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // X86TargetLowering - X86 Implementation of the TargetLowering interface 108dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner class X86TargetLowering : public TargetLowering { 109dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner int VarArgsFrameIndex; // FrameIndex for start of varargs area. 110dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner int ReturnAddrIndex; // FrameIndex for return slot. 111dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner int BytesToPopOnReturn; // Number of arg bytes ret should pop. 112dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner int BytesCallerReserves; // Number of arg bytes caller makes. 113dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner public: 114dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner X86TargetLowering(TargetMachine &TM); 115dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 116dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // Return the number of bytes that a function should pop when it returns (in 117dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // addition to the space used by the return address). 118dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // 119dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; } 120dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 121dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // Return the number of bytes that the caller reserves for arguments passed 122dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // to this function. 123dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner unsigned getBytesCallerReserves() const { return BytesCallerReserves; } 124dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 125dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// LowerOperation - Provide custom lowering hooks for some operations. 126dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// 127dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG); 128dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 129dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// LowerArguments - This hook must be implemented to indicate how we should 130dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// lower the arguments for the specified function, into the specified DAG. 131dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual std::vector<SDOperand> 132dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerArguments(Function &F, SelectionDAG &DAG); 133dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 134dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// LowerCallTo - This hook lowers an abstract call to a function into an 135dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner /// actual call. 136dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual std::pair<SDOperand, SDOperand> 137dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC, 138dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner bool isTailCall, SDOperand Callee, ArgListTy &Args, 139dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner SelectionDAG &DAG); 140dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 141b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op, 142b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng SelectionDAG &DAG); 143b077b842b64af39c8e2e9aaad327b3be446790ddEvan Cheng 144dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP, 145dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner Value *VAListV, SelectionDAG &DAG); 146dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual std::pair<SDOperand,SDOperand> 147dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV, 148dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner const Type *ArgTy, SelectionDAG &DAG); 149dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 150dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner virtual std::pair<SDOperand, SDOperand> 151dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth, 152dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner SelectionDAG &DAG); 153dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 1547226158d7e3986e55b58214a749aa4eabb3fb6d5Evan Cheng /// getTargetNodeName - This method returns the name of a target specific 1557226158d7e3986e55b58214a749aa4eabb3fb6d5Evan Cheng /// DAG node. 1567226158d7e3986e55b58214a749aa4eabb3fb6d5Evan Cheng virtual const char *getTargetNodeName(unsigned Opcode) const; 1577226158d7e3986e55b58214a749aa4eabb3fb6d5Evan Cheng 1583a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to 1593a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng /// be zero. Op is expected to be a target specific node. Used by DAG 1603a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng /// combiner. 1613a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng virtual bool isMaskedValueZeroForTargetNode(const SDOperand &Op, 1623a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng uint64_t Mask) const; 1633a03ebb37747c2b3fd9b4f8b44f1124f53727894Evan Cheng 164dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner SDOperand getReturnAddressFrameIndex(SelectionDAG &DAG); 165dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 166dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner private: 167dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // C Calling Convention implementation. 168dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner std::vector<SDOperand> LowerCCCArguments(Function &F, SelectionDAG &DAG); 169dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner std::pair<SDOperand, SDOperand> 170dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerCCCCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, 171dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner bool isTailCall, 172dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG); 173dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 174dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner // Fast Calling Convention implementation. 175dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner std::vector<SDOperand> LowerFastCCArguments(Function &F, SelectionDAG &DAG); 176dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner std::pair<SDOperand, SDOperand> 177dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, bool isTailCall, 178dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG); 179dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner }; 180dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner} 181dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner 182dbdbf0ce2eef7b6585397121f56d3845e04866d1Chris Lattner#endif // X86ISELLOWERING_H 183