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/Value.h"
24 #include "llvm/ADT/GraphTraits.h"
25 #include "llvm/ADT/GraphTraits.h"
26 #include "llvm/ADT/iterator"
27 #include "llvm/Support/DataTypes.h"
35 class MachineBasicBlock;
37 template <typename T> struct simplify_type;
39 /// ISD namespace - This namespace contains an enum which represents all of the
40 /// SelectionDAG node types and value types.
43 //===--------------------------------------------------------------------===//
44 /// ISD::NodeType enum - This enum defines all of the operators valid in a
48 // EntryToken - This is the marker used to indicate the start of the region.
51 // Token factor - This node is takes multiple tokens as input and produces a
52 // single token result. This is used to represent the fact that the operand
53 // operators are independent of each other.
56 // Various leaf nodes.
57 Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool,
58 BasicBlock, ExternalSymbol,
60 // CopyToReg - This node has chain and child nodes, and an associated
61 // register number. The instruction selector must guarantee that the value
62 // of the value node is available in the register stored in the RegSDNode
66 // CopyFromReg - This node indicates that the input value is a virtual or
67 // physical register that is defined outside of the scope of this
68 // SelectionDAG. The register is available from the RegSDNode object.
71 // ImplicitDef - This node indicates that the specified register is
72 // implicitly defined by some operation (e.g. its a live-in argument). This
73 // register is indicated in the RegSDNode object. The only operand to this
74 // is the token chain coming in, the only result is the token chain going
78 // UNDEF - An undefined node
81 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
82 // a Constant, which is required to be operand #1), element of the aggregate
83 // value specified as operand #0. This is only for use before legalization,
84 // for values that will be broken into multiple registers.
87 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
88 // two values of the same integer value type, this produces a value twice as
89 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
93 // Simple binary arithmetic operators.
94 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
96 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
97 // an unsigned/signed value of type i[2*n], then return the top part.
100 // Bitwise operators.
101 AND, OR, XOR, SHL, SRA, SRL,
103 // Counting operators
109 // SetCC operator - This evaluates to a boolean (i1) true value if the
110 // condition is true. These nodes are instances of the
111 // SetCCSDNode class, which contains the condition code as extra
115 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
116 // broken into a multiple pieces each, and return the resulting pieces of
117 // doing an atomic add/sub operation. This is used to handle add/sub of
118 // expanded types. The operation ordering is:
119 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
120 ADD_PARTS, SUB_PARTS,
122 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
123 // integer shift operations, just like ADD/SUB_PARTS. The operation
125 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
126 SHL_PARTS, SRA_PARTS, SRL_PARTS,
128 // Conversion operators. These are all single input single output
129 // operations. For all of these, the result type must be strictly
130 // wider or narrower (depending on the operation) than the source
133 // SIGN_EXTEND - Used for integer types, replicating the sign bit
137 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
140 // TRUNCATE - Completely drop the high bits.
143 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
144 // depends on the first letter) to floating point.
148 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
149 // sign extend a small value in a large integer register (e.g. sign
150 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
151 // with the 7th bit). The size of the smaller type is indicated by the
152 // ExtraValueType in the MVTSDNode for the operator.
155 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
160 // FP_ROUND - Perform a rounding operation from the current
161 // precision down to the specified precision (currently always 64->32).
164 // FP_ROUND_INREG - This operator takes a floating point register, and
165 // rounds it to a floating point value. It then promotes it and returns it
166 // in a register of the same size. This operation effectively just discards
167 // excess precision. The type to round down to is specified by the
168 // ExtraValueType in the MVTSDNode (currently always 64->32->64).
171 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
174 // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
175 // absolute value, square root, sine and cosine operations.
176 FNEG, FABS, FSQRT, FSIN, FCOS,
178 // Other operators. LOAD and STORE have token chains as their first
179 // operand, then the same operands as an LLVM load/store instruction.
182 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the
183 // MVTSDNode. All of these load a value from memory and extend them to a
184 // larger value (e.g. load a byte into a word register). All three of these
185 // have two operands, a chain and a pointer to load from. The extra value
186 // type is the source type being loaded.
188 // SEXTLOAD loads the integer operand and sign extends it to a larger
189 // integer result type.
190 // ZEXTLOAD loads the integer operand and zero extends it to a larger
191 // integer result type.
192 // EXTLOAD is used for two things: floating point extending loads, and
193 // integer extending loads where it doesn't matter what the high
194 // bits are set to. The code generator is allowed to codegen this
195 // into whichever operation is more efficient.
196 EXTLOAD, SEXTLOAD, ZEXTLOAD,
198 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
199 // value and stores it to memory in one operation. This can be used for
200 // either integer or floating point operands, and the stored type
201 // represented as the 'extra' value type in the MVTSDNode representing the
202 // operator. This node has the same three operands as a standard store.
205 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
206 // to a specified boundary. The first operand is the token chain, the
207 // second is the number of bytes to allocate, and the third is the alignment
211 // Control flow instructions. These all have token chains.
213 // BR - Unconditional branch. The first operand is the chain
214 // operand, the second is the MBB to branch to.
217 // BRCOND - Conditional branch. The first operand is the chain,
218 // the second is the condition, the third is the block to branch
219 // to if the condition is true.
222 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the
223 // chain, the second is the condition, the third is the block to branch to
224 // if true, and the forth is the block to branch to if false. Targets
225 // usually do not implement this, preferring to have legalize demote the
226 // operation to BRCOND/BR pairs when necessary.
229 // RET - Return from function. The first operand is the chain,
230 // and any subsequent operands are the return values for the
231 // function. This operation can have variable number of operands.
234 // CALL - Call to a function pointer. The first operand is the chain, the
235 // second is the destination function pointer (a GlobalAddress for a direct
236 // call). Arguments have already been lowered to explicit DAGs according to
237 // the calling convention in effect here.
240 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
241 // correspond to the operands of the LLVM intrinsic functions. The only
242 // result is a token chain. The alignment argument is guaranteed to be a
248 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
249 // a call sequence, and carry arbitrary information that target might want
250 // to know. The first operand is a chain, the rest are specified by the
251 // target and not touched by the DAG optimizers.
252 CALLSEQ_START, // Beginning of a call sequence
253 CALLSEQ_END, // End of a call sequence
255 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
256 // locations with their value. This allows one use alias analysis
257 // information in the backend.
260 // PCMARKER - This corresponds to the pcmarker intrinsic.
263 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM
264 // intrinsics of the same name. The first operand is a token chain, the
265 // other operands match the intrinsic. These produce a token chain in
266 // addition to a value (if any).
267 READPORT, WRITEPORT, READIO, WRITEIO,
269 // BUILTIN_OP_END - This must be the last enum value in this list.
273 //===--------------------------------------------------------------------===//
274 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
275 /// below work out, when considering SETFALSE (something that never exists
276 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
277 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
278 /// to. If the "N" column is 1, the result of the comparison is undefined if
279 /// the input is a NAN.
281 /// All of these (except for the 'always folded ops') should be handled for
282 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
283 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
285 /// Note that these are laid out in a specific order to allow bit-twiddling
286 /// to transform conditions.
288 // Opcode N U L G E Intuitive operation
289 SETFALSE, // 0 0 0 0 Always false (always folded)
290 SETOEQ, // 0 0 0 1 True if ordered and equal
291 SETOGT, // 0 0 1 0 True if ordered and greater than
292 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
293 SETOLT, // 0 1 0 0 True if ordered and less than
294 SETOLE, // 0 1 0 1 True if ordered and less than or equal
295 SETONE, // 0 1 1 0 True if ordered and operands are unequal
296 SETO, // 0 1 1 1 True if ordered (no nans)
297 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
298 SETUEQ, // 1 0 0 1 True if unordered or equal
299 SETUGT, // 1 0 1 0 True if unordered or greater than
300 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
301 SETULT, // 1 1 0 0 True if unordered or less than
302 SETULE, // 1 1 0 1 True if unordered, less than, or equal
303 SETUNE, // 1 1 1 0 True if unordered or not equal
304 SETTRUE, // 1 1 1 1 Always true (always folded)
305 // Don't care operations: undefined if the input is a nan.
306 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
307 SETEQ, // 1 X 0 0 1 True if equal
308 SETGT, // 1 X 0 1 0 True if greater than
309 SETGE, // 1 X 0 1 1 True if greater than or equal
310 SETLT, // 1 X 1 0 0 True if less than
311 SETLE, // 1 X 1 0 1 True if less than or equal
312 SETNE, // 1 X 1 1 0 True if not equal
313 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
315 SETCC_INVALID, // Marker value.
318 /// isSignedIntSetCC - Return true if this is a setcc instruction that
319 /// performs a signed comparison when used with integer operands.
320 inline bool isSignedIntSetCC(CondCode Code) {
321 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
324 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
325 /// performs an unsigned comparison when used with integer operands.
326 inline bool isUnsignedIntSetCC(CondCode Code) {
327 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
330 /// isTrueWhenEqual - Return true if the specified condition returns true if
331 /// the two operands to the condition are equal. Note that if one of the two
332 /// operands is a NaN, this value is meaningless.
333 inline bool isTrueWhenEqual(CondCode Cond) {
334 return ((int)Cond & 1) != 0;
337 /// getUnorderedFlavor - This function returns 0 if the condition is always
338 /// false if an operand is a NaN, 1 if the condition is always true if the
339 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
341 inline unsigned getUnorderedFlavor(CondCode Cond) {
342 return ((int)Cond >> 3) & 3;
345 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
346 /// 'op' is a valid SetCC operation.
347 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
349 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
350 /// when given the operation for (X op Y).
351 CondCode getSetCCSwappedOperands(CondCode Operation);
353 /// getSetCCOrOperation - Return the result of a logical OR between different
354 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
355 /// function returns SETCC_INVALID if it is not possible to represent the
356 /// resultant comparison.
357 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
359 /// getSetCCAndOperation - Return the result of a logical AND between
360 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
361 /// function returns SETCC_INVALID if it is not possible to represent the
362 /// resultant comparison.
363 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
364 } // end llvm::ISD namespace
367 //===----------------------------------------------------------------------===//
368 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
369 /// values as the result of a computation. Many nodes return multiple values,
370 /// from loads (which define a token and a return value) to ADDC (which returns
371 /// a result and a carry value), to calls (which may return an arbitrary number
374 /// As such, each use of a SelectionDAG computation must indicate the node that
375 /// computes it as well as which return value to use from that node. This pair
376 /// of information is represented with the SDOperand value type.
380 SDNode *Val; // The node defining the value we are using.
381 unsigned ResNo; // Which return value of the node we are using.
383 SDOperand() : Val(0) {}
384 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
386 bool operator==(const SDOperand &O) const {
387 return Val == O.Val && ResNo == O.ResNo;
389 bool operator!=(const SDOperand &O) const {
390 return !operator==(O);
392 bool operator<(const SDOperand &O) const {
393 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
396 SDOperand getValue(unsigned R) const {
397 return SDOperand(Val, R);
400 /// getValueType - Return the ValueType of the referenced return value.
402 inline MVT::ValueType getValueType() const;
404 // Forwarding methods - These forward to the corresponding methods in SDNode.
405 inline unsigned getOpcode() const;
406 inline unsigned getNodeDepth() const;
407 inline unsigned getNumOperands() const;
408 inline const SDOperand &getOperand(unsigned i) const;
410 /// hasOneUse - Return true if there is exactly one operation using this
411 /// result value of the defining operator.
412 inline bool hasOneUse() const;
416 /// simplify_type specializations - Allow casting operators to work directly on
417 /// SDOperands as if they were SDNode*'s.
418 template<> struct simplify_type<SDOperand> {
419 typedef SDNode* SimpleType;
420 static SimpleType getSimplifiedValue(const SDOperand &Val) {
421 return static_cast<SimpleType>(Val.Val);
424 template<> struct simplify_type<const SDOperand> {
425 typedef SDNode* SimpleType;
426 static SimpleType getSimplifiedValue(const SDOperand &Val) {
427 return static_cast<SimpleType>(Val.Val);
432 /// SDNode - Represents one node in the SelectionDAG.
435 /// NodeType - The operation that this node performs.
437 unsigned short NodeType;
439 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
440 /// means that leaves have a depth of 1, things that use only leaves have a
442 unsigned short NodeDepth;
444 /// Operands - The values that are used by this operation.
446 std::vector<SDOperand> Operands;
448 /// Values - The types of the values this node defines. SDNode's may define
449 /// multiple values simultaneously.
450 std::vector<MVT::ValueType> Values;
452 /// Uses - These are all of the SDNode's that use a value produced by this
454 std::vector<SDNode*> Uses;
457 //===--------------------------------------------------------------------===//
460 unsigned getOpcode() const { return NodeType; }
462 size_t use_size() const { return Uses.size(); }
463 bool use_empty() const { return Uses.empty(); }
464 bool hasOneUse() const { return Uses.size() == 1; }
466 /// getNodeDepth - Return the distance from this node to the leaves in the
467 /// graph. The leaves have a depth of 1.
468 unsigned getNodeDepth() const { return NodeDepth; }
470 typedef std::vector<SDNode*>::const_iterator use_iterator;
471 use_iterator use_begin() const { return Uses.begin(); }
472 use_iterator use_end() const { return Uses.end(); }
474 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
475 /// indicated value. This method ignores uses of other values defined by this
477 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
479 /// getNumOperands - Return the number of values used by this operation.
481 unsigned getNumOperands() const { return Operands.size(); }
483 const SDOperand &getOperand(unsigned Num) {
484 assert(Num < Operands.size() && "Invalid child # of SDNode!");
485 return Operands[Num];
488 const SDOperand &getOperand(unsigned Num) const {
489 assert(Num < Operands.size() && "Invalid child # of SDNode!");
490 return Operands[Num];
493 /// getNumValues - Return the number of values defined/returned by this
496 unsigned getNumValues() const { return Values.size(); }
498 /// getValueType - Return the type of a specified result.
500 MVT::ValueType getValueType(unsigned ResNo) const {
501 assert(ResNo < Values.size() && "Illegal result number!");
502 return Values[ResNo];
505 /// getOperationName - Return the opcode of this operation for printing.
507 const char* getOperationName() const;
510 static bool classof(const SDNode *) { return true; }
513 /// setAdjCallChain - This method should only be used by the legalizer.
514 void setAdjCallChain(SDOperand N);
517 friend class SelectionDAG;
519 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
521 Values.push_back(VT);
523 SDNode(unsigned NT, SDOperand Op)
524 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
525 Operands.reserve(1); Operands.push_back(Op);
526 Op.Val->Uses.push_back(this);
528 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
530 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
531 NodeDepth = N1.Val->getNodeDepth()+1;
533 NodeDepth = N2.Val->getNodeDepth()+1;
534 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
535 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
537 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
539 unsigned ND = N1.Val->getNodeDepth();
540 if (ND < N2.Val->getNodeDepth())
541 ND = N2.Val->getNodeDepth();
542 if (ND < N3.Val->getNodeDepth())
543 ND = N3.Val->getNodeDepth();
546 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
547 Operands.push_back(N3);
548 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
549 N3.Val->Uses.push_back(this);
551 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
553 unsigned ND = N1.Val->getNodeDepth();
554 if (ND < N2.Val->getNodeDepth())
555 ND = N2.Val->getNodeDepth();
556 if (ND < N3.Val->getNodeDepth())
557 ND = N3.Val->getNodeDepth();
558 if (ND < N4.Val->getNodeDepth())
559 ND = N4.Val->getNodeDepth();
562 Operands.reserve(4); Operands.push_back(N1); Operands.push_back(N2);
563 Operands.push_back(N3); Operands.push_back(N4);
564 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
565 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
567 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
568 Operands.swap(Nodes);
570 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
571 Operands[i].Val->Uses.push_back(this);
572 if (ND < Operands[i].Val->getNodeDepth())
573 ND = Operands[i].Val->getNodeDepth();
582 void setValueTypes(MVT::ValueType VT) {
584 Values.push_back(VT);
586 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
588 Values.push_back(VT1);
589 Values.push_back(VT2);
591 /// Note: this method destroys the vector passed in.
592 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
593 std::swap(Values, VTs);
596 void removeUser(SDNode *User) {
597 // Remove this user from the operand's use list.
598 for (unsigned i = Uses.size(); ; --i) {
599 assert(i != 0 && "Didn't find user!");
600 if (Uses[i-1] == User) {
601 Uses.erase(Uses.begin()+i-1);
609 // Define inline functions from the SDOperand class.
611 inline unsigned SDOperand::getOpcode() const {
612 return Val->getOpcode();
614 inline unsigned SDOperand::getNodeDepth() const {
615 return Val->getNodeDepth();
617 inline MVT::ValueType SDOperand::getValueType() const {
618 return Val->getValueType(ResNo);
620 inline unsigned SDOperand::getNumOperands() const {
621 return Val->getNumOperands();
623 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
624 return Val->getOperand(i);
626 inline bool SDOperand::hasOneUse() const {
627 return Val->hasNUsesOfValue(1, ResNo);
631 class ConstantSDNode : public SDNode {
634 friend class SelectionDAG;
635 ConstantSDNode(uint64_t val, MVT::ValueType VT)
636 : SDNode(ISD::Constant, VT), Value(val) {
640 uint64_t getValue() const { return Value; }
642 int64_t getSignExtended() const {
643 unsigned Bits = MVT::getSizeInBits(getValueType(0));
644 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
647 bool isNullValue() const { return Value == 0; }
648 bool isAllOnesValue() const {
649 int NumBits = MVT::getSizeInBits(getValueType(0));
650 if (NumBits == 64) return Value+1 == 0;
651 return Value == (1ULL << NumBits)-1;
654 static bool classof(const ConstantSDNode *) { return true; }
655 static bool classof(const SDNode *N) {
656 return N->getOpcode() == ISD::Constant;
660 class ConstantFPSDNode : public SDNode {
663 friend class SelectionDAG;
664 ConstantFPSDNode(double val, MVT::ValueType VT)
665 : SDNode(ISD::ConstantFP, VT), Value(val) {
669 double getValue() const { return Value; }
671 /// isExactlyValue - We don't rely on operator== working on double values, as
672 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
673 /// As such, this method can be used to do an exact bit-for-bit comparison of
674 /// two floating point values.
675 bool isExactlyValue(double V) const {
689 static bool classof(const ConstantFPSDNode *) { return true; }
690 static bool classof(const SDNode *N) {
691 return N->getOpcode() == ISD::ConstantFP;
695 class GlobalAddressSDNode : public SDNode {
696 GlobalValue *TheGlobal;
698 friend class SelectionDAG;
699 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
700 : SDNode(ISD::GlobalAddress, VT) {
701 TheGlobal = const_cast<GlobalValue*>(GA);
705 GlobalValue *getGlobal() const { return TheGlobal; }
707 static bool classof(const GlobalAddressSDNode *) { return true; }
708 static bool classof(const SDNode *N) {
709 return N->getOpcode() == ISD::GlobalAddress;
714 class FrameIndexSDNode : public SDNode {
717 friend class SelectionDAG;
718 FrameIndexSDNode(int fi, MVT::ValueType VT)
719 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
722 int getIndex() const { return FI; }
724 static bool classof(const FrameIndexSDNode *) { return true; }
725 static bool classof(const SDNode *N) {
726 return N->getOpcode() == ISD::FrameIndex;
730 class ConstantPoolSDNode : public SDNode {
733 friend class SelectionDAG;
734 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
735 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
738 unsigned getIndex() const { return CPI; }
740 static bool classof(const ConstantPoolSDNode *) { return true; }
741 static bool classof(const SDNode *N) {
742 return N->getOpcode() == ISD::ConstantPool;
746 class BasicBlockSDNode : public SDNode {
747 MachineBasicBlock *MBB;
749 friend class SelectionDAG;
750 BasicBlockSDNode(MachineBasicBlock *mbb)
751 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
754 MachineBasicBlock *getBasicBlock() const { return MBB; }
756 static bool classof(const BasicBlockSDNode *) { return true; }
757 static bool classof(const SDNode *N) {
758 return N->getOpcode() == ISD::BasicBlock;
762 class SrcValueSDNode : public SDNode {
766 friend class SelectionDAG;
767 SrcValueSDNode(const Value* v, int o)
768 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
771 const Value *getValue() const { return V; }
772 int getOffset() const { return offset; }
774 static bool classof(const SrcValueSDNode *) { return true; }
775 static bool classof(const SDNode *N) {
776 return N->getOpcode() == ISD::SRCVALUE;
781 class RegSDNode : public SDNode {
784 friend class SelectionDAG;
785 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg)
786 : SDNode(Opc, Chain, Src), Reg(reg) {
788 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg)
789 : SDNode(Opc, Chain), Reg(reg) {}
792 unsigned getReg() const { return Reg; }
794 static bool classof(const RegSDNode *) { return true; }
795 static bool classof(const SDNode *N) {
796 return N->getOpcode() == ISD::CopyToReg ||
797 N->getOpcode() == ISD::CopyFromReg ||
798 N->getOpcode() == ISD::ImplicitDef;
802 class ExternalSymbolSDNode : public SDNode {
805 friend class SelectionDAG;
806 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
807 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
811 const char *getSymbol() const { return Symbol; }
813 static bool classof(const ExternalSymbolSDNode *) { return true; }
814 static bool classof(const SDNode *N) {
815 return N->getOpcode() == ISD::ExternalSymbol;
819 class SetCCSDNode : public SDNode {
820 ISD::CondCode Condition;
822 friend class SelectionDAG;
823 SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS)
824 : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) {
828 ISD::CondCode getCondition() const { return Condition; }
830 static bool classof(const SetCCSDNode *) { return true; }
831 static bool classof(const SDNode *N) {
832 return N->getOpcode() == ISD::SETCC;
836 /// MVTSDNode - This class is used for operators that require an extra
837 /// value-type to be kept with the node.
838 class MVTSDNode : public SDNode {
839 MVT::ValueType ExtraValueType;
841 friend class SelectionDAG;
842 MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT)
843 : SDNode(Opc, Op0), ExtraValueType(EVT) {
846 MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2,
847 SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT)
848 : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) {
849 setValueTypes(VT1, VT2);
852 MVTSDNode(unsigned Opc, MVT::ValueType VT,
853 SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, MVT::ValueType EVT)
854 : SDNode(Opc, Op0, Op1, Op2, Op3), ExtraValueType(EVT) {
859 MVT::ValueType getExtraValueType() const { return ExtraValueType; }
861 static bool classof(const MVTSDNode *) { return true; }
862 static bool classof(const SDNode *N) {
864 N->getOpcode() == ISD::SIGN_EXTEND_INREG ||
865 N->getOpcode() == ISD::FP_ROUND_INREG ||
866 N->getOpcode() == ISD::EXTLOAD ||
867 N->getOpcode() == ISD::SEXTLOAD ||
868 N->getOpcode() == ISD::ZEXTLOAD ||
869 N->getOpcode() == ISD::TRUNCSTORE;
873 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
877 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
879 bool operator==(const SDNodeIterator& x) const {
880 return Operand == x.Operand;
882 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
884 const SDNodeIterator &operator=(const SDNodeIterator &I) {
885 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
890 pointer operator*() const {
891 return Node->getOperand(Operand).Val;
893 pointer operator->() const { return operator*(); }
895 SDNodeIterator& operator++() { // Preincrement
899 SDNodeIterator operator++(int) { // Postincrement
900 SDNodeIterator tmp = *this; ++*this; return tmp;
903 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
904 static SDNodeIterator end (SDNode *N) {
905 return SDNodeIterator(N, N->getNumOperands());
908 unsigned getOperand() const { return Operand; }
909 const SDNode *getNode() const { return Node; }
912 template <> struct GraphTraits<SDNode*> {
913 typedef SDNode NodeType;
914 typedef SDNodeIterator ChildIteratorType;
915 static inline NodeType *getEntryNode(SDNode *N) { return N; }
916 static inline ChildIteratorType child_begin(NodeType *N) {
917 return SDNodeIterator::begin(N);
919 static inline ChildIteratorType child_end(NodeType *N) {
920 return SDNodeIterator::end(N);
927 } // end llvm namespace