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