Cleanup the simplify_type implementation.
[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/IR/Constants.h"
32 #include "llvm/IR/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(SDValue &Val) {
200     return Val.getNode();
201   }
202 };
203 template<> struct simplify_type<const SDValue> {
204   typedef /*const*/ SDNode* SimpleType;
205   static SimpleType getSimplifiedValue(const SDValue &Val) {
206     return 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(SDUse &Val) {
299     return 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   /// Return the type of a specified result as a simple type.
598   ///
599   MVT getSimpleValueType(unsigned ResNo) const {
600     return getValueType(ResNo).getSimpleVT();
601   }
602
603   /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
604   ///
605   unsigned getValueSizeInBits(unsigned ResNo) const {
606     return getValueType(ResNo).getSizeInBits();
607   }
608
609   typedef const EVT* value_iterator;
610   value_iterator value_begin() const { return ValueList; }
611   value_iterator value_end() const { return ValueList+NumValues; }
612
613   /// getOperationName - Return the opcode of this operation for printing.
614   ///
615   std::string getOperationName(const SelectionDAG *G = 0) const;
616   static const char* getIndexedModeName(ISD::MemIndexedMode AM);
617   void print_types(raw_ostream &OS, const SelectionDAG *G) const;
618   void print_details(raw_ostream &OS, const SelectionDAG *G) const;
619   void print(raw_ostream &OS, const SelectionDAG *G = 0) const;
620   void printr(raw_ostream &OS, const SelectionDAG *G = 0) const;
621
622   /// printrFull - Print a SelectionDAG node and all children down to
623   /// the leaves.  The given SelectionDAG allows target-specific nodes
624   /// to be printed in human-readable form.  Unlike printr, this will
625   /// print the whole DAG, including children that appear multiple
626   /// times.
627   ///
628   void printrFull(raw_ostream &O, const SelectionDAG *G = 0) const;
629
630   /// printrWithDepth - Print a SelectionDAG node and children up to
631   /// depth "depth."  The given SelectionDAG allows target-specific
632   /// nodes to be printed in human-readable form.  Unlike printr, this
633   /// will print children that appear multiple times wherever they are
634   /// used.
635   ///
636   void printrWithDepth(raw_ostream &O, const SelectionDAG *G = 0,
637                        unsigned depth = 100) const;
638
639
640   /// dump - Dump this node, for debugging.
641   void dump() const;
642
643   /// dumpr - Dump (recursively) this node and its use-def subgraph.
644   void dumpr() const;
645
646   /// dump - Dump this node, for debugging.
647   /// The given SelectionDAG allows target-specific nodes to be printed
648   /// in human-readable form.
649   void dump(const SelectionDAG *G) const;
650
651   /// dumpr - Dump (recursively) this node and its use-def subgraph.
652   /// The given SelectionDAG allows target-specific nodes to be printed
653   /// in human-readable form.
654   void dumpr(const SelectionDAG *G) const;
655
656   /// dumprFull - printrFull to dbgs().  The given SelectionDAG allows
657   /// target-specific nodes to be printed in human-readable form.
658   /// Unlike dumpr, this will print the whole DAG, including children
659   /// that appear multiple times.
660   ///
661   void dumprFull(const SelectionDAG *G = 0) const;
662
663   /// dumprWithDepth - printrWithDepth to dbgs().  The given
664   /// SelectionDAG allows target-specific nodes to be printed in
665   /// human-readable form.  Unlike dumpr, this will print children
666   /// that appear multiple times wherever they are used.
667   ///
668   void dumprWithDepth(const SelectionDAG *G = 0, unsigned depth = 100) const;
669
670   /// Profile - Gather unique data for the node.
671   ///
672   void Profile(FoldingSetNodeID &ID) const;
673
674   /// addUse - This method should only be used by the SDUse class.
675   ///
676   void addUse(SDUse &U) { U.addToList(&UseList); }
677
678 protected:
679   static SDVTList getSDVTList(EVT VT) {
680     SDVTList Ret = { getValueTypeList(VT), 1 };
681     return Ret;
682   }
683
684   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs, const SDValue *Ops,
685          unsigned NumOps)
686     : NodeType(Opc), OperandsNeedDelete(true), HasDebugValue(false),
687       SubclassData(0), NodeId(-1),
688       OperandList(NumOps ? new SDUse[NumOps] : 0),
689       ValueList(VTs.VTs), UseList(NULL),
690       NumOperands(NumOps), NumValues(VTs.NumVTs),
691       debugLoc(dl) {
692     for (unsigned i = 0; i != NumOps; ++i) {
693       OperandList[i].setUser(this);
694       OperandList[i].setInitial(Ops[i]);
695     }
696     checkForCycles(this);
697   }
698
699   /// This constructor adds no operands itself; operands can be
700   /// set later with InitOperands.
701   SDNode(unsigned Opc, const DebugLoc dl, SDVTList VTs)
702     : NodeType(Opc), OperandsNeedDelete(false), HasDebugValue(false),
703       SubclassData(0), NodeId(-1), OperandList(0), ValueList(VTs.VTs),
704       UseList(NULL), NumOperands(0), NumValues(VTs.NumVTs),
705       debugLoc(dl) {}
706
707   /// InitOperands - Initialize the operands list of this with 1 operand.
708   void InitOperands(SDUse *Ops, const SDValue &Op0) {
709     Ops[0].setUser(this);
710     Ops[0].setInitial(Op0);
711     NumOperands = 1;
712     OperandList = Ops;
713     checkForCycles(this);
714   }
715
716   /// InitOperands - Initialize the operands list of this with 2 operands.
717   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1) {
718     Ops[0].setUser(this);
719     Ops[0].setInitial(Op0);
720     Ops[1].setUser(this);
721     Ops[1].setInitial(Op1);
722     NumOperands = 2;
723     OperandList = Ops;
724     checkForCycles(this);
725   }
726
727   /// InitOperands - Initialize the operands list of this with 3 operands.
728   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
729                     const SDValue &Op2) {
730     Ops[0].setUser(this);
731     Ops[0].setInitial(Op0);
732     Ops[1].setUser(this);
733     Ops[1].setInitial(Op1);
734     Ops[2].setUser(this);
735     Ops[2].setInitial(Op2);
736     NumOperands = 3;
737     OperandList = Ops;
738     checkForCycles(this);
739   }
740
741   /// InitOperands - Initialize the operands list of this with 4 operands.
742   void InitOperands(SDUse *Ops, const SDValue &Op0, const SDValue &Op1,
743                     const SDValue &Op2, const SDValue &Op3) {
744     Ops[0].setUser(this);
745     Ops[0].setInitial(Op0);
746     Ops[1].setUser(this);
747     Ops[1].setInitial(Op1);
748     Ops[2].setUser(this);
749     Ops[2].setInitial(Op2);
750     Ops[3].setUser(this);
751     Ops[3].setInitial(Op3);
752     NumOperands = 4;
753     OperandList = Ops;
754     checkForCycles(this);
755   }
756
757   /// InitOperands - Initialize the operands list of this with N operands.
758   void InitOperands(SDUse *Ops, const SDValue *Vals, unsigned N) {
759     for (unsigned i = 0; i != N; ++i) {
760       Ops[i].setUser(this);
761       Ops[i].setInitial(Vals[i]);
762     }
763     NumOperands = N;
764     OperandList = Ops;
765     checkForCycles(this);
766   }
767
768   /// DropOperands - Release the operands and set this node to have
769   /// zero operands.
770   void DropOperands();
771 };
772
773
774 // Define inline functions from the SDValue class.
775
776 inline unsigned SDValue::getOpcode() const {
777   return Node->getOpcode();
778 }
779 inline EVT SDValue::getValueType() const {
780   return Node->getValueType(ResNo);
781 }
782 inline unsigned SDValue::getNumOperands() const {
783   return Node->getNumOperands();
784 }
785 inline const SDValue &SDValue::getOperand(unsigned i) const {
786   return Node->getOperand(i);
787 }
788 inline uint64_t SDValue::getConstantOperandVal(unsigned i) const {
789   return Node->getConstantOperandVal(i);
790 }
791 inline bool SDValue::isTargetOpcode() const {
792   return Node->isTargetOpcode();
793 }
794 inline bool SDValue::isTargetMemoryOpcode() const {
795   return Node->isTargetMemoryOpcode();
796 }
797 inline bool SDValue::isMachineOpcode() const {
798   return Node->isMachineOpcode();
799 }
800 inline unsigned SDValue::getMachineOpcode() const {
801   return Node->getMachineOpcode();
802 }
803 inline bool SDValue::use_empty() const {
804   return !Node->hasAnyUseOfValue(ResNo);
805 }
806 inline bool SDValue::hasOneUse() const {
807   return Node->hasNUsesOfValue(1, ResNo);
808 }
809 inline const DebugLoc SDValue::getDebugLoc() const {
810   return Node->getDebugLoc();
811 }
812 inline void SDValue::dump() const {
813   return Node->dump();
814 }
815 inline void SDValue::dumpr() const {
816   return Node->dumpr();
817 }
818 // Define inline functions from the SDUse class.
819
820 inline void SDUse::set(const SDValue &V) {
821   if (Val.getNode()) removeFromList();
822   Val = V;
823   if (V.getNode()) V.getNode()->addUse(*this);
824 }
825
826 inline void SDUse::setInitial(const SDValue &V) {
827   Val = V;
828   V.getNode()->addUse(*this);
829 }
830
831 inline void SDUse::setNode(SDNode *N) {
832   if (Val.getNode()) removeFromList();
833   Val.setNode(N);
834   if (N) N->addUse(*this);
835 }
836
837 /// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
838 /// to allow co-allocation of node operands with the node itself.
839 class UnarySDNode : public SDNode {
840   SDUse Op;
841 public:
842   UnarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X)
843     : SDNode(Opc, dl, VTs) {
844     InitOperands(&Op, X);
845   }
846 };
847
848 /// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
849 /// to allow co-allocation of node operands with the node itself.
850 class BinarySDNode : public SDNode {
851   SDUse Ops[2];
852 public:
853   BinarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y)
854     : SDNode(Opc, dl, VTs) {
855     InitOperands(Ops, X, Y);
856   }
857 };
858
859 /// TernarySDNode - This class is used for three-operand SDNodes. This is solely
860 /// to allow co-allocation of node operands with the node itself.
861 class TernarySDNode : public SDNode {
862   SDUse Ops[3];
863 public:
864   TernarySDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, SDValue X, SDValue Y,
865                 SDValue Z)
866     : SDNode(Opc, dl, VTs) {
867     InitOperands(Ops, X, Y, Z);
868   }
869 };
870
871
872 /// HandleSDNode - This class is used to form a handle around another node that
873 /// is persistent and is updated across invocations of replaceAllUsesWith on its
874 /// operand.  This node should be directly created by end-users and not added to
875 /// the AllNodes list.
876 class HandleSDNode : public SDNode {
877   SDUse Op;
878 public:
879   // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
880   // fixed.
881 #if __GNUC__==4 && __GNUC_MINOR__==2 && defined(__APPLE__) && !defined(__llvm__)
882   explicit __attribute__((__noinline__)) HandleSDNode(SDValue X)
883 #else
884   explicit HandleSDNode(SDValue X)
885 #endif
886     : SDNode(ISD::HANDLENODE, DebugLoc(), getSDVTList(MVT::Other)) {
887     InitOperands(&Op, X);
888   }
889   ~HandleSDNode();
890   const SDValue &getValue() const { return Op; }
891 };
892
893 /// Abstact virtual class for operations for memory operations
894 class MemSDNode : public SDNode {
895 private:
896   // MemoryVT - VT of in-memory value.
897   EVT MemoryVT;
898
899 protected:
900   /// MMO - Memory reference information.
901   MachineMemOperand *MMO;
902
903 public:
904   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, EVT MemoryVT,
905             MachineMemOperand *MMO);
906
907   MemSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs, const SDValue *Ops,
908             unsigned NumOps, EVT MemoryVT, MachineMemOperand *MMO);
909
910   bool readMem() const { return MMO->isLoad(); }
911   bool writeMem() const { return MMO->isStore(); }
912
913   /// Returns alignment and volatility of the memory access
914   unsigned getOriginalAlignment() const { 
915     return MMO->getBaseAlignment();
916   }
917   unsigned getAlignment() const {
918     return MMO->getAlignment();
919   }
920
921   /// getRawSubclassData - Return the SubclassData value, which contains an
922   /// encoding of the volatile flag, as well as bits used by subclasses. This
923   /// function should only be used to compute a FoldingSetNodeID value.
924   unsigned getRawSubclassData() const {
925     return SubclassData;
926   }
927
928   // We access subclass data here so that we can check consistency
929   // with MachineMemOperand information.
930   bool isVolatile() const { return (SubclassData >> 5) & 1; }
931   bool isNonTemporal() const { return (SubclassData >> 6) & 1; }
932   bool isInvariant() const { return (SubclassData >> 7) & 1; }
933
934   AtomicOrdering getOrdering() const {
935     return AtomicOrdering((SubclassData >> 8) & 15);
936   }
937   SynchronizationScope getSynchScope() const {
938     return SynchronizationScope((SubclassData >> 12) & 1);
939   }
940
941   /// Returns the SrcValue and offset that describes the location of the access
942   const Value *getSrcValue() const { return MMO->getValue(); }
943   int64_t getSrcValueOffset() const { return MMO->getOffset(); }
944
945   /// Returns the TBAAInfo that describes the dereference.
946   const MDNode *getTBAAInfo() const { return MMO->getTBAAInfo(); }
947
948   /// Returns the Ranges that describes the dereference.
949   const MDNode *getRanges() const { return MMO->getRanges(); }
950
951   /// getMemoryVT - Return the type of the in-memory value.
952   EVT getMemoryVT() const { return MemoryVT; }
953
954   /// getMemOperand - Return a MachineMemOperand object describing the memory
955   /// reference performed by operation.
956   MachineMemOperand *getMemOperand() const { return MMO; }
957
958   const MachinePointerInfo &getPointerInfo() const {
959     return MMO->getPointerInfo();
960   }
961
962   /// getAddressSpace - Return the address space for the associated pointer
963   unsigned getAddressSpace() const {
964     return getPointerInfo().getAddrSpace();
965   }
966
967   /// refineAlignment - Update this MemSDNode's MachineMemOperand information
968   /// to reflect the alignment of NewMMO, if it has a greater alignment.
969   /// This must only be used when the new alignment applies to all users of
970   /// this MachineMemOperand.
971   void refineAlignment(const MachineMemOperand *NewMMO) {
972     MMO->refineAlignment(NewMMO);
973   }
974
975   const SDValue &getChain() const { return getOperand(0); }
976   const SDValue &getBasePtr() const {
977     return getOperand(getOpcode() == ISD::STORE ? 2 : 1);
978   }
979
980   // Methods to support isa and dyn_cast
981   static bool classof(const SDNode *N) {
982     // For some targets, we lower some target intrinsics to a MemIntrinsicNode
983     // with either an intrinsic or a target opcode.
984     return N->getOpcode() == ISD::LOAD                ||
985            N->getOpcode() == ISD::STORE               ||
986            N->getOpcode() == ISD::PREFETCH            ||
987            N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
988            N->getOpcode() == ISD::ATOMIC_SWAP         ||
989            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
990            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
991            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
992            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
993            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
994            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
995            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
996            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
997            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
998            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
999            N->getOpcode() == ISD::ATOMIC_LOAD         ||
1000            N->getOpcode() == ISD::ATOMIC_STORE        ||
1001            N->isTargetMemoryOpcode();
1002   }
1003 };
1004
1005 /// AtomicSDNode - A SDNode reprenting atomic operations.
1006 ///
1007 class AtomicSDNode : public MemSDNode {
1008   SDUse Ops[4];
1009
1010   void InitAtomic(AtomicOrdering Ordering, SynchronizationScope SynchScope) {
1011     // This must match encodeMemSDNodeFlags() in SelectionDAG.cpp.
1012     assert((Ordering & 15) == Ordering &&
1013            "Ordering may not require more than 4 bits!");
1014     assert((SynchScope & 1) == SynchScope &&
1015            "SynchScope may not require more than 1 bit!");
1016     SubclassData |= Ordering << 8;
1017     SubclassData |= SynchScope << 12;
1018     assert(getOrdering() == Ordering && "Ordering encoding error!");
1019     assert(getSynchScope() == SynchScope && "Synch-scope encoding error!");
1020   }
1021
1022 public:
1023   // Opc:   opcode for atomic
1024   // VTL:    value type list
1025   // Chain:  memory chain for operaand
1026   // Ptr:    address to update as a SDValue
1027   // Cmp:    compare value
1028   // Swp:    swap value
1029   // SrcVal: address to update as a Value (used for MemOperand)
1030   // Align:  alignment of memory
1031   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1032                SDValue Chain, SDValue Ptr,
1033                SDValue Cmp, SDValue Swp, MachineMemOperand *MMO,
1034                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1035     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1036     InitAtomic(Ordering, SynchScope);
1037     InitOperands(Ops, Chain, Ptr, Cmp, Swp);
1038   }
1039   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1040                SDValue Chain, SDValue Ptr,
1041                SDValue Val, MachineMemOperand *MMO,
1042                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1043     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1044     InitAtomic(Ordering, SynchScope);
1045     InitOperands(Ops, Chain, Ptr, Val);
1046   }
1047   AtomicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTL, EVT MemVT,
1048                SDValue Chain, SDValue Ptr,
1049                MachineMemOperand *MMO,
1050                AtomicOrdering Ordering, SynchronizationScope SynchScope)
1051     : MemSDNode(Opc, dl, VTL, MemVT, MMO) {
1052     InitAtomic(Ordering, SynchScope);
1053     InitOperands(Ops, Chain, Ptr);
1054   }
1055
1056   const SDValue &getBasePtr() const { return getOperand(1); }
1057   const SDValue &getVal() const { return getOperand(2); }
1058
1059   bool isCompareAndSwap() const {
1060     unsigned Op = getOpcode();
1061     return Op == ISD::ATOMIC_CMP_SWAP;
1062   }
1063
1064   // Methods to support isa and dyn_cast
1065   static bool classof(const SDNode *N) {
1066     return N->getOpcode() == ISD::ATOMIC_CMP_SWAP     ||
1067            N->getOpcode() == ISD::ATOMIC_SWAP         ||
1068            N->getOpcode() == ISD::ATOMIC_LOAD_ADD     ||
1069            N->getOpcode() == ISD::ATOMIC_LOAD_SUB     ||
1070            N->getOpcode() == ISD::ATOMIC_LOAD_AND     ||
1071            N->getOpcode() == ISD::ATOMIC_LOAD_OR      ||
1072            N->getOpcode() == ISD::ATOMIC_LOAD_XOR     ||
1073            N->getOpcode() == ISD::ATOMIC_LOAD_NAND    ||
1074            N->getOpcode() == ISD::ATOMIC_LOAD_MIN     ||
1075            N->getOpcode() == ISD::ATOMIC_LOAD_MAX     ||
1076            N->getOpcode() == ISD::ATOMIC_LOAD_UMIN    ||
1077            N->getOpcode() == ISD::ATOMIC_LOAD_UMAX    ||
1078            N->getOpcode() == ISD::ATOMIC_LOAD         ||
1079            N->getOpcode() == ISD::ATOMIC_STORE;
1080   }
1081 };
1082
1083 /// MemIntrinsicSDNode - This SDNode is used for target intrinsics that touch
1084 /// memory and need an associated MachineMemOperand. Its opcode may be
1085 /// INTRINSIC_VOID, INTRINSIC_W_CHAIN, PREFETCH, or a target-specific opcode
1086 /// with a value not less than FIRST_TARGET_MEMORY_OPCODE.
1087 class MemIntrinsicSDNode : public MemSDNode {
1088 public:
1089   MemIntrinsicSDNode(unsigned Opc, DebugLoc dl, SDVTList VTs,
1090                      const SDValue *Ops, unsigned NumOps,
1091                      EVT MemoryVT, MachineMemOperand *MMO)
1092     : MemSDNode(Opc, dl, VTs, Ops, NumOps, MemoryVT, MMO) {
1093   }
1094
1095   // Methods to support isa and dyn_cast
1096   static bool classof(const SDNode *N) {
1097     // We lower some target intrinsics to their target opcode
1098     // early a node with a target opcode can be of this class
1099     return N->getOpcode() == ISD::INTRINSIC_W_CHAIN ||
1100            N->getOpcode() == ISD::INTRINSIC_VOID ||
1101            N->getOpcode() == ISD::PREFETCH ||
1102            N->isTargetMemoryOpcode();
1103   }
1104 };
1105
1106 /// ShuffleVectorSDNode - This SDNode is used to implement the code generator
1107 /// support for the llvm IR shufflevector instruction.  It combines elements
1108 /// from two input vectors into a new input vector, with the selection and
1109 /// ordering of elements determined by an array of integers, referred to as
1110 /// the shuffle mask.  For input vectors of width N, mask indices of 0..N-1
1111 /// refer to elements from the LHS input, and indices from N to 2N-1 the RHS.
1112 /// An index of -1 is treated as undef, such that the code generator may put
1113 /// any value in the corresponding element of the result.
1114 class ShuffleVectorSDNode : public SDNode {
1115   SDUse Ops[2];
1116
1117   // The memory for Mask is owned by the SelectionDAG's OperandAllocator, and
1118   // is freed when the SelectionDAG object is destroyed.
1119   const int *Mask;
1120 protected:
1121   friend class SelectionDAG;
1122   ShuffleVectorSDNode(EVT VT, DebugLoc dl, SDValue N1, SDValue N2, 
1123                       const int *M)
1124     : SDNode(ISD::VECTOR_SHUFFLE, dl, getSDVTList(VT)), Mask(M) {
1125     InitOperands(Ops, N1, N2);
1126   }
1127 public:
1128
1129   ArrayRef<int> getMask() const {
1130     EVT VT = getValueType(0);
1131     return makeArrayRef(Mask, VT.getVectorNumElements());
1132   }
1133   int getMaskElt(unsigned Idx) const {
1134     assert(Idx < getValueType(0).getVectorNumElements() && "Idx out of range!");
1135     return Mask[Idx];
1136   }
1137   
1138   bool isSplat() const { return isSplatMask(Mask, getValueType(0)); }
1139   int  getSplatIndex() const { 
1140     assert(isSplat() && "Cannot get splat index for non-splat!");
1141     EVT VT = getValueType(0);
1142     for (unsigned i = 0, e = VT.getVectorNumElements(); i != e; ++i) {
1143       if (Mask[i] != -1)
1144         return Mask[i];
1145     }
1146     return -1;
1147   }
1148   static bool isSplatMask(const int *Mask, EVT VT);
1149
1150   static bool classof(const SDNode *N) {
1151     return N->getOpcode() == ISD::VECTOR_SHUFFLE;
1152   }
1153 };
1154   
1155 class ConstantSDNode : public SDNode {
1156   const ConstantInt *Value;
1157   friend class SelectionDAG;
1158   ConstantSDNode(bool isTarget, const ConstantInt *val, EVT VT)
1159     : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant,
1160              DebugLoc(), getSDVTList(VT)), Value(val) {
1161   }
1162 public:
1163
1164   const ConstantInt *getConstantIntValue() const { return Value; }
1165   const APInt &getAPIntValue() const { return Value->getValue(); }
1166   uint64_t getZExtValue() const { return Value->getZExtValue(); }
1167   int64_t getSExtValue() const { return Value->getSExtValue(); }
1168
1169   bool isOne() const { return Value->isOne(); }
1170   bool isNullValue() const { return Value->isNullValue(); }
1171   bool isAllOnesValue() const { return Value->isAllOnesValue(); }
1172
1173   static bool classof(const SDNode *N) {
1174     return N->getOpcode() == ISD::Constant ||
1175            N->getOpcode() == ISD::TargetConstant;
1176   }
1177 };
1178
1179 class ConstantFPSDNode : public SDNode {
1180   const ConstantFP *Value;
1181   friend class SelectionDAG;
1182   ConstantFPSDNode(bool isTarget, const ConstantFP *val, EVT VT)
1183     : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
1184              DebugLoc(), getSDVTList(VT)), Value(val) {
1185   }
1186 public:
1187
1188   const APFloat& getValueAPF() const { return Value->getValueAPF(); }
1189   const ConstantFP *getConstantFPValue() const { return Value; }
1190
1191   /// isZero - Return true if the value is positive or negative zero.
1192   bool isZero() const { return Value->isZero(); }
1193
1194   /// isNaN - Return true if the value is a NaN.
1195   bool isNaN() const { return Value->isNaN(); }
1196
1197   /// isExactlyValue - We don't rely on operator== working on double values, as
1198   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
1199   /// As such, this method can be used to do an exact bit-for-bit comparison of
1200   /// two floating point values.
1201
1202   /// We leave the version with the double argument here because it's just so
1203   /// convenient to write "2.0" and the like.  Without this function we'd
1204   /// have to duplicate its logic everywhere it's called.
1205   bool isExactlyValue(double V) const {
1206     bool ignored;
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 SDNode *N) {
1217     return N->getOpcode() == ISD::ConstantFP ||
1218            N->getOpcode() == ISD::TargetConstantFP;
1219   }
1220 };
1221
1222 class GlobalAddressSDNode : public SDNode {
1223   const GlobalValue *TheGlobal;
1224   int64_t Offset;
1225   unsigned char TargetFlags;
1226   friend class SelectionDAG;
1227   GlobalAddressSDNode(unsigned Opc, DebugLoc DL, const GlobalValue *GA, EVT VT,
1228                       int64_t o, unsigned char TargetFlags);
1229 public:
1230
1231   const GlobalValue *getGlobal() const { return TheGlobal; }
1232   int64_t getOffset() const { return Offset; }
1233   unsigned char getTargetFlags() const { return TargetFlags; }
1234   // Return the address space this GlobalAddress belongs to.
1235   unsigned getAddressSpace() const;
1236
1237   static bool classof(const SDNode *N) {
1238     return N->getOpcode() == ISD::GlobalAddress ||
1239            N->getOpcode() == ISD::TargetGlobalAddress ||
1240            N->getOpcode() == ISD::GlobalTLSAddress ||
1241            N->getOpcode() == ISD::TargetGlobalTLSAddress;
1242   }
1243 };
1244
1245 class FrameIndexSDNode : public SDNode {
1246   int FI;
1247   friend class SelectionDAG;
1248   FrameIndexSDNode(int fi, EVT VT, bool isTarg)
1249     : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex,
1250       DebugLoc(), getSDVTList(VT)), FI(fi) {
1251   }
1252 public:
1253
1254   int getIndex() const { return FI; }
1255
1256   static bool classof(const SDNode *N) {
1257     return N->getOpcode() == ISD::FrameIndex ||
1258            N->getOpcode() == ISD::TargetFrameIndex;
1259   }
1260 };
1261
1262 class JumpTableSDNode : public SDNode {
1263   int JTI;
1264   unsigned char TargetFlags;
1265   friend class SelectionDAG;
1266   JumpTableSDNode(int jti, EVT VT, bool isTarg, unsigned char TF)
1267     : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable,
1268       DebugLoc(), getSDVTList(VT)), JTI(jti), TargetFlags(TF) {
1269   }
1270 public:
1271
1272   int getIndex() const { return JTI; }
1273   unsigned char getTargetFlags() const { return TargetFlags; }
1274
1275   static bool classof(const SDNode *N) {
1276     return N->getOpcode() == ISD::JumpTable ||
1277            N->getOpcode() == ISD::TargetJumpTable;
1278   }
1279 };
1280
1281 class ConstantPoolSDNode : public SDNode {
1282   union {
1283     const Constant *ConstVal;
1284     MachineConstantPoolValue *MachineCPVal;
1285   } Val;
1286   int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1287   unsigned Alignment;  // Minimum alignment requirement of CP (not log2 value).
1288   unsigned char TargetFlags;
1289   friend class SelectionDAG;
1290   ConstantPoolSDNode(bool isTarget, const Constant *c, EVT VT, int o,
1291                      unsigned Align, unsigned char TF)
1292     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1293              DebugLoc(),
1294              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1295     assert(Offset >= 0 && "Offset is too large");
1296     Val.ConstVal = c;
1297   }
1298   ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1299                      EVT VT, int o, unsigned Align, unsigned char TF)
1300     : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1301              DebugLoc(),
1302              getSDVTList(VT)), Offset(o), Alignment(Align), TargetFlags(TF) {
1303     assert(Offset >= 0 && "Offset is too large");
1304     Val.MachineCPVal = v;
1305     Offset |= 1 << (sizeof(unsigned)*CHAR_BIT-1);
1306   }
1307 public:
1308   
1309
1310   bool isMachineConstantPoolEntry() const {
1311     return Offset < 0;
1312   }
1313
1314   const Constant *getConstVal() const {
1315     assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1316     return Val.ConstVal;
1317   }
1318
1319   MachineConstantPoolValue *getMachineCPVal() const {
1320     assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1321     return Val.MachineCPVal;
1322   }
1323
1324   int getOffset() const {
1325     return Offset & ~(1 << (sizeof(unsigned)*CHAR_BIT-1));
1326   }
1327
1328   // Return the alignment of this constant pool object, which is either 0 (for
1329   // default alignment) or the desired value.
1330   unsigned getAlignment() const { return Alignment; }
1331   unsigned char getTargetFlags() const { return TargetFlags; }
1332
1333   Type *getType() const;
1334
1335   static bool classof(const SDNode *N) {
1336     return N->getOpcode() == ISD::ConstantPool ||
1337            N->getOpcode() == ISD::TargetConstantPool;
1338   }
1339 };
1340
1341 /// Completely target-dependent object reference.
1342 class TargetIndexSDNode : public SDNode {
1343   unsigned char TargetFlags;
1344   int Index;
1345   int64_t Offset;
1346   friend class SelectionDAG;
1347 public:
1348
1349   TargetIndexSDNode(int Idx, EVT VT, int64_t Ofs, unsigned char TF)
1350     : SDNode(ISD::TargetIndex, DebugLoc(), getSDVTList(VT)),
1351       TargetFlags(TF), Index(Idx), Offset(Ofs) {}
1352 public:
1353
1354   unsigned char getTargetFlags() const { return TargetFlags; }
1355   int getIndex() const { return Index; }
1356   int64_t getOffset() const { return Offset; }
1357
1358   static bool classof(const SDNode *N) {
1359     return N->getOpcode() == ISD::TargetIndex;
1360   }
1361 };
1362
1363 class BasicBlockSDNode : public SDNode {
1364   MachineBasicBlock *MBB;
1365   friend class SelectionDAG;
1366   /// Debug info is meaningful and potentially useful here, but we create
1367   /// blocks out of order when they're jumped to, which makes it a bit
1368   /// harder.  Let's see if we need it first.
1369   explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1370     : SDNode(ISD::BasicBlock, DebugLoc(), getSDVTList(MVT::Other)), MBB(mbb) {
1371   }
1372 public:
1373
1374   MachineBasicBlock *getBasicBlock() const { return MBB; }
1375
1376   static bool classof(const SDNode *N) {
1377     return N->getOpcode() == ISD::BasicBlock;
1378   }
1379 };
1380
1381 /// BuildVectorSDNode - A "pseudo-class" with methods for operating on
1382 /// BUILD_VECTORs.
1383 class BuildVectorSDNode : public SDNode {
1384   // These are constructed as SDNodes and then cast to BuildVectorSDNodes.
1385   explicit BuildVectorSDNode() LLVM_DELETED_FUNCTION;
1386 public:
1387   /// isConstantSplat - Check if this is a constant splat, and if so, find the
1388   /// smallest element size that splats the vector.  If MinSplatBits is
1389   /// nonzero, the element size must be at least that large.  Note that the
1390   /// splat element may be the entire vector (i.e., a one element vector).
1391   /// Returns the splat element value in SplatValue.  Any undefined bits in
1392   /// that value are zero, and the corresponding bits in the SplatUndef mask
1393   /// are set.  The SplatBitSize value is set to the splat element size in
1394   /// bits.  HasAnyUndefs is set to true if any bits in the vector are
1395   /// undefined.  isBigEndian describes the endianness of the target.
1396   bool isConstantSplat(APInt &SplatValue, APInt &SplatUndef,
1397                        unsigned &SplatBitSize, bool &HasAnyUndefs,
1398                        unsigned MinSplatBits = 0, bool isBigEndian = false);
1399
1400   static inline bool classof(const SDNode *N) {
1401     return N->getOpcode() == ISD::BUILD_VECTOR;
1402   }
1403 };
1404
1405 /// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
1406 /// used when the SelectionDAG needs to make a simple reference to something
1407 /// in the LLVM IR representation.
1408 ///
1409 class SrcValueSDNode : public SDNode {
1410   const Value *V;
1411   friend class SelectionDAG;
1412   /// Create a SrcValue for a general value.
1413   explicit SrcValueSDNode(const Value *v)
1414     : SDNode(ISD::SRCVALUE, DebugLoc(), getSDVTList(MVT::Other)), V(v) {}
1415
1416 public:
1417   /// getValue - return the contained Value.
1418   const Value *getValue() const { return V; }
1419
1420   static bool classof(const SDNode *N) {
1421     return N->getOpcode() == ISD::SRCVALUE;
1422   }
1423 };
1424   
1425 class MDNodeSDNode : public SDNode {
1426   const MDNode *MD;
1427   friend class SelectionDAG;
1428   explicit MDNodeSDNode(const MDNode *md)
1429   : SDNode(ISD::MDNODE_SDNODE, DebugLoc(), getSDVTList(MVT::Other)), MD(md) {}
1430 public:
1431   
1432   const MDNode *getMD() const { return MD; }
1433   
1434   static bool classof(const SDNode *N) {
1435     return N->getOpcode() == ISD::MDNODE_SDNODE;
1436   }
1437 };
1438
1439
1440 class RegisterSDNode : public SDNode {
1441   unsigned Reg;
1442   friend class SelectionDAG;
1443   RegisterSDNode(unsigned reg, EVT VT)
1444     : SDNode(ISD::Register, DebugLoc(), getSDVTList(VT)), Reg(reg) {
1445   }
1446 public:
1447
1448   unsigned getReg() const { return Reg; }
1449
1450   static bool classof(const SDNode *N) {
1451     return N->getOpcode() == ISD::Register;
1452   }
1453 };
1454
1455 class RegisterMaskSDNode : public SDNode {
1456   // The memory for RegMask is not owned by the node.
1457   const uint32_t *RegMask;
1458   friend class SelectionDAG;
1459   RegisterMaskSDNode(const uint32_t *mask)
1460     : SDNode(ISD::RegisterMask, DebugLoc(), getSDVTList(MVT::Untyped)),
1461       RegMask(mask) {}
1462 public:
1463
1464   const uint32_t *getRegMask() const { return RegMask; }
1465
1466   static bool classof(const SDNode *N) {
1467     return N->getOpcode() == ISD::RegisterMask;
1468   }
1469 };
1470
1471 class BlockAddressSDNode : public SDNode {
1472   const BlockAddress *BA;
1473   int64_t Offset;
1474   unsigned char TargetFlags;
1475   friend class SelectionDAG;
1476   BlockAddressSDNode(unsigned NodeTy, EVT VT, const BlockAddress *ba,
1477                      int64_t o, unsigned char Flags)
1478     : SDNode(NodeTy, DebugLoc(), getSDVTList(VT)),
1479              BA(ba), Offset(o), TargetFlags(Flags) {
1480   }
1481 public:
1482   const BlockAddress *getBlockAddress() const { return BA; }
1483   int64_t getOffset() const { return Offset; }
1484   unsigned char getTargetFlags() const { return TargetFlags; }
1485
1486   static bool classof(const SDNode *N) {
1487     return N->getOpcode() == ISD::BlockAddress ||
1488            N->getOpcode() == ISD::TargetBlockAddress;
1489   }
1490 };
1491
1492 class EHLabelSDNode : public SDNode {
1493   SDUse Chain;
1494   MCSymbol *Label;
1495   friend class SelectionDAG;
1496   EHLabelSDNode(DebugLoc dl, SDValue ch, MCSymbol *L)
1497     : SDNode(ISD::EH_LABEL, dl, getSDVTList(MVT::Other)), Label(L) {
1498     InitOperands(&Chain, ch);
1499   }
1500 public:
1501   MCSymbol *getLabel() const { return Label; }
1502
1503   static bool classof(const SDNode *N) {
1504     return N->getOpcode() == ISD::EH_LABEL;
1505   }
1506 };
1507
1508 class ExternalSymbolSDNode : public SDNode {
1509   const char *Symbol;
1510   unsigned char TargetFlags;
1511   
1512   friend class SelectionDAG;
1513   ExternalSymbolSDNode(bool isTarget, const char *Sym, unsigned char TF, EVT VT)
1514     : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1515              DebugLoc(), getSDVTList(VT)), Symbol(Sym), TargetFlags(TF) {
1516   }
1517 public:
1518
1519   const char *getSymbol() const { return Symbol; }
1520   unsigned char getTargetFlags() const { return TargetFlags; }
1521
1522   static bool classof(const SDNode *N) {
1523     return N->getOpcode() == ISD::ExternalSymbol ||
1524            N->getOpcode() == ISD::TargetExternalSymbol;
1525   }
1526 };
1527
1528 class CondCodeSDNode : public SDNode {
1529   ISD::CondCode Condition;
1530   friend class SelectionDAG;
1531   explicit CondCodeSDNode(ISD::CondCode Cond)
1532     : SDNode(ISD::CONDCODE, DebugLoc(), getSDVTList(MVT::Other)),
1533       Condition(Cond) {
1534   }
1535 public:
1536
1537   ISD::CondCode get() const { return Condition; }
1538
1539   static bool classof(const SDNode *N) {
1540     return N->getOpcode() == ISD::CONDCODE;
1541   }
1542 };
1543   
1544 /// CvtRndSatSDNode - NOTE: avoid using this node as this may disappear in the
1545 /// future and most targets don't support it.
1546 class CvtRndSatSDNode : public SDNode {
1547   ISD::CvtCode CvtCode;
1548   friend class SelectionDAG;
1549   explicit CvtRndSatSDNode(EVT VT, DebugLoc dl, const SDValue *Ops,
1550                            unsigned NumOps, ISD::CvtCode Code)
1551     : SDNode(ISD::CONVERT_RNDSAT, dl, getSDVTList(VT), Ops, NumOps),
1552       CvtCode(Code) {
1553     assert(NumOps == 5 && "wrong number of operations");
1554   }
1555 public:
1556   ISD::CvtCode getCvtCode() const { return CvtCode; }
1557
1558   static bool classof(const SDNode *N) {
1559     return N->getOpcode() == ISD::CONVERT_RNDSAT;
1560   }
1561 };
1562
1563 /// VTSDNode - This class is used to represent EVT's, which are used
1564 /// to parameterize some operations.
1565 class VTSDNode : public SDNode {
1566   EVT ValueType;
1567   friend class SelectionDAG;
1568   explicit VTSDNode(EVT VT)
1569     : SDNode(ISD::VALUETYPE, DebugLoc(), getSDVTList(MVT::Other)),
1570       ValueType(VT) {
1571   }
1572 public:
1573
1574   EVT getVT() const { return ValueType; }
1575
1576   static bool classof(const SDNode *N) {
1577     return N->getOpcode() == ISD::VALUETYPE;
1578   }
1579 };
1580
1581 /// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
1582 ///
1583 class LSBaseSDNode : public MemSDNode {
1584   //! Operand array for load and store
1585   /*!
1586     \note Moving this array to the base class captures more
1587     common functionality shared between LoadSDNode and
1588     StoreSDNode
1589    */
1590   SDUse Ops[4];
1591 public:
1592   LSBaseSDNode(ISD::NodeType NodeTy, DebugLoc dl, SDValue *Operands,
1593                unsigned numOperands, SDVTList VTs, ISD::MemIndexedMode AM,
1594                EVT MemVT, MachineMemOperand *MMO)
1595     : MemSDNode(NodeTy, dl, VTs, MemVT, MMO) {
1596     SubclassData |= AM << 2;
1597     assert(getAddressingMode() == AM && "MemIndexedMode encoding error!");
1598     InitOperands(Ops, Operands, numOperands);
1599     assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1600            "Only indexed loads and stores have a non-undef offset operand");
1601   }
1602
1603   const SDValue &getOffset() const {
1604     return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
1605   }
1606
1607   /// getAddressingMode - Return the addressing mode for this load or store:
1608   /// unindexed, pre-inc, pre-dec, post-inc, or post-dec.
1609   ISD::MemIndexedMode getAddressingMode() const {
1610     return ISD::MemIndexedMode((SubclassData >> 2) & 7);
1611   }
1612
1613   /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1614   bool isIndexed() const { return getAddressingMode() != ISD::UNINDEXED; }
1615
1616   /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1617   bool isUnindexed() const { return getAddressingMode() == ISD::UNINDEXED; }
1618
1619   static bool classof(const SDNode *N) {
1620     return N->getOpcode() == ISD::LOAD ||
1621            N->getOpcode() == ISD::STORE;
1622   }
1623 };
1624
1625 /// LoadSDNode - This class is used to represent ISD::LOAD nodes.
1626 ///
1627 class LoadSDNode : public LSBaseSDNode {
1628   friend class SelectionDAG;
1629   LoadSDNode(SDValue *ChainPtrOff, DebugLoc dl, SDVTList VTs,
1630              ISD::MemIndexedMode AM, ISD::LoadExtType ETy, EVT MemVT,
1631              MachineMemOperand *MMO)
1632     : LSBaseSDNode(ISD::LOAD, dl, ChainPtrOff, 3,
1633                    VTs, AM, MemVT, MMO) {
1634     SubclassData |= (unsigned short)ETy;
1635     assert(getExtensionType() == ETy && "LoadExtType encoding error!");
1636     assert(readMem() && "Load MachineMemOperand is not a load!");
1637     assert(!writeMem() && "Load MachineMemOperand is a store!");
1638   }
1639 public:
1640
1641   /// getExtensionType - Return whether this is a plain node,
1642   /// or one of the varieties of value-extending loads.
1643   ISD::LoadExtType getExtensionType() const {
1644     return ISD::LoadExtType(SubclassData & 3);
1645   }
1646
1647   const SDValue &getBasePtr() const { return getOperand(1); }
1648   const SDValue &getOffset() const { return getOperand(2); }
1649
1650   static bool classof(const SDNode *N) {
1651     return N->getOpcode() == ISD::LOAD;
1652   }
1653 };
1654
1655 /// StoreSDNode - This class is used to represent ISD::STORE nodes.
1656 ///
1657 class StoreSDNode : public LSBaseSDNode {
1658   friend class SelectionDAG;
1659   StoreSDNode(SDValue *ChainValuePtrOff, DebugLoc dl, SDVTList VTs,
1660               ISD::MemIndexedMode AM, bool isTrunc, EVT MemVT,
1661               MachineMemOperand *MMO)
1662     : LSBaseSDNode(ISD::STORE, dl, ChainValuePtrOff, 4,
1663                    VTs, AM, MemVT, MMO) {
1664     SubclassData |= (unsigned short)isTrunc;
1665     assert(isTruncatingStore() == isTrunc && "isTrunc encoding error!");
1666     assert(!readMem() && "Store MachineMemOperand is a load!");
1667     assert(writeMem() && "Store MachineMemOperand is not a store!");
1668   }
1669 public:
1670
1671   /// isTruncatingStore - Return true if the op does a truncation before store.
1672   /// For integers this is the same as doing a TRUNCATE and storing the result.
1673   /// For floats, it is the same as doing an FP_ROUND and storing the result.
1674   bool isTruncatingStore() const { return SubclassData & 1; }
1675
1676   const SDValue &getValue() const { return getOperand(1); }
1677   const SDValue &getBasePtr() const { return getOperand(2); }
1678   const SDValue &getOffset() const { return getOperand(3); }
1679
1680   static bool classof(const SDNode *N) {
1681     return N->getOpcode() == ISD::STORE;
1682   }
1683 };
1684
1685 /// MachineSDNode - An SDNode that represents everything that will be needed
1686 /// to construct a MachineInstr. These nodes are created during the
1687 /// instruction selection proper phase.
1688 ///
1689 class MachineSDNode : public SDNode {
1690 public:
1691   typedef MachineMemOperand **mmo_iterator;
1692
1693 private:
1694   friend class SelectionDAG;
1695   MachineSDNode(unsigned Opc, const DebugLoc DL, SDVTList VTs)
1696     : SDNode(Opc, DL, VTs), MemRefs(0), MemRefsEnd(0) {}
1697
1698   /// LocalOperands - Operands for this instruction, if they fit here. If
1699   /// they don't, this field is unused.
1700   SDUse LocalOperands[4];
1701
1702   /// MemRefs - Memory reference descriptions for this instruction.
1703   mmo_iterator MemRefs;
1704   mmo_iterator MemRefsEnd;
1705
1706 public:
1707   mmo_iterator memoperands_begin() const { return MemRefs; }
1708   mmo_iterator memoperands_end() const { return MemRefsEnd; }
1709   bool memoperands_empty() const { return MemRefsEnd == MemRefs; }
1710
1711   /// setMemRefs - Assign this MachineSDNodes's memory reference descriptor
1712   /// list. This does not transfer ownership.
1713   void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd) {
1714     for (mmo_iterator MMI = NewMemRefs, MME = NewMemRefsEnd; MMI != MME; ++MMI)
1715       assert(*MMI && "Null mem ref detected!");
1716     MemRefs = NewMemRefs;
1717     MemRefsEnd = NewMemRefsEnd;
1718   }
1719
1720   static bool classof(const SDNode *N) {
1721     return N->isMachineOpcode();
1722   }
1723 };
1724
1725 class SDNodeIterator : public std::iterator<std::forward_iterator_tag,
1726                                             SDNode, ptrdiff_t> {
1727   const SDNode *Node;
1728   unsigned Operand;
1729
1730   SDNodeIterator(const SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
1731 public:
1732   bool operator==(const SDNodeIterator& x) const {
1733     return Operand == x.Operand;
1734   }
1735   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
1736
1737   const SDNodeIterator &operator=(const SDNodeIterator &I) {
1738     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
1739     Operand = I.Operand;
1740     return *this;
1741   }
1742
1743   pointer operator*() const {
1744     return Node->getOperand(Operand).getNode();
1745   }
1746   pointer operator->() const { return operator*(); }
1747
1748   SDNodeIterator& operator++() {                // Preincrement
1749     ++Operand;
1750     return *this;
1751   }
1752   SDNodeIterator operator++(int) { // Postincrement
1753     SDNodeIterator tmp = *this; ++*this; return tmp;
1754   }
1755   size_t operator-(SDNodeIterator Other) const {
1756     assert(Node == Other.Node &&
1757            "Cannot compare iterators of two different nodes!");
1758     return Operand - Other.Operand;
1759   }
1760
1761   static SDNodeIterator begin(const SDNode *N) { return SDNodeIterator(N, 0); }
1762   static SDNodeIterator end  (const SDNode *N) {
1763     return SDNodeIterator(N, N->getNumOperands());
1764   }
1765
1766   unsigned getOperand() const { return Operand; }
1767   const SDNode *getNode() const { return Node; }
1768 };
1769
1770 template <> struct GraphTraits<SDNode*> {
1771   typedef SDNode NodeType;
1772   typedef SDNodeIterator ChildIteratorType;
1773   static inline NodeType *getEntryNode(SDNode *N) { return N; }
1774   static inline ChildIteratorType child_begin(NodeType *N) {
1775     return SDNodeIterator::begin(N);
1776   }
1777   static inline ChildIteratorType child_end(NodeType *N) {
1778     return SDNodeIterator::end(N);
1779   }
1780 };
1781
1782 /// LargestSDNode - The largest SDNode class.
1783 ///
1784 typedef LoadSDNode LargestSDNode;
1785
1786 /// MostAlignedSDNode - The SDNode class with the greatest alignment
1787 /// requirement.
1788 ///
1789 typedef GlobalAddressSDNode MostAlignedSDNode;
1790
1791 namespace ISD {
1792   /// isNormalLoad - Returns true if the specified node is a non-extending
1793   /// and unindexed load.
1794   inline bool isNormalLoad(const SDNode *N) {
1795     const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N);
1796     return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD &&
1797       Ld->getAddressingMode() == ISD::UNINDEXED;
1798   }
1799
1800   /// isNON_EXTLoad - Returns true if the specified node is a non-extending
1801   /// load.
1802   inline bool isNON_EXTLoad(const SDNode *N) {
1803     return isa<LoadSDNode>(N) &&
1804       cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
1805   }
1806
1807   /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
1808   ///
1809   inline bool isEXTLoad(const SDNode *N) {
1810     return isa<LoadSDNode>(N) &&
1811       cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
1812   }
1813
1814   /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
1815   ///
1816   inline bool isSEXTLoad(const SDNode *N) {
1817     return isa<LoadSDNode>(N) &&
1818       cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
1819   }
1820
1821   /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
1822   ///
1823   inline bool isZEXTLoad(const SDNode *N) {
1824     return isa<LoadSDNode>(N) &&
1825       cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
1826   }
1827
1828   /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load.
1829   ///
1830   inline bool isUNINDEXEDLoad(const SDNode *N) {
1831     return isa<LoadSDNode>(N) &&
1832       cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1833   }
1834
1835   /// isNormalStore - Returns true if the specified node is a non-truncating
1836   /// and unindexed store.
1837   inline bool isNormalStore(const SDNode *N) {
1838     const StoreSDNode *St = dyn_cast<StoreSDNode>(N);
1839     return St && !St->isTruncatingStore() &&
1840       St->getAddressingMode() == ISD::UNINDEXED;
1841   }
1842
1843   /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
1844   /// store.
1845   inline bool isNON_TRUNCStore(const SDNode *N) {
1846     return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore();
1847   }
1848
1849   /// isTRUNCStore - Returns true if the specified node is a truncating
1850   /// store.
1851   inline bool isTRUNCStore(const SDNode *N) {
1852     return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore();
1853   }
1854
1855   /// isUNINDEXEDStore - Returns true if the specified node is an
1856   /// unindexed store.
1857   inline bool isUNINDEXEDStore(const SDNode *N) {
1858     return isa<StoreSDNode>(N) &&
1859       cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
1860   }
1861 }
1862
1863 } // end llvm namespace
1864
1865 #endif