SelectionDAGNodes.h revision 7ece380440238ad0630a225b85a09a2dbed1165a
1//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 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. 7// 8//===----------------------------------------------------------------------===// 9// 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. 14// 15// Clients should include the SelectionDAG.h file instead of this file directly. 16// 17//===----------------------------------------------------------------------===// 18 19#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H 20#define LLVM_CODEGEN_SELECTIONDAGNODES_H 21 22#include "llvm/CodeGen/ValueTypes.h" 23#include "llvm/ADT/GraphTraits.h" 24#include "llvm/ADT/GraphTraits.h" 25#include "llvm/ADT/iterator" 26#include "llvm/Support/DataTypes.h" 27#include <cassert> 28#include <vector> 29 30namespace llvm { 31 32class SelectionDAG; 33class GlobalValue; 34class MachineBasicBlock; 35class SDNode; 36template <typename T> struct simplify_type; 37 38/// ISD namespace - This namespace contains an enum which represents all of the 39/// SelectionDAG node types and value types. 40/// 41namespace ISD { 42 //===--------------------------------------------------------------------===// 43 /// ISD::NodeType enum - This enum defines all of the operators valid in a 44 /// SelectionDAG. 45 /// 46 enum NodeType { 47 // EntryToken - This is the marker used to indicate the start of the region. 48 EntryToken, 49 50 // Token factor - This node is takes multiple tokens as input and produces a 51 // single token result. This is used to represent the fact that the operand 52 // operators are independent of each other. 53 TokenFactor, 54 55 // Various leaf nodes. 56 Constant, ConstantFP, GlobalAddress, FrameIndex, ConstantPool, 57 BasicBlock, ExternalSymbol, 58 59 // CopyToReg - This node has chain and child nodes, and an associated 60 // register number. The instruction selector must guarantee that the value 61 // of the value node is available in the register stored in the RegSDNode 62 // object. 63 CopyToReg, 64 65 // CopyFromReg - This node indicates that the input value is a virtual or 66 // physical register that is defined outside of the scope of this 67 // SelectionDAG. The register is available from the RegSDNode object. 68 CopyFromReg, 69 70 // ImplicitDef - This node indicates that the specified register is 71 // implicitly defined by some operation (e.g. its a live-in argument). This 72 // register is indicated in the RegSDNode object. The only operand to this 73 // is the token chain coming in, the only result is the token chain going 74 // out. 75 ImplicitDef, 76 77 // EXTRACT_ELEMENT - This is used to get the first or second (determined by 78 // a Constant, which is required to be operand #1), element of the aggregate 79 // value specified as operand #0. This is only for use before legalization, 80 // for values that will be broken into multiple registers. 81 EXTRACT_ELEMENT, 82 83 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given 84 // two values of the same integer value type, this produces a value twice as 85 // big. Like EXTRACT_ELEMENT, this can only be used before legalization. 86 BUILD_PAIR, 87 88 89 // Simple binary arithmetic operators. 90 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, 91 92 // Bitwise operators. 93 AND, OR, XOR, SHL, SRA, SRL, 94 95 // Select operator. 96 SELECT, 97 98 // SetCC operator - This evaluates to a boolean (i1) true value if the 99 // condition is true. These nodes are instances of the 100 // SetCCSDNode class, which contains the condition code as extra 101 // state. 102 SETCC, 103 104 // addc - Three input, two output operator: (X, Y, C) -> (X+Y+C, 105 // Cout). X,Y are integer inputs of agreeing size, C is a one bit 106 // value, and two values are produced: the sum and a carry out. 107 ADDC, SUBB, 108 109 // Conversion operators. These are all single input single output 110 // operations. For all of these, the result type must be strictly 111 // wider or narrower (depending on the operation) than the source 112 // type. 113 114 // SIGN_EXTEND - Used for integer types, replicating the sign bit 115 // into new bits. 116 SIGN_EXTEND, 117 118 // ZERO_EXTEND - Used for integer types, zeroing the new bits. 119 ZERO_EXTEND, 120 121 // TRUNCATE - Completely drop the high bits. 122 TRUNCATE, 123 124 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign 125 // depends on the first letter) to floating point. 126 SINT_TO_FP, 127 UINT_TO_FP, 128 129 // SIGN_EXTEND_INREG/ZERO_EXTEND_INREG - These operators atomically performs 130 // a SHL/(SRA|SHL) pair to (sign|zero) extend a small value in a large 131 // integer register (e.g. sign extending the low 8 bits of a 32-bit register 132 // to fill the top 24 bits with the 7th bit). The size of the smaller type 133 // is indicated by the ExtraValueType in the MVTSDNode for the operator. 134 SIGN_EXTEND_INREG, 135 ZERO_EXTEND_INREG, 136 137 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned 138 // integer. 139 FP_TO_SINT, 140 FP_TO_UINT, 141 142 // FP_ROUND - Perform a rounding operation from the current 143 // precision down to the specified precision (currently always 64->32). 144 FP_ROUND, 145 146 // FP_ROUND_INREG - This operator takes a floating point register, and 147 // rounds it to a floating point value. It then promotes it and returns it 148 // in a register of the same size. This operation effectively just discards 149 // excess precision. The type to round down to is specified by the 150 // ExtraValueType in the MVTSDNode (currently always 64->32->64). 151 FP_ROUND_INREG, 152 153 // FP_EXTEND - Extend a smaller FP type into a larger FP type. 154 FP_EXTEND, 155 156 // Other operators. LOAD and STORE have token chains as their first 157 // operand, then the same operands as an LLVM load/store instruction. 158 LOAD, STORE, 159 160 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators are instances of the 161 // MVTSDNode. All of these load a value from memory and extend them to a 162 // larger value (e.g. load a byte into a word register). All three of these 163 // have two operands, a chain and a pointer to load from. The extra value 164 // type is the source type being loaded. 165 // 166 // SEXTLOAD loads the integer operand and sign extends it to a larger 167 // integer result type. 168 // ZEXTLOAD loads the integer operand and zero extends it to a larger 169 // integer result type. 170 // EXTLOAD is used for two things: floating point extending loads, and 171 // integer extending loads where it doesn't matter what the high 172 // bits are set to. The code generator is allowed to codegen this 173 // into whichever operation is more efficient. 174 EXTLOAD, SEXTLOAD, ZEXTLOAD, 175 176 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a 177 // value and stores it to memory in one operation. This can be used for 178 // either integer or floating point operands, and the stored type 179 // represented as the 'extra' value type in the MVTSDNode representing the 180 // operator. This node has the same three operands as a standard store. 181 TRUNCSTORE, 182 183 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned 184 // to a specified boundary. The first operand is the token chain, the 185 // second is the number of bytes to allocate, and the third is the alignment 186 // boundary. 187 DYNAMIC_STACKALLOC, 188 189 // Control flow instructions. These all have token chains. 190 191 // BR - Unconditional branch. The first operand is the chain 192 // operand, the second is the MBB to branch to. 193 BR, 194 195 // BRCOND - Conditional branch. The first operand is the chain, 196 // the second is the condition, the third is the block to branch 197 // to if the condition is true. 198 BRCOND, 199 200 // RET - Return from function. The first operand is the chain, 201 // and any subsequent operands are the return values for the 202 // function. This operation can have variable number of operands. 203 RET, 204 205 // CALL - Call to a function pointer. The first operand is the chain, the 206 // second is the destination function pointer (a GlobalAddress for a direct 207 // call). Arguments have already been lowered to explicit DAGs according to 208 // the calling convention in effect here. 209 CALL, 210 211 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest 212 // correspond to the operands of the LLVM intrinsic functions. The only 213 // result is a token chain. The alignment argument is guaranteed to be a 214 // Constant node. 215 MEMSET, 216 MEMMOVE, 217 MEMCPY, 218 219 // ADJCALLSTACKDOWN/ADJCALLSTACKUP - These operators mark the beginning and 220 // end of a call sequence and indicate how much the stack pointer needs to 221 // be adjusted for that particular call. The first operand is a chain, the 222 // second is a ConstantSDNode of intptr type. 223 ADJCALLSTACKDOWN, // Beginning of a call sequence 224 ADJCALLSTACKUP, // End of a call sequence 225 226 227 // BUILTIN_OP_END - This must be the last enum value in this list. 228 BUILTIN_OP_END, 229 }; 230 231 //===--------------------------------------------------------------------===// 232 /// ISD::CondCode enum - These are ordered carefully to make the bitfields 233 /// below work out, when considering SETFALSE (something that never exists 234 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered 235 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal 236 /// to. If the "N" column is 1, the result of the comparison is undefined if 237 /// the input is a NAN. 238 /// 239 /// All of these (except for the 'always folded ops') should be handled for 240 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT, 241 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used. 242 /// 243 /// Note that these are laid out in a specific order to allow bit-twiddling 244 /// to transform conditions. 245 enum CondCode { 246 // Opcode N U L G E Intuitive operation 247 SETFALSE, // 0 0 0 0 Always false (always folded) 248 SETOEQ, // 0 0 0 1 True if ordered and equal 249 SETOGT, // 0 0 1 0 True if ordered and greater than 250 SETOGE, // 0 0 1 1 True if ordered and greater than or equal 251 SETOLT, // 0 1 0 0 True if ordered and less than 252 SETOLE, // 0 1 0 1 True if ordered and less than or equal 253 SETONE, // 0 1 1 0 True if ordered and operands are unequal 254 SETO, // 0 1 1 1 True if ordered (no nans) 255 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y) 256 SETUEQ, // 1 0 0 1 True if unordered or equal 257 SETUGT, // 1 0 1 0 True if unordered or greater than 258 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal 259 SETULT, // 1 1 0 0 True if unordered or less than 260 SETULE, // 1 1 0 1 True if unordered, less than, or equal 261 SETUNE, // 1 1 1 0 True if unordered or not equal 262 SETTRUE, // 1 1 1 1 Always true (always folded) 263 // Don't care operations: undefined if the input is a nan. 264 SETFALSE2, // 1 X 0 0 0 Always false (always folded) 265 SETEQ, // 1 X 0 0 1 True if equal 266 SETGT, // 1 X 0 1 0 True if greater than 267 SETGE, // 1 X 0 1 1 True if greater than or equal 268 SETLT, // 1 X 1 0 0 True if less than 269 SETLE, // 1 X 1 0 1 True if less than or equal 270 SETNE, // 1 X 1 1 0 True if not equal 271 SETTRUE2, // 1 X 1 1 1 Always true (always folded) 272 273 SETCC_INVALID, // Marker value. 274 }; 275 276 /// isSignedIntSetCC - Return true if this is a setcc instruction that 277 /// performs a signed comparison when used with integer operands. 278 inline bool isSignedIntSetCC(CondCode Code) { 279 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE; 280 } 281 282 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that 283 /// performs an unsigned comparison when used with integer operands. 284 inline bool isUnsignedIntSetCC(CondCode Code) { 285 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE; 286 } 287 288 /// isTrueWhenEqual - Return true if the specified condition returns true if 289 /// the two operands to the condition are equal. Note that if one of the two 290 /// operands is a NaN, this value is meaningless. 291 inline bool isTrueWhenEqual(CondCode Cond) { 292 return ((int)Cond & 1) != 0; 293 } 294 295 /// getUnorderedFlavor - This function returns 0 if the condition is always 296 /// false if an operand is a NaN, 1 if the condition is always true if the 297 /// operand is a NaN, and 2 if the condition is undefined if the operand is a 298 /// NaN. 299 inline unsigned getUnorderedFlavor(CondCode Cond) { 300 return ((int)Cond >> 3) & 3; 301 } 302 303 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where 304 /// 'op' is a valid SetCC operation. 305 CondCode getSetCCInverse(CondCode Operation, bool isInteger); 306 307 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) 308 /// when given the operation for (X op Y). 309 CondCode getSetCCSwappedOperands(CondCode Operation); 310 311 /// getSetCCOrOperation - Return the result of a logical OR between different 312 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This 313 /// function returns SETCC_INVALID if it is not possible to represent the 314 /// resultant comparison. 315 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger); 316 317 /// getSetCCAndOperation - Return the result of a logical AND between 318 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This 319 /// function returns SETCC_INVALID if it is not possible to represent the 320 /// resultant comparison. 321 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); 322} // end llvm::ISD namespace 323 324 325//===----------------------------------------------------------------------===// 326/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple 327/// values as the result of a computation. Many nodes return multiple values, 328/// from loads (which define a token and a return value) to ADDC (which returns 329/// a result and a carry value), to calls (which may return an arbitrary number 330/// of values). 331/// 332/// As such, each use of a SelectionDAG computation must indicate the node that 333/// computes it as well as which return value to use from that node. This pair 334/// of information is represented with the SDOperand value type. 335/// 336class SDOperand { 337public: 338 SDNode *Val; // The node defining the value we are using. 339 unsigned ResNo; // Which return value of the node we are using. 340 341 SDOperand() : Val(0) {} 342 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} 343 344 bool operator==(const SDOperand &O) const { 345 return Val == O.Val && ResNo == O.ResNo; 346 } 347 bool operator!=(const SDOperand &O) const { 348 return !operator==(O); 349 } 350 bool operator<(const SDOperand &O) const { 351 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); 352 } 353 354 SDOperand getValue(unsigned R) const { 355 return SDOperand(Val, R); 356 } 357 358 /// getValueType - Return the ValueType of the referenced return value. 359 /// 360 inline MVT::ValueType getValueType() const; 361 362 // Forwarding methods - These forward to the corresponding methods in SDNode. 363 inline unsigned getOpcode() const; 364 inline unsigned getNumOperands() const; 365 inline const SDOperand &getOperand(unsigned i) const; 366 367 /// hasOneUse - Return true if there is exactly one operation using this 368 /// result value of the defining operator. 369 inline bool hasOneUse() const; 370}; 371 372 373/// simplify_type specializations - Allow casting operators to work directly on 374/// SDOperands as if they were SDNode*'s. 375template<> struct simplify_type<SDOperand> { 376 typedef SDNode* SimpleType; 377 static SimpleType getSimplifiedValue(const SDOperand &Val) { 378 return static_cast<SimpleType>(Val.Val); 379 } 380}; 381template<> struct simplify_type<const SDOperand> { 382 typedef SDNode* SimpleType; 383 static SimpleType getSimplifiedValue(const SDOperand &Val) { 384 return static_cast<SimpleType>(Val.Val); 385 } 386}; 387 388 389/// SDNode - Represents one node in the SelectionDAG. 390/// 391class SDNode { 392 unsigned NodeType; 393 std::vector<SDOperand> Operands; 394 395 /// Values - The types of the values this node defines. SDNode's may define 396 /// multiple values simultaneously. 397 std::vector<MVT::ValueType> Values; 398 399 /// Uses - These are all of the SDNode's that use a value produced by this 400 /// node. 401 std::vector<SDNode*> Uses; 402public: 403 404 //===--------------------------------------------------------------------===// 405 // Accessors 406 // 407 unsigned getOpcode() const { return NodeType; } 408 409 size_t use_size() const { return Uses.size(); } 410 bool use_empty() const { return Uses.empty(); } 411 bool hasOneUse() const { return Uses.size() == 1; } 412 413 typedef std::vector<SDNode*>::const_iterator use_iterator; 414 use_iterator use_begin() const { return Uses.begin(); } 415 use_iterator use_end() const { return Uses.end(); } 416 417 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the 418 /// indicated value. This method ignores uses of other values defined by this 419 /// operation. 420 bool hasNUsesOfValue(unsigned NUses, unsigned Value); 421 422 /// getNumOperands - Return the number of values used by this operation. 423 /// 424 unsigned getNumOperands() const { return Operands.size(); } 425 426 const SDOperand &getOperand(unsigned Num) { 427 assert(Num < Operands.size() && "Invalid child # of SDNode!"); 428 return Operands[Num]; 429 } 430 431 const SDOperand &getOperand(unsigned Num) const { 432 assert(Num < Operands.size() && "Invalid child # of SDNode!"); 433 return Operands[Num]; 434 } 435 436 /// getNumValues - Return the number of values defined/returned by this 437 /// operator. 438 /// 439 unsigned getNumValues() const { return Values.size(); } 440 441 /// getValueType - Return the type of a specified result. 442 /// 443 MVT::ValueType getValueType(unsigned ResNo) const { 444 assert(ResNo < Values.size() && "Illegal result number!"); 445 return Values[ResNo]; 446 } 447 448 /// getOperationName - Return the opcode of this operation for printing. 449 /// 450 const char* getOperationName() const; 451 void dump() const; 452 453 static bool classof(const SDNode *) { return true; } 454 455protected: 456 friend class SelectionDAG; 457 458 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT) { 459 Values.reserve(1); 460 Values.push_back(VT); 461 } 462 463 SDNode(unsigned NT, SDOperand Op) 464 : NodeType(NT) { 465 Operands.reserve(1); Operands.push_back(Op); 466 Op.Val->Uses.push_back(this); 467 } 468 SDNode(unsigned NT, SDOperand N1, SDOperand N2) 469 : NodeType(NT) { 470 Operands.reserve(2); Operands.push_back(N1); Operands.push_back(N2); 471 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); 472 } 473 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3) 474 : NodeType(NT) { 475 Operands.reserve(3); Operands.push_back(N1); Operands.push_back(N2); 476 Operands.push_back(N3); 477 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); 478 N3.Val->Uses.push_back(this); 479 } 480 SDNode(unsigned NT, std::vector<SDOperand> &Nodes) : NodeType(NT) { 481 Operands.swap(Nodes); 482 for (unsigned i = 0, e = Operands.size(); i != e; ++i) 483 Operands[i].Val->Uses.push_back(this); 484 } 485 486 virtual ~SDNode() { 487 // FIXME: Drop uses. 488 } 489 490 void setValueTypes(MVT::ValueType VT) { 491 Values.reserve(1); 492 Values.push_back(VT); 493 } 494 void setValueTypes(MVT::ValueType VT1, MVT::ValueType VT2) { 495 Values.reserve(2); 496 Values.push_back(VT1); 497 Values.push_back(VT2); 498 } 499 /// Note: this method destroys the vector passed in. 500 void setValueTypes(std::vector<MVT::ValueType> &VTs) { 501 std::swap(Values, VTs); 502 } 503 504 void removeUser(SDNode *User) { 505 // Remove this user from the operand's use list. 506 for (unsigned i = Uses.size(); ; --i) { 507 assert(i != 0 && "Didn't find user!"); 508 if (Uses[i-1] == User) { 509 Uses.erase(Uses.begin()+i-1); 510 break; 511 } 512 } 513 } 514}; 515 516 517// Define inline functions from the SDOperand class. 518 519inline unsigned SDOperand::getOpcode() const { 520 return Val->getOpcode(); 521} 522inline MVT::ValueType SDOperand::getValueType() const { 523 return Val->getValueType(ResNo); 524} 525inline unsigned SDOperand::getNumOperands() const { 526 return Val->getNumOperands(); 527} 528inline const SDOperand &SDOperand::getOperand(unsigned i) const { 529 return Val->getOperand(i); 530} 531inline bool SDOperand::hasOneUse() const { 532 return Val->hasNUsesOfValue(1, ResNo); 533} 534 535 536class ConstantSDNode : public SDNode { 537 uint64_t Value; 538protected: 539 friend class SelectionDAG; 540 ConstantSDNode(uint64_t val, MVT::ValueType VT) 541 : SDNode(ISD::Constant, VT), Value(val) { 542 } 543public: 544 545 uint64_t getValue() const { return Value; } 546 547 int64_t getSignExtended() const { 548 unsigned Bits = MVT::getSizeInBits(getValueType(0)); 549 return ((int64_t)Value << (64-Bits)) >> (64-Bits); 550 } 551 552 bool isNullValue() const { return Value == 0; } 553 bool isAllOnesValue() const { 554 return Value == (1ULL << MVT::getSizeInBits(getValueType(0)))-1; 555 } 556 557 static bool classof(const ConstantSDNode *) { return true; } 558 static bool classof(const SDNode *N) { 559 return N->getOpcode() == ISD::Constant; 560 } 561}; 562 563class ConstantFPSDNode : public SDNode { 564 double Value; 565protected: 566 friend class SelectionDAG; 567 ConstantFPSDNode(double val, MVT::ValueType VT) 568 : SDNode(ISD::ConstantFP, VT), Value(val) { 569 } 570public: 571 572 double getValue() const { return Value; } 573 574 /// isExactlyValue - We don't rely on operator== working on double values, as 575 /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 576 /// As such, this method can be used to do an exact bit-for-bit comparison of 577 /// two floating point values. 578 bool isExactlyValue(double V) const { 579 union { 580 double V; 581 uint64_t I; 582 } T1; 583 T1.V = Value; 584 union { 585 double V; 586 uint64_t I; 587 } T2; 588 T2.V = V; 589 return T1.I == T2.I; 590 } 591 592 static bool classof(const ConstantFPSDNode *) { return true; } 593 static bool classof(const SDNode *N) { 594 return N->getOpcode() == ISD::ConstantFP; 595 } 596}; 597 598class GlobalAddressSDNode : public SDNode { 599 GlobalValue *TheGlobal; 600protected: 601 friend class SelectionDAG; 602 GlobalAddressSDNode(const GlobalValue *GA, MVT::ValueType VT) 603 : SDNode(ISD::GlobalAddress, VT) { 604 TheGlobal = const_cast<GlobalValue*>(GA); 605 } 606public: 607 608 GlobalValue *getGlobal() const { return TheGlobal; } 609 610 static bool classof(const GlobalAddressSDNode *) { return true; } 611 static bool classof(const SDNode *N) { 612 return N->getOpcode() == ISD::GlobalAddress; 613 } 614}; 615 616 617class FrameIndexSDNode : public SDNode { 618 int FI; 619protected: 620 friend class SelectionDAG; 621 FrameIndexSDNode(int fi, MVT::ValueType VT) 622 : SDNode(ISD::FrameIndex, VT), FI(fi) {} 623public: 624 625 int getIndex() const { return FI; } 626 627 static bool classof(const FrameIndexSDNode *) { return true; } 628 static bool classof(const SDNode *N) { 629 return N->getOpcode() == ISD::FrameIndex; 630 } 631}; 632 633class ConstantPoolSDNode : public SDNode { 634 unsigned CPI; 635protected: 636 friend class SelectionDAG; 637 ConstantPoolSDNode(unsigned cpi, MVT::ValueType VT) 638 : SDNode(ISD::ConstantPool, VT), CPI(cpi) {} 639public: 640 641 unsigned getIndex() const { return CPI; } 642 643 static bool classof(const ConstantPoolSDNode *) { return true; } 644 static bool classof(const SDNode *N) { 645 return N->getOpcode() == ISD::ConstantPool; 646 } 647}; 648 649class BasicBlockSDNode : public SDNode { 650 MachineBasicBlock *MBB; 651protected: 652 friend class SelectionDAG; 653 BasicBlockSDNode(MachineBasicBlock *mbb) 654 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {} 655public: 656 657 MachineBasicBlock *getBasicBlock() const { return MBB; } 658 659 static bool classof(const BasicBlockSDNode *) { return true; } 660 static bool classof(const SDNode *N) { 661 return N->getOpcode() == ISD::BasicBlock; 662 } 663}; 664 665 666class RegSDNode : public SDNode { 667 unsigned Reg; 668protected: 669 friend class SelectionDAG; 670 RegSDNode(unsigned Opc, SDOperand Chain, SDOperand Src, unsigned reg) 671 : SDNode(Opc, Chain, Src), Reg(reg) { 672 } 673 RegSDNode(unsigned Opc, SDOperand Chain, unsigned reg) 674 : SDNode(Opc, Chain), Reg(reg) {} 675public: 676 677 unsigned getReg() const { return Reg; } 678 679 static bool classof(const RegSDNode *) { return true; } 680 static bool classof(const SDNode *N) { 681 return N->getOpcode() == ISD::CopyToReg || 682 N->getOpcode() == ISD::CopyFromReg || 683 N->getOpcode() == ISD::ImplicitDef; 684 } 685}; 686 687class ExternalSymbolSDNode : public SDNode { 688 const char *Symbol; 689protected: 690 friend class SelectionDAG; 691 ExternalSymbolSDNode(const char *Sym, MVT::ValueType VT) 692 : SDNode(ISD::ExternalSymbol, VT), Symbol(Sym) { 693 } 694public: 695 696 const char *getSymbol() const { return Symbol; } 697 698 static bool classof(const ExternalSymbolSDNode *) { return true; } 699 static bool classof(const SDNode *N) { 700 return N->getOpcode() == ISD::ExternalSymbol; 701 } 702}; 703 704class SetCCSDNode : public SDNode { 705 ISD::CondCode Condition; 706protected: 707 friend class SelectionDAG; 708 SetCCSDNode(ISD::CondCode Cond, SDOperand LHS, SDOperand RHS) 709 : SDNode(ISD::SETCC, LHS, RHS), Condition(Cond) { 710 setValueTypes(MVT::i1); 711 } 712public: 713 714 ISD::CondCode getCondition() const { return Condition; } 715 716 static bool classof(const SetCCSDNode *) { return true; } 717 static bool classof(const SDNode *N) { 718 return N->getOpcode() == ISD::SETCC; 719 } 720}; 721 722/// MVTSDNode - This class is used for operators that require an extra 723/// value-type to be kept with the node. 724class MVTSDNode : public SDNode { 725 MVT::ValueType ExtraValueType; 726protected: 727 friend class SelectionDAG; 728 MVTSDNode(unsigned Opc, MVT::ValueType VT1, SDOperand Op0, MVT::ValueType EVT) 729 : SDNode(Opc, Op0), ExtraValueType(EVT) { 730 setValueTypes(VT1); 731 } 732 MVTSDNode(unsigned Opc, MVT::ValueType VT1, MVT::ValueType VT2, 733 SDOperand Op0, SDOperand Op1, MVT::ValueType EVT) 734 : SDNode(Opc, Op0, Op1), ExtraValueType(EVT) { 735 setValueTypes(VT1, VT2); 736 } 737 MVTSDNode(unsigned Opc, MVT::ValueType VT, 738 SDOperand Op0, SDOperand Op1, SDOperand Op2, MVT::ValueType EVT) 739 : SDNode(Opc, Op0, Op1, Op2), ExtraValueType(EVT) { 740 setValueTypes(VT); 741 } 742public: 743 744 MVT::ValueType getExtraValueType() const { return ExtraValueType; } 745 746 static bool classof(const MVTSDNode *) { return true; } 747 static bool classof(const SDNode *N) { 748 return 749 N->getOpcode() == ISD::SIGN_EXTEND_INREG || 750 N->getOpcode() == ISD::ZERO_EXTEND_INREG || 751 N->getOpcode() == ISD::FP_ROUND_INREG || 752 N->getOpcode() == ISD::EXTLOAD || 753 N->getOpcode() == ISD::SEXTLOAD || 754 N->getOpcode() == ISD::ZEXTLOAD || 755 N->getOpcode() == ISD::TRUNCSTORE; 756 } 757}; 758 759class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { 760 SDNode *Node; 761 unsigned Operand; 762 763 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} 764public: 765 bool operator==(const SDNodeIterator& x) const { 766 return Operand == x.Operand; 767 } 768 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } 769 770 const SDNodeIterator &operator=(const SDNodeIterator &I) { 771 assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); 772 Operand = I.Operand; 773 return *this; 774 } 775 776 pointer operator*() const { 777 return Node->getOperand(Operand).Val; 778 } 779 pointer operator->() const { return operator*(); } 780 781 SDNodeIterator& operator++() { // Preincrement 782 ++Operand; 783 return *this; 784 } 785 SDNodeIterator operator++(int) { // Postincrement 786 SDNodeIterator tmp = *this; ++*this; return tmp; 787 } 788 789 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } 790 static SDNodeIterator end (SDNode *N) { 791 return SDNodeIterator(N, N->getNumOperands()); 792 } 793 794 unsigned getOperand() const { return Operand; } 795 const SDNode *getNode() const { return Node; } 796}; 797 798template <> struct GraphTraits<SDNode*> { 799 typedef SDNode NodeType; 800 typedef SDNodeIterator ChildIteratorType; 801 static inline NodeType *getEntryNode(SDNode *N) { return N; } 802 static inline ChildIteratorType child_begin(NodeType *N) { 803 return SDNodeIterator::begin(N); 804 } 805 static inline ChildIteratorType child_end(NodeType *N) { 806 return SDNodeIterator::end(N); 807 } 808}; 809 810 811 812 813} // end llvm namespace 814 815#endif 816