blob: fbe5c4cc95e4aeed2a1ff6e7c2a74c14d05a980b [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
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
Evan Chengd5781fc2005-12-21 20:21:51 +000084 /// X86 SetCC. Operand 1 is condition code, and operand 2 is the flag
85 /// operand produced by a CMP instruction.
86 SETCC,
87
88 /// X86 conditional moves. Operand 1 and operand 2 are the two values
89 /// to select from (operand 1 is a R/W operand). Operand 3 is the condition
90 /// code, and operand 4 is the flag operand produced by a CMP or TEST
91 /// instruction.
Evan Cheng7df96d62005-12-17 01:21:05 +000092 CMOV,
Evan Cheng898101c2005-12-19 23:12:38 +000093
Evan Chengd5781fc2005-12-21 20:21:51 +000094 /// X86 conditional branches. Operand 1 is the chain operand, operand 2
95 /// is the block to branch if condition is true, operand 3 is the
96 /// condition code, and operand 4 is the flag operand produced by a CMP
97 /// or TEST instruction.
Evan Cheng898101c2005-12-19 23:12:38 +000098 BRCOND,
Evan Chengb077b842005-12-21 02:39:21 +000099
Evan Chengd5781fc2005-12-21 20:21:51 +0000100 /// Return with a flag operand. Operand 1 is the number of bytes of stack
101 /// to pop, operand 2 is the chain and operand 3 is a flag operand.
Evan Chengb077b842005-12-21 02:39:21 +0000102 RET_FLAG,
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000103 };
104 }
105
106 //===----------------------------------------------------------------------===//
107 // X86TargetLowering - X86 Implementation of the TargetLowering interface
108 class X86TargetLowering : public TargetLowering {
109 int VarArgsFrameIndex; // FrameIndex for start of varargs area.
110 int ReturnAddrIndex; // FrameIndex for return slot.
111 int BytesToPopOnReturn; // Number of arg bytes ret should pop.
112 int BytesCallerReserves; // Number of arg bytes caller makes.
113 public:
114 X86TargetLowering(TargetMachine &TM);
115
116 // Return the number of bytes that a function should pop when it returns (in
117 // addition to the space used by the return address).
118 //
119 unsigned getBytesToPopOnReturn() const { return BytesToPopOnReturn; }
120
121 // Return the number of bytes that the caller reserves for arguments passed
122 // to this function.
123 unsigned getBytesCallerReserves() const { return BytesCallerReserves; }
124
125 /// LowerOperation - Provide custom lowering hooks for some operations.
126 ///
127 virtual SDOperand LowerOperation(SDOperand Op, SelectionDAG &DAG);
128
129 /// LowerArguments - This hook must be implemented to indicate how we should
130 /// lower the arguments for the specified function, into the specified DAG.
131 virtual std::vector<SDOperand>
132 LowerArguments(Function &F, SelectionDAG &DAG);
133
134 /// LowerCallTo - This hook lowers an abstract call to a function into an
135 /// actual call.
136 virtual std::pair<SDOperand, SDOperand>
137 LowerCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg, unsigned CC,
138 bool isTailCall, SDOperand Callee, ArgListTy &Args,
139 SelectionDAG &DAG);
140
Evan Chengb077b842005-12-21 02:39:21 +0000141 virtual SDOperand LowerReturnTo(SDOperand Chain, SDOperand Op,
142 SelectionDAG &DAG);
143
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000144 virtual SDOperand LowerVAStart(SDOperand Chain, SDOperand VAListP,
145 Value *VAListV, SelectionDAG &DAG);
146 virtual std::pair<SDOperand,SDOperand>
147 LowerVAArg(SDOperand Chain, SDOperand VAListP, Value *VAListV,
148 const Type *ArgTy, SelectionDAG &DAG);
149
150 virtual std::pair<SDOperand, SDOperand>
151 LowerFrameReturnAddress(bool isFrameAddr, SDOperand Chain, unsigned Depth,
152 SelectionDAG &DAG);
153
Evan Cheng72261582005-12-20 06:22:03 +0000154 /// getTargetNodeName - This method returns the name of a target specific
155 /// DAG node.
156 virtual const char *getTargetNodeName(unsigned Opcode) const;
157
Evan Cheng3a03ebb2005-12-21 23:05:39 +0000158 /// isMaskedValueZeroForTargetNode - Return true if 'Op & Mask' is known to
159 /// be zero. Op is expected to be a target specific node. Used by DAG
160 /// combiner.
161 virtual bool isMaskedValueZeroForTargetNode(const SDOperand &Op,
162 uint64_t Mask) const;
163
Chris Lattnerdbdbf0c2005-11-15 00:40:23 +0000164 SDOperand getReturnAddressFrameIndex(SelectionDAG &DAG);
165
166 private:
167 // C Calling Convention implementation.
168 std::vector<SDOperand> LowerCCCArguments(Function &F, SelectionDAG &DAG);
169 std::pair<SDOperand, SDOperand>
170 LowerCCCCallTo(SDOperand Chain, const Type *RetTy, bool isVarArg,
171 bool isTailCall,
172 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
173
174 // Fast Calling Convention implementation.
175 std::vector<SDOperand> LowerFastCCArguments(Function &F, SelectionDAG &DAG);
176 std::pair<SDOperand, SDOperand>
177 LowerFastCCCallTo(SDOperand Chain, const Type *RetTy, bool isTailCall,
178 SDOperand Callee, ArgListTy &Args, SelectionDAG &DAG);
179 };
180}
181
182#endif // X86ISELLOWERING_H