SelectionDAGNodes.h revision b18a2f816cc9d1351ca8e380a6db5c5ef981943e
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 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 register number is available from the CopyRegSDNode
60    // 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    // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
159    // correspond to the operands of the LLVM intrinsic functions.  The only
160    // result is a token chain.  The alignment argument is guaranteed to be a
161    // Constant node.
162    MEMSET,
163    MEMMOVE,
164    MEMCPY,
165
166    // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and
167    // end of a call sequence and indicate how much the stack pointer needs to
168    // be adjusted for that particular call.  The first operand is a chain, the
169    // second is a ConstantSDNode of intptr type.
170    ADJCALLSTACKDOWN,  // Beginning of a call sequence
171    ADJCALLSTACKUP,    // End of a call sequence
172
173
174    // BUILTIN_OP_END - This must be the last enum value in this list.
175    BUILTIN_OP_END,
176  };
177
178  //===--------------------------------------------------------------------===//
179  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
180  /// below work out, when considering SETFALSE (something that never exists
181  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
182  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
183  /// to.  If the "N" column is 1, the result of the comparison is undefined if
184  /// the input is a NAN.
185  ///
186  /// All of these (except for the 'always folded ops') should be handled for
187  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
188  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
189  ///
190  /// Note that these are laid out in a specific order to allow bit-twiddling
191  /// to transform conditions.
192  enum CondCode {
193    // Opcode          N U L G E       Intuitive operation
194    SETFALSE,      //    0 0 0 0       Always false (always folded)
195    SETOEQ,        //    0 0 0 1       True if ordered and equal
196    SETOGT,        //    0 0 1 0       True if ordered and greater than
197    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
198    SETOLT,        //    0 1 0 0       True if ordered and less than
199    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
200    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
201    SETO,          //    0 1 1 1       True if ordered (no nans)
202    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
203    SETUEQ,        //    1 0 0 1       True if unordered or equal
204    SETUGT,        //    1 0 1 0       True if unordered or greater than
205    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
206    SETULT,        //    1 1 0 0       True if unordered or less than
207    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
208    SETUNE,        //    1 1 1 0       True if unordered or not equal
209    SETTRUE,       //    1 1 1 1       Always true (always folded)
210    // Don't care operations: undefined if the input is a nan.
211    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
212    SETEQ,         //  1 X 0 0 1       True if equal
213    SETGT,         //  1 X 0 1 0       True if greater than
214    SETGE,         //  1 X 0 1 1       True if greater than or equal
215    SETLT,         //  1 X 1 0 0       True if less than
216    SETLE,         //  1 X 1 0 1       True if less than or equal
217    SETNE,         //  1 X 1 1 0       True if not equal
218    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
219
220    SETCC_INVALID,      // Marker value.
221  };
222
223  /// isSignedIntSetCC - Return true if this is a setcc instruction that
224  /// performs a signed comparison when used with integer operands.
225  inline bool isSignedIntSetCC(CondCode Code) {
226    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
227  }
228
229  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
230  /// performs an unsigned comparison when used with integer operands.
231  inline bool isUnsignedIntSetCC(CondCode Code) {
232    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
233  }
234
235  /// isTrueWhenEqual - Return true if the specified condition returns true if
236  /// the two operands to the condition are equal.  Note that if one of the two
237  /// operands is a NaN, this value is meaningless.
238  inline bool isTrueWhenEqual(CondCode Cond) {
239    return ((int)Cond & 1) != 0;
240  }
241
242  /// getUnorderedFlavor - This function returns 0 if the condition is always
243  /// false if an operand is a NaN, 1 if the condition is always true if the
244  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
245  /// NaN.
246  inline unsigned getUnorderedFlavor(CondCode Cond) {
247    return ((int)Cond >> 3) & 3;
248  }
249
250  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
251  /// 'op' is a valid SetCC operation.
252  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
253
254  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
255  /// when given the operation for (X op Y).
256  CondCode getSetCCSwappedOperands(CondCode Operation);
257
258  /// getSetCCOrOperation - Return the result of a logical OR between different
259  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
260  /// function returns SETCC_INVALID if it is not possible to represent the
261  /// resultant comparison.
262  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
263
264  /// getSetCCAndOperation - Return the result of a logical AND between
265  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
266  /// function returns SETCC_INVALID if it is not possible to represent the
267  /// resultant comparison.
268  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
269}  // end llvm::ISD namespace
270
271
272//===----------------------------------------------------------------------===//
273/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
274/// values as the result of a computation.  Many nodes return multiple values,
275/// from loads (which define a token and a return value) to ADDC (which returns
276/// a result and a carry value), to calls (which may return an arbitrary number
277/// of values).
278///
279/// As such, each use of a SelectionDAG computation must indicate the node that
280/// computes it as well as which return value to use from that node.  This pair
281/// of information is represented with the SDOperand value type.
282///
283class SDOperand {
284public:
285  SDNode *Val;        // The node defining the value we are using.
286  unsigned ResNo;     // Which return value of the node we are using.
287
288  SDOperand() : Val(0) {}
289  SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
290
291  bool operator==(const SDOperand &O) const {
292    return Val == O.Val && ResNo == O.ResNo;
293  }
294  bool operator!=(const SDOperand &O) const {
295    return !operator==(O);
296  }
297  bool operator<(const SDOperand &O) const {
298    return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
299  }
300
301  SDOperand getValue(unsigned R) const {
302    return SDOperand(Val, R);
303  }
304
305  /// getValueType - Return the ValueType of the referenced return value.
306  ///
307  inline MVT::ValueType getValueType() const;
308
309  // Forwarding methods - These forward to the corresponding methods in SDNode.
310  inline unsigned getOpcode() const;
311  inline unsigned getNumOperands() const;
312  inline const SDOperand &getOperand(unsigned i) const;
313};
314
315
316/// simplify_type specializations - Allow casting operators to work directly on
317/// SDOperands as if they were SDNode*'s.
318template<> struct simplify_type<SDOperand> {
319  typedef SDNode* SimpleType;
320  static SimpleType getSimplifiedValue(const SDOperand &Val) {
321    return static_cast<SimpleType>(Val.Val);
322  }
323};
324template<> struct simplify_type<const SDOperand> {
325  typedef SDNode* SimpleType;
326  static SimpleType getSimplifiedValue(const SDOperand &Val) {
327    return static_cast<SimpleType>(Val.Val);
328  }
329};
330
331
332/// SDNode - Represents one node in the SelectionDAG.
333///
334class SDNode {
335  unsigned NodeType;
336  std::vector<SDOperand> Operands;
337
338  /// Values - The types of the values this node defines.  SDNode's may define
339  /// multiple values simultaneously.
340  std::vector<MVT::ValueType> Values;
341
342  /// Uses - These are all of the SDNode's that use a value produced by this
343  /// node.
344  std::vector<SDNode*> Uses;
345public:
346
347  //===--------------------------------------------------------------------===//
348  //  Accessors
349  //
350  unsigned getOpcode()  const { return NodeType; }
351
352  size_t use_size() const { return Uses.size(); }
353  bool use_empty() const { return Uses.empty(); }
354  bool hasOneUse() const { return Uses.size() == 1; }
355
356  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
357  /// indicated value.  This method ignores uses of other values defined by this
358  /// operation.
359  bool hasNUsesOfValue(unsigned NUses, unsigned Value);
360
361  /// getNumOperands - Return the number of values used by this operation.
362  ///
363  unsigned getNumOperands() const { return Operands.size(); }
364
365  const SDOperand &getOperand(unsigned Num) {
366    assert(Num < Operands.size() && "Invalid child # of SDNode!");
367    return Operands[Num];
368  }
369
370  const SDOperand &getOperand(unsigned Num) const {
371    assert(Num < Operands.size() && "Invalid child # of SDNode!");
372    return Operands[Num];
373  }
374
375  /// getNumValues - Return the number of values defined/returned by this
376  /// operator.
377  ///
378  unsigned getNumValues() const { return Values.size(); }
379
380  /// getValueType - Return the type of a specified result.
381  ///
382  MVT::ValueType getValueType(unsigned ResNo) const {
383    assert(ResNo < Values.size() && "Illegal result number!");
384    return Values[ResNo];
385  }
386
387  /// getOperationName - Return the opcode of this operation for printing.
388  ///
389  const char* getOperationName() const;
390  void dump() const;
391
392  static bool classof(const SDNode *) { return true; }
393
394protected:
395  friend class SelectionDAG;
396
397  SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT) {
398    Values.reserve(1);
399    Values.push_back(VT);
400  }
401
402  SDNode(unsigned NT, SDOperand Op)
403    : NodeType(NT) {
404    Operands.reserve(1); Operands.push_back(Op);
405    Op.Val->Uses.push_back(this);
406  }
407  SDNode(unsigned NT, SDOperand N1, SDOperand N2)
408    : NodeType(NT) {
409    Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
410    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
411  }
412  SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
413    : NodeType(NT) {
414    Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
415    Operands.push_back(N3);
416    N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
417    N3.Val->Uses.push_back(this);
418  }
419  SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
420    Operands.swap(Nodes);
421    for (unsigned i = 0, e = Operands.size(); i != e; ++i)
422      Operands[i].Val->Uses.push_back(this);
423  }
424
425  virtual ~SDNode() {
426    // FIXME: Drop uses.
427  }
428
429  void setValueTypes(MVT::ValueType VT) {
430    Values.reserve(1);
431    Values.push_back(VT);
432  }
433  void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
434    Values.reserve(2);
435    Values.push_back(VT1);
436    Values.push_back(VT2);
437  }
438  /// Note: this method destroys the vector passed in.
439  void setValueTypes(std::vector<MVT::ValueType> &VTs) {
440    std::swap(Values, VTs);
441  }
442
443  void removeUser(SDNode *User) {
444    // Remove this user from the operand's use list.
445    for (unsigned i = Uses.size(); ; --i) {
446      assert(i != 0 && "Didn't find user!");
447      if (Uses[i-1] == User) {
448        Uses.erase(Uses.begin()+i-1);
449        break;
450      }
451    }
452  }
453};
454
455
456// Define inline functions from the SDOperand class.
457
458inline unsigned SDOperand::getOpcode() const {
459  return Val->getOpcode();
460}
461inline MVT::ValueType SDOperand::getValueType() const {
462  return Val->getValueType(ResNo);
463}
464inline unsigned SDOperand::getNumOperands() const {
465  return Val->getNumOperands();
466}
467inline const SDOperand &SDOperand::getOperand(unsigned i) const {
468  return Val->getOperand(i);
469}
470
471
472
473class ConstantSDNode : public SDNode {
474  uint64_t Value;
475protected:
476  friend class SelectionDAG;
477  ConstantSDNode(uint64_t val, MVT::ValueType VT)
478    : SDNode(ISD::Constant, VT), Value(val) {
479  }
480public:
481
482  uint64_t getValue() const { return Value; }
483
484  int64_t getSignExtended() const {
485    unsigned Bits = MVT::getSizeInBits(getValueType(0));
486    return ((int64_t)Value << (64-Bits)) >> (64-Bits);
487  }
488
489  bool isNullValue() const { return Value == 0; }
490  bool isAllOnesValue() const {
491    return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
492  }
493
494  static bool classof(const ConstantSDNode *) { return true; }
495  static bool classof(const SDNode *N) {
496    return N->getOpcode() == ISD::Constant;
497  }
498};
499
500class ConstantFPSDNode : public SDNode {
501  double Value;
502protected:
503  friend class SelectionDAG;
504  ConstantFPSDNode(double val, MVT::ValueType VT)
505    : SDNode(ISD::ConstantFP, VT), Value(val) {
506  }
507public:
508
509  double getValue() const { return Value; }
510
511  /// isExactlyValue - We don't rely on operator== working on double values, as
512  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
513  /// As such, this method can be used to do an exact bit-for-bit comparison of
514  /// two floating point values.
515  bool isExactlyValue(double V) const {
516    union {
517      double V;
518      uint64_t I;
519    } T1;
520    T1.V = Value;
521    union {
522      double V;
523      uint64_t I;
524    } T2;
525    T2.V = V;
526    return T1.I == T2.I;
527  }
528
529  static bool classof(const ConstantFPSDNode *) { return true; }
530  static bool classof(const SDNode *N) {
531    return N->getOpcode() == ISD::ConstantFP;
532  }
533};
534
535class GlobalAddressSDNode : public SDNode {
536  GlobalValue *TheGlobal;
537protected:
538  friend class SelectionDAG;
539  GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
540    : SDNode(ISD::GlobalAddress, VT) {
541    TheGlobal = const_cast<GlobalValue*>(GA);
542  }
543public:
544
545  GlobalValue *getGlobal() const { return TheGlobal; }
546
547  static bool classof(const GlobalAddressSDNode *) { return true; }
548  static bool classof(const SDNode *N) {
549    return N->getOpcode() == ISD::GlobalAddress;
550  }
551};
552
553
554class FrameIndexSDNode : public SDNode {
555  int FI;
556protected:
557  friend class SelectionDAG;
558  FrameIndexSDNode(int fi, MVT::ValueType VT)
559    : SDNode(ISD::FrameIndex, VT), FI(fi) {}
560public:
561
562  int getIndex() const { return FI; }
563
564  static bool classof(const FrameIndexSDNode *) { return true; }
565  static bool classof(const SDNode *N) {
566    return N->getOpcode() == ISD::FrameIndex;
567  }
568};
569
570class ConstantPoolSDNode : public SDNode {
571  unsigned CPI;
572protected:
573  friend class SelectionDAG;
574  ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
575    : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
576public:
577
578  unsigned getIndex() const { return CPI; }
579
580  static bool classof(const ConstantPoolSDNode *) { return true; }
581  static bool classof(const SDNode *N) {
582    return N->getOpcode() == ISD::ConstantPool;
583  }
584};
585
586class BasicBlockSDNode : public SDNode {
587  MachineBasicBlock *MBB;
588protected:
589  friend class SelectionDAG;
590  BasicBlockSDNode(MachineBasicBlock *mbb)
591    : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
592public:
593
594  MachineBasicBlock *getBasicBlock() const { return MBB; }
595
596  static bool classof(const BasicBlockSDNode *) { return true; }
597  static bool classof(const SDNode *N) {
598    return N->getOpcode() == ISD::BasicBlock;
599  }
600};
601
602
603class CopyRegSDNode : public SDNode {
604  unsigned Reg;
605protected:
606  friend class SelectionDAG;
607  CopyRegSDNode(SDOperand Chain, SDOperand Src, unsigned reg)
608    : SDNode(ISD::CopyToReg, Chain, Src), Reg(reg) {
609    setValueTypes(MVT::Other);  // Just a token chain.
610  }
611  CopyRegSDNode(unsigned reg, MVT::ValueType VT)
612    : SDNode(ISD::CopyFromReg, VT), Reg(reg) {
613  }
614public:
615
616  unsigned getReg() const { return Reg; }
617
618  static bool classof(const CopyRegSDNode *) { return true; }
619  static bool classof(const SDNode *N) {
620    return N->getOpcode() == ISD::CopyToReg ||
621           N->getOpcode() == ISD::CopyFromReg;
622  }
623};
624
625class ExternalSymbolSDNode : public SDNode {
626  const char *Symbol;
627protected:
628  friend class SelectionDAG;
629  ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
630    : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
631    }
632public:
633
634  const char *getSymbol() const { return Symbol; }
635
636  static bool classof(const ExternalSymbolSDNode *) { return true; }
637  static bool classof(const SDNode *N) {
638    return N->getOpcode() == ISD::ExternalSymbol;
639  }
640};
641
642class SetCCSDNode : public SDNode {
643  ISD::CondCode Condition;
644protected:
645  friend class SelectionDAG;
646  SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
647    : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
648    setValueTypes(MVT::i1);
649  }
650public:
651
652  ISD::CondCode getCondition() const { return Condition; }
653
654  static bool classof(const SetCCSDNode *) { return true; }
655  static bool classof(const SDNode *N) {
656    return N->getOpcode() == ISD::SETCC;
657  }
658};
659
660
661class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
662  SDNode *Node;
663  unsigned Operand;
664
665  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
666public:
667  bool operator==(const SDNodeIterator& x) const {
668    return Operand == x.Operand;
669  }
670  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
671
672  const SDNodeIterator &operator=(const SDNodeIterator &I) {
673    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
674    Operand = I.Operand;
675    return *this;
676  }
677
678  pointer operator*() const {
679    return Node->getOperand(Operand).Val;
680  }
681  pointer operator->() const { return operator*(); }
682
683  SDNodeIterator& operator++() {                // Preincrement
684    ++Operand;
685    return *this;
686  }
687  SDNodeIterator operator++(int) { // Postincrement
688    SDNodeIterator tmp = *this; ++*this; return tmp;
689  }
690
691  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
692  static SDNodeIterator end  (SDNode *N) {
693    return SDNodeIterator(N, N->getNumOperands());
694  }
695
696  unsigned getOperand() const { return Operand; }
697  const SDNode *getNode() const { return Node; }
698};
699
700template <> struct GraphTraits<SDNode*> {
701  typedef SDNode NodeType;
702  typedef SDNodeIterator ChildIteratorType;
703  static inline NodeType *getEntryNode(SDNode *N) { return N; }
704  static inline ChildIteratorType child_begin(NodeType *N) {
705    return SDNodeIterator::begin(N);
706  }
707  static inline ChildIteratorType child_end(NodeType *N) {
708    return SDNodeIterator::end(N);
709  }
710};
711
712
713
714
715} // end llvm namespace
716
717#endif
718