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, Register,
60 // TargetConstant - Like Constant, but the DAG does not do any folding or
61 // simplification of the constant. This is used by the DAG->DAG selector.
64 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
65 // anything else with this node, and this is valid in the target-specific
66 // dag, turning into a GlobalAddress operand.
69 // CopyToReg - This node has three operands: a chain, a register number to
70 // set to this value, and a value.
73 // CopyFromReg - This node indicates that the input value is a virtual or
74 // physical register that is defined outside of the scope of this
75 // SelectionDAG. The register is available from the RegSDNode object.
78 // ImplicitDef - This node indicates that the specified register is
79 // implicitly defined by some operation (e.g. its a live-in argument). The
80 // two operands to this are the token chain coming in and the register.
81 // The only result is the token chain going out.
84 // UNDEF - An undefined node
87 // EXTRACT_ELEMENT - This is used to get the first or second (determined by
88 // a Constant, which is required to be operand #1), element of the aggregate
89 // value specified as operand #0. This is only for use before legalization,
90 // for values that will be broken into multiple registers.
93 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given
94 // two values of the same integer value type, this produces a value twice as
95 // big. Like EXTRACT_ELEMENT, this can only be used before legalization.
99 // Simple binary arithmetic operators.
100 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
102 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
103 // an unsigned/signed value of type i[2*n], then return the top part.
106 // Bitwise operators.
107 AND, OR, XOR, SHL, SRA, SRL,
109 // Counting operators
115 // Select with condition operator - This selects between a true value and
116 // a false value (ops #2 and #3) based on the boolean result of comparing
117 // the lhs and rhs (ops #0 and #1) of a conditional expression with the
118 // condition code in op #4, a CondCodeSDNode.
121 // SetCC operator - This evaluates to a boolean (i1) true value if the
122 // condition is true. The operands to this are the left and right operands
123 // to compare (ops #0, and #1) and the condition code to compare them with
124 // (op #2) as a CondCodeSDNode.
127 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are
128 // broken into a multiple pieces each, and return the resulting pieces of
129 // doing an atomic add/sub operation. This is used to handle add/sub of
130 // expanded types. The operation ordering is:
131 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS]
132 ADD_PARTS, SUB_PARTS,
134 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
135 // integer shift operations, just like ADD/SUB_PARTS. The operation
137 // [Lo,Hi] = op [LoLHS,HiLHS], Amt
138 SHL_PARTS, SRA_PARTS, SRL_PARTS,
140 // Conversion operators. These are all single input single output
141 // operations. For all of these, the result type must be strictly
142 // wider or narrower (depending on the operation) than the source
145 // SIGN_EXTEND - Used for integer types, replicating the sign bit
149 // ZERO_EXTEND - Used for integer types, zeroing the new bits.
152 // TRUNCATE - Completely drop the high bits.
155 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
156 // depends on the first letter) to floating point.
160 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
161 // sign extend a small value in a large integer register (e.g. sign
162 // extending the low 8 bits of a 32-bit register to fill the top 24 bits
163 // with the 7th bit). The size of the smaller type is indicated by the 1th
164 // operand, a ValueType node.
167 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
172 // FP_ROUND - Perform a rounding operation from the current
173 // precision down to the specified precision (currently always 64->32).
176 // FP_ROUND_INREG - This operator takes a floating point register, and
177 // rounds it to a floating point value. It then promotes it and returns it
178 // in a register of the same size. This operation effectively just discards
179 // excess precision. The type to round down to is specified by the 1th
180 // operation, a VTSDNode (currently always 64->32->64).
183 // FP_EXTEND - Extend a smaller FP type into a larger FP type.
186 // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation,
187 // absolute value, square root, sine and cosine operations.
188 FNEG, FABS, FSQRT, FSIN, FCOS,
190 // Other operators. LOAD and STORE have token chains as their first
191 // operand, then the same operands as an LLVM load/store instruction, then a
192 // SRCVALUE node that provides alias analysis information.
195 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from
196 // memory and extend them to a larger value (e.g. load a byte into a word
197 // register). All three of these have four operands, a token chain, a
198 // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node
199 // indicating the type to load.
201 // SEXTLOAD loads the integer operand and sign extends it to a larger
202 // integer result type.
203 // ZEXTLOAD loads the integer operand and zero extends it to a larger
204 // integer result type.
205 // EXTLOAD is used for two things: floating point extending loads, and
206 // integer extending loads where it doesn't matter what the high
207 // bits are set to. The code generator is allowed to codegen this
208 // into whichever operation is more efficient.
209 EXTLOAD, SEXTLOAD, ZEXTLOAD,
211 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a
212 // value and stores it to memory in one operation. This can be used for
213 // either integer or floating point operands. The first four operands of
214 // this are the same as a standard store. The fifth is the ValueType to
215 // store it as (which will be smaller than the source value).
218 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
219 // to a specified boundary. The first operand is the token chain, the
220 // second is the number of bytes to allocate, and the third is the alignment
224 // Control flow instructions. These all have token chains.
226 // BR - Unconditional branch. The first operand is the chain
227 // operand, the second is the MBB to branch to.
230 // BRCOND - Conditional branch. The first operand is the chain,
231 // the second is the condition, the third is the block to branch
232 // to if the condition is true.
235 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the
236 // chain, the second is the condition, the third is the block to branch to
237 // if true, and the forth is the block to branch to if false. Targets
238 // usually do not implement this, preferring to have legalize demote the
239 // operation to BRCOND/BR pairs when necessary.
242 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in
243 // that the condition is represented as condition code, and two nodes to
244 // compare, rather than as a combined SetCC node. The operands in order are
245 // chain, cc, lhs, rhs, block to branch to if condition is true.
248 // BRTWOWAY_CC - Two-way conditional branch. The operands in order are
249 // chain, cc, lhs, rhs, block to branch to if condition is true, block to
250 // branch to if condition is false. Targets usually do not implement this,
251 // preferring to have legalize demote the operation to BRCOND/BR pairs.
254 // RET - Return from function. The first operand is the chain,
255 // and any subsequent operands are the return values for the
256 // function. This operation can have variable number of operands.
259 // CALL - Call to a function pointer. The first operand is the chain, the
260 // second is the destination function pointer (a GlobalAddress for a direct
261 // call). Arguments have already been lowered to explicit DAGs according to
262 // the calling convention in effect here. TAILCALL is the same as CALL, but
263 // the callee is known not to access the stack of the caller.
267 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest
268 // correspond to the operands of the LLVM intrinsic functions. The only
269 // result is a token chain. The alignment argument is guaranteed to be a
275 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
276 // a call sequence, and carry arbitrary information that target might want
277 // to know. The first operand is a chain, the rest are specified by the
278 // target and not touched by the DAG optimizers.
279 CALLSEQ_START, // Beginning of a call sequence
280 CALLSEQ_END, // End of a call sequence
282 // SRCVALUE - This corresponds to a Value*, and is used to associate memory
283 // locations with their value. This allows one use alias analysis
284 // information in the backend.
287 // PCMARKER - This corresponds to the pcmarker intrinsic.
290 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM
291 // intrinsics of the same name. The first operand is a token chain, the
292 // other operands match the intrinsic. These produce a token chain in
293 // addition to a value (if any).
294 READPORT, WRITEPORT, READIO, WRITEIO,
296 // BUILTIN_OP_END - This must be the last enum value in this list.
300 //===--------------------------------------------------------------------===//
301 /// ISD::CondCode enum - These are ordered carefully to make the bitfields
302 /// below work out, when considering SETFALSE (something that never exists
303 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered
304 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
305 /// to. If the "N" column is 1, the result of the comparison is undefined if
306 /// the input is a NAN.
308 /// All of these (except for the 'always folded ops') should be handled for
309 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
310 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
312 /// Note that these are laid out in a specific order to allow bit-twiddling
313 /// to transform conditions.
315 // Opcode N U L G E Intuitive operation
316 SETFALSE, // 0 0 0 0 Always false (always folded)
317 SETOEQ, // 0 0 0 1 True if ordered and equal
318 SETOGT, // 0 0 1 0 True if ordered and greater than
319 SETOGE, // 0 0 1 1 True if ordered and greater than or equal
320 SETOLT, // 0 1 0 0 True if ordered and less than
321 SETOLE, // 0 1 0 1 True if ordered and less than or equal
322 SETONE, // 0 1 1 0 True if ordered and operands are unequal
323 SETO, // 0 1 1 1 True if ordered (no nans)
324 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y)
325 SETUEQ, // 1 0 0 1 True if unordered or equal
326 SETUGT, // 1 0 1 0 True if unordered or greater than
327 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal
328 SETULT, // 1 1 0 0 True if unordered or less than
329 SETULE, // 1 1 0 1 True if unordered, less than, or equal
330 SETUNE, // 1 1 1 0 True if unordered or not equal
331 SETTRUE, // 1 1 1 1 Always true (always folded)
332 // Don't care operations: undefined if the input is a nan.
333 SETFALSE2, // 1 X 0 0 0 Always false (always folded)
334 SETEQ, // 1 X 0 0 1 True if equal
335 SETGT, // 1 X 0 1 0 True if greater than
336 SETGE, // 1 X 0 1 1 True if greater than or equal
337 SETLT, // 1 X 1 0 0 True if less than
338 SETLE, // 1 X 1 0 1 True if less than or equal
339 SETNE, // 1 X 1 1 0 True if not equal
340 SETTRUE2, // 1 X 1 1 1 Always true (always folded)
342 SETCC_INVALID, // Marker value.
345 /// isSignedIntSetCC - Return true if this is a setcc instruction that
346 /// performs a signed comparison when used with integer operands.
347 inline bool isSignedIntSetCC(CondCode Code) {
348 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
351 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
352 /// performs an unsigned comparison when used with integer operands.
353 inline bool isUnsignedIntSetCC(CondCode Code) {
354 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
357 /// isTrueWhenEqual - Return true if the specified condition returns true if
358 /// the two operands to the condition are equal. Note that if one of the two
359 /// operands is a NaN, this value is meaningless.
360 inline bool isTrueWhenEqual(CondCode Cond) {
361 return ((int)Cond & 1) != 0;
364 /// getUnorderedFlavor - This function returns 0 if the condition is always
365 /// false if an operand is a NaN, 1 if the condition is always true if the
366 /// operand is a NaN, and 2 if the condition is undefined if the operand is a
368 inline unsigned getUnorderedFlavor(CondCode Cond) {
369 return ((int)Cond >> 3) & 3;
372 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
373 /// 'op' is a valid SetCC operation.
374 CondCode getSetCCInverse(CondCode Operation, bool isInteger);
376 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
377 /// when given the operation for (X op Y).
378 CondCode getSetCCSwappedOperands(CondCode Operation);
380 /// getSetCCOrOperation - Return the result of a logical OR between different
381 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This
382 /// function returns SETCC_INVALID if it is not possible to represent the
383 /// resultant comparison.
384 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
386 /// getSetCCAndOperation - Return the result of a logical AND between
387 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This
388 /// function returns SETCC_INVALID if it is not possible to represent the
389 /// resultant comparison.
390 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
391 } // end llvm::ISD namespace
394 //===----------------------------------------------------------------------===//
395 /// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
396 /// values as the result of a computation. Many nodes return multiple values,
397 /// from loads (which define a token and a return value) to ADDC (which returns
398 /// a result and a carry value), to calls (which may return an arbitrary number
401 /// As such, each use of a SelectionDAG computation must indicate the node that
402 /// computes it as well as which return value to use from that node. This pair
403 /// of information is represented with the SDOperand value type.
407 SDNode *Val; // The node defining the value we are using.
408 unsigned ResNo; // Which return value of the node we are using.
410 SDOperand() : Val(0) {}
411 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
413 bool operator==(const SDOperand &O) const {
414 return Val == O.Val && ResNo == O.ResNo;
416 bool operator!=(const SDOperand &O) const {
417 return !operator==(O);
419 bool operator<(const SDOperand &O) const {
420 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
423 SDOperand getValue(unsigned R) const {
424 return SDOperand(Val, R);
427 /// getValueType - Return the ValueType of the referenced return value.
429 inline MVT::ValueType getValueType() const;
431 // Forwarding methods - These forward to the corresponding methods in SDNode.
432 inline unsigned getOpcode() const;
433 inline unsigned getNodeDepth() const;
434 inline unsigned getNumOperands() const;
435 inline const SDOperand &getOperand(unsigned i) const;
436 inline bool isTargetOpcode() const;
437 inline unsigned getTargetOpcode() const;
439 /// hasOneUse - Return true if there is exactly one operation using this
440 /// result value of the defining operator.
441 inline bool hasOneUse() const;
445 /// simplify_type specializations - Allow casting operators to work directly on
446 /// SDOperands as if they were SDNode*'s.
447 template<> struct simplify_type<SDOperand> {
448 typedef SDNode* SimpleType;
449 static SimpleType getSimplifiedValue(const SDOperand &Val) {
450 return static_cast<SimpleType>(Val.Val);
453 template<> struct simplify_type<const SDOperand> {
454 typedef SDNode* SimpleType;
455 static SimpleType getSimplifiedValue(const SDOperand &Val) {
456 return static_cast<SimpleType>(Val.Val);
461 /// SDNode - Represents one node in the SelectionDAG.
464 /// NodeType - The operation that this node performs.
466 unsigned short NodeType;
468 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This
469 /// means that leaves have a depth of 1, things that use only leaves have a
471 unsigned short NodeDepth;
473 /// Operands - The values that are used by this operation.
475 std::vector<SDOperand> Operands;
477 /// Values - The types of the values this node defines. SDNode's may define
478 /// multiple values simultaneously.
479 std::vector<MVT::ValueType> Values;
481 /// Uses - These are all of the SDNode's that use a value produced by this
483 std::vector<SDNode*> Uses;
486 //===--------------------------------------------------------------------===//
489 unsigned getOpcode() const { return NodeType; }
490 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
491 unsigned getTargetOpcode() const {
492 assert(isTargetOpcode() && "Not a target opcode!");
493 return NodeType - ISD::BUILTIN_OP_END;
496 size_t use_size() const { return Uses.size(); }
497 bool use_empty() const { return Uses.empty(); }
498 bool hasOneUse() const { return Uses.size() == 1; }
500 /// getNodeDepth - Return the distance from this node to the leaves in the
501 /// graph. The leaves have a depth of 1.
502 unsigned getNodeDepth() const { return NodeDepth; }
504 typedef std::vector<SDNode*>::const_iterator use_iterator;
505 use_iterator use_begin() const { return Uses.begin(); }
506 use_iterator use_end() const { return Uses.end(); }
508 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
509 /// indicated value. This method ignores uses of other values defined by this
511 bool hasNUsesOfValue(unsigned NUses, unsigned Value);
513 /// getNumOperands - Return the number of values used by this operation.
515 unsigned getNumOperands() const { return Operands.size(); }
517 const SDOperand &getOperand(unsigned Num) {
518 assert(Num < Operands.size() && "Invalid child # of SDNode!");
519 return Operands[Num];
522 const SDOperand &getOperand(unsigned Num) const {
523 assert(Num < Operands.size() && "Invalid child # of SDNode!");
524 return Operands[Num];
526 typedef std::vector<SDOperand>::const_iterator op_iterator;
527 op_iterator op_begin() const { return Operands.begin(); }
528 op_iterator op_end() const { return Operands.end(); }
531 /// getNumValues - Return the number of values defined/returned by this
534 unsigned getNumValues() const { return Values.size(); }
536 /// getValueType - Return the type of a specified result.
538 MVT::ValueType getValueType(unsigned ResNo) const {
539 assert(ResNo < Values.size() && "Illegal result number!");
540 return Values[ResNo];
543 typedef std::vector<MVT::ValueType>::const_iterator value_iterator;
544 value_iterator value_begin() const { return Values.begin(); }
545 value_iterator value_end() const { return Values.end(); }
547 /// getOperationName - Return the opcode of this operation for printing.
549 const char* getOperationName(const SelectionDAG *G = 0) const;
551 void dump(const SelectionDAG *G) const;
553 static bool classof(const SDNode *) { return true; }
556 /// setAdjCallChain - This method should only be used by the legalizer.
557 void setAdjCallChain(SDOperand N);
560 friend class SelectionDAG;
562 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) {
564 Values.push_back(VT);
566 SDNode(unsigned NT, SDOperand Op)
567 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) {
568 Operands.reserve(1); Operands.push_back(Op);
569 Op.Val->Uses.push_back(this);
571 SDNode(unsigned NT, SDOperand N1, SDOperand N2)
573 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth())
574 NodeDepth = N1.Val->getNodeDepth()+1;
576 NodeDepth = N2.Val->getNodeDepth()+1;
577 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2);
578 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
580 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3)
582 unsigned ND = N1.Val->getNodeDepth();
583 if (ND < N2.Val->getNodeDepth())
584 ND = N2.Val->getNodeDepth();
585 if (ND < N3.Val->getNodeDepth())
586 ND = N3.Val->getNodeDepth();
589 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2);
590 Operands.push_back(N3);
591 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
592 N3.Val->Uses.push_back(this);
594 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4)
596 unsigned ND = N1.Val->getNodeDepth();
597 if (ND < N2.Val->getNodeDepth())
598 ND = N2.Val->getNodeDepth();
599 if (ND < N3.Val->getNodeDepth())
600 ND = N3.Val->getNodeDepth();
601 if (ND < N4.Val->getNodeDepth())
602 ND = N4.Val->getNodeDepth();
605 Operands.reserve(4); Operands.push_back(N1); Operands.push_back(N2);
606 Operands.push_back(N3); Operands.push_back(N4);
607 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this);
608 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this);
610 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) {
611 Operands.swap(Nodes);
613 for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
614 Operands[i].Val->Uses.push_back(this);
615 if (ND < Operands[i].Val->getNodeDepth())
616 ND = Operands[i].Val->getNodeDepth();
623 /// MorphNodeTo - This clears the return value and operands list, and sets the
624 /// opcode of the node to the specified value. This should only be used by
625 /// the SelectionDAG class.
626 void MorphNodeTo(unsigned Opc) {
630 // Clear the operands list, updating used nodes to remove this from their
632 while (!Operands.empty()) {
633 SDNode *O = Operands.back().Val;
639 void setValueTypes(MVT::ValueType VT) {
641 Values.push_back(VT);
643 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) {
645 Values.push_back(VT1);
646 Values.push_back(VT2);
648 /// Note: this method destroys the vector passed in.
649 void setValueTypes(std::vector<MVT::ValueType> &VTs) {
650 std::swap(Values, VTs);
653 void setOperands(SDOperand Op0) {
655 Operands.push_back(Op0);
656 Op0.Val->Uses.push_back(this);
658 void setOperands(SDOperand Op0, SDOperand Op1) {
660 Operands.push_back(Op0);
661 Operands.push_back(Op1);
662 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
664 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) {
666 Operands.push_back(Op0);
667 Operands.push_back(Op1);
668 Operands.push_back(Op2);
669 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
670 Op2.Val->Uses.push_back(this);
672 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) {
674 Operands.push_back(Op0);
675 Operands.push_back(Op1);
676 Operands.push_back(Op2);
677 Operands.push_back(Op3);
678 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this);
679 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this);
681 void addUser(SDNode *User) {
682 Uses.push_back(User);
684 void removeUser(SDNode *User) {
685 // Remove this user from the operand's use list.
686 for (unsigned i = Uses.size(); ; --i) {
687 assert(i != 0 && "Didn't find user!");
688 if (Uses[i-1] == User) {
689 Uses[i-1] = Uses.back();
698 // Define inline functions from the SDOperand class.
700 inline unsigned SDOperand::getOpcode() const {
701 return Val->getOpcode();
703 inline unsigned SDOperand::getNodeDepth() const {
704 return Val->getNodeDepth();
706 inline MVT::ValueType SDOperand::getValueType() const {
707 return Val->getValueType(ResNo);
709 inline unsigned SDOperand::getNumOperands() const {
710 return Val->getNumOperands();
712 inline const SDOperand &SDOperand::getOperand(unsigned i) const {
713 return Val->getOperand(i);
715 inline bool SDOperand::isTargetOpcode() const {
716 return Val->isTargetOpcode();
718 inline unsigned SDOperand::getTargetOpcode() const {
719 return Val->getTargetOpcode();
721 inline bool SDOperand::hasOneUse() const {
722 return Val->hasNUsesOfValue(1, ResNo);
726 class ConstantSDNode : public SDNode {
729 friend class SelectionDAG;
730 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT)
731 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) {
735 uint64_t getValue() const { return Value; }
737 int64_t getSignExtended() const {
738 unsigned Bits = MVT::getSizeInBits(getValueType(0));
739 return ((int64_t)Value << (64-Bits)) >> (64-Bits);
742 bool isNullValue() const { return Value == 0; }
743 bool isAllOnesValue() const {
744 int NumBits = MVT::getSizeInBits(getValueType(0));
745 if (NumBits == 64) return Value+1 == 0;
746 return Value == (1ULL << NumBits)-1;
749 static bool classof(const ConstantSDNode *) { return true; }
750 static bool classof(const SDNode *N) {
751 return N->getOpcode() == ISD::Constant ||
752 N->getOpcode() == ISD::TargetConstant;
756 class ConstantFPSDNode : public SDNode {
759 friend class SelectionDAG;
760 ConstantFPSDNode(double val, MVT::ValueType VT)
761 : SDNode(ISD::ConstantFP, VT), Value(val) {
765 double getValue() const { return Value; }
767 /// isExactlyValue - We don't rely on operator== working on double values, as
768 /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
769 /// As such, this method can be used to do an exact bit-for-bit comparison of
770 /// two floating point values.
771 bool isExactlyValue(double V) const;
773 static bool classof(const ConstantFPSDNode *) { return true; }
774 static bool classof(const SDNode *N) {
775 return N->getOpcode() == ISD::ConstantFP;
779 class GlobalAddressSDNode : public SDNode {
780 GlobalValue *TheGlobal;
782 friend class SelectionDAG;
783 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT)
784 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) {
785 TheGlobal = const_cast<GlobalValue*>(GA);
789 GlobalValue *getGlobal() const { return TheGlobal; }
791 static bool classof(const GlobalAddressSDNode *) { return true; }
792 static bool classof(const SDNode *N) {
793 return N->getOpcode() == ISD::GlobalAddress ||
794 N->getOpcode() == ISD::TargetGlobalAddress;
799 class FrameIndexSDNode : public SDNode {
802 friend class SelectionDAG;
803 FrameIndexSDNode(int fi, MVT::ValueType VT)
804 : SDNode(ISD::FrameIndex, VT), FI(fi) {}
807 int getIndex() const { return FI; }
809 static bool classof(const FrameIndexSDNode *) { return true; }
810 static bool classof(const SDNode *N) {
811 return N->getOpcode() == ISD::FrameIndex;
815 class ConstantPoolSDNode : public SDNode {
818 friend class SelectionDAG;
819 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT)
820 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {}
823 unsigned getIndex() const { return CPI; }
825 static bool classof(const ConstantPoolSDNode *) { return true; }
826 static bool classof(const SDNode *N) {
827 return N->getOpcode() == ISD::ConstantPool;
831 class BasicBlockSDNode : public SDNode {
832 MachineBasicBlock *MBB;
834 friend class SelectionDAG;
835 BasicBlockSDNode(MachineBasicBlock *mbb)
836 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {}
839 MachineBasicBlock *getBasicBlock() const { return MBB; }
841 static bool classof(const BasicBlockSDNode *) { return true; }
842 static bool classof(const SDNode *N) {
843 return N->getOpcode() == ISD::BasicBlock;
847 class SrcValueSDNode : public SDNode {
851 friend class SelectionDAG;
852 SrcValueSDNode(const Value* v, int o)
853 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {}
856 const Value *getValue() const { return V; }
857 int getOffset() const { return offset; }
859 static bool classof(const SrcValueSDNode *) { return true; }
860 static bool classof(const SDNode *N) {
861 return N->getOpcode() == ISD::SRCVALUE;
866 class RegisterSDNode : public SDNode {
869 friend class SelectionDAG;
870 RegisterSDNode(unsigned reg, MVT::ValueType VT)
871 : SDNode(ISD::Register, VT), Reg(reg) {}
874 unsigned getReg() const { return Reg; }
876 static bool classof(const RegisterSDNode *) { return true; }
877 static bool classof(const SDNode *N) {
878 return N->getOpcode() == ISD::Register;
882 class ExternalSymbolSDNode : public SDNode {
885 friend class SelectionDAG;
886 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT)
887 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) {
891 const char *getSymbol() const { return Symbol; }
893 static bool classof(const ExternalSymbolSDNode *) { return true; }
894 static bool classof(const SDNode *N) {
895 return N->getOpcode() == ISD::ExternalSymbol;
899 class CondCodeSDNode : public SDNode {
900 ISD::CondCode Condition;
902 friend class SelectionDAG;
903 CondCodeSDNode(ISD::CondCode Cond)
904 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) {
908 ISD::CondCode get() const { return Condition; }
910 static bool classof(const CondCodeSDNode *) { return true; }
911 static bool classof(const SDNode *N) {
912 return N->getOpcode() == ISD::CONDCODE;
916 /// VTSDNode - This class is used to represent MVT::ValueType's, which are used
917 /// to parameterize some operations.
918 class VTSDNode : public SDNode {
919 MVT::ValueType ValueType;
921 friend class SelectionDAG;
922 VTSDNode(MVT::ValueType VT)
923 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {}
926 MVT::ValueType getVT() const { return ValueType; }
928 static bool classof(const VTSDNode *) { return true; }
929 static bool classof(const SDNode *N) {
930 return N->getOpcode() == ISD::VALUETYPE;
935 class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
939 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
941 bool operator==(const SDNodeIterator& x) const {
942 return Operand == x.Operand;
944 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
946 const SDNodeIterator &operator=(const SDNodeIterator &I) {
947 assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
952 pointer operator*() const {
953 return Node->getOperand(Operand).Val;
955 pointer operator->() const { return operator*(); }
957 SDNodeIterator& operator++() { // Preincrement
961 SDNodeIterator operator++(int) { // Postincrement
962 SDNodeIterator tmp = *this; ++*this; return tmp;
965 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
966 static SDNodeIterator end (SDNode *N) {
967 return SDNodeIterator(N, N->getNumOperands());
970 unsigned getOperand() const { return Operand; }
971 const SDNode *getNode() const { return Node; }
974 template <> struct GraphTraits<SDNode*> {
975 typedef SDNode NodeType;
976 typedef SDNodeIterator ChildIteratorType;
977 static inline NodeType *getEntryNode(SDNode *N) { return N; }
978 static inline ChildIteratorType child_begin(NodeType *N) {
979 return SDNodeIterator::begin(N);
981 static inline ChildIteratorType child_end(NodeType *N) {
982 return SDNodeIterator::end(N);
986 } // end llvm namespace