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