Update comments to indicate CopyFrom/ToReg take physregs as well as vregs.
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAGNodes.h
1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file 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
30 namespace llvm {
31
32 class SelectionDAG;
33 class GlobalValue;
34 class MachineBasicBlock;
35 class SDNode;
36 template <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 ///
41 namespace 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 ///
283 class SDOperand {
284 public:
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.
318 template<> struct simplify_type<SDOperand> {
319   typedef SDNode* SimpleType;
320   static SimpleType getSimplifiedValue(const SDOperand &Val) {
321     return static_cast<SimpleType>(Val.Val);
322   }
323 };
324 template<> 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 ///
334 class 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;
345 public:
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   /// getNumOperands - Return the number of values used by this operation.
357   ///
358   unsigned getNumOperands() const { return Operands.size(); }
359
360   const SDOperand &getOperand(unsigned Num) {
361     assert(Num < Operands.size() && "Invalid child # of SDNode!");
362     return Operands[Num];
363   }
364
365   const SDOperand &getOperand(unsigned Num) const {
366     assert(Num < Operands.size() && "Invalid child # of SDNode!");
367     return Operands[Num];
368   }
369
370   /// getNumValues - Return the number of values defined/returned by this
371   /// operator.
372   ///
373   unsigned getNumValues() const { return Values.size(); }
374
375   /// getValueType - Return the type of a specified result.
376   ///
377   MVT::ValueType getValueType(unsigned ResNo) const {
378     assert(ResNo < Values.size() && "Illegal result number!");
379     return Values[ResNo];
380   }
381
382   /// getOperationName - Return the opcode of this operation for printing.
383   ///
384   const char* getOperationName() const;
385   void dump() const;
386
387   static bool classof(const SDNode *) { return true; }
388
389 protected:
390   friend class SelectionDAG;
391
392   SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT) {
393     Values.reserve(1);
394     Values.push_back(VT);
395   }
396
397   SDNode(unsigned NT, SDOperand Op)
398     : NodeType(NT) {
399     Operands.reserve(1); Operands.push_back(Op);
400     Op.Val->Uses.push_back(this);
401   }
402   SDNode(unsigned NT, SDOperand N1, SDOperand N2)
403     : NodeType(NT) {
404     Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
405     N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
406   }
407   SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
408     : NodeType(NT) {
409     Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
410     Operands.push_back(N3);
411     N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
412     N3.Val->Uses.push_back(this);
413   }
414   SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
415     Operands.swap(Nodes);
416     for (unsigned i = 0, e = Operands.size(); i != e; ++i)
417       Operands[i].Val->Uses.push_back(this);
418   }
419
420   virtual ~SDNode() {
421     // FIXME: Drop uses.
422   }
423
424   void setValueTypes(MVT::ValueType VT) {
425     Values.reserve(1);
426     Values.push_back(VT);
427   }
428   void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
429     Values.reserve(2);
430     Values.push_back(VT1);
431     Values.push_back(VT2);
432   }
433   /// Note: this method destroys the vector passed in.
434   void setValueTypes(std::vector<MVT::ValueType> &VTs) {
435     std::swap(Values, VTs);
436   }
437
438   void removeUser(SDNode *User) {
439     // Remove this user from the operand's use list.
440     for (unsigned i = Uses.size(); ; --i) {
441       assert(i != 0 && "Didn't find user!");
442       if (Uses[i-1] == User) {
443         Uses.erase(Uses.begin()+i-1);
444         break;
445       }
446     }
447   }
448 };
449
450
451 // Define inline functions from the SDOperand class.
452
453 inline unsigned SDOperand::getOpcode() const {
454   return Val->getOpcode();
455 }
456 inline MVT::ValueType SDOperand::getValueType() const {
457   return Val->getValueType(ResNo);
458 }
459 inline unsigned SDOperand::getNumOperands() const {
460   return Val->getNumOperands();
461 }
462 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
463   return Val->getOperand(i);
464 }
465
466
467
468 class ConstantSDNode : public SDNode {
469   uint64_t Value;
470 protected:
471   friend class SelectionDAG;
472   ConstantSDNode(uint64_t val, MVT::ValueType VT)
473     : SDNode(ISD::Constant, VT), Value(val) {
474   }
475 public:
476
477   uint64_t getValue() const { return Value; }
478
479   int64_t getSignExtended() const {
480     unsigned Bits = MVT::getSizeInBits(getValueType(0));
481     return ((int64_t)Value << (64-Bits)) >> (64-Bits);
482   }
483
484   bool isNullValue() const { return Value == 0; }
485   bool isAllOnesValue() const {
486     return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
487   }
488
489   static bool classof(const ConstantSDNode *) { return true; }
490   static bool classof(const SDNode *N) {
491     return N->getOpcode() == ISD::Constant;
492   }
493 };
494
495 class ConstantFPSDNode : public SDNode {
496   double Value;
497 protected:
498   friend class SelectionDAG;
499   ConstantFPSDNode(double val, MVT::ValueType VT)
500     : SDNode(ISD::ConstantFP, VT), Value(val) {
501   }
502 public:
503
504   double getValue() const { return Value; }
505
506   /// isExactlyValue - We don't rely on operator== working on double values, as
507   /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
508   /// As such, this method can be used to do an exact bit-for-bit comparison of
509   /// two floating point values.
510   bool isExactlyValue(double V) const {
511     union {
512       double V;
513       uint64_t I;
514     } T1;
515     T1.V = Value;
516     union {
517       double V;
518       uint64_t I;
519     } T2;
520     T2.V = V;
521     return T1.I == T2.I;
522   }
523
524   static bool classof(const ConstantFPSDNode *) { return true; }
525   static bool classof(const SDNode *N) {
526     return N->getOpcode() == ISD::ConstantFP;
527   }
528 };
529
530 class GlobalAddressSDNode : public SDNode {
531   GlobalValue *TheGlobal;
532 protected:
533   friend class SelectionDAG;
534   GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
535     : SDNode(ISD::GlobalAddress, VT) {
536     TheGlobal = const_cast<GlobalValue*>(GA);
537   }
538 public:
539
540   GlobalValue *getGlobal() const { return TheGlobal; }
541
542   static bool classof(const GlobalAddressSDNode *) { return true; }
543   static bool classof(const SDNode *N) {
544     return N->getOpcode() == ISD::GlobalAddress;
545   }
546 };
547
548
549 class FrameIndexSDNode : public SDNode {
550   int FI;
551 protected:
552   friend class SelectionDAG;
553   FrameIndexSDNode(int fi, MVT::ValueType VT)
554     : SDNode(ISD::FrameIndex, VT), FI(fi) {}
555 public:
556
557   int getIndex() const { return FI; }
558
559   static bool classof(const FrameIndexSDNode *) { return true; }
560   static bool classof(const SDNode *N) {
561     return N->getOpcode() == ISD::FrameIndex;
562   }
563 };
564
565 class ConstantPoolSDNode : public SDNode {
566   unsigned CPI;
567 protected:
568   friend class SelectionDAG;
569   ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
570     : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
571 public:
572
573   unsigned getIndex() const { return CPI; }
574
575   static bool classof(const ConstantPoolSDNode *) { return true; }
576   static bool classof(const SDNode *N) {
577     return N->getOpcode() == ISD::ConstantPool;
578   }
579 };
580
581 class BasicBlockSDNode : public SDNode {
582   MachineBasicBlock *MBB;
583 protected:
584   friend class SelectionDAG;
585   BasicBlockSDNode(MachineBasicBlock *mbb)
586     : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
587 public:
588
589   MachineBasicBlock *getBasicBlock() const { return MBB; }
590
591   static bool classof(const BasicBlockSDNode *) { return true; }
592   static bool classof(const SDNode *N) {
593     return N->getOpcode() == ISD::BasicBlock;
594   }
595 };
596
597
598 class CopyRegSDNode : public SDNode {
599   unsigned Reg;
600 protected:
601   friend class SelectionDAG;
602   CopyRegSDNode(SDOperand Chain, SDOperand Src, unsigned reg)
603     : SDNode(ISD::CopyToReg, Chain, Src), Reg(reg) {
604     setValueTypes(MVT::Other);  // Just a token chain.
605   }
606   CopyRegSDNode(unsigned reg, MVT::ValueType VT)
607     : SDNode(ISD::CopyFromReg, VT), Reg(reg) {
608   }
609 public:
610
611   unsigned getReg() const { return Reg; }
612
613   static bool classof(const CopyRegSDNode *) { return true; }
614   static bool classof(const SDNode *N) {
615     return N->getOpcode() == ISD::CopyToReg ||
616            N->getOpcode() == ISD::CopyFromReg;
617   }
618 };
619
620 class ExternalSymbolSDNode : public SDNode {
621   const char *Symbol;
622 protected:
623   friend class SelectionDAG;
624   ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
625     : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
626     }
627 public:
628
629   const char *getSymbol() const { return Symbol; }
630
631   static bool classof(const ExternalSymbolSDNode *) { return true; }
632   static bool classof(const SDNode *N) {
633     return N->getOpcode() == ISD::ExternalSymbol;
634   }
635 };
636
637 class SetCCSDNode : public SDNode {
638   ISD::CondCode Condition;
639 protected:
640   friend class SelectionDAG;
641   SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
642     : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
643     setValueTypes(MVT::i1);
644   }
645 public:
646
647   ISD::CondCode getCondition() const { return Condition; }
648
649   static bool classof(const SetCCSDNode *) { return true; }
650   static bool classof(const SDNode *N) {
651     return N->getOpcode() == ISD::SETCC;
652   }
653 };
654
655
656 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
657   SDNode *Node;
658   unsigned Operand;
659   
660   SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
661 public:
662   bool operator==(const SDNodeIterator& x) const {
663     return Operand == x.Operand;
664   }
665   bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
666
667   const SDNodeIterator &operator=(const SDNodeIterator &I) {
668     assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
669     Operand = I.Operand;
670     return *this;
671   }
672   
673   pointer operator*() const {
674     return Node->getOperand(Operand).Val;
675   }
676   pointer operator->() const { return operator*(); }
677   
678   SDNodeIterator& operator++() {                // Preincrement
679     ++Operand;
680     return *this;
681   }
682   SDNodeIterator operator++(int) { // Postincrement
683     SDNodeIterator tmp = *this; ++*this; return tmp; 
684   }
685
686   static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
687   static SDNodeIterator end  (SDNode *N) {
688     return SDNodeIterator(N, N->getNumOperands());
689   }
690
691   unsigned getOperand() const { return Operand; }
692   const SDNode *getNode() const { return Node; }
693 };
694
695 template <> struct GraphTraits<SDNode*> {
696   typedef SDNode NodeType;
697   typedef SDNodeIterator ChildIteratorType;
698   static inline NodeType *getEntryNode(SDNode *N) { return N; }
699   static inline ChildIteratorType child_begin(NodeType *N) { 
700     return SDNodeIterator::begin(N);
701   }
702   static inline ChildIteratorType child_end(NodeType *N) { 
703     return SDNodeIterator::end(N);
704   }
705 };
706
707
708
709
710 } // end llvm namespace
711
712 #endif