Home | History | Annotate | Download | only in CodeGen
      1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is distributed under the University of Illinois Open Source
      6 // License. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 //
     10 // This file declares the SDNode class and derived classes, which are used to
     11 // represent the nodes and operations present in a SelectionDAG.  These nodes
     12 // and operations are machine code level operations, with some similarities to
     13 // the GCC RTL representation.
     14 //
     15 // Clients should include the SelectionDAG.h file instead of this file directly.
     16 //
     17 //===----------------------------------------------------------------------===//
     18 
     19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
     20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
     21 
     22 #include "llvm/Constants.h"
     23 #include "llvm/Instructions.h"
     24 #include "llvm/ADT/FoldingSet.h"
     25 #include "llvm/ADT/GraphTraits.h"
     26 #include "llvm/ADT/ilist_node.h"
     27 #include "llvm/ADT/SmallPtrSet.h"
     28 #include "llvm/ADT/SmallVector.h"
     29 #include "llvm/ADT/STLExtras.h"
     30 #include "llvm/CodeGen/ISDOpcodes.h"
     31 #include "llvm/CodeGen/ValueTypes.h"
     32 #include "llvm/CodeGen/MachineMemOperand.h"
     33 #include "llvm/Support/MathExtras.h"
     34 #include "llvm/Support/DataTypes.h"
     35 #include "llvm/Support/DebugLoc.h"
     36 #include <cassert>
     37 
     38 namespace llvm {
     39 
     40 class SelectionDAG;
     41 class GlobalValue;
     42 class MachineBasicBlock;
     43 class MachineConstantPoolValue;
     44 class SDNode;
     45 class Value;
     46 class MCSymbol;
     47 template <typename T> struct DenseMapInfo;
     48 template <typename T> struct simplify_type;
     49 template <typename T> struct ilist_traits;
     50 
     51 void checkForCycles(const SDNode *N);
     52 
     53 /// SDVTList - This represents a list of ValueType's that has been intern'd by
     54 /// a SelectionDAG.  Instances of this simple value class are returned by
     55 /// SelectionDAG::getVTList(...).
     56 ///
     57 struct SDVTList {
     58   const EVT *VTs;
     59   unsigned int NumVTs;
     60 };
     61 
     62 namespace ISD {
     63   /// Node predicates
     64 
     65   /// isBuildVectorAllOnes - Return true if the specified node is a
     66   /// BUILD_VECTOR where all of the elements are ~0 or undef.
     67   bool isBuildVectorAllOnes(const SDNode *N);
     68 
     69   /// isBuildVectorAllZeros - Return true if the specified node is a
     70   /// BUILD_VECTOR where all of the elements are 0 or undef.
     71   bool isBuildVectorAllZeros(const SDNode *N);
     72 
     73   /// isScalarToVector - Return true if the specified node is a
     74   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
     75   /// element is not an undef.
     76   bool isScalarToVector(const SDNode *N);
     77 }  // end llvm:ISD namespace
     78 
     79 //===----------------------------------------------------------------------===//
     80 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
     81 /// values as the result of a computation.  Many nodes return multiple values,
     82 /// from loads (which define a token and a return value) to ADDC (which returns
     83 /// a result and a carry value), to calls (which may return an arbitrary number
     84 /// of values).
     85 ///
     86 /// As such, each use of a SelectionDAG computation must indicate the node that
     87 /// computes it as well as which return value to use from that node.  This pair
     88 /// of information is represented with the SDValue value type.
     89 ///
     90 class SDValue {
     91   SDNode *Node;       // The node defining the value we are using.
     92   unsigned ResNo;     // Which return value of the node we are using.
     93 public:
     94   SDValue() : Node(0), ResNo(0) {}
     95   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
     96 
     97   /// get the index which selects a specific result in the SDNode
     98   unsigned getResNo() const { return ResNo; }
     99 
    100   /// get the SDNode which holds the desired result
    101   SDNode *getNode() const { return Node; }
    102 
    103   /// set the SDNode
    104   void setNode(SDNode *N) { Node = N; }
    105 
    106   inline SDNode *operator->() const { return Node; }
    107 
    108   bool operator==(const SDValue &O) const {
    109     return Node == O.Node && ResNo == O.ResNo;
    110   }
    111   bool operator!=(const SDValue &O) const {
    112     return !operator==(O);
    113   }
    114   bool operator<(const SDValue &O) const {
    115     return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
    116   }
    117 
    118   SDValue getValue(unsigned R) const {
    119     return SDValue(Node, R);
    120   }
    121 
    122   // isOperandOf - Return true if this node is an operand of N.
    123   bool isOperandOf(SDNode *N) const;
    124 
    125   /// getValueType - Return the ValueType of the referenced return value.
    126   ///
    127   inline EVT getValueType() const;
    128 
    129   /// getValueSizeInBits - Returns the size of the value in bits.
    130   ///
    131   unsigned getValueSizeInBits() const {
    132     return getValueType().getSizeInBits();
    133   }
    134 
    135   // Forwarding methods - These forward to the corresponding methods in SDNode.
    136   inline unsigned getOpcode() const;
    137   inline unsigned getNumOperands() const;
    138   inline const SDValue &getOperand(unsigned i) const;
    139   inline uint64_t getConstantOperandVal(unsigned i) const;
    140   inline bool isTargetMemoryOpcode() const;
    141   inline bool isTargetOpcode() const;
    142   inline bool isMachineOpcode() const;
    143   inline unsigned getMachineOpcode() const;
    144   inline const DebugLoc getDebugLoc() const;
    145 
    146 
    147   /// reachesChainWithoutSideEffects - Return true if this operand (which must
    148   /// be a chain) reaches the specified operand without crossing any
    149   /// side-effecting instructions.  In practice, this looks through token
    150   /// factors and non-volatile loads.  In order to remain efficient, this only
    151   /// looks a couple of nodes in, it does not do an exhaustive search.
    152   bool reachesChainWithoutSideEffects(SDValue Dest,
    153                                       unsigned Depth = 2) const;
    154 
    155   /// use_empty - Return true if there are no nodes using value ResNo
    156   /// of Node.
    157   ///
    158   inline bool use_empty() const;
    159 
    160   /// hasOneUse - Return true if there is exactly one node using value
    161   /// ResNo of Node.
    162   ///
    163   inline bool hasOneUse() const;
    164 };
    165 
    166 
    167 template<> struct DenseMapInfo<SDValue> {
    168   static inline SDValue getEmptyKey() {
    169     return SDValue((SDNode*)-1, -1U);
    170   }
    171   static inline SDValue getTombstoneKey() {
    172     return SDValue((SDNode*)-1, 0);
    173   }
    174   static unsigned getHashValue(const SDValue &Val) {
    175     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
    176             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
    177   }
    178   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
    179     return LHS == RHS;
    180   }
    181 };
    182 template <> struct isPodLike<SDValue> { static const bool value = true; };
    183 
    184 
    185 /// simplify_type specializations - Allow casting operators to work directly on
    186 /// SDValues as if they were SDNode*'s.
    187 template<> struct simplify_type<SDValue> {
    188   typedef SDNode* SimpleType;
    189   static SimpleType getSimplifiedValue(const SDValue &Val) {
    190     return static_cast<SimpleType>(Val.getNode());
    191   }
    192 };
    193 template<> struct simplify_type<const SDValue> {
    194   typedef SDNode* SimpleType;
    195   static SimpleType getSimplifiedValue(const SDValue &Val) {
    196     return static_cast<SimpleType>(Val.getNode());
    197   }
    198 };
    199 
    200 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
    201 /// which records the SDNode being used and the result number, a
    202 /// pointer to the SDNode using the value, and Next and Prev pointers,
    203 /// which link together all the uses of an SDNode.
    204 ///
    205 class SDUse {
    206   /// Val - The value being used.
    207   SDValue Val;
    208   /// User - The user of this value.
    209   SDNode *User;
    210   /// Prev, Next - Pointers to the uses list of the SDNode referred by
    211   /// this operand.
    212   SDUse **Prev, *Next;
    213 
    214   SDUse(const SDUse &U);          // Do not implement
    215   void operator=(const SDUse &U); // Do not implement
    216 
    217 public:
    218   SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
    219 
    220   /// Normally SDUse will just implicitly convert to an SDValue that it holds.
    221   operator const SDValue&() const { return Val; }
    222 
    223   /// If implicit conversion to SDValue doesn't work, the get() method returns
    224   /// the SDValue.
    225   const SDValue &get() const { return Val; }
    226 
    227   /// getUser - This returns the SDNode that contains this Use.
    228   SDNode *getUser() { return User; }
    229 
    230   /// getNext - Get the next SDUse in the use list.
    231   SDUse *getNext() const { return Next; }
    232 
    233   /// getNode - Convenience function for get().getNode().
    234   SDNode *getNode() const { return Val.getNode(); }
    235   /// getResNo - Convenience function for get().getResNo().
    236   unsigned getResNo() const { return Val.getResNo(); }
    237   /// getValueType - Convenience function for get().getValueType().
    238   EVT getValueType() const { return Val.getValueType(); }
    239 
    240   /// operator== - Convenience function for get().operator==
    241   bool operator==(const SDValue &V) const {
    242     return Val == V;
    243   }
    244 
    245   /// operator!= - Convenience function for get().operator!=
    246   bool operator!=(const SDValue &V) const {
    247     return Val != V;
    248   }
    249 
    250   /// operator< - Convenience function for get().operator<
    251   bool operator<(const SDValue &V) const {
    252     return Val < V;
    253   }
    254 
    255 private:
    256   friend class SelectionDAG;
    257   friend class SDNode;
    258 
    259   void setUser(SDNode *p) { User = p; }
    260 
    261   /// set - Remove this use from its existing use list, assign it the
    262   /// given value, and add it to the new value's node's use list.
    263   inline void set(const SDValue &V);
    264   /// setInitial - like set, but only supports initializing a newly-allocated
    265   /// SDUse with a non-null value.
    266   inline void setInitial(const SDValue &V);
    267   /// setNode - like set, but only sets the Node portion of the value,
    268   /// leaving the ResNo portion unmodified.
    269   inline void setNode(SDNode *N);
    270 
    271   void addToList(SDUse **List) {
    272     Next = *List;
    273     if (Next) Next->Prev = &Next;
    274     Prev = List;
    275     *List = this;
    276   }
    277 
    278   void removeFromList() {
    279     *Prev = Next;
    280     if (Next) Next->Prev = Prev;
    281   }
    282 };
    283 
    284 /// simplify_type specializations - Allow casting operators to work directly on
    285 /// SDValues as if they were SDNode*'s.
    286 template<> struct simplify_type<SDUse> {
    287   typedef SDNode* SimpleType;
    288   static SimpleType getSimplifiedValue(const SDUse &Val) {
    289     return static_cast<SimpleType>(Val.getNode());
    290   }
    291 };
    292 template<> struct simplify_type<const SDUse> {
    293   typedef SDNode* SimpleType;
    294   static SimpleType getSimplifiedValue(const SDUse &Val) {
    295     return static_cast<SimpleType>(Val.getNode());
    296   }
    297 };
    298 
    299 
    300 /// SDNode - Represents one node in the SelectionDAG.
    301 ///
    302 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
    303 private:
    304   /// NodeType - The operation that this node performs.
    305   ///
    306   int16_t NodeType;
    307 
    308   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
    309   /// then they will be delete[]'d when the node is destroyed.
    310   uint16_t OperandsNeedDelete : 1;
    311 
    312   /// HasDebugValue - This tracks whether this node has one or more dbg_value
    313   /// nodes corresponding to it.
    314   uint16_t HasDebugValue : 1;
    315 
    316 protected:
    317   /// SubclassData - This member is defined by this class, but is not used for
    318   /// anything.  Subclasses can use it to hold whatever state they find useful.
    319   /// This field is initialized to zero by the ctor.
    320   uint16_t SubclassData : 14;
    321 
    322 private:
    323   /// NodeId - Unique id per SDNode in the DAG.
    324   int NodeId;
    325 
    326   /// OperandList - The values that are used by this operation.
    327   ///
    328   SDUse *OperandList;
    329 
    330   /// ValueList - The types of the values this node defines.  SDNode's may
    331   /// define multiple values simultaneously.
    332   const EVT *ValueList;
    333 
    334   /// UseList - List of uses for this SDNode.
    335   SDUse *UseList;
    336 
    337   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
    338   unsigned short NumOperands, NumValues;
    339 
    340   /// debugLoc - source line information.
    341   DebugLoc debugLoc;
    342 
    343   /// getValueTypeList - Return a pointer to the specified value type.
    344   static const EVT *getValueTypeList(EVT VT);
    345 
    346   friend class SelectionDAG;
    347   friend struct ilist_traits<SDNode>;
    348 
    349 public:
    350   //===--------------------------------------------------------------------===//
    351   //  Accessors
    352   //
    353 
    354   /// getOpcode - Return the SelectionDAG opcode value for this node. For
    355   /// pre-isel nodes (those for which isMachineOpcode returns false), these
    356   /// are the opcode values in the ISD and <target>ISD namespaces. For
    357   /// post-isel opcodes, see getMachineOpcode.
    358   unsigned getOpcode()  const { return (unsigned short)NodeType; }
    359 
    360   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
    361   /// \<target\>ISD namespace).
    362   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
    363 
    364   /// isTargetMemoryOpcode - Test if this node has a target-specific
    365   /// memory-referencing opcode (in the \<target\>ISD namespace and
    366   /// greater than FIRST_TARGET_MEMORY_OPCODE).
    367   bool isTargetMemoryOpcode() const {
    368     return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
    369   }
    370 
    371   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
    372   /// corresponding to a MachineInstr opcode.
    373   bool isMachineOpcode() const { return NodeType < 0; }
    374 
    375   /// getMachineOpcode - This may only be called if isMachineOpcode returns
    376   /// true. It returns the MachineInstr opcode value that the node's opcode
    377   /// corresponds to.
    378   unsigned getMachineOpcode() const {
    379     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
    380     return ~NodeType;
    381   }
    382 
    383   /// getHasDebugValue - get this bit.
    384   bool getHasDebugValue() const { return HasDebugValue; }
    385 
    386   /// setHasDebugValue - set this bit.
    387   void setHasDebugValue(bool b) { HasDebugValue = b; }
    388 
    389   /// use_empty - Return true if there are no uses of this node.
    390   ///
    391   bool use_empty() const { return UseList == NULL; }
    392 
    393   /// hasOneUse - Return true if there is exactly one use of this node.
    394   ///
    395   bool hasOneUse() const {
    396     return !use_empty() && llvm::next(use_begin()) == use_end();
    397   }
    398 
    399   /// use_size - Return the number of uses of this node. This method takes
    400   /// time proportional to the number of uses.
    401   ///
    402   size_t use_size() const { return std::distance(use_begin(), use_end()); }
    403 
    404   /// getNodeId - Return the unique node id.
    405   ///
    406   int getNodeId() const { return NodeId; }
    407 
    408   /// setNodeId - Set unique node id.
    409   void setNodeId(int Id) { NodeId = Id; }
    410 
    411   /// getDebugLoc - Return the source location info.
    412   const DebugLoc getDebugLoc() const { return debugLoc; }
    413 
    414   /// setDebugLoc - Set source location info.  Try to avoid this, putting
    415   /// it in the constructor is preferable.
    416   void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
    417 
    418   /// use_iterator - This class provides iterator support for SDUse
    419   /// operands that use a specific SDNode.
    420   class use_iterator
    421     : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
    422     SDUse *Op;
    423     explicit use_iterator(SDUse *op) : Op(op) {
    424     }
    425     friend class SDNode;
    426   public:
    427     typedef std::iterator<std::forward_iterator_tag,
    428                           SDUse, ptrdiff_t>::reference reference;
    429     typedef std::iterator<std::forward_iterator_tag,
    430                           SDUse, ptrdiff_t>::pointer pointer;
    431 
    432     use_iterator(const use_iterator &I) : Op(I.Op) {}
    433     use_iterator() : Op(0) {}
    434 
    435     bool operator==(const use_iterator &x) const {
    436       return Op == x.Op;
    437     }
    438     bool operator!=(const use_iterator &x) const {
    439       return !operator==(x);
    440     }
    441 
    442     /// atEnd - return true if this iterator is at the end of uses list.
    443     bool atEnd() const { return Op == 0; }
    444 
    445     // Iterator traversal: forward iteration only.
    446     use_iterator &operator++() {          // Preincrement
    447       assert(Op && "Cannot increment end iterator!");
    448       Op = Op->getNext();
    449       return *this;
    450     }
    451 
    452     use_iterator operator++(int) {        // Postincrement
    453       use_iterator tmp = *this; ++*this; return tmp;
    454     }
    455 
    456     /// Retrieve a pointer to the current user node.
    457     SDNode *operator*() const {
    458       assert(Op && "Cannot dereference end iterator!");
    459       return Op->getUser();
    460     }
    461 
    462     SDNode *operator->() const { return operator*(); }
    463 
    464     SDUse &getUse() const { return *Op; }
    465 
    466     /// getOperandNo - Retrieve the operand # of this use in its user.
    467     ///
    468     unsigned getOperandNo() const {
    469       assert(Op && "Cannot dereference end iterator!");
    470       return (unsigned)(Op - Op->getUser()->OperandList);
    471     }
    472   };
    473 
    474   /// use_begin/use_end - Provide iteration support to walk over all uses
    475   /// of an SDNode.
    476 
    477   use_iterator use_begin() const {
    478     return use_iterator(UseList);
    479   }
    480 
    481   static use_iterator use_end() { return use_iterator(0); }
    482 
    483 
    484   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
    485   /// indicated value.  This method ignores uses of other values defined by this
    486   /// operation.
    487   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
    488 
    489   /// hasAnyUseOfValue - Return true if there are any use of the indicated
    490   /// value. This method ignores uses of other values defined by this operation.
    491   bool hasAnyUseOfValue(unsigned Value) const;
    492 
    493   /// isOnlyUserOf - Return true if this node is the only use of N.
    494   ///
    495   bool isOnlyUserOf(SDNode *N) const;
    496 
    497   /// isOperandOf - Return true if this node is an operand of N.
    498   ///
    499   bool isOperandOf(SDNode *N) const;
    500 
    501   /// isPredecessorOf - Return true if this node is a predecessor of N.
    502   /// NOTE: Implemented on top of hasPredecessor and every bit as
    503   /// expensive. Use carefully.
    504   bool isPredecessorOf(const SDNode *N) const { return N->hasPredecessor(this); }
    505 
    506   /// hasPredecessor - Return true if N is a predecessor of this node.
    507   /// N is either an operand of this node, or can be reached by recursively
    508   /// traversing up the operands.
    509   /// NOTE: This is an expensive method. Use it carefully.
    510   bool hasPredecessor(const SDNode *N) const;
    511 
    512   /// hasPredecesorHelper - Return true if N is a predecessor of this node.
    513   /// N is either an operand of this node, or can be reached by recursively
    514   /// traversing up the operands.
    515   /// In this helper the Visited and worklist sets are held externally to
    516   /// cache predecessors over multiple invocations. If you want to test for
    517   /// multiple predecessors this method is preferable to multiple calls to
    518   /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
    519   /// changes.
    520   /// NOTE: This is still very expensive. Use carefully.
    521   bool hasPredecessorHelper(const SDNode *N,
    522                             SmallPtrSet<const SDNode *, 32> &Visited,
    523                             SmallVector<const SDNode *, 16> &Worklist) const;
    524 
    525   /// getNumOperands - Return the number of values used by this operation.
    526   ///
    527   unsigned getNumOperands() const { return NumOperands; }
    528 
    529   /// getConstantOperandVal - Helper method returns the integer value of a
    530   /// ConstantSDNode operand.
    531   uint64_t getConstantOperandVal(unsigned Num) const;
    532 
    533   const SDValue &getOperand(unsigned Num) const {
    534     assert(Num < NumOperands && "Invalid child # of SDNode!");
    535     return OperandList[Num];
    536   }
    537 
    538   typedef SDUse* op_iterator;
    539   op_iterator op_begin() const { return OperandList; }
    540   op_iterator op_end() const { return OperandList+NumOperands; }
    541 
    542   SDVTList getVTList() const {
    543     SDVTList X = { ValueList, NumValues };
    544     return X;
    545   }
    546 
    547   /// getGluedNode - If this node has a glue operand, return the node
    548   /// to which the glue operand points. Otherwise return NULL.
    549   SDNode *getGluedNode() const {
    550     if (getNumOperands() != 0 &&
    551       getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
    552       return getOperand(getNumOperands()-1).getNode();
    553     return 0;
    554   }
    555 
    556   // If this is a pseudo op, like copyfromreg, look to see if there is a
    557   // real target node glued to it.  If so, return the target node.
    558   const SDNode *getGluedMachineNode() const {
    559     const SDNode *FoundNode = this;
    560 
    561     // Climb up glue edges until a machine-opcode node is found, or the
    562     // end of the chain is reached.
    563     while (!FoundNode->isMachineOpcode()) {
    564       const SDNode *N = FoundNode->getGluedNode();
    565       if (!N) break;
    566       FoundNode = N;
    567     }
    568 
    569     return FoundNode;
    570   }
    571 
    572   /// getGluedUser - If this node has a glue value with a user, return
    573   /// the user (there is at most one). Otherwise return NULL.
    574   SDNode *getGluedUser() const {
    575     for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
    576       if (UI.getUse().get().getValueType() == MVT::Glue)
    577         return *UI;
    578     return 0;
    579   }
    580 
    581   /// getNumValues - Return the number of values defined/returned by this
    582   /// operator.
    583   ///
    584   unsigned getNumValues() const { return NumValues; }
    585 
    586   /// getValueType - Return the type of a specified result.
    587   ///
    588   EVT getValueType(unsigned ResNo) const {
    589     assert(ResNo < NumValues && "Illegal result number!");
    590     return ValueList[ResNo];
    591   }
    592 
    593   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
    594   ///
    595   unsigned getValueSizeInBits(unsigned ResNo) const {
    596     return getValueType(ResNo).getSizeInBits();
    597   }
    598 
    599   typedef const EVT* value_iterator;
    600   value_iterator value_begin() const { return ValueList; }
    601   value_iterator value_end() const { return ValueList+NumValues; }
    602 
    603   /// getOperationName - Return the opcode of this operation for printing.
    604   ///
    605   std::string getOperationName(const SelectionDAG *G = 0) const;
    606   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
    607   void print_types(raw_ostream &OS, const SelectionDAG *G) const;
    608   void print_details(raw_ostream &OS, const SelectionDAG *G) const;
    609   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
    610   void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
    611 
    612   /// printrFull - Print a SelectionDAG node and all children down to
    613   /// the leaves.  The given SelectionDAG allows target-specific nodes
    614   /// to be printed in human-readable form.  Unlike printr, this will
    615   /// print the whole DAG, including children that appear multiple
    616   /// times.
    617   ///
    618   void printrFull(raw_ostream &O, const SelectionDAG *G = 0) const;
    619 
    620   /// printrWithDepth - Print a SelectionDAG node and children up to
    621   /// depth "depth."  The given SelectionDAG allows target-specific
    622   /// nodes to be printed in human-readable form.  Unlike printr, this
    623   /// will print children that appear multiple times wherever they are
    624   /// used.
    625   ///
    626   void printrWithDepth(raw_ostream &O, const SelectionDAG *G = 0,
    627                        unsigned depth = 100) const;
    628 
    629 
    630   /// dump - Dump this node, for debugging.
    631   void dump() const;
    632 
    633   /// dumpr - Dump (recursively) this node and its use-def subgraph.
    634   void dumpr() const;
    635 
    636   /// dump - Dump this node, for debugging.
    637   /// The given SelectionDAG allows target-specific nodes to be printed
    638   /// in human-readable form.
    639   void dump(const SelectionDAG *G) const;
    640 
    641   /// dumpr - Dump (recursively) this node and its use-def subgraph.
    642   /// The given SelectionDAG allows target-specific nodes to be printed
    643   /// in human-readable form.
    644   void dumpr(const SelectionDAG *G) const;
    645 
    646   /// dumprFull - printrFull to dbgs().  The given SelectionDAG allows
    647   /// target-specific nodes to be printed in human-readable form.
    648   /// Unlike dumpr, this will print the whole DAG, including children
    649   /// that appear multiple times.
    650   ///
    651   void dumprFull(const SelectionDAG *G = 0) const;
    652 
    653   /// dumprWithDepth - printrWithDepth to dbgs().  The given
    654   /// SelectionDAG allows target-specific nodes to be printed in
    655   /// human-readable form.  Unlike dumpr, this will print children
    656   /// that appear multiple times wherever they are used.
    657   ///
    658   void dumprWithDepth(const SelectionDAG *G = 0, unsigned depth = 100) const;
    659 
    660 
    661   static bool classof(const SDNode *) { return true; }
    662 
    663   /// Profile - Gather unique data for the node.
    664   ///
    665   void Profile(FoldingSetNodeID &ID) const;
    666 
    667   /// addUse - This method should only be used by the SDUse class.
    668   ///
    669   void addUse(SDUse &U) { U.addToList(&UseList); }
    670 
    671 protected:
    672   static SDVTList getSDVTList(EVT VT) {
    673     SDVTList Ret = { getValueTypeList(VT), 1 };
    674     return Ret;
    675   }
    676 
    677   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
    678          unsigned NumOps)
    679     : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
    680       SubclassData(0), NodeId(-1),
    681       OperandList(NumOps ? new SDUse[NumOps] : 0),
    682       ValueList(VTs.VTs), UseList(NULL),
    683       NumOperands(NumOps), NumValues(VTs.NumVTs),
    684       debugLoc(dl) {
    685     for (unsigned i = 0; i != NumOps; ++i) {
    686       OperandList[i].setUser(this);
    687       OperandList[i].setInitial(Ops[i]);
    688     }
    689     checkForCycles(this);
    690   }
    691 
    692   /// This constructor adds no operands itself; operands can be
    693   /// set later with InitOperands.
    694   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
    695     : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
    696       SubclassData(0), NodeId(-1), OperandList(0), ValueList(VTs.VTs),
    697       UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs),
    698       debugLoc(dl) {}
    699 
    700   /// InitOperands - Initialize the operands list of this with 1 operand.
    701   void InitOperands(SDUse *Ops, const SDValue &Op0) {
    702     Ops[0].setUser(this);
    703     Ops[0].setInitial(Op0);
    704     NumOperands = 1;
    705     OperandList = Ops;
    706     checkForCycles(this);
    707   }
    708 
    709   /// InitOperands - Initialize the operands list of this with 2 operands.
    710   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
    711     Ops[0].setUser(this);
    712     Ops[0].setInitial(Op0);
    713     Ops[1].setUser(this);
    714     Ops[1].setInitial(Op1);
    715     NumOperands = 2;
    716     OperandList = Ops;
    717     checkForCycles(this);
    718   }
    719 
    720   /// InitOperands - Initialize the operands list of this with 3 operands.
    721   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
    722                     const SDValue &Op2) {
    723     Ops[0].setUser(this);
    724     Ops[0].setInitial(Op0);
    725     Ops[1].setUser(this);
    726     Ops[1].setInitial(Op1);
    727     Ops[2].setUser(this);
    728     Ops[2].setInitial(Op2);
    729     NumOperands = 3;
    730     OperandList = Ops;
    731     checkForCycles(this);
    732   }
    733 
    734   /// InitOperands - Initialize the operands list of this with 4 operands.
    735   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
    736                     const SDValue &Op2, const SDValue &Op3) {
    737     Ops[0].setUser(this);
    738     Ops[0].setInitial(Op0);
    739     Ops[1].setUser(this);
    740     Ops[1].setInitial(Op1);
    741     Ops[2].setUser(this);
    742     Ops[2].setInitial(Op2);
    743     Ops[3].setUser(this);
    744     Ops[3].setInitial(Op3);
    745     NumOperands = 4;
    746     OperandList = Ops;
    747     checkForCycles(this);
    748   }
    749 
    750   /// InitOperands - Initialize the operands list of this with N operands.
    751   void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
    752     for (unsigned i = 0; i != N; ++i) {
    753       Ops[i].setUser(this);
    754       Ops[i].setInitial(Vals[i]);
    755     }
    756     NumOperands = N;
    757     OperandList = Ops;
    758     checkForCycles(this);
    759   }
    760 
    761   /// DropOperands - Release the operands and set this node to have
    762   /// zero operands.
    763   void DropOperands();
    764 };
    765 
    766 
    767 // Define inline functions from the SDValue class.
    768 
    769 inline unsigned SDValue::getOpcode() const {
    770   return Node->getOpcode();
    771 }
    772 inline EVT SDValue::getValueType() const {
    773   return Node->getValueType(ResNo);
    774 }
    775 inline unsigned SDValue::getNumOperands() const {
    776   return Node->getNumOperands();
    777 }
    778 inline const SDValue &SDValue::getOperand(unsigned i) const {
    779   return Node->getOperand(i);
    780 }
    781 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
    782   return Node->getConstantOperandVal(i);
    783 }
    784 inline bool SDValue::isTargetOpcode() const {
    785   return Node->isTargetOpcode();
    786 }
    787 inline bool SDValue::isTargetMemoryOpcode() const {
    788   return Node->isTargetMemoryOpcode();
    789 }
    790 inline bool SDValue::isMachineOpcode() const {
    791   return Node->isMachineOpcode();
    792 }
    793 inline unsigned SDValue::getMachineOpcode() const {
    794   return Node->getMachineOpcode();
    795 }
    796 inline bool SDValue::use_empty() const {
    797   return !Node->hasAnyUseOfValue(ResNo);
    798 }
    799 inline bool SDValue::hasOneUse() const {
    800   return Node->hasNUsesOfValue(1, ResNo);
    801 }
    802 inline const DebugLoc SDValue::getDebugLoc() const {
    803   return Node->getDebugLoc();
    804 }
    805 
    806 // Define inline functions from the SDUse class.
    807 
    808 inline void SDUse::set(const SDValue &V) {
    809   if (Val.getNode()) removeFromList();
    810   Val = V;
    811   if (V.getNode()) V.getNode()->addUse(*this);
    812 }
    813 
    814 inline void SDUse::setInitial(const SDValue &V) {
    815   Val = V;
    816   V.getNode()->addUse(*this);
    817 }
    818 
    819 inline void SDUse::setNode(SDNode *N) {
    820   if (Val.getNode()) removeFromList();
    821   Val.setNode(N);
    822   if (N) N->addUse(*this);
    823 }
    824 
    825 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
    826 /// to allow co-allocation of node operands with the node itself.
    827 class UnarySDNode : public SDNode {
    828   SDUse Op;
    829 public:
    830   UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
    831     : SDNode(Opc, dl, VTs) {
    832     InitOperands(&Op, X);
    833   }
    834 };
    835 
    836 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
    837 /// to allow co-allocation of node operands with the node itself.
    838 class BinarySDNode : public SDNode {
    839   SDUse Ops[2];
    840 public:
    841   BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
    842     : SDNode(Opc, dl, VTs) {
    843     InitOperands(Ops, X, Y);
    844   }
    845 };
    846 
    847 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
    848 /// to allow co-allocation of node operands with the node itself.
    849 class TernarySDNode : public SDNode {
    850   SDUse Ops[3];
    851 public:
    852   TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
    853                 SDValue Z)
    854     : SDNode(Opc, dl, VTs) {
    855     InitOperands(Ops, X, Y, Z);
    856   }
    857 };
    858 
    859 
    860 /// HandleSDNode - This class is used to form a handle around another node that
    861 /// is persistent and is updated across invocations of replaceAllUsesWith on its
    862 /// operand.  This node should be directly created by end-users and not added to
    863 /// the AllNodes list.
    864 class HandleSDNode : public SDNode {
    865   SDUse Op;
    866 public:
    867   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
    868   // fixed.
    869 #if __GNUC__==4 && __GNUC_MINOR__==2 && defined(__APPLE__) && !defined(__llvm__)
    870   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
    871 #else
    872   explicit HandleSDNode(SDValue X)
    873 #endif
    874     : SDNode(ISD::HANDLENODE, DebugLoc(), getSDVTList(MVT::Other)) {
    875     InitOperands(&Op, X);
    876   }
    877   ~HandleSDNode();
    878   const SDValue &getValue() const { return Op; }
    879 };
    880 
    881 /// Abstact virtual class for operations for memory operations
    882 class MemSDNode : public SDNode {
    883 private:
    884   // MemoryVT - VT of in-memory value.
    885   EVT MemoryVT;
    886 
    887 protected:
    888   /// MMO - Memory reference information.
    889   MachineMemOperand *MMO;
    890 
    891 public:
    892   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
    893             MachineMemOperand *MMO);
    894 
    895   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
    896             unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
    897 
    898   bool readMem() const { return MMO->isLoad(); }
    899   bool writeMem() const { return MMO->isStore(); }
    900 
    901   /// Returns alignment and volatility of the memory access
    902   unsigned getOriginalAlignment() const {
    903     return MMO->getBaseAlignment();
    904   }
    905   unsigned getAlignment() const {
    906     return MMO->getAlignment();
    907   }
    908 
    909   /// getRawSubclassData - Return the SubclassData value, which contains an
    910   /// encoding of the volatile flag, as well as bits used by subclasses. This
    911   /// function should only be used to compute a FoldingSetNodeID value.
    912   unsigned getRawSubclassData() const {
    913     return SubclassData;
    914   }
    915 
    916   // We access subclass data here so that we can check consistency
    917   // with MachineMemOperand information.
    918   bool isVolatile() const { return (SubclassData >> 5) & 1; }
    919   bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
    920   bool isInvariant() const { return (SubclassData >> 7) & 1; }
    921 
    922   AtomicOrdering getOrdering() const {
    923     return AtomicOrdering((SubclassData >> 8) & 15);
    924   }
    925   SynchronizationScope getSynchScope() const {
    926     return SynchronizationScope((SubclassData >> 12) & 1);
    927   }
    928 
    929   /// Returns the SrcValue and offset that describes the location of the access
    930   const Value *getSrcValue() const { return MMO->getValue(); }
    931   int64_t getSrcValueOffset() const { return MMO->getOffset(); }
    932 
    933   /// Returns the TBAAInfo that describes the dereference.
    934   const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
    935 
    936   /// Returns the Ranges that describes the dereference.
    937   const MDNode *getRanges() const { return MMO->getRanges(); }
    938 
    939   /// getMemoryVT - Return the type of the in-memory value.
    940   EVT getMemoryVT() const { return MemoryVT; }
    941 
    942   /// getMemOperand - Return a MachineMemOperand object describing the memory
    943   /// reference performed by operation.
    944   MachineMemOperand *getMemOperand() const { return MMO; }
    945 
    946   const MachinePointerInfo &getPointerInfo() const {
    947     return MMO->getPointerInfo();
    948   }
    949 
    950   /// refineAlignment - Update this MemSDNode's MachineMemOperand information
    951   /// to reflect the alignment of NewMMO, if it has a greater alignment.
    952   /// This must only be used when the new alignment applies to all users of
    953   /// this MachineMemOperand.
    954   void refineAlignment(const MachineMemOperand *NewMMO) {
    955     MMO->refineAlignment(NewMMO);
    956   }
    957 
    958   const SDValue &getChain() const { return getOperand(0); }
    959   const SDValue &getBasePtr() const {
    960     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
    961   }
    962 
    963   // Methods to support isa and dyn_cast
    964   static bool classof(const MemSDNode *) { return true; }
    965   static bool classof(const SDNode *N) {
    966     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
    967     // with either an intrinsic or a target opcode.
    968     return N->getOpcode() == ISD::LOAD                ||
    969            N->getOpcode() == ISD::STORE               ||
    970            N->getOpcode() == ISD::PREFETCH            ||
    971            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
    972            N->getOpcode() == ISD::ATOMIC_SWAP         ||
    973            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
    974            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
    975            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
    976            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
    977            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
    978            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
    979            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
    980            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
    981            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
    982            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
    983            N->getOpcode() == ISD::ATOMIC_LOAD         ||
    984            N->getOpcode() == ISD::ATOMIC_STORE        ||
    985            N->isTargetMemoryOpcode();
    986   }
    987 };
    988 
    989 /// AtomicSDNode - A SDNode reprenting atomic operations.
    990 ///
    991 class AtomicSDNode : public MemSDNode {
    992   SDUse Ops[4];
    993 
    994   void InitAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope) {
    995     // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
    996     assert((Ordering & 15) == Ordering &&
    997            "Ordering may not require more than 4 bits!");
    998     assert((SynchScope & 1) == SynchScope &&
    999            "SynchScope may not require more than 1 bit!");
   1000     SubclassData |= Ordering << 8;
   1001     SubclassData |= SynchScope << 12;
   1002     assert(getOrdering() == Ordering && "Ordering encoding error!");
   1003     assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
   1004 
   1005     assert((readMem() || getOrdering() <= Monotonic) &&
   1006            "Acquire/Release MachineMemOperand must be a load!");
   1007     assert((writeMem() || getOrdering() <= Monotonic) &&
   1008            "Acquire/Release MachineMemOperand must be a store!");
   1009   }
   1010 
   1011 public:
   1012   // Opc:   opcode for atomic
   1013   // VTL:    value type list
   1014   // Chain:  memory chain for operaand
   1015   // Ptr:    address to update as a SDValue
   1016   // Cmp:    compare value
   1017   // Swp:    swap value
   1018   // SrcVal: address to update as a Value (used for MemOperand)
   1019   // Align:  alignment of memory
   1020   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
   1021                SDValue Chain, SDValue Ptr,
   1022                SDValue Cmp, SDValue Swp, MachineMemOperand *MMO,
   1023                AtomicOrdering Ordering, SynchronizationScope SynchScope)
   1024     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
   1025     InitAtomic(Ordering, SynchScope);
   1026     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
   1027   }
   1028   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
   1029                SDValue Chain, SDValue Ptr,
   1030                SDValue Val, MachineMemOperand *MMO,
   1031                AtomicOrdering Ordering, SynchronizationScope SynchScope)
   1032     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
   1033     InitAtomic(Ordering, SynchScope);
   1034     InitOperands(Ops, Chain, Ptr, Val);
   1035   }
   1036   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
   1037                SDValue Chain, SDValue Ptr,
   1038                MachineMemOperand *MMO,
   1039                AtomicOrdering Ordering, SynchronizationScope SynchScope)
   1040     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
   1041     InitAtomic(Ordering, SynchScope);
   1042     InitOperands(Ops, Chain, Ptr);
   1043   }
   1044 
   1045   const SDValue &getBasePtr() const { return getOperand(1); }
   1046   const SDValue &getVal() const { return getOperand(2); }
   1047 
   1048   bool isCompareAndSwap() const {
   1049     unsigned Op = getOpcode();
   1050     return Op == ISD::ATOMIC_CMP_SWAP;
   1051   }
   1052 
   1053   // Methods to support isa and dyn_cast
   1054   static bool classof(const AtomicSDNode *) { return true; }
   1055   static bool classof(const SDNode *N) {
   1056     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
   1057            N->getOpcode() == ISD::ATOMIC_SWAP         ||
   1058            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
   1059            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
   1060            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
   1061            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
   1062            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
   1063            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
   1064            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
   1065            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
   1066            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
   1067            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
   1068            N->getOpcode() == ISD::ATOMIC_LOAD         ||
   1069            N->getOpcode() == ISD::ATOMIC_STORE;
   1070   }
   1071 };
   1072 
   1073 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
   1074 /// memory and need an associated MachineMemOperand. Its opcode may be
   1075 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
   1076 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
   1077 class MemIntrinsicSDNode : public MemSDNode {
   1078 public:
   1079   MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
   1080                      const SDValue *Ops, unsigned NumOps,
   1081                      EVT MemoryVT, MachineMemOperand *MMO)
   1082     : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
   1083   }
   1084 
   1085   // Methods to support isa and dyn_cast
   1086   static bool classof(const MemIntrinsicSDNode *) { return true; }
   1087   static bool classof(const SDNode *N) {
   1088     // We lower some target intrinsics to their target opcode
   1089     // early a node with a target opcode can be of this class
   1090     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
   1091            N->getOpcode() == ISD::INTRINSIC_VOID ||
   1092            N->getOpcode() == ISD::PREFETCH ||
   1093            N->isTargetMemoryOpcode();
   1094   }
   1095 };
   1096 
   1097 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
   1098 /// support for the llvm IR shufflevector instruction.  It combines elements
   1099 /// from two input vectors into a new input vector, with the selection and
   1100 /// ordering of elements determined by an array of integers, referred to as
   1101 /// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
   1102 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
   1103 /// An index of -1 is treated as undef, such that the code generator may put
   1104 /// any value in the corresponding element of the result.
   1105 class ShuffleVectorSDNode : public SDNode {
   1106   SDUse Ops[2];
   1107 
   1108   // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
   1109   // is freed when the SelectionDAG object is destroyed.
   1110   const int *Mask;
   1111 protected:
   1112   friend class SelectionDAG;
   1113   ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2,
   1114                       const int *M)
   1115     : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
   1116     InitOperands(Ops, N1, N2);
   1117   }
   1118 public:
   1119 
   1120   ArrayRef<int> getMask() const {
   1121     EVT VT = getValueType(0);
   1122     return makeArrayRef(Mask, VT.getVectorNumElements());
   1123   }
   1124   int getMaskElt(unsigned Idx) const {
   1125     assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
   1126     return Mask[Idx];
   1127   }
   1128 
   1129   bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
   1130   int  getSplatIndex() const {
   1131     assert(isSplat() && "Cannot get splat index for non-splat!");
   1132     EVT VT = getValueType(0);
   1133     for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
   1134       if (Mask[i] != -1)
   1135         return Mask[i];
   1136     }
   1137     return -1;
   1138   }
   1139   static bool isSplatMask(const int *Mask, EVT VT);
   1140 
   1141   static bool classof(const ShuffleVectorSDNode *) { return true; }
   1142   static bool classof(const SDNode *N) {
   1143     return N->getOpcode() == ISD::VECTOR_SHUFFLE;
   1144   }
   1145 };
   1146 
   1147 class ConstantSDNode : public SDNode {
   1148   const ConstantInt *Value;
   1149   friend class SelectionDAG;
   1150   ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
   1151     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
   1152              DebugLoc(), getSDVTList(VT)), Value(val) {
   1153   }
   1154 public:
   1155 
   1156   const ConstantInt *getConstantIntValue() const { return Value; }
   1157   const APInt &getAPIntValue() const { return Value->getValue(); }
   1158   uint64_t getZExtValue() const { return Value->getZExtValue(); }
   1159   int64_t getSExtValue() const { return Value->getSExtValue(); }
   1160 
   1161   bool isOne() const { return Value->isOne(); }
   1162   bool isNullValue() const { return Value->isNullValue(); }
   1163   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
   1164 
   1165   static bool classof(const ConstantSDNode *) { return true; }
   1166   static bool classof(const SDNode *N) {
   1167     return N->getOpcode() == ISD::Constant ||
   1168            N->getOpcode() == ISD::TargetConstant;
   1169   }
   1170 };
   1171 
   1172 class ConstantFPSDNode : public SDNode {
   1173   const ConstantFP *Value;
   1174   friend class SelectionDAG;
   1175   ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
   1176     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
   1177              DebugLoc(), getSDVTList(VT)), Value(val) {
   1178   }
   1179 public:
   1180 
   1181   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
   1182   const ConstantFP *getConstantFPValue() const { return Value; }
   1183 
   1184   /// isZero - Return true if the value is positive or negative zero.
   1185   bool isZero() const { return Value->isZero(); }
   1186 
   1187   /// isNaN - Return true if the value is a NaN.
   1188   bool isNaN() const { return Value->isNaN(); }
   1189 
   1190   /// isExactlyValue - We don't rely on operator== working on double values, as
   1191   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
   1192   /// As such, this method can be used to do an exact bit-for-bit comparison of
   1193   /// two floating point values.
   1194 
   1195   /// We leave the version with the double argument here because it's just so
   1196   /// convenient to write "2.0" and the like.  Without this function we'd
   1197   /// have to duplicate its logic everywhere it's called.
   1198   bool isExactlyValue(double V) const {
   1199     bool ignored;
   1200     // convert is not supported on this type
   1201     if (&Value->getValueAPF().getSemantics() == &APFloat::PPCDoubleDouble)
   1202       return false;
   1203     APFloat Tmp(V);
   1204     Tmp.convert(Value->getValueAPF().getSemantics(),
   1205                 APFloat::rmNearestTiesToEven, &ignored);
   1206     return isExactlyValue(Tmp);
   1207   }
   1208   bool isExactlyValue(const APFloat& V) const;
   1209 
   1210   static bool isValueValidForType(EVT VT, const APFloat& Val);
   1211 
   1212   static bool classof(const ConstantFPSDNode *) { return true; }
   1213   static bool classof(const SDNode *N) {
   1214     return N->getOpcode() == ISD::ConstantFP ||
   1215            N->getOpcode() == ISD::TargetConstantFP;
   1216   }
   1217 };
   1218 
   1219 class GlobalAddressSDNode : public SDNode {
   1220   const GlobalValue *TheGlobal;
   1221   int64_t Offset;
   1222   unsigned char TargetFlags;
   1223   friend class SelectionDAG;
   1224   GlobalAddressSDNode(unsigned Opc, DebugLoc DL, const GlobalValue *GA, EVT VT,
   1225                       int64_t o, unsigned char TargetFlags);
   1226 public:
   1227 
   1228   const GlobalValue *getGlobal() const { return TheGlobal; }
   1229   int64_t getOffset() const { return Offset; }
   1230   unsigned char getTargetFlags() const { return TargetFlags; }
   1231   // Return the address space this GlobalAddress belongs to.
   1232   unsigned getAddressSpace() const;
   1233 
   1234   static bool classof(const GlobalAddressSDNode *) { return true; }
   1235   static bool classof(const SDNode *N) {
   1236     return N->getOpcode() == ISD::GlobalAddress ||
   1237            N->getOpcode() == ISD::TargetGlobalAddress ||
   1238            N->getOpcode() == ISD::GlobalTLSAddress ||
   1239            N->getOpcode() == ISD::TargetGlobalTLSAddress;
   1240   }
   1241 };
   1242 
   1243 class FrameIndexSDNode : public SDNode {
   1244   int FI;
   1245   friend class SelectionDAG;
   1246   FrameIndexSDNode(int fi, EVT VT, bool isTarg)
   1247     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
   1248       DebugLoc(), getSDVTList(VT)), FI(fi) {
   1249   }
   1250 public:
   1251 
   1252   int getIndex() const { return FI; }
   1253 
   1254   static bool classof(const FrameIndexSDNode *) { return true; }
   1255   static bool classof(const SDNode *N) {
   1256     return N->getOpcode() == ISD::FrameIndex ||
   1257            N->getOpcode() == ISD::TargetFrameIndex;
   1258   }
   1259 };
   1260 
   1261 class JumpTableSDNode : public SDNode {
   1262   int JTI;
   1263   unsigned char TargetFlags;
   1264   friend class SelectionDAG;
   1265   JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
   1266     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
   1267       DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
   1268   }
   1269 public:
   1270 
   1271   int getIndex() const { return JTI; }
   1272   unsigned char getTargetFlags() const { return TargetFlags; }
   1273 
   1274   static bool classof(const JumpTableSDNode *) { return true; }
   1275   static bool classof(const SDNode *N) {
   1276     return N->getOpcode() == ISD::JumpTable ||
   1277            N->getOpcode() == ISD::TargetJumpTable;
   1278   }
   1279 };
   1280 
   1281 class ConstantPoolSDNode : public SDNode {
   1282   union {
   1283     const Constant *ConstVal;
   1284     MachineConstantPoolValue *MachineCPVal;
   1285   } Val;
   1286   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
   1287   unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
   1288   unsigned char TargetFlags;
   1289   friend class SelectionDAG;
   1290   ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
   1291                      unsigned Align, unsigned char TF)
   1292     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
   1293              DebugLoc(),
   1294              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
   1295     assert((int)Offset >= 0 && "Offset is too large");
   1296     Val.ConstVal = c;
   1297   }
   1298   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
   1299                      EVT VT, int o, unsigned Align, unsigned char TF)
   1300     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
   1301              DebugLoc(),
   1302              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
   1303     assert((int)Offset >= 0 && "Offset is too large");
   1304     Val.MachineCPVal = v;
   1305     Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
   1306   }
   1307 public:
   1308 
   1309 
   1310   bool isMachineConstantPoolEntry() const {
   1311     return (int)Offset < 0;
   1312   }
   1313 
   1314   const Constant *getConstVal() const {
   1315     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
   1316     return Val.ConstVal;
   1317   }
   1318 
   1319   MachineConstantPoolValue *getMachineCPVal() const {
   1320     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
   1321     return Val.MachineCPVal;
   1322   }
   1323 
   1324   int getOffset() const {
   1325     return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
   1326   }
   1327 
   1328   // Return the alignment of this constant pool object, which is either 0 (for
   1329   // default alignment) or the desired value.
   1330   unsigned getAlignment() const { return Alignment; }
   1331   unsigned char getTargetFlags() const { return TargetFlags; }
   1332 
   1333   Type *getType() const;
   1334 
   1335   static bool classof(const ConstantPoolSDNode *) { return true; }
   1336   static bool classof(const SDNode *N) {
   1337     return N->getOpcode() == ISD::ConstantPool ||
   1338            N->getOpcode() == ISD::TargetConstantPool;
   1339   }
   1340 };
   1341 
   1342 class BasicBlockSDNode : public SDNode {
   1343   MachineBasicBlock *MBB;
   1344   friend class SelectionDAG;
   1345   /// Debug info is meaningful and potentially useful here, but we create
   1346   /// blocks out of order when they're jumped to, which makes it a bit
   1347   /// harder.  Let's see if we need it first.
   1348   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
   1349     : SDNode(ISD::BasicBlock, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb) {
   1350   }
   1351 public:
   1352 
   1353   MachineBasicBlock *getBasicBlock() const { return MBB; }
   1354 
   1355   static bool classof(const BasicBlockSDNode *) { return true; }
   1356   static bool classof(const SDNode *N) {
   1357     return N->getOpcode() == ISD::BasicBlock;
   1358   }
   1359 };
   1360 
   1361 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
   1362 /// BUILD_VECTORs.
   1363 class BuildVectorSDNode : public SDNode {
   1364   // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
   1365   explicit BuildVectorSDNode();        // Do not implement
   1366 public:
   1367   /// isConstantSplat - Check if this is a constant splat, and if so, find the
   1368   /// smallest element size that splats the vector.  If MinSplatBits is
   1369   /// nonzero, the element size must be at least that large.  Note that the
   1370   /// splat element may be the entire vector (i.e., a one element vector).
   1371   /// Returns the splat element value in SplatValue.  Any undefined bits in
   1372   /// that value are zero, and the corresponding bits in the SplatUndef mask
   1373   /// are set.  The SplatBitSize value is set to the splat element size in
   1374   /// bits.  HasAnyUndefs is set to true if any bits in the vector are
   1375   /// undefined.  isBigEndian describes the endianness of the target.
   1376   bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
   1377                        unsigned &SplatBitSize, bool &HasAnyUndefs,
   1378                        unsigned MinSplatBits = 0, bool isBigEndian = false);
   1379 
   1380   static inline bool classof(const BuildVectorSDNode *) { return true; }
   1381   static inline bool classof(const SDNode *N) {
   1382     return N->getOpcode() == ISD::BUILD_VECTOR;
   1383   }
   1384 };
   1385 
   1386 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
   1387 /// used when the SelectionDAG needs to make a simple reference to something
   1388 /// in the LLVM IR representation.
   1389 ///
   1390 class SrcValueSDNode : public SDNode {
   1391   const Value *V;
   1392   friend class SelectionDAG;
   1393   /// Create a SrcValue for a general value.
   1394   explicit SrcValueSDNode(const Value *v)
   1395     : SDNode(ISD::SRCVALUE, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
   1396 
   1397 public:
   1398   /// getValue - return the contained Value.
   1399   const Value *getValue() const { return V; }
   1400 
   1401   static bool classof(const SrcValueSDNode *) { return true; }
   1402   static bool classof(const SDNode *N) {
   1403     return N->getOpcode() == ISD::SRCVALUE;
   1404   }
   1405 };
   1406 
   1407 class MDNodeSDNode : public SDNode {
   1408   const MDNode *MD;
   1409   friend class SelectionDAG;
   1410   explicit MDNodeSDNode(const MDNode *md)
   1411   : SDNode(ISD::MDNODE_SDNODE, DebugLoc(), getSDVTList(MVT::Other)), MD(md) {}
   1412 public:
   1413 
   1414   const MDNode *getMD() const { return MD; }
   1415 
   1416   static bool classof(const MDNodeSDNode *) { return true; }
   1417   static bool classof(const SDNode *N) {
   1418     return N->getOpcode() == ISD::MDNODE_SDNODE;
   1419   }
   1420 };
   1421 
   1422 
   1423 class RegisterSDNode : public SDNode {
   1424   unsigned Reg;
   1425   friend class SelectionDAG;
   1426   RegisterSDNode(unsigned reg, EVT VT)
   1427     : SDNode(ISD::Register, DebugLoc(), getSDVTList(VT)), Reg(reg) {
   1428   }
   1429 public:
   1430 
   1431   unsigned getReg() const { return Reg; }
   1432 
   1433   static bool classof(const RegisterSDNode *) { return true; }
   1434   static bool classof(const SDNode *N) {
   1435     return N->getOpcode() == ISD::Register;
   1436   }
   1437 };
   1438 
   1439 class RegisterMaskSDNode : public SDNode {
   1440   // The memory for RegMask is not owned by the node.
   1441   const uint32_t *RegMask;
   1442   friend class SelectionDAG;
   1443   RegisterMaskSDNode(const uint32_t *mask)
   1444     : SDNode(ISD::RegisterMask, DebugLoc(), getSDVTList(MVT::Untyped)),
   1445       RegMask(mask) {}
   1446 public:
   1447 
   1448   const uint32_t *getRegMask() const { return RegMask; }
   1449 
   1450   static bool classof(const RegisterMaskSDNode *) { return true; }
   1451   static bool classof(const SDNode *N) {
   1452     return N->getOpcode() == ISD::RegisterMask;
   1453   }
   1454 };
   1455 
   1456 class BlockAddressSDNode : public SDNode {
   1457   const BlockAddress *BA;
   1458   unsigned char TargetFlags;
   1459   friend class SelectionDAG;
   1460   BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
   1461                      unsigned char Flags)
   1462     : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
   1463              BA(ba), TargetFlags(Flags) {
   1464   }
   1465 public:
   1466   const BlockAddress *getBlockAddress() const { return BA; }
   1467   unsigned char getTargetFlags() const { return TargetFlags; }
   1468 
   1469   static bool classof(const BlockAddressSDNode *) { return true; }
   1470   static bool classof(const SDNode *N) {
   1471     return N->getOpcode() == ISD::BlockAddress ||
   1472            N->getOpcode() == ISD::TargetBlockAddress;
   1473   }
   1474 };
   1475 
   1476 class EHLabelSDNode : public SDNode {
   1477   SDUse Chain;
   1478   MCSymbol *Label;
   1479   friend class SelectionDAG;
   1480   EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
   1481     : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
   1482     InitOperands(&Chain, ch);
   1483   }
   1484 public:
   1485   MCSymbol *getLabel() const { return Label; }
   1486 
   1487   static bool classof(const EHLabelSDNode *) { return true; }
   1488   static bool classof(const SDNode *N) {
   1489     return N->getOpcode() == ISD::EH_LABEL;
   1490   }
   1491 };
   1492 
   1493 class ExternalSymbolSDNode : public SDNode {
   1494   const char *Symbol;
   1495   unsigned char TargetFlags;
   1496 
   1497   friend class SelectionDAG;
   1498   ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
   1499     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
   1500              DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
   1501   }
   1502 public:
   1503 
   1504   const char *getSymbol() const { return Symbol; }
   1505   unsigned char getTargetFlags() const { return TargetFlags; }
   1506 
   1507   static bool classof(const ExternalSymbolSDNode *) { return true; }
   1508   static bool classof(const SDNode *N) {
   1509     return N->getOpcode() == ISD::ExternalSymbol ||
   1510            N->getOpcode() == ISD::TargetExternalSymbol;
   1511   }
   1512 };
   1513 
   1514 class CondCodeSDNode : public SDNode {
   1515   ISD::CondCode Condition;
   1516   friend class SelectionDAG;
   1517   explicit CondCodeSDNode(ISD::CondCode Cond)
   1518     : SDNode(ISD::CONDCODE, DebugLoc(), getSDVTList(MVT::Other)),
   1519       Condition(Cond) {
   1520   }
   1521 public:
   1522 
   1523   ISD::CondCode get() const { return Condition; }
   1524 
   1525   static bool classof(const CondCodeSDNode *) { return true; }
   1526   static bool classof(const SDNode *N) {
   1527     return N->getOpcode() == ISD::CONDCODE;
   1528   }
   1529 };
   1530 
   1531 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
   1532 /// future and most targets don't support it.
   1533 class CvtRndSatSDNode : public SDNode {
   1534   ISD::CvtCode CvtCode;
   1535   friend class SelectionDAG;
   1536   explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
   1537                            unsigned NumOps, ISD::CvtCode Code)
   1538     : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
   1539       CvtCode(Code) {
   1540     assert(NumOps == 5 && "wrong number of operations");
   1541   }
   1542 public:
   1543   ISD::CvtCode getCvtCode() const { return CvtCode; }
   1544 
   1545   static bool classof(const CvtRndSatSDNode *) { return true; }
   1546   static bool classof(const SDNode *N) {
   1547     return N->getOpcode() == ISD::CONVERT_RNDSAT;
   1548   }
   1549 };
   1550 
   1551 /// VTSDNode - This class is used to represent EVT's, which are used
   1552 /// to parameterize some operations.
   1553 class VTSDNode : public SDNode {
   1554   EVT ValueType;
   1555   friend class SelectionDAG;
   1556   explicit VTSDNode(EVT VT)
   1557     : SDNode(ISD::VALUETYPE, DebugLoc(), getSDVTList(MVT::Other)),
   1558       ValueType(VT) {
   1559   }
   1560 public:
   1561 
   1562   EVT getVT() const { return ValueType; }
   1563 
   1564   static bool classof(const VTSDNode *) { return true; }
   1565   static bool classof(const SDNode *N) {
   1566     return N->getOpcode() == ISD::VALUETYPE;
   1567   }
   1568 };
   1569 
   1570 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
   1571 ///
   1572 class LSBaseSDNode : public MemSDNode {
   1573   //! Operand array for load and store
   1574   /*!
   1575     \note Moving this array to the base class captures more
   1576     common functionality shared between LoadSDNode and
   1577     StoreSDNode
   1578    */
   1579   SDUse Ops[4];
   1580 public:
   1581   LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
   1582                unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
   1583                EVT MemVT, MachineMemOperand *MMO)
   1584     : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
   1585     SubclassData |= AM << 2;
   1586     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
   1587     InitOperands(Ops, Operands, numOperands);
   1588     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
   1589            "Only indexed loads and stores have a non-undef offset operand");
   1590   }
   1591 
   1592   const SDValue &getOffset() const {
   1593     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
   1594   }
   1595 
   1596   /// getAddressingMode - Return the addressing mode for this load or store:
   1597   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
   1598   ISD::MemIndexedMode getAddressingMode() const {
   1599     return ISD::MemIndexedMode((SubclassData >> 2) & 7);
   1600   }
   1601 
   1602   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
   1603   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
   1604 
   1605   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
   1606   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
   1607 
   1608   static bool classof(const LSBaseSDNode *) { return true; }
   1609   static bool classof(const SDNode *N) {
   1610     return N->getOpcode() == ISD::LOAD ||
   1611            N->getOpcode() == ISD::STORE;
   1612   }
   1613 };
   1614 
   1615 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
   1616 ///
   1617 class LoadSDNode : public LSBaseSDNode {
   1618   friend class SelectionDAG;
   1619   LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
   1620              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
   1621              MachineMemOperand *MMO)
   1622     : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
   1623                    VTs, AM, MemVT, MMO) {
   1624     SubclassData |= (unsigned short)ETy;
   1625     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
   1626     assert(readMem() && "Load MachineMemOperand is not a load!");
   1627     assert(!writeMem() && "Load MachineMemOperand is a store!");
   1628   }
   1629 public:
   1630 
   1631   /// getExtensionType - Return whether this is a plain node,
   1632   /// or one of the varieties of value-extending loads.
   1633   ISD::LoadExtType getExtensionType() const {
   1634     return ISD::LoadExtType(SubclassData & 3);
   1635   }
   1636 
   1637   const SDValue &getBasePtr() const { return getOperand(1); }
   1638   const SDValue &getOffset() const { return getOperand(2); }
   1639 
   1640   static bool classof(const LoadSDNode *) { return true; }
   1641   static bool classof(const SDNode *N) {
   1642     return N->getOpcode() == ISD::LOAD;
   1643   }
   1644 };
   1645 
   1646 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
   1647 ///
   1648 class StoreSDNode : public LSBaseSDNode {
   1649   friend class SelectionDAG;
   1650   StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
   1651               ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
   1652               MachineMemOperand *MMO)
   1653     : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
   1654                    VTs, AM, MemVT, MMO) {
   1655     SubclassData |= (unsigned short)isTrunc;
   1656     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
   1657     assert(!readMem() && "Store MachineMemOperand is a load!");
   1658     assert(writeMem() && "Store MachineMemOperand is not a store!");
   1659   }
   1660 public:
   1661 
   1662   /// isTruncatingStore - Return true if the op does a truncation before store.
   1663   /// For integers this is the same as doing a TRUNCATE and storing the result.
   1664   /// For floats, it is the same as doing an FP_ROUND and storing the result.
   1665   bool isTruncatingStore() const { return SubclassData & 1; }
   1666 
   1667   const SDValue &getValue() const { return getOperand(1); }
   1668   const SDValue &getBasePtr() const { return getOperand(2); }
   1669   const SDValue &getOffset() const { return getOperand(3); }
   1670 
   1671   static bool classof(const StoreSDNode *) { return true; }
   1672   static bool classof(const SDNode *N) {
   1673     return N->getOpcode() == ISD::STORE;
   1674   }
   1675 };
   1676 
   1677 /// MachineSDNode - An SDNode that represents everything that will be needed
   1678 /// to construct a MachineInstr. These nodes are created during the
   1679 /// instruction selection proper phase.
   1680 ///
   1681 class MachineSDNode : public SDNode {
   1682 public:
   1683   typedef MachineMemOperand **mmo_iterator;
   1684 
   1685 private:
   1686   friend class SelectionDAG;
   1687   MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
   1688     : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
   1689 
   1690   /// LocalOperands - Operands for this instruction, if they fit here. If
   1691   /// they don't, this field is unused.
   1692   SDUse LocalOperands[4];
   1693 
   1694   /// MemRefs - Memory reference descriptions for this instruction.
   1695   mmo_iterator MemRefs;
   1696   mmo_iterator MemRefsEnd;
   1697 
   1698 public:
   1699   mmo_iterator memoperands_begin() const { return MemRefs; }
   1700   mmo_iterator memoperands_end() const { return MemRefsEnd; }
   1701   bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
   1702 
   1703   /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
   1704   /// list. This does not transfer ownership.
   1705   void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
   1706     for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
   1707       assert(*MMI && "Null mem ref detected!");
   1708     MemRefs = NewMemRefs;
   1709     MemRefsEnd = NewMemRefsEnd;
   1710   }
   1711 
   1712   static bool classof(const MachineSDNode *) { return true; }
   1713   static bool classof(const SDNode *N) {
   1714     return N->isMachineOpcode();
   1715   }
   1716 };
   1717 
   1718 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
   1719                                             SDNode, ptrdiff_t> {
   1720   SDNode *Node;
   1721   unsigned Operand;
   1722 
   1723   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
   1724 public:
   1725   bool operator==(const SDNodeIterator& x) const {
   1726     return Operand == x.Operand;
   1727   }
   1728   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
   1729 
   1730   const SDNodeIterator &operator=(const SDNodeIterator &I) {
   1731     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
   1732     Operand = I.Operand;
   1733     return *this;
   1734   }
   1735 
   1736   pointer operator*() const {
   1737     return Node->getOperand(Operand).getNode();
   1738   }
   1739   pointer operator->() const { return operator*(); }
   1740 
   1741   SDNodeIterator& operator++() {                // Preincrement
   1742     ++Operand;
   1743     return *this;
   1744   }
   1745   SDNodeIterator operator++(int) { // Postincrement
   1746     SDNodeIterator tmp = *this; ++*this; return tmp;
   1747   }
   1748   size_t operator-(SDNodeIterator Other) const {
   1749     assert(Node == Other.Node &&
   1750            "Cannot compare iterators of two different nodes!");
   1751     return Operand - Other.Operand;
   1752   }
   1753 
   1754   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
   1755   static SDNodeIterator end  (SDNode *N) {
   1756     return SDNodeIterator(N, N->getNumOperands());
   1757   }
   1758 
   1759   unsigned getOperand() const { return Operand; }
   1760   const SDNode *getNode() const { return Node; }
   1761 };
   1762 
   1763 template <> struct GraphTraits<SDNode*> {
   1764   typedef SDNode NodeType;
   1765   typedef SDNodeIterator ChildIteratorType;
   1766   static inline NodeType *getEntryNode(SDNode *N) { return N; }
   1767   static inline ChildIteratorType child_begin(NodeType *N) {
   1768     return SDNodeIterator::begin(N);
   1769   }
   1770   static inline ChildIteratorType child_end(NodeType *N) {
   1771     return SDNodeIterator::end(N);
   1772   }
   1773 };
   1774 
   1775 /// LargestSDNode - The largest SDNode class.
   1776 ///
   1777 typedef LoadSDNode LargestSDNode;
   1778 
   1779 /// MostAlignedSDNode - The SDNode class with the greatest alignment
   1780 /// requirement.
   1781 ///
   1782 typedef GlobalAddressSDNode MostAlignedSDNode;
   1783 
   1784 namespace ISD {
   1785   /// isNormalLoad - Returns true if the specified node is a non-extending
   1786   /// and unindexed load.
   1787   inline bool isNormalLoad(const SDNode *N) {
   1788     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
   1789     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
   1790       Ld->getAddressingMode() == ISD::UNINDEXED;
   1791   }
   1792 
   1793   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
   1794   /// load.
   1795   inline bool isNON_EXTLoad(const SDNode *N) {
   1796     return isa<LoadSDNode>(N) &&
   1797       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
   1798   }
   1799 
   1800   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
   1801   ///
   1802   inline bool isEXTLoad(const SDNode *N) {
   1803     return isa<LoadSDNode>(N) &&
   1804       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
   1805   }
   1806 
   1807   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
   1808   ///
   1809   inline bool isSEXTLoad(const SDNode *N) {
   1810     return isa<LoadSDNode>(N) &&
   1811       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
   1812   }
   1813 
   1814   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
   1815   ///
   1816   inline bool isZEXTLoad(const SDNode *N) {
   1817     return isa<LoadSDNode>(N) &&
   1818       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
   1819   }
   1820 
   1821   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
   1822   ///
   1823   inline bool isUNINDEXEDLoad(const SDNode *N) {
   1824     return isa<LoadSDNode>(N) &&
   1825       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
   1826   }
   1827 
   1828   /// isNormalStore - Returns true if the specified node is a non-truncating
   1829   /// and unindexed store.
   1830   inline bool isNormalStore(const SDNode *N) {
   1831     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
   1832     return St && !St->isTruncatingStore() &&
   1833       St->getAddressingMode() == ISD::UNINDEXED;
   1834   }
   1835 
   1836   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
   1837   /// store.
   1838   inline bool isNON_TRUNCStore(const SDNode *N) {
   1839     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
   1840   }
   1841 
   1842   /// isTRUNCStore - Returns true if the specified node is a truncating
   1843   /// store.
   1844   inline bool isTRUNCStore(const SDNode *N) {
   1845     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
   1846   }
   1847 
   1848   /// isUNINDEXEDStore - Returns true if the specified node is an
   1849   /// unindexed store.
   1850   inline bool isUNINDEXEDStore(const SDNode *N) {
   1851     return isa<StoreSDNode>(N) &&
   1852       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
   1853   }
   1854 }
   1855 
   1856 } // end llvm namespace
   1857 
   1858 #endif
   1859