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