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