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