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