SelectionDAGNodes.h revision 1080b9ee534579c67f7c99364cc6fa11edbcd919
1//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file was developed by the LLVM research group and is distributed under
6// the University of Illinois Open Source 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/CodeGen/ValueTypes.h"
23#include "llvm/ADT/GraphTraits.h"
24#include "llvm/ADT/GraphTraits.h"
25#include "llvm/ADT/iterator"
26#include "llvm/Support/DataTypes.h"
27#include <cassert>
28#include <vector>
29
30namespace llvm {
31
32class SelectionDAG;
33class GlobalValue;
34class MachineBasicBlock;
35class SDNode;
36template <typename T> struct simplify_type;
37
38/// ISD namespace - This namespace contains an enum which represents all of the
39/// SelectionDAG node types and value types.
40///
41namespace ISD {
42  //===--------------------------------------------------------------------===//
43  /// ISD::NodeType enum - This enum defines all of the operators valid in a
44  /// SelectionDAG.
45  ///
46  enum NodeType {
47    // Leaf nodes
48    EntryToken, Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool,
49    BasicBlock, ExternalSymbol,
50
51    // CopyToReg - This node has chain and child nodes, and an associated
52    // register number.  The instruction selector must guarantee that the value
53    // of the value node is available in the virtual register stored in the
54    // CopyRegSDNode object.
55    CopyToReg,
56
57    // CopyFromReg - This node indicates that the input value is a virtual or
58    // physical register that is defined outside of the scope of this
59    // SelectionDAG.  The virtual register is available from the
60    // CopyRegSDNode object.
61    CopyFromReg,
62
63    // EXTRACT_ELEMENT - This is used to get the first or second (determined by
64    // a Constant, which is required to be operand #1), element of the aggregate
65    // value specified as operand #0.  This is only for use before legalization,
66    // for values that will be broken into multiple registers.
67    EXTRACT_ELEMENT,
68
69    // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
70    // two values of the same integer value type, this produces a value twice as
71    // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
72    BUILD_PAIR,
73
74
75    // Simple binary arithmetic operators.
76    ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
77
78    // Bitwise operators.
79    AND, OR, XOR, SHL, SRA, SRL,
80
81    // Select operator.
82    SELECT,
83
84    // SetCC operator - This evaluates to a boolean (i1) true value if the
85    // condition is true.  These nodes are instances of the
86    // SetCCSDNode class, which contains the condition code as extra
87    // state.
88    SETCC,
89
90    // addc - Three input, two output operator: (X, Y, C) -> (X+Y+C,
91    // Cout).  X,Y are integer inputs of agreeing size, C is a one bit
92    // value, and two values are produced: the sum and a carry out.
93    ADDC, SUBB,
94
95    // Conversion operators.  These are all single input single output
96    // operations.  For all of these, the result type must be strictly
97    // wider or narrower (depending on the operation) than the source
98    // type.
99
100    // SIGN_EXTEND - Used for integer types, replicating the sign bit
101    // into new bits.
102    SIGN_EXTEND,
103
104    // ZERO_EXTEND - Used for integer types, zeroing the new bits.
105    ZERO_EXTEND,
106
107    // TRUNCATE - Completely drop the high bits.
108    TRUNCATE,
109
110    // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
111    // depends on the first letter) to floating point.
112    SINT_TO_FP,
113    UINT_TO_FP,
114
115    // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
116    // integer.
117    FP_TO_SINT,
118    FP_TO_UINT,
119
120    // FP_ROUND - Perform a rounding operation from the current
121    // precision down to the specified precision.
122    FP_ROUND,
123
124    // FP_EXTEND - Extend a smaller FP type into a larger FP type.
125    FP_EXTEND,
126
127    // Other operators.  LOAD and STORE have token chains.
128    LOAD, STORE,
129
130    // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
131    // to a specified boundary.  The first operand is the token chain, the
132    // second is the number of bytes to allocate, and the third is the alignment
133    // boundary.
134    DYNAMIC_STACKALLOC,
135
136    // Control flow instructions.  These all have token chains.
137
138    // BR - Unconditional branch.  The first operand is the chain
139    // operand, the second is the MBB to branch to.
140    BR,
141
142    // BRCOND - Conditional branch.  The first operand is the chain,
143    // the second is the condition, the third is the block to branch
144    // to if the condition is true.
145    BRCOND,
146
147    // RET - Return from function.  The first operand is the chain,
148    // and any subsequent operands are the return values for the
149    // function.  This operation can have variable number of operands.
150    RET,
151
152    // CALL - Call to a function pointer.  The first operand is the chain, the
153    // second is the destination function pointer (a GlobalAddress for a direct
154    // call).  Arguments have already been lowered to explicit DAGs according to
155    // the calling convention in effect here.
156    CALL,
157
158    // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and
159    // end of a call sequence and indicate how much the stack pointer needs to
160    // be adjusted for that particular call.  The first operand is a chain, the
161    // second is a ConstantSDNode of intptr type.
162    ADJCALLSTACKDOWN,  // Beginning of a call sequence
163    ADJCALLSTACKUP,    // End of a call sequence
164
165
166    // BUILTIN_OP_END - This must be the last enum value in this list.
167    BUILTIN_OP_END,
168  };
169
170  //===--------------------------------------------------------------------===//
171  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
172  /// below work out, when considering SETFALSE (something that never exists
173  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
174  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
175  /// to.  If the "N" column is 1, the result of the comparison is undefined if
176  /// the input is a NAN.
177  ///
178  /// All of these (except for the 'always folded ops') should be handled for
179  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
180  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
181  ///
182  /// Note that these are laid out in a specific order to allow bit-twiddling
183  /// to transform conditions.
184  enum CondCode {
185    // Opcode          N U L G E       Intuitive operation
186    SETFALSE,      //    0 0 0 0       Always false (always folded)
187    SETOEQ,        //    0 0 0 1       True if ordered and equal
188    SETOGT,        //    0 0 1 0       True if ordered and greater than
189    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
190    SETOLT,        //    0 1 0 0       True if ordered and less than
191    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
192    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
193    SETO,          //    0 1 1 1       True if ordered (no nans)
194    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
195    SETUEQ,        //    1 0 0 1       True if unordered or equal
196    SETUGT,        //    1 0 1 0       True if unordered or greater than
197    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
198    SETULT,        //    1 1 0 0       True if unordered or less than
199    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
200    SETUNE,        //    1 1 1 0       True if unordered or not equal
201    SETTRUE,       //    1 1 1 1       Always true (always folded)
202    // Don't care operations: undefined if the input is a nan.
203    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
204    SETEQ,         //  1 X 0 0 1       True if equal
205    SETGT,         //  1 X 0 1 0       True if greater than
206    SETGE,         //  1 X 0 1 1       True if greater than or equal
207    SETLT,         //  1 X 1 0 0       True if less than
208    SETLE,         //  1 X 1 0 1       True if less than or equal
209    SETNE,         //  1 X 1 1 0       True if not equal
210    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
211
212    SETCC_INVALID,      // Marker value.
213  };
214
215  /// isSignedIntSetCC - Return true if this is a setcc instruction that
216  /// performs a signed comparison when used with integer operands.
217  inline bool isSignedIntSetCC(CondCode Code) {
218    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
219  }
220
221  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
222  /// performs an unsigned comparison when used with integer operands.
223  inline bool isUnsignedIntSetCC(CondCode Code) {
224    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
225  }
226
227  /// isTrueWhenEqual - Return true if the specified condition returns true if
228  /// the two operands to the condition are equal.  Note that if one of the two
229  /// operands is a NaN, this value is meaningless.
230  inline bool isTrueWhenEqual(CondCode Cond) {
231    return ((int)Cond & 1) != 0;
232  }
233
234  /// getUnorderedFlavor - This function returns 0 if the condition is always
235  /// false if an operand is a NaN, 1 if the condition is always true if the
236  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
237  /// NaN.
238  inline unsigned getUnorderedFlavor(CondCode Cond) {
239    return ((int)Cond >> 3) & 3;
240  }
241
242  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
243  /// 'op' is a valid SetCC operation.
244  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
245
246  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
247  /// when given the operation for (X op Y).
248  CondCode getSetCCSwappedOperands(CondCode Operation);
249
250  /// getSetCCOrOperation - Return the result of a logical OR between different
251  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
252  /// function returns SETCC_INVALID if it is not possible to represent the
253  /// resultant comparison.
254  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
255
256  /// getSetCCAndOperation - Return the result of a logical AND between
257  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
258  /// function returns SETCC_INVALID if it is not possible to represent the
259  /// resultant comparison.
260  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
261}  // end llvm::ISD namespace
262
263
264//===----------------------------------------------------------------------===//
265/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
266/// values as the result of a computation.  Many nodes return multiple values,
267/// from loads (which define a token and a return value) to ADDC (which returns
268/// a result and a carry value), to calls (which may return an arbitrary number
269/// of values).
270///
271/// As such, each use of a SelectionDAG computation must indicate the node that
272/// computes it as well as which return value to use from that node.  This pair
273/// of information is represented with the SDOperand value type.
274///
275class SDOperand {
276public:
277  SDNode *Val;        // The node defining the value we are using.
278  unsigned ResNo;     // Which return value of the node we are using.
279
280  SDOperand() : Val(0) {}
281  SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
282
283  bool operator==(const SDOperand &O) const {
284    return Val == O.Val && ResNo == O.ResNo;
285  }
286  bool operator!=(const SDOperand &O) const {
287    return !operator==(O);
288  }
289  bool operator<(const SDOperand &O) const {
290    return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
291  }
292
293  SDOperand getValue(unsigned R) const {
294    return SDOperand(Val, R);
295  }
296
297  /// getValueType - Return the ValueType of the referenced return value.
298  ///
299  inline MVT::ValueType getValueType() const;
300
301  // Forwarding methods - These forward to the corresponding methods in SDNode.
302  inline unsigned getOpcode() const;
303  inline unsigned getNumOperands() const;
304  inline const SDOperand &getOperand(unsigned i) const;
305};
306
307
308/// simplify_type specializations - Allow casting operators to work directly on
309/// SDOperands as if they were SDNode*'s.
310template<> struct simplify_type<SDOperand> {
311  typedef SDNode* SimpleType;
312  static SimpleType getSimplifiedValue(const SDOperand &Val) {
313    return static_cast<SimpleType>(Val.Val);
314  }
315};
316template<> struct simplify_type<const SDOperand> {
317  typedef SDNode* SimpleType;
318  static SimpleType getSimplifiedValue(const SDOperand &Val) {
319    return static_cast<SimpleType>(Val.Val);
320  }
321};
322
323
324/// SDNode - Represents one node in the SelectionDAG.
325///
326class SDNode {
327  unsigned NodeType;
328  std::vector<SDOperand> Operands;
329
330  /// Values - The types of the values this node defines.  SDNode's may define
331  /// multiple values simultaneously.
332  std::vector<MVT::ValueType> Values;
333
334  /// Uses - These are all of the SDNode's that use a value produced by this
335  /// node.
336  std::vector<SDNode*> Uses;
337public:
338
339  //===--------------------------------------------------------------------===//
340  //  Accessors
341  //
342  unsigned getOpcode()  const { return NodeType; }
343
344  size_t use_size() const { return Uses.size(); }
345  bool use_empty() const { return Uses.empty(); }
346  bool hasOneUse() const { return Uses.size() == 1; }
347
348  /// getNumOperands - Return the number of values used by this operation.
349  ///
350  unsigned getNumOperands() const { return Operands.size(); }
351
352  const SDOperand &getOperand(unsigned Num) {
353    assert(Num < Operands.size() && "Invalid child # of SDNode!");
354    return Operands[Num];
355  }
356
357  const SDOperand &getOperand(unsigned Num) const {
358    assert(Num < Operands.size() && "Invalid child # of SDNode!");
359    return Operands[Num];
360  }
361
362  /// getNumValues - Return the number of values defined/returned by this
363  /// operator.
364  ///
365  unsigned getNumValues() const { return Values.size(); }
366
367  /// getValueType - Return the type of a specified result.
368  ///
369  MVT::ValueType getValueType(unsigned ResNo) const {
370    assert(ResNo < Values.size() && "Illegal result number!");
371    return Values[ResNo];
372  }
373
374  void dump() const;
375
376  static bool classof(const SDNode *) { return true; }
377
378protected:
379  friend class SelectionDAG;
380
381  SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT) {
382    Values.reserve(1);
383    Values.push_back(VT);
384  }
385
386  SDNode(unsigned NT, SDOperand Op)
387    : NodeType(NT) {
388    Operands.reserve(1); Operands.push_back(Op);
389    Op.Val->Uses.push_back(this);
390  }
391  SDNode(unsigned NT, SDOperand N1, SDOperand N2)
392    : NodeType(NT) {
393    Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
394    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
395  }
396  SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
397    : NodeType(NT) {
398    Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
399    Operands.push_back(N3);
400    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
401    N3.Val->Uses.push_back(this);
402  }
403  SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
404    Operands.swap(Nodes);
405    for (unsigned i = 0, e = Nodes.size(); i != e; ++i)
406      Nodes[i].Val->Uses.push_back(this);
407  }
408
409  virtual ~SDNode() {
410    // FIXME: Drop uses.
411  }
412
413  void setValueTypes(MVT::ValueType VT) {
414    Values.reserve(1);
415    Values.push_back(VT);
416  }
417  void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
418    Values.reserve(2);
419    Values.push_back(VT1);
420    Values.push_back(VT2);
421  }
422  /// Note: this method destroys the vector passed in.
423  void setValueTypes(std::vector<MVT::ValueType> &VTs) {
424    std::swap(Values, VTs);
425  }
426
427  void removeUser(SDNode *User) {
428    // Remove this user from the operand's use list.
429    for (unsigned i = Uses.size(); ; --i) {
430      assert(i != 0 && "Didn't find user!");
431      if (Uses[i-1] == User) {
432        Uses.erase(Uses.begin()+i-1);
433        break;
434      }
435    }
436  }
437};
438
439
440// Define inline functions from the SDOperand class.
441
442inline unsigned SDOperand::getOpcode() const {
443  return Val->getOpcode();
444}
445inline MVT::ValueType SDOperand::getValueType() const {
446  return Val->getValueType(ResNo);
447}
448inline unsigned SDOperand::getNumOperands() const {
449  return Val->getNumOperands();
450}
451inline const SDOperand &SDOperand::getOperand(unsigned i) const {
452  return Val->getOperand(i);
453}
454
455
456
457class ConstantSDNode : public SDNode {
458  uint64_t Value;
459protected:
460  friend class SelectionDAG;
461  ConstantSDNode(uint64_t val, MVT::ValueType VT)
462    : SDNode(ISD::Constant, VT), Value(val) {
463  }
464public:
465
466  uint64_t getValue() const { return Value; }
467
468  int64_t getSignExtended() const {
469    unsigned Bits = MVT::getSizeInBits(getValueType(0));
470    return ((int64_t)Value << (64-Bits)) >> (64-Bits);
471  }
472
473  bool isNullValue() const { return Value == 0; }
474  bool isAllOnesValue() const {
475    return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
476  }
477
478  static bool classof(const ConstantSDNode *) { return true; }
479  static bool classof(const SDNode *N) {
480    return N->getOpcode() == ISD::Constant;
481  }
482};
483
484class ConstantFPSDNode : public SDNode {
485  double Value;
486protected:
487  friend class SelectionDAG;
488  ConstantFPSDNode(double val, MVT::ValueType VT)
489    : SDNode(ISD::ConstantFP, VT), Value(val) {
490  }
491public:
492
493  double getValue() const { return Value; }
494
495  /// isExactlyValue - We don't rely on operator== working on double values, as
496  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
497  /// As such, this method can be used to do an exact bit-for-bit comparison of
498  /// two floating point values.
499  bool isExactlyValue(double V) const {
500    union {
501      double V;
502      uint64_t I;
503    } T1;
504    T1.V = Value;
505    union {
506      double V;
507      uint64_t I;
508    } T2;
509    T2.V = V;
510    return T1.I == T2.I;
511  }
512
513  static bool classof(const ConstantFPSDNode *) { return true; }
514  static bool classof(const SDNode *N) {
515    return N->getOpcode() == ISD::ConstantFP;
516  }
517};
518
519class GlobalAddressSDNode : public SDNode {
520  GlobalValue *TheGlobal;
521protected:
522  friend class SelectionDAG;
523  GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
524    : SDNode(ISD::GlobalAddress, VT) {
525    TheGlobal = const_cast<GlobalValue*>(GA);
526  }
527public:
528
529  GlobalValue *getGlobal() const { return TheGlobal; }
530
531  static bool classof(const GlobalAddressSDNode *) { return true; }
532  static bool classof(const SDNode *N) {
533    return N->getOpcode() == ISD::GlobalAddress;
534  }
535};
536
537
538class FrameIndexSDNode : public SDNode {
539  int FI;
540protected:
541  friend class SelectionDAG;
542  FrameIndexSDNode(int fi, MVT::ValueType VT)
543    : SDNode(ISD::FrameIndex, VT), FI(fi) {}
544public:
545
546  int getIndex() const { return FI; }
547
548  static bool classof(const FrameIndexSDNode *) { return true; }
549  static bool classof(const SDNode *N) {
550    return N->getOpcode() == ISD::FrameIndex;
551  }
552};
553
554class ConstantPoolSDNode : public SDNode {
555  unsigned CPI;
556protected:
557  friend class SelectionDAG;
558  ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
559    : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
560public:
561
562  unsigned getIndex() const { return CPI; }
563
564  static bool classof(const ConstantPoolSDNode *) { return true; }
565  static bool classof(const SDNode *N) {
566    return N->getOpcode() == ISD::ConstantPool;
567  }
568};
569
570class BasicBlockSDNode : public SDNode {
571  MachineBasicBlock *MBB;
572protected:
573  friend class SelectionDAG;
574  BasicBlockSDNode(MachineBasicBlock *mbb)
575    : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
576public:
577
578  MachineBasicBlock *getBasicBlock() const { return MBB; }
579
580  static bool classof(const BasicBlockSDNode *) { return true; }
581  static bool classof(const SDNode *N) {
582    return N->getOpcode() == ISD::BasicBlock;
583  }
584};
585
586
587class CopyRegSDNode : public SDNode {
588  unsigned Reg;
589protected:
590  friend class SelectionDAG;
591  CopyRegSDNode(SDOperand Chain, SDOperand Src, unsigned reg)
592    : SDNode(ISD::CopyToReg, Chain, Src), Reg(reg) {
593    setValueTypes(MVT::Other);  // Just a token chain.
594  }
595  CopyRegSDNode(unsigned reg, MVT::ValueType VT)
596    : SDNode(ISD::CopyFromReg, VT), Reg(reg) {
597  }
598public:
599
600  unsigned getReg() const { return Reg; }
601
602  static bool classof(const CopyRegSDNode *) { return true; }
603  static bool classof(const SDNode *N) {
604    return N->getOpcode() == ISD::CopyToReg ||
605           N->getOpcode() == ISD::CopyFromReg;
606  }
607};
608
609class ExternalSymbolSDNode : public SDNode {
610  const char *Symbol;
611protected:
612  friend class SelectionDAG;
613  ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
614    : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
615    }
616public:
617
618  const char *getSymbol() const { return Symbol; }
619
620  static bool classof(const ExternalSymbolSDNode *) { return true; }
621  static bool classof(const SDNode *N) {
622    return N->getOpcode() == ISD::ExternalSymbol;
623  }
624};
625
626class SetCCSDNode : public SDNode {
627  ISD::CondCode Condition;
628protected:
629  friend class SelectionDAG;
630  SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
631    : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
632    setValueTypes(MVT::i1);
633  }
634public:
635
636  ISD::CondCode getCondition() const { return Condition; }
637
638  static bool classof(const SetCCSDNode *) { return true; }
639  static bool classof(const SDNode *N) {
640    return N->getOpcode() == ISD::SETCC;
641  }
642};
643
644
645class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
646  SDNode *Node;
647  unsigned Operand;
648
649  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
650public:
651  bool operator==(const SDNodeIterator& x) const {
652    return Operand == x.Operand;
653  }
654  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
655
656  const SDNodeIterator &operator=(const SDNodeIterator &I) {
657    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
658    Operand = I.Operand;
659    return *this;
660  }
661
662  pointer operator*() const {
663    return Node->getOperand(Operand).Val;
664  }
665  pointer operator->() const { return operator*(); }
666
667  SDNodeIterator& operator++() {                // Preincrement
668    ++Operand;
669    return *this;
670  }
671  SDNodeIterator operator++(int) { // Postincrement
672    SDNodeIterator tmp = *this; ++*this; return tmp;
673  }
674
675  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
676  static SDNodeIterator end  (SDNode *N) {
677    return SDNodeIterator(N, N->getNumOperands());
678  }
679
680  unsigned getOperand() const { return Operand; }
681  const SDNode *getNode() const { return Node; }
682};
683
684template <> struct GraphTraits<SDNode*> {
685  typedef SDNode NodeType;
686  typedef SDNodeIterator ChildIteratorType;
687  static inline NodeType *getEntryNode(SDNode *N) { return N; }
688  static inline ChildIteratorType child_begin(NodeType *N) {
689    return SDNodeIterator::begin(N);
690  }
691  static inline ChildIteratorType child_end(NodeType *N) {
692    return SDNodeIterator::end(N);
693  }
694};
695
696
697
698
699} // end llvm namespace
700
701#endif
702