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, VALUETYPE, CONDCODE,
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. The operands to this are the left and right operands
111 // to compare (ops #0, and #1) and the condition code to compare them with
112 // (op #2) as a CondCodeSDNode.
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 1th
152 // operand, a ValueType node.
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 1th
168 // operation, a VTSDNode (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, then a
180 // SRCVALUE node that provides alias analysis information.
183 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
184 // memory and extend them to a larger value (e.g. load a byte into a word
185 // register). All three of these have four operands, a token chain, a
186 // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
187 // indicating the type to load.
189 // SEXTLOAD loads the integer operand and sign extends it to a larger
190 // integer result type.
191 // ZEXTLOAD loads the integer operand and zero extends it to a larger
192 // integer result type.
193 // EXTLOAD is used for two things: floating point extending loads, and
194 // integer extending loads where it doesn't matter what the high
195 // bits are set to. The code generator is allowed to codegen this
196 // into whichever operation is more efficient.
197 EXTLOAD, SEXTLOAD, ZEXTLOAD,
199 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
200 // value and stores it to memory in one operation. This can be used for
201 // either integer or floating point operands. The first four operands of
202 // this are the same as a standard store. The fifth is the ValueType to
203 // store it as (which will be smaller than the source value).
206 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
207 // to a specified boundary. The first operand is the token chain, the
208 // second is the number of bytes to allocate, and the third is the alignment
212 // Control flow instructions. These all have token chains.
214 // BR - Unconditional branch. The first operand is the chain
215 // operand, the second is the MBB to branch to.
218 // BRCOND - Conditional branch. The first operand is the chain,
219 // the second is the condition, the third is the block to branch
220 // to if the condition is true.
223 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the
224 // chain, the second is the condition, the third is the block to branch to
225 // if true, and the forth is the block to branch to if false. Targets
226 // usually do not implement this, preferring to have legalize demote the
227 // operation to BRCOND/BR pairs when necessary.
230 // RET - Return from function. The first operand is the chain,
231 // and any subsequent operands are the return values for the
232 // function. This operation can have variable number of operands.
235 // CALL - Call to a function pointer. The first operand is the chain, the
236 // second is the destination function pointer (a GlobalAddress for a direct
237 // call). Arguments have already been lowered to explicit DAGs according to
238 // the calling convention in effect here. TAILCALL is the same as CALL, but
239 // the callee is known not to access the stack of the caller.
243 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
244 // correspond to the operands of the LLVM intrinsic functions. The only
245 // result is a token chain. The alignment argument is guaranteed to be a
251 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
252 // a call sequence, and carry arbitrary information that target might want
253 // to know. The first operand is a chain, the rest are specified by the
254 // target and not touched by the DAG optimizers.
255 CALLSEQ_START, // Beginning of a call sequence
256 CALLSEQ_END, // End of a call sequence
258 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
259 // locations with their value. This allows one use alias analysis
260 // information in the backend.
263 // PCMARKER - This corresponds to the pcmarker intrinsic.
266 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM
267 // intrinsics of the same name. The first operand is a token chain, the
268 // other operands match the intrinsic. These produce a token chain in
269 // addition to a value (if any).
270 READPORT, WRITEPORT, READIO, WRITEIO,
272 // BUILTIN_OP_END - This must be the last enum value in this list.
276 //===--------------------------------------------------------------------===//
277 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
278 /// below work out, when considering SETFALSE (something that never exists
279 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
280 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
281 /// to. If the "N" column is 1, the result of the comparison is undefined if
282 /// the input is a NAN.
284 /// All of these (except for the 'always folded ops') should be handled for
285 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
286 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
288 /// Note that these are laid out in a specific order to allow bit-twiddling
289 /// to transform conditions.
291 // Opcode N U L G E Intuitive operation
292 SETFALSE, // 0 0 0 0 Always false (always folded)
293 SETOEQ, // 0 0 0 1 True if ordered and equal
294 SETOGT, // 0 0 1 0 True if ordered and greater than
295 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
296 SETOLT, // 0 1 0 0 True if ordered and less than
297 SETOLE, // 0 1 0 1 True if ordered and less than or equal
298 SETONE, // 0 1 1 0 True if ordered and operands are unequal
299 SETO, // 0 1 1 1 True if ordered (no nans)
300 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
301 SETUEQ, // 1 0 0 1 True if unordered or equal
302 SETUGT, // 1 0 1 0 True if unordered or greater than
303 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
304 SETULT, // 1 1 0 0 True if unordered or less than
305 SETULE, // 1 1 0 1 True if unordered, less than, or equal
306 SETUNE, // 1 1 1 0 True if unordered or not equal
307 SETTRUE, // 1 1 1 1 Always true (always folded)
308 // Don't care operations: undefined if the input is a nan.
309 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
310 SETEQ, // 1 X 0 0 1 True if equal
311 SETGT, // 1 X 0 1 0 True if greater than
312 SETGE, // 1 X 0 1 1 True if greater than or equal
313 SETLT, // 1 X 1 0 0 True if less than
314 SETLE, // 1 X 1 0 1 True if less than or equal
315 SETNE, // 1 X 1 1 0 True if not equal
316 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
318 SETCC_INVALID, // Marker value.
321 /// isSignedIntSetCC - Return true if this is a setcc instruction that
322 /// performs a signed comparison when used with integer operands.
323 inline bool isSignedIntSetCC(CondCode Code) {
324 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
327 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
328 /// performs an unsigned comparison when used with integer operands.
329 inline bool isUnsignedIntSetCC(CondCode Code) {
330 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
333 /// isTrueWhenEqual - Return true if the specified condition returns true if
334 /// the two operands to the condition are equal. Note that if one of the two
335 /// operands is a NaN, this value is meaningless.
336 inline bool isTrueWhenEqual(CondCode Cond) {
337 return ((int)Cond & 1) != 0;
340 /// getUnorderedFlavor - This function returns 0 if the condition is always
341 /// false if an operand is a NaN, 1 if the condition is always true if the
342 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
344 inline unsigned getUnorderedFlavor(CondCode Cond) {
345 return ((int)Cond >> 3) & 3;
348 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
349 /// 'op' is a valid SetCC operation.
350 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
352 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
353 /// when given the operation for (X op Y).
354 CondCode getSetCCSwappedOperands(CondCode Operation);
356 /// getSetCCOrOperation - Return the result of a logical OR between different
357 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
358 /// function returns SETCC_INVALID if it is not possible to represent the
359 /// resultant comparison.
360 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
362 /// getSetCCAndOperation - Return the result of a logical AND between
363 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
364 /// function returns SETCC_INVALID if it is not possible to represent the
365 /// resultant comparison.
366 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
367 } // end llvm::ISD namespace
370 //===----------------------------------------------------------------------===//
371 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
372 /// values as the result of a computation. Many nodes return multiple values,
373 /// from loads (which define a token and a return value) to ADDC (which returns
374 /// a result and a carry value), to calls (which may return an arbitrary number
377 /// As such, each use of a SelectionDAG computation must indicate the node that
378 /// computes it as well as which return value to use from that node. This pair
379 /// of information is represented with the SDOperand value type.
383 SDNode *Val; // The node defining the value we are using.
384 unsigned ResNo; // Which return value of the node we are using.
386 SDOperand() : Val(0) {}
387 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
389 bool operator==(const SDOperand &O) const {
390 return Val == O.Val && ResNo == O.ResNo;
392 bool operator!=(const SDOperand &O) const {
393 return !operator==(O);
395 bool operator<(const SDOperand &O) const {
396 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
399 SDOperand getValue(unsigned R) const {
400 return SDOperand(Val, R);
403 /// getValueType - Return the ValueType of the referenced return value.
405 inline MVT::ValueType getValueType() const;
407 // Forwarding methods - These forward to the corresponding methods in SDNode.
408 inline unsigned getOpcode() const;
409 inline unsigned getNodeDepth() const;
410 inline unsigned getNumOperands() const;
411 inline const SDOperand &getOperand(unsigned i) const;
413 /// hasOneUse - Return true if there is exactly one operation using this
414 /// result value of the defining operator.
415 inline bool hasOneUse() const;
419 /// simplify_type specializations - Allow casting operators to work directly on
420 /// SDOperands as if they were SDNode*'s.
421 template<> struct simplify_type<SDOperand> {
422 typedef SDNode* SimpleType;
423 static SimpleType getSimplifiedValue(const SDOperand &Val) {
424 return static_cast<SimpleType>(Val.Val);
427 template<> struct simplify_type<const SDOperand> {
428 typedef SDNode* SimpleType;
429 static SimpleType getSimplifiedValue(const SDOperand &Val) {
430 return static_cast<SimpleType>(Val.Val);
435 /// SDNode - Represents one node in the SelectionDAG.
438 /// NodeType - The operation that this node performs.
440 unsigned short NodeType;
442 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
443 /// means that leaves have a depth of 1, things that use only leaves have a
445 unsigned short NodeDepth;
447 /// Operands - The values that are used by this operation.
449 std::vector<SDOperand> Operands;
451 /// Values - The types of the values this node defines. SDNode's may define
452 /// multiple values simultaneously.
453 std::vector<MVT::ValueType> Values;
455 /// Uses - These are all of the SDNode's that use a value produced by this
457 std::vector<SDNode*> Uses;
460 //===--------------------------------------------------------------------===//
463 unsigned getOpcode() const { return NodeType; }
465 size_t use_size() const { return Uses.size(); }
466 bool use_empty() const { return Uses.empty(); }
467 bool hasOneUse() const { return Uses.size() == 1; }
469 /// getNodeDepth - Return the distance from this node to the leaves in the
470 /// graph. The leaves have a depth of 1.
471 unsigned getNodeDepth() const { return NodeDepth; }
473 typedef std::vector<SDNode*>::const_iterator use_iterator;
474 use_iterator use_begin() const { return Uses.begin(); }
475 use_iterator use_end() const { return Uses.end(); }
477 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
478 /// indicated value. This method ignores uses of other values defined by this
480 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
482 /// getNumOperands - Return the number of values used by this operation.
484 unsigned getNumOperands() const { return Operands.size(); }
486 const SDOperand &getOperand(unsigned Num) {
487 assert(Num < Operands.size() && "Invalid child # of SDNode!");
488 return Operands[Num];
491 const SDOperand &getOperand(unsigned Num) const {
492 assert(Num < Operands.size() && "Invalid child # of SDNode!");
493 return Operands[Num];
495 typedef std::vector<SDOperand>::const_iterator op_iterator;
496 op_iterator op_begin() const { return Operands.begin(); }
497 op_iterator op_end() const { return Operands.end(); }
500 /// getNumValues - Return the number of values defined/returned by this
503 unsigned getNumValues() const { return Values.size(); }
505 /// getValueType - Return the type of a specified result.
507 MVT::ValueType getValueType(unsigned ResNo) const {
508 assert(ResNo < Values.size() && "Illegal result number!");
509 return Values[ResNo];
512 typedef std::vector<MVT::ValueType>::const_iterator value_iterator;
513 value_iterator value_begin() const { return Values.begin(); }
514 value_iterator value_end() const { return Values.end(); }
516 /// getOperationName - Return the opcode of this operation for printing.
518 const char* getOperationName() const;
521 static bool classof(const SDNode *) { return true; }
524 /// setAdjCallChain - This method should only be used by the legalizer.
525 void setAdjCallChain(SDOperand N);
528 friend class SelectionDAG;
530 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
532 Values.push_back(VT);
534 SDNode(unsigned NT, SDOperand Op)
535 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
536 Operands.reserve(1); Operands.push_back(Op);
537 Op.Val->Uses.push_back(this);
539 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
541 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
542 NodeDepth = N1.Val->getNodeDepth()+1;
544 NodeDepth = N2.Val->getNodeDepth()+1;
545 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
546 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
548 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
550 unsigned ND = N1.Val->getNodeDepth();
551 if (ND < N2.Val->getNodeDepth())
552 ND = N2.Val->getNodeDepth();
553 if (ND < N3.Val->getNodeDepth())
554 ND = N3.Val->getNodeDepth();
557 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
558 Operands.push_back(N3);
559 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
560 N3.Val->Uses.push_back(this);
562 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
564 unsigned ND = N1.Val->getNodeDepth();
565 if (ND < N2.Val->getNodeDepth())
566 ND = N2.Val->getNodeDepth();
567 if (ND < N3.Val->getNodeDepth())
568 ND = N3.Val->getNodeDepth();
569 if (ND < N4.Val->getNodeDepth())
570 ND = N4.Val->getNodeDepth();
573 Operands.reserve(4); Operands.push_back(N1); Operands.push_back(N2);
574 Operands.push_back(N3); Operands.push_back(N4);
575 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
576 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
578 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
579 Operands.swap(Nodes);
581 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
582 Operands[i].Val->Uses.push_back(this);
583 if (ND < Operands[i].Val->getNodeDepth())
584 ND = Operands[i].Val->getNodeDepth();
593 void setValueTypes(MVT::ValueType VT) {
595 Values.push_back(VT);
597 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
599 Values.push_back(VT1);
600 Values.push_back(VT2);
602 /// Note: this method destroys the vector passed in.
603 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
604 std::swap(Values, VTs);
607 void removeUser(SDNode *User) {
608 // Remove this user from the operand's use list.
609 for (unsigned i = Uses.size(); ; --i) {
610 assert(i != 0 && "Didn't find user!");
611 if (Uses[i-1] == User) {
612 Uses.erase(Uses.begin()+i-1);
620 // Define inline functions from the SDOperand class.
622 inline unsigned SDOperand::getOpcode() const {
623 return Val->getOpcode();
625 inline unsigned SDOperand::getNodeDepth() const {
626 return Val->getNodeDepth();
628 inline MVT::ValueType SDOperand::getValueType() const {
629 return Val->getValueType(ResNo);
631 inline unsigned SDOperand::getNumOperands() const {
632 return Val->getNumOperands();
634 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
635 return Val->getOperand(i);
637 inline bool SDOperand::hasOneUse() const {
638 return Val->hasNUsesOfValue(1, ResNo);
642 class ConstantSDNode : public SDNode {
645 friend class SelectionDAG;
646 ConstantSDNode(uint64_t val, MVT::ValueType VT)
647 : SDNode(ISD::Constant, VT), Value(val) {
651 uint64_t getValue() const { return Value; }
653 int64_t getSignExtended() const {
654 unsigned Bits = MVT::getSizeInBits(getValueType(0));
655 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
658 bool isNullValue() const { return Value == 0; }
659 bool isAllOnesValue() const {
660 int NumBits = MVT::getSizeInBits(getValueType(0));
661 if (NumBits == 64) return Value+1 == 0;
662 return Value == (1ULL << NumBits)-1;
665 static bool classof(const ConstantSDNode *) { return true; }
666 static bool classof(const SDNode *N) {
667 return N->getOpcode() == ISD::Constant;
671 class ConstantFPSDNode : public SDNode {
674 friend class SelectionDAG;
675 ConstantFPSDNode(double val, MVT::ValueType VT)
676 : SDNode(ISD::ConstantFP, VT), Value(val) {
680 double getValue() const { return Value; }
682 /// isExactlyValue - We don't rely on operator== working on double values, as
683 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
684 /// As such, this method can be used to do an exact bit-for-bit comparison of
685 /// two floating point values.
686 bool isExactlyValue(double V) const {
700 static bool classof(const ConstantFPSDNode *) { return true; }
701 static bool classof(const SDNode *N) {
702 return N->getOpcode() == ISD::ConstantFP;
706 class GlobalAddressSDNode : public SDNode {
707 GlobalValue *TheGlobal;
709 friend class SelectionDAG;
710 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT)
711 : SDNode(ISD::GlobalAddress, VT) {
712 TheGlobal = const_cast<GlobalValue*>(GA);
716 GlobalValue *getGlobal() const { return TheGlobal; }
718 static bool classof(const GlobalAddressSDNode *) { return true; }
719 static bool classof(const SDNode *N) {
720 return N->getOpcode() == ISD::GlobalAddress;
725 class FrameIndexSDNode : public SDNode {
728 friend class SelectionDAG;
729 FrameIndexSDNode(int fi, MVT::ValueType VT)
730 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
733 int getIndex() const { return FI; }
735 static bool classof(const FrameIndexSDNode *) { return true; }
736 static bool classof(const SDNode *N) {
737 return N->getOpcode() == ISD::FrameIndex;
741 class ConstantPoolSDNode : public SDNode {
744 friend class SelectionDAG;
745 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
746 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
749 unsigned getIndex() const { return CPI; }
751 static bool classof(const ConstantPoolSDNode *) { return true; }
752 static bool classof(const SDNode *N) {
753 return N->getOpcode() == ISD::ConstantPool;
757 class BasicBlockSDNode : public SDNode {
758 MachineBasicBlock *MBB;
760 friend class SelectionDAG;
761 BasicBlockSDNode(MachineBasicBlock *mbb)
762 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
765 MachineBasicBlock *getBasicBlock() const { return MBB; }
767 static bool classof(const BasicBlockSDNode *) { return true; }
768 static bool classof(const SDNode *N) {
769 return N->getOpcode() == ISD::BasicBlock;
773 class SrcValueSDNode : public SDNode {
777 friend class SelectionDAG;
778 SrcValueSDNode(const Value* v, int o)
779 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
782 const Value *getValue() const { return V; }
783 int getOffset() const { return offset; }
785 static bool classof(const SrcValueSDNode *) { return true; }
786 static bool classof(const SDNode *N) {
787 return N->getOpcode() == ISD::SRCVALUE;
792 class RegSDNode : public SDNode {
795 friend class SelectionDAG;
796 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg)
797 : SDNode(Opc, Chain, Src), Reg(reg) {
799 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg)
800 : SDNode(Opc, Chain), Reg(reg) {}
803 unsigned getReg() const { return Reg; }
805 static bool classof(const RegSDNode *) { return true; }
806 static bool classof(const SDNode *N) {
807 return N->getOpcode() == ISD::CopyToReg ||
808 N->getOpcode() == ISD::CopyFromReg ||
809 N->getOpcode() == ISD::ImplicitDef;
813 class ExternalSymbolSDNode : public SDNode {
816 friend class SelectionDAG;
817 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
818 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
822 const char *getSymbol() const { return Symbol; }
824 static bool classof(const ExternalSymbolSDNode *) { return true; }
825 static bool classof(const SDNode *N) {
826 return N->getOpcode() == ISD::ExternalSymbol;
830 class CondCodeSDNode : public SDNode {
831 ISD::CondCode Condition;
833 friend class SelectionDAG;
834 CondCodeSDNode(ISD::CondCode Cond)
835 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
839 ISD::CondCode get() const { return Condition; }
841 static bool classof(const CondCodeSDNode *) { return true; }
842 static bool classof(const SDNode *N) {
843 return N->getOpcode() == ISD::CONDCODE;
847 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
848 /// to parameterize some operations.
849 class VTSDNode : public SDNode {
850 MVT::ValueType ValueType;
852 friend class SelectionDAG;
853 VTSDNode(MVT::ValueType VT)
854 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
857 MVT::ValueType getVT() const { return ValueType; }
859 static bool classof(const VTSDNode *) { return true; }
860 static bool classof(const SDNode *N) {
861 return N->getOpcode() == ISD::VALUETYPE;
866 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
870 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
872 bool operator==(const SDNodeIterator& x) const {
873 return Operand == x.Operand;
875 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
877 const SDNodeIterator &operator=(const SDNodeIterator &I) {
878 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
883 pointer operator*() const {
884 return Node->getOperand(Operand).Val;
886 pointer operator->() const { return operator*(); }
888 SDNodeIterator& operator++() { // Preincrement
892 SDNodeIterator operator++(int) { // Postincrement
893 SDNodeIterator tmp = *this; ++*this; return tmp;
896 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
897 static SDNodeIterator end (SDNode *N) {
898 return SDNodeIterator(N, N->getNumOperands());
901 unsigned getOperand() const { return Operand; }
902 const SDNode *getNode() const { return Node; }
905 template <> struct GraphTraits<SDNode*> {
906 typedef SDNode NodeType;
907 typedef SDNodeIterator ChildIteratorType;
908 static inline NodeType *getEntryNode(SDNode *N) { return N; }
909 static inline ChildIteratorType child_begin(NodeType *N) {
910 return SDNodeIterator::begin(N);
912 static inline ChildIteratorType child_end(NodeType *N) {
913 return SDNodeIterator::end(N);
917 } // end llvm namespace