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