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