LLVM API Documentation

SelectionDAGNodes.h
Go to the documentation of this file.
00001 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 //
00010 // This file declares the SDNode class and derived classes, which are used to
00011 // represent the nodes and operations present in a SelectionDAG.  These nodes
00012 // and operations are machine code level operations, with some similarities to
00013 // the GCC RTL representation.
00014 //
00015 // Clients should include the SelectionDAG.h file instead of this file directly.
00016 //
00017 //===----------------------------------------------------------------------===//
00018 
00019 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
00020 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
00021 
00022 #include "llvm/ADT/iterator_range.h"
00023 #include "llvm/ADT/BitVector.h"
00024 #include "llvm/ADT/FoldingSet.h"
00025 #include "llvm/ADT/GraphTraits.h"
00026 #include "llvm/ADT/STLExtras.h"
00027 #include "llvm/ADT/SmallPtrSet.h"
00028 #include "llvm/ADT/SmallVector.h"
00029 #include "llvm/ADT/ilist_node.h"
00030 #include "llvm/CodeGen/ISDOpcodes.h"
00031 #include "llvm/CodeGen/MachineMemOperand.h"
00032 #include "llvm/CodeGen/ValueTypes.h"
00033 #include "llvm/IR/Constants.h"
00034 #include "llvm/IR/DebugLoc.h"
00035 #include "llvm/IR/Instructions.h"
00036 #include "llvm/Support/DataTypes.h"
00037 #include "llvm/Support/MathExtras.h"
00038 #include <cassert>
00039 
00040 namespace llvm {
00041 
00042 class SelectionDAG;
00043 class GlobalValue;
00044 class MachineBasicBlock;
00045 class MachineConstantPoolValue;
00046 class SDNode;
00047 class Value;
00048 class MCSymbol;
00049 template <typename T> struct DenseMapInfo;
00050 template <typename T> struct simplify_type;
00051 template <typename T> struct ilist_traits;
00052 
00053 /// isBinOpWithFlags - Returns true if the opcode is a binary operation
00054 /// with flags.
00055 static bool isBinOpWithFlags(unsigned Opcode) {
00056   switch (Opcode) {
00057   case ISD::SDIV:
00058   case ISD::UDIV:
00059   case ISD::SRA:
00060   case ISD::SRL:
00061   case ISD::MUL:
00062   case ISD::ADD:
00063   case ISD::SUB:
00064   case ISD::SHL:
00065     return true;
00066   default:
00067     return false;
00068   }
00069 }
00070 
00071 void checkForCycles(const SDNode *N, const SelectionDAG *DAG = nullptr,
00072                     bool force = false);
00073 
00074 /// SDVTList - This represents a list of ValueType's that has been intern'd by
00075 /// a SelectionDAG.  Instances of this simple value class are returned by
00076 /// SelectionDAG::getVTList(...).
00077 ///
00078 struct SDVTList {
00079   const EVT *VTs;
00080   unsigned int NumVTs;
00081 };
00082 
00083 namespace ISD {
00084   /// Node predicates
00085 
00086   /// isBuildVectorAllOnes - Return true if the specified node is a
00087   /// BUILD_VECTOR where all of the elements are ~0 or undef.
00088   bool isBuildVectorAllOnes(const SDNode *N);
00089 
00090   /// isBuildVectorAllZeros - Return true if the specified node is a
00091   /// BUILD_VECTOR where all of the elements are 0 or undef.
00092   bool isBuildVectorAllZeros(const SDNode *N);
00093 
00094   /// \brief Return true if the specified node is a BUILD_VECTOR node of
00095   /// all ConstantSDNode or undef.
00096   bool isBuildVectorOfConstantSDNodes(const SDNode *N);
00097 
00098   /// isScalarToVector - Return true if the specified node is a
00099   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
00100   /// element is not an undef.
00101   bool isScalarToVector(const SDNode *N);
00102 
00103   /// allOperandsUndef - Return true if the node has at least one operand
00104   /// and all operands of the specified node are ISD::UNDEF.
00105   bool allOperandsUndef(const SDNode *N);
00106 }  // end llvm:ISD namespace
00107 
00108 //===----------------------------------------------------------------------===//
00109 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
00110 /// values as the result of a computation.  Many nodes return multiple values,
00111 /// from loads (which define a token and a return value) to ADDC (which returns
00112 /// a result and a carry value), to calls (which may return an arbitrary number
00113 /// of values).
00114 ///
00115 /// As such, each use of a SelectionDAG computation must indicate the node that
00116 /// computes it as well as which return value to use from that node.  This pair
00117 /// of information is represented with the SDValue value type.
00118 ///
00119 class SDValue {
00120   SDNode *Node;       // The node defining the value we are using.
00121   unsigned ResNo;     // Which return value of the node we are using.
00122 public:
00123   SDValue() : Node(nullptr), ResNo(0) {}
00124   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
00125 
00126   /// get the index which selects a specific result in the SDNode
00127   unsigned getResNo() const { return ResNo; }
00128 
00129   /// get the SDNode which holds the desired result
00130   SDNode *getNode() const { return Node; }
00131 
00132   /// set the SDNode
00133   void setNode(SDNode *N) { Node = N; }
00134 
00135   inline SDNode *operator->() const { return Node; }
00136 
00137   bool operator==(const SDValue &O) const {
00138     return Node == O.Node && ResNo == O.ResNo;
00139   }
00140   bool operator!=(const SDValue &O) const {
00141     return !operator==(O);
00142   }
00143   bool operator<(const SDValue &O) const {
00144     return std::tie(Node, ResNo) < std::tie(O.Node, O.ResNo);
00145   }
00146   LLVM_EXPLICIT operator bool() const {
00147     return Node != nullptr;
00148   }
00149 
00150   SDValue getValue(unsigned R) const {
00151     return SDValue(Node, R);
00152   }
00153 
00154   // isOperandOf - Return true if this node is an operand of N.
00155   bool isOperandOf(SDNode *N) const;
00156 
00157   /// getValueType - Return the ValueType of the referenced return value.
00158   ///
00159   inline EVT getValueType() const;
00160 
00161   /// Return the simple ValueType of the referenced return value.
00162   MVT getSimpleValueType() const {
00163     return getValueType().getSimpleVT();
00164   }
00165 
00166   /// getValueSizeInBits - Returns the size of the value in bits.
00167   ///
00168   unsigned getValueSizeInBits() const {
00169     return getValueType().getSizeInBits();
00170   }
00171 
00172   unsigned getScalarValueSizeInBits() const {
00173     return getValueType().getScalarType().getSizeInBits();
00174   }
00175 
00176   // Forwarding methods - These forward to the corresponding methods in SDNode.
00177   inline unsigned getOpcode() const;
00178   inline unsigned getNumOperands() const;
00179   inline const SDValue &getOperand(unsigned i) const;
00180   inline uint64_t getConstantOperandVal(unsigned i) const;
00181   inline bool isTargetMemoryOpcode() const;
00182   inline bool isTargetOpcode() const;
00183   inline bool isMachineOpcode() const;
00184   inline unsigned getMachineOpcode() const;
00185   inline const DebugLoc getDebugLoc() const;
00186   inline void dump() const;
00187   inline void dumpr() const;
00188 
00189   /// reachesChainWithoutSideEffects - Return true if this operand (which must
00190   /// be a chain) reaches the specified operand without crossing any
00191   /// side-effecting instructions.  In practice, this looks through token
00192   /// factors and non-volatile loads.  In order to remain efficient, this only
00193   /// looks a couple of nodes in, it does not do an exhaustive search.
00194   bool reachesChainWithoutSideEffects(SDValue Dest,
00195                                       unsigned Depth = 2) const;
00196 
00197   /// use_empty - Return true if there are no nodes using value ResNo
00198   /// of Node.
00199   ///
00200   inline bool use_empty() const;
00201 
00202   /// hasOneUse - Return true if there is exactly one node using value
00203   /// ResNo of Node.
00204   ///
00205   inline bool hasOneUse() const;
00206 };
00207 
00208 
00209 template<> struct DenseMapInfo<SDValue> {
00210   static inline SDValue getEmptyKey() {
00211     return SDValue((SDNode*)-1, -1U);
00212   }
00213   static inline SDValue getTombstoneKey() {
00214     return SDValue((SDNode*)-1, 0);
00215   }
00216   static unsigned getHashValue(const SDValue &Val) {
00217     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
00218             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
00219   }
00220   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
00221     return LHS == RHS;
00222   }
00223 };
00224 template <> struct isPodLike<SDValue> { static const bool value = true; };
00225 
00226 
00227 /// simplify_type specializations - Allow casting operators to work directly on
00228 /// SDValues as if they were SDNode*'s.
00229 template<> struct simplify_type<SDValue> {
00230   typedef SDNode* SimpleType;
00231   static SimpleType getSimplifiedValue(SDValue &Val) {
00232     return Val.getNode();
00233   }
00234 };
00235 template<> struct simplify_type<const SDValue> {
00236   typedef /*const*/ SDNode* SimpleType;
00237   static SimpleType getSimplifiedValue(const SDValue &Val) {
00238     return Val.getNode();
00239   }
00240 };
00241 
00242 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
00243 /// which records the SDNode being used and the result number, a
00244 /// pointer to the SDNode using the value, and Next and Prev pointers,
00245 /// which link together all the uses of an SDNode.
00246 ///
00247 class SDUse {
00248   /// Val - The value being used.
00249   SDValue Val;
00250   /// User - The user of this value.
00251   SDNode *User;
00252   /// Prev, Next - Pointers to the uses list of the SDNode referred by
00253   /// this operand.
00254   SDUse **Prev, *Next;
00255 
00256   SDUse(const SDUse &U) LLVM_DELETED_FUNCTION;
00257   void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
00258 
00259 public:
00260   SDUse() : Val(), User(nullptr), Prev(nullptr), Next(nullptr) {}
00261 
00262   /// Normally SDUse will just implicitly convert to an SDValue that it holds.
00263   operator const SDValue&() const { return Val; }
00264 
00265   /// If implicit conversion to SDValue doesn't work, the get() method returns
00266   /// the SDValue.
00267   const SDValue &get() const { return Val; }
00268 
00269   /// getUser - This returns the SDNode that contains this Use.
00270   SDNode *getUser() { return User; }
00271 
00272   /// getNext - Get the next SDUse in the use list.
00273   SDUse *getNext() const { return Next; }
00274 
00275   /// getNode - Convenience function for get().getNode().
00276   SDNode *getNode() const { return Val.getNode(); }
00277   /// getResNo - Convenience function for get().getResNo().
00278   unsigned getResNo() const { return Val.getResNo(); }
00279   /// getValueType - Convenience function for get().getValueType().
00280   EVT getValueType() const { return Val.getValueType(); }
00281 
00282   /// operator== - Convenience function for get().operator==
00283   bool operator==(const SDValue &V) const {
00284     return Val == V;
00285   }
00286 
00287   /// operator!= - Convenience function for get().operator!=
00288   bool operator!=(const SDValue &V) const {
00289     return Val != V;
00290   }
00291 
00292   /// operator< - Convenience function for get().operator<
00293   bool operator<(const SDValue &V) const {
00294     return Val < V;
00295   }
00296 
00297 private:
00298   friend class SelectionDAG;
00299   friend class SDNode;
00300 
00301   void setUser(SDNode *p) { User = p; }
00302 
00303   /// set - Remove this use from its existing use list, assign it the
00304   /// given value, and add it to the new value's node's use list.
00305   inline void set(const SDValue &V);
00306   /// setInitial - like set, but only supports initializing a newly-allocated
00307   /// SDUse with a non-null value.
00308   inline void setInitial(const SDValue &V);
00309   /// setNode - like set, but only sets the Node portion of the value,
00310   /// leaving the ResNo portion unmodified.
00311   inline void setNode(SDNode *N);
00312 
00313   void addToList(SDUse **List) {
00314     Next = *List;
00315     if (Next) Next->Prev = &Next;
00316     Prev = List;
00317     *List = this;
00318   }
00319 
00320   void removeFromList() {
00321     *Prev = Next;
00322     if (Next) Next->Prev = Prev;
00323   }
00324 };
00325 
00326 /// simplify_type specializations - Allow casting operators to work directly on
00327 /// SDValues as if they were SDNode*'s.
00328 template<> struct simplify_type<SDUse> {
00329   typedef SDNode* SimpleType;
00330   static SimpleType getSimplifiedValue(SDUse &Val) {
00331     return Val.getNode();
00332   }
00333 };
00334 
00335 
00336 /// SDNode - Represents one node in the SelectionDAG.
00337 ///
00338 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
00339 private:
00340   /// NodeType - The operation that this node performs.
00341   ///
00342   int16_t NodeType;
00343 
00344   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
00345   /// then they will be delete[]'d when the node is destroyed.
00346   uint16_t OperandsNeedDelete : 1;
00347 
00348   /// HasDebugValue - This tracks whether this node has one or more dbg_value
00349   /// nodes corresponding to it.
00350   uint16_t HasDebugValue : 1;
00351 
00352 protected:
00353   /// SubclassData - This member is defined by this class, but is not used for
00354   /// anything.  Subclasses can use it to hold whatever state they find useful.
00355   /// This field is initialized to zero by the ctor.
00356   uint16_t SubclassData : 14;
00357 
00358 private:
00359   /// NodeId - Unique id per SDNode in the DAG.
00360   int NodeId;
00361 
00362   /// OperandList - The values that are used by this operation.
00363   ///
00364   SDUse *OperandList;
00365 
00366   /// ValueList - The types of the values this node defines.  SDNode's may
00367   /// define multiple values simultaneously.
00368   const EVT *ValueList;
00369 
00370   /// UseList - List of uses for this SDNode.
00371   SDUse *UseList;
00372 
00373   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
00374   unsigned short NumOperands, NumValues;
00375 
00376   /// debugLoc - source line information.
00377   DebugLoc debugLoc;
00378 
00379   // The ordering of the SDNodes. It roughly corresponds to the ordering of the
00380   // original LLVM instructions.
00381   // This is used for turning off scheduling, because we'll forgo
00382   // the normal scheduling algorithms and output the instructions according to
00383   // this ordering.
00384   unsigned IROrder;
00385 
00386   /// getValueTypeList - Return a pointer to the specified value type.
00387   static const EVT *getValueTypeList(EVT VT);
00388 
00389   friend class SelectionDAG;
00390   friend struct ilist_traits<SDNode>;
00391 
00392 public:
00393   //===--------------------------------------------------------------------===//
00394   //  Accessors
00395   //
00396 
00397   /// getOpcode - Return the SelectionDAG opcode value for this node. For
00398   /// pre-isel nodes (those for which isMachineOpcode returns false), these
00399   /// are the opcode values in the ISD and <target>ISD namespaces. For
00400   /// post-isel opcodes, see getMachineOpcode.
00401   unsigned getOpcode()  const { return (unsigned short)NodeType; }
00402 
00403   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
00404   /// <target>ISD namespace).
00405   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
00406 
00407   /// isTargetMemoryOpcode - Test if this node has a target-specific
00408   /// memory-referencing opcode (in the <target>ISD namespace and
00409   /// greater than FIRST_TARGET_MEMORY_OPCODE).
00410   bool isTargetMemoryOpcode() const {
00411     return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
00412   }
00413 
00414   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
00415   /// corresponding to a MachineInstr opcode.
00416   bool isMachineOpcode() const { return NodeType < 0; }
00417 
00418   /// getMachineOpcode - This may only be called if isMachineOpcode returns
00419   /// true. It returns the MachineInstr opcode value that the node's opcode
00420   /// corresponds to.
00421   unsigned getMachineOpcode() const {
00422     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
00423     return ~NodeType;
00424   }
00425 
00426   /// getHasDebugValue - get this bit.
00427   bool getHasDebugValue() const { return HasDebugValue; }
00428 
00429   /// setHasDebugValue - set this bit.
00430   void setHasDebugValue(bool b) { HasDebugValue = b; }
00431 
00432   /// use_empty - Return true if there are no uses of this node.
00433   ///
00434   bool use_empty() const { return UseList == nullptr; }
00435 
00436   /// hasOneUse - Return true if there is exactly one use of this node.
00437   ///
00438   bool hasOneUse() const {
00439     return !use_empty() && std::next(use_begin()) == use_end();
00440   }
00441 
00442   /// use_size - Return the number of uses of this node. This method takes
00443   /// time proportional to the number of uses.
00444   ///
00445   size_t use_size() const { return std::distance(use_begin(), use_end()); }
00446 
00447   /// getNodeId - Return the unique node id.
00448   ///
00449   int getNodeId() const { return NodeId; }
00450 
00451   /// setNodeId - Set unique node id.
00452   void setNodeId(int Id) { NodeId = Id; }
00453 
00454   /// getIROrder - Return the node ordering.
00455   ///
00456   unsigned getIROrder() const { return IROrder; }
00457 
00458   /// setIROrder - Set the node ordering.
00459   ///
00460   void setIROrder(unsigned Order) { IROrder = Order; }
00461 
00462   /// getDebugLoc - Return the source location info.
00463   const DebugLoc getDebugLoc() const { return debugLoc; }
00464 
00465   /// setDebugLoc - Set source location info.  Try to avoid this, putting
00466   /// it in the constructor is preferable.
00467   void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
00468 
00469   /// use_iterator - This class provides iterator support for SDUse
00470   /// operands that use a specific SDNode.
00471   class use_iterator
00472     : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
00473     SDUse *Op;
00474     explicit use_iterator(SDUse *op) : Op(op) {
00475     }
00476     friend class SDNode;
00477   public:
00478     typedef std::iterator<std::forward_iterator_tag,
00479                           SDUse, ptrdiff_t>::reference reference;
00480     typedef std::iterator<std::forward_iterator_tag,
00481                           SDUse, ptrdiff_t>::pointer pointer;
00482 
00483     use_iterator(const use_iterator &I) : Op(I.Op) {}
00484     use_iterator() : Op(nullptr) {}
00485 
00486     bool operator==(const use_iterator &x) const {
00487       return Op == x.Op;
00488     }
00489     bool operator!=(const use_iterator &x) const {
00490       return !operator==(x);
00491     }
00492 
00493     /// atEnd - return true if this iterator is at the end of uses list.
00494     bool atEnd() const { return Op == nullptr; }
00495 
00496     // Iterator traversal: forward iteration only.
00497     use_iterator &operator++() {          // Preincrement
00498       assert(Op && "Cannot increment end iterator!");
00499       Op = Op->getNext();
00500       return *this;
00501     }
00502 
00503     use_iterator operator++(int) {        // Postincrement
00504       use_iterator tmp = *this; ++*this; return tmp;
00505     }
00506 
00507     /// Retrieve a pointer to the current user node.
00508     SDNode *operator*() const {
00509       assert(Op && "Cannot dereference end iterator!");
00510       return Op->getUser();
00511     }
00512 
00513     SDNode *operator->() const { return operator*(); }
00514 
00515     SDUse &getUse() const { return *Op; }
00516 
00517     /// getOperandNo - Retrieve the operand # of this use in its user.
00518     ///
00519     unsigned getOperandNo() const {
00520       assert(Op && "Cannot dereference end iterator!");
00521       return (unsigned)(Op - Op->getUser()->OperandList);
00522     }
00523   };
00524 
00525   /// use_begin/use_end - Provide iteration support to walk over all uses
00526   /// of an SDNode.
00527 
00528   use_iterator use_begin() const {
00529     return use_iterator(UseList);
00530   }
00531 
00532   static use_iterator use_end() { return use_iterator(nullptr); }
00533 
00534   inline iterator_range<use_iterator> uses() {
00535     return iterator_range<use_iterator>(use_begin(), use_end());
00536   }
00537   inline iterator_range<use_iterator> uses() const {
00538     return iterator_range<use_iterator>(use_begin(), use_end());
00539   }
00540 
00541   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
00542   /// indicated value.  This method ignores uses of other values defined by this
00543   /// operation.
00544   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
00545 
00546   /// hasAnyUseOfValue - Return true if there are any use of the indicated
00547   /// value. This method ignores uses of other values defined by this operation.
00548   bool hasAnyUseOfValue(unsigned Value) const;
00549 
00550   /// isOnlyUserOf - Return true if this node is the only use of N.
00551   ///
00552   bool isOnlyUserOf(SDNode *N) const;
00553 
00554   /// isOperandOf - Return true if this node is an operand of N.
00555   ///
00556   bool isOperandOf(SDNode *N) const;
00557 
00558   /// isPredecessorOf - Return true if this node is a predecessor of N.
00559   /// NOTE: Implemented on top of hasPredecessor and every bit as
00560   /// expensive. Use carefully.
00561   bool isPredecessorOf(const SDNode *N) const {
00562     return N->hasPredecessor(this);
00563   }
00564 
00565   /// hasPredecessor - Return true if N is a predecessor of this node.
00566   /// N is either an operand of this node, or can be reached by recursively
00567   /// traversing up the operands.
00568   /// NOTE: This is an expensive method. Use it carefully.
00569   bool hasPredecessor(const SDNode *N) const;
00570 
00571   /// hasPredecesorHelper - Return true if N is a predecessor of this node.
00572   /// N is either an operand of this node, or can be reached by recursively
00573   /// traversing up the operands.
00574   /// In this helper the Visited and worklist sets are held externally to
00575   /// cache predecessors over multiple invocations. If you want to test for
00576   /// multiple predecessors this method is preferable to multiple calls to
00577   /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
00578   /// changes.
00579   /// NOTE: This is still very expensive. Use carefully.
00580   bool hasPredecessorHelper(const SDNode *N,
00581                             SmallPtrSet<const SDNode *, 32> &Visited,
00582                             SmallVectorImpl<const SDNode *> &Worklist) const;
00583 
00584   /// getNumOperands - Return the number of values used by this operation.
00585   ///
00586   unsigned getNumOperands() const { return NumOperands; }
00587 
00588   /// getConstantOperandVal - Helper method returns the integer value of a
00589   /// ConstantSDNode operand.
00590   uint64_t getConstantOperandVal(unsigned Num) const;
00591 
00592   const SDValue &getOperand(unsigned Num) const {
00593     assert(Num < NumOperands && "Invalid child # of SDNode!");
00594     return OperandList[Num];
00595   }
00596 
00597   typedef SDUse* op_iterator;
00598   op_iterator op_begin() const { return OperandList; }
00599   op_iterator op_end() const { return OperandList+NumOperands; }
00600   ArrayRef<SDUse> ops() const { return makeArrayRef(op_begin(), op_end()); }
00601 
00602   SDVTList getVTList() const {
00603     SDVTList X = { ValueList, NumValues };
00604     return X;
00605   }
00606 
00607   /// getGluedNode - If this node has a glue operand, return the node
00608   /// to which the glue operand points. Otherwise return NULL.
00609   SDNode *getGluedNode() const {
00610     if (getNumOperands() != 0 &&
00611       getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
00612       return getOperand(getNumOperands()-1).getNode();
00613     return nullptr;
00614   }
00615 
00616   // If this is a pseudo op, like copyfromreg, look to see if there is a
00617   // real target node glued to it.  If so, return the target node.
00618   const SDNode *getGluedMachineNode() const {
00619     const SDNode *FoundNode = this;
00620 
00621     // Climb up glue edges until a machine-opcode node is found, or the
00622     // end of the chain is reached.
00623     while (!FoundNode->isMachineOpcode()) {
00624       const SDNode *N = FoundNode->getGluedNode();
00625       if (!N) break;
00626       FoundNode = N;
00627     }
00628 
00629     return FoundNode;
00630   }
00631 
00632   /// getGluedUser - If this node has a glue value with a user, return
00633   /// the user (there is at most one). Otherwise return NULL.
00634   SDNode *getGluedUser() const {
00635     for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
00636       if (UI.getUse().get().getValueType() == MVT::Glue)
00637         return *UI;
00638     return nullptr;
00639   }
00640 
00641   /// getNumValues - Return the number of values defined/returned by this
00642   /// operator.
00643   ///
00644   unsigned getNumValues() const { return NumValues; }
00645 
00646   /// getValueType - Return the type of a specified result.
00647   ///
00648   EVT getValueType(unsigned ResNo) const {
00649     assert(ResNo < NumValues && "Illegal result number!");
00650     return ValueList[ResNo];
00651   }
00652 
00653   /// Return the type of a specified result as a simple type.
00654   ///
00655   MVT getSimpleValueType(unsigned ResNo) const {
00656     return getValueType(ResNo).getSimpleVT();
00657   }
00658 
00659   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
00660   ///
00661   unsigned getValueSizeInBits(unsigned ResNo) const {
00662     return getValueType(ResNo).getSizeInBits();
00663   }
00664 
00665   typedef const EVT* value_iterator;
00666   value_iterator value_begin() const { return ValueList; }
00667   value_iterator value_end() const { return ValueList+NumValues; }
00668 
00669   /// getOperationName - Return the opcode of this operation for printing.
00670   ///
00671   std::string getOperationName(const SelectionDAG *G = nullptr) const;
00672   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
00673   void print_types(raw_ostream &OS, const SelectionDAG *G) const;
00674   void print_details(raw_ostream &OS, const SelectionDAG *G) const;
00675   void print(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
00676   void printr(raw_ostream &OS, const SelectionDAG *G = nullptr) const;
00677 
00678   /// printrFull - Print a SelectionDAG node and all children down to
00679   /// the leaves.  The given SelectionDAG allows target-specific nodes
00680   /// to be printed in human-readable form.  Unlike printr, this will
00681   /// print the whole DAG, including children that appear multiple
00682   /// times.
00683   ///
00684   void printrFull(raw_ostream &O, const SelectionDAG *G = nullptr) const;
00685 
00686   /// printrWithDepth - Print a SelectionDAG node and children up to
00687   /// depth "depth."  The given SelectionDAG allows target-specific
00688   /// nodes to be printed in human-readable form.  Unlike printr, this
00689   /// will print children that appear multiple times wherever they are
00690   /// used.
00691   ///
00692   void printrWithDepth(raw_ostream &O, const SelectionDAG *G = nullptr,
00693                        unsigned depth = 100) const;
00694 
00695 
00696   /// dump - Dump this node, for debugging.
00697   void dump() const;
00698 
00699   /// dumpr - Dump (recursively) this node and its use-def subgraph.
00700   void dumpr() const;
00701 
00702   /// dump - Dump this node, for debugging.
00703   /// The given SelectionDAG allows target-specific nodes to be printed
00704   /// in human-readable form.
00705   void dump(const SelectionDAG *G) const;
00706 
00707   /// dumpr - Dump (recursively) this node and its use-def subgraph.
00708   /// The given SelectionDAG allows target-specific nodes to be printed
00709   /// in human-readable form.
00710   void dumpr(const SelectionDAG *G) const;
00711 
00712   /// dumprFull - printrFull to dbgs().  The given SelectionDAG allows
00713   /// target-specific nodes to be printed in human-readable form.
00714   /// Unlike dumpr, this will print the whole DAG, including children
00715   /// that appear multiple times.
00716   ///
00717   void dumprFull(const SelectionDAG *G = nullptr) const;
00718 
00719   /// dumprWithDepth - printrWithDepth to dbgs().  The given
00720   /// SelectionDAG allows target-specific nodes to be printed in
00721   /// human-readable form.  Unlike dumpr, this will print children
00722   /// that appear multiple times wherever they are used.
00723   ///
00724   void dumprWithDepth(const SelectionDAG *G = nullptr,
00725                       unsigned depth = 100) const;
00726 
00727   /// Profile - Gather unique data for the node.
00728   ///
00729   void Profile(FoldingSetNodeID &ID) const;
00730 
00731   /// addUse - This method should only be used by the SDUse class.
00732   ///
00733   void addUse(SDUse &U) { U.addToList(&UseList); }
00734 
00735 protected:
00736   static SDVTList getSDVTList(EVT VT) {
00737     SDVTList Ret = { getValueTypeList(VT), 1 };
00738     return Ret;
00739   }
00740 
00741   SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs,
00742          ArrayRef<SDValue> Ops)
00743     : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
00744       SubclassData(0), NodeId(-1),
00745       OperandList(Ops.size() ? new SDUse[Ops.size()] : nullptr),
00746       ValueList(VTs.VTs), UseList(nullptr),
00747       NumOperands(Ops.size()), NumValues(VTs.NumVTs),
00748       debugLoc(dl), IROrder(Order) {
00749     for (unsigned i = 0; i != Ops.size(); ++i) {
00750       OperandList[i].setUser(this);
00751       OperandList[i].setInitial(Ops[i]);
00752     }
00753     checkForCycles(this);
00754   }
00755 
00756   /// This constructor adds no operands itself; operands can be
00757   /// set later with InitOperands.
00758   SDNode(unsigned Opc, unsigned Order, const DebugLoc dl, SDVTList VTs)
00759     : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
00760       SubclassData(0), NodeId(-1), OperandList(nullptr), ValueList(VTs.VTs),
00761       UseList(nullptr), NumOperands(0), NumValues(VTs.NumVTs), debugLoc(dl),
00762       IROrder(Order) {}
00763 
00764   /// InitOperands - Initialize the operands list of this with 1 operand.
00765   void InitOperands(SDUse *Ops, const SDValue &Op0) {
00766     Ops[0].setUser(this);
00767     Ops[0].setInitial(Op0);
00768     NumOperands = 1;
00769     OperandList = Ops;
00770     checkForCycles(this);
00771   }
00772 
00773   /// InitOperands - Initialize the operands list of this with 2 operands.
00774   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
00775     Ops[0].setUser(this);
00776     Ops[0].setInitial(Op0);
00777     Ops[1].setUser(this);
00778     Ops[1].setInitial(Op1);
00779     NumOperands = 2;
00780     OperandList = Ops;
00781     checkForCycles(this);
00782   }
00783 
00784   /// InitOperands - Initialize the operands list of this with 3 operands.
00785   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
00786                     const SDValue &Op2) {
00787     Ops[0].setUser(this);
00788     Ops[0].setInitial(Op0);
00789     Ops[1].setUser(this);
00790     Ops[1].setInitial(Op1);
00791     Ops[2].setUser(this);
00792     Ops[2].setInitial(Op2);
00793     NumOperands = 3;
00794     OperandList = Ops;
00795     checkForCycles(this);
00796   }
00797 
00798   /// InitOperands - Initialize the operands list of this with 4 operands.
00799   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
00800                     const SDValue &Op2, const SDValue &Op3) {
00801     Ops[0].setUser(this);
00802     Ops[0].setInitial(Op0);
00803     Ops[1].setUser(this);
00804     Ops[1].setInitial(Op1);
00805     Ops[2].setUser(this);
00806     Ops[2].setInitial(Op2);
00807     Ops[3].setUser(this);
00808     Ops[3].setInitial(Op3);
00809     NumOperands = 4;
00810     OperandList = Ops;
00811     checkForCycles(this);
00812   }
00813 
00814   /// InitOperands - Initialize the operands list of this with N operands.
00815   void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
00816     for (unsigned i = 0; i != N; ++i) {
00817       Ops[i].setUser(this);
00818       Ops[i].setInitial(Vals[i]);
00819     }
00820     NumOperands = N;
00821     OperandList = Ops;
00822     checkForCycles(this);
00823   }
00824 
00825   /// DropOperands - Release the operands and set this node to have
00826   /// zero operands.
00827   void DropOperands();
00828 };
00829 
00830 /// Wrapper class for IR location info (IR ordering and DebugLoc) to be passed
00831 /// into SDNode creation functions.
00832 /// When an SDNode is created from the DAGBuilder, the DebugLoc is extracted
00833 /// from the original Instruction, and IROrder is the ordinal position of
00834 /// the instruction.
00835 /// When an SDNode is created after the DAG is being built, both DebugLoc and
00836 /// the IROrder are propagated from the original SDNode.
00837 /// So SDLoc class provides two constructors besides the default one, one to
00838 /// be used by the DAGBuilder, the other to be used by others.
00839 class SDLoc {
00840 private:
00841   // Ptr could be used for either Instruction* or SDNode*. It is used for
00842   // Instruction* if IROrder is not -1.
00843   const void *Ptr;
00844   int IROrder;
00845 
00846 public:
00847   SDLoc() : Ptr(nullptr), IROrder(0) {}
00848   SDLoc(const SDNode *N) : Ptr(N), IROrder(-1) {
00849     assert(N && "null SDNode");
00850   }
00851   SDLoc(const SDValue V) : Ptr(V.getNode()), IROrder(-1) {
00852     assert(Ptr && "null SDNode");
00853   }
00854   SDLoc(const Instruction *I, int Order) : Ptr(I), IROrder(Order) {
00855     assert(Order >= 0 && "bad IROrder");
00856   }
00857   unsigned getIROrder() {
00858     if (IROrder >= 0 || Ptr == nullptr) {
00859       return (unsigned)IROrder;
00860     }
00861     const SDNode *N = (const SDNode*)(Ptr);
00862     return N->getIROrder();
00863   }
00864   DebugLoc getDebugLoc() {
00865     if (!Ptr) {
00866       return DebugLoc();
00867     }
00868     if (IROrder >= 0) {
00869       const Instruction *I = (const Instruction*)(Ptr);
00870       return I->getDebugLoc();
00871     }
00872     const SDNode *N = (const SDNode*)(Ptr);
00873     return N->getDebugLoc();
00874   }
00875 };
00876 
00877 
00878 // Define inline functions from the SDValue class.
00879 
00880 inline unsigned SDValue::getOpcode() const {
00881   return Node->getOpcode();
00882 }
00883 inline EVT SDValue::getValueType() const {
00884   return Node->getValueType(ResNo);
00885 }
00886 inline unsigned SDValue::getNumOperands() const {
00887   return Node->getNumOperands();
00888 }
00889 inline const SDValue &SDValue::getOperand(unsigned i) const {
00890   return Node->getOperand(i);
00891 }
00892 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
00893   return Node->getConstantOperandVal(i);
00894 }
00895 inline bool SDValue::isTargetOpcode() const {
00896   return Node->isTargetOpcode();
00897 }
00898 inline bool SDValue::isTargetMemoryOpcode() const {
00899   return Node->isTargetMemoryOpcode();
00900 }
00901 inline bool SDValue::isMachineOpcode() const {
00902   return Node->isMachineOpcode();
00903 }
00904 inline unsigned SDValue::getMachineOpcode() const {
00905   return Node->getMachineOpcode();
00906 }
00907 inline bool SDValue::use_empty() const {
00908   return !Node->hasAnyUseOfValue(ResNo);
00909 }
00910 inline bool SDValue::hasOneUse() const {
00911   return Node->hasNUsesOfValue(1, ResNo);
00912 }
00913 inline const DebugLoc SDValue::getDebugLoc() const {
00914   return Node->getDebugLoc();
00915 }
00916 inline void SDValue::dump() const {
00917   return Node->dump();
00918 }
00919 inline void SDValue::dumpr() const {
00920   return Node->dumpr();
00921 }
00922 // Define inline functions from the SDUse class.
00923 
00924 inline void SDUse::set(const SDValue &V) {
00925   if (Val.getNode()) removeFromList();
00926   Val = V;
00927   if (V.getNode()) V.getNode()->addUse(*this);
00928 }
00929 
00930 inline void SDUse::setInitial(const SDValue &V) {
00931   Val = V;
00932   V.getNode()->addUse(*this);
00933 }
00934 
00935 inline void SDUse::setNode(SDNode *N) {
00936   if (Val.getNode()) removeFromList();
00937   Val.setNode(N);
00938   if (N) N->addUse(*this);
00939 }
00940 
00941 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
00942 /// to allow co-allocation of node operands with the node itself.
00943 class UnarySDNode : public SDNode {
00944   SDUse Op;
00945 public:
00946   UnarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
00947               SDValue X)
00948     : SDNode(Opc, Order, dl, VTs) {
00949     InitOperands(&Op, X);
00950   }
00951 };
00952 
00953 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
00954 /// to allow co-allocation of node operands with the node itself.
00955 class BinarySDNode : public SDNode {
00956   SDUse Ops[2];
00957 public:
00958   BinarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
00959                SDValue X, SDValue Y)
00960     : SDNode(Opc, Order, dl, VTs) {
00961     InitOperands(Ops, X, Y);
00962   }
00963 };
00964 
00965 /// BinaryWithFlagsSDNode - This class is an extension of BinarySDNode
00966 /// used from those opcodes that have associated extra flags.
00967 class BinaryWithFlagsSDNode : public BinarySDNode {
00968   enum { NUW = (1 << 0), NSW = (1 << 1), EXACT = (1 << 2) };
00969 
00970 public:
00971   BinaryWithFlagsSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
00972                         SDValue X, SDValue Y)
00973       : BinarySDNode(Opc, Order, dl, VTs, X, Y) {}
00974   /// getRawSubclassData - Return the SubclassData value, which contains an
00975   /// encoding of the flags.
00976   /// This function should be used to add subclass data to the NodeID value.
00977   unsigned getRawSubclassData() const { return SubclassData; }
00978   void setHasNoUnsignedWrap(bool b) {
00979     SubclassData = (SubclassData & ~NUW) | (b ? NUW : 0);
00980   }
00981   void setHasNoSignedWrap(bool b) {
00982     SubclassData = (SubclassData & ~NSW) | (b ? NSW : 0);
00983   }
00984   void setIsExact(bool b) {
00985     SubclassData = (SubclassData & ~EXACT) | (b ? EXACT : 0);
00986   }
00987   bool hasNoUnsignedWrap() const { return SubclassData & NUW; }
00988   bool hasNoSignedWrap() const { return SubclassData & NSW; }
00989   bool isExact() const { return SubclassData & EXACT; }
00990   static bool classof(const SDNode *N) {
00991     return isBinOpWithFlags(N->getOpcode());
00992   }
00993 };
00994 
00995 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
00996 /// to allow co-allocation of node operands with the node itself.
00997 class TernarySDNode : public SDNode {
00998   SDUse Ops[3];
00999 public:
01000   TernarySDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
01001                 SDValue X, SDValue Y, SDValue Z)
01002     : SDNode(Opc, Order, dl, VTs) {
01003     InitOperands(Ops, X, Y, Z);
01004   }
01005 };
01006 
01007 
01008 /// HandleSDNode - This class is used to form a handle around another node that
01009 /// is persistent and is updated across invocations of replaceAllUsesWith on its
01010 /// operand.  This node should be directly created by end-users and not added to
01011 /// the AllNodes list.
01012 class HandleSDNode : public SDNode {
01013   SDUse Op;
01014 public:
01015   explicit HandleSDNode(SDValue X)
01016     : SDNode(ISD::HANDLENODE, 0, DebugLoc(), getSDVTList(MVT::Other)) {
01017     InitOperands(&Op, X);
01018   }
01019   ~HandleSDNode();
01020   const SDValue &getValue() const { return Op; }
01021 };
01022 
01023 class AddrSpaceCastSDNode : public UnarySDNode {
01024 private:
01025   unsigned SrcAddrSpace;
01026   unsigned DestAddrSpace;
01027 
01028 public:
01029   AddrSpaceCastSDNode(unsigned Order, DebugLoc dl, EVT VT, SDValue X,
01030                       unsigned SrcAS, unsigned DestAS);
01031 
01032   unsigned getSrcAddressSpace() const { return SrcAddrSpace; }
01033   unsigned getDestAddressSpace() const { return DestAddrSpace; }
01034 
01035   static bool classof(const SDNode *N) {
01036     return N->getOpcode() == ISD::ADDRSPACECAST;
01037   }
01038 };
01039 
01040 /// Abstact virtual class for operations for memory operations
01041 class MemSDNode : public SDNode {
01042 private:
01043   // MemoryVT - VT of in-memory value.
01044   EVT MemoryVT;
01045 
01046 protected:
01047   /// MMO - Memory reference information.
01048   MachineMemOperand *MMO;
01049 
01050 public:
01051   MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
01052             EVT MemoryVT, MachineMemOperand *MMO);
01053 
01054   MemSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
01055             ArrayRef<SDValue> Ops, EVT MemoryVT, MachineMemOperand *MMO);
01056 
01057   bool readMem() const { return MMO->isLoad(); }
01058   bool writeMem() const { return MMO->isStore(); }
01059 
01060   /// Returns alignment and volatility of the memory access
01061   unsigned getOriginalAlignment() const {
01062     return MMO->getBaseAlignment();
01063   }
01064   unsigned getAlignment() const {
01065     return MMO->getAlignment();
01066   }
01067 
01068   /// getRawSubclassData - Return the SubclassData value, which contains an
01069   /// encoding of the volatile flag, as well as bits used by subclasses. This
01070   /// function should only be used to compute a FoldingSetNodeID value.
01071   unsigned getRawSubclassData() const {
01072     return SubclassData;
01073   }
01074 
01075   // We access subclass data here so that we can check consistency
01076   // with MachineMemOperand information.
01077   bool isVolatile() const { return (SubclassData >> 5) & 1; }
01078   bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
01079   bool isInvariant() const { return (SubclassData >> 7) & 1; }
01080 
01081   AtomicOrdering getOrdering() const {
01082     return AtomicOrdering((SubclassData >> 8) & 15);
01083   }
01084   SynchronizationScope getSynchScope() const {
01085     return SynchronizationScope((SubclassData >> 12) & 1);
01086   }
01087 
01088   // Returns the offset from the location of the access.
01089   int64_t getSrcValueOffset() const { return MMO->getOffset(); }
01090 
01091   /// Returns the TBAAInfo that describes the dereference.
01092   const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
01093 
01094   /// Returns the Ranges that describes the dereference.
01095   const MDNode *getRanges() const { return MMO->getRanges(); }
01096 
01097   /// getMemoryVT - Return the type of the in-memory value.
01098   EVT getMemoryVT() const { return MemoryVT; }
01099 
01100   /// getMemOperand - Return a MachineMemOperand object describing the memory
01101   /// reference performed by operation.
01102   MachineMemOperand *getMemOperand() const { return MMO; }
01103 
01104   const MachinePointerInfo &getPointerInfo() const {
01105     return MMO->getPointerInfo();
01106   }
01107 
01108   /// getAddressSpace - Return the address space for the associated pointer
01109   unsigned getAddressSpace() const {
01110     return getPointerInfo().getAddrSpace();
01111   }
01112 
01113   /// refineAlignment - Update this MemSDNode's MachineMemOperand information
01114   /// to reflect the alignment of NewMMO, if it has a greater alignment.
01115   /// This must only be used when the new alignment applies to all users of
01116   /// this MachineMemOperand.
01117   void refineAlignment(const MachineMemOperand *NewMMO) {
01118     MMO->refineAlignment(NewMMO);
01119   }
01120 
01121   const SDValue &getChain() const { return getOperand(0); }
01122   const SDValue &getBasePtr() const {
01123     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
01124   }
01125 
01126   // Methods to support isa and dyn_cast
01127   static bool classof(const SDNode *N) {
01128     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
01129     // with either an intrinsic or a target opcode.
01130     return N->getOpcode() == ISD::LOAD                ||
01131            N->getOpcode() == ISD::STORE               ||
01132            N->getOpcode() == ISD::PREFETCH            ||
01133            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
01134            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
01135            N->getOpcode() == ISD::ATOMIC_SWAP         ||
01136            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
01137            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
01138            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
01139            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
01140            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
01141            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
01142            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
01143            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
01144            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
01145            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
01146            N->getOpcode() == ISD::ATOMIC_LOAD         ||
01147            N->getOpcode() == ISD::ATOMIC_STORE        ||
01148            N->isTargetMemoryOpcode();
01149   }
01150 };
01151 
01152 /// AtomicSDNode - A SDNode reprenting atomic operations.
01153 ///
01154 class AtomicSDNode : public MemSDNode {
01155   SDUse Ops[4];
01156 
01157   /// For cmpxchg instructions, the ordering requirements when a store does not
01158   /// occur.
01159   AtomicOrdering FailureOrdering;
01160 
01161   void InitAtomic(AtomicOrdering SuccessOrdering,
01162                   AtomicOrdering FailureOrdering,
01163                   SynchronizationScope SynchScope) {
01164     // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
01165     assert((SuccessOrdering & 15) == SuccessOrdering &&
01166            "Ordering may not require more than 4 bits!");
01167     assert((FailureOrdering & 15) == FailureOrdering &&
01168            "Ordering may not require more than 4 bits!");
01169     assert((SynchScope & 1) == SynchScope &&
01170            "SynchScope may not require more than 1 bit!");
01171     SubclassData |= SuccessOrdering << 8;
01172     SubclassData |= SynchScope << 12;
01173     this->FailureOrdering = FailureOrdering;
01174     assert(getSuccessOrdering() == SuccessOrdering &&
01175            "Ordering encoding error!");
01176     assert(getFailureOrdering() == FailureOrdering &&
01177            "Ordering encoding error!");
01178     assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
01179   }
01180 
01181 public:
01182   // Opc:   opcode for atomic
01183   // VTL:    value type list
01184   // Chain:  memory chain for operaand
01185   // Ptr:    address to update as a SDValue
01186   // Cmp:    compare value
01187   // Swp:    swap value
01188   // SrcVal: address to update as a Value (used for MemOperand)
01189   // Align:  alignment of memory
01190   AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
01191                EVT MemVT, SDValue Chain, SDValue Ptr, SDValue Cmp, SDValue Swp,
01192                MachineMemOperand *MMO, AtomicOrdering Ordering,
01193                SynchronizationScope SynchScope)
01194       : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
01195     InitAtomic(Ordering, Ordering, SynchScope);
01196     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
01197   }
01198   AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
01199                EVT MemVT,
01200                SDValue Chain, SDValue Ptr,
01201                SDValue Val, MachineMemOperand *MMO,
01202                AtomicOrdering Ordering, SynchronizationScope SynchScope)
01203     : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
01204     InitAtomic(Ordering, Ordering, SynchScope);
01205     InitOperands(Ops, Chain, Ptr, Val);
01206   }
01207   AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL,
01208                EVT MemVT,
01209                SDValue Chain, SDValue Ptr,
01210                MachineMemOperand *MMO,
01211                AtomicOrdering Ordering, SynchronizationScope SynchScope)
01212     : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
01213     InitAtomic(Ordering, Ordering, SynchScope);
01214     InitOperands(Ops, Chain, Ptr);
01215   }
01216   AtomicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTL, EVT MemVT,
01217                const SDValue* AllOps, SDUse *DynOps, unsigned NumOps,
01218                MachineMemOperand *MMO,
01219                AtomicOrdering SuccessOrdering, AtomicOrdering FailureOrdering,
01220                SynchronizationScope SynchScope)
01221     : MemSDNode(Opc, Order, dl, VTL, MemVT, MMO) {
01222     InitAtomic(SuccessOrdering, FailureOrdering, SynchScope);
01223     assert((DynOps || NumOps <= array_lengthof(Ops)) &&
01224            "Too many ops for internal storage!");
01225     InitOperands(DynOps ? DynOps : Ops, AllOps, NumOps);
01226   }
01227 
01228   const SDValue &getBasePtr() const { return getOperand(1); }
01229   const SDValue &getVal() const { return getOperand(2); }
01230 
01231   AtomicOrdering getSuccessOrdering() const {
01232     return getOrdering();
01233   }
01234 
01235   // Not quite enough room in SubclassData for everything, so failure gets its
01236   // own field.
01237   AtomicOrdering getFailureOrdering() const {
01238     return FailureOrdering;
01239   }
01240 
01241   bool isCompareAndSwap() const {
01242     unsigned Op = getOpcode();
01243     return Op == ISD::ATOMIC_CMP_SWAP || Op == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS;
01244   }
01245 
01246   // Methods to support isa and dyn_cast
01247   static bool classof(const SDNode *N) {
01248     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
01249            N->getOpcode() == ISD::ATOMIC_CMP_SWAP_WITH_SUCCESS ||
01250            N->getOpcode() == ISD::ATOMIC_SWAP         ||
01251            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
01252            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
01253            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
01254            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
01255            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
01256            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
01257            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
01258            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
01259            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
01260            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
01261            N->getOpcode() == ISD::ATOMIC_LOAD         ||
01262            N->getOpcode() == ISD::ATOMIC_STORE;
01263   }
01264 };
01265 
01266 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
01267 /// memory and need an associated MachineMemOperand. Its opcode may be
01268 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
01269 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
01270 class MemIntrinsicSDNode : public MemSDNode {
01271 public:
01272   MemIntrinsicSDNode(unsigned Opc, unsigned Order, DebugLoc dl, SDVTList VTs,
01273                      ArrayRef<SDValue> Ops, EVT MemoryVT,
01274                      MachineMemOperand *MMO)
01275     : MemSDNode(Opc, Order, dl, VTs, Ops, MemoryVT, MMO) {
01276   }
01277 
01278   // Methods to support isa and dyn_cast
01279   static bool classof(const SDNode *N) {
01280     // We lower some target intrinsics to their target opcode
01281     // early a node with a target opcode can be of this class
01282     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
01283            N->getOpcode() == ISD::INTRINSIC_VOID ||
01284            N->getOpcode() == ISD::PREFETCH ||
01285            N->isTargetMemoryOpcode();
01286   }
01287 };
01288 
01289 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
01290 /// support for the llvm IR shufflevector instruction.  It combines elements
01291 /// from two input vectors into a new input vector, with the selection and
01292 /// ordering of elements determined by an array of integers, referred to as
01293 /// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
01294 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
01295 /// An index of -1 is treated as undef, such that the code generator may put
01296 /// any value in the corresponding element of the result.
01297 class ShuffleVectorSDNode : public SDNode {
01298   SDUse Ops[2];
01299 
01300   // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
01301   // is freed when the SelectionDAG object is destroyed.
01302   const int *Mask;
01303 protected:
01304   friend class SelectionDAG;
01305   ShuffleVectorSDNode(EVT VT, unsigned Order, DebugLoc dl, SDValue N1,
01306                       SDValue N2, const int *M)
01307     : SDNode(ISD::VECTOR_SHUFFLE, Order, dl, getSDVTList(VT)), Mask(M) {
01308     InitOperands(Ops, N1, N2);
01309   }
01310 public:
01311 
01312   ArrayRef<int> getMask() const {
01313     EVT VT = getValueType(0);
01314     return makeArrayRef(Mask, VT.getVectorNumElements());
01315   }
01316   int getMaskElt(unsigned Idx) const {
01317     assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
01318     return Mask[Idx];
01319   }
01320 
01321   bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
01322   int  getSplatIndex() const {
01323     assert(isSplat() && "Cannot get splat index for non-splat!");
01324     EVT VT = getValueType(0);
01325     for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
01326       if (Mask[i] >= 0)
01327         return Mask[i];
01328     }
01329     llvm_unreachable("Splat with all undef indices?");
01330   }
01331   static bool isSplatMask(const int *Mask, EVT VT);
01332 
01333   static bool classof(const SDNode *N) {
01334     return N->getOpcode() == ISD::VECTOR_SHUFFLE;
01335   }
01336 };
01337 
01338 class ConstantSDNode : public SDNode {
01339   const ConstantInt *Value;
01340   friend class SelectionDAG;
01341   ConstantSDNode(bool isTarget, bool isOpaque, const ConstantInt *val, EVT VT)
01342     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
01343              0, DebugLoc(), getSDVTList(VT)), Value(val) {
01344     SubclassData |= (uint16_t)isOpaque;
01345   }
01346 public:
01347 
01348   const ConstantInt *getConstantIntValue() const { return Value; }
01349   const APInt &getAPIntValue() const { return Value->getValue(); }
01350   uint64_t getZExtValue() const { return Value->getZExtValue(); }
01351   int64_t getSExtValue() const { return Value->getSExtValue(); }
01352 
01353   bool isOne() const { return Value->isOne(); }
01354   bool isNullValue() const { return Value->isNullValue(); }
01355   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
01356 
01357   bool isOpaque() const { return SubclassData & 1; }
01358 
01359   static bool classof(const SDNode *N) {
01360     return N->getOpcode() == ISD::Constant ||
01361            N->getOpcode() == ISD::TargetConstant;
01362   }
01363 };
01364 
01365 class ConstantFPSDNode : public SDNode {
01366   const ConstantFP *Value;
01367   friend class SelectionDAG;
01368   ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
01369     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
01370              0, DebugLoc(), getSDVTList(VT)), Value(val) {
01371   }
01372 public:
01373 
01374   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
01375   const ConstantFP *getConstantFPValue() const { return Value; }
01376 
01377   /// isZero - Return true if the value is positive or negative zero.
01378   bool isZero() const { return Value->isZero(); }
01379 
01380   /// isNaN - Return true if the value is a NaN.
01381   bool isNaN() const { return Value->isNaN(); }
01382 
01383   /// isExactlyValue - We don't rely on operator== working on double values, as
01384   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
01385   /// As such, this method can be used to do an exact bit-for-bit comparison of
01386   /// two floating point values.
01387 
01388   /// We leave the version with the double argument here because it's just so
01389   /// convenient to write "2.0" and the like.  Without this function we'd
01390   /// have to duplicate its logic everywhere it's called.
01391   bool isExactlyValue(double V) const {
01392     bool ignored;
01393     APFloat Tmp(V);
01394     Tmp.convert(Value->getValueAPF().getSemantics(),
01395                 APFloat::rmNearestTiesToEven, &ignored);
01396     return isExactlyValue(Tmp);
01397   }
01398   bool isExactlyValue(const APFloat& V) const;
01399 
01400   static bool isValueValidForType(EVT VT, const APFloat& Val);
01401 
01402   static bool classof(const SDNode *N) {
01403     return N->getOpcode() == ISD::ConstantFP ||
01404            N->getOpcode() == ISD::TargetConstantFP;
01405   }
01406 };
01407 
01408 class GlobalAddressSDNode : public SDNode {
01409   const GlobalValue *TheGlobal;
01410   int64_t Offset;
01411   unsigned char TargetFlags;
01412   friend class SelectionDAG;
01413   GlobalAddressSDNode(unsigned Opc, unsigned Order, DebugLoc DL,
01414                       const GlobalValue *GA, EVT VT, int64_t o,
01415                       unsigned char TargetFlags);
01416 public:
01417 
01418   const GlobalValue *getGlobal() const { return TheGlobal; }
01419   int64_t getOffset() const { return Offset; }
01420   unsigned char getTargetFlags() const { return TargetFlags; }
01421   // Return the address space this GlobalAddress belongs to.
01422   unsigned getAddressSpace() const;
01423 
01424   static bool classof(const SDNode *N) {
01425     return N->getOpcode() == ISD::GlobalAddress ||
01426            N->getOpcode() == ISD::TargetGlobalAddress ||
01427            N->getOpcode() == ISD::GlobalTLSAddress ||
01428            N->getOpcode() == ISD::TargetGlobalTLSAddress;
01429   }
01430 };
01431 
01432 class FrameIndexSDNode : public SDNode {
01433   int FI;
01434   friend class SelectionDAG;
01435   FrameIndexSDNode(int fi, EVT VT, bool isTarg)
01436     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
01437       0, DebugLoc(), getSDVTList(VT)), FI(fi) {
01438   }
01439 public:
01440 
01441   int getIndex() const { return FI; }
01442 
01443   static bool classof(const SDNode *N) {
01444     return N->getOpcode() == ISD::FrameIndex ||
01445            N->getOpcode() == ISD::TargetFrameIndex;
01446   }
01447 };
01448 
01449 class JumpTableSDNode : public SDNode {
01450   int JTI;
01451   unsigned char TargetFlags;
01452   friend class SelectionDAG;
01453   JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
01454     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
01455       0, DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
01456   }
01457 public:
01458 
01459   int getIndex() const { return JTI; }
01460   unsigned char getTargetFlags() const { return TargetFlags; }
01461 
01462   static bool classof(const SDNode *N) {
01463     return N->getOpcode() == ISD::JumpTable ||
01464            N->getOpcode() == ISD::TargetJumpTable;
01465   }
01466 };
01467 
01468 class ConstantPoolSDNode : public SDNode {
01469   union {
01470     const Constant *ConstVal;
01471     MachineConstantPoolValue *MachineCPVal;
01472   } Val;
01473   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
01474   unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
01475   unsigned char TargetFlags;
01476   friend class SelectionDAG;
01477   ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
01478                      unsigned Align, unsigned char TF)
01479     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
01480              DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
01481              TargetFlags(TF) {
01482     assert(Offset >= 0 && "Offset is too large");
01483     Val.ConstVal = c;
01484   }
01485   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
01486                      EVT VT, int o, unsigned Align, unsigned char TF)
01487     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 0,
01488              DebugLoc(), getSDVTList(VT)), Offset(o), Alignment(Align),
01489              TargetFlags(TF) {
01490     assert(Offset >= 0 && "Offset is too large");
01491     Val.MachineCPVal = v;
01492     Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
01493   }
01494 public:
01495 
01496   bool isMachineConstantPoolEntry() const {
01497     return Offset < 0;
01498   }
01499 
01500   const Constant *getConstVal() const {
01501     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
01502     return Val.ConstVal;
01503   }
01504 
01505   MachineConstantPoolValue *getMachineCPVal() const {
01506     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
01507     return Val.MachineCPVal;
01508   }
01509 
01510   int getOffset() const {
01511     return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
01512   }
01513 
01514   // Return the alignment of this constant pool object, which is either 0 (for
01515   // default alignment) or the desired value.
01516   unsigned getAlignment() const { return Alignment; }
01517   unsigned char getTargetFlags() const { return TargetFlags; }
01518 
01519   Type *getType() const;
01520 
01521   static bool classof(const SDNode *N) {
01522     return N->getOpcode() == ISD::ConstantPool ||
01523            N->getOpcode() == ISD::TargetConstantPool;
01524   }
01525 };
01526 
01527 /// Completely target-dependent object reference.
01528 class TargetIndexSDNode : public SDNode {
01529   unsigned char TargetFlags;
01530   int Index;
01531   int64_t Offset;
01532   friend class SelectionDAG;
01533 public:
01534 
01535   TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
01536     : SDNode(ISD::TargetIndex, 0, DebugLoc(), getSDVTList(VT)),
01537       TargetFlags(TF), Index(Idx), Offset(Ofs) {}
01538 public:
01539 
01540   unsigned char getTargetFlags() const { return TargetFlags; }
01541   int getIndex() const { return Index; }
01542   int64_t getOffset() const { return Offset; }
01543 
01544   static bool classof(const SDNode *N) {
01545     return N->getOpcode() == ISD::TargetIndex;
01546   }
01547 };
01548 
01549 class BasicBlockSDNode : public SDNode {
01550   MachineBasicBlock *MBB;
01551   friend class SelectionDAG;
01552   /// Debug info is meaningful and potentially useful here, but we create
01553   /// blocks out of order when they're jumped to, which makes it a bit
01554   /// harder.  Let's see if we need it first.
01555   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
01556     : SDNode(ISD::BasicBlock, 0, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb)
01557   {}
01558 public:
01559 
01560   MachineBasicBlock *getBasicBlock() const { return MBB; }
01561 
01562   static bool classof(const SDNode *N) {
01563     return N->getOpcode() == ISD::BasicBlock;
01564   }
01565 };
01566 
01567 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
01568 /// BUILD_VECTORs.
01569 class BuildVectorSDNode : public SDNode {
01570   // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
01571   explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
01572 public:
01573   /// isConstantSplat - Check if this is a constant splat, and if so, find the
01574   /// smallest element size that splats the vector.  If MinSplatBits is
01575   /// nonzero, the element size must be at least that large.  Note that the
01576   /// splat element may be the entire vector (i.e., a one element vector).
01577   /// Returns the splat element value in SplatValue.  Any undefined bits in
01578   /// that value are zero, and the corresponding bits in the SplatUndef mask
01579   /// are set.  The SplatBitSize value is set to the splat element size in
01580   /// bits.  HasAnyUndefs is set to true if any bits in the vector are
01581   /// undefined.  isBigEndian describes the endianness of the target.
01582   bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
01583                        unsigned &SplatBitSize, bool &HasAnyUndefs,
01584                        unsigned MinSplatBits = 0,
01585                        bool isBigEndian = false) const;
01586 
01587   /// \brief Returns the splatted value or a null value if this is not a splat.
01588   ///
01589   /// If passed a non-null UndefElements bitvector, it will resize it to match
01590   /// the vector width and set the bits where elements are undef.
01591   SDValue getSplatValue(BitVector *UndefElements = nullptr) const;
01592 
01593   /// \brief Returns the splatted constant or null if this is not a constant
01594   /// splat.
01595   ///
01596   /// If passed a non-null UndefElements bitvector, it will resize it to match
01597   /// the vector width and set the bits where elements are undef.
01598   ConstantSDNode *
01599   getConstantSplatNode(BitVector *UndefElements = nullptr) const;
01600 
01601   /// \brief Returns the splatted constant FP or null if this is not a constant
01602   /// FP splat.
01603   ///
01604   /// If passed a non-null UndefElements bitvector, it will resize it to match
01605   /// the vector width and set the bits where elements are undef.
01606   ConstantFPSDNode *
01607   getConstantFPSplatNode(BitVector *UndefElements = nullptr) const;
01608 
01609   bool isConstant() const;
01610 
01611   static inline bool classof(const SDNode *N) {
01612     return N->getOpcode() == ISD::BUILD_VECTOR;
01613   }
01614 };
01615 
01616 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
01617 /// used when the SelectionDAG needs to make a simple reference to something
01618 /// in the LLVM IR representation.
01619 ///
01620 class SrcValueSDNode : public SDNode {
01621   const Value *V;
01622   friend class SelectionDAG;
01623   /// Create a SrcValue for a general value.
01624   explicit SrcValueSDNode(const Value *v)
01625     : SDNode(ISD::SRCVALUE, 0, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
01626 
01627 public:
01628   /// getValue - return the contained Value.
01629   const Value *getValue() const { return V; }
01630 
01631   static bool classof(const SDNode *N) {
01632     return N->getOpcode() == ISD::SRCVALUE;
01633   }
01634 };
01635 
01636 class MDNodeSDNode : public SDNode {
01637   const MDNode *MD;
01638   friend class SelectionDAG;
01639   explicit MDNodeSDNode(const MDNode *md)
01640   : SDNode(ISD::MDNODE_SDNODE, 0, DebugLoc(), getSDVTList(MVT::Other)), MD(md)
01641   {}
01642 public:
01643 
01644   const MDNode *getMD() const { return MD; }
01645 
01646   static bool classof(const SDNode *N) {
01647     return N->getOpcode() == ISD::MDNODE_SDNODE;
01648   }
01649 };
01650 
01651 class RegisterSDNode : public SDNode {
01652   unsigned Reg;
01653   friend class SelectionDAG;
01654   RegisterSDNode(unsigned reg, EVT VT)
01655     : SDNode(ISD::Register, 0, DebugLoc(), getSDVTList(VT)), Reg(reg) {
01656   }
01657 public:
01658 
01659   unsigned getReg() const { return Reg; }
01660 
01661   static bool classof(const SDNode *N) {
01662     return N->getOpcode() == ISD::Register;
01663   }
01664 };
01665 
01666 class RegisterMaskSDNode : public SDNode {
01667   // The memory for RegMask is not owned by the node.
01668   const uint32_t *RegMask;
01669   friend class SelectionDAG;
01670   RegisterMaskSDNode(const uint32_t *mask)
01671     : SDNode(ISD::RegisterMask, 0, DebugLoc(), getSDVTList(MVT::Untyped)),
01672       RegMask(mask) {}
01673 public:
01674 
01675   const uint32_t *getRegMask() const { return RegMask; }
01676 
01677   static bool classof(const SDNode *N) {
01678     return N->getOpcode() == ISD::RegisterMask;
01679   }
01680 };
01681 
01682 class BlockAddressSDNode : public SDNode {
01683   const BlockAddress *BA;
01684   int64_t Offset;
01685   unsigned char TargetFlags;
01686   friend class SelectionDAG;
01687   BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
01688                      int64_t o, unsigned char Flags)
01689     : SDNode(NodeTy, 0, DebugLoc(), getSDVTList(VT)),
01690              BA(ba), Offset(o), TargetFlags(Flags) {
01691   }
01692 public:
01693   const BlockAddress *getBlockAddress() const { return BA; }
01694   int64_t getOffset() const { return Offset; }
01695   unsigned char getTargetFlags() const { return TargetFlags; }
01696 
01697   static bool classof(const SDNode *N) {
01698     return N->getOpcode() == ISD::BlockAddress ||
01699            N->getOpcode() == ISD::TargetBlockAddress;
01700   }
01701 };
01702 
01703 class EHLabelSDNode : public SDNode {
01704   SDUse Chain;
01705   MCSymbol *Label;
01706   friend class SelectionDAG;
01707   EHLabelSDNode(unsigned Order, DebugLoc dl, SDValue ch, MCSymbol *L)
01708     : SDNode(ISD::EH_LABEL, Order, dl, getSDVTList(MVT::Other)), Label(L) {
01709     InitOperands(&Chain, ch);
01710   }
01711 public:
01712   MCSymbol *getLabel() const { return Label; }
01713 
01714   static bool classof(const SDNode *N) {
01715     return N->getOpcode() == ISD::EH_LABEL;
01716   }
01717 };
01718 
01719 class ExternalSymbolSDNode : public SDNode {
01720   const char *Symbol;
01721   unsigned char TargetFlags;
01722 
01723   friend class SelectionDAG;
01724   ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
01725     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
01726              0, DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
01727   }
01728 public:
01729 
01730   const char *getSymbol() const { return Symbol; }
01731   unsigned char getTargetFlags() const { return TargetFlags; }
01732 
01733   static bool classof(const SDNode *N) {
01734     return N->getOpcode() == ISD::ExternalSymbol ||
01735            N->getOpcode() == ISD::TargetExternalSymbol;
01736   }
01737 };
01738 
01739 class CondCodeSDNode : public SDNode {
01740   ISD::CondCode Condition;
01741   friend class SelectionDAG;
01742   explicit CondCodeSDNode(ISD::CondCode Cond)
01743     : SDNode(ISD::CONDCODE, 0, DebugLoc(), getSDVTList(MVT::Other)),
01744       Condition(Cond) {
01745   }
01746 public:
01747 
01748   ISD::CondCode get() const { return Condition; }
01749 
01750   static bool classof(const SDNode *N) {
01751     return N->getOpcode() == ISD::CONDCODE;
01752   }
01753 };
01754 
01755 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
01756 /// future and most targets don't support it.
01757 class CvtRndSatSDNode : public SDNode {
01758   ISD::CvtCode CvtCode;
01759   friend class SelectionDAG;
01760   explicit CvtRndSatSDNode(EVT VT, unsigned Order, DebugLoc dl,
01761                            ArrayRef<SDValue> Ops, ISD::CvtCode Code)
01762     : SDNode(ISD::CONVERT_RNDSAT, Order, dl, getSDVTList(VT), Ops),
01763       CvtCode(Code) {
01764     assert(Ops.size() == 5 && "wrong number of operations");
01765   }
01766 public:
01767   ISD::CvtCode getCvtCode() const { return CvtCode; }
01768 
01769   static bool classof(const SDNode *N) {
01770     return N->getOpcode() == ISD::CONVERT_RNDSAT;
01771   }
01772 };
01773 
01774 /// VTSDNode - This class is used to represent EVT's, which are used
01775 /// to parameterize some operations.
01776 class VTSDNode : public SDNode {
01777   EVT ValueType;
01778   friend class SelectionDAG;
01779   explicit VTSDNode(EVT VT)
01780     : SDNode(ISD::VALUETYPE, 0, DebugLoc(), getSDVTList(MVT::Other)),
01781       ValueType(VT) {
01782   }
01783 public:
01784 
01785   EVT getVT() const { return ValueType; }
01786 
01787   static bool classof(const SDNode *N) {
01788     return N->getOpcode() == ISD::VALUETYPE;
01789   }
01790 };
01791 
01792 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
01793 ///
01794 class LSBaseSDNode : public MemSDNode {
01795   //! Operand array for load and store
01796   /*!
01797     \note Moving this array to the base class captures more
01798     common functionality shared between LoadSDNode and
01799     StoreSDNode
01800    */
01801   SDUse Ops[4];
01802 public:
01803   LSBaseSDNode(ISD::NodeType NodeTy, unsigned Order, DebugLoc dl,
01804                SDValue *Operands, unsigned numOperands,
01805                SDVTList VTs, ISD::MemIndexedMode AM, EVT MemVT,
01806                MachineMemOperand *MMO)
01807     : MemSDNode(NodeTy, Order, dl, VTs, MemVT, MMO) {
01808     SubclassData |= AM << 2;
01809     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
01810     InitOperands(Ops, Operands, numOperands);
01811     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
01812            "Only indexed loads and stores have a non-undef offset operand");
01813   }
01814 
01815   const SDValue &getOffset() const {
01816     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
01817   }
01818 
01819   /// getAddressingMode - Return the addressing mode for this load or store:
01820   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
01821   ISD::MemIndexedMode getAddressingMode() const {
01822     return ISD::MemIndexedMode((SubclassData >> 2) & 7);
01823   }
01824 
01825   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
01826   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
01827 
01828   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
01829   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
01830 
01831   static bool classof(const SDNode *N) {
01832     return N->getOpcode() == ISD::LOAD ||
01833            N->getOpcode() == ISD::STORE;
01834   }
01835 };
01836 
01837 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
01838 ///
01839 class LoadSDNode : public LSBaseSDNode {
01840   friend class SelectionDAG;
01841   LoadSDNode(SDValue *ChainPtrOff, unsigned Order, DebugLoc dl, SDVTList VTs,
01842              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
01843              MachineMemOperand *MMO)
01844     : LSBaseSDNode(ISD::LOAD, Order, dl, ChainPtrOff, 3, VTs, AM, MemVT, MMO) {
01845     SubclassData |= (unsigned short)ETy;
01846     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
01847     assert(readMem() && "Load MachineMemOperand is not a load!");
01848     assert(!writeMem() && "Load MachineMemOperand is a store!");
01849   }
01850 public:
01851 
01852   /// getExtensionType - Return whether this is a plain node,
01853   /// or one of the varieties of value-extending loads.
01854   ISD::LoadExtType getExtensionType() const {
01855     return ISD::LoadExtType(SubclassData & 3);
01856   }
01857 
01858   const SDValue &getBasePtr() const { return getOperand(1); }
01859   const SDValue &getOffset() const { return getOperand(2); }
01860 
01861   static bool classof(const SDNode *N) {
01862     return N->getOpcode() == ISD::LOAD;
01863   }
01864 };
01865 
01866 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
01867 ///
01868 class StoreSDNode : public LSBaseSDNode {
01869   friend class SelectionDAG;
01870   StoreSDNode(SDValue *ChainValuePtrOff, unsigned Order, DebugLoc dl,
01871               SDVTList VTs, ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
01872               MachineMemOperand *MMO)
01873     : LSBaseSDNode(ISD::STORE, Order, dl, ChainValuePtrOff, 4,
01874                    VTs, AM, MemVT, MMO) {
01875     SubclassData |= (unsigned short)isTrunc;
01876     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
01877     assert(!readMem() && "Store MachineMemOperand is a load!");
01878     assert(writeMem() && "Store MachineMemOperand is not a store!");
01879   }
01880 public:
01881 
01882   /// isTruncatingStore - Return true if the op does a truncation before store.
01883   /// For integers this is the same as doing a TRUNCATE and storing the result.
01884   /// For floats, it is the same as doing an FP_ROUND and storing the result.
01885   bool isTruncatingStore() const { return SubclassData & 1; }
01886 
01887   const SDValue &getValue() const { return getOperand(1); }
01888   const SDValue &getBasePtr() const { return getOperand(2); }
01889   const SDValue &getOffset() const { return getOperand(3); }
01890 
01891   static bool classof(const SDNode *N) {
01892     return N->getOpcode() == ISD::STORE;
01893   }
01894 };
01895 
01896 /// MachineSDNode - An SDNode that represents everything that will be needed
01897 /// to construct a MachineInstr. These nodes are created during the
01898 /// instruction selection proper phase.
01899 ///
01900 class MachineSDNode : public SDNode {
01901 public:
01902   typedef MachineMemOperand **mmo_iterator;
01903 
01904 private:
01905   friend class SelectionDAG;
01906   MachineSDNode(unsigned Opc, unsigned Order, const DebugLoc DL, SDVTList VTs)
01907     : SDNode(Opc, Order, DL, VTs), MemRefs(nullptr), MemRefsEnd(nullptr) {}
01908 
01909   /// LocalOperands - Operands for this instruction, if they fit here. If
01910   /// they don't, this field is unused.
01911   SDUse LocalOperands[4];
01912 
01913   /// MemRefs - Memory reference descriptions for this instruction.
01914   mmo_iterator MemRefs;
01915   mmo_iterator MemRefsEnd;
01916 
01917 public:
01918   mmo_iterator memoperands_begin() const { return MemRefs; }
01919   mmo_iterator memoperands_end() const { return MemRefsEnd; }
01920   bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
01921 
01922   /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
01923   /// list. This does not transfer ownership.
01924   void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
01925     for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
01926       assert(*MMI && "Null mem ref detected!");
01927     MemRefs = NewMemRefs;
01928     MemRefsEnd = NewMemRefsEnd;
01929   }
01930 
01931   static bool classof(const SDNode *N) {
01932     return N->isMachineOpcode();
01933   }
01934 };
01935 
01936 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
01937                                             SDNode, ptrdiff_t> {
01938   const SDNode *Node;
01939   unsigned Operand;
01940 
01941   SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
01942 public:
01943   bool operator==(const SDNodeIterator& x) const {
01944     return Operand == x.Operand;
01945   }
01946   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
01947 
01948   const SDNodeIterator &operator=(const SDNodeIterator &I) {
01949     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
01950     Operand = I.Operand;
01951     return *this;
01952   }
01953 
01954   pointer operator*() const {
01955     return Node->getOperand(Operand).getNode();
01956   }
01957   pointer operator->() const { return operator*(); }
01958 
01959   SDNodeIterator& operator++() {                // Preincrement
01960     ++Operand;
01961     return *this;
01962   }
01963   SDNodeIterator operator++(int) { // Postincrement
01964     SDNodeIterator tmp = *this; ++*this; return tmp;
01965   }
01966   size_t operator-(SDNodeIterator Other) const {
01967     assert(Node == Other.Node &&
01968            "Cannot compare iterators of two different nodes!");
01969     return Operand - Other.Operand;
01970   }
01971 
01972   static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
01973   static SDNodeIterator end  (const SDNode *N) {
01974     return SDNodeIterator(N, N->getNumOperands());
01975   }
01976 
01977   unsigned getOperand() const { return Operand; }
01978   const SDNode *getNode() const { return Node; }
01979 };
01980 
01981 template <> struct GraphTraits<SDNode*> {
01982   typedef SDNode NodeType;
01983   typedef SDNodeIterator ChildIteratorType;
01984   static inline NodeType *getEntryNode(SDNode *N) { return N; }
01985   static inline ChildIteratorType child_begin(NodeType *N) {
01986     return SDNodeIterator::begin(N);
01987   }
01988   static inline ChildIteratorType child_end(NodeType *N) {
01989     return SDNodeIterator::end(N);
01990   }
01991 };
01992 
01993 /// LargestSDNode - The largest SDNode class.
01994 ///
01995 typedef AtomicSDNode LargestSDNode;
01996 
01997 /// MostAlignedSDNode - The SDNode class with the greatest alignment
01998 /// requirement.
01999 ///
02000 typedef GlobalAddressSDNode MostAlignedSDNode;
02001 
02002 namespace ISD {
02003   /// isNormalLoad - Returns true if the specified node is a non-extending
02004   /// and unindexed load.
02005   inline bool isNormalLoad(const SDNode *N) {
02006     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
02007     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
02008       Ld->getAddressingMode() == ISD::UNINDEXED;
02009   }
02010 
02011   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
02012   /// load.
02013   inline bool isNON_EXTLoad(const SDNode *N) {
02014     return isa<LoadSDNode>(N) &&
02015       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
02016   }
02017 
02018   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
02019   ///
02020   inline bool isEXTLoad(const SDNode *N) {
02021     return isa<LoadSDNode>(N) &&
02022       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
02023   }
02024 
02025   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
02026   ///
02027   inline bool isSEXTLoad(const SDNode *N) {
02028     return isa<LoadSDNode>(N) &&
02029       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
02030   }
02031 
02032   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
02033   ///
02034   inline bool isZEXTLoad(const SDNode *N) {
02035     return isa<LoadSDNode>(N) &&
02036       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
02037   }
02038 
02039   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
02040   ///
02041   inline bool isUNINDEXEDLoad(const SDNode *N) {
02042     return isa<LoadSDNode>(N) &&
02043       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
02044   }
02045 
02046   /// isNormalStore - Returns true if the specified node is a non-truncating
02047   /// and unindexed store.
02048   inline bool isNormalStore(const SDNode *N) {
02049     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
02050     return St && !St->isTruncatingStore() &&
02051       St->getAddressingMode() == ISD::UNINDEXED;
02052   }
02053 
02054   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
02055   /// store.
02056   inline bool isNON_TRUNCStore(const SDNode *N) {
02057     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
02058   }
02059 
02060   /// isTRUNCStore - Returns true if the specified node is a truncating
02061   /// store.
02062   inline bool isTRUNCStore(const SDNode *N) {
02063     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
02064   }
02065 
02066   /// isUNINDEXEDStore - Returns true if the specified node is an
02067   /// unindexed store.
02068   inline bool isUNINDEXEDStore(const SDNode *N) {
02069     return isa<StoreSDNode>(N) &&
02070       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
02071   }
02072 }
02073 
02074 } // end llvm namespace
02075 
02076 #endif