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