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