Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 1 | //===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Chris Lattner | 84e66db | 2007-12-29 19:59:42 +0000 | [diff] [blame] | 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file declares the SelectionDAG class, and transitively defines the |
| 11 | // SDNode class and subclasses. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
| 15 | #ifndef LLVM_CODEGEN_SELECTIONDAG_H |
| 16 | #define LLVM_CODEGEN_SELECTIONDAG_H |
| 17 | |
| 18 | #include "llvm/ADT/FoldingSet.h" |
Dan Gohman | c96298c | 2008-06-23 21:08:32 +0000 | [diff] [blame] | 19 | #include "llvm/ADT/StringMap.h" |
Anton Korobeynikov | a9db7a2 | 2008-05-29 17:41:17 +0000 | [diff] [blame] | 20 | #include "llvm/ADT/ilist.h" |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 21 | #include "llvm/CodeGen/SelectionDAGNodes.h" |
| 22 | |
| 23 | #include <list> |
| 24 | #include <vector> |
| 25 | #include <map> |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 26 | #include <string> |
| 27 | |
| 28 | namespace llvm { |
| 29 | class AliasAnalysis; |
| 30 | class TargetLowering; |
| 31 | class TargetMachine; |
| 32 | class MachineModuleInfo; |
| 33 | class MachineFunction; |
| 34 | class MachineConstantPoolValue; |
Chris Lattner | 68068cc | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 35 | class FunctionLoweringInfo; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 36 | |
| 37 | /// SelectionDAG class - This is used to represent a portion of an LLVM function |
| 38 | /// in a low-level Data Dependence DAG representation suitable for instruction |
| 39 | /// selection. This DAG is constructed as the first step of instruction |
| 40 | /// selection in order to allow implementation of machine specific optimizations |
| 41 | /// and code simplifications. |
| 42 | /// |
| 43 | /// The representation used by the SelectionDAG is a target-independent |
| 44 | /// representation, which has some similarities to the GCC RTL representation, |
| 45 | /// but is significantly more simple, powerful, and is a graph form instead of a |
| 46 | /// linear form. |
| 47 | /// |
| 48 | class SelectionDAG { |
| 49 | TargetLowering &TLI; |
| 50 | MachineFunction &MF; |
Chris Lattner | 68068cc | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 51 | FunctionLoweringInfo &FLI; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 52 | MachineModuleInfo *MMI; |
| 53 | |
| 54 | /// Root - The root of the entire DAG. EntryNode - The starting token. |
| 55 | SDOperand Root, EntryNode; |
| 56 | |
| 57 | /// AllNodes - A linked list of nodes in the current DAG. |
| 58 | ilist<SDNode> AllNodes; |
| 59 | |
| 60 | /// CSEMap - This structure is used to memoize nodes, automatically performing |
| 61 | /// CSE with existing nodes with a duplicate is requested. |
| 62 | FoldingSet<SDNode> CSEMap; |
| 63 | |
| 64 | public: |
Chris Lattner | 68068cc | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 65 | SelectionDAG(TargetLowering &tli, MachineFunction &mf, |
| 66 | FunctionLoweringInfo &fli, MachineModuleInfo *mmi) |
| 67 | : TLI(tli), MF(mf), FLI(fli), MMI(mmi) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 68 | EntryNode = Root = getNode(ISD::EntryToken, MVT::Other); |
| 69 | } |
| 70 | ~SelectionDAG(); |
| 71 | |
| 72 | MachineFunction &getMachineFunction() const { return MF; } |
| 73 | const TargetMachine &getTarget() const; |
| 74 | TargetLowering &getTargetLoweringInfo() const { return TLI; } |
Chris Lattner | 68068cc | 2008-06-17 06:09:18 +0000 | [diff] [blame] | 75 | FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 76 | MachineModuleInfo *getMachineModuleInfo() const { return MMI; } |
| 77 | |
| 78 | /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'. |
| 79 | /// |
| 80 | void viewGraph(); |
| 81 | |
| 82 | #ifndef NDEBUG |
| 83 | std::map<const SDNode *, std::string> NodeGraphAttrs; |
| 84 | #endif |
| 85 | |
| 86 | /// clearGraphAttrs - Clear all previously defined node graph attributes. |
| 87 | /// Intended to be used from a debugging tool (eg. gdb). |
| 88 | void clearGraphAttrs(); |
| 89 | |
| 90 | /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".) |
| 91 | /// |
| 92 | void setGraphAttrs(const SDNode *N, const char *Attrs); |
| 93 | |
| 94 | /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".) |
| 95 | /// Used from getNodeAttributes. |
| 96 | const std::string getGraphAttrs(const SDNode *N) const; |
| 97 | |
| 98 | /// setGraphColor - Convenience for setting node color attribute. |
| 99 | /// |
| 100 | void setGraphColor(const SDNode *N, const char *Color); |
| 101 | |
| 102 | typedef ilist<SDNode>::const_iterator allnodes_const_iterator; |
| 103 | allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); } |
| 104 | allnodes_const_iterator allnodes_end() const { return AllNodes.end(); } |
| 105 | typedef ilist<SDNode>::iterator allnodes_iterator; |
| 106 | allnodes_iterator allnodes_begin() { return AllNodes.begin(); } |
| 107 | allnodes_iterator allnodes_end() { return AllNodes.end(); } |
Dan Gohman | 4c5e2d7 | 2008-06-20 16:03:16 +0000 | [diff] [blame] | 108 | ilist<SDNode>::size_type allnodes_size() const { return AllNodes.size(); } |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 109 | |
| 110 | /// getRoot - Return the root tag of the SelectionDAG. |
| 111 | /// |
| 112 | const SDOperand &getRoot() const { return Root; } |
| 113 | |
| 114 | /// getEntryNode - Return the token chain corresponding to the entry of the |
| 115 | /// function. |
| 116 | const SDOperand &getEntryNode() const { return EntryNode; } |
| 117 | |
| 118 | /// setRoot - Set the current root tag of the SelectionDAG. |
| 119 | /// |
| 120 | const SDOperand &setRoot(SDOperand N) { return Root = N; } |
| 121 | |
| 122 | /// Combine - This iterates over the nodes in the SelectionDAG, folding |
| 123 | /// certain types of nodes together, or eliminating superfluous nodes. When |
| 124 | /// the AfterLegalize argument is set to 'true', Combine takes care not to |
| 125 | /// generate any nodes that will be illegal on the target. |
| 126 | void Combine(bool AfterLegalize, AliasAnalysis &AA); |
| 127 | |
Chris Lattner | 8a25820 | 2007-10-15 06:10:22 +0000 | [diff] [blame] | 128 | /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that |
| 129 | /// only uses types natively supported by the target. |
| 130 | /// |
| 131 | /// Note that this is an involved process that may invalidate pointers into |
| 132 | /// the graph. |
| 133 | void LegalizeTypes(); |
| 134 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 135 | /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is |
| 136 | /// compatible with the target instruction selector, as indicated by the |
| 137 | /// TargetLowering object. |
| 138 | /// |
| 139 | /// Note that this is an involved process that may invalidate pointers into |
| 140 | /// the graph. |
| 141 | void Legalize(); |
| 142 | |
| 143 | /// RemoveDeadNodes - This method deletes all unreachable nodes in the |
| 144 | /// SelectionDAG. |
| 145 | void RemoveDeadNodes(); |
| 146 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 147 | /// DeleteNode - Remove the specified node from the system. This node must |
| 148 | /// have no referrers. |
| 149 | void DeleteNode(SDNode *N); |
| 150 | |
| 151 | /// getVTList - Return an SDVTList that represents the list of values |
| 152 | /// specified. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 153 | SDVTList getVTList(MVT VT); |
| 154 | SDVTList getVTList(MVT VT1, MVT VT2); |
| 155 | SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3); |
| 156 | SDVTList getVTList(const MVT *VTs, unsigned NumVTs); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 157 | |
| 158 | /// getNodeValueTypes - These are obsolete, use getVTList instead. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 159 | const MVT *getNodeValueTypes(MVT VT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 160 | return getVTList(VT).VTs; |
| 161 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 162 | const MVT *getNodeValueTypes(MVT VT1, MVT VT2) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 163 | return getVTList(VT1, VT2).VTs; |
| 164 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 165 | const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 166 | return getVTList(VT1, VT2, VT3).VTs; |
| 167 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 168 | const MVT *getNodeValueTypes(std::vector<MVT> &vtList) { |
Bill Wendling | 51bacec | 2008-05-19 20:15:12 +0000 | [diff] [blame] | 169 | return getVTList(&vtList[0], (unsigned)vtList.size()).VTs; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | |
| 173 | //===--------------------------------------------------------------------===// |
| 174 | // Node creation methods. |
| 175 | // |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 176 | SDOperand getConstant(uint64_t Val, MVT VT, bool isTarget = false); |
| 177 | SDOperand getConstant(const APInt &Val, MVT VT, bool isTarget = false); |
Chris Lattner | 5872a36 | 2008-01-17 07:00:52 +0000 | [diff] [blame] | 178 | SDOperand getIntPtrConstant(uint64_t Val, bool isTarget = false); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 179 | SDOperand getTargetConstant(uint64_t Val, MVT VT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 180 | return getConstant(Val, VT, true); |
| 181 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 182 | SDOperand getTargetConstant(const APInt &Val, MVT VT) { |
Dan Gohman | dc458cf | 2008-02-08 22:59:30 +0000 | [diff] [blame] | 183 | return getConstant(Val, VT, true); |
| 184 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 185 | SDOperand getConstantFP(double Val, MVT VT, bool isTarget = false); |
| 186 | SDOperand getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false); |
| 187 | SDOperand getTargetConstantFP(double Val, MVT VT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 188 | return getConstantFP(Val, VT, true); |
| 189 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 190 | SDOperand getTargetConstantFP(const APFloat& Val, MVT VT) { |
Dale Johannesen | bbe2b70 | 2007-08-30 00:23:21 +0000 | [diff] [blame] | 191 | return getConstantFP(Val, VT, true); |
| 192 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 193 | SDOperand getGlobalAddress(const GlobalValue *GV, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 194 | int offset = 0, bool isTargetGA = false); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 195 | SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 196 | int offset = 0) { |
| 197 | return getGlobalAddress(GV, VT, offset, true); |
| 198 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 199 | SDOperand getFrameIndex(int FI, MVT VT, bool isTarget = false); |
| 200 | SDOperand getTargetFrameIndex(int FI, MVT VT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 201 | return getFrameIndex(FI, VT, true); |
| 202 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 203 | SDOperand getJumpTable(int JTI, MVT VT, bool isTarget = false); |
| 204 | SDOperand getTargetJumpTable(int JTI, MVT VT) { |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 205 | return getJumpTable(JTI, VT, true); |
| 206 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 207 | SDOperand getConstantPool(Constant *C, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 208 | unsigned Align = 0, int Offs = 0, bool isT=false); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 209 | SDOperand getTargetConstantPool(Constant *C, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 210 | unsigned Align = 0, int Offset = 0) { |
| 211 | return getConstantPool(C, VT, Align, Offset, true); |
| 212 | } |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 213 | SDOperand getConstantPool(MachineConstantPoolValue *C, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 214 | unsigned Align = 0, int Offs = 0, bool isT=false); |
| 215 | SDOperand getTargetConstantPool(MachineConstantPoolValue *C, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 216 | MVT VT, unsigned Align = 0, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 217 | int Offset = 0) { |
| 218 | return getConstantPool(C, VT, Align, Offset, true); |
| 219 | } |
| 220 | SDOperand getBasicBlock(MachineBasicBlock *MBB); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 221 | SDOperand getExternalSymbol(const char *Sym, MVT VT); |
| 222 | SDOperand getTargetExternalSymbol(const char *Sym, MVT VT); |
Duncan Sands | c93fae3 | 2008-03-21 09:14:45 +0000 | [diff] [blame] | 223 | SDOperand getArgFlags(ISD::ArgFlagsTy Flags); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 224 | SDOperand getValueType(MVT); |
| 225 | SDOperand getRegister(unsigned Reg, MVT VT); |
Dan Gohman | 472d12c | 2008-06-30 20:59:49 +0000 | [diff] [blame] | 226 | SDOperand getDbgStopPoint(SDOperand Root, unsigned Line, unsigned Col, |
| 227 | const CompileUnitDesc *CU); |
Dan Gohman | fa607c9 | 2008-07-01 00:05:16 +0000 | [diff] [blame] | 228 | SDOperand getLabel(unsigned Opcode, SDOperand Root, unsigned LabelID); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 229 | |
| 230 | SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) { |
| 231 | return getNode(ISD::CopyToReg, MVT::Other, Chain, |
| 232 | getRegister(Reg, N.getValueType()), N); |
| 233 | } |
| 234 | |
| 235 | // This version of the getCopyToReg method takes an extra operand, which |
| 236 | // indicates that there is potentially an incoming flag value (if Flag is not |
| 237 | // null) and that there should be a flag result. |
| 238 | SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N, |
| 239 | SDOperand Flag) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 240 | const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 241 | SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag }; |
| 242 | return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3); |
| 243 | } |
| 244 | |
| 245 | // Similar to last getCopyToReg() except parameter Reg is a SDOperand |
| 246 | SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N, |
| 247 | SDOperand Flag) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 248 | const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 249 | SDOperand Ops[] = { Chain, Reg, N, Flag }; |
| 250 | return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3); |
| 251 | } |
| 252 | |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 253 | SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT) { |
| 254 | const MVT *VTs = getNodeValueTypes(VT, MVT::Other); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 255 | SDOperand Ops[] = { Chain, getRegister(Reg, VT) }; |
| 256 | return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2); |
| 257 | } |
| 258 | |
| 259 | // This version of the getCopyFromReg method takes an extra operand, which |
| 260 | // indicates that there is potentially an incoming flag value (if Flag is not |
| 261 | // null) and that there should be a flag result. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 262 | SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 263 | SDOperand Flag) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 264 | const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 265 | SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag }; |
| 266 | return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2); |
| 267 | } |
| 268 | |
| 269 | SDOperand getCondCode(ISD::CondCode Cond); |
| 270 | |
| 271 | /// getZeroExtendInReg - Return the expression required to zero extend the Op |
| 272 | /// value assuming it was the smaller SrcTy value. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 273 | SDOperand getZeroExtendInReg(SDOperand Op, MVT SrcTy); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 274 | |
| 275 | /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have |
| 276 | /// a flag result (to ensure it's not CSE'd). |
| 277 | SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) { |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 278 | const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 279 | SDOperand Ops[] = { Chain, Op }; |
| 280 | return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2); |
| 281 | } |
| 282 | |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 283 | /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a |
| 284 | /// flag result (to ensure it's not CSE'd). |
| 285 | SDOperand getCALLSEQ_END(SDOperand Chain, SDOperand Op1, SDOperand Op2, |
| 286 | SDOperand InFlag) { |
| 287 | SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag); |
| 288 | SmallVector<SDOperand, 4> Ops; |
| 289 | Ops.push_back(Chain); |
| 290 | Ops.push_back(Op1); |
| 291 | Ops.push_back(Op2); |
| 292 | Ops.push_back(InFlag); |
| 293 | return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0], |
Evan Cheng | 591bfc8 | 2008-05-05 18:30:58 +0000 | [diff] [blame] | 294 | (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0)); |
Bill Wendling | 22f8deb | 2007-11-13 00:44:25 +0000 | [diff] [blame] | 295 | } |
| 296 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 297 | /// getNode - Gets or creates the specified node. |
| 298 | /// |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 299 | SDOperand getNode(unsigned Opcode, MVT VT); |
| 300 | SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N); |
| 301 | SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N1, SDOperand N2); |
| 302 | SDOperand getNode(unsigned Opcode, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 303 | SDOperand N1, SDOperand N2, SDOperand N3); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 304 | SDOperand getNode(unsigned Opcode, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 305 | SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 306 | SDOperand getNode(unsigned Opcode, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 307 | SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4, |
| 308 | SDOperand N5); |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 309 | SDOperand getNode(unsigned Opcode, MVT VT, |
| 310 | const SDOperand *Ops, unsigned NumOps); |
| 311 | SDOperand getNode(unsigned Opcode, MVT VT, |
| 312 | const SDUse *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 313 | SDOperand getNode(unsigned Opcode, std::vector<MVT> &ResultTys, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 314 | const SDOperand *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 315 | SDOperand getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 316 | const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | 798d127 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 317 | SDOperand getNode(unsigned Opcode, SDVTList VTs); |
| 318 | SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 319 | SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N1, SDOperand N2); |
Dan Gohman | 798d127 | 2007-10-08 15:49:58 +0000 | [diff] [blame] | 320 | SDOperand getNode(unsigned Opcode, SDVTList VTs, |
| 321 | SDOperand N1, SDOperand N2, SDOperand N3); |
| 322 | SDOperand getNode(unsigned Opcode, SDVTList VTs, |
| 323 | SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4); |
| 324 | SDOperand getNode(unsigned Opcode, SDVTList VTs, |
| 325 | SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4, |
| 326 | SDOperand N5); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 327 | SDOperand getNode(unsigned Opcode, SDVTList VTs, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 328 | const SDOperand *Ops, unsigned NumOps); |
Rafael Espindola | 8082590 | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 329 | |
Dan Gohman | e8b391e | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 330 | SDOperand getMemcpy(SDOperand Chain, SDOperand Dst, SDOperand Src, |
| 331 | SDOperand Size, unsigned Align, |
| 332 | bool AlwaysInline, |
Dan Gohman | 65118f4 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 333 | const Value *DstSV, uint64_t DstSVOff, |
| 334 | const Value *SrcSV, uint64_t SrcSVOff); |
Rafael Espindola | 8082590 | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 335 | |
Dan Gohman | e8b391e | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 336 | SDOperand getMemmove(SDOperand Chain, SDOperand Dst, SDOperand Src, |
Dan Gohman | 1457fa8 | 2008-04-23 17:50:15 +0000 | [diff] [blame] | 337 | SDOperand Size, unsigned Align, |
Dan Gohman | 65118f4 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 338 | const Value *DstSV, uint64_t DstOSVff, |
| 339 | const Value *SrcSV, uint64_t SrcSVOff); |
Rafael Espindola | 8082590 | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 340 | |
Dan Gohman | e8b391e | 2008-04-12 04:36:06 +0000 | [diff] [blame] | 341 | SDOperand getMemset(SDOperand Chain, SDOperand Dst, SDOperand Src, |
| 342 | SDOperand Size, unsigned Align, |
Dan Gohman | 65118f4 | 2008-04-28 17:15:20 +0000 | [diff] [blame] | 343 | const Value *DstSV, uint64_t DstSVOff); |
Rafael Espindola | 8082590 | 2007-10-19 10:41:11 +0000 | [diff] [blame] | 344 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 345 | /// getSetCC - Helper function to make it easier to build SetCC's if you just |
| 346 | /// have an ISD::CondCode instead of an SDOperand. |
| 347 | /// |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 348 | SDOperand getSetCC(MVT VT, SDOperand LHS, SDOperand RHS, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 349 | ISD::CondCode Cond) { |
| 350 | return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond)); |
| 351 | } |
| 352 | |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 353 | /// getVSetCC - Helper function to make it easier to build VSetCC's nodes |
| 354 | /// if you just have an ISD::CondCode instead of an SDOperand. |
| 355 | /// |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 356 | SDOperand getVSetCC(MVT VT, SDOperand LHS, SDOperand RHS, |
Nate Begeman | 9a1ce15 | 2008-05-12 19:40:03 +0000 | [diff] [blame] | 357 | ISD::CondCode Cond) { |
| 358 | return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond)); |
| 359 | } |
| 360 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 361 | /// getSelectCC - Helper function to make it easier to build SelectCC's if you |
| 362 | /// just have an ISD::CondCode instead of an SDOperand. |
| 363 | /// |
| 364 | SDOperand getSelectCC(SDOperand LHS, SDOperand RHS, |
| 365 | SDOperand True, SDOperand False, ISD::CondCode Cond) { |
| 366 | return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False, |
| 367 | getCondCode(Cond)); |
| 368 | } |
| 369 | |
| 370 | /// getVAArg - VAArg produces a result and token chain, and takes a pointer |
| 371 | /// and a source value as input. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 372 | SDOperand getVAArg(MVT VT, SDOperand Chain, SDOperand Ptr, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 373 | SDOperand SV); |
| 374 | |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 375 | /// getAtomic - Gets a node for an atomic op, produces result and chain, takes |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 376 | /// 3 operands |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 377 | SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr, |
Dan Gohman | c70fa75 | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 378 | SDOperand Cmp, SDOperand Swp, const Value* PtrVal, |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 379 | unsigned Alignment=0); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 380 | |
| 381 | /// getAtomic - Gets a node for an atomic op, produces result and chain, takes |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 382 | /// 2 operands |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 383 | SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr, |
Dan Gohman | c70fa75 | 2008-06-25 16:07:49 +0000 | [diff] [blame] | 384 | SDOperand Val, const Value* PtrVal, |
Mon P Wang | 6bde9ec | 2008-06-25 08:15:39 +0000 | [diff] [blame] | 385 | unsigned Alignment = 0); |
Andrew Lenharth | e44f390 | 2008-02-21 06:45:13 +0000 | [diff] [blame] | 386 | |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 387 | /// getMergeValues - Create a MERGE_VALUES node from the given operands. |
| 388 | /// Allowed to return something different (and simpler) if Simplify is true. |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 389 | SDOperand getMergeValues(const SDOperand *Ops, unsigned NumOps, |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 390 | bool Simplify = true); |
| 391 | |
Duncan Sands | f19591c | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 392 | /// getMergeValues - Create a MERGE_VALUES node from the given types and ops. |
| 393 | /// Allowed to return something different (and simpler) if Simplify is true. |
Duncan Sands | 698842f | 2008-07-02 17:40:58 +0000 | [diff] [blame] | 394 | /// May be faster than the above version if VTs is known and NumOps is large. |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 395 | SDOperand getMergeValues(SDVTList VTs, const SDOperand *Ops, unsigned NumOps, |
Duncan Sands | f19591c | 2008-06-30 10:19:09 +0000 | [diff] [blame] | 396 | bool Simplify = true) { |
| 397 | if (Simplify && NumOps == 1) |
| 398 | return Ops[0]; |
| 399 | return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps); |
| 400 | } |
| 401 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 402 | /// getLoad - Loads are not normal binary operators: their result type is not |
| 403 | /// determined by their operands, and they produce a value AND a token chain. |
| 404 | /// |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 405 | SDOperand getLoad(MVT VT, SDOperand Chain, SDOperand Ptr, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 406 | const Value *SV, int SVOffset, bool isVolatile=false, |
| 407 | unsigned Alignment=0); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 408 | SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 409 | SDOperand Chain, SDOperand Ptr, const Value *SV, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 410 | int SVOffset, MVT EVT, bool isVolatile=false, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 411 | unsigned Alignment=0); |
| 412 | SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base, |
| 413 | SDOperand Offset, ISD::MemIndexedMode AM); |
Duncan Sands | b258971 | 2008-03-28 09:45:24 +0000 | [diff] [blame] | 414 | SDOperand getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 415 | MVT VT, SDOperand Chain, |
Duncan Sands | b258971 | 2008-03-28 09:45:24 +0000 | [diff] [blame] | 416 | SDOperand Ptr, SDOperand Offset, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 417 | const Value *SV, int SVOffset, MVT EVT, |
Duncan Sands | b258971 | 2008-03-28 09:45:24 +0000 | [diff] [blame] | 418 | bool isVolatile=false, unsigned Alignment=0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 419 | |
| 420 | /// getStore - Helper function to build ISD::STORE nodes. |
| 421 | /// |
| 422 | SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr, |
| 423 | const Value *SV, int SVOffset, bool isVolatile=false, |
| 424 | unsigned Alignment=0); |
| 425 | SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr, |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 426 | const Value *SV, int SVOffset, MVT TVT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 427 | bool isVolatile=false, unsigned Alignment=0); |
| 428 | SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base, |
| 429 | SDOperand Offset, ISD::MemIndexedMode AM); |
| 430 | |
Dan Gohman | 12a9c08 | 2008-02-06 22:27:42 +0000 | [diff] [blame] | 431 | // getSrcValue - Construct a node to track a Value* through the backend. |
| 432 | SDOperand getSrcValue(const Value *v); |
| 433 | |
| 434 | // getMemOperand - Construct a node to track a memory reference |
| 435 | // through the backend. |
Dan Gohman | 1fad9e6 | 2008-04-07 19:35:22 +0000 | [diff] [blame] | 436 | SDOperand getMemOperand(const MachineMemOperand &MO); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 437 | |
| 438 | /// UpdateNodeOperands - *Mutate* the specified node in-place to have the |
| 439 | /// specified operands. If the resultant node already exists in the DAG, |
| 440 | /// this does not modify the specified node, instead it returns the node that |
| 441 | /// already exists. If the resultant node does not exist in the DAG, the |
| 442 | /// input node is returned. As a degenerate case, if you specify the same |
| 443 | /// input operands as the node already has, the input node is returned. |
| 444 | SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op); |
| 445 | SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2); |
| 446 | SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, |
| 447 | SDOperand Op3); |
| 448 | SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, |
| 449 | SDOperand Op3, SDOperand Op4); |
| 450 | SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2, |
| 451 | SDOperand Op3, SDOperand Op4, SDOperand Op5); |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 452 | SDOperand UpdateNodeOperands(SDOperand N, |
| 453 | const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 454 | |
| 455 | /// SelectNodeTo - These are used for target selectors to *mutate* the |
| 456 | /// specified node to have the specified return type, Target opcode, and |
| 457 | /// operands. Note that target opcodes are stored as |
| 458 | /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field. The 0th value |
| 459 | /// of the resultant node is returned. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 460 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT); |
| 461 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDOperand Op1); |
| 462 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 463 | SDOperand Op1, SDOperand Op2); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 464 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 465 | SDOperand Op1, SDOperand Op2, SDOperand Op3); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 466 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 467 | const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | 7eced11 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 468 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2); |
| 469 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 470 | MVT VT2, const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | 7eced11 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 471 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 472 | MVT VT2, MVT VT3, const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | 7eced11 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 473 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, |
| 474 | MVT VT2, SDOperand Op1); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 475 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, |
| 476 | MVT VT2, SDOperand Op1, SDOperand Op2); |
| 477 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, |
| 478 | MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3); |
Dan Gohman | 7eced11 | 2008-07-02 23:23:19 +0000 | [diff] [blame] | 479 | SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 480 | const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 481 | |
| 482 | |
| 483 | /// getTargetNode - These are used for target selectors to create a new node |
| 484 | /// with specified return type(s), target opcode, and operands. |
| 485 | /// |
| 486 | /// Note that getTargetNode returns the resultant node. If there is already a |
| 487 | /// node of the specified opcode and operands, it returns that node instead of |
| 488 | /// the current one. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 489 | SDNode *getTargetNode(unsigned Opcode, MVT VT); |
| 490 | SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1); |
| 491 | SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1, SDOperand Op2); |
| 492 | SDNode *getTargetNode(unsigned Opcode, MVT VT, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 493 | SDOperand Op1, SDOperand Op2, SDOperand Op3); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 494 | SDNode *getTargetNode(unsigned Opcode, MVT VT, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 495 | const SDOperand *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 496 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2); |
| 497 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDOperand Op1); |
| 498 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, |
| 499 | MVT VT2, SDOperand Op1, SDOperand Op2); |
| 500 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, |
| 501 | MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3); |
| 502 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 503 | const SDOperand *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 504 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 505 | SDOperand Op1, SDOperand Op2); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 506 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 507 | SDOperand Op1, SDOperand Op2, SDOperand Op3); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 508 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 509 | const SDOperand *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 510 | SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 511 | const SDOperand *Ops, unsigned NumOps); |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 512 | SDNode *getTargetNode(unsigned Opcode, std::vector<MVT> &ResultTys, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 513 | const SDOperand *Ops, unsigned NumOps); |
Evan Cheng | d111358 | 2008-03-22 01:55:50 +0000 | [diff] [blame] | 514 | |
| 515 | /// getNodeIfExists - Get the specified node if it's already available, or |
| 516 | /// else return NULL. |
| 517 | SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs, |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 518 | const SDOperand *Ops, unsigned NumOps); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 519 | |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 520 | /// DAGUpdateListener - Clients of various APIs that cause global effects on |
| 521 | /// the DAG can optionally implement this interface. This allows the clients |
| 522 | /// to handle the various sorts of updates that happen. |
| 523 | class DAGUpdateListener { |
| 524 | public: |
| 525 | virtual ~DAGUpdateListener(); |
Duncan Sands | 3866b1c | 2008-06-11 11:42:12 +0000 | [diff] [blame] | 526 | |
| 527 | /// NodeDeleted - The node N that was deleted and, if E is not null, an |
| 528 | /// equivalent node E that replaced it. |
| 529 | virtual void NodeDeleted(SDNode *N, SDNode *E) = 0; |
| 530 | |
| 531 | /// NodeUpdated - The node N that was updated. |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 532 | virtual void NodeUpdated(SDNode *N) = 0; |
| 533 | }; |
| 534 | |
| 535 | /// RemoveDeadNode - Remove the specified node from the system. If any of its |
| 536 | /// operands then becomes dead, remove them as well. Inform UpdateListener |
| 537 | /// for each node deleted. |
| 538 | void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0); |
| 539 | |
Dan Gohman | b997a4e | 2008-07-07 20:57:48 +0000 | [diff] [blame] | 540 | /// RemoveDeadNodes - This method deletes the unreachable nodes in the |
| 541 | /// given list, and any nodes that become unreachable as a result. |
| 542 | void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes, |
| 543 | DAGUpdateListener *UpdateListener = 0); |
| 544 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 545 | /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead. |
| 546 | /// This can cause recursive merging of nodes in the DAG. Use the first |
| 547 | /// version if 'From' is known to have a single result, use the second |
| 548 | /// if you have two nodes with identical results, use the third otherwise. |
| 549 | /// |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 550 | /// These methods all take an optional UpdateListener, which (if not null) is |
| 551 | /// informed about nodes that are deleted and modified due to recursive |
| 552 | /// changes in the dag. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 553 | /// |
| 554 | void ReplaceAllUsesWith(SDOperand From, SDOperand Op, |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 555 | DAGUpdateListener *UpdateListener = 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 556 | void ReplaceAllUsesWith(SDNode *From, SDNode *To, |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 557 | DAGUpdateListener *UpdateListener = 0); |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 558 | void ReplaceAllUsesWith(SDNode *From, const SDOperand *To, |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 559 | DAGUpdateListener *UpdateListener = 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 560 | |
| 561 | /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 562 | /// uses of other values produced by From.Val alone. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 563 | void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To, |
Chris Lattner | 7bcb18f | 2008-02-03 06:49:24 +0000 | [diff] [blame] | 564 | DAGUpdateListener *UpdateListener = 0); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 565 | |
| 566 | /// AssignNodeIds - Assign a unique node id for each node in the DAG based on |
| 567 | /// their allnodes order. It returns the maximum id. |
| 568 | unsigned AssignNodeIds(); |
| 569 | |
| 570 | /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG |
| 571 | /// based on their topological order. It returns the maximum id and a vector |
| 572 | /// of the SDNodes* in assigned order by reference. |
| 573 | unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder); |
| 574 | |
| 575 | /// isCommutativeBinOp - Returns true if the opcode is a commutative binary |
| 576 | /// operation. |
| 577 | static bool isCommutativeBinOp(unsigned Opcode) { |
Chris Lattner | 94a4bcd | 2008-01-25 06:20:20 +0000 | [diff] [blame] | 578 | // FIXME: This should get its info from the td file, so that we can include |
| 579 | // target info. |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 580 | switch (Opcode) { |
| 581 | case ISD::ADD: |
| 582 | case ISD::MUL: |
| 583 | case ISD::MULHU: |
| 584 | case ISD::MULHS: |
Dan Gohman | ad24f69 | 2007-10-05 14:09:33 +0000 | [diff] [blame] | 585 | case ISD::SMUL_LOHI: |
| 586 | case ISD::UMUL_LOHI: |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 587 | case ISD::FADD: |
| 588 | case ISD::FMUL: |
| 589 | case ISD::AND: |
| 590 | case ISD::OR: |
| 591 | case ISD::XOR: |
| 592 | case ISD::ADDC: |
| 593 | case ISD::ADDE: return true; |
| 594 | default: return false; |
| 595 | } |
| 596 | } |
| 597 | |
| 598 | void dump() const; |
| 599 | |
Chris Lattner | 53f5aee | 2007-10-15 17:47:20 +0000 | [diff] [blame] | 600 | /// CreateStackTemporary - Create a stack temporary, suitable for holding the |
Mon P Wang | 55854cc | 2008-07-05 20:40:31 +0000 | [diff] [blame] | 601 | /// specified value type. If minAlign is specified, the slot size will have |
| 602 | /// at least that alignment. |
| 603 | SDOperand CreateStackTemporary(MVT VT, unsigned minAlign = 1); |
| 604 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 605 | /// FoldSetCC - Constant fold a setcc to true or false. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 606 | SDOperand FoldSetCC(MVT VT, SDOperand N1, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 607 | SDOperand N2, ISD::CondCode Cond); |
| 608 | |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 609 | /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We |
| 610 | /// use this predicate to simplify operations downstream. |
| 611 | bool SignBitIsZero(SDOperand Op, unsigned Depth = 0) const; |
| 612 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 613 | /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We |
| 614 | /// use this predicate to simplify operations downstream. Op and Mask are |
| 615 | /// known to be the same type. |
Dan Gohman | 07961cd | 2008-02-25 21:11:39 +0000 | [diff] [blame] | 616 | bool MaskedValueIsZero(SDOperand Op, const APInt &Mask, unsigned Depth = 0) |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 617 | const; |
| 618 | |
| 619 | /// ComputeMaskedBits - Determine which of the bits specified in Mask are |
| 620 | /// known to be either zero or one and return them in the KnownZero/KnownOne |
| 621 | /// bitsets. This code only analyzes bits in Mask, in order to short-circuit |
| 622 | /// processing. Targets can implement the computeMaskedBitsForTargetNode |
| 623 | /// method in the TargetLowering class to allow target nodes to be understood. |
Dan Gohman | d0dfc77 | 2008-02-13 22:28:48 +0000 | [diff] [blame] | 624 | void ComputeMaskedBits(SDOperand Op, const APInt &Mask, APInt &KnownZero, |
Dan Gohman | 229fa05 | 2008-02-13 00:35:47 +0000 | [diff] [blame] | 625 | APInt &KnownOne, unsigned Depth = 0) const; |
| 626 | |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 627 | /// ComputeNumSignBits - Return the number of times the sign bit of the |
| 628 | /// register is replicated into the other bits. We know that at least 1 bit |
| 629 | /// is always equal to the sign bit (itself), but other cases can give us |
| 630 | /// information. For example, immediately after an "SRA X, 2", we know that |
| 631 | /// the top 3 bits are all equal to each other, so we return 3. Targets can |
| 632 | /// implement the ComputeNumSignBitsForTarget method in the TargetLowering |
| 633 | /// class to allow target nodes to be understood. |
| 634 | unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const; |
Evan Cheng | 2e28d62 | 2008-02-02 04:07:54 +0000 | [diff] [blame] | 635 | |
| 636 | /// isVerifiedDebugInfoDesc - Returns true if the specified SDOperand has |
| 637 | /// been verified as a debug information descriptor. |
| 638 | bool isVerifiedDebugInfoDesc(SDOperand Op) const; |
Evan Cheng | 411fc17 | 2008-05-13 08:35:03 +0000 | [diff] [blame] | 639 | |
| 640 | /// getShuffleScalarElt - Returns the scalar element that will make up the ith |
| 641 | /// element of the result of the vector shuffle. |
| 642 | SDOperand getShuffleScalarElt(const SDNode *N, unsigned Idx); |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 643 | |
| 644 | private: |
| 645 | void RemoveNodeFromCSEMaps(SDNode *N); |
| 646 | SDNode *AddNonLeafNodeToCSEMaps(SDNode *N); |
| 647 | SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos); |
| 648 | SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2, |
| 649 | void *&InsertPos); |
Dan Gohman | 703ce5d | 2008-07-07 18:26:29 +0000 | [diff] [blame] | 650 | SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps, |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 651 | void *&InsertPos); |
| 652 | |
| 653 | void DeleteNodeNotInCSEMaps(SDNode *N); |
| 654 | |
| 655 | // List of non-single value types. |
Duncan Sands | 92c4391 | 2008-06-06 12:08:01 +0000 | [diff] [blame] | 656 | std::list<std::vector<MVT> > VTList; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 657 | |
| 658 | // Maps to auto-CSE operations. |
| 659 | std::vector<CondCodeSDNode*> CondCodeNodes; |
| 660 | |
| 661 | std::vector<SDNode*> ValueTypeNodes; |
Duncan Sands | ec142ee | 2008-06-08 20:54:56 +0000 | [diff] [blame] | 662 | std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes; |
Dan Gohman | c96298c | 2008-06-23 21:08:32 +0000 | [diff] [blame] | 663 | StringMap<SDNode*> ExternalSymbols; |
| 664 | StringMap<SDNode*> TargetExternalSymbols; |
Dan Gohman | f17a25c | 2007-07-18 16:29:46 +0000 | [diff] [blame] | 665 | }; |
| 666 | |
| 667 | template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> { |
| 668 | typedef SelectionDAG::allnodes_iterator nodes_iterator; |
| 669 | static nodes_iterator nodes_begin(SelectionDAG *G) { |
| 670 | return G->allnodes_begin(); |
| 671 | } |
| 672 | static nodes_iterator nodes_end(SelectionDAG *G) { |
| 673 | return G->allnodes_end(); |
| 674 | } |
| 675 | }; |
| 676 | |
| 677 | } // end namespace llvm |
| 678 | |
| 679 | #endif |