SelectionDAGNodes.h revision b8973bd8f50d7321635e1e07b81a880a0828d185
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/Value.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; 37template <typename T> struct ilist_traits; 38template<typename NodeTy, typename Traits> class iplist; 39template<typename NodeTy> class ilist_iterator; 40 41/// ISD namespace - This namespace contains an enum which represents all of the 42/// SelectionDAG node types and value types. 43/// 44namespace ISD { 45 //===--------------------------------------------------------------------===// 46 /// ISD::NodeType enum - This enum defines all of the operators valid in a 47 /// SelectionDAG. 48 /// 49 enum NodeType { 50 // EntryToken - This is the marker used to indicate the start of the region. 51 EntryToken, 52 53 // Token factor - This node takes multiple tokens as input and produces a 54 // single token result. This is used to represent the fact that the operand 55 // operators are independent of each other. 56 TokenFactor, 57 58 // AssertSext, AssertZext - These nodes record if a register contains a 59 // value that has already been zero or sign extended from a narrower type. 60 // These nodes take two operands. The first is the node that has already 61 // been extended, and the second is a value type node indicating the width 62 // of the extension 63 AssertSext, AssertZext, 64 65 // Various leaf nodes. 66 Constant, ConstantFP, STRING, 67 GlobalAddress, FrameIndex, ConstantPool, 68 BasicBlock, ExternalSymbol, VALUETYPE, CONDCODE, Register, 69 70 // ConstantVec works like Constant or ConstantFP, except that it is not a 71 // leaf node. All operands are either Constant or ConstantFP nodes. 72 ConstantVec, 73 74 // TargetConstant* - Like Constant*, but the DAG does not do any folding or 75 // simplification of the constant. 76 TargetConstant, 77 TargetConstantFP, 78 TargetConstantVec, 79 80 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or 81 // anything else with this node, and this is valid in the target-specific 82 // dag, turning into a GlobalAddress operand. 83 TargetGlobalAddress, 84 TargetFrameIndex, 85 TargetConstantPool, 86 TargetExternalSymbol, 87 88 // CopyToReg - This node has three operands: a chain, a register number to 89 // set to this value, and a value. 90 CopyToReg, 91 92 // CopyFromReg - This node indicates that the input value is a virtual or 93 // physical register that is defined outside of the scope of this 94 // SelectionDAG. The register is available from the RegSDNode object. 95 CopyFromReg, 96 97 // UNDEF - An undefined node 98 UNDEF, 99 100 // EXTRACT_ELEMENT - This is used to get the first or second (determined by 101 // a Constant, which is required to be operand #1), element of the aggregate 102 // value specified as operand #0. This is only for use before legalization, 103 // for values that will be broken into multiple registers. 104 EXTRACT_ELEMENT, 105 106 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given 107 // two values of the same integer value type, this produces a value twice as 108 // big. Like EXTRACT_ELEMENT, this can only be used before legalization. 109 BUILD_PAIR, 110 111 // MERGE_VALUES - This node takes multiple discrete operands and returns 112 // them all as its individual results. This nodes has exactly the same 113 // number of inputs and outputs, and is only valid before legalization. 114 // This node is useful for some pieces of the code generator that want to 115 // think about a single node with multiple results, not multiple nodes. 116 MERGE_VALUES, 117 118 // Simple integer binary arithmetic operators. 119 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, 120 121 // Simple binary floating point operators. 122 FADD, FSUB, FMUL, FDIV, FREM, 123 124 // Simple abstract vector operators. Unlike the integer and floating point 125 // binary operators, these nodes also take two additional operands: 126 // a constant element count, and a value type node indicating the type of 127 // the elements. The order is op0, op1, count, type. All vector opcodes, 128 // including VLOAD, must currently have count and type as their 3rd and 4th 129 // arguments. 130 VADD, VSUB, VMUL, 131 132 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing 133 // an unsigned/signed value of type i[2*n], then return the top part. 134 MULHU, MULHS, 135 136 // Bitwise operators - logical and, logical or, logical xor, shift left, 137 // shift right algebraic (shift in sign bits), shift right logical (shift in 138 // zeroes), rotate left, rotate right, and byteswap. 139 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP, 140 141 // Counting operators 142 CTTZ, CTLZ, CTPOP, 143 144 // Select 145 SELECT, 146 147 // Select with condition operator - This selects between a true value and 148 // a false value (ops #2 and #3) based on the boolean result of comparing 149 // the lhs and rhs (ops #0 and #1) of a conditional expression with the 150 // condition code in op #4, a CondCodeSDNode. 151 SELECT_CC, 152 153 // SetCC operator - This evaluates to a boolean (i1) true value if the 154 // condition is true. The operands to this are the left and right operands 155 // to compare (ops #0, and #1) and the condition code to compare them with 156 // (op #2) as a CondCodeSDNode. 157 SETCC, 158 159 // ADD_PARTS/SUB_PARTS - These operators take two logical operands which are 160 // broken into a multiple pieces each, and return the resulting pieces of 161 // doing an atomic add/sub operation. This is used to handle add/sub of 162 // expanded types. The operation ordering is: 163 // [Lo,Hi] = op [LoLHS,HiLHS], [LoRHS,HiRHS] 164 ADD_PARTS, SUB_PARTS, 165 166 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded 167 // integer shift operations, just like ADD/SUB_PARTS. The operation 168 // ordering is: 169 // [Lo,Hi] = op [LoLHS,HiLHS], Amt 170 SHL_PARTS, SRA_PARTS, SRL_PARTS, 171 172 // Conversion operators. These are all single input single output 173 // operations. For all of these, the result type must be strictly 174 // wider or narrower (depending on the operation) than the source 175 // type. 176 177 // SIGN_EXTEND - Used for integer types, replicating the sign bit 178 // into new bits. 179 SIGN_EXTEND, 180 181 // ZERO_EXTEND - Used for integer types, zeroing the new bits. 182 ZERO_EXTEND, 183 184 // ANY_EXTEND - Used for integer types. The high bits are undefined. 185 ANY_EXTEND, 186 187 // TRUNCATE - Completely drop the high bits. 188 TRUNCATE, 189 190 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign 191 // depends on the first letter) to floating point. 192 SINT_TO_FP, 193 UINT_TO_FP, 194 195 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to 196 // sign extend a small value in a large integer register (e.g. sign 197 // extending the low 8 bits of a 32-bit register to fill the top 24 bits 198 // with the 7th bit). The size of the smaller type is indicated by the 1th 199 // operand, a ValueType node. 200 SIGN_EXTEND_INREG, 201 202 // FP_TO_[US]INT - Convert a floating point value to a signed or unsigned 203 // integer. 204 FP_TO_SINT, 205 FP_TO_UINT, 206 207 // FP_ROUND - Perform a rounding operation from the current 208 // precision down to the specified precision (currently always 64->32). 209 FP_ROUND, 210 211 // FP_ROUND_INREG - This operator takes a floating point register, and 212 // rounds it to a floating point value. It then promotes it and returns it 213 // in a register of the same size. This operation effectively just discards 214 // excess precision. The type to round down to is specified by the 1th 215 // operation, a VTSDNode (currently always 64->32->64). 216 FP_ROUND_INREG, 217 218 // FP_EXTEND - Extend a smaller FP type into a larger FP type. 219 FP_EXTEND, 220 221 // BIT_CONVERT - Theis operator converts between integer and FP values, as 222 // if one was stored to memory as integer and the other was loaded from the 223 // same address (or equivalently for vector format conversions, etc). The 224 // source and result are required to have the same bit size (e.g. 225 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp 226 // conversions, but that is a noop, deleted by getNode(). 227 BIT_CONVERT, 228 229 // FNEG, FABS, FSQRT, FSIN, FCOS - Perform unary floating point negation, 230 // absolute value, square root, sine and cosine operations. 231 FNEG, FABS, FSQRT, FSIN, FCOS, 232 233 // Other operators. LOAD and STORE have token chains as their first 234 // operand, then the same operands as an LLVM load/store instruction, then a 235 // SRCVALUE node that provides alias analysis information. 236 LOAD, STORE, 237 238 // Abstract vector version of LOAD. VLOAD has a token chain as the first 239 // operand, followed by a pointer operand, a constant element count, a value 240 // type node indicating the type of the elements, and a SRCVALUE node. 241 VLOAD, 242 243 // EXTLOAD, SEXTLOAD, ZEXTLOAD - These three operators all load a value from 244 // memory and extend them to a larger value (e.g. load a byte into a word 245 // register). All three of these have four operands, a token chain, a 246 // pointer to load from, a SRCVALUE for alias analysis, and a VALUETYPE node 247 // indicating the type to load. 248 // 249 // SEXTLOAD loads the integer operand and sign extends it to a larger 250 // integer result type. 251 // ZEXTLOAD loads the integer operand and zero extends it to a larger 252 // integer result type. 253 // EXTLOAD is used for two things: floating point extending loads, and 254 // integer extending loads where it doesn't matter what the high 255 // bits are set to. The code generator is allowed to codegen this 256 // into whichever operation is more efficient. 257 EXTLOAD, SEXTLOAD, ZEXTLOAD, 258 259 // TRUNCSTORE - This operators truncates (for integer) or rounds (for FP) a 260 // value and stores it to memory in one operation. This can be used for 261 // either integer or floating point operands. The first four operands of 262 // this are the same as a standard store. The fifth is the ValueType to 263 // store it as (which will be smaller than the source value). 264 TRUNCSTORE, 265 266 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned 267 // to a specified boundary. The first operand is the token chain, the 268 // second is the number of bytes to allocate, and the third is the alignment 269 // boundary. The size is guaranteed to be a multiple of the stack 270 // alignment, and the alignment is guaranteed to be bigger than the stack 271 // alignment (if required) or 0 to get standard stack alignment. 272 DYNAMIC_STACKALLOC, 273 274 // Control flow instructions. These all have token chains. 275 276 // BR - Unconditional branch. The first operand is the chain 277 // operand, the second is the MBB to branch to. 278 BR, 279 280 // BRCOND - Conditional branch. The first operand is the chain, 281 // the second is the condition, the third is the block to branch 282 // to if the condition is true. 283 BRCOND, 284 285 // BRCONDTWOWAY - Two-way conditional branch. The first operand is the 286 // chain, the second is the condition, the third is the block to branch to 287 // if true, and the forth is the block to branch to if false. Targets 288 // usually do not implement this, preferring to have legalize demote the 289 // operation to BRCOND/BR pairs when necessary. 290 BRCONDTWOWAY, 291 292 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in 293 // that the condition is represented as condition code, and two nodes to 294 // compare, rather than as a combined SetCC node. The operands in order are 295 // chain, cc, lhs, rhs, block to branch to if condition is true. 296 BR_CC, 297 298 // BRTWOWAY_CC - Two-way conditional branch. The operands in order are 299 // chain, cc, lhs, rhs, block to branch to if condition is true, block to 300 // branch to if condition is false. Targets usually do not implement this, 301 // preferring to have legalize demote the operation to BRCOND/BR pairs. 302 BRTWOWAY_CC, 303 304 // RET - Return from function. The first operand is the chain, 305 // and any subsequent operands are the return values for the 306 // function. This operation can have variable number of operands. 307 RET, 308 309 // INLINEASM - Represents an inline asm block. This node always has two 310 // return values: a chain and a flag result. The inputs are as follows: 311 // Operand #0 : Input chain. 312 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string. 313 // Operand #2n+2: A RegisterNode. 314 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def 315 // Operand #last: Optional, an incoming flag. 316 INLINEASM, 317 318 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a 319 // value, the same type as the pointer type for the system, and an output 320 // chain. 321 STACKSAVE, 322 323 // STACKRESTORE has two operands, an input chain and a pointer to restore to 324 // it returns an output chain. 325 STACKRESTORE, 326 327 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain, and the rest 328 // correspond to the operands of the LLVM intrinsic functions. The only 329 // result is a token chain. The alignment argument is guaranteed to be a 330 // Constant node. 331 MEMSET, 332 MEMMOVE, 333 MEMCPY, 334 335 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of 336 // a call sequence, and carry arbitrary information that target might want 337 // to know. The first operand is a chain, the rest are specified by the 338 // target and not touched by the DAG optimizers. 339 CALLSEQ_START, // Beginning of a call sequence 340 CALLSEQ_END, // End of a call sequence 341 342 // VAARG - VAARG has three operands: an input chain, a pointer, and a 343 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain. 344 VAARG, 345 346 // VACOPY - VACOPY has five operands: an input chain, a destination pointer, 347 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the 348 // source. 349 VACOPY, 350 351 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a 352 // pointer, and a SRCVALUE. 353 VAEND, VASTART, 354 355 // SRCVALUE - This corresponds to a Value*, and is used to associate memory 356 // locations with their value. This allows one use alias analysis 357 // information in the backend. 358 SRCVALUE, 359 360 // PCMARKER - This corresponds to the pcmarker intrinsic. 361 PCMARKER, 362 363 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic. 364 // The only operand is a chain and a value and a chain are produced. The 365 // value is the contents of the architecture specific cycle counter like 366 // register (or other high accuracy low latency clock source) 367 READCYCLECOUNTER, 368 369 // READPORT, WRITEPORT, READIO, WRITEIO - These correspond to the LLVM 370 // intrinsics of the same name. The first operand is a token chain, the 371 // other operands match the intrinsic. These produce a token chain in 372 // addition to a value (if any). 373 READPORT, WRITEPORT, READIO, WRITEIO, 374 375 // HANDLENODE node - Used as a handle for various purposes. 376 HANDLENODE, 377 378 // LOCATION - This node is used to represent a source location for debug 379 // info. It takes token chain as input, then a line number, then a column 380 // number, then a filename, then a working dir. It produces a token chain 381 // as output. 382 LOCATION, 383 384 // DEBUG_LOC - This node is used to represent source line information 385 // embedded in the code. It takes a token chain as input, then a line 386 // number, then a column then a file id (provided by MachineDebugInfo.) It 387 // produces a token chain as output. 388 DEBUG_LOC, 389 390 // DEBUG_LABEL - This node is used to mark a location in the code where a 391 // label should be generated for use by the debug information. It takes a 392 // token chain as input and then a unique id (provided by MachineDebugInfo.) 393 // It produces a token chain as output. 394 DEBUG_LABEL, 395 396 // BUILTIN_OP_END - This must be the last enum value in this list. 397 BUILTIN_OP_END, 398 }; 399 400 //===--------------------------------------------------------------------===// 401 /// ISD::CondCode enum - These are ordered carefully to make the bitfields 402 /// below work out, when considering SETFALSE (something that never exists 403 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered 404 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal 405 /// to. If the "N" column is 1, the result of the comparison is undefined if 406 /// the input is a NAN. 407 /// 408 /// All of these (except for the 'always folded ops') should be handled for 409 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT, 410 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used. 411 /// 412 /// Note that these are laid out in a specific order to allow bit-twiddling 413 /// to transform conditions. 414 enum CondCode { 415 // Opcode N U L G E Intuitive operation 416 SETFALSE, // 0 0 0 0 Always false (always folded) 417 SETOEQ, // 0 0 0 1 True if ordered and equal 418 SETOGT, // 0 0 1 0 True if ordered and greater than 419 SETOGE, // 0 0 1 1 True if ordered and greater than or equal 420 SETOLT, // 0 1 0 0 True if ordered and less than 421 SETOLE, // 0 1 0 1 True if ordered and less than or equal 422 SETONE, // 0 1 1 0 True if ordered and operands are unequal 423 SETO, // 0 1 1 1 True if ordered (no nans) 424 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y) 425 SETUEQ, // 1 0 0 1 True if unordered or equal 426 SETUGT, // 1 0 1 0 True if unordered or greater than 427 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal 428 SETULT, // 1 1 0 0 True if unordered or less than 429 SETULE, // 1 1 0 1 True if unordered, less than, or equal 430 SETUNE, // 1 1 1 0 True if unordered or not equal 431 SETTRUE, // 1 1 1 1 Always true (always folded) 432 // Don't care operations: undefined if the input is a nan. 433 SETFALSE2, // 1 X 0 0 0 Always false (always folded) 434 SETEQ, // 1 X 0 0 1 True if equal 435 SETGT, // 1 X 0 1 0 True if greater than 436 SETGE, // 1 X 0 1 1 True if greater than or equal 437 SETLT, // 1 X 1 0 0 True if less than 438 SETLE, // 1 X 1 0 1 True if less than or equal 439 SETNE, // 1 X 1 1 0 True if not equal 440 SETTRUE2, // 1 X 1 1 1 Always true (always folded) 441 442 SETCC_INVALID, // Marker value. 443 }; 444 445 /// isSignedIntSetCC - Return true if this is a setcc instruction that 446 /// performs a signed comparison when used with integer operands. 447 inline bool isSignedIntSetCC(CondCode Code) { 448 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE; 449 } 450 451 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that 452 /// performs an unsigned comparison when used with integer operands. 453 inline bool isUnsignedIntSetCC(CondCode Code) { 454 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE; 455 } 456 457 /// isTrueWhenEqual - Return true if the specified condition returns true if 458 /// the two operands to the condition are equal. Note that if one of the two 459 /// operands is a NaN, this value is meaningless. 460 inline bool isTrueWhenEqual(CondCode Cond) { 461 return ((int)Cond & 1) != 0; 462 } 463 464 /// getUnorderedFlavor - This function returns 0 if the condition is always 465 /// false if an operand is a NaN, 1 if the condition is always true if the 466 /// operand is a NaN, and 2 if the condition is undefined if the operand is a 467 /// NaN. 468 inline unsigned getUnorderedFlavor(CondCode Cond) { 469 return ((int)Cond >> 3) & 3; 470 } 471 472 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where 473 /// 'op' is a valid SetCC operation. 474 CondCode getSetCCInverse(CondCode Operation, bool isInteger); 475 476 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) 477 /// when given the operation for (X op Y). 478 CondCode getSetCCSwappedOperands(CondCode Operation); 479 480 /// getSetCCOrOperation - Return the result of a logical OR between different 481 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This 482 /// function returns SETCC_INVALID if it is not possible to represent the 483 /// resultant comparison. 484 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger); 485 486 /// getSetCCAndOperation - Return the result of a logical AND between 487 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This 488 /// function returns SETCC_INVALID if it is not possible to represent the 489 /// resultant comparison. 490 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); 491} // end llvm::ISD namespace 492 493 494//===----------------------------------------------------------------------===// 495/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple 496/// values as the result of a computation. Many nodes return multiple values, 497/// from loads (which define a token and a return value) to ADDC (which returns 498/// a result and a carry value), to calls (which may return an arbitrary number 499/// of values). 500/// 501/// As such, each use of a SelectionDAG computation must indicate the node that 502/// computes it as well as which return value to use from that node. This pair 503/// of information is represented with the SDOperand value type. 504/// 505class SDOperand { 506public: 507 SDNode *Val; // The node defining the value we are using. 508 unsigned ResNo; // Which return value of the node we are using. 509 510 SDOperand() : Val(0) {} 511 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} 512 513 bool operator==(const SDOperand &O) const { 514 return Val == O.Val && ResNo == O.ResNo; 515 } 516 bool operator!=(const SDOperand &O) const { 517 return !operator==(O); 518 } 519 bool operator<(const SDOperand &O) const { 520 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); 521 } 522 523 SDOperand getValue(unsigned R) const { 524 return SDOperand(Val, R); 525 } 526 527 /// getValueType - Return the ValueType of the referenced return value. 528 /// 529 inline MVT::ValueType getValueType() const; 530 531 // Forwarding methods - These forward to the corresponding methods in SDNode. 532 inline unsigned getOpcode() const; 533 inline unsigned getNodeDepth() const; 534 inline unsigned getNumOperands() const; 535 inline const SDOperand &getOperand(unsigned i) const; 536 inline bool isTargetOpcode() const; 537 inline unsigned getTargetOpcode() const; 538 539 /// hasOneUse - Return true if there is exactly one operation using this 540 /// result value of the defining operator. 541 inline bool hasOneUse() const; 542}; 543 544 545/// simplify_type specializations - Allow casting operators to work directly on 546/// SDOperands as if they were SDNode*'s. 547template<> struct simplify_type<SDOperand> { 548 typedef SDNode* SimpleType; 549 static SimpleType getSimplifiedValue(const SDOperand &Val) { 550 return static_cast<SimpleType>(Val.Val); 551 } 552}; 553template<> struct simplify_type<const SDOperand> { 554 typedef SDNode* SimpleType; 555 static SimpleType getSimplifiedValue(const SDOperand &Val) { 556 return static_cast<SimpleType>(Val.Val); 557 } 558}; 559 560 561/// SDNode - Represents one node in the SelectionDAG. 562/// 563class SDNode { 564 /// NodeType - The operation that this node performs. 565 /// 566 unsigned short NodeType; 567 568 /// NodeDepth - Node depth is defined as MAX(Node depth of children)+1. This 569 /// means that leaves have a depth of 1, things that use only leaves have a 570 /// depth of 2, etc. 571 unsigned short NodeDepth; 572 573 /// OperandList - The values that are used by this operation. 574 /// 575 SDOperand *OperandList; 576 577 /// ValueList - The types of the values this node defines. SDNode's may 578 /// define multiple values simultaneously. 579 MVT::ValueType *ValueList; 580 581 /// NumOperands/NumValues - The number of entries in the Operand/Value list. 582 unsigned short NumOperands, NumValues; 583 584 /// Prev/Next pointers - These pointers form the linked list of of the 585 /// AllNodes list in the current DAG. 586 SDNode *Prev, *Next; 587 friend struct ilist_traits<SDNode>; 588 589 /// Uses - These are all of the SDNode's that use a value produced by this 590 /// node. 591 std::vector<SDNode*> Uses; 592public: 593 virtual ~SDNode() { 594 assert(NumOperands == 0 && "Operand list not cleared before deletion"); 595 } 596 597 //===--------------------------------------------------------------------===// 598 // Accessors 599 // 600 unsigned getOpcode() const { return NodeType; } 601 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; } 602 unsigned getTargetOpcode() const { 603 assert(isTargetOpcode() && "Not a target opcode!"); 604 return NodeType - ISD::BUILTIN_OP_END; 605 } 606 607 size_t use_size() const { return Uses.size(); } 608 bool use_empty() const { return Uses.empty(); } 609 bool hasOneUse() const { return Uses.size() == 1; } 610 611 /// getNodeDepth - Return the distance from this node to the leaves in the 612 /// graph. The leaves have a depth of 1. 613 unsigned getNodeDepth() const { return NodeDepth; } 614 615 typedef std::vector<SDNode*>::const_iterator use_iterator; 616 use_iterator use_begin() const { return Uses.begin(); } 617 use_iterator use_end() const { return Uses.end(); } 618 619 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the 620 /// indicated value. This method ignores uses of other values defined by this 621 /// operation. 622 bool hasNUsesOfValue(unsigned NUses, unsigned Value); 623 624 /// getNumOperands - Return the number of values used by this operation. 625 /// 626 unsigned getNumOperands() const { return NumOperands; } 627 628 const SDOperand &getOperand(unsigned Num) const { 629 assert(Num < NumOperands && "Invalid child # of SDNode!"); 630 return OperandList[Num]; 631 } 632 typedef const SDOperand* op_iterator; 633 op_iterator op_begin() const { return OperandList; } 634 op_iterator op_end() const { return OperandList+NumOperands; } 635 636 637 /// getNumValues - Return the number of values defined/returned by this 638 /// operator. 639 /// 640 unsigned getNumValues() const { return NumValues; } 641 642 /// getValueType - Return the type of a specified result. 643 /// 644 MVT::ValueType getValueType(unsigned ResNo) const { 645 assert(ResNo < NumValues && "Illegal result number!"); 646 return ValueList[ResNo]; 647 } 648 649 typedef const MVT::ValueType* value_iterator; 650 value_iterator value_begin() const { return ValueList; } 651 value_iterator value_end() const { return ValueList+NumValues; } 652 653 /// getOperationName - Return the opcode of this operation for printing. 654 /// 655 const char* getOperationName(const SelectionDAG *G = 0) const; 656 void dump() const; 657 void dump(const SelectionDAG *G) const; 658 659 static bool classof(const SDNode *) { return true; } 660 661protected: 662 friend class SelectionDAG; 663 664 /// getValueTypeList - Return a pointer to the specified value type. 665 /// 666 static MVT::ValueType *getValueTypeList(MVT::ValueType VT); 667 668 SDNode(unsigned NT, MVT::ValueType VT) : NodeType(NT), NodeDepth(1) { 669 OperandList = 0; NumOperands = 0; 670 ValueList = getValueTypeList(VT); 671 NumValues = 1; 672 Prev = 0; Next = 0; 673 } 674 SDNode(unsigned NT, SDOperand Op) 675 : NodeType(NT), NodeDepth(Op.Val->getNodeDepth()+1) { 676 OperandList = new SDOperand[1]; 677 OperandList[0] = Op; 678 NumOperands = 1; 679 Op.Val->Uses.push_back(this); 680 ValueList = 0; 681 NumValues = 0; 682 Prev = 0; Next = 0; 683 } 684 SDNode(unsigned NT, SDOperand N1, SDOperand N2) 685 : NodeType(NT) { 686 if (N1.Val->getNodeDepth() > N2.Val->getNodeDepth()) 687 NodeDepth = N1.Val->getNodeDepth()+1; 688 else 689 NodeDepth = N2.Val->getNodeDepth()+1; 690 OperandList = new SDOperand[2]; 691 OperandList[0] = N1; 692 OperandList[1] = N2; 693 NumOperands = 2; 694 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); 695 ValueList = 0; 696 NumValues = 0; 697 Prev = 0; Next = 0; 698 } 699 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3) 700 : NodeType(NT) { 701 unsigned ND = N1.Val->getNodeDepth(); 702 if (ND < N2.Val->getNodeDepth()) 703 ND = N2.Val->getNodeDepth(); 704 if (ND < N3.Val->getNodeDepth()) 705 ND = N3.Val->getNodeDepth(); 706 NodeDepth = ND+1; 707 708 OperandList = new SDOperand[3]; 709 OperandList[0] = N1; 710 OperandList[1] = N2; 711 OperandList[2] = N3; 712 NumOperands = 3; 713 714 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); 715 N3.Val->Uses.push_back(this); 716 ValueList = 0; 717 NumValues = 0; 718 Prev = 0; Next = 0; 719 } 720 SDNode(unsigned NT, SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4) 721 : NodeType(NT) { 722 unsigned ND = N1.Val->getNodeDepth(); 723 if (ND < N2.Val->getNodeDepth()) 724 ND = N2.Val->getNodeDepth(); 725 if (ND < N3.Val->getNodeDepth()) 726 ND = N3.Val->getNodeDepth(); 727 if (ND < N4.Val->getNodeDepth()) 728 ND = N4.Val->getNodeDepth(); 729 NodeDepth = ND+1; 730 731 OperandList = new SDOperand[4]; 732 OperandList[0] = N1; 733 OperandList[1] = N2; 734 OperandList[2] = N3; 735 OperandList[3] = N4; 736 NumOperands = 4; 737 738 N1.Val->Uses.push_back(this); N2.Val->Uses.push_back(this); 739 N3.Val->Uses.push_back(this); N4.Val->Uses.push_back(this); 740 ValueList = 0; 741 NumValues = 0; 742 Prev = 0; Next = 0; 743 } 744 SDNode(unsigned Opc, const std::vector<SDOperand> &Nodes) : NodeType(Opc) { 745 NumOperands = Nodes.size(); 746 OperandList = new SDOperand[NumOperands]; 747 748 unsigned ND = 0; 749 for (unsigned i = 0, e = Nodes.size(); i != e; ++i) { 750 OperandList[i] = Nodes[i]; 751 SDNode *N = OperandList[i].Val; 752 N->Uses.push_back(this); 753 if (ND < N->getNodeDepth()) ND = N->getNodeDepth(); 754 } 755 NodeDepth = ND+1; 756 ValueList = 0; 757 NumValues = 0; 758 Prev = 0; Next = 0; 759 } 760 761 /// MorphNodeTo - This clears the return value and operands list, and sets the 762 /// opcode of the node to the specified value. This should only be used by 763 /// the SelectionDAG class. 764 void MorphNodeTo(unsigned Opc) { 765 NodeType = Opc; 766 ValueList = 0; 767 NumValues = 0; 768 769 // Clear the operands list, updating used nodes to remove this from their 770 // use list. 771 for (op_iterator I = op_begin(), E = op_end(); I != E; ++I) 772 I->Val->removeUser(this); 773 delete [] OperandList; 774 OperandList = 0; 775 NumOperands = 0; 776 } 777 778 void setValueTypes(MVT::ValueType VT) { 779 assert(NumValues == 0 && "Should not have values yet!"); 780 ValueList = getValueTypeList(VT); 781 NumValues = 1; 782 } 783 void setValueTypes(MVT::ValueType *List, unsigned NumVal) { 784 assert(NumValues == 0 && "Should not have values yet!"); 785 ValueList = List; 786 NumValues = NumVal; 787 } 788 789 void setOperands(SDOperand Op0) { 790 assert(NumOperands == 0 && "Should not have operands yet!"); 791 OperandList = new SDOperand[1]; 792 OperandList[0] = Op0; 793 NumOperands = 1; 794 Op0.Val->Uses.push_back(this); 795 } 796 void setOperands(SDOperand Op0, SDOperand Op1) { 797 assert(NumOperands == 0 && "Should not have operands yet!"); 798 OperandList = new SDOperand[2]; 799 OperandList[0] = Op0; 800 OperandList[1] = Op1; 801 NumOperands = 2; 802 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 803 } 804 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2) { 805 assert(NumOperands == 0 && "Should not have operands yet!"); 806 OperandList = new SDOperand[3]; 807 OperandList[0] = Op0; 808 OperandList[1] = Op1; 809 OperandList[2] = Op2; 810 NumOperands = 3; 811 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 812 Op2.Val->Uses.push_back(this); 813 } 814 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3) { 815 assert(NumOperands == 0 && "Should not have operands yet!"); 816 OperandList = new SDOperand[4]; 817 OperandList[0] = Op0; 818 OperandList[1] = Op1; 819 OperandList[2] = Op2; 820 OperandList[3] = Op3; 821 NumOperands = 4; 822 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 823 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); 824 } 825 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, 826 SDOperand Op4) { 827 assert(NumOperands == 0 && "Should not have operands yet!"); 828 OperandList = new SDOperand[5]; 829 OperandList[0] = Op0; 830 OperandList[1] = Op1; 831 OperandList[2] = Op2; 832 OperandList[3] = Op3; 833 OperandList[4] = Op4; 834 NumOperands = 5; 835 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 836 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); 837 Op4.Val->Uses.push_back(this); 838 } 839 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, 840 SDOperand Op4, SDOperand Op5) { 841 assert(NumOperands == 0 && "Should not have operands yet!"); 842 OperandList = new SDOperand[6]; 843 OperandList[0] = Op0; 844 OperandList[1] = Op1; 845 OperandList[2] = Op2; 846 OperandList[3] = Op3; 847 OperandList[4] = Op4; 848 OperandList[5] = Op5; 849 NumOperands = 6; 850 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 851 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); 852 Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this); 853 } 854 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, 855 SDOperand Op4, SDOperand Op5, SDOperand Op6) { 856 assert(NumOperands == 0 && "Should not have operands yet!"); 857 OperandList = new SDOperand[7]; 858 OperandList[0] = Op0; 859 OperandList[1] = Op1; 860 OperandList[2] = Op2; 861 OperandList[3] = Op3; 862 OperandList[4] = Op4; 863 OperandList[5] = Op5; 864 OperandList[6] = Op6; 865 NumOperands = 7; 866 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 867 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); 868 Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this); 869 Op6.Val->Uses.push_back(this); 870 } 871 void setOperands(SDOperand Op0, SDOperand Op1, SDOperand Op2, SDOperand Op3, 872 SDOperand Op4, SDOperand Op5, SDOperand Op6, SDOperand Op7) { 873 assert(NumOperands == 0 && "Should not have operands yet!"); 874 OperandList = new SDOperand[8]; 875 OperandList[0] = Op0; 876 OperandList[1] = Op1; 877 OperandList[2] = Op2; 878 OperandList[3] = Op3; 879 OperandList[4] = Op4; 880 OperandList[5] = Op5; 881 OperandList[6] = Op6; 882 OperandList[7] = Op7; 883 NumOperands = 8; 884 Op0.Val->Uses.push_back(this); Op1.Val->Uses.push_back(this); 885 Op2.Val->Uses.push_back(this); Op3.Val->Uses.push_back(this); 886 Op4.Val->Uses.push_back(this); Op5.Val->Uses.push_back(this); 887 Op6.Val->Uses.push_back(this); Op7.Val->Uses.push_back(this); 888 } 889 890 void addUser(SDNode *User) { 891 Uses.push_back(User); 892 } 893 void removeUser(SDNode *User) { 894 // Remove this user from the operand's use list. 895 for (unsigned i = Uses.size(); ; --i) { 896 assert(i != 0 && "Didn't find user!"); 897 if (Uses[i-1] == User) { 898 Uses[i-1] = Uses.back(); 899 Uses.pop_back(); 900 return; 901 } 902 } 903 } 904}; 905 906 907// Define inline functions from the SDOperand class. 908 909inline unsigned SDOperand::getOpcode() const { 910 return Val->getOpcode(); 911} 912inline unsigned SDOperand::getNodeDepth() const { 913 return Val->getNodeDepth(); 914} 915inline MVT::ValueType SDOperand::getValueType() const { 916 return Val->getValueType(ResNo); 917} 918inline unsigned SDOperand::getNumOperands() const { 919 return Val->getNumOperands(); 920} 921inline const SDOperand &SDOperand::getOperand(unsigned i) const { 922 return Val->getOperand(i); 923} 924inline bool SDOperand::isTargetOpcode() const { 925 return Val->isTargetOpcode(); 926} 927inline unsigned SDOperand::getTargetOpcode() const { 928 return Val->getTargetOpcode(); 929} 930inline bool SDOperand::hasOneUse() const { 931 return Val->hasNUsesOfValue(1, ResNo); 932} 933 934/// HandleSDNode - This class is used to form a handle around another node that 935/// is persistant and is updated across invocations of replaceAllUsesWith on its 936/// operand. This node should be directly created by end-users and not added to 937/// the AllNodes list. 938class HandleSDNode : public SDNode { 939public: 940 HandleSDNode(SDOperand X) : SDNode(ISD::HANDLENODE, X) {} 941 ~HandleSDNode() { 942 MorphNodeTo(ISD::HANDLENODE); // Drops operand uses. 943 } 944 945 SDOperand getValue() const { return getOperand(0); } 946}; 947 948class StringSDNode : public SDNode { 949 std::string Value; 950protected: 951 friend class SelectionDAG; 952 StringSDNode(const std::string &val) 953 : SDNode(ISD::STRING, MVT::Other), Value(val) { 954 } 955public: 956 const std::string &getValue() const { return Value; } 957 static bool classof(const StringSDNode *) { return true; } 958 static bool classof(const SDNode *N) { 959 return N->getOpcode() == ISD::STRING; 960 } 961}; 962 963class ConstantSDNode : public SDNode { 964 uint64_t Value; 965protected: 966 friend class SelectionDAG; 967 ConstantSDNode(bool isTarget, uint64_t val, MVT::ValueType VT) 968 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, VT), Value(val) { 969 } 970public: 971 972 uint64_t getValue() const { return Value; } 973 974 int64_t getSignExtended() const { 975 unsigned Bits = MVT::getSizeInBits(getValueType(0)); 976 return ((int64_t)Value << (64-Bits)) >> (64-Bits); 977 } 978 979 bool isNullValue() const { return Value == 0; } 980 bool isAllOnesValue() const { 981 int NumBits = MVT::getSizeInBits(getValueType(0)); 982 if (NumBits == 64) return Value+1 == 0; 983 return Value == (1ULL << NumBits)-1; 984 } 985 986 static bool classof(const ConstantSDNode *) { return true; } 987 static bool classof(const SDNode *N) { 988 return N->getOpcode() == ISD::Constant || 989 N->getOpcode() == ISD::TargetConstant; 990 } 991}; 992 993class ConstantFPSDNode : public SDNode { 994 double Value; 995protected: 996 friend class SelectionDAG; 997 ConstantFPSDNode(bool isTarget, double val, MVT::ValueType VT) 998 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, VT), 999 Value(val) { 1000 } 1001public: 1002 1003 double getValue() const { return Value; } 1004 1005 /// isExactlyValue - We don't rely on operator== working on double values, as 1006 /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 1007 /// As such, this method can be used to do an exact bit-for-bit comparison of 1008 /// two floating point values. 1009 bool isExactlyValue(double V) const; 1010 1011 static bool classof(const ConstantFPSDNode *) { return true; } 1012 static bool classof(const SDNode *N) { 1013 return N->getOpcode() == ISD::ConstantFP || 1014 N->getOpcode() == ISD::TargetConstantFP; 1015 } 1016}; 1017 1018class GlobalAddressSDNode : public SDNode { 1019 GlobalValue *TheGlobal; 1020 int offset; 1021protected: 1022 friend class SelectionDAG; 1023 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT, 1024 int o=0) 1025 : SDNode(isTarget ? ISD::TargetGlobalAddress : ISD::GlobalAddress, VT) { 1026 TheGlobal = const_cast<GlobalValue*>(GA); 1027 offset = o; 1028 } 1029public: 1030 1031 GlobalValue *getGlobal() const { return TheGlobal; } 1032 int getOffset() const { return offset; } 1033 1034 static bool classof(const GlobalAddressSDNode *) { return true; } 1035 static bool classof(const SDNode *N) { 1036 return N->getOpcode() == ISD::GlobalAddress || 1037 N->getOpcode() == ISD::TargetGlobalAddress; 1038 } 1039}; 1040 1041 1042class FrameIndexSDNode : public SDNode { 1043 int FI; 1044protected: 1045 friend class SelectionDAG; 1046 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg) 1047 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, VT), FI(fi) {} 1048public: 1049 1050 int getIndex() const { return FI; } 1051 1052 static bool classof(const FrameIndexSDNode *) { return true; } 1053 static bool classof(const SDNode *N) { 1054 return N->getOpcode() == ISD::FrameIndex || 1055 N->getOpcode() == ISD::TargetFrameIndex; 1056 } 1057}; 1058 1059class ConstantPoolSDNode : public SDNode { 1060 Constant *C; 1061 unsigned Alignment; 1062protected: 1063 friend class SelectionDAG; 1064 ConstantPoolSDNode(Constant *c, MVT::ValueType VT, bool isTarget) 1065 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), 1066 C(c), Alignment(0) {} 1067 ConstantPoolSDNode(Constant *c, MVT::ValueType VT, unsigned Align, 1068 bool isTarget) 1069 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, VT), 1070 C(c), Alignment(Align) {} 1071public: 1072 1073 Constant *get() const { return C; } 1074 unsigned getAlignment() const { return Alignment; } 1075 1076 static bool classof(const ConstantPoolSDNode *) { return true; } 1077 static bool classof(const SDNode *N) { 1078 return N->getOpcode() == ISD::ConstantPool || 1079 N->getOpcode() == ISD::TargetConstantPool; 1080 } 1081}; 1082 1083class BasicBlockSDNode : public SDNode { 1084 MachineBasicBlock *MBB; 1085protected: 1086 friend class SelectionDAG; 1087 BasicBlockSDNode(MachineBasicBlock *mbb) 1088 : SDNode(ISD::BasicBlock, MVT::Other), MBB(mbb) {} 1089public: 1090 1091 MachineBasicBlock *getBasicBlock() const { return MBB; } 1092 1093 static bool classof(const BasicBlockSDNode *) { return true; } 1094 static bool classof(const SDNode *N) { 1095 return N->getOpcode() == ISD::BasicBlock; 1096 } 1097}; 1098 1099class SrcValueSDNode : public SDNode { 1100 const Value *V; 1101 int offset; 1102protected: 1103 friend class SelectionDAG; 1104 SrcValueSDNode(const Value* v, int o) 1105 : SDNode(ISD::SRCVALUE, MVT::Other), V(v), offset(o) {} 1106 1107public: 1108 const Value *getValue() const { return V; } 1109 int getOffset() const { return offset; } 1110 1111 static bool classof(const SrcValueSDNode *) { return true; } 1112 static bool classof(const SDNode *N) { 1113 return N->getOpcode() == ISD::SRCVALUE; 1114 } 1115}; 1116 1117 1118class RegisterSDNode : public SDNode { 1119 unsigned Reg; 1120protected: 1121 friend class SelectionDAG; 1122 RegisterSDNode(unsigned reg, MVT::ValueType VT) 1123 : SDNode(ISD::Register, VT), Reg(reg) {} 1124public: 1125 1126 unsigned getReg() const { return Reg; } 1127 1128 static bool classof(const RegisterSDNode *) { return true; } 1129 static bool classof(const SDNode *N) { 1130 return N->getOpcode() == ISD::Register; 1131 } 1132}; 1133 1134class ExternalSymbolSDNode : public SDNode { 1135 const char *Symbol; 1136protected: 1137 friend class SelectionDAG; 1138 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT) 1139 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, VT), 1140 Symbol(Sym) { 1141 } 1142public: 1143 1144 const char *getSymbol() const { return Symbol; } 1145 1146 static bool classof(const ExternalSymbolSDNode *) { return true; } 1147 static bool classof(const SDNode *N) { 1148 return N->getOpcode() == ISD::ExternalSymbol || 1149 N->getOpcode() == ISD::TargetExternalSymbol; 1150 } 1151}; 1152 1153class CondCodeSDNode : public SDNode { 1154 ISD::CondCode Condition; 1155protected: 1156 friend class SelectionDAG; 1157 CondCodeSDNode(ISD::CondCode Cond) 1158 : SDNode(ISD::CONDCODE, MVT::Other), Condition(Cond) { 1159 } 1160public: 1161 1162 ISD::CondCode get() const { return Condition; } 1163 1164 static bool classof(const CondCodeSDNode *) { return true; } 1165 static bool classof(const SDNode *N) { 1166 return N->getOpcode() == ISD::CONDCODE; 1167 } 1168}; 1169 1170/// VTSDNode - This class is used to represent MVT::ValueType's, which are used 1171/// to parameterize some operations. 1172class VTSDNode : public SDNode { 1173 MVT::ValueType ValueType; 1174protected: 1175 friend class SelectionDAG; 1176 VTSDNode(MVT::ValueType VT) 1177 : SDNode(ISD::VALUETYPE, MVT::Other), ValueType(VT) {} 1178public: 1179 1180 MVT::ValueType getVT() const { return ValueType; } 1181 1182 static bool classof(const VTSDNode *) { return true; } 1183 static bool classof(const SDNode *N) { 1184 return N->getOpcode() == ISD::VALUETYPE; 1185 } 1186}; 1187 1188 1189class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { 1190 SDNode *Node; 1191 unsigned Operand; 1192 1193 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} 1194public: 1195 bool operator==(const SDNodeIterator& x) const { 1196 return Operand == x.Operand; 1197 } 1198 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } 1199 1200 const SDNodeIterator &operator=(const SDNodeIterator &I) { 1201 assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); 1202 Operand = I.Operand; 1203 return *this; 1204 } 1205 1206 pointer operator*() const { 1207 return Node->getOperand(Operand).Val; 1208 } 1209 pointer operator->() const { return operator*(); } 1210 1211 SDNodeIterator& operator++() { // Preincrement 1212 ++Operand; 1213 return *this; 1214 } 1215 SDNodeIterator operator++(int) { // Postincrement 1216 SDNodeIterator tmp = *this; ++*this; return tmp; 1217 } 1218 1219 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } 1220 static SDNodeIterator end (SDNode *N) { 1221 return SDNodeIterator(N, N->getNumOperands()); 1222 } 1223 1224 unsigned getOperand() const { return Operand; } 1225 const SDNode *getNode() const { return Node; } 1226}; 1227 1228template <> struct GraphTraits<SDNode*> { 1229 typedef SDNode NodeType; 1230 typedef SDNodeIterator ChildIteratorType; 1231 static inline NodeType *getEntryNode(SDNode *N) { return N; } 1232 static inline ChildIteratorType child_begin(NodeType *N) { 1233 return SDNodeIterator::begin(N); 1234 } 1235 static inline ChildIteratorType child_end(NodeType *N) { 1236 return SDNodeIterator::end(N); 1237 } 1238}; 1239 1240template<> 1241struct ilist_traits<SDNode> { 1242 static SDNode *getPrev(const SDNode *N) { return N->Prev; } 1243 static SDNode *getNext(const SDNode *N) { return N->Next; } 1244 1245 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; } 1246 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; } 1247 1248 static SDNode *createSentinel() { 1249 return new SDNode(ISD::EntryToken, MVT::Other); 1250 } 1251 static void destroySentinel(SDNode *N) { delete N; } 1252 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); } 1253 1254 1255 void addNodeToList(SDNode *NTy) {} 1256 void removeNodeFromList(SDNode *NTy) {} 1257 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2, 1258 const ilist_iterator<SDNode> &X, 1259 const ilist_iterator<SDNode> &Y) {} 1260}; 1261 1262} // end llvm namespace 1263 1264#endif 1265