1 //===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
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.
15 // Clients should include the SelectionDAG.h file instead of this file directly.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
20 #define LLVM_CODEGEN_SELECTIONDAGNODES_H
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"
34 class MachineBasicBlock;
36 template <typename T> struct simplify_type;
38 /// ISD namespace - This namespace contains an enum which represents all of the
39 /// SelectionDAG node types and value types.
42 //===--------------------------------------------------------------------===//
43 /// ISD::NodeType enum - This enum defines all of the operators valid in a
47 // EntryToken - This is the marker used to indicate the start of the region.
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.
55 // Various leaf nodes.
56 Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool,
57 BasicBlock, ExternalSymbol,
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
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.
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
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.
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.
89 // Simple binary arithmetic operators.
90 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
93 AND, OR, XOR, SHL, SRA, SRL,
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
104 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
105 // broken into a multiple pieces each, and return the resulting pieces of
106 // doing an atomic add/sub operation. This is used to handle add/sub of
107 // expanded types. The operation ordering is:
108 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
109 ADD_PARTS, SUB_PARTS,
111 // Conversion operators. These are all single input single output
112 // operations. For all of these, the result type must be strictly
113 // wider or narrower (depending on the operation) than the source
116 // SIGN_EXTEND - Used for integer types, replicating the sign bit
120 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
123 // TRUNCATE - Completely drop the high bits.
126 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
127 // depends on the first letter) to floating point.
131 // SIGN_EXTEND_INREG/ZERO_EXTEND_INREG - These operators atomically performs
132 // a SHL/(SRA|SHL) pair to (sign|zero) extend a small value in a large
133 // integer register (e.g. sign extending the low 8 bits of a 32-bit register
134 // to fill the top 24 bits with the 7th bit). The size of the smaller type
135 // is indicated by the ExtraValueType in the MVTSDNode for the operator.
139 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
144 // FP_ROUND - Perform a rounding operation from the current
145 // precision down to the specified precision (currently always 64->32).
148 // FP_ROUND_INREG - This operator takes a floating point register, and
149 // rounds it to a floating point value. It then promotes it and returns it
150 // in a register of the same size. This operation effectively just discards
151 // excess precision. The type to round down to is specified by the
152 // ExtraValueType in the MVTSDNode (currently always 64->32->64).
155 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
158 // Other operators. LOAD and STORE have token chains as their first
159 // operand, then the same operands as an LLVM load/store instruction.
162 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the
163 // MVTSDNode. All of these load a value from memory and extend them to a
164 // larger value (e.g. load a byte into a word register). All three of these
165 // have two operands, a chain and a pointer to load from. The extra value
166 // type is the source type being loaded.
168 // SEXTLOAD loads the integer operand and sign extends it to a larger
169 // integer result type.
170 // ZEXTLOAD loads the integer operand and zero extends it to a larger
171 // integer result type.
172 // EXTLOAD is used for two things: floating point extending loads, and
173 // integer extending loads where it doesn't matter what the high
174 // bits are set to. The code generator is allowed to codegen this
175 // into whichever operation is more efficient.
176 EXTLOAD, SEXTLOAD, ZEXTLOAD,
178 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
179 // value and stores it to memory in one operation. This can be used for
180 // either integer or floating point operands, and the stored type
181 // represented as the 'extra' value type in the MVTSDNode representing the
182 // operator. This node has the same three operands as a standard store.
185 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
186 // to a specified boundary. The first operand is the token chain, the
187 // second is the number of bytes to allocate, and the third is the alignment
191 // Control flow instructions. These all have token chains.
193 // BR - Unconditional branch. The first operand is the chain
194 // operand, the second is the MBB to branch to.
197 // BRCOND - Conditional branch. The first operand is the chain,
198 // the second is the condition, the third is the block to branch
199 // to if the condition is true.
202 // RET - Return from function. The first operand is the chain,
203 // and any subsequent operands are the return values for the
204 // function. This operation can have variable number of operands.
207 // CALL - Call to a function pointer. The first operand is the chain, the
208 // second is the destination function pointer (a GlobalAddress for a direct
209 // call). Arguments have already been lowered to explicit DAGs according to
210 // the calling convention in effect here.
213 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
214 // correspond to the operands of the LLVM intrinsic functions. The only
215 // result is a token chain. The alignment argument is guaranteed to be a
221 // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and
222 // end of a call sequence and indicate how much the stack pointer needs to
223 // be adjusted for that particular call. The first operand is a chain, the
224 // second is a ConstantSDNode of intptr type.
225 ADJCALLSTACKDOWN, // Beginning of a call sequence
226 ADJCALLSTACKUP, // End of a call sequence
229 // BUILTIN_OP_END - This must be the last enum value in this list.
233 //===--------------------------------------------------------------------===//
234 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
235 /// below work out, when considering SETFALSE (something that never exists
236 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
237 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
238 /// to. If the "N" column is 1, the result of the comparison is undefined if
239 /// the input is a NAN.
241 /// All of these (except for the 'always folded ops') should be handled for
242 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
243 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
245 /// Note that these are laid out in a specific order to allow bit-twiddling
246 /// to transform conditions.
248 // Opcode N U L G E Intuitive operation
249 SETFALSE, // 0 0 0 0 Always false (always folded)
250 SETOEQ, // 0 0 0 1 True if ordered and equal
251 SETOGT, // 0 0 1 0 True if ordered and greater than
252 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
253 SETOLT, // 0 1 0 0 True if ordered and less than
254 SETOLE, // 0 1 0 1 True if ordered and less than or equal
255 SETONE, // 0 1 1 0 True if ordered and operands are unequal
256 SETO, // 0 1 1 1 True if ordered (no nans)
257 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
258 SETUEQ, // 1 0 0 1 True if unordered or equal
259 SETUGT, // 1 0 1 0 True if unordered or greater than
260 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
261 SETULT, // 1 1 0 0 True if unordered or less than
262 SETULE, // 1 1 0 1 True if unordered, less than, or equal
263 SETUNE, // 1 1 1 0 True if unordered or not equal
264 SETTRUE, // 1 1 1 1 Always true (always folded)
265 // Don't care operations: undefined if the input is a nan.
266 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
267 SETEQ, // 1 X 0 0 1 True if equal
268 SETGT, // 1 X 0 1 0 True if greater than
269 SETGE, // 1 X 0 1 1 True if greater than or equal
270 SETLT, // 1 X 1 0 0 True if less than
271 SETLE, // 1 X 1 0 1 True if less than or equal
272 SETNE, // 1 X 1 1 0 True if not equal
273 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
275 SETCC_INVALID, // Marker value.
278 /// isSignedIntSetCC - Return true if this is a setcc instruction that
279 /// performs a signed comparison when used with integer operands.
280 inline bool isSignedIntSetCC(CondCode Code) {
281 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
284 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
285 /// performs an unsigned comparison when used with integer operands.
286 inline bool isUnsignedIntSetCC(CondCode Code) {
287 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
290 /// isTrueWhenEqual - Return true if the specified condition returns true if
291 /// the two operands to the condition are equal. Note that if one of the two
292 /// operands is a NaN, this value is meaningless.
293 inline bool isTrueWhenEqual(CondCode Cond) {
294 return ((int)Cond & 1) != 0;
297 /// getUnorderedFlavor - This function returns 0 if the condition is always
298 /// false if an operand is a NaN, 1 if the condition is always true if the
299 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
301 inline unsigned getUnorderedFlavor(CondCode Cond) {
302 return ((int)Cond >> 3) & 3;
305 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
306 /// 'op' is a valid SetCC operation.
307 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
309 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
310 /// when given the operation for (X op Y).
311 CondCode getSetCCSwappedOperands(CondCode Operation);
313 /// getSetCCOrOperation - Return the result of a logical OR between different
314 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
315 /// function returns SETCC_INVALID if it is not possible to represent the
316 /// resultant comparison.
317 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
319 /// getSetCCAndOperation - Return the result of a logical AND between
320 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
321 /// function returns SETCC_INVALID if it is not possible to represent the
322 /// resultant comparison.
323 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
324 } // end llvm::ISD namespace
327 //===----------------------------------------------------------------------===//
328 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
329 /// values as the result of a computation. Many nodes return multiple values,
330 /// from loads (which define a token and a return value) to ADDC (which returns
331 /// a result and a carry value), to calls (which may return an arbitrary number
334 /// As such, each use of a SelectionDAG computation must indicate the node that
335 /// computes it as well as which return value to use from that node. This pair
336 /// of information is represented with the SDOperand value type.
340 SDNode *Val; // The node defining the value we are using.
341 unsigned ResNo; // Which return value of the node we are using.
343 SDOperand() : Val(0) {}
344 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
346 bool operator==(const SDOperand &O) const {
347 return Val == O.Val && ResNo == O.ResNo;
349 bool operator!=(const SDOperand &O) const {
350 return !operator==(O);
352 bool operator<(const SDOperand &O) const {
353 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
356 SDOperand getValue(unsigned R) const {
357 return SDOperand(Val, R);
360 /// getValueType - Return the ValueType of the referenced return value.
362 inline MVT::ValueType getValueType() const;
364 // Forwarding methods - These forward to the corresponding methods in SDNode.
365 inline unsigned getOpcode() const;
366 inline unsigned getNodeDepth() const;
367 inline unsigned getNumOperands() const;
368 inline const SDOperand &getOperand(unsigned i) const;
370 /// hasOneUse - Return true if there is exactly one operation using this
371 /// result value of the defining operator.
372 inline bool hasOneUse() const;
376 /// simplify_type specializations - Allow casting operators to work directly on
377 /// SDOperands as if they were SDNode*'s.
378 template<> struct simplify_type<SDOperand> {
379 typedef SDNode* SimpleType;
380 static SimpleType getSimplifiedValue(const SDOperand &Val) {
381 return static_cast<SimpleType>(Val.Val);
384 template<> struct simplify_type<const SDOperand> {
385 typedef SDNode* SimpleType;
386 static SimpleType getSimplifiedValue(const SDOperand &Val) {
387 return static_cast<SimpleType>(Val.Val);
392 /// SDNode - Represents one node in the SelectionDAG.
395 /// NodeType - The operation that this node performs.
397 unsigned short NodeType;
399 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
400 /// means that leaves have a depth of 1, things that use only leaves have a
402 unsigned short NodeDepth;
404 /// Operands - The values that are used by this operation.
406 std::vector<SDOperand> Operands;
408 /// Values - The types of the values this node defines. SDNode's may define
409 /// multiple values simultaneously.
410 std::vector<MVT::ValueType> Values;
412 /// Uses - These are all of the SDNode's that use a value produced by this
414 std::vector<SDNode*> Uses;
417 //===--------------------------------------------------------------------===//
420 unsigned getOpcode() const { return NodeType; }
422 size_t use_size() const { return Uses.size(); }
423 bool use_empty() const { return Uses.empty(); }
424 bool hasOneUse() const { return Uses.size() == 1; }
426 /// getNodeDepth - Return the distance from this node to the leaves in the
427 /// graph. The leaves have a depth of 1.
428 unsigned getNodeDepth() const { return NodeDepth; }
430 typedef std::vector<SDNode*>::const_iterator use_iterator;
431 use_iterator use_begin() const { return Uses.begin(); }
432 use_iterator use_end() const { return Uses.end(); }
434 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
435 /// indicated value. This method ignores uses of other values defined by this
437 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
439 /// getNumOperands - Return the number of values used by this operation.
441 unsigned getNumOperands() const { return Operands.size(); }
443 const SDOperand &getOperand(unsigned Num) {
444 assert(Num < Operands.size() && "Invalid child # of SDNode!");
445 return Operands[Num];
448 const SDOperand &getOperand(unsigned Num) const {
449 assert(Num < Operands.size() && "Invalid child # of SDNode!");
450 return Operands[Num];
453 /// getNumValues - Return the number of values defined/returned by this
456 unsigned getNumValues() const { return Values.size(); }
458 /// getValueType - Return the type of a specified result.
460 MVT::ValueType getValueType(unsigned ResNo) const {
461 assert(ResNo < Values.size() && "Illegal result number!");
462 return Values[ResNo];
465 /// getOperationName - Return the opcode of this operation for printing.
467 const char* getOperationName() const;
470 static bool classof(const SDNode *) { return true; }
473 friend class SelectionDAG;
475 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
477 Values.push_back(VT);
479 SDNode(unsigned NT, SDOperand Op)
480 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
481 Operands.reserve(1); Operands.push_back(Op);
482 Op.Val->Uses.push_back(this);
484 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
486 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
487 NodeDepth = N1.Val->getNodeDepth()+1;
489 NodeDepth = N2.Val->getNodeDepth()+1;
490 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
491 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
493 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
495 unsigned ND = N1.Val->getNodeDepth();
496 if (ND < N2.Val->getNodeDepth())
497 ND = N2.Val->getNodeDepth();
498 if (ND < N3.Val->getNodeDepth())
499 ND = N3.Val->getNodeDepth();
502 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
503 Operands.push_back(N3);
504 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
505 N3.Val->Uses.push_back(this);
507 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
508 Operands.swap(Nodes);
510 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
511 Operands[i].Val->Uses.push_back(this);
512 if (ND < Operands[i].Val->getNodeDepth())
513 ND = Operands[i].Val->getNodeDepth();
522 void setValueTypes(MVT::ValueType VT) {
524 Values.push_back(VT);
526 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
528 Values.push_back(VT1);
529 Values.push_back(VT2);
531 /// Note: this method destroys the vector passed in.
532 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
533 std::swap(Values, VTs);
536 void removeUser(SDNode *User) {
537 // Remove this user from the operand's use list.
538 for (unsigned i = Uses.size(); ; --i) {
539 assert(i != 0 && "Didn't find user!");
540 if (Uses[i-1] == User) {
541 Uses.erase(Uses.begin()+i-1);
549 // Define inline functions from the SDOperand class.
551 inline unsigned SDOperand::getOpcode() const {
552 return Val->getOpcode();
554 inline unsigned SDOperand::getNodeDepth() const {
555 return Val->getNodeDepth();
557 inline MVT::ValueType SDOperand::getValueType() const {
558 return Val->getValueType(ResNo);
560 inline unsigned SDOperand::getNumOperands() const {
561 return Val->getNumOperands();
563 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
564 return Val->getOperand(i);
566 inline bool SDOperand::hasOneUse() const {
567 return Val->hasNUsesOfValue(1, ResNo);
571 class ConstantSDNode : public SDNode {
574 friend class SelectionDAG;
575 ConstantSDNode(uint64_t val, MVT::ValueType VT)
576 : SDNode(ISD::Constant, VT), Value(val) {
580 uint64_t getValue() const { return Value; }
582 int64_t getSignExtended() const {
583 unsigned Bits = MVT::getSizeInBits(getValueType(0));
584 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
587 bool isNullValue() const { return Value == 0; }
588 bool isAllOnesValue() const {
589 return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
592 static bool classof(const ConstantSDNode *) { return true; }
593 static bool classof(const SDNode *N) {
594 return N->getOpcode() == ISD::Constant;
598 class ConstantFPSDNode : public SDNode {
601 friend class SelectionDAG;
602 ConstantFPSDNode(double val, MVT::ValueType VT)
603 : SDNode(ISD::ConstantFP, VT), Value(val) {
607 double getValue() const { return Value; }
609 /// isExactlyValue - We don't rely on operator== working on double values, as
610 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
611 /// As such, this method can be used to do an exact bit-for-bit comparison of
612 /// two floating point values.
613 bool isExactlyValue(double V) const {
627 static bool classof(const ConstantFPSDNode *) { return true; }
628 static bool classof(const SDNode *N) {
629 return N->getOpcode() == ISD::ConstantFP;
633 class GlobalAddressSDNode : public SDNode {
634 GlobalValue *TheGlobal;
636 friend class SelectionDAG;
637 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
638 : SDNode(ISD::GlobalAddress, VT) {
639 TheGlobal = const_cast<GlobalValue*>(GA);
643 GlobalValue *getGlobal() const { return TheGlobal; }
645 static bool classof(const GlobalAddressSDNode *) { return true; }
646 static bool classof(const SDNode *N) {
647 return N->getOpcode() == ISD::GlobalAddress;
652 class FrameIndexSDNode : public SDNode {
655 friend class SelectionDAG;
656 FrameIndexSDNode(int fi, MVT::ValueType VT)
657 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
660 int getIndex() const { return FI; }
662 static bool classof(const FrameIndexSDNode *) { return true; }
663 static bool classof(const SDNode *N) {
664 return N->getOpcode() == ISD::FrameIndex;
668 class ConstantPoolSDNode : public SDNode {
671 friend class SelectionDAG;
672 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
673 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
676 unsigned getIndex() const { return CPI; }
678 static bool classof(const ConstantPoolSDNode *) { return true; }
679 static bool classof(const SDNode *N) {
680 return N->getOpcode() == ISD::ConstantPool;
684 class BasicBlockSDNode : public SDNode {
685 MachineBasicBlock *MBB;
687 friend class SelectionDAG;
688 BasicBlockSDNode(MachineBasicBlock *mbb)
689 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
692 MachineBasicBlock *getBasicBlock() const { return MBB; }
694 static bool classof(const BasicBlockSDNode *) { return true; }
695 static bool classof(const SDNode *N) {
696 return N->getOpcode() == ISD::BasicBlock;
701 class RegSDNode : public SDNode {
704 friend class SelectionDAG;
705 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg)
706 : SDNode(Opc, Chain, Src), Reg(reg) {
708 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg)
709 : SDNode(Opc, Chain), Reg(reg) {}
712 unsigned getReg() const { return Reg; }
714 static bool classof(const RegSDNode *) { return true; }
715 static bool classof(const SDNode *N) {
716 return N->getOpcode() == ISD::CopyToReg ||
717 N->getOpcode() == ISD::CopyFromReg ||
718 N->getOpcode() == ISD::ImplicitDef;
722 class ExternalSymbolSDNode : public SDNode {
725 friend class SelectionDAG;
726 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
727 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
731 const char *getSymbol() const { return Symbol; }
733 static bool classof(const ExternalSymbolSDNode *) { return true; }
734 static bool classof(const SDNode *N) {
735 return N->getOpcode() == ISD::ExternalSymbol;
739 class SetCCSDNode : public SDNode {
740 ISD::CondCode Condition;
742 friend class SelectionDAG;
743 SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
744 : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
748 ISD::CondCode getCondition() const { return Condition; }
750 static bool classof(const SetCCSDNode *) { return true; }
751 static bool classof(const SDNode *N) {
752 return N->getOpcode() == ISD::SETCC;
756 /// MVTSDNode - This class is used for operators that require an extra
757 /// value-type to be kept with the node.
758 class MVTSDNode : public SDNode {
759 MVT::ValueType ExtraValueType;
761 friend class SelectionDAG;
762 MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT)
763 : SDNode(Opc, Op0), ExtraValueType(EVT) {
766 MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2,
767 SDOperand Op0, SDOperand Op1, MVT::ValueType EVT)
768 : SDNode(Opc, Op0, Op1), ExtraValueType(EVT) {
769 setValueTypes(VT1, VT2);
771 MVTSDNode(unsigned Opc, MVT::ValueType VT,
772 SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT)
773 : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) {
778 MVT::ValueType getExtraValueType() const { return ExtraValueType; }
780 static bool classof(const MVTSDNode *) { return true; }
781 static bool classof(const SDNode *N) {
783 N->getOpcode() == ISD::SIGN_EXTEND_INREG ||
784 N->getOpcode() == ISD::ZERO_EXTEND_INREG ||
785 N->getOpcode() == ISD::FP_ROUND_INREG ||
786 N->getOpcode() == ISD::EXTLOAD ||
787 N->getOpcode() == ISD::SEXTLOAD ||
788 N->getOpcode() == ISD::ZEXTLOAD ||
789 N->getOpcode() == ISD::TRUNCSTORE;
793 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
797 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
799 bool operator==(const SDNodeIterator& x) const {
800 return Operand == x.Operand;
802 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
804 const SDNodeIterator &operator=(const SDNodeIterator &I) {
805 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
810 pointer operator*() const {
811 return Node->getOperand(Operand).Val;
813 pointer operator->() const { return operator*(); }
815 SDNodeIterator& operator++() { // Preincrement
819 SDNodeIterator operator++(int) { // Postincrement
820 SDNodeIterator tmp = *this; ++*this; return tmp;
823 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
824 static SDNodeIterator end (SDNode *N) {
825 return SDNodeIterator(N, N->getNumOperands());
828 unsigned getOperand() const { return Operand; }
829 const SDNode *getNode() const { return Node; }
832 template <> struct GraphTraits<SDNode*> {
833 typedef SDNode NodeType;
834 typedef SDNodeIterator ChildIteratorType;
835 static inline NodeType *getEntryNode(SDNode *N) { return N; }
836 static inline ChildIteratorType child_begin(NodeType *N) {
837 return SDNodeIterator::begin(N);
839 static inline ChildIteratorType child_end(NodeType *N) {
840 return SDNodeIterator::end(N);
847 } // end llvm namespace