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