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