Change TargetLowering::getRegClassFor to take an MVT, instead of EVT.
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAGNodes.h
1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SDNode class and derived classes, which are used to
11 // represent the nodes and operations present in a SelectionDAG.  These nodes
12 // and operations are machine code level operations, with some similarities to
13 // the GCC RTL representation.
14 //
15 // Clients should include the SelectionDAG.h file instead of this file directly.
16 //
17 //===----------------------------------------------------------------------===//
18
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
21
22 #include "llvm/ADT/FoldingSet.h"
23 #include "llvm/ADT/GraphTraits.h"
24 #include "llvm/ADT/STLExtras.h"
25 #include "llvm/ADT/SmallPtrSet.h"
26 #include "llvm/ADT/SmallVector.h"
27 #include "llvm/ADT/ilist_node.h"
28 #include "llvm/CodeGen/ISDOpcodes.h"
29 #include "llvm/CodeGen/MachineMemOperand.h"
30 #include "llvm/CodeGen/ValueTypes.h"
31 #include "llvm/Constants.h"
32 #include "llvm/Instructions.h"
33 #include "llvm/Support/DataTypes.h"
34 #include "llvm/Support/DebugLoc.h"
35 #include "llvm/Support/MathExtras.h"
36 #include <cassert>
37
38 namespace llvm {
39
40 class SelectionDAG;
41 class GlobalValue;
42 class MachineBasicBlock;
43 class MachineConstantPoolValue;
44 class SDNode;
45 class Value;
46 class MCSymbol;
47 template <typename T> struct DenseMapInfo;
48 template <typename T> struct simplify_type;
49 template <typename T> struct ilist_traits;
50
51 void checkForCycles(const SDNode *N);
52   
53 /// SDVTList - This represents a list of ValueType's that has been intern'd by
54 /// a SelectionDAG.  Instances of this simple value class are returned by
55 /// SelectionDAG::getVTList(...).
56 ///
57 struct SDVTList {
58   const EVT *VTs;
59   unsigned int NumVTs;
60 };
61
62 namespace ISD {
63   /// Node predicates
64
65   /// isBuildVectorAllOnes - Return true if the specified node is a
66   /// BUILD_VECTOR where all of the elements are ~0 or undef.
67   bool isBuildVectorAllOnes(const SDNode *N);
68
69   /// isBuildVectorAllZeros - Return true if the specified node is a
70   /// BUILD_VECTOR where all of the elements are 0 or undef.
71   bool isBuildVectorAllZeros(const SDNode *N);
72
73   /// isScalarToVector - Return true if the specified node is a
74   /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
75   /// element is not an undef.
76   bool isScalarToVector(const SDNode *N);
77
78   /// allOperandsUndef - Return true if the node has at least one operand
79   /// and all operands of the specified node are ISD::UNDEF.
80   bool allOperandsUndef(const SDNode *N);
81 }  // end llvm:ISD namespace
82
83 //===----------------------------------------------------------------------===//
84 /// SDValue - Unlike LLVM values, Selection DAG nodes may return multiple
85 /// values as the result of a computation.  Many nodes return multiple values,
86 /// from loads (which define a token and a return value) to ADDC (which returns
87 /// a result and a carry value), to calls (which may return an arbitrary number
88 /// of values).
89 ///
90 /// As such, each use of a SelectionDAG computation must indicate the node that
91 /// computes it as well as which return value to use from that node.  This pair
92 /// of information is represented with the SDValue value type.
93 ///
94 class SDValue {
95   SDNode *Node;       // The node defining the value we are using.
96   unsigned ResNo;     // Which return value of the node we are using.
97 public:
98   SDValue() : Node(0), ResNo(0) {}
99   SDValue(SDNode *node, unsigned resno) : Node(node), ResNo(resno) {}
100
101   /// get the index which selects a specific result in the SDNode
102   unsigned getResNo() const { return ResNo; }
103
104   /// get the SDNode which holds the desired result
105   SDNode *getNode() const { return Node; }
106
107   /// set the SDNode
108   void setNode(SDNode *N) { Node = N; }
109
110   inline SDNode *operator->() const { return Node; }
111   
112   bool operator==(const SDValue &O) const {
113     return Node == O.Node && ResNo == O.ResNo;
114   }
115   bool operator!=(const SDValue &O) const {
116     return !operator==(O);
117   }
118   bool operator<(const SDValue &O) const {
119     return Node < O.Node || (Node == O.Node && ResNo < O.ResNo);
120   }
121
122   SDValue getValue(unsigned R) const {
123     return SDValue(Node, R);
124   }
125
126   // isOperandOf - Return true if this node is an operand of N.
127   bool isOperandOf(SDNode *N) const;
128
129   /// getValueType - Return the ValueType of the referenced return value.
130   ///
131   inline EVT getValueType() const;
132
133   /// Return the simple ValueType of the referenced return value.
134   MVT getSimpleValueType() const {
135     return getValueType().getSimpleVT();
136   }
137
138   /// getValueSizeInBits - Returns the size of the value in bits.
139   ///
140   unsigned getValueSizeInBits() const {
141     return getValueType().getSizeInBits();
142   }
143
144   // Forwarding methods - These forward to the corresponding methods in SDNode.
145   inline unsigned getOpcode() const;
146   inline unsigned getNumOperands() const;
147   inline const SDValue &getOperand(unsigned i) const;
148   inline uint64_t getConstantOperandVal(unsigned i) const;
149   inline bool isTargetMemoryOpcode() const;
150   inline bool isTargetOpcode() const;
151   inline bool isMachineOpcode() const;
152   inline unsigned getMachineOpcode() const;
153   inline const DebugLoc getDebugLoc() const;
154   inline void dump() const;
155   inline void dumpr() const;
156
157   /// reachesChainWithoutSideEffects - Return true if this operand (which must
158   /// be a chain) reaches the specified operand without crossing any
159   /// side-effecting instructions.  In practice, this looks through token
160   /// factors and non-volatile loads.  In order to remain efficient, this only
161   /// looks a couple of nodes in, it does not do an exhaustive search.
162   bool reachesChainWithoutSideEffects(SDValue Dest,
163                                       unsigned Depth = 2) const;
164
165   /// use_empty - Return true if there are no nodes using value ResNo
166   /// of Node.
167   ///
168   inline bool use_empty() const;
169
170   /// hasOneUse - Return true if there is exactly one node using value
171   /// ResNo of Node.
172   ///
173   inline bool hasOneUse() const;
174 };
175
176
177 template<> struct DenseMapInfo<SDValue> {
178   static inline SDValue getEmptyKey() {
179     return SDValue((SDNode*)-1, -1U);
180   }
181   static inline SDValue getTombstoneKey() {
182     return SDValue((SDNode*)-1, 0);
183   }
184   static unsigned getHashValue(const SDValue &Val) {
185     return ((unsigned)((uintptr_t)Val.getNode() >> 4) ^
186             (unsigned)((uintptr_t)Val.getNode() >> 9)) + Val.getResNo();
187   }
188   static bool isEqual(const SDValue &LHS, const SDValue &RHS) {
189     return LHS == RHS;
190   }
191 };
192 template <> struct isPodLike<SDValue> { static const bool value = true; };
193
194
195 /// simplify_type specializations - Allow casting operators to work directly on
196 /// SDValues as if they were SDNode*'s.
197 template<> struct simplify_type<SDValue> {
198   typedef SDNode* SimpleType;
199   static SimpleType getSimplifiedValue(const SDValue &Val) {
200     return static_cast<SimpleType>(Val.getNode());
201   }
202 };
203 template<> struct simplify_type<const SDValue> {
204   typedef SDNode* SimpleType;
205   static SimpleType getSimplifiedValue(const SDValue &Val) {
206     return static_cast<SimpleType>(Val.getNode());
207   }
208 };
209
210 /// SDUse - Represents a use of a SDNode. This class holds an SDValue,
211 /// which records the SDNode being used and the result number, a
212 /// pointer to the SDNode using the value, and Next and Prev pointers,
213 /// which link together all the uses of an SDNode.
214 ///
215 class SDUse {
216   /// Val - The value being used.
217   SDValue Val;
218   /// User - The user of this value.
219   SDNode *User;
220   /// Prev, Next - Pointers to the uses list of the SDNode referred by
221   /// this operand.
222   SDUse **Prev, *Next;
223
224   SDUse(const SDUse &U) LLVM_DELETED_FUNCTION;
225   void operator=(const SDUse &U) LLVM_DELETED_FUNCTION;
226
227 public:
228   SDUse() : Val(), User(NULL), Prev(NULL), Next(NULL) {}
229
230   /// Normally SDUse will just implicitly convert to an SDValue that it holds.
231   operator const SDValue&() const { return Val; }
232
233   /// If implicit conversion to SDValue doesn't work, the get() method returns
234   /// the SDValue.
235   const SDValue &get() const { return Val; }
236
237   /// getUser - This returns the SDNode that contains this Use.
238   SDNode *getUser() { return User; }
239
240   /// getNext - Get the next SDUse in the use list.
241   SDUse *getNext() const { return Next; }
242
243   /// getNode - Convenience function for get().getNode().
244   SDNode *getNode() const { return Val.getNode(); }
245   /// getResNo - Convenience function for get().getResNo().
246   unsigned getResNo() const { return Val.getResNo(); }
247   /// getValueType - Convenience function for get().getValueType().
248   EVT getValueType() const { return Val.getValueType(); }
249
250   /// operator== - Convenience function for get().operator==
251   bool operator==(const SDValue &V) const {
252     return Val == V;
253   }
254
255   /// operator!= - Convenience function for get().operator!=
256   bool operator!=(const SDValue &V) const {
257     return Val != V;
258   }
259
260   /// operator< - Convenience function for get().operator<
261   bool operator<(const SDValue &V) const {
262     return Val < V;
263   }
264
265 private:
266   friend class SelectionDAG;
267   friend class SDNode;
268
269   void setUser(SDNode *p) { User = p; }
270
271   /// set - Remove this use from its existing use list, assign it the
272   /// given value, and add it to the new value's node's use list.
273   inline void set(const SDValue &V);
274   /// setInitial - like set, but only supports initializing a newly-allocated
275   /// SDUse with a non-null value.
276   inline void setInitial(const SDValue &V);
277   /// setNode - like set, but only sets the Node portion of the value,
278   /// leaving the ResNo portion unmodified.
279   inline void setNode(SDNode *N);
280
281   void addToList(SDUse **List) {
282     Next = *List;
283     if (Next) Next->Prev = &Next;
284     Prev = List;
285     *List = this;
286   }
287
288   void removeFromList() {
289     *Prev = Next;
290     if (Next) Next->Prev = Prev;
291   }
292 };
293
294 /// simplify_type specializations - Allow casting operators to work directly on
295 /// SDValues as if they were SDNode*'s.
296 template<> struct simplify_type<SDUse> {
297   typedef SDNode* SimpleType;
298   static SimpleType getSimplifiedValue(const SDUse &Val) {
299     return static_cast<SimpleType>(Val.getNode());
300   }
301 };
302 template<> struct simplify_type<const SDUse> {
303   typedef SDNode* SimpleType;
304   static SimpleType getSimplifiedValue(const SDUse &Val) {
305     return static_cast<SimpleType>(Val.getNode());
306   }
307 };
308
309
310 /// SDNode - Represents one node in the SelectionDAG.
311 ///
312 class SDNode : public FoldingSetNode, public ilist_node<SDNode> {
313 private:
314   /// NodeType - The operation that this node performs.
315   ///
316   int16_t NodeType;
317
318   /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
319   /// then they will be delete[]'d when the node is destroyed.
320   uint16_t OperandsNeedDelete : 1;
321
322   /// HasDebugValue - This tracks whether this node has one or more dbg_value
323   /// nodes corresponding to it.
324   uint16_t HasDebugValue : 1;
325
326 protected:
327   /// SubclassData - This member is defined by this class, but is not used for
328   /// anything.  Subclasses can use it to hold whatever state they find useful.
329   /// This field is initialized to zero by the ctor.
330   uint16_t SubclassData : 14;
331
332 private:
333   /// NodeId - Unique id per SDNode in the DAG.
334   int NodeId;
335
336   /// OperandList - The values that are used by this operation.
337   ///
338   SDUse *OperandList;
339
340   /// ValueList - The types of the values this node defines.  SDNode's may
341   /// define multiple values simultaneously.
342   const EVT *ValueList;
343
344   /// UseList - List of uses for this SDNode.
345   SDUse *UseList;
346
347   /// NumOperands/NumValues - The number of entries in the Operand/Value list.
348   unsigned short NumOperands, NumValues;
349
350   /// debugLoc - source line information.
351   DebugLoc debugLoc;
352
353   /// getValueTypeList - Return a pointer to the specified value type.
354   static const EVT *getValueTypeList(EVT VT);
355
356   friend class SelectionDAG;
357   friend struct ilist_traits<SDNode>;
358
359 public:
360   //===--------------------------------------------------------------------===//
361   //  Accessors
362   //
363
364   /// getOpcode - Return the SelectionDAG opcode value for this node. For
365   /// pre-isel nodes (those for which isMachineOpcode returns false), these
366   /// are the opcode values in the ISD and <target>ISD namespaces. For
367   /// post-isel opcodes, see getMachineOpcode.
368   unsigned getOpcode()  const { return (unsigned short)NodeType; }
369
370   /// isTargetOpcode - Test if this node has a target-specific opcode (in the
371   /// \<target\>ISD namespace).
372   bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
373
374   /// isTargetMemoryOpcode - Test if this node has a target-specific 
375   /// memory-referencing opcode (in the \<target\>ISD namespace and
376   /// greater than FIRST_TARGET_MEMORY_OPCODE).
377   bool isTargetMemoryOpcode() const {
378     return NodeType >= ISD::FIRST_TARGET_MEMORY_OPCODE;
379   }
380
381   /// isMachineOpcode - Test if this node has a post-isel opcode, directly
382   /// corresponding to a MachineInstr opcode.
383   bool isMachineOpcode() const { return NodeType < 0; }
384
385   /// getMachineOpcode - This may only be called if isMachineOpcode returns
386   /// true. It returns the MachineInstr opcode value that the node's opcode
387   /// corresponds to.
388   unsigned getMachineOpcode() const {
389     assert(isMachineOpcode() && "Not a MachineInstr opcode!");
390     return ~NodeType;
391   }
392
393   /// getHasDebugValue - get this bit.
394   bool getHasDebugValue() const { return HasDebugValue; }
395
396   /// setHasDebugValue - set this bit.
397   void setHasDebugValue(bool b) { HasDebugValue = b; }
398
399   /// use_empty - Return true if there are no uses of this node.
400   ///
401   bool use_empty() const { return UseList == NULL; }
402
403   /// hasOneUse - Return true if there is exactly one use of this node.
404   ///
405   bool hasOneUse() const {
406     return !use_empty() && llvm::next(use_begin()) == use_end();
407   }
408
409   /// use_size - Return the number of uses of this node. This method takes
410   /// time proportional to the number of uses.
411   ///
412   size_t use_size() const { return std::distance(use_begin(), use_end()); }
413
414   /// getNodeId - Return the unique node id.
415   ///
416   int getNodeId() const { return NodeId; }
417
418   /// setNodeId - Set unique node id.
419   void setNodeId(int Id) { NodeId = Id; }
420
421   /// getDebugLoc - Return the source location info.
422   const DebugLoc getDebugLoc() const { return debugLoc; }
423
424   /// setDebugLoc - Set source location info.  Try to avoid this, putting
425   /// it in the constructor is preferable.
426   void setDebugLoc(const DebugLoc dl) { debugLoc = dl; }
427
428   /// use_iterator - This class provides iterator support for SDUse
429   /// operands that use a specific SDNode.
430   class use_iterator
431     : public std::iterator<std::forward_iterator_tag, SDUse, ptrdiff_t> {
432     SDUse *Op;
433     explicit use_iterator(SDUse *op) : Op(op) {
434     }
435     friend class SDNode;
436   public:
437     typedef std::iterator<std::forward_iterator_tag,
438                           SDUse, ptrdiff_t>::reference reference;
439     typedef std::iterator<std::forward_iterator_tag,
440                           SDUse, ptrdiff_t>::pointer pointer;
441
442     use_iterator(const use_iterator &I) : Op(I.Op) {}
443     use_iterator() : Op(0) {}
444
445     bool operator==(const use_iterator &x) const {
446       return Op == x.Op;
447     }
448     bool operator!=(const use_iterator &x) const {
449       return !operator==(x);
450     }
451
452     /// atEnd - return true if this iterator is at the end of uses list.
453     bool atEnd() const { return Op == 0; }
454
455     // Iterator traversal: forward iteration only.
456     use_iterator &operator++() {          // Preincrement
457       assert(Op && "Cannot increment end iterator!");
458       Op = Op->getNext();
459       return *this;
460     }
461
462     use_iterator operator++(int) {        // Postincrement
463       use_iterator tmp = *this; ++*this; return tmp;
464     }
465
466     /// Retrieve a pointer to the current user node.
467     SDNode *operator*() const {
468       assert(Op && "Cannot dereference end iterator!");
469       return Op->getUser();
470     }
471
472     SDNode *operator->() const { return operator*(); }
473
474     SDUse &getUse() const { return *Op; }
475
476     /// getOperandNo - Retrieve the operand # of this use in its user.
477     ///
478     unsigned getOperandNo() const {
479       assert(Op && "Cannot dereference end iterator!");
480       return (unsigned)(Op - Op->getUser()->OperandList);
481     }
482   };
483
484   /// use_begin/use_end - Provide iteration support to walk over all uses
485   /// of an SDNode.
486
487   use_iterator use_begin() const {
488     return use_iterator(UseList);
489   }
490
491   static use_iterator use_end() { return use_iterator(0); }
492
493
494   /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
495   /// indicated value.  This method ignores uses of other values defined by this
496   /// operation.
497   bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
498
499   /// hasAnyUseOfValue - Return true if there are any use of the indicated
500   /// value. This method ignores uses of other values defined by this operation.
501   bool hasAnyUseOfValue(unsigned Value) const;
502
503   /// isOnlyUserOf - Return true if this node is the only use of N.
504   ///
505   bool isOnlyUserOf(SDNode *N) const;
506
507   /// isOperandOf - Return true if this node is an operand of N.
508   ///
509   bool isOperandOf(SDNode *N) const;
510
511   /// isPredecessorOf - Return true if this node is a predecessor of N.
512   /// NOTE: Implemented on top of hasPredecessor and every bit as
513   /// expensive. Use carefully.
514   bool isPredecessorOf(const SDNode *N) const { return N->hasPredecessor(this); }
515
516   /// hasPredecessor - Return true if N is a predecessor of this node.
517   /// N is either an operand of this node, or can be reached by recursively
518   /// traversing up the operands.
519   /// NOTE: This is an expensive method. Use it carefully.
520   bool hasPredecessor(const SDNode *N) const;
521
522   /// hasPredecesorHelper - Return true if N is a predecessor of this node.
523   /// N is either an operand of this node, or can be reached by recursively
524   /// traversing up the operands.
525   /// In this helper the Visited and worklist sets are held externally to
526   /// cache predecessors over multiple invocations. If you want to test for
527   /// multiple predecessors this method is preferable to multiple calls to
528   /// hasPredecessor. Be sure to clear Visited and Worklist if the DAG
529   /// changes.
530   /// NOTE: This is still very expensive. Use carefully.
531   bool hasPredecessorHelper(const SDNode *N,
532                             SmallPtrSet<const SDNode *, 32> &Visited,
533                             SmallVector<const SDNode *, 16> &Worklist) const; 
534
535   /// getNumOperands - Return the number of values used by this operation.
536   ///
537   unsigned getNumOperands() const { return NumOperands; }
538
539   /// getConstantOperandVal - Helper method returns the integer value of a
540   /// ConstantSDNode operand.
541   uint64_t getConstantOperandVal(unsigned Num) const;
542
543   const SDValue &getOperand(unsigned Num) const {
544     assert(Num < NumOperands && "Invalid child # of SDNode!");
545     return OperandList[Num];
546   }
547
548   typedef SDUse* op_iterator;
549   op_iterator op_begin() const { return OperandList; }
550   op_iterator op_end() const { return OperandList+NumOperands; }
551
552   SDVTList getVTList() const {
553     SDVTList X = { ValueList, NumValues };
554     return X;
555   }
556
557   /// getGluedNode - If this node has a glue operand, return the node
558   /// to which the glue operand points. Otherwise return NULL.
559   SDNode *getGluedNode() const {
560     if (getNumOperands() != 0 &&
561       getOperand(getNumOperands()-1).getValueType() == MVT::Glue)
562       return getOperand(getNumOperands()-1).getNode();
563     return 0;
564   }
565
566   // If this is a pseudo op, like copyfromreg, look to see if there is a
567   // real target node glued to it.  If so, return the target node.
568   const SDNode *getGluedMachineNode() const {
569     const SDNode *FoundNode = this;
570
571     // Climb up glue edges until a machine-opcode node is found, or the
572     // end of the chain is reached.
573     while (!FoundNode->isMachineOpcode()) {
574       const SDNode *N = FoundNode->getGluedNode();
575       if (!N) break;
576       FoundNode = N;
577     }
578
579     return FoundNode;
580   }
581
582   /// getGluedUser - If this node has a glue value with a user, return
583   /// the user (there is at most one). Otherwise return NULL.
584   SDNode *getGluedUser() const {
585     for (use_iterator UI = use_begin(), UE = use_end(); UI != UE; ++UI)
586       if (UI.getUse().get().getValueType() == MVT::Glue)
587         return *UI;
588     return 0;
589   }
590
591   /// getNumValues - Return the number of values defined/returned by this
592   /// operator.
593   ///
594   unsigned getNumValues() const { return NumValues; }
595
596   /// getValueType - Return the type of a specified result.
597   ///
598   EVT getValueType(unsigned ResNo) const {
599     assert(ResNo < NumValues && "Illegal result number!");
600     return ValueList[ResNo];
601   }
602
603   /// Return the type of a specified result as a simple type.
604   ///
605   MVT getSimpleValueType(unsigned ResNo) const {
606     return getValueType(ResNo).getSimpleVT();
607   }
608
609   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
610   ///
611   unsigned getValueSizeInBits(unsigned ResNo) const {
612     return getValueType(ResNo).getSizeInBits();
613   }
614
615   typedef const EVT* value_iterator;
616   value_iterator value_begin() const { return ValueList; }
617   value_iterator value_end() const { return ValueList+NumValues; }
618
619   /// getOperationName - Return the opcode of this operation for printing.
620   ///
621   std::string getOperationName(const SelectionDAG *G = 0) const;
622   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
623   void print_types(raw_ostream &OS, const SelectionDAG *G) const;
624   void print_details(raw_ostream &OS, const SelectionDAG *G) const;
625   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
626   void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
627
628   /// printrFull - Print a SelectionDAG node and all children down to
629   /// the leaves.  The given SelectionDAG allows target-specific nodes
630   /// to be printed in human-readable form.  Unlike printr, this will
631   /// print the whole DAG, including children that appear multiple
632   /// times.
633   ///
634   void printrFull(raw_ostream &O, const SelectionDAG *G = 0) const;
635
636   /// printrWithDepth - Print a SelectionDAG node and children up to
637   /// depth "depth."  The given SelectionDAG allows target-specific
638   /// nodes to be printed in human-readable form.  Unlike printr, this
639   /// will print children that appear multiple times wherever they are
640   /// used.
641   ///
642   void printrWithDepth(raw_ostream &O, const SelectionDAG *G = 0,
643                        unsigned depth = 100) const;
644
645
646   /// dump - Dump this node, for debugging.
647   void dump() const;
648
649   /// dumpr - Dump (recursively) this node and its use-def subgraph.
650   void dumpr() const;
651
652   /// dump - Dump this node, for debugging.
653   /// The given SelectionDAG allows target-specific nodes to be printed
654   /// in human-readable form.
655   void dump(const SelectionDAG *G) const;
656
657   /// dumpr - Dump (recursively) this node and its use-def subgraph.
658   /// The given SelectionDAG allows target-specific nodes to be printed
659   /// in human-readable form.
660   void dumpr(const SelectionDAG *G) const;
661
662   /// dumprFull - printrFull to dbgs().  The given SelectionDAG allows
663   /// target-specific nodes to be printed in human-readable form.
664   /// Unlike dumpr, this will print the whole DAG, including children
665   /// that appear multiple times.
666   ///
667   void dumprFull(const SelectionDAG *G = 0) const;
668
669   /// dumprWithDepth - printrWithDepth to dbgs().  The given
670   /// SelectionDAG allows target-specific nodes to be printed in
671   /// human-readable form.  Unlike dumpr, this will print children
672   /// that appear multiple times wherever they are used.
673   ///
674   void dumprWithDepth(const SelectionDAG *G = 0, unsigned depth = 100) const;
675
676   /// Profile - Gather unique data for the node.
677   ///
678   void Profile(FoldingSetNodeID &ID) const;
679
680   /// addUse - This method should only be used by the SDUse class.
681   ///
682   void addUse(SDUse &U) { U.addToList(&UseList); }
683
684 protected:
685   static SDVTList getSDVTList(EVT VT) {
686     SDVTList Ret = { getValueTypeList(VT), 1 };
687     return Ret;
688   }
689
690   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
691          unsigned NumOps)
692     : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
693       SubclassData(0), NodeId(-1),
694       OperandList(NumOps ? new SDUse[NumOps] : 0),
695       ValueList(VTs.VTs), UseList(NULL),
696       NumOperands(NumOps), NumValues(VTs.NumVTs),
697       debugLoc(dl) {
698     for (unsigned i = 0; i != NumOps; ++i) {
699       OperandList[i].setUser(this);
700       OperandList[i].setInitial(Ops[i]);
701     }
702     checkForCycles(this);
703   }
704
705   /// This constructor adds no operands itself; operands can be
706   /// set later with InitOperands.
707   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
708     : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
709       SubclassData(0), NodeId(-1), OperandList(0), ValueList(VTs.VTs),
710       UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs),
711       debugLoc(dl) {}
712
713   /// InitOperands - Initialize the operands list of this with 1 operand.
714   void InitOperands(SDUse *Ops, const SDValue &Op0) {
715     Ops[0].setUser(this);
716     Ops[0].setInitial(Op0);
717     NumOperands = 1;
718     OperandList = Ops;
719     checkForCycles(this);
720   }
721
722   /// InitOperands - Initialize the operands list of this with 2 operands.
723   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
724     Ops[0].setUser(this);
725     Ops[0].setInitial(Op0);
726     Ops[1].setUser(this);
727     Ops[1].setInitial(Op1);
728     NumOperands = 2;
729     OperandList = Ops;
730     checkForCycles(this);
731   }
732
733   /// InitOperands - Initialize the operands list of this with 3 operands.
734   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
735                     const SDValue &Op2) {
736     Ops[0].setUser(this);
737     Ops[0].setInitial(Op0);
738     Ops[1].setUser(this);
739     Ops[1].setInitial(Op1);
740     Ops[2].setUser(this);
741     Ops[2].setInitial(Op2);
742     NumOperands = 3;
743     OperandList = Ops;
744     checkForCycles(this);
745   }
746
747   /// InitOperands - Initialize the operands list of this with 4 operands.
748   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
749                     const SDValue &Op2, const SDValue &Op3) {
750     Ops[0].setUser(this);
751     Ops[0].setInitial(Op0);
752     Ops[1].setUser(this);
753     Ops[1].setInitial(Op1);
754     Ops[2].setUser(this);
755     Ops[2].setInitial(Op2);
756     Ops[3].setUser(this);
757     Ops[3].setInitial(Op3);
758     NumOperands = 4;
759     OperandList = Ops;
760     checkForCycles(this);
761   }
762
763   /// InitOperands - Initialize the operands list of this with N operands.
764   void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
765     for (unsigned i = 0; i != N; ++i) {
766       Ops[i].setUser(this);
767       Ops[i].setInitial(Vals[i]);
768     }
769     NumOperands = N;
770     OperandList = Ops;
771     checkForCycles(this);
772   }
773
774   /// DropOperands - Release the operands and set this node to have
775   /// zero operands.
776   void DropOperands();
777 };
778
779
780 // Define inline functions from the SDValue class.
781
782 inline unsigned SDValue::getOpcode() const {
783   return Node->getOpcode();
784 }
785 inline EVT SDValue::getValueType() const {
786   return Node->getValueType(ResNo);
787 }
788 inline unsigned SDValue::getNumOperands() const {
789   return Node->getNumOperands();
790 }
791 inline const SDValue &SDValue::getOperand(unsigned i) const {
792   return Node->getOperand(i);
793 }
794 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
795   return Node->getConstantOperandVal(i);
796 }
797 inline bool SDValue::isTargetOpcode() const {
798   return Node->isTargetOpcode();
799 }
800 inline bool SDValue::isTargetMemoryOpcode() const {
801   return Node->isTargetMemoryOpcode();
802 }
803 inline bool SDValue::isMachineOpcode() const {
804   return Node->isMachineOpcode();
805 }
806 inline unsigned SDValue::getMachineOpcode() const {
807   return Node->getMachineOpcode();
808 }
809 inline bool SDValue::use_empty() const {
810   return !Node->hasAnyUseOfValue(ResNo);
811 }
812 inline bool SDValue::hasOneUse() const {
813   return Node->hasNUsesOfValue(1, ResNo);
814 }
815 inline const DebugLoc SDValue::getDebugLoc() const {
816   return Node->getDebugLoc();
817 }
818 inline void SDValue::dump() const {
819   return Node->dump();
820 }
821 inline void SDValue::dumpr() const {
822   return Node->dumpr();
823 }
824 // Define inline functions from the SDUse class.
825
826 inline void SDUse::set(const SDValue &V) {
827   if (Val.getNode()) removeFromList();
828   Val = V;
829   if (V.getNode()) V.getNode()->addUse(*this);
830 }
831
832 inline void SDUse::setInitial(const SDValue &V) {
833   Val = V;
834   V.getNode()->addUse(*this);
835 }
836
837 inline void SDUse::setNode(SDNode *N) {
838   if (Val.getNode()) removeFromList();
839   Val.setNode(N);
840   if (N) N->addUse(*this);
841 }
842
843 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
844 /// to allow co-allocation of node operands with the node itself.
845 class UnarySDNode : public SDNode {
846   SDUse Op;
847 public:
848   UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
849     : SDNode(Opc, dl, VTs) {
850     InitOperands(&Op, X);
851   }
852 };
853
854 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
855 /// to allow co-allocation of node operands with the node itself.
856 class BinarySDNode : public SDNode {
857   SDUse Ops[2];
858 public:
859   BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
860     : SDNode(Opc, dl, VTs) {
861     InitOperands(Ops, X, Y);
862   }
863 };
864
865 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
866 /// to allow co-allocation of node operands with the node itself.
867 class TernarySDNode : public SDNode {
868   SDUse Ops[3];
869 public:
870   TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
871                 SDValue Z)
872     : SDNode(Opc, dl, VTs) {
873     InitOperands(Ops, X, Y, Z);
874   }
875 };
876
877
878 /// HandleSDNode - This class is used to form a handle around another node that
879 /// is persistent and is updated across invocations of replaceAllUsesWith on its
880 /// operand.  This node should be directly created by end-users and not added to
881 /// the AllNodes list.
882 class HandleSDNode : public SDNode {
883   SDUse Op;
884 public:
885   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
886   // fixed.
887 #if __GNUC__==4 && __GNUC_MINOR__==2 && defined(__APPLE__) && !defined(__llvm__)
888   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
889 #else
890   explicit HandleSDNode(SDValue X)
891 #endif
892     : SDNode(ISD::HANDLENODE, DebugLoc(), getSDVTList(MVT::Other)) {
893     InitOperands(&Op, X);
894   }
895   ~HandleSDNode();
896   const SDValue &getValue() const { return Op; }
897 };
898
899 /// Abstact virtual class for operations for memory operations
900 class MemSDNode : public SDNode {
901 private:
902   // MemoryVT - VT of in-memory value.
903   EVT MemoryVT;
904
905 protected:
906   /// MMO - Memory reference information.
907   MachineMemOperand *MMO;
908
909 public:
910   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
911             MachineMemOperand *MMO);
912
913   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
914             unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
915
916   bool readMem() const { return MMO->isLoad(); }
917   bool writeMem() const { return MMO->isStore(); }
918
919   /// Returns alignment and volatility of the memory access
920   unsigned getOriginalAlignment() const { 
921     return MMO->getBaseAlignment();
922   }
923   unsigned getAlignment() const {
924     return MMO->getAlignment();
925   }
926
927   /// getRawSubclassData - Return the SubclassData value, which contains an
928   /// encoding of the volatile flag, as well as bits used by subclasses. This
929   /// function should only be used to compute a FoldingSetNodeID value.
930   unsigned getRawSubclassData() const {
931     return SubclassData;
932   }
933
934   // We access subclass data here so that we can check consistency
935   // with MachineMemOperand information.
936   bool isVolatile() const { return (SubclassData >> 5) & 1; }
937   bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
938   bool isInvariant() const { return (SubclassData >> 7) & 1; }
939
940   AtomicOrdering getOrdering() const {
941     return AtomicOrdering((SubclassData >> 8) & 15);
942   }
943   SynchronizationScope getSynchScope() const {
944     return SynchronizationScope((SubclassData >> 12) & 1);
945   }
946
947   /// Returns the SrcValue and offset that describes the location of the access
948   const Value *getSrcValue() const { return MMO->getValue(); }
949   int64_t getSrcValueOffset() const { return MMO->getOffset(); }
950
951   /// Returns the TBAAInfo that describes the dereference.
952   const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
953
954   /// Returns the Ranges that describes the dereference.
955   const MDNode *getRanges() const { return MMO->getRanges(); }
956
957   /// getMemoryVT - Return the type of the in-memory value.
958   EVT getMemoryVT() const { return MemoryVT; }
959
960   /// getMemOperand - Return a MachineMemOperand object describing the memory
961   /// reference performed by operation.
962   MachineMemOperand *getMemOperand() const { return MMO; }
963
964   const MachinePointerInfo &getPointerInfo() const {
965     return MMO->getPointerInfo();
966   }
967
968   /// getAddressSpace - Return the address space for the associated pointer
969   unsigned getAddressSpace() const {
970     return getPointerInfo().getAddrSpace();
971   }
972
973   /// refineAlignment - Update this MemSDNode's MachineMemOperand information
974   /// to reflect the alignment of NewMMO, if it has a greater alignment.
975   /// This must only be used when the new alignment applies to all users of
976   /// this MachineMemOperand.
977   void refineAlignment(const MachineMemOperand *NewMMO) {
978     MMO->refineAlignment(NewMMO);
979   }
980
981   const SDValue &getChain() const { return getOperand(0); }
982   const SDValue &getBasePtr() const {
983     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
984   }
985
986   // Methods to support isa and dyn_cast
987   static bool classof(const SDNode *N) {
988     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
989     // with either an intrinsic or a target opcode.
990     return N->getOpcode() == ISD::LOAD                ||
991            N->getOpcode() == ISD::STORE               ||
992            N->getOpcode() == ISD::PREFETCH            ||
993            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
994            N->getOpcode() == ISD::ATOMIC_SWAP         ||
995            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
996            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
997            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
998            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
999            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1000            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1001            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1002            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1003            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1004            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
1005            N->getOpcode() == ISD::ATOMIC_LOAD         ||
1006            N->getOpcode() == ISD::ATOMIC_STORE        ||
1007            N->isTargetMemoryOpcode();
1008   }
1009 };
1010
1011 /// AtomicSDNode - A SDNode reprenting atomic operations.
1012 ///
1013 class AtomicSDNode : public MemSDNode {
1014   SDUse Ops[4];
1015
1016   void InitAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope) {
1017     // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1018     assert((Ordering & 15) == Ordering &&
1019            "Ordering may not require more than 4 bits!");
1020     assert((SynchScope & 1) == SynchScope &&
1021            "SynchScope may not require more than 1 bit!");
1022     SubclassData |= Ordering << 8;
1023     SubclassData |= SynchScope << 12;
1024     assert(getOrdering() == Ordering && "Ordering encoding error!");
1025     assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1026   }
1027
1028 public:
1029   // Opc:   opcode for atomic
1030   // VTL:    value type list
1031   // Chain:  memory chain for operaand
1032   // Ptr:    address to update as a SDValue
1033   // Cmp:    compare value
1034   // Swp:    swap value
1035   // SrcVal: address to update as a Value (used for MemOperand)
1036   // Align:  alignment of memory
1037   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1038                SDValue Chain, SDValue Ptr,
1039                SDValue Cmp, SDValue Swp, MachineMemOperand *MMO,
1040                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1041     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1042     InitAtomic(Ordering, SynchScope);
1043     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1044   }
1045   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1046                SDValue Chain, SDValue Ptr,
1047                SDValue Val, MachineMemOperand *MMO,
1048                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1049     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1050     InitAtomic(Ordering, SynchScope);
1051     InitOperands(Ops, Chain, Ptr, Val);
1052   }
1053   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1054                SDValue Chain, SDValue Ptr,
1055                MachineMemOperand *MMO,
1056                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1057     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1058     InitAtomic(Ordering, SynchScope);
1059     InitOperands(Ops, Chain, Ptr);
1060   }
1061
1062   const SDValue &getBasePtr() const { return getOperand(1); }
1063   const SDValue &getVal() const { return getOperand(2); }
1064
1065   bool isCompareAndSwap() const {
1066     unsigned Op = getOpcode();
1067     return Op == ISD::ATOMIC_CMP_SWAP;
1068   }
1069
1070   // Methods to support isa and dyn_cast
1071   static bool classof(const SDNode *N) {
1072     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1073            N->getOpcode() == ISD::ATOMIC_SWAP         ||
1074            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1075            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1076            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1077            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1078            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1079            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1080            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1081            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1082            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1083            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
1084            N->getOpcode() == ISD::ATOMIC_LOAD         ||
1085            N->getOpcode() == ISD::ATOMIC_STORE;
1086   }
1087 };
1088
1089 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1090 /// memory and need an associated MachineMemOperand. Its opcode may be
1091 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1092 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1093 class MemIntrinsicSDNode : public MemSDNode {
1094 public:
1095   MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1096                      const SDValue *Ops, unsigned NumOps,
1097                      EVT MemoryVT, MachineMemOperand *MMO)
1098     : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
1099   }
1100
1101   // Methods to support isa and dyn_cast
1102   static bool classof(const SDNode *N) {
1103     // We lower some target intrinsics to their target opcode
1104     // early a node with a target opcode can be of this class
1105     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1106            N->getOpcode() == ISD::INTRINSIC_VOID ||
1107            N->getOpcode() == ISD::PREFETCH ||
1108            N->isTargetMemoryOpcode();
1109   }
1110 };
1111
1112 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1113 /// support for the llvm IR shufflevector instruction.  It combines elements
1114 /// from two input vectors into a new input vector, with the selection and
1115 /// ordering of elements determined by an array of integers, referred to as
1116 /// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1117 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1118 /// An index of -1 is treated as undef, such that the code generator may put
1119 /// any value in the corresponding element of the result.
1120 class ShuffleVectorSDNode : public SDNode {
1121   SDUse Ops[2];
1122
1123   // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1124   // is freed when the SelectionDAG object is destroyed.
1125   const int *Mask;
1126 protected:
1127   friend class SelectionDAG;
1128   ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2, 
1129                       const int *M)
1130     : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1131     InitOperands(Ops, N1, N2);
1132   }
1133 public:
1134
1135   ArrayRef<int> getMask() const {
1136     EVT VT = getValueType(0);
1137     return makeArrayRef(Mask, VT.getVectorNumElements());
1138   }
1139   int getMaskElt(unsigned Idx) const {
1140     assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1141     return Mask[Idx];
1142   }
1143   
1144   bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1145   int  getSplatIndex() const { 
1146     assert(isSplat() && "Cannot get splat index for non-splat!");
1147     EVT VT = getValueType(0);
1148     for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1149       if (Mask[i] != -1)
1150         return Mask[i];
1151     }
1152     return -1;
1153   }
1154   static bool isSplatMask(const int *Mask, EVT VT);
1155
1156   static bool classof(const SDNode *N) {
1157     return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1158   }
1159 };
1160   
1161 class ConstantSDNode : public SDNode {
1162   const ConstantInt *Value;
1163   friend class SelectionDAG;
1164   ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
1165     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1166              DebugLoc(), getSDVTList(VT)), Value(val) {
1167   }
1168 public:
1169
1170   const ConstantInt *getConstantIntValue() const { return Value; }
1171   const APInt &getAPIntValue() const { return Value->getValue(); }
1172   uint64_t getZExtValue() const { return Value->getZExtValue(); }
1173   int64_t getSExtValue() const { return Value->getSExtValue(); }
1174
1175   bool isOne() const { return Value->isOne(); }
1176   bool isNullValue() const { return Value->isNullValue(); }
1177   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1178
1179   static bool classof(const SDNode *N) {
1180     return N->getOpcode() == ISD::Constant ||
1181            N->getOpcode() == ISD::TargetConstant;
1182   }
1183 };
1184
1185 class ConstantFPSDNode : public SDNode {
1186   const ConstantFP *Value;
1187   friend class SelectionDAG;
1188   ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1189     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1190              DebugLoc(), getSDVTList(VT)), Value(val) {
1191   }
1192 public:
1193
1194   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1195   const ConstantFP *getConstantFPValue() const { return Value; }
1196
1197   /// isZero - Return true if the value is positive or negative zero.
1198   bool isZero() const { return Value->isZero(); }
1199
1200   /// isNaN - Return true if the value is a NaN.
1201   bool isNaN() const { return Value->isNaN(); }
1202
1203   /// isExactlyValue - We don't rely on operator== working on double values, as
1204   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1205   /// As such, this method can be used to do an exact bit-for-bit comparison of
1206   /// two floating point values.
1207
1208   /// We leave the version with the double argument here because it's just so
1209   /// convenient to write "2.0" and the like.  Without this function we'd
1210   /// have to duplicate its logic everywhere it's called.
1211   bool isExactlyValue(double V) const {
1212     bool ignored;
1213     APFloat Tmp(V);
1214     Tmp.convert(Value->getValueAPF().getSemantics(),
1215                 APFloat::rmNearestTiesToEven, &ignored);
1216     return isExactlyValue(Tmp);
1217   }
1218   bool isExactlyValue(const APFloat& V) const;
1219
1220   static bool isValueValidForType(EVT VT, const APFloat& Val);
1221
1222   static bool classof(const SDNode *N) {
1223     return N->getOpcode() == ISD::ConstantFP ||
1224            N->getOpcode() == ISD::TargetConstantFP;
1225   }
1226 };
1227
1228 class GlobalAddressSDNode : public SDNode {
1229   const GlobalValue *TheGlobal;
1230   int64_t Offset;
1231   unsigned char TargetFlags;
1232   friend class SelectionDAG;
1233   GlobalAddressSDNode(unsigned Opc, DebugLoc DL, const GlobalValue *GA, EVT VT,
1234                       int64_t o, unsigned char TargetFlags);
1235 public:
1236
1237   const GlobalValue *getGlobal() const { return TheGlobal; }
1238   int64_t getOffset() const { return Offset; }
1239   unsigned char getTargetFlags() const { return TargetFlags; }
1240   // Return the address space this GlobalAddress belongs to.
1241   unsigned getAddressSpace() const;
1242
1243   static bool classof(const SDNode *N) {
1244     return N->getOpcode() == ISD::GlobalAddress ||
1245            N->getOpcode() == ISD::TargetGlobalAddress ||
1246            N->getOpcode() == ISD::GlobalTLSAddress ||
1247            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1248   }
1249 };
1250
1251 class FrameIndexSDNode : public SDNode {
1252   int FI;
1253   friend class SelectionDAG;
1254   FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1255     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1256       DebugLoc(), getSDVTList(VT)), FI(fi) {
1257   }
1258 public:
1259
1260   int getIndex() const { return FI; }
1261
1262   static bool classof(const SDNode *N) {
1263     return N->getOpcode() == ISD::FrameIndex ||
1264            N->getOpcode() == ISD::TargetFrameIndex;
1265   }
1266 };
1267
1268 class JumpTableSDNode : public SDNode {
1269   int JTI;
1270   unsigned char TargetFlags;
1271   friend class SelectionDAG;
1272   JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1273     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1274       DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1275   }
1276 public:
1277
1278   int getIndex() const { return JTI; }
1279   unsigned char getTargetFlags() const { return TargetFlags; }
1280
1281   static bool classof(const SDNode *N) {
1282     return N->getOpcode() == ISD::JumpTable ||
1283            N->getOpcode() == ISD::TargetJumpTable;
1284   }
1285 };
1286
1287 class ConstantPoolSDNode : public SDNode {
1288   union {
1289     const Constant *ConstVal;
1290     MachineConstantPoolValue *MachineCPVal;
1291   } Val;
1292   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1293   unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1294   unsigned char TargetFlags;
1295   friend class SelectionDAG;
1296   ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1297                      unsigned Align, unsigned char TF)
1298     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1299              DebugLoc(),
1300              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1301     assert((int)Offset >= 0 && "Offset is too large");
1302     Val.ConstVal = c;
1303   }
1304   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1305                      EVT VT, int o, unsigned Align, unsigned char TF)
1306     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1307              DebugLoc(),
1308              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1309     assert((int)Offset >= 0 && "Offset is too large");
1310     Val.MachineCPVal = v;
1311     Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1312   }
1313 public:
1314   
1315
1316   bool isMachineConstantPoolEntry() const {
1317     return (int)Offset < 0;
1318   }
1319
1320   const Constant *getConstVal() const {
1321     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1322     return Val.ConstVal;
1323   }
1324
1325   MachineConstantPoolValue *getMachineCPVal() const {
1326     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1327     return Val.MachineCPVal;
1328   }
1329
1330   int getOffset() const {
1331     return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1332   }
1333
1334   // Return the alignment of this constant pool object, which is either 0 (for
1335   // default alignment) or the desired value.
1336   unsigned getAlignment() const { return Alignment; }
1337   unsigned char getTargetFlags() const { return TargetFlags; }
1338
1339   Type *getType() const;
1340
1341   static bool classof(const SDNode *N) {
1342     return N->getOpcode() == ISD::ConstantPool ||
1343            N->getOpcode() == ISD::TargetConstantPool;
1344   }
1345 };
1346
1347 /// Completely target-dependent object reference.
1348 class TargetIndexSDNode : public SDNode {
1349   unsigned char TargetFlags;
1350   int Index;
1351   int64_t Offset;
1352   friend class SelectionDAG;
1353 public:
1354
1355   TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1356     : SDNode(ISD::TargetIndex, DebugLoc(), getSDVTList(VT)),
1357       TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1358 public:
1359
1360   unsigned char getTargetFlags() const { return TargetFlags; }
1361   int getIndex() const { return Index; }
1362   int64_t getOffset() const { return Offset; }
1363
1364   static bool classof(const SDNode *N) {
1365     return N->getOpcode() == ISD::TargetIndex;
1366   }
1367 };
1368
1369 class BasicBlockSDNode : public SDNode {
1370   MachineBasicBlock *MBB;
1371   friend class SelectionDAG;
1372   /// Debug info is meaningful and potentially useful here, but we create
1373   /// blocks out of order when they're jumped to, which makes it a bit
1374   /// harder.  Let's see if we need it first.
1375   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1376     : SDNode(ISD::BasicBlock, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb) {
1377   }
1378 public:
1379
1380   MachineBasicBlock *getBasicBlock() const { return MBB; }
1381
1382   static bool classof(const SDNode *N) {
1383     return N->getOpcode() == ISD::BasicBlock;
1384   }
1385 };
1386
1387 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1388 /// BUILD_VECTORs.
1389 class BuildVectorSDNode : public SDNode {
1390   // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1391   explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1392 public:
1393   /// isConstantSplat - Check if this is a constant splat, and if so, find the
1394   /// smallest element size that splats the vector.  If MinSplatBits is
1395   /// nonzero, the element size must be at least that large.  Note that the
1396   /// splat element may be the entire vector (i.e., a one element vector).
1397   /// Returns the splat element value in SplatValue.  Any undefined bits in
1398   /// that value are zero, and the corresponding bits in the SplatUndef mask
1399   /// are set.  The SplatBitSize value is set to the splat element size in
1400   /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1401   /// undefined.  isBigEndian describes the endianness of the target.
1402   bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1403                        unsigned &SplatBitSize, bool &HasAnyUndefs,
1404                        unsigned MinSplatBits = 0, bool isBigEndian = false);
1405
1406   static inline bool classof(const SDNode *N) {
1407     return N->getOpcode() == ISD::BUILD_VECTOR;
1408   }
1409 };
1410
1411 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1412 /// used when the SelectionDAG needs to make a simple reference to something
1413 /// in the LLVM IR representation.
1414 ///
1415 class SrcValueSDNode : public SDNode {
1416   const Value *V;
1417   friend class SelectionDAG;
1418   /// Create a SrcValue for a general value.
1419   explicit SrcValueSDNode(const Value *v)
1420     : SDNode(ISD::SRCVALUE, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1421
1422 public:
1423   /// getValue - return the contained Value.
1424   const Value *getValue() const { return V; }
1425
1426   static bool classof(const SDNode *N) {
1427     return N->getOpcode() == ISD::SRCVALUE;
1428   }
1429 };
1430   
1431 class MDNodeSDNode : public SDNode {
1432   const MDNode *MD;
1433   friend class SelectionDAG;
1434   explicit MDNodeSDNode(const MDNode *md)
1435   : SDNode(ISD::MDNODE_SDNODE, DebugLoc(), getSDVTList(MVT::Other)), MD(md) {}
1436 public:
1437   
1438   const MDNode *getMD() const { return MD; }
1439   
1440   static bool classof(const SDNode *N) {
1441     return N->getOpcode() == ISD::MDNODE_SDNODE;
1442   }
1443 };
1444
1445
1446 class RegisterSDNode : public SDNode {
1447   unsigned Reg;
1448   friend class SelectionDAG;
1449   RegisterSDNode(unsigned reg, EVT VT)
1450     : SDNode(ISD::Register, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1451   }
1452 public:
1453
1454   unsigned getReg() const { return Reg; }
1455
1456   static bool classof(const SDNode *N) {
1457     return N->getOpcode() == ISD::Register;
1458   }
1459 };
1460
1461 class RegisterMaskSDNode : public SDNode {
1462   // The memory for RegMask is not owned by the node.
1463   const uint32_t *RegMask;
1464   friend class SelectionDAG;
1465   RegisterMaskSDNode(const uint32_t *mask)
1466     : SDNode(ISD::RegisterMask, DebugLoc(), getSDVTList(MVT::Untyped)),
1467       RegMask(mask) {}
1468 public:
1469
1470   const uint32_t *getRegMask() const { return RegMask; }
1471
1472   static bool classof(const SDNode *N) {
1473     return N->getOpcode() == ISD::RegisterMask;
1474   }
1475 };
1476
1477 class BlockAddressSDNode : public SDNode {
1478   const BlockAddress *BA;
1479   int64_t Offset;
1480   unsigned char TargetFlags;
1481   friend class SelectionDAG;
1482   BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1483                      int64_t o, unsigned char Flags)
1484     : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
1485              BA(ba), Offset(o), TargetFlags(Flags) {
1486   }
1487 public:
1488   const BlockAddress *getBlockAddress() const { return BA; }
1489   int64_t getOffset() const { return Offset; }
1490   unsigned char getTargetFlags() const { return TargetFlags; }
1491
1492   static bool classof(const SDNode *N) {
1493     return N->getOpcode() == ISD::BlockAddress ||
1494            N->getOpcode() == ISD::TargetBlockAddress;
1495   }
1496 };
1497
1498 class EHLabelSDNode : public SDNode {
1499   SDUse Chain;
1500   MCSymbol *Label;
1501   friend class SelectionDAG;
1502   EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
1503     : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
1504     InitOperands(&Chain, ch);
1505   }
1506 public:
1507   MCSymbol *getLabel() const { return Label; }
1508
1509   static bool classof(const SDNode *N) {
1510     return N->getOpcode() == ISD::EH_LABEL;
1511   }
1512 };
1513
1514 class ExternalSymbolSDNode : public SDNode {
1515   const char *Symbol;
1516   unsigned char TargetFlags;
1517   
1518   friend class SelectionDAG;
1519   ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1520     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1521              DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1522   }
1523 public:
1524
1525   const char *getSymbol() const { return Symbol; }
1526   unsigned char getTargetFlags() const { return TargetFlags; }
1527
1528   static bool classof(const SDNode *N) {
1529     return N->getOpcode() == ISD::ExternalSymbol ||
1530            N->getOpcode() == ISD::TargetExternalSymbol;
1531   }
1532 };
1533
1534 class CondCodeSDNode : public SDNode {
1535   ISD::CondCode Condition;
1536   friend class SelectionDAG;
1537   explicit CondCodeSDNode(ISD::CondCode Cond)
1538     : SDNode(ISD::CONDCODE, DebugLoc(), getSDVTList(MVT::Other)),
1539       Condition(Cond) {
1540   }
1541 public:
1542
1543   ISD::CondCode get() const { return Condition; }
1544
1545   static bool classof(const SDNode *N) {
1546     return N->getOpcode() == ISD::CONDCODE;
1547   }
1548 };
1549   
1550 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1551 /// future and most targets don't support it.
1552 class CvtRndSatSDNode : public SDNode {
1553   ISD::CvtCode CvtCode;
1554   friend class SelectionDAG;
1555   explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
1556                            unsigned NumOps, ISD::CvtCode Code)
1557     : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
1558       CvtCode(Code) {
1559     assert(NumOps == 5 && "wrong number of operations");
1560   }
1561 public:
1562   ISD::CvtCode getCvtCode() const { return CvtCode; }
1563
1564   static bool classof(const SDNode *N) {
1565     return N->getOpcode() == ISD::CONVERT_RNDSAT;
1566   }
1567 };
1568
1569 /// VTSDNode - This class is used to represent EVT's, which are used
1570 /// to parameterize some operations.
1571 class VTSDNode : public SDNode {
1572   EVT ValueType;
1573   friend class SelectionDAG;
1574   explicit VTSDNode(EVT VT)
1575     : SDNode(ISD::VALUETYPE, DebugLoc(), getSDVTList(MVT::Other)),
1576       ValueType(VT) {
1577   }
1578 public:
1579
1580   EVT getVT() const { return ValueType; }
1581
1582   static bool classof(const SDNode *N) {
1583     return N->getOpcode() == ISD::VALUETYPE;
1584   }
1585 };
1586
1587 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1588 ///
1589 class LSBaseSDNode : public MemSDNode {
1590   //! Operand array for load and store
1591   /*!
1592     \note Moving this array to the base class captures more
1593     common functionality shared between LoadSDNode and
1594     StoreSDNode
1595    */
1596   SDUse Ops[4];
1597 public:
1598   LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
1599                unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
1600                EVT MemVT, MachineMemOperand *MMO)
1601     : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
1602     SubclassData |= AM << 2;
1603     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1604     InitOperands(Ops, Operands, numOperands);
1605     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1606            "Only indexed loads and stores have a non-undef offset operand");
1607   }
1608
1609   const SDValue &getOffset() const {
1610     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1611   }
1612
1613   /// getAddressingMode - Return the addressing mode for this load or store:
1614   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1615   ISD::MemIndexedMode getAddressingMode() const {
1616     return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1617   }
1618
1619   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1620   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1621
1622   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1623   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1624
1625   static bool classof(const SDNode *N) {
1626     return N->getOpcode() == ISD::LOAD ||
1627            N->getOpcode() == ISD::STORE;
1628   }
1629 };
1630
1631 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1632 ///
1633 class LoadSDNode : public LSBaseSDNode {
1634   friend class SelectionDAG;
1635   LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
1636              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1637              MachineMemOperand *MMO)
1638     : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
1639                    VTs, AM, MemVT, MMO) {
1640     SubclassData |= (unsigned short)ETy;
1641     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1642     assert(readMem() && "Load MachineMemOperand is not a load!");
1643     assert(!writeMem() && "Load MachineMemOperand is a store!");
1644   }
1645 public:
1646
1647   /// getExtensionType - Return whether this is a plain node,
1648   /// or one of the varieties of value-extending loads.
1649   ISD::LoadExtType getExtensionType() const {
1650     return ISD::LoadExtType(SubclassData & 3);
1651   }
1652
1653   const SDValue &getBasePtr() const { return getOperand(1); }
1654   const SDValue &getOffset() const { return getOperand(2); }
1655
1656   static bool classof(const SDNode *N) {
1657     return N->getOpcode() == ISD::LOAD;
1658   }
1659 };
1660
1661 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1662 ///
1663 class StoreSDNode : public LSBaseSDNode {
1664   friend class SelectionDAG;
1665   StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
1666               ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1667               MachineMemOperand *MMO)
1668     : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
1669                    VTs, AM, MemVT, MMO) {
1670     SubclassData |= (unsigned short)isTrunc;
1671     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1672     assert(!readMem() && "Store MachineMemOperand is a load!");
1673     assert(writeMem() && "Store MachineMemOperand is not a store!");
1674   }
1675 public:
1676
1677   /// isTruncatingStore - Return true if the op does a truncation before store.
1678   /// For integers this is the same as doing a TRUNCATE and storing the result.
1679   /// For floats, it is the same as doing an FP_ROUND and storing the result.
1680   bool isTruncatingStore() const { return SubclassData & 1; }
1681
1682   const SDValue &getValue() const { return getOperand(1); }
1683   const SDValue &getBasePtr() const { return getOperand(2); }
1684   const SDValue &getOffset() const { return getOperand(3); }
1685
1686   static bool classof(const SDNode *N) {
1687     return N->getOpcode() == ISD::STORE;
1688   }
1689 };
1690
1691 /// MachineSDNode - An SDNode that represents everything that will be needed
1692 /// to construct a MachineInstr. These nodes are created during the
1693 /// instruction selection proper phase.
1694 ///
1695 class MachineSDNode : public SDNode {
1696 public:
1697   typedef MachineMemOperand **mmo_iterator;
1698
1699 private:
1700   friend class SelectionDAG;
1701   MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
1702     : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
1703
1704   /// LocalOperands - Operands for this instruction, if they fit here. If
1705   /// they don't, this field is unused.
1706   SDUse LocalOperands[4];
1707
1708   /// MemRefs - Memory reference descriptions for this instruction.
1709   mmo_iterator MemRefs;
1710   mmo_iterator MemRefsEnd;
1711
1712 public:
1713   mmo_iterator memoperands_begin() const { return MemRefs; }
1714   mmo_iterator memoperands_end() const { return MemRefsEnd; }
1715   bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
1716
1717   /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
1718   /// list. This does not transfer ownership.
1719   void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1720     for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
1721       assert(*MMI && "Null mem ref detected!");
1722     MemRefs = NewMemRefs;
1723     MemRefsEnd = NewMemRefsEnd;
1724   }
1725
1726   static bool classof(const SDNode *N) {
1727     return N->isMachineOpcode();
1728   }
1729 };
1730
1731 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
1732                                             SDNode, ptrdiff_t> {
1733   const SDNode *Node;
1734   unsigned Operand;
1735
1736   SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1737 public:
1738   bool operator==(const SDNodeIterator& x) const {
1739     return Operand == x.Operand;
1740   }
1741   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1742
1743   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1744     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1745     Operand = I.Operand;
1746     return *this;
1747   }
1748
1749   pointer operator*() const {
1750     return Node->getOperand(Operand).getNode();
1751   }
1752   pointer operator->() const { return operator*(); }
1753
1754   SDNodeIterator& operator++() {                // Preincrement
1755     ++Operand;
1756     return *this;
1757   }
1758   SDNodeIterator operator++(int) { // Postincrement
1759     SDNodeIterator tmp = *this; ++*this; return tmp;
1760   }
1761   size_t operator-(SDNodeIterator Other) const {
1762     assert(Node == Other.Node &&
1763            "Cannot compare iterators of two different nodes!");
1764     return Operand - Other.Operand;
1765   }
1766
1767   static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
1768   static SDNodeIterator end  (const SDNode *N) {
1769     return SDNodeIterator(N, N->getNumOperands());
1770   }
1771
1772   unsigned getOperand() const { return Operand; }
1773   const SDNode *getNode() const { return Node; }
1774 };
1775
1776 template <> struct GraphTraits<SDNode*> {
1777   typedef SDNode NodeType;
1778   typedef SDNodeIterator ChildIteratorType;
1779   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1780   static inline ChildIteratorType child_begin(NodeType *N) {
1781     return SDNodeIterator::begin(N);
1782   }
1783   static inline ChildIteratorType child_end(NodeType *N) {
1784     return SDNodeIterator::end(N);
1785   }
1786 };
1787
1788 /// LargestSDNode - The largest SDNode class.
1789 ///
1790 typedef LoadSDNode LargestSDNode;
1791
1792 /// MostAlignedSDNode - The SDNode class with the greatest alignment
1793 /// requirement.
1794 ///
1795 typedef GlobalAddressSDNode MostAlignedSDNode;
1796
1797 namespace ISD {
1798   /// isNormalLoad - Returns true if the specified node is a non-extending
1799   /// and unindexed load.
1800   inline bool isNormalLoad(const SDNode *N) {
1801     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
1802     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1803       Ld->getAddressingMode() == ISD::UNINDEXED;
1804   }
1805
1806   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1807   /// load.
1808   inline bool isNON_EXTLoad(const SDNode *N) {
1809     return isa<LoadSDNode>(N) &&
1810       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1811   }
1812
1813   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1814   ///
1815   inline bool isEXTLoad(const SDNode *N) {
1816     return isa<LoadSDNode>(N) &&
1817       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1818   }
1819
1820   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1821   ///
1822   inline bool isSEXTLoad(const SDNode *N) {
1823     return isa<LoadSDNode>(N) &&
1824       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1825   }
1826
1827   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1828   ///
1829   inline bool isZEXTLoad(const SDNode *N) {
1830     return isa<LoadSDNode>(N) &&
1831       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1832   }
1833
1834   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
1835   ///
1836   inline bool isUNINDEXEDLoad(const SDNode *N) {
1837     return isa<LoadSDNode>(N) &&
1838       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1839   }
1840
1841   /// isNormalStore - Returns true if the specified node is a non-truncating
1842   /// and unindexed store.
1843   inline bool isNormalStore(const SDNode *N) {
1844     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
1845     return St && !St->isTruncatingStore() &&
1846       St->getAddressingMode() == ISD::UNINDEXED;
1847   }
1848
1849   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1850   /// store.
1851   inline bool isNON_TRUNCStore(const SDNode *N) {
1852     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
1853   }
1854
1855   /// isTRUNCStore - Returns true if the specified node is a truncating
1856   /// store.
1857   inline bool isTRUNCStore(const SDNode *N) {
1858     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
1859   }
1860
1861   /// isUNINDEXEDStore - Returns true if the specified node is an
1862   /// unindexed store.
1863   inline bool isUNINDEXEDStore(const SDNode *N) {
1864     return isa<StoreSDNode>(N) &&
1865       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1866   }
1867 }
1868
1869 } // end llvm namespace
1870
1871 #endif