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 // 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.
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
114 // SIGN_EXTEND - Used for integer types, replicating the sign bit
118 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
121 // TRUNCATE - Completely drop the high bits.
124 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
125 // depends on the first letter) to floating point.
129 // SIGN_EXTEND_INREG/ZERO_EXTEND_INREG - These operators atomically performs
130 // a SHL/(SRA|SHL) pair to (sign|zero) extend a small value in a large
131 // integer register (e.g. sign extending the low 8 bits of a 32-bit register
132 // to fill the top 24 bits with the 7th bit). The size of the smaller type
133 // is indicated by the ExtraValueType in the MVTSDNode for the operator.
137 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
142 // FP_ROUND - Perform a rounding operation from the current
143 // precision down to the specified precision (currently always 64->32).
146 // FP_ROUND_INREG - This operator takes a floating point register, and
147 // rounds it to a floating point value. It then promotes it and returns it
148 // in a register of the same size. This operation effectively just discards
149 // excess precision. The type to round down to is specified by the
150 // ExtraValueType in the MVTSDNode (currently always 64->32->64).
153 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
156 // Other operators. LOAD and STORE have token chains as their first
157 // operand, then the same operands as an LLVM load/store instruction.
160 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the
161 // MVTSDNode. All of these load a value from memory and extend them to a
162 // larger value (e.g. load a byte into a word register). All three of these
163 // have two operands, a chain and a pointer to load from. The extra value
164 // type is the source type being loaded.
166 // SEXTLOAD loads the integer operand and sign extends it to a larger
167 // integer result type.
168 // ZEXTLOAD loads the integer operand and zero extends it to a larger
169 // integer result type.
170 // EXTLOAD is used for two things: floating point extending loads, and
171 // integer extending loads where it doesn't matter what the high
172 // bits are set to. The code generator is allowed to codegen this
173 // into whichever operation is more efficient.
174 EXTLOAD, SEXTLOAD, ZEXTLOAD,
176 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
177 // value and stores it to memory in one operation. This can be used for
178 // either integer or floating point operands, and the stored type
179 // represented as the 'extra' value type in the MVTSDNode representing the
180 // operator. This node has the same three operands as a standard store.
183 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
184 // to a specified boundary. The first operand is the token chain, the
185 // second is the number of bytes to allocate, and the third is the alignment
189 // Control flow instructions. These all have token chains.
191 // BR - Unconditional branch. The first operand is the chain
192 // operand, the second is the MBB to branch to.
195 // BRCOND - Conditional branch. The first operand is the chain,
196 // the second is the condition, the third is the block to branch
197 // to if the condition is true.
200 // RET - Return from function. The first operand is the chain,
201 // and any subsequent operands are the return values for the
202 // function. This operation can have variable number of operands.
205 // CALL - Call to a function pointer. The first operand is the chain, the
206 // second is the destination function pointer (a GlobalAddress for a direct
207 // call). Arguments have already been lowered to explicit DAGs according to
208 // the calling convention in effect here.
211 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
212 // correspond to the operands of the LLVM intrinsic functions. The only
213 // result is a token chain. The alignment argument is guaranteed to be a
219 // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and
220 // end of a call sequence and indicate how much the stack pointer needs to
221 // be adjusted for that particular call. The first operand is a chain, the
222 // second is a ConstantSDNode of intptr type.
223 ADJCALLSTACKDOWN, // Beginning of a call sequence
224 ADJCALLSTACKUP, // End of a call sequence
227 // BUILTIN_OP_END - This must be the last enum value in this list.
231 //===--------------------------------------------------------------------===//
232 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
233 /// below work out, when considering SETFALSE (something that never exists
234 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
235 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
236 /// to. If the "N" column is 1, the result of the comparison is undefined if
237 /// the input is a NAN.
239 /// All of these (except for the 'always folded ops') should be handled for
240 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
241 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
243 /// Note that these are laid out in a specific order to allow bit-twiddling
244 /// to transform conditions.
246 // Opcode N U L G E Intuitive operation
247 SETFALSE, // 0 0 0 0 Always false (always folded)
248 SETOEQ, // 0 0 0 1 True if ordered and equal
249 SETOGT, // 0 0 1 0 True if ordered and greater than
250 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
251 SETOLT, // 0 1 0 0 True if ordered and less than
252 SETOLE, // 0 1 0 1 True if ordered and less than or equal
253 SETONE, // 0 1 1 0 True if ordered and operands are unequal
254 SETO, // 0 1 1 1 True if ordered (no nans)
255 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
256 SETUEQ, // 1 0 0 1 True if unordered or equal
257 SETUGT, // 1 0 1 0 True if unordered or greater than
258 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
259 SETULT, // 1 1 0 0 True if unordered or less than
260 SETULE, // 1 1 0 1 True if unordered, less than, or equal
261 SETUNE, // 1 1 1 0 True if unordered or not equal
262 SETTRUE, // 1 1 1 1 Always true (always folded)
263 // Don't care operations: undefined if the input is a nan.
264 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
265 SETEQ, // 1 X 0 0 1 True if equal
266 SETGT, // 1 X 0 1 0 True if greater than
267 SETGE, // 1 X 0 1 1 True if greater than or equal
268 SETLT, // 1 X 1 0 0 True if less than
269 SETLE, // 1 X 1 0 1 True if less than or equal
270 SETNE, // 1 X 1 1 0 True if not equal
271 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
273 SETCC_INVALID, // Marker value.
276 /// isSignedIntSetCC - Return true if this is a setcc instruction that
277 /// performs a signed comparison when used with integer operands.
278 inline bool isSignedIntSetCC(CondCode Code) {
279 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
282 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
283 /// performs an unsigned comparison when used with integer operands.
284 inline bool isUnsignedIntSetCC(CondCode Code) {
285 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
288 /// isTrueWhenEqual - Return true if the specified condition returns true if
289 /// the two operands to the condition are equal. Note that if one of the two
290 /// operands is a NaN, this value is meaningless.
291 inline bool isTrueWhenEqual(CondCode Cond) {
292 return ((int)Cond & 1) != 0;
295 /// getUnorderedFlavor - This function returns 0 if the condition is always
296 /// false if an operand is a NaN, 1 if the condition is always true if the
297 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
299 inline unsigned getUnorderedFlavor(CondCode Cond) {
300 return ((int)Cond >> 3) & 3;
303 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
304 /// 'op' is a valid SetCC operation.
305 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
307 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
308 /// when given the operation for (X op Y).
309 CondCode getSetCCSwappedOperands(CondCode Operation);
311 /// getSetCCOrOperation - Return the result of a logical OR between different
312 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
313 /// function returns SETCC_INVALID if it is not possible to represent the
314 /// resultant comparison.
315 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
317 /// getSetCCAndOperation - Return the result of a logical AND between
318 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
319 /// function returns SETCC_INVALID if it is not possible to represent the
320 /// resultant comparison.
321 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
322 } // end llvm::ISD namespace
325 //===----------------------------------------------------------------------===//
326 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
327 /// values as the result of a computation. Many nodes return multiple values,
328 /// from loads (which define a token and a return value) to ADDC (which returns
329 /// a result and a carry value), to calls (which may return an arbitrary number
332 /// As such, each use of a SelectionDAG computation must indicate the node that
333 /// computes it as well as which return value to use from that node. This pair
334 /// of information is represented with the SDOperand value type.
338 SDNode *Val; // The node defining the value we are using.
339 unsigned ResNo; // Which return value of the node we are using.
341 SDOperand() : Val(0) {}
342 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
344 bool operator==(const SDOperand &O) const {
345 return Val == O.Val && ResNo == O.ResNo;
347 bool operator!=(const SDOperand &O) const {
348 return !operator==(O);
350 bool operator<(const SDOperand &O) const {
351 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
354 SDOperand getValue(unsigned R) const {
355 return SDOperand(Val, R);
358 /// getValueType - Return the ValueType of the referenced return value.
360 inline MVT::ValueType getValueType() const;
362 // Forwarding methods - These forward to the corresponding methods in SDNode.
363 inline unsigned getOpcode() const;
364 inline unsigned getNumOperands() const;
365 inline const SDOperand &getOperand(unsigned i) const;
367 /// hasOneUse - Return true if there is exactly one operation using this
368 /// result value of the defining operator.
369 inline bool hasOneUse() const;
373 /// simplify_type specializations - Allow casting operators to work directly on
374 /// SDOperands as if they were SDNode*'s.
375 template<> struct simplify_type<SDOperand> {
376 typedef SDNode* SimpleType;
377 static SimpleType getSimplifiedValue(const SDOperand &Val) {
378 return static_cast<SimpleType>(Val.Val);
381 template<> struct simplify_type<const SDOperand> {
382 typedef SDNode* SimpleType;
383 static SimpleType getSimplifiedValue(const SDOperand &Val) {
384 return static_cast<SimpleType>(Val.Val);
389 /// SDNode - Represents one node in the SelectionDAG.
393 std::vector<SDOperand> Operands;
395 /// Values - The types of the values this node defines. SDNode's may define
396 /// multiple values simultaneously.
397 std::vector<MVT::ValueType> Values;
399 /// Uses - These are all of the SDNode's that use a value produced by this
401 std::vector<SDNode*> Uses;
404 //===--------------------------------------------------------------------===//
407 unsigned getOpcode() const { return NodeType; }
409 size_t use_size() const { return Uses.size(); }
410 bool use_empty() const { return Uses.empty(); }
411 bool hasOneUse() const { return Uses.size() == 1; }
413 typedef std::vector<SDNode*>::const_iterator use_iterator;
414 use_iterator use_begin() const { return Uses.begin(); }
415 use_iterator use_end() const { return Uses.end(); }
417 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
418 /// indicated value. This method ignores uses of other values defined by this
420 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
422 /// getNumOperands - Return the number of values used by this operation.
424 unsigned getNumOperands() const { return Operands.size(); }
426 const SDOperand &getOperand(unsigned Num) {
427 assert(Num < Operands.size() && "Invalid child # of SDNode!");
428 return Operands[Num];
431 const SDOperand &getOperand(unsigned Num) const {
432 assert(Num < Operands.size() && "Invalid child # of SDNode!");
433 return Operands[Num];
436 /// getNumValues - Return the number of values defined/returned by this
439 unsigned getNumValues() const { return Values.size(); }
441 /// getValueType - Return the type of a specified result.
443 MVT::ValueType getValueType(unsigned ResNo) const {
444 assert(ResNo < Values.size() && "Illegal result number!");
445 return Values[ResNo];
448 /// getOperationName - Return the opcode of this operation for printing.
450 const char* getOperationName() const;
453 static bool classof(const SDNode *) { return true; }
456 friend class SelectionDAG;
458 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT) {
460 Values.push_back(VT);
463 SDNode(unsigned NT, SDOperand Op)
465 Operands.reserve(1); Operands.push_back(Op);
466 Op.Val->Uses.push_back(this);
468 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
470 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
471 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
473 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
475 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
476 Operands.push_back(N3);
477 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
478 N3.Val->Uses.push_back(this);
480 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
481 Operands.swap(Nodes);
482 for (unsigned i = 0, e = Operands.size(); i != e; ++i)
483 Operands[i].Val->Uses.push_back(this);
490 void setValueTypes(MVT::ValueType VT) {
492 Values.push_back(VT);
494 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
496 Values.push_back(VT1);
497 Values.push_back(VT2);
499 /// Note: this method destroys the vector passed in.
500 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
501 std::swap(Values, VTs);
504 void removeUser(SDNode *User) {
505 // Remove this user from the operand's use list.
506 for (unsigned i = Uses.size(); ; --i) {
507 assert(i != 0 && "Didn't find user!");
508 if (Uses[i-1] == User) {
509 Uses.erase(Uses.begin()+i-1);
517 // Define inline functions from the SDOperand class.
519 inline unsigned SDOperand::getOpcode() const {
520 return Val->getOpcode();
522 inline MVT::ValueType SDOperand::getValueType() const {
523 return Val->getValueType(ResNo);
525 inline unsigned SDOperand::getNumOperands() const {
526 return Val->getNumOperands();
528 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
529 return Val->getOperand(i);
531 inline bool SDOperand::hasOneUse() const {
532 return Val->hasNUsesOfValue(1, ResNo);
536 class ConstantSDNode : public SDNode {
539 friend class SelectionDAG;
540 ConstantSDNode(uint64_t val, MVT::ValueType VT)
541 : SDNode(ISD::Constant, VT), Value(val) {
545 uint64_t getValue() const { return Value; }
547 int64_t getSignExtended() const {
548 unsigned Bits = MVT::getSizeInBits(getValueType(0));
549 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
552 bool isNullValue() const { return Value == 0; }
553 bool isAllOnesValue() const {
554 return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
557 static bool classof(const ConstantSDNode *) { return true; }
558 static bool classof(const SDNode *N) {
559 return N->getOpcode() == ISD::Constant;
563 class ConstantFPSDNode : public SDNode {
566 friend class SelectionDAG;
567 ConstantFPSDNode(double val, MVT::ValueType VT)
568 : SDNode(ISD::ConstantFP, VT), Value(val) {
572 double getValue() const { return Value; }
574 /// isExactlyValue - We don't rely on operator== working on double values, as
575 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
576 /// As such, this method can be used to do an exact bit-for-bit comparison of
577 /// two floating point values.
578 bool isExactlyValue(double V) const {
592 static bool classof(const ConstantFPSDNode *) { return true; }
593 static bool classof(const SDNode *N) {
594 return N->getOpcode() == ISD::ConstantFP;
598 class GlobalAddressSDNode : public SDNode {
599 GlobalValue *TheGlobal;
601 friend class SelectionDAG;
602 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
603 : SDNode(ISD::GlobalAddress, VT) {
604 TheGlobal = const_cast<GlobalValue*>(GA);
608 GlobalValue *getGlobal() const { return TheGlobal; }
610 static bool classof(const GlobalAddressSDNode *) { return true; }
611 static bool classof(const SDNode *N) {
612 return N->getOpcode() == ISD::GlobalAddress;
617 class FrameIndexSDNode : public SDNode {
620 friend class SelectionDAG;
621 FrameIndexSDNode(int fi, MVT::ValueType VT)
622 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
625 int getIndex() const { return FI; }
627 static bool classof(const FrameIndexSDNode *) { return true; }
628 static bool classof(const SDNode *N) {
629 return N->getOpcode() == ISD::FrameIndex;
633 class ConstantPoolSDNode : public SDNode {
636 friend class SelectionDAG;
637 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
638 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
641 unsigned getIndex() const { return CPI; }
643 static bool classof(const ConstantPoolSDNode *) { return true; }
644 static bool classof(const SDNode *N) {
645 return N->getOpcode() == ISD::ConstantPool;
649 class BasicBlockSDNode : public SDNode {
650 MachineBasicBlock *MBB;
652 friend class SelectionDAG;
653 BasicBlockSDNode(MachineBasicBlock *mbb)
654 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
657 MachineBasicBlock *getBasicBlock() const { return MBB; }
659 static bool classof(const BasicBlockSDNode *) { return true; }
660 static bool classof(const SDNode *N) {
661 return N->getOpcode() == ISD::BasicBlock;
666 class RegSDNode : public SDNode {
669 friend class SelectionDAG;
670 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg)
671 : SDNode(Opc, Chain, Src), Reg(reg) {
673 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg)
674 : SDNode(Opc, Chain), Reg(reg) {}
677 unsigned getReg() const { return Reg; }
679 static bool classof(const RegSDNode *) { return true; }
680 static bool classof(const SDNode *N) {
681 return N->getOpcode() == ISD::CopyToReg ||
682 N->getOpcode() == ISD::CopyFromReg ||
683 N->getOpcode() == ISD::ImplicitDef;
687 class ExternalSymbolSDNode : public SDNode {
690 friend class SelectionDAG;
691 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
692 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
696 const char *getSymbol() const { return Symbol; }
698 static bool classof(const ExternalSymbolSDNode *) { return true; }
699 static bool classof(const SDNode *N) {
700 return N->getOpcode() == ISD::ExternalSymbol;
704 class SetCCSDNode : public SDNode {
705 ISD::CondCode Condition;
707 friend class SelectionDAG;
708 SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
709 : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
713 ISD::CondCode getCondition() const { return Condition; }
715 static bool classof(const SetCCSDNode *) { return true; }
716 static bool classof(const SDNode *N) {
717 return N->getOpcode() == ISD::SETCC;
721 /// MVTSDNode - This class is used for operators that require an extra
722 /// value-type to be kept with the node.
723 class MVTSDNode : public SDNode {
724 MVT::ValueType ExtraValueType;
726 friend class SelectionDAG;
727 MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT)
728 : SDNode(Opc, Op0), ExtraValueType(EVT) {
731 MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2,
732 SDOperand Op0, SDOperand Op1, MVT::ValueType EVT)
733 : SDNode(Opc, Op0, Op1), ExtraValueType(EVT) {
734 setValueTypes(VT1, VT2);
736 MVTSDNode(unsigned Opc, MVT::ValueType VT,
737 SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT)
738 : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) {
743 MVT::ValueType getExtraValueType() const { return ExtraValueType; }
745 static bool classof(const MVTSDNode *) { return true; }
746 static bool classof(const SDNode *N) {
748 N->getOpcode() == ISD::SIGN_EXTEND_INREG ||
749 N->getOpcode() == ISD::ZERO_EXTEND_INREG ||
750 N->getOpcode() == ISD::FP_ROUND_INREG ||
751 N->getOpcode() == ISD::EXTLOAD ||
752 N->getOpcode() == ISD::SEXTLOAD ||
753 N->getOpcode() == ISD::ZEXTLOAD ||
754 N->getOpcode() == ISD::TRUNCSTORE;
758 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
762 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
764 bool operator==(const SDNodeIterator& x) const {
765 return Operand == x.Operand;
767 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
769 const SDNodeIterator &operator=(const SDNodeIterator &I) {
770 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
775 pointer operator*() const {
776 return Node->getOperand(Operand).Val;
778 pointer operator->() const { return operator*(); }
780 SDNodeIterator& operator++() { // Preincrement
784 SDNodeIterator operator++(int) { // Postincrement
785 SDNodeIterator tmp = *this; ++*this; return tmp;
788 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
789 static SDNodeIterator end (SDNode *N) {
790 return SDNodeIterator(N, N->getNumOperands());
793 unsigned getOperand() const { return Operand; }
794 const SDNode *getNode() const { return Node; }
797 template <> struct GraphTraits<SDNode*> {
798 typedef SDNode NodeType;
799 typedef SDNodeIterator ChildIteratorType;
800 static inline NodeType *getEntryNode(SDNode *N) { return N; }
801 static inline ChildIteratorType child_begin(NodeType *N) {
802 return SDNodeIterator::begin(N);
804 static inline ChildIteratorType child_end(NodeType *N) {
805 return SDNodeIterator::end(N);
812 } // end llvm namespace