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