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 // UNDEF - An undefined node
80 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
81 // a Constant, which is required to be operand #1), element of the aggregate
82 // value specified as operand #0. This is only for use before legalization,
83 // for values that will be broken into multiple registers.
86 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
87 // two values of the same integer value type, this produces a value twice as
88 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
92 // Simple binary arithmetic operators.
93 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
96 AND, OR, XOR, SHL, SRA, SRL,
101 // SetCC operator - This evaluates to a boolean (i1) true value if the
102 // condition is true. These nodes are instances of the
103 // SetCCSDNode class, which contains the condition code as extra
107 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
108 // broken into a multiple pieces each, and return the resulting pieces of
109 // doing an atomic add/sub operation. This is used to handle add/sub of
110 // expanded types. The operation ordering is:
111 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
112 ADD_PARTS, SUB_PARTS,
114 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
115 // integer shift operations, just like ADD/SUB_PARTS. The operation
117 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
118 SHL_PARTS, SRA_PARTS, SRL_PARTS,
120 // Conversion operators. These are all single input single output
121 // operations. For all of these, the result type must be strictly
122 // wider or narrower (depending on the operation) than the source
125 // SIGN_EXTEND - Used for integer types, replicating the sign bit
129 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
132 // TRUNCATE - Completely drop the high bits.
135 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
136 // depends on the first letter) to floating point.
140 // SIGN_EXTEND_INREG/ZERO_EXTEND_INREG - These operators atomically performs
141 // a SHL/(SRA|SHL) pair to (sign|zero) extend a small value in a large
142 // integer register (e.g. sign extending the low 8 bits of a 32-bit register
143 // to fill the top 24 bits with the 7th bit). The size of the smaller type
144 // is indicated by the ExtraValueType in the MVTSDNode for the operator.
148 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
153 // FP_ROUND - Perform a rounding operation from the current
154 // precision down to the specified precision (currently always 64->32).
157 // FP_ROUND_INREG - This operator takes a floating point register, and
158 // rounds it to a floating point value. It then promotes it and returns it
159 // in a register of the same size. This operation effectively just discards
160 // excess precision. The type to round down to is specified by the
161 // ExtraValueType in the MVTSDNode (currently always 64->32->64).
164 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
167 // Other operators. LOAD and STORE have token chains as their first
168 // operand, then the same operands as an LLVM load/store instruction.
171 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the
172 // MVTSDNode. All of these load a value from memory and extend them to a
173 // larger value (e.g. load a byte into a word register). All three of these
174 // have two operands, a chain and a pointer to load from. The extra value
175 // type is the source type being loaded.
177 // SEXTLOAD loads the integer operand and sign extends it to a larger
178 // integer result type.
179 // ZEXTLOAD loads the integer operand and zero extends it to a larger
180 // integer result type.
181 // EXTLOAD is used for two things: floating point extending loads, and
182 // integer extending loads where it doesn't matter what the high
183 // bits are set to. The code generator is allowed to codegen this
184 // into whichever operation is more efficient.
185 EXTLOAD, SEXTLOAD, ZEXTLOAD,
187 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
188 // value and stores it to memory in one operation. This can be used for
189 // either integer or floating point operands, and the stored type
190 // represented as the 'extra' value type in the MVTSDNode representing the
191 // operator. This node has the same three operands as a standard store.
194 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
195 // to a specified boundary. The first operand is the token chain, the
196 // second is the number of bytes to allocate, and the third is the alignment
200 // Control flow instructions. These all have token chains.
202 // BR - Unconditional branch. The first operand is the chain
203 // operand, the second is the MBB to branch to.
206 // BRCOND - Conditional branch. The first operand is the chain,
207 // the second is the condition, the third is the block to branch
208 // to if the condition is true.
211 // RET - Return from function. The first operand is the chain,
212 // and any subsequent operands are the return values for the
213 // function. This operation can have variable number of operands.
216 // CALL - Call to a function pointer. The first operand is the chain, the
217 // second is the destination function pointer (a GlobalAddress for a direct
218 // call). Arguments have already been lowered to explicit DAGs according to
219 // the calling convention in effect here.
222 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
223 // correspond to the operands of the LLVM intrinsic functions. The only
224 // result is a token chain. The alignment argument is guaranteed to be a
230 // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and
231 // end of a call sequence and indicate how much the stack pointer needs to
232 // be adjusted for that particular call. The first operand is a chain, the
233 // second is a ConstantSDNode of intptr type.
234 ADJCALLSTACKDOWN, // Beginning of a call sequence
235 ADJCALLSTACKUP, // End of a call sequence
237 // PCMARKER - This corresponds to the pcmarker intrinsic.
240 // BUILTIN_OP_END - This must be the last enum value in this list.
244 //===--------------------------------------------------------------------===//
245 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
246 /// below work out, when considering SETFALSE (something that never exists
247 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
248 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
249 /// to. If the "N" column is 1, the result of the comparison is undefined if
250 /// the input is a NAN.
252 /// All of these (except for the 'always folded ops') should be handled for
253 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
254 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
256 /// Note that these are laid out in a specific order to allow bit-twiddling
257 /// to transform conditions.
259 // Opcode N U L G E Intuitive operation
260 SETFALSE, // 0 0 0 0 Always false (always folded)
261 SETOEQ, // 0 0 0 1 True if ordered and equal
262 SETOGT, // 0 0 1 0 True if ordered and greater than
263 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
264 SETOLT, // 0 1 0 0 True if ordered and less than
265 SETOLE, // 0 1 0 1 True if ordered and less than or equal
266 SETONE, // 0 1 1 0 True if ordered and operands are unequal
267 SETO, // 0 1 1 1 True if ordered (no nans)
268 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
269 SETUEQ, // 1 0 0 1 True if unordered or equal
270 SETUGT, // 1 0 1 0 True if unordered or greater than
271 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
272 SETULT, // 1 1 0 0 True if unordered or less than
273 SETULE, // 1 1 0 1 True if unordered, less than, or equal
274 SETUNE, // 1 1 1 0 True if unordered or not equal
275 SETTRUE, // 1 1 1 1 Always true (always folded)
276 // Don't care operations: undefined if the input is a nan.
277 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
278 SETEQ, // 1 X 0 0 1 True if equal
279 SETGT, // 1 X 0 1 0 True if greater than
280 SETGE, // 1 X 0 1 1 True if greater than or equal
281 SETLT, // 1 X 1 0 0 True if less than
282 SETLE, // 1 X 1 0 1 True if less than or equal
283 SETNE, // 1 X 1 1 0 True if not equal
284 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
286 SETCC_INVALID, // Marker value.
289 /// isSignedIntSetCC - Return true if this is a setcc instruction that
290 /// performs a signed comparison when used with integer operands.
291 inline bool isSignedIntSetCC(CondCode Code) {
292 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
295 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
296 /// performs an unsigned comparison when used with integer operands.
297 inline bool isUnsignedIntSetCC(CondCode Code) {
298 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
301 /// isTrueWhenEqual - Return true if the specified condition returns true if
302 /// the two operands to the condition are equal. Note that if one of the two
303 /// operands is a NaN, this value is meaningless.
304 inline bool isTrueWhenEqual(CondCode Cond) {
305 return ((int)Cond & 1) != 0;
308 /// getUnorderedFlavor - This function returns 0 if the condition is always
309 /// false if an operand is a NaN, 1 if the condition is always true if the
310 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
312 inline unsigned getUnorderedFlavor(CondCode Cond) {
313 return ((int)Cond >> 3) & 3;
316 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
317 /// 'op' is a valid SetCC operation.
318 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
320 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
321 /// when given the operation for (X op Y).
322 CondCode getSetCCSwappedOperands(CondCode Operation);
324 /// getSetCCOrOperation - Return the result of a logical OR between different
325 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
326 /// function returns SETCC_INVALID if it is not possible to represent the
327 /// resultant comparison.
328 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
330 /// getSetCCAndOperation - Return the result of a logical AND between
331 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
332 /// function returns SETCC_INVALID if it is not possible to represent the
333 /// resultant comparison.
334 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
335 } // end llvm::ISD namespace
338 //===----------------------------------------------------------------------===//
339 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
340 /// values as the result of a computation. Many nodes return multiple values,
341 /// from loads (which define a token and a return value) to ADDC (which returns
342 /// a result and a carry value), to calls (which may return an arbitrary number
345 /// As such, each use of a SelectionDAG computation must indicate the node that
346 /// computes it as well as which return value to use from that node. This pair
347 /// of information is represented with the SDOperand value type.
351 SDNode *Val; // The node defining the value we are using.
352 unsigned ResNo; // Which return value of the node we are using.
354 SDOperand() : Val(0) {}
355 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
357 bool operator==(const SDOperand &O) const {
358 return Val == O.Val && ResNo == O.ResNo;
360 bool operator!=(const SDOperand &O) const {
361 return !operator==(O);
363 bool operator<(const SDOperand &O) const {
364 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
367 SDOperand getValue(unsigned R) const {
368 return SDOperand(Val, R);
371 /// getValueType - Return the ValueType of the referenced return value.
373 inline MVT::ValueType getValueType() const;
375 // Forwarding methods - These forward to the corresponding methods in SDNode.
376 inline unsigned getOpcode() const;
377 inline unsigned getNodeDepth() const;
378 inline unsigned getNumOperands() const;
379 inline const SDOperand &getOperand(unsigned i) const;
381 /// hasOneUse - Return true if there is exactly one operation using this
382 /// result value of the defining operator.
383 inline bool hasOneUse() const;
387 /// simplify_type specializations - Allow casting operators to work directly on
388 /// SDOperands as if they were SDNode*'s.
389 template<> struct simplify_type<SDOperand> {
390 typedef SDNode* SimpleType;
391 static SimpleType getSimplifiedValue(const SDOperand &Val) {
392 return static_cast<SimpleType>(Val.Val);
395 template<> struct simplify_type<const SDOperand> {
396 typedef SDNode* SimpleType;
397 static SimpleType getSimplifiedValue(const SDOperand &Val) {
398 return static_cast<SimpleType>(Val.Val);
403 /// SDNode - Represents one node in the SelectionDAG.
406 /// NodeType - The operation that this node performs.
408 unsigned short NodeType;
410 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
411 /// means that leaves have a depth of 1, things that use only leaves have a
413 unsigned short NodeDepth;
415 /// Operands - The values that are used by this operation.
417 std::vector<SDOperand> Operands;
419 /// Values - The types of the values this node defines. SDNode's may define
420 /// multiple values simultaneously.
421 std::vector<MVT::ValueType> Values;
423 /// Uses - These are all of the SDNode's that use a value produced by this
425 std::vector<SDNode*> Uses;
428 //===--------------------------------------------------------------------===//
431 unsigned getOpcode() const { return NodeType; }
433 size_t use_size() const { return Uses.size(); }
434 bool use_empty() const { return Uses.empty(); }
435 bool hasOneUse() const { return Uses.size() == 1; }
437 /// getNodeDepth - Return the distance from this node to the leaves in the
438 /// graph. The leaves have a depth of 1.
439 unsigned getNodeDepth() const { return NodeDepth; }
441 typedef std::vector<SDNode*>::const_iterator use_iterator;
442 use_iterator use_begin() const { return Uses.begin(); }
443 use_iterator use_end() const { return Uses.end(); }
445 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
446 /// indicated value. This method ignores uses of other values defined by this
448 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
450 /// getNumOperands - Return the number of values used by this operation.
452 unsigned getNumOperands() const { return Operands.size(); }
454 const SDOperand &getOperand(unsigned Num) {
455 assert(Num < Operands.size() && "Invalid child # of SDNode!");
456 return Operands[Num];
459 const SDOperand &getOperand(unsigned Num) const {
460 assert(Num < Operands.size() && "Invalid child # of SDNode!");
461 return Operands[Num];
464 /// getNumValues - Return the number of values defined/returned by this
467 unsigned getNumValues() const { return Values.size(); }
469 /// getValueType - Return the type of a specified result.
471 MVT::ValueType getValueType(unsigned ResNo) const {
472 assert(ResNo < Values.size() && "Illegal result number!");
473 return Values[ResNo];
476 /// getOperationName - Return the opcode of this operation for printing.
478 const char* getOperationName() const;
481 static bool classof(const SDNode *) { return true; }
484 friend class SelectionDAG;
486 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
488 Values.push_back(VT);
490 SDNode(unsigned NT, SDOperand Op)
491 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
492 Operands.reserve(1); Operands.push_back(Op);
493 Op.Val->Uses.push_back(this);
495 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
497 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
498 NodeDepth = N1.Val->getNodeDepth()+1;
500 NodeDepth = N2.Val->getNodeDepth()+1;
501 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
502 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
504 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
506 unsigned ND = N1.Val->getNodeDepth();
507 if (ND < N2.Val->getNodeDepth())
508 ND = N2.Val->getNodeDepth();
509 if (ND < N3.Val->getNodeDepth())
510 ND = N3.Val->getNodeDepth();
513 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
514 Operands.push_back(N3);
515 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
516 N3.Val->Uses.push_back(this);
518 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
519 Operands.swap(Nodes);
521 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
522 Operands[i].Val->Uses.push_back(this);
523 if (ND < Operands[i].Val->getNodeDepth())
524 ND = Operands[i].Val->getNodeDepth();
533 void setValueTypes(MVT::ValueType VT) {
535 Values.push_back(VT);
537 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
539 Values.push_back(VT1);
540 Values.push_back(VT2);
542 /// Note: this method destroys the vector passed in.
543 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
544 std::swap(Values, VTs);
547 void removeUser(SDNode *User) {
548 // Remove this user from the operand's use list.
549 for (unsigned i = Uses.size(); ; --i) {
550 assert(i != 0 && "Didn't find user!");
551 if (Uses[i-1] == User) {
552 Uses.erase(Uses.begin()+i-1);
560 // Define inline functions from the SDOperand class.
562 inline unsigned SDOperand::getOpcode() const {
563 return Val->getOpcode();
565 inline unsigned SDOperand::getNodeDepth() const {
566 return Val->getNodeDepth();
568 inline MVT::ValueType SDOperand::getValueType() const {
569 return Val->getValueType(ResNo);
571 inline unsigned SDOperand::getNumOperands() const {
572 return Val->getNumOperands();
574 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
575 return Val->getOperand(i);
577 inline bool SDOperand::hasOneUse() const {
578 return Val->hasNUsesOfValue(1, ResNo);
582 class ConstantSDNode : public SDNode {
585 friend class SelectionDAG;
586 ConstantSDNode(uint64_t val, MVT::ValueType VT)
587 : SDNode(ISD::Constant, VT), Value(val) {
591 uint64_t getValue() const { return Value; }
593 int64_t getSignExtended() const {
594 unsigned Bits = MVT::getSizeInBits(getValueType(0));
595 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
598 bool isNullValue() const { return Value == 0; }
599 bool isAllOnesValue() const {
600 return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1;
603 static bool classof(const ConstantSDNode *) { return true; }
604 static bool classof(const SDNode *N) {
605 return N->getOpcode() == ISD::Constant;
609 class ConstantFPSDNode : public SDNode {
612 friend class SelectionDAG;
613 ConstantFPSDNode(double val, MVT::ValueType VT)
614 : SDNode(ISD::ConstantFP, VT), Value(val) {
618 double getValue() const { return Value; }
620 /// isExactlyValue - We don't rely on operator== working on double values, as
621 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
622 /// As such, this method can be used to do an exact bit-for-bit comparison of
623 /// two floating point values.
624 bool isExactlyValue(double V) const {
638 static bool classof(const ConstantFPSDNode *) { return true; }
639 static bool classof(const SDNode *N) {
640 return N->getOpcode() == ISD::ConstantFP;
644 class GlobalAddressSDNode : public SDNode {
645 GlobalValue *TheGlobal;
647 friend class SelectionDAG;
648 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
649 : SDNode(ISD::GlobalAddress, VT) {
650 TheGlobal = const_cast<GlobalValue*>(GA);
654 GlobalValue *getGlobal() const { return TheGlobal; }
656 static bool classof(const GlobalAddressSDNode *) { return true; }
657 static bool classof(const SDNode *N) {
658 return N->getOpcode() == ISD::GlobalAddress;
663 class FrameIndexSDNode : public SDNode {
666 friend class SelectionDAG;
667 FrameIndexSDNode(int fi, MVT::ValueType VT)
668 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
671 int getIndex() const { return FI; }
673 static bool classof(const FrameIndexSDNode *) { return true; }
674 static bool classof(const SDNode *N) {
675 return N->getOpcode() == ISD::FrameIndex;
679 class ConstantPoolSDNode : public SDNode {
682 friend class SelectionDAG;
683 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
684 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
687 unsigned getIndex() const { return CPI; }
689 static bool classof(const ConstantPoolSDNode *) { return true; }
690 static bool classof(const SDNode *N) {
691 return N->getOpcode() == ISD::ConstantPool;
695 class BasicBlockSDNode : public SDNode {
696 MachineBasicBlock *MBB;
698 friend class SelectionDAG;
699 BasicBlockSDNode(MachineBasicBlock *mbb)
700 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
703 MachineBasicBlock *getBasicBlock() const { return MBB; }
705 static bool classof(const BasicBlockSDNode *) { return true; }
706 static bool classof(const SDNode *N) {
707 return N->getOpcode() == ISD::BasicBlock;
712 class RegSDNode : public SDNode {
715 friend class SelectionDAG;
716 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg)
717 : SDNode(Opc, Chain, Src), Reg(reg) {
719 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg)
720 : SDNode(Opc, Chain), Reg(reg) {}
723 unsigned getReg() const { return Reg; }
725 static bool classof(const RegSDNode *) { return true; }
726 static bool classof(const SDNode *N) {
727 return N->getOpcode() == ISD::CopyToReg ||
728 N->getOpcode() == ISD::CopyFromReg ||
729 N->getOpcode() == ISD::ImplicitDef;
733 class ExternalSymbolSDNode : public SDNode {
736 friend class SelectionDAG;
737 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
738 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
742 const char *getSymbol() const { return Symbol; }
744 static bool classof(const ExternalSymbolSDNode *) { return true; }
745 static bool classof(const SDNode *N) {
746 return N->getOpcode() == ISD::ExternalSymbol;
750 class SetCCSDNode : public SDNode {
751 ISD::CondCode Condition;
753 friend class SelectionDAG;
754 SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
755 : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
759 ISD::CondCode getCondition() const { return Condition; }
761 static bool classof(const SetCCSDNode *) { return true; }
762 static bool classof(const SDNode *N) {
763 return N->getOpcode() == ISD::SETCC;
767 /// MVTSDNode - This class is used for operators that require an extra
768 /// value-type to be kept with the node.
769 class MVTSDNode : public SDNode {
770 MVT::ValueType ExtraValueType;
772 friend class SelectionDAG;
773 MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT)
774 : SDNode(Opc, Op0), ExtraValueType(EVT) {
777 MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2,
778 SDOperand Op0, SDOperand Op1, MVT::ValueType EVT)
779 : SDNode(Opc, Op0, Op1), ExtraValueType(EVT) {
780 setValueTypes(VT1, VT2);
782 MVTSDNode(unsigned Opc, MVT::ValueType VT,
783 SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT)
784 : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) {
789 MVT::ValueType getExtraValueType() const { return ExtraValueType; }
791 static bool classof(const MVTSDNode *) { return true; }
792 static bool classof(const SDNode *N) {
794 N->getOpcode() == ISD::SIGN_EXTEND_INREG ||
795 N->getOpcode() == ISD::ZERO_EXTEND_INREG ||
796 N->getOpcode() == ISD::FP_ROUND_INREG ||
797 N->getOpcode() == ISD::EXTLOAD ||
798 N->getOpcode() == ISD::SEXTLOAD ||
799 N->getOpcode() == ISD::ZEXTLOAD ||
800 N->getOpcode() == ISD::TRUNCSTORE;
804 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
808 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
810 bool operator==(const SDNodeIterator& x) const {
811 return Operand == x.Operand;
813 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
815 const SDNodeIterator &operator=(const SDNodeIterator &I) {
816 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
821 pointer operator*() const {
822 return Node->getOperand(Operand).Val;
824 pointer operator->() const { return operator*(); }
826 SDNodeIterator& operator++() { // Preincrement
830 SDNodeIterator operator++(int) { // Postincrement
831 SDNodeIterator tmp = *this; ++*this; return tmp;
834 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
835 static SDNodeIterator end (SDNode *N) {
836 return SDNodeIterator(N, N->getNumOperands());
839 unsigned getOperand() const { return Operand; }
840 const SDNode *getNode() const { return Node; }
843 template <> struct GraphTraits<SDNode*> {
844 typedef SDNode NodeType;
845 typedef SDNodeIterator ChildIteratorType;
846 static inline NodeType *getEntryNode(SDNode *N) { return N; }
847 static inline ChildIteratorType child_begin(NodeType *N) {
848 return SDNodeIterator::begin(N);
850 static inline ChildIteratorType child_end(NodeType *N) {
851 return SDNodeIterator::end(N);
858 } // end llvm namespace