LLVM API Documentation

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