SelectionDAGNodes.h revision 7f460203b0c5350e9b2c592f438e40f7a7de6e45
1//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// 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.h" 26#include "llvm/ADT/APFloat.h" 27#include "llvm/ADT/APInt.h" 28#include "llvm/CodeGen/ValueTypes.h" 29#include "llvm/CodeGen/MachineMemOperand.h" 30#include "llvm/Support/DataTypes.h" 31#include <cassert> 32 33namespace llvm { 34 35class SelectionDAG; 36class GlobalValue; 37class MachineBasicBlock; 38class MachineConstantPoolValue; 39class SDNode; 40class CompileUnitDesc; 41template <typename T> struct DenseMapInfo; 42template <typename T> struct simplify_type; 43template <typename T> struct ilist_traits; 44template<typename NodeTy, typename Traits> class iplist; 45template<typename NodeTy> class ilist_iterator; 46 47/// SDVTList - This represents a list of ValueType's that has been intern'd by 48/// a SelectionDAG. Instances of this simple value class are returned by 49/// SelectionDAG::getVTList(...). 50/// 51struct SDVTList { 52 const MVT *VTs; 53 unsigned short NumVTs; 54}; 55 56/// ISD namespace - This namespace contains an enum which represents all of the 57/// SelectionDAG node types and value types. 58/// 59namespace ISD { 60 61 //===--------------------------------------------------------------------===// 62 /// ISD::NodeType enum - This enum defines all of the operators valid in a 63 /// SelectionDAG. 64 /// 65 enum NodeType { 66 // DELETED_NODE - This is an illegal flag value that is used to catch 67 // errors. This opcode is not a legal opcode for any node. 68 DELETED_NODE, 69 70 // EntryToken - This is the marker used to indicate the start of the region. 71 EntryToken, 72 73 // Token factor - This node takes multiple tokens as input and produces a 74 // single token result. This is used to represent the fact that the operand 75 // operators are independent of each other. 76 TokenFactor, 77 78 // AssertSext, AssertZext - These nodes record if a register contains a 79 // value that has already been zero or sign extended from a narrower type. 80 // These nodes take two operands. The first is the node that has already 81 // been extended, and the second is a value type node indicating the width 82 // of the extension 83 AssertSext, AssertZext, 84 85 // Various leaf nodes. 86 BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register, 87 Constant, ConstantFP, 88 GlobalAddress, GlobalTLSAddress, FrameIndex, 89 JumpTable, ConstantPool, ExternalSymbol, 90 91 // The address of the GOT 92 GLOBAL_OFFSET_TABLE, 93 94 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and 95 // llvm.returnaddress on the DAG. These nodes take one operand, the index 96 // of the frame or return address to return. An index of zero corresponds 97 // to the current function's frame or return address, an index of one to the 98 // parent's frame or return address, and so on. 99 FRAMEADDR, RETURNADDR, 100 101 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to 102 // first (possible) on-stack argument. This is needed for correct stack 103 // adjustment during unwind. 104 FRAME_TO_ARGS_OFFSET, 105 106 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the 107 // address of the exception block on entry to an landing pad block. 108 EXCEPTIONADDR, 109 110 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents 111 // the selection index of the exception thrown. 112 EHSELECTION, 113 114 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 115 // 'eh_return' gcc dwarf builtin, which is used to return from 116 // exception. The general meaning is: adjust stack by OFFSET and pass 117 // execution to HANDLER. Many platform-related details also :) 118 EH_RETURN, 119 120 // TargetConstant* - Like Constant*, but the DAG does not do any folding or 121 // simplification of the constant. 122 TargetConstant, 123 TargetConstantFP, 124 125 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or 126 // anything else with this node, and this is valid in the target-specific 127 // dag, turning into a GlobalAddress operand. 128 TargetGlobalAddress, 129 TargetGlobalTLSAddress, 130 TargetFrameIndex, 131 TargetJumpTable, 132 TargetConstantPool, 133 TargetExternalSymbol, 134 135 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) 136 /// This node represents a target intrinsic function with no side effects. 137 /// The first operand is the ID number of the intrinsic from the 138 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The 139 /// node has returns the result of the intrinsic. 140 INTRINSIC_WO_CHAIN, 141 142 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) 143 /// This node represents a target intrinsic function with side effects that 144 /// returns a result. The first operand is a chain pointer. The second is 145 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The 146 /// operands to the intrinsic follow. The node has two results, the result 147 /// of the intrinsic and an output chain. 148 INTRINSIC_W_CHAIN, 149 150 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) 151 /// This node represents a target intrinsic function with side effects that 152 /// does not return a result. The first operand is a chain pointer. The 153 /// second is the ID number of the intrinsic from the llvm::Intrinsic 154 /// namespace. The operands to the intrinsic follow. 155 INTRINSIC_VOID, 156 157 // CopyToReg - This node has three operands: a chain, a register number to 158 // set to this value, and a value. 159 CopyToReg, 160 161 // CopyFromReg - This node indicates that the input value is a virtual or 162 // physical register that is defined outside of the scope of this 163 // SelectionDAG. The register is available from the RegisterSDNode object. 164 CopyFromReg, 165 166 // UNDEF - An undefined node 167 UNDEF, 168 169 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node 170 /// represents the formal arguments for a function. CC# is a Constant value 171 /// indicating the calling convention of the function, and ISVARARG is a 172 /// flag that indicates whether the function is varargs or not. This node 173 /// has one result value for each incoming argument, plus one for the output 174 /// chain. It must be custom legalized. See description of CALL node for 175 /// FLAG argument contents explanation. 176 /// 177 FORMAL_ARGUMENTS, 178 179 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE, 180 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn) 181 /// This node represents a fully general function call, before the legalizer 182 /// runs. This has one result value for each argument / flag pair, plus 183 /// a chain result. It must be custom legalized. Flag argument indicates 184 /// misc. argument attributes. Currently: 185 /// Bit 0 - signness 186 /// Bit 1 - 'inreg' attribute 187 /// Bit 2 - 'sret' attribute 188 /// Bit 4 - 'byval' attribute 189 /// Bit 5 - 'nest' attribute 190 /// Bit 6-9 - alignment of byval structures 191 /// Bit 10-26 - size of byval structures 192 /// Bits 31:27 - argument ABI alignment in the first argument piece and 193 /// alignment '1' in other argument pieces. 194 CALL, 195 196 // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by 197 // a Constant, which is required to be operand #1) half of the integer or 198 // float value specified as operand #0. This is only for use before 199 // legalization, for values that will be broken into multiple registers. 200 EXTRACT_ELEMENT, 201 202 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given 203 // two values of the same integer value type, this produces a value twice as 204 // big. Like EXTRACT_ELEMENT, this can only be used before legalization. 205 BUILD_PAIR, 206 207 // MERGE_VALUES - This node takes multiple discrete operands and returns 208 // them all as its individual results. This nodes has exactly the same 209 // number of inputs and outputs, and is only valid before legalization. 210 // This node is useful for some pieces of the code generator that want to 211 // think about a single node with multiple results, not multiple nodes. 212 MERGE_VALUES, 213 214 // Simple integer binary arithmetic operators. 215 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, 216 217 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing 218 // a signed/unsigned value of type i[2*N], and return the full value as 219 // two results, each of type iN. 220 SMUL_LOHI, UMUL_LOHI, 221 222 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and 223 // remainder result. 224 SDIVREM, UDIVREM, 225 226 // CARRY_FALSE - This node is used when folding other nodes, 227 // like ADDC/SUBC, which indicate the carry result is always false. 228 CARRY_FALSE, 229 230 // Carry-setting nodes for multiple precision addition and subtraction. 231 // These nodes take two operands of the same value type, and produce two 232 // results. The first result is the normal add or sub result, the second 233 // result is the carry flag result. 234 ADDC, SUBC, 235 236 // Carry-using nodes for multiple precision addition and subtraction. These 237 // nodes take three operands: The first two are the normal lhs and rhs to 238 // the add or sub, and the third is the input carry flag. These nodes 239 // produce two results; the normal result of the add or sub, and the output 240 // carry flag. These nodes both read and write a carry flag to allow them 241 // to them to be chained together for add and sub of arbitrarily large 242 // values. 243 ADDE, SUBE, 244 245 // Simple binary floating point operators. 246 FADD, FSUB, FMUL, FDIV, FREM, 247 248 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This 249 // DAG node does not require that X and Y have the same type, just that they 250 // are both floating point. X and the result must have the same type. 251 // FCOPYSIGN(f32, f64) is allowed. 252 FCOPYSIGN, 253 254 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point 255 // value as an integer 0/1 value. 256 FGETSIGN, 257 258 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector 259 /// with the specified, possibly variable, elements. The number of elements 260 /// is required to be a power of two. 261 BUILD_VECTOR, 262 263 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element 264 /// at IDX replaced with VAL. If the type of VAL is larger than the vector 265 /// element type then VAL is truncated before replacement. 266 INSERT_VECTOR_ELT, 267 268 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR 269 /// identified by the (potentially variable) element number IDX. 270 EXTRACT_VECTOR_ELT, 271 272 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of 273 /// vector type with the same length and element type, this produces a 274 /// concatenated vector result value, with length equal to the sum of the 275 /// lengths of the input vectors. 276 CONCAT_VECTORS, 277 278 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an 279 /// vector value) starting with the (potentially variable) element number 280 /// IDX, which must be a multiple of the result vector length. 281 EXTRACT_SUBVECTOR, 282 283 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same 284 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values 285 /// (maybe of an illegal datatype) or undef that indicate which value each 286 /// result element will get. The elements of VEC1/VEC2 are enumerated in 287 /// order. This is quite similar to the Altivec 'vperm' instruction, except 288 /// that the indices must be constants and are in terms of the element size 289 /// of VEC1/VEC2, not in terms of bytes. 290 VECTOR_SHUFFLE, 291 292 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a 293 /// scalar value into element 0 of the resultant vector type. The top 294 /// elements 1 to N-1 of the N-element vector are undefined. 295 SCALAR_TO_VECTOR, 296 297 // EXTRACT_SUBREG - This node is used to extract a sub-register value. 298 // This node takes a superreg and a constant sub-register index as operands. 299 // Note sub-register indices must be increasing. That is, if the 300 // sub-register index of a 8-bit sub-register is N, then the index for a 301 // 16-bit sub-register must be at least N+1. 302 EXTRACT_SUBREG, 303 304 // INSERT_SUBREG - This node is used to insert a sub-register value. 305 // This node takes a superreg, a subreg value, and a constant sub-register 306 // index as operands. 307 INSERT_SUBREG, 308 309 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing 310 // an unsigned/signed value of type i[2*N], then return the top part. 311 MULHU, MULHS, 312 313 // Bitwise operators - logical and, logical or, logical xor, shift left, 314 // shift right algebraic (shift in sign bits), shift right logical (shift in 315 // zeroes), rotate left, rotate right, and byteswap. 316 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP, 317 318 // Counting operators 319 CTTZ, CTLZ, CTPOP, 320 321 // Select(COND, TRUEVAL, FALSEVAL) 322 SELECT, 323 324 // Select with condition operator - This selects between a true value and 325 // a false value (ops #2 and #3) based on the boolean result of comparing 326 // the lhs and rhs (ops #0 and #1) of a conditional expression with the 327 // condition code in op #4, a CondCodeSDNode. 328 SELECT_CC, 329 330 // SetCC operator - This evaluates to a boolean (i1) true value if the 331 // condition is true. The operands to this are the left and right operands 332 // to compare (ops #0, and #1) and the condition code to compare them with 333 // (op #2) as a CondCodeSDNode. 334 SETCC, 335 336 // Vector SetCC operator - This evaluates to a vector of integer elements 337 // with the high bit in each element set to true if the comparison is true 338 // and false if the comparison is false. All other bits in each element 339 // are undefined. The operands to this are the left and right operands 340 // to compare (ops #0, and #1) and the condition code to compare them with 341 // (op #2) as a CondCodeSDNode. 342 VSETCC, 343 344 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded 345 // integer shift operations, just like ADD/SUB_PARTS. The operation 346 // ordering is: 347 // [Lo,Hi] = op [LoLHS,HiLHS], Amt 348 SHL_PARTS, SRA_PARTS, SRL_PARTS, 349 350 // Conversion operators. These are all single input single output 351 // operations. For all of these, the result type must be strictly 352 // wider or narrower (depending on the operation) than the source 353 // type. 354 355 // SIGN_EXTEND - Used for integer types, replicating the sign bit 356 // into new bits. 357 SIGN_EXTEND, 358 359 // ZERO_EXTEND - Used for integer types, zeroing the new bits. 360 ZERO_EXTEND, 361 362 // ANY_EXTEND - Used for integer types. The high bits are undefined. 363 ANY_EXTEND, 364 365 // TRUNCATE - Completely drop the high bits. 366 TRUNCATE, 367 368 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign 369 // depends on the first letter) to floating point. 370 SINT_TO_FP, 371 UINT_TO_FP, 372 373 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to 374 // sign extend a small value in a large integer register (e.g. sign 375 // extending the low 8 bits of a 32-bit register to fill the top 24 bits 376 // with the 7th bit). The size of the smaller type is indicated by the 1th 377 // operand, a ValueType node. 378 SIGN_EXTEND_INREG, 379 380 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned 381 /// integer. 382 FP_TO_SINT, 383 FP_TO_UINT, 384 385 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type 386 /// down to the precision of the destination VT. TRUNC is a flag, which is 387 /// always an integer that is zero or one. If TRUNC is 0, this is a 388 /// normal rounding, if it is 1, this FP_ROUND is known to not change the 389 /// value of Y. 390 /// 391 /// The TRUNC = 1 case is used in cases where we know that the value will 392 /// not be modified by the node, because Y is not using any of the extra 393 /// precision of source type. This allows certain transformations like 394 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 395 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed. 396 FP_ROUND, 397 398 // FLT_ROUNDS_ - Returns current rounding mode: 399 // -1 Undefined 400 // 0 Round to 0 401 // 1 Round to nearest 402 // 2 Round to +inf 403 // 3 Round to -inf 404 FLT_ROUNDS_, 405 406 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and 407 /// rounds it to a floating point value. It then promotes it and returns it 408 /// in a register of the same size. This operation effectively just 409 /// discards excess precision. The type to round down to is specified by 410 /// the VT operand, a VTSDNode. 411 FP_ROUND_INREG, 412 413 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type. 414 FP_EXTEND, 415 416 // BIT_CONVERT - Theis operator converts between integer and FP values, as 417 // if one was stored to memory as integer and the other was loaded from the 418 // same address (or equivalently for vector format conversions, etc). The 419 // source and result are required to have the same bit size (e.g. 420 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp 421 // conversions, but that is a noop, deleted by getNode(). 422 BIT_CONVERT, 423 424 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point 425 // negation, absolute value, square root, sine and cosine, powi, and pow 426 // operations. 427 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, 428 429 // LOAD and STORE have token chains as their first operand, then the same 430 // operands as an LLVM load/store instruction, then an offset node that 431 // is added / subtracted from the base pointer to form the address (for 432 // indexed memory ops). 433 LOAD, STORE, 434 435 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned 436 // to a specified boundary. This node always has two return values: a new 437 // stack pointer value and a chain. The first operand is the token chain, 438 // the second is the number of bytes to allocate, and the third is the 439 // alignment boundary. The size is guaranteed to be a multiple of the stack 440 // alignment, and the alignment is guaranteed to be bigger than the stack 441 // alignment (if required) or 0 to get standard stack alignment. 442 DYNAMIC_STACKALLOC, 443 444 // Control flow instructions. These all have token chains. 445 446 // BR - Unconditional branch. The first operand is the chain 447 // operand, the second is the MBB to branch to. 448 BR, 449 450 // BRIND - Indirect branch. The first operand is the chain, the second 451 // is the value to branch to, which must be of the same type as the target's 452 // pointer type. 453 BRIND, 454 455 // BR_JT - Jumptable branch. The first operand is the chain, the second 456 // is the jumptable index, the last one is the jumptable entry index. 457 BR_JT, 458 459 // BRCOND - Conditional branch. The first operand is the chain, 460 // the second is the condition, the third is the block to branch 461 // to if the condition is true. 462 BRCOND, 463 464 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in 465 // that the condition is represented as condition code, and two nodes to 466 // compare, rather than as a combined SetCC node. The operands in order are 467 // chain, cc, lhs, rhs, block to branch to if condition is true. 468 BR_CC, 469 470 // RET - Return from function. The first operand is the chain, 471 // and any subsequent operands are pairs of return value and return value 472 // signness for the function. This operation can have variable number of 473 // operands. 474 RET, 475 476 // INLINEASM - Represents an inline asm block. This node always has two 477 // return values: a chain and a flag result. The inputs are as follows: 478 // Operand #0 : Input chain. 479 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string. 480 // Operand #2n+2: A RegisterNode. 481 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def 482 // Operand #last: Optional, an incoming flag. 483 INLINEASM, 484 485 // LABEL - Represents a label in mid basic block used to track 486 // locations needed for debug and exception handling tables. This node 487 // returns a chain. 488 // Operand #0 : input chain. 489 // Operand #1 : module unique number use to identify the label. 490 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates 491 // a EH label, 2 indicates unknown label type. 492 LABEL, 493 494 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track 495 // local variable declarations for debugging information. First operand is 496 // a chain, while the next two operands are first two arguments (address 497 // and variable) of a llvm.dbg.declare instruction. 498 DECLARE, 499 500 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a 501 // value, the same type as the pointer type for the system, and an output 502 // chain. 503 STACKSAVE, 504 505 // STACKRESTORE has two operands, an input chain and a pointer to restore to 506 // it returns an output chain. 507 STACKRESTORE, 508 509 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of 510 // a call sequence, and carry arbitrary information that target might want 511 // to know. The first operand is a chain, the rest are specified by the 512 // target and not touched by the DAG optimizers. 513 // CALLSEQ_START..CALLSEQ_END pairs may not be nested. 514 CALLSEQ_START, // Beginning of a call sequence 515 CALLSEQ_END, // End of a call sequence 516 517 // VAARG - VAARG has three operands: an input chain, a pointer, and a 518 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain. 519 VAARG, 520 521 // VACOPY - VACOPY has five operands: an input chain, a destination pointer, 522 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the 523 // source. 524 VACOPY, 525 526 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a 527 // pointer, and a SRCVALUE. 528 VAEND, VASTART, 529 530 // SRCVALUE - This is a node type that holds a Value* that is used to 531 // make reference to a value in the LLVM IR. 532 SRCVALUE, 533 534 // MEMOPERAND - This is a node that contains a MachineMemOperand which 535 // records information about a memory reference. This is used to make 536 // AliasAnalysis queries from the backend. 537 MEMOPERAND, 538 539 // PCMARKER - This corresponds to the pcmarker intrinsic. 540 PCMARKER, 541 542 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic. 543 // The only operand is a chain and a value and a chain are produced. The 544 // value is the contents of the architecture specific cycle counter like 545 // register (or other high accuracy low latency clock source) 546 READCYCLECOUNTER, 547 548 // HANDLENODE node - Used as a handle for various purposes. 549 HANDLENODE, 550 551 // DBG_STOPPOINT - This node is used to represent a source location for 552 // debug info. It takes token chain as input, and carries a line number, 553 // column number, and a pointer to a CompileUnitDesc object identifying 554 // the containing compilation unit. It produces a token chain as output. 555 DBG_STOPPOINT, 556 557 // DEBUG_LOC - This node is used to represent source line information 558 // embedded in the code. It takes a token chain as input, then a line 559 // number, then a column then a file id (provided by MachineModuleInfo.) It 560 // produces a token chain as output. 561 DEBUG_LOC, 562 563 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic. 564 // It takes as input a token chain, the pointer to the trampoline, 565 // the pointer to the nested function, the pointer to pass for the 566 // 'nest' parameter, a SRCVALUE for the trampoline and another for 567 // the nested function (allowing targets to access the original 568 // Function*). It produces the result of the intrinsic and a token 569 // chain as output. 570 TRAMPOLINE, 571 572 // TRAP - Trapping instruction 573 TRAP, 574 575 // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are 576 // their first operand. The other operands are the address to prefetch, 577 // read / write specifier, and locality specifier. 578 PREFETCH, 579 580 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 581 // store-store, device) 582 // This corresponds to the memory.barrier intrinsic. 583 // it takes an input chain, 4 operands to specify the type of barrier, an 584 // operand specifying if the barrier applies to device and uncached memory 585 // and produces an output chain. 586 MEMBARRIER, 587 588 // Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) 589 // this corresponds to the atomic.lcs intrinsic. 590 // cmp is compared to *ptr, and if equal, swap is stored in *ptr. 591 // the return is always the original value in *ptr 592 ATOMIC_CMP_SWAP, 593 594 // Val, OUTCHAIN = ATOMIC_LOAD_ADD(INCHAIN, ptr, amt) 595 // this corresponds to the atomic.las intrinsic. 596 // *ptr + amt is stored to *ptr atomically. 597 // the return is always the original value in *ptr 598 ATOMIC_LOAD_ADD, 599 600 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) 601 // this corresponds to the atomic.swap intrinsic. 602 // amt is stored to *ptr atomically. 603 // the return is always the original value in *ptr 604 ATOMIC_SWAP, 605 606 // Val, OUTCHAIN = ATOMIC_LOAD_SUB(INCHAIN, ptr, amt) 607 // this corresponds to the atomic.lss intrinsic. 608 // *ptr - amt is stored to *ptr atomically. 609 // the return is always the original value in *ptr 610 ATOMIC_LOAD_SUB, 611 612 // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt) 613 // this corresponds to the atomic.[OpName] intrinsic. 614 // op(*ptr, amt) is stored to *ptr atomically. 615 // the return is always the original value in *ptr 616 ATOMIC_LOAD_AND, 617 ATOMIC_LOAD_OR, 618 ATOMIC_LOAD_XOR, 619 ATOMIC_LOAD_NAND, 620 ATOMIC_LOAD_MIN, 621 ATOMIC_LOAD_MAX, 622 ATOMIC_LOAD_UMIN, 623 ATOMIC_LOAD_UMAX, 624 625 // BUILTIN_OP_END - This must be the last enum value in this list. 626 BUILTIN_OP_END 627 }; 628 629 /// Node predicates 630 631 /// isBuildVectorAllOnes - Return true if the specified node is a 632 /// BUILD_VECTOR where all of the elements are ~0 or undef. 633 bool isBuildVectorAllOnes(const SDNode *N); 634 635 /// isBuildVectorAllZeros - Return true if the specified node is a 636 /// BUILD_VECTOR where all of the elements are 0 or undef. 637 bool isBuildVectorAllZeros(const SDNode *N); 638 639 /// isScalarToVector - Return true if the specified node is a 640 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low 641 /// element is not an undef. 642 bool isScalarToVector(const SDNode *N); 643 644 /// isDebugLabel - Return true if the specified node represents a debug 645 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand 646 /// is 0). 647 bool isDebugLabel(const SDNode *N); 648 649 //===--------------------------------------------------------------------===// 650 /// MemIndexedMode enum - This enum defines the load / store indexed 651 /// addressing modes. 652 /// 653 /// UNINDEXED "Normal" load / store. The effective address is already 654 /// computed and is available in the base pointer. The offset 655 /// operand is always undefined. In addition to producing a 656 /// chain, an unindexed load produces one value (result of the 657 /// load); an unindexed store does not produce a value. 658 /// 659 /// PRE_INC Similar to the unindexed mode where the effective address is 660 /// PRE_DEC the value of the base pointer add / subtract the offset. 661 /// It considers the computation as being folded into the load / 662 /// store operation (i.e. the load / store does the address 663 /// computation as well as performing the memory transaction). 664 /// The base operand is always undefined. In addition to 665 /// producing a chain, pre-indexed load produces two values 666 /// (result of the load and the result of the address 667 /// computation); a pre-indexed store produces one value (result 668 /// of the address computation). 669 /// 670 /// POST_INC The effective address is the value of the base pointer. The 671 /// POST_DEC value of the offset operand is then added to / subtracted 672 /// from the base after memory transaction. In addition to 673 /// producing a chain, post-indexed load produces two values 674 /// (the result of the load and the result of the base +/- offset 675 /// computation); a post-indexed store produces one value (the 676 /// the result of the base +/- offset computation). 677 /// 678 enum MemIndexedMode { 679 UNINDEXED = 0, 680 PRE_INC, 681 PRE_DEC, 682 POST_INC, 683 POST_DEC, 684 LAST_INDEXED_MODE 685 }; 686 687 //===--------------------------------------------------------------------===// 688 /// LoadExtType enum - This enum defines the three variants of LOADEXT 689 /// (load with extension). 690 /// 691 /// SEXTLOAD loads the integer operand and sign extends it to a larger 692 /// integer result type. 693 /// ZEXTLOAD loads the integer operand and zero extends it to a larger 694 /// integer result type. 695 /// EXTLOAD is used for three things: floating point extending loads, 696 /// integer extending loads [the top bits are undefined], and vector 697 /// extending loads [load into low elt]. 698 /// 699 enum LoadExtType { 700 NON_EXTLOAD = 0, 701 EXTLOAD, 702 SEXTLOAD, 703 ZEXTLOAD, 704 LAST_LOADX_TYPE 705 }; 706 707 //===--------------------------------------------------------------------===// 708 /// ISD::CondCode enum - These are ordered carefully to make the bitfields 709 /// below work out, when considering SETFALSE (something that never exists 710 /// dynamically) as 0. "U" -> Unsigned (for integer operands) or Unordered 711 /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal 712 /// to. If the "N" column is 1, the result of the comparison is undefined if 713 /// the input is a NAN. 714 /// 715 /// All of these (except for the 'always folded ops') should be handled for 716 /// floating point. For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT, 717 /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used. 718 /// 719 /// Note that these are laid out in a specific order to allow bit-twiddling 720 /// to transform conditions. 721 enum CondCode { 722 // Opcode N U L G E Intuitive operation 723 SETFALSE, // 0 0 0 0 Always false (always folded) 724 SETOEQ, // 0 0 0 1 True if ordered and equal 725 SETOGT, // 0 0 1 0 True if ordered and greater than 726 SETOGE, // 0 0 1 1 True if ordered and greater than or equal 727 SETOLT, // 0 1 0 0 True if ordered and less than 728 SETOLE, // 0 1 0 1 True if ordered and less than or equal 729 SETONE, // 0 1 1 0 True if ordered and operands are unequal 730 SETO, // 0 1 1 1 True if ordered (no nans) 731 SETUO, // 1 0 0 0 True if unordered: isnan(X) | isnan(Y) 732 SETUEQ, // 1 0 0 1 True if unordered or equal 733 SETUGT, // 1 0 1 0 True if unordered or greater than 734 SETUGE, // 1 0 1 1 True if unordered, greater than, or equal 735 SETULT, // 1 1 0 0 True if unordered or less than 736 SETULE, // 1 1 0 1 True if unordered, less than, or equal 737 SETUNE, // 1 1 1 0 True if unordered or not equal 738 SETTRUE, // 1 1 1 1 Always true (always folded) 739 // Don't care operations: undefined if the input is a nan. 740 SETFALSE2, // 1 X 0 0 0 Always false (always folded) 741 SETEQ, // 1 X 0 0 1 True if equal 742 SETGT, // 1 X 0 1 0 True if greater than 743 SETGE, // 1 X 0 1 1 True if greater than or equal 744 SETLT, // 1 X 1 0 0 True if less than 745 SETLE, // 1 X 1 0 1 True if less than or equal 746 SETNE, // 1 X 1 1 0 True if not equal 747 SETTRUE2, // 1 X 1 1 1 Always true (always folded) 748 749 SETCC_INVALID // Marker value. 750 }; 751 752 /// isSignedIntSetCC - Return true if this is a setcc instruction that 753 /// performs a signed comparison when used with integer operands. 754 inline bool isSignedIntSetCC(CondCode Code) { 755 return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE; 756 } 757 758 /// isUnsignedIntSetCC - Return true if this is a setcc instruction that 759 /// performs an unsigned comparison when used with integer operands. 760 inline bool isUnsignedIntSetCC(CondCode Code) { 761 return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE; 762 } 763 764 /// isTrueWhenEqual - Return true if the specified condition returns true if 765 /// the two operands to the condition are equal. Note that if one of the two 766 /// operands is a NaN, this value is meaningless. 767 inline bool isTrueWhenEqual(CondCode Cond) { 768 return ((int)Cond & 1) != 0; 769 } 770 771 /// getUnorderedFlavor - This function returns 0 if the condition is always 772 /// false if an operand is a NaN, 1 if the condition is always true if the 773 /// operand is a NaN, and 2 if the condition is undefined if the operand is a 774 /// NaN. 775 inline unsigned getUnorderedFlavor(CondCode Cond) { 776 return ((int)Cond >> 3) & 3; 777 } 778 779 /// getSetCCInverse - Return the operation corresponding to !(X op Y), where 780 /// 'op' is a valid SetCC operation. 781 CondCode getSetCCInverse(CondCode Operation, bool isInteger); 782 783 /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X) 784 /// when given the operation for (X op Y). 785 CondCode getSetCCSwappedOperands(CondCode Operation); 786 787 /// getSetCCOrOperation - Return the result of a logical OR between different 788 /// comparisons of identical values: ((X op1 Y) | (X op2 Y)). This 789 /// function returns SETCC_INVALID if it is not possible to represent the 790 /// resultant comparison. 791 CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger); 792 793 /// getSetCCAndOperation - Return the result of a logical AND between 794 /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)). This 795 /// function returns SETCC_INVALID if it is not possible to represent the 796 /// resultant comparison. 797 CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger); 798} // end llvm::ISD namespace 799 800 801//===----------------------------------------------------------------------===// 802/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple 803/// values as the result of a computation. Many nodes return multiple values, 804/// from loads (which define a token and a return value) to ADDC (which returns 805/// a result and a carry value), to calls (which may return an arbitrary number 806/// of values). 807/// 808/// As such, each use of a SelectionDAG computation must indicate the node that 809/// computes it as well as which return value to use from that node. This pair 810/// of information is represented with the SDOperand value type. 811/// 812class SDOperand { 813public: 814 SDNode *Val; // The node defining the value we are using. 815 unsigned ResNo; // Which return value of the node we are using. 816 817 SDOperand() : Val(0), ResNo(0) {} 818 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} 819 820 bool operator==(const SDOperand &O) const { 821 return Val == O.Val && ResNo == O.ResNo; 822 } 823 bool operator!=(const SDOperand &O) const { 824 return !operator==(O); 825 } 826 bool operator<(const SDOperand &O) const { 827 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); 828 } 829 830 SDOperand getValue(unsigned R) const { 831 return SDOperand(Val, R); 832 } 833 834 // isOperandOf - Return true if this node is an operand of N. 835 bool isOperandOf(SDNode *N) const; 836 837 /// getValueType - Return the ValueType of the referenced return value. 838 /// 839 inline MVT getValueType() const; 840 841 /// getValueSizeInBits - Returns the size of the value in bits. 842 /// 843 unsigned getValueSizeInBits() const { 844 return getValueType().getSizeInBits(); 845 } 846 847 // Forwarding methods - These forward to the corresponding methods in SDNode. 848 inline unsigned getOpcode() const; 849 inline unsigned getNumOperands() const; 850 inline const SDOperand &getOperand(unsigned i) const; 851 inline uint64_t getConstantOperandVal(unsigned i) const; 852 inline bool isTargetOpcode() const; 853 inline unsigned getTargetOpcode() const; 854 855 856 /// reachesChainWithoutSideEffects - Return true if this operand (which must 857 /// be a chain) reaches the specified operand without crossing any 858 /// side-effecting instructions. In practice, this looks through token 859 /// factors and non-volatile loads. In order to remain efficient, this only 860 /// looks a couple of nodes in, it does not do an exhaustive search. 861 bool reachesChainWithoutSideEffects(SDOperand Dest, 862 unsigned Depth = 2) const; 863 864 /// hasOneUse - Return true if there is exactly one operation using this 865 /// result value of the defining operator. 866 inline bool hasOneUse() const; 867 868 /// use_empty - Return true if there are no operations using this 869 /// result value of the defining operator. 870 inline bool use_empty() const; 871}; 872 873 874template<> struct DenseMapInfo<SDOperand> { 875 static inline SDOperand getEmptyKey() { 876 return SDOperand((SDNode*)-1, -1U); 877 } 878 static inline SDOperand getTombstoneKey() { 879 return SDOperand((SDNode*)-1, 0); 880 } 881 static unsigned getHashValue(const SDOperand &Val) { 882 return ((unsigned)((uintptr_t)Val.Val >> 4) ^ 883 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo; 884 } 885 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) { 886 return LHS == RHS; 887 } 888 static bool isPod() { return true; } 889}; 890 891/// simplify_type specializations - Allow casting operators to work directly on 892/// SDOperands as if they were SDNode*'s. 893template<> struct simplify_type<SDOperand> { 894 typedef SDNode* SimpleType; 895 static SimpleType getSimplifiedValue(const SDOperand &Val) { 896 return static_cast<SimpleType>(Val.Val); 897 } 898}; 899template<> struct simplify_type<const SDOperand> { 900 typedef SDNode* SimpleType; 901 static SimpleType getSimplifiedValue(const SDOperand &Val) { 902 return static_cast<SimpleType>(Val.Val); 903 } 904}; 905 906/// SDUse - Represents a use of the SDNode referred by 907/// the SDOperand. 908class SDUse { 909 SDOperand Operand; 910 /// User - Parent node of this operand. 911 SDNode *User; 912 /// Prev, next - Pointers to the uses list of the SDNode referred by 913 /// this operand. 914 SDUse **Prev, *Next; 915public: 916 friend class SDNode; 917 SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {} 918 919 SDUse(SDNode *val, unsigned resno) : 920 Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {} 921 922 SDUse& operator= (const SDOperand& Op) { 923 Operand = Op; 924 Next = NULL; 925 Prev = NULL; 926 return *this; 927 } 928 929 SDUse& operator= (const SDUse& Op) { 930 Operand = Op; 931 Next = NULL; 932 Prev = NULL; 933 return *this; 934 } 935 936 SDUse * getNext() { return Next; } 937 938 SDNode *getUser() { return User; } 939 940 void setUser(SDNode *p) { User = p; } 941 942 operator SDOperand() const { return Operand; } 943 944 const SDOperand& getSDOperand() const { return Operand; } 945 946 SDNode* &getVal () { return Operand.Val; } 947 948 bool operator==(const SDOperand &O) const { 949 return Operand == O; 950 } 951 952 bool operator!=(const SDOperand &O) const { 953 return !(Operand == O); 954 } 955 956 bool operator<(const SDOperand &O) const { 957 return Operand < O; 958 } 959 960protected: 961 void addToList(SDUse **List) { 962 Next = *List; 963 if (Next) Next->Prev = &Next; 964 Prev = List; 965 *List = this; 966 } 967 968 void removeFromList() { 969 *Prev = Next; 970 if (Next) Next->Prev = Prev; 971 } 972}; 973 974 975/// simplify_type specializations - Allow casting operators to work directly on 976/// SDOperands as if they were SDNode*'s. 977template<> struct simplify_type<SDUse> { 978 typedef SDNode* SimpleType; 979 static SimpleType getSimplifiedValue(const SDUse &Val) { 980 return static_cast<SimpleType>(Val.getSDOperand().Val); 981 } 982}; 983template<> struct simplify_type<const SDUse> { 984 typedef SDNode* SimpleType; 985 static SimpleType getSimplifiedValue(const SDUse &Val) { 986 return static_cast<SimpleType>(Val.getSDOperand().Val); 987 } 988}; 989 990 991/// SDOperandPtr - A helper SDOperand pointer class, that can handle 992/// arrays of SDUse and arrays of SDOperand objects. This is required 993/// in many places inside the SelectionDAG. 994/// 995class SDOperandPtr { 996 const SDOperand *ptr; // The pointer to the SDOperand object 997 int object_size; // The size of the object containg the SDOperand 998public: 999 SDOperandPtr() : ptr(0), object_size(0) {} 1000 1001 SDOperandPtr(SDUse * use_ptr) { 1002 ptr = &use_ptr->getSDOperand(); 1003 object_size = (int)sizeof(SDUse); 1004 } 1005 1006 SDOperandPtr(const SDOperand * op_ptr) { 1007 ptr = op_ptr; 1008 object_size = (int)sizeof(SDOperand); 1009 } 1010 1011 const SDOperand operator *() { return *ptr; } 1012 const SDOperand *operator ->() { return ptr; } 1013 SDOperandPtr operator ++ () { 1014 ptr = (SDOperand*)((char *)ptr + object_size); 1015 return *this; 1016 } 1017 1018 SDOperandPtr operator ++ (int) { 1019 SDOperandPtr tmp = *this; 1020 ptr = (SDOperand*)((char *)ptr + object_size); 1021 return tmp; 1022 } 1023 1024 SDOperand operator[] (int idx) const { 1025 return *(SDOperand*)((char*) ptr + object_size * idx); 1026 } 1027}; 1028 1029/// SDNode - Represents one node in the SelectionDAG. 1030/// 1031class SDNode : public FoldingSetNode { 1032private: 1033 /// NodeType - The operation that this node performs. 1034 /// 1035 unsigned short NodeType; 1036 1037 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true, 1038 /// then they will be delete[]'d when the node is destroyed. 1039 bool OperandsNeedDelete : 1; 1040 1041 /// NodeId - Unique id per SDNode in the DAG. 1042 int NodeId; 1043 1044 /// OperandList - The values that are used by this operation. 1045 /// 1046 SDUse *OperandList; 1047 1048 /// ValueList - The types of the values this node defines. SDNode's may 1049 /// define multiple values simultaneously. 1050 const MVT *ValueList; 1051 1052 /// NumOperands/NumValues - The number of entries in the Operand/Value list. 1053 unsigned short NumOperands, NumValues; 1054 1055 /// UsesSize - The size of the uses list. 1056 unsigned UsesSize; 1057 1058 /// Uses - List of uses for this SDNode. 1059 SDUse *Uses; 1060 1061 /// Prev/Next pointers - These pointers form the linked list of of the 1062 /// AllNodes list in the current DAG. 1063 SDNode *Prev, *Next; 1064 friend struct ilist_traits<SDNode>; 1065 1066 /// addUse - add SDUse to the list of uses. 1067 void addUse(SDUse &U) { U.addToList(&Uses); } 1068 1069 // Out-of-line virtual method to give class a home. 1070 virtual void ANCHOR(); 1071public: 1072 virtual ~SDNode() { 1073 assert(NumOperands == 0 && "Operand list not cleared before deletion"); 1074 NodeType = ISD::DELETED_NODE; 1075 } 1076 1077 //===--------------------------------------------------------------------===// 1078 // Accessors 1079 // 1080 unsigned getOpcode() const { return NodeType; } 1081 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; } 1082 unsigned getTargetOpcode() const { 1083 assert(isTargetOpcode() && "Not a target opcode!"); 1084 return NodeType - ISD::BUILTIN_OP_END; 1085 } 1086 1087 size_t use_size() const { return UsesSize; } 1088 bool use_empty() const { return Uses == NULL; } 1089 bool hasOneUse() const { return use_size() == 1; } 1090 1091 /// getNodeId - Return the unique node id. 1092 /// 1093 int getNodeId() const { return NodeId; } 1094 1095 /// setNodeId - Set unique node id. 1096 void setNodeId(int Id) { NodeId = Id; } 1097 1098 /// use_iterator - This class provides iterator support for SDUse 1099 /// operands that use a specific SDNode. 1100 class use_iterator 1101 : public forward_iterator<SDUse, ptrdiff_t> { 1102 SDUse *Op; 1103 explicit use_iterator(SDUse *op) : Op(op) { 1104 } 1105 friend class SDNode; 1106 public: 1107 typedef forward_iterator<SDUse, ptrdiff_t>::reference reference; 1108 typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer; 1109 1110 use_iterator(const use_iterator &I) : Op(I.Op) {} 1111 use_iterator() : Op(0) {} 1112 1113 bool operator==(const use_iterator &x) const { 1114 return Op == x.Op; 1115 } 1116 bool operator!=(const use_iterator &x) const { 1117 return !operator==(x); 1118 } 1119 1120 /// atEnd - return true if this iterator is at the end of uses list. 1121 bool atEnd() const { return Op == 0; } 1122 1123 // Iterator traversal: forward iteration only. 1124 use_iterator &operator++() { // Preincrement 1125 assert(Op && "Cannot increment end iterator!"); 1126 Op = Op->getNext(); 1127 return *this; 1128 } 1129 1130 use_iterator operator++(int) { // Postincrement 1131 use_iterator tmp = *this; ++*this; return tmp; 1132 } 1133 1134 1135 /// getOperandNum - Retrive a number of a current operand. 1136 unsigned getOperandNum() const { 1137 assert(Op && "Cannot dereference end iterator!"); 1138 return (unsigned)(Op - Op->getUser()->OperandList); 1139 } 1140 1141 /// Retrieve a reference to the current operand. 1142 SDUse &operator*() const { 1143 assert(Op && "Cannot dereference end iterator!"); 1144 return *Op; 1145 } 1146 1147 /// Retrieve a pointer to the current operand. 1148 SDUse *operator->() const { 1149 assert(Op && "Cannot dereference end iterator!"); 1150 return Op; 1151 } 1152 }; 1153 1154 /// use_begin/use_end - Provide iteration support to walk over all uses 1155 /// of an SDNode. 1156 1157 use_iterator use_begin(SDNode *node) const { 1158 return use_iterator(node->Uses); 1159 } 1160 1161 use_iterator use_begin() const { 1162 return use_iterator(Uses); 1163 } 1164 1165 static use_iterator use_end() { return use_iterator(0); } 1166 1167 1168 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the 1169 /// indicated value. This method ignores uses of other values defined by this 1170 /// operation. 1171 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const; 1172 1173 /// hasAnyUseOfValue - Return true if there are any use of the indicated 1174 /// value. This method ignores uses of other values defined by this operation. 1175 bool hasAnyUseOfValue(unsigned Value) const; 1176 1177 /// isOnlyUseOf - Return true if this node is the only use of N. 1178 /// 1179 bool isOnlyUseOf(SDNode *N) const; 1180 1181 /// isOperandOf - Return true if this node is an operand of N. 1182 /// 1183 bool isOperandOf(SDNode *N) const; 1184 1185 /// isPredecessorOf - Return true if this node is a predecessor of N. This 1186 /// node is either an operand of N or it can be reached by recursively 1187 /// traversing up the operands. 1188 /// NOTE: this is an expensive method. Use it carefully. 1189 bool isPredecessorOf(SDNode *N) const; 1190 1191 /// getNumOperands - Return the number of values used by this operation. 1192 /// 1193 unsigned getNumOperands() const { return NumOperands; } 1194 1195 /// getConstantOperandVal - Helper method returns the integer value of a 1196 /// ConstantSDNode operand. 1197 uint64_t getConstantOperandVal(unsigned Num) const; 1198 1199 const SDOperand &getOperand(unsigned Num) const { 1200 assert(Num < NumOperands && "Invalid child # of SDNode!"); 1201 return OperandList[Num].getSDOperand(); 1202 } 1203 1204 typedef SDUse* op_iterator; 1205 op_iterator op_begin() const { return OperandList; } 1206 op_iterator op_end() const { return OperandList+NumOperands; } 1207 1208 1209 SDVTList getVTList() const { 1210 SDVTList X = { ValueList, NumValues }; 1211 return X; 1212 }; 1213 1214 /// getNumValues - Return the number of values defined/returned by this 1215 /// operator. 1216 /// 1217 unsigned getNumValues() const { return NumValues; } 1218 1219 /// getValueType - Return the type of a specified result. 1220 /// 1221 MVT getValueType(unsigned ResNo) const { 1222 assert(ResNo < NumValues && "Illegal result number!"); 1223 return ValueList[ResNo]; 1224 } 1225 1226 /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)). 1227 /// 1228 unsigned getValueSizeInBits(unsigned ResNo) const { 1229 return getValueType(ResNo).getSizeInBits(); 1230 } 1231 1232 typedef const MVT* value_iterator; 1233 value_iterator value_begin() const { return ValueList; } 1234 value_iterator value_end() const { return ValueList+NumValues; } 1235 1236 /// getOperationName - Return the opcode of this operation for printing. 1237 /// 1238 std::string getOperationName(const SelectionDAG *G = 0) const; 1239 static const char* getIndexedModeName(ISD::MemIndexedMode AM); 1240 void dump() const; 1241 void dump(const SelectionDAG *G) const; 1242 1243 static bool classof(const SDNode *) { return true; } 1244 1245 /// Profile - Gather unique data for the node. 1246 /// 1247 void Profile(FoldingSetNodeID &ID); 1248 1249protected: 1250 friend class SelectionDAG; 1251 1252 /// getValueTypeList - Return a pointer to the specified value type. 1253 /// 1254 static const MVT *getValueTypeList(MVT VT); 1255 static SDVTList getSDVTList(MVT VT) { 1256 SDVTList Ret = { getValueTypeList(VT), 1 }; 1257 return Ret; 1258 } 1259 1260 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps) 1261 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) { 1262 OperandsNeedDelete = true; 1263 NumOperands = NumOps; 1264 OperandList = NumOps ? new SDUse[NumOperands] : 0; 1265 1266 for (unsigned i = 0; i != NumOps; ++i) { 1267 OperandList[i] = Ops[i]; 1268 OperandList[i].setUser(this); 1269 Ops[i].Val->addUse(OperandList[i]); 1270 ++Ops[i].Val->UsesSize; 1271 } 1272 1273 ValueList = VTs.VTs; 1274 NumValues = VTs.NumVTs; 1275 Prev = 0; Next = 0; 1276 } 1277 1278 SDNode(unsigned Opc, SDVTList VTs, SDOperandPtr Ops, unsigned NumOps) 1279 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) { 1280 OperandsNeedDelete = true; 1281 NumOperands = NumOps; 1282 OperandList = NumOps ? new SDUse[NumOperands] : 0; 1283 1284 for (unsigned i = 0; i != NumOps; ++i) { 1285 OperandList[i] = Ops[i]; 1286 OperandList[i].setUser(this); 1287 Ops[i].Val->addUse(OperandList[i]); 1288 ++Ops[i].Val->UsesSize; 1289 } 1290 1291 ValueList = VTs.VTs; 1292 NumValues = VTs.NumVTs; 1293 Prev = 0; Next = 0; 1294 } 1295 1296 SDNode(unsigned Opc, SDVTList VTs) 1297 : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) { 1298 OperandsNeedDelete = false; // Operands set with InitOperands. 1299 NumOperands = 0; 1300 OperandList = 0; 1301 ValueList = VTs.VTs; 1302 NumValues = VTs.NumVTs; 1303 Prev = 0; Next = 0; 1304 } 1305 1306 /// InitOperands - Initialize the operands list of this node with the 1307 /// specified values, which are part of the node (thus they don't need to be 1308 /// copied in or allocated). 1309 void InitOperands(SDUse *Ops, unsigned NumOps) { 1310 assert(OperandList == 0 && "Operands already set!"); 1311 NumOperands = NumOps; 1312 OperandList = Ops; 1313 UsesSize = 0; 1314 Uses = NULL; 1315 1316 for (unsigned i = 0; i != NumOps; ++i) { 1317 OperandList[i].setUser(this); 1318 Ops[i].getVal()->addUse(OperandList[i]); 1319 ++Ops[i].getVal()->UsesSize; 1320 } 1321 } 1322 1323 /// MorphNodeTo - This frees the operands of the current node, resets the 1324 /// opcode, types, and operands to the specified value. This should only be 1325 /// used by the SelectionDAG class. 1326 void MorphNodeTo(unsigned Opc, SDVTList L, 1327 SDOperandPtr Ops, unsigned NumOps); 1328 1329 void addUser(unsigned i, SDNode *User) { 1330 assert(User->OperandList[i].getUser() && "Node without parent"); 1331 addUse(User->OperandList[i]); 1332 ++UsesSize; 1333 } 1334 1335 void removeUser(unsigned i, SDNode *User) { 1336 assert(User->OperandList[i].getUser() && "Node without parent"); 1337 SDUse &Op = User->OperandList[i]; 1338 Op.removeFromList(); 1339 --UsesSize; 1340 } 1341}; 1342 1343 1344// Define inline functions from the SDOperand class. 1345 1346inline unsigned SDOperand::getOpcode() const { 1347 return Val->getOpcode(); 1348} 1349inline MVT SDOperand::getValueType() const { 1350 return Val->getValueType(ResNo); 1351} 1352inline unsigned SDOperand::getNumOperands() const { 1353 return Val->getNumOperands(); 1354} 1355inline const SDOperand &SDOperand::getOperand(unsigned i) const { 1356 return Val->getOperand(i); 1357} 1358inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const { 1359 return Val->getConstantOperandVal(i); 1360} 1361inline bool SDOperand::isTargetOpcode() const { 1362 return Val->isTargetOpcode(); 1363} 1364inline unsigned SDOperand::getTargetOpcode() const { 1365 return Val->getTargetOpcode(); 1366} 1367inline bool SDOperand::hasOneUse() const { 1368 return Val->hasNUsesOfValue(1, ResNo); 1369} 1370inline bool SDOperand::use_empty() const { 1371 return !Val->hasAnyUseOfValue(ResNo); 1372} 1373 1374/// UnarySDNode - This class is used for single-operand SDNodes. This is solely 1375/// to allow co-allocation of node operands with the node itself. 1376class UnarySDNode : public SDNode { 1377 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1378 SDUse Op; 1379public: 1380 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X) 1381 : SDNode(Opc, VTs) { 1382 Op = X; 1383 InitOperands(&Op, 1); 1384 } 1385}; 1386 1387/// BinarySDNode - This class is used for two-operand SDNodes. This is solely 1388/// to allow co-allocation of node operands with the node itself. 1389class BinarySDNode : public SDNode { 1390 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1391 SDUse Ops[2]; 1392public: 1393 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y) 1394 : SDNode(Opc, VTs) { 1395 Ops[0] = X; 1396 Ops[1] = Y; 1397 InitOperands(Ops, 2); 1398 } 1399}; 1400 1401/// TernarySDNode - This class is used for three-operand SDNodes. This is solely 1402/// to allow co-allocation of node operands with the node itself. 1403class TernarySDNode : public SDNode { 1404 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1405 SDUse Ops[3]; 1406public: 1407 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y, 1408 SDOperand Z) 1409 : SDNode(Opc, VTs) { 1410 Ops[0] = X; 1411 Ops[1] = Y; 1412 Ops[2] = Z; 1413 InitOperands(Ops, 3); 1414 } 1415}; 1416 1417 1418/// HandleSDNode - This class is used to form a handle around another node that 1419/// is persistant and is updated across invocations of replaceAllUsesWith on its 1420/// operand. This node should be directly created by end-users and not added to 1421/// the AllNodes list. 1422class HandleSDNode : public SDNode { 1423 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1424 SDUse Op; 1425public: 1426 // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is 1427 // fixed. 1428#ifdef __GNUC__ 1429 explicit __attribute__((__noinline__)) HandleSDNode(SDOperand X) 1430#else 1431 explicit HandleSDNode(SDOperand X) 1432#endif 1433 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) { 1434 Op = X; 1435 InitOperands(&Op, 1); 1436 } 1437 ~HandleSDNode(); 1438 SDUse getValue() const { return Op; } 1439}; 1440 1441/// Abstact virtual class for operations for memory operations 1442class MemSDNode : public SDNode { 1443 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1444 1445private: 1446 //! SrcValue - Memory location for alias analysis. 1447 const Value *SrcValue; 1448 1449 //! Alignment - Alignment of memory location in bytes. 1450 unsigned Alignment; 1451 1452public: 1453 MemSDNode(unsigned Opc, SDVTList VTs, const Value *srcValue, 1454 unsigned alignment) 1455 : SDNode(Opc, VTs), SrcValue(srcValue), Alignment(alignment) {} 1456 1457 virtual ~MemSDNode() {} 1458 1459 /// Returns alignment and volatility of the memory access 1460 unsigned getAlignment() const { return Alignment; } 1461 virtual bool isVolatile() const = 0; 1462 1463 /// Returns the SrcValue and offset that describes the location of the access 1464 const Value *getSrcValue() const { return SrcValue; } 1465 virtual int getSrcValueOffset() const = 0; 1466 1467 /// getMemOperand - Return a MachineMemOperand object describing the memory 1468 /// reference performed by operation. 1469 virtual MachineMemOperand getMemOperand() const = 0; 1470 1471 // Methods to support isa and dyn_cast 1472 static bool classof(const MemSDNode *) { return true; } 1473 static bool classof(const SDNode *N) { 1474 return N->getOpcode() == ISD::LOAD || 1475 N->getOpcode() == ISD::STORE || 1476 N->getOpcode() == ISD::ATOMIC_CMP_SWAP || 1477 N->getOpcode() == ISD::ATOMIC_LOAD_ADD || 1478 N->getOpcode() == ISD::ATOMIC_SWAP || 1479 N->getOpcode() == ISD::ATOMIC_LOAD_SUB || 1480 N->getOpcode() == ISD::ATOMIC_LOAD_AND || 1481 N->getOpcode() == ISD::ATOMIC_LOAD_OR || 1482 N->getOpcode() == ISD::ATOMIC_LOAD_XOR || 1483 N->getOpcode() == ISD::ATOMIC_LOAD_NAND || 1484 N->getOpcode() == ISD::ATOMIC_LOAD_MIN || 1485 N->getOpcode() == ISD::ATOMIC_LOAD_MAX || 1486 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN || 1487 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX; 1488 } 1489}; 1490 1491/// Atomic operations node 1492class AtomicSDNode : public MemSDNode { 1493 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1494 SDUse Ops[4]; 1495 1496 public: 1497 // Opc: opcode for atomic 1498 // VTL: value type list 1499 // Chain: memory chain for operaand 1500 // Ptr: address to update as a SDOperand 1501 // Cmp: compare value 1502 // Swp: swap value 1503 // SrcVal: address to update as a Value (used for MemOperand) 1504 // Align: alignment of memory 1505 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 1506 SDOperand Cmp, SDOperand Swp, const Value* SrcVal, 1507 unsigned Align=0) 1508 : MemSDNode(Opc, VTL, SrcVal, Align) { 1509 Ops[0] = Chain; 1510 Ops[1] = Ptr; 1511 Ops[2] = Swp; 1512 Ops[3] = Cmp; 1513 InitOperands(Ops, 4); 1514 } 1515 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 1516 SDOperand Val, const Value* SrcVal, unsigned Align=0) 1517 : MemSDNode(Opc, VTL, SrcVal, Align) { 1518 Ops[0] = Chain; 1519 Ops[1] = Ptr; 1520 Ops[2] = Val; 1521 InitOperands(Ops, 3); 1522 } 1523 1524 const SDOperand &getChain() const { return getOperand(0); } 1525 const SDOperand &getBasePtr() const { return getOperand(1); } 1526 const SDOperand &getVal() const { return getOperand(2); } 1527 1528 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_CMP_SWAP; } 1529 1530 // Implementation for MemSDNode 1531 virtual int getSrcValueOffset() const { return 0; } 1532 virtual bool isVolatile() const { return true; } 1533 1534 /// getMemOperand - Return a MachineMemOperand object describing the memory 1535 /// reference performed by this atomic load/store. 1536 virtual MachineMemOperand getMemOperand() const; 1537 1538 // Methods to support isa and dyn_cast 1539 static bool classof(const AtomicSDNode *) { return true; } 1540 static bool classof(const SDNode *N) { 1541 return N->getOpcode() == ISD::ATOMIC_CMP_SWAP || 1542 N->getOpcode() == ISD::ATOMIC_LOAD_ADD || 1543 N->getOpcode() == ISD::ATOMIC_SWAP || 1544 N->getOpcode() == ISD::ATOMIC_LOAD_SUB || 1545 N->getOpcode() == ISD::ATOMIC_LOAD_AND || 1546 N->getOpcode() == ISD::ATOMIC_LOAD_OR || 1547 N->getOpcode() == ISD::ATOMIC_LOAD_XOR || 1548 N->getOpcode() == ISD::ATOMIC_LOAD_NAND || 1549 N->getOpcode() == ISD::ATOMIC_LOAD_MIN || 1550 N->getOpcode() == ISD::ATOMIC_LOAD_MAX || 1551 N->getOpcode() == ISD::ATOMIC_LOAD_UMIN || 1552 N->getOpcode() == ISD::ATOMIC_LOAD_UMAX; 1553 } 1554}; 1555 1556class ConstantSDNode : public SDNode { 1557 APInt Value; 1558 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1559protected: 1560 friend class SelectionDAG; 1561 ConstantSDNode(bool isTarget, const APInt &val, MVT VT) 1562 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)), 1563 Value(val) { 1564 } 1565public: 1566 1567 const APInt &getAPIntValue() const { return Value; } 1568 uint64_t getValue() const { return Value.getZExtValue(); } 1569 1570 int64_t getSignExtended() const { 1571 unsigned Bits = getValueType(0).getSizeInBits(); 1572 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits); 1573 } 1574 1575 bool isNullValue() const { return Value == 0; } 1576 bool isAllOnesValue() const { 1577 return Value == getValueType(0).getIntegerVTBitMask(); 1578 } 1579 1580 static bool classof(const ConstantSDNode *) { return true; } 1581 static bool classof(const SDNode *N) { 1582 return N->getOpcode() == ISD::Constant || 1583 N->getOpcode() == ISD::TargetConstant; 1584 } 1585}; 1586 1587class ConstantFPSDNode : public SDNode { 1588 APFloat Value; 1589 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1590protected: 1591 friend class SelectionDAG; 1592 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT VT) 1593 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 1594 getSDVTList(VT)), Value(val) { 1595 } 1596public: 1597 1598 const APFloat& getValueAPF() const { return Value; } 1599 1600 /// isExactlyValue - We don't rely on operator== working on double values, as 1601 /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 1602 /// As such, this method can be used to do an exact bit-for-bit comparison of 1603 /// two floating point values. 1604 1605 /// We leave the version with the double argument here because it's just so 1606 /// convenient to write "2.0" and the like. Without this function we'd 1607 /// have to duplicate its logic everywhere it's called. 1608 bool isExactlyValue(double V) const { 1609 // convert is not supported on this type 1610 if (&Value.getSemantics() == &APFloat::PPCDoubleDouble) 1611 return false; 1612 APFloat Tmp(V); 1613 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven); 1614 return isExactlyValue(Tmp); 1615 } 1616 bool isExactlyValue(const APFloat& V) const; 1617 1618 bool isValueValidForType(MVT VT, const APFloat& Val); 1619 1620 static bool classof(const ConstantFPSDNode *) { return true; } 1621 static bool classof(const SDNode *N) { 1622 return N->getOpcode() == ISD::ConstantFP || 1623 N->getOpcode() == ISD::TargetConstantFP; 1624 } 1625}; 1626 1627class GlobalAddressSDNode : public SDNode { 1628 GlobalValue *TheGlobal; 1629 int Offset; 1630 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1631protected: 1632 friend class SelectionDAG; 1633 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT VT, int o = 0); 1634public: 1635 1636 GlobalValue *getGlobal() const { return TheGlobal; } 1637 int getOffset() const { return Offset; } 1638 1639 static bool classof(const GlobalAddressSDNode *) { return true; } 1640 static bool classof(const SDNode *N) { 1641 return N->getOpcode() == ISD::GlobalAddress || 1642 N->getOpcode() == ISD::TargetGlobalAddress || 1643 N->getOpcode() == ISD::GlobalTLSAddress || 1644 N->getOpcode() == ISD::TargetGlobalTLSAddress; 1645 } 1646}; 1647 1648class FrameIndexSDNode : public SDNode { 1649 int FI; 1650 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1651protected: 1652 friend class SelectionDAG; 1653 FrameIndexSDNode(int fi, MVT VT, bool isTarg) 1654 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)), 1655 FI(fi) { 1656 } 1657public: 1658 1659 int getIndex() const { return FI; } 1660 1661 static bool classof(const FrameIndexSDNode *) { return true; } 1662 static bool classof(const SDNode *N) { 1663 return N->getOpcode() == ISD::FrameIndex || 1664 N->getOpcode() == ISD::TargetFrameIndex; 1665 } 1666}; 1667 1668class JumpTableSDNode : public SDNode { 1669 int JTI; 1670 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1671protected: 1672 friend class SelectionDAG; 1673 JumpTableSDNode(int jti, MVT VT, bool isTarg) 1674 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)), 1675 JTI(jti) { 1676 } 1677public: 1678 1679 int getIndex() const { return JTI; } 1680 1681 static bool classof(const JumpTableSDNode *) { return true; } 1682 static bool classof(const SDNode *N) { 1683 return N->getOpcode() == ISD::JumpTable || 1684 N->getOpcode() == ISD::TargetJumpTable; 1685 } 1686}; 1687 1688class ConstantPoolSDNode : public SDNode { 1689 union { 1690 Constant *ConstVal; 1691 MachineConstantPoolValue *MachineCPVal; 1692 } Val; 1693 int Offset; // It's a MachineConstantPoolValue if top bit is set. 1694 unsigned Alignment; 1695 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1696protected: 1697 friend class SelectionDAG; 1698 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o=0) 1699 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1700 getSDVTList(VT)), Offset(o), Alignment(0) { 1701 assert((int)Offset >= 0 && "Offset is too large"); 1702 Val.ConstVal = c; 1703 } 1704 ConstantPoolSDNode(bool isTarget, Constant *c, MVT VT, int o, unsigned Align) 1705 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1706 getSDVTList(VT)), Offset(o), Alignment(Align) { 1707 assert((int)Offset >= 0 && "Offset is too large"); 1708 Val.ConstVal = c; 1709 } 1710 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, 1711 MVT VT, int o=0) 1712 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1713 getSDVTList(VT)), Offset(o), Alignment(0) { 1714 assert((int)Offset >= 0 && "Offset is too large"); 1715 Val.MachineCPVal = v; 1716 Offset |= 1 << (sizeof(unsigned)*8-1); 1717 } 1718 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, 1719 MVT VT, int o, unsigned Align) 1720 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1721 getSDVTList(VT)), Offset(o), Alignment(Align) { 1722 assert((int)Offset >= 0 && "Offset is too large"); 1723 Val.MachineCPVal = v; 1724 Offset |= 1 << (sizeof(unsigned)*8-1); 1725 } 1726public: 1727 1728 bool isMachineConstantPoolEntry() const { 1729 return (int)Offset < 0; 1730 } 1731 1732 Constant *getConstVal() const { 1733 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type"); 1734 return Val.ConstVal; 1735 } 1736 1737 MachineConstantPoolValue *getMachineCPVal() const { 1738 assert(isMachineConstantPoolEntry() && "Wrong constantpool type"); 1739 return Val.MachineCPVal; 1740 } 1741 1742 int getOffset() const { 1743 return Offset & ~(1 << (sizeof(unsigned)*8-1)); 1744 } 1745 1746 // Return the alignment of this constant pool object, which is either 0 (for 1747 // default alignment) or log2 of the desired value. 1748 unsigned getAlignment() const { return Alignment; } 1749 1750 const Type *getType() const; 1751 1752 static bool classof(const ConstantPoolSDNode *) { return true; } 1753 static bool classof(const SDNode *N) { 1754 return N->getOpcode() == ISD::ConstantPool || 1755 N->getOpcode() == ISD::TargetConstantPool; 1756 } 1757}; 1758 1759class BasicBlockSDNode : public SDNode { 1760 MachineBasicBlock *MBB; 1761 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1762protected: 1763 friend class SelectionDAG; 1764 explicit BasicBlockSDNode(MachineBasicBlock *mbb) 1765 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) { 1766 } 1767public: 1768 1769 MachineBasicBlock *getBasicBlock() const { return MBB; } 1770 1771 static bool classof(const BasicBlockSDNode *) { return true; } 1772 static bool classof(const SDNode *N) { 1773 return N->getOpcode() == ISD::BasicBlock; 1774 } 1775}; 1776 1777/// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is 1778/// used when the SelectionDAG needs to make a simple reference to something 1779/// in the LLVM IR representation. 1780/// 1781/// Note that this is not used for carrying alias information; that is done 1782/// with MemOperandSDNode, which includes a Value which is required to be a 1783/// pointer, and several other fields specific to memory references. 1784/// 1785class SrcValueSDNode : public SDNode { 1786 const Value *V; 1787 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1788protected: 1789 friend class SelectionDAG; 1790 /// Create a SrcValue for a general value. 1791 explicit SrcValueSDNode(const Value *v) 1792 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {} 1793 1794public: 1795 /// getValue - return the contained Value. 1796 const Value *getValue() const { return V; } 1797 1798 static bool classof(const SrcValueSDNode *) { return true; } 1799 static bool classof(const SDNode *N) { 1800 return N->getOpcode() == ISD::SRCVALUE; 1801 } 1802}; 1803 1804 1805/// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is 1806/// used to represent a reference to memory after ISD::LOAD 1807/// and ISD::STORE have been lowered. 1808/// 1809class MemOperandSDNode : public SDNode { 1810 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1811protected: 1812 friend class SelectionDAG; 1813 /// Create a MachineMemOperand node 1814 explicit MemOperandSDNode(const MachineMemOperand &mo) 1815 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {} 1816 1817public: 1818 /// MO - The contained MachineMemOperand. 1819 const MachineMemOperand MO; 1820 1821 static bool classof(const MemOperandSDNode *) { return true; } 1822 static bool classof(const SDNode *N) { 1823 return N->getOpcode() == ISD::MEMOPERAND; 1824 } 1825}; 1826 1827 1828class RegisterSDNode : public SDNode { 1829 unsigned Reg; 1830 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1831protected: 1832 friend class SelectionDAG; 1833 RegisterSDNode(unsigned reg, MVT VT) 1834 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) { 1835 } 1836public: 1837 1838 unsigned getReg() const { return Reg; } 1839 1840 static bool classof(const RegisterSDNode *) { return true; } 1841 static bool classof(const SDNode *N) { 1842 return N->getOpcode() == ISD::Register; 1843 } 1844}; 1845 1846class DbgStopPointSDNode : public SDNode { 1847 SDUse Chain; 1848 unsigned Line; 1849 unsigned Column; 1850 const CompileUnitDesc *CU; 1851 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1852protected: 1853 friend class SelectionDAG; 1854 DbgStopPointSDNode(SDOperand ch, unsigned l, unsigned c, 1855 const CompileUnitDesc *cu) 1856 : SDNode(ISD::DBG_STOPPOINT, getSDVTList(MVT::Other)), 1857 Line(l), Column(c), CU(cu) { 1858 Chain = ch; 1859 InitOperands(&Chain, 1); 1860 } 1861public: 1862 1863 unsigned getLine() const { return Line; } 1864 unsigned getColumn() const { return Column; } 1865 const CompileUnitDesc *getCompileUnit() const { return CU; } 1866 1867 static bool classof(const DbgStopPointSDNode *) { return true; } 1868 static bool classof(const SDNode *N) { 1869 return N->getOpcode() == ISD::DBG_STOPPOINT; 1870 } 1871}; 1872 1873class ExternalSymbolSDNode : public SDNode { 1874 const char *Symbol; 1875 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1876protected: 1877 friend class SelectionDAG; 1878 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT VT) 1879 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 1880 getSDVTList(VT)), Symbol(Sym) { 1881 } 1882public: 1883 1884 const char *getSymbol() const { return Symbol; } 1885 1886 static bool classof(const ExternalSymbolSDNode *) { return true; } 1887 static bool classof(const SDNode *N) { 1888 return N->getOpcode() == ISD::ExternalSymbol || 1889 N->getOpcode() == ISD::TargetExternalSymbol; 1890 } 1891}; 1892 1893class CondCodeSDNode : public SDNode { 1894 ISD::CondCode Condition; 1895 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1896protected: 1897 friend class SelectionDAG; 1898 explicit CondCodeSDNode(ISD::CondCode Cond) 1899 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) { 1900 } 1901public: 1902 1903 ISD::CondCode get() const { return Condition; } 1904 1905 static bool classof(const CondCodeSDNode *) { return true; } 1906 static bool classof(const SDNode *N) { 1907 return N->getOpcode() == ISD::CONDCODE; 1908 } 1909}; 1910 1911namespace ISD { 1912 struct ArgFlagsTy { 1913 private: 1914 static const uint64_t NoFlagSet = 0ULL; 1915 static const uint64_t ZExt = 1ULL<<0; ///< Zero extended 1916 static const uint64_t ZExtOffs = 0; 1917 static const uint64_t SExt = 1ULL<<1; ///< Sign extended 1918 static const uint64_t SExtOffs = 1; 1919 static const uint64_t InReg = 1ULL<<2; ///< Passed in register 1920 static const uint64_t InRegOffs = 2; 1921 static const uint64_t SRet = 1ULL<<3; ///< Hidden struct-ret ptr 1922 static const uint64_t SRetOffs = 3; 1923 static const uint64_t ByVal = 1ULL<<4; ///< Struct passed by value 1924 static const uint64_t ByValOffs = 4; 1925 static const uint64_t Nest = 1ULL<<5; ///< Nested fn static chain 1926 static const uint64_t NestOffs = 5; 1927 static const uint64_t ByValAlign = 0xFULL << 6; //< Struct alignment 1928 static const uint64_t ByValAlignOffs = 6; 1929 static const uint64_t Split = 1ULL << 10; 1930 static const uint64_t SplitOffs = 10; 1931 static const uint64_t OrigAlign = 0x1FULL<<27; 1932 static const uint64_t OrigAlignOffs = 27; 1933 static const uint64_t ByValSize = 0xffffffffULL << 32; //< Struct size 1934 static const uint64_t ByValSizeOffs = 32; 1935 1936 static const uint64_t One = 1ULL; //< 1 of this type, for shifts 1937 1938 uint64_t Flags; 1939 public: 1940 ArgFlagsTy() : Flags(0) { } 1941 1942 bool isZExt() const { return Flags & ZExt; } 1943 void setZExt() { Flags |= One << ZExtOffs; } 1944 1945 bool isSExt() const { return Flags & SExt; } 1946 void setSExt() { Flags |= One << SExtOffs; } 1947 1948 bool isInReg() const { return Flags & InReg; } 1949 void setInReg() { Flags |= One << InRegOffs; } 1950 1951 bool isSRet() const { return Flags & SRet; } 1952 void setSRet() { Flags |= One << SRetOffs; } 1953 1954 bool isByVal() const { return Flags & ByVal; } 1955 void setByVal() { Flags |= One << ByValOffs; } 1956 1957 bool isNest() const { return Flags & Nest; } 1958 void setNest() { Flags |= One << NestOffs; } 1959 1960 unsigned getByValAlign() const { 1961 return (unsigned) 1962 ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2); 1963 } 1964 void setByValAlign(unsigned A) { 1965 Flags = (Flags & ~ByValAlign) | 1966 (uint64_t(Log2_32(A) + 1) << ByValAlignOffs); 1967 } 1968 1969 bool isSplit() const { return Flags & Split; } 1970 void setSplit() { Flags |= One << SplitOffs; } 1971 1972 unsigned getOrigAlign() const { 1973 return (unsigned) 1974 ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2); 1975 } 1976 void setOrigAlign(unsigned A) { 1977 Flags = (Flags & ~OrigAlign) | 1978 (uint64_t(Log2_32(A) + 1) << OrigAlignOffs); 1979 } 1980 1981 unsigned getByValSize() const { 1982 return (unsigned)((Flags & ByValSize) >> ByValSizeOffs); 1983 } 1984 void setByValSize(unsigned S) { 1985 Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs); 1986 } 1987 1988 /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4". 1989 std::string getArgFlagsString(); 1990 1991 /// getRawBits - Represent the flags as a bunch of bits. 1992 uint64_t getRawBits() const { return Flags; } 1993 }; 1994} 1995 1996/// ARG_FLAGSSDNode - Leaf node holding parameter flags. 1997class ARG_FLAGSSDNode : public SDNode { 1998 ISD::ArgFlagsTy TheFlags; 1999 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 2000protected: 2001 friend class SelectionDAG; 2002 explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags) 2003 : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) { 2004 } 2005public: 2006 ISD::ArgFlagsTy getArgFlags() const { return TheFlags; } 2007 2008 static bool classof(const ARG_FLAGSSDNode *) { return true; } 2009 static bool classof(const SDNode *N) { 2010 return N->getOpcode() == ISD::ARG_FLAGS; 2011 } 2012}; 2013 2014/// VTSDNode - This class is used to represent MVT's, which are used 2015/// to parameterize some operations. 2016class VTSDNode : public SDNode { 2017 MVT ValueType; 2018 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 2019protected: 2020 friend class SelectionDAG; 2021 explicit VTSDNode(MVT VT) 2022 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) { 2023 } 2024public: 2025 2026 MVT getVT() const { return ValueType; } 2027 2028 static bool classof(const VTSDNode *) { return true; } 2029 static bool classof(const SDNode *N) { 2030 return N->getOpcode() == ISD::VALUETYPE; 2031 } 2032}; 2033 2034/// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode 2035/// 2036class LSBaseSDNode : public MemSDNode { 2037private: 2038 // AddrMode - unindexed, pre-indexed, post-indexed. 2039 ISD::MemIndexedMode AddrMode; 2040 2041 // MemoryVT - VT of in-memory value. 2042 MVT MemoryVT; 2043 2044 //! SVOffset - Memory location offset. Note that base is defined in MemSDNode 2045 int SVOffset; 2046 2047 //! IsVolatile - True if the load/store is volatile. 2048 bool IsVolatile; 2049 2050protected: 2051 //! Operand array for load and store 2052 /*! 2053 \note Moving this array to the base class captures more 2054 common functionality shared between LoadSDNode and 2055 StoreSDNode 2056 */ 2057 SDUse Ops[4]; 2058public: 2059 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned numOperands, 2060 SDVTList VTs, ISD::MemIndexedMode AM, MVT VT, 2061 const Value *SV, int SVO, unsigned Align, bool Vol) 2062 : MemSDNode(NodeTy, VTs, SV, Align), AddrMode(AM), MemoryVT(VT), 2063 SVOffset(SVO), IsVolatile(Vol) { 2064 for (unsigned i = 0; i != numOperands; ++i) 2065 Ops[i] = Operands[i]; 2066 InitOperands(Ops, numOperands); 2067 assert(Align != 0 && "Loads and stores should have non-zero aligment"); 2068 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) && 2069 "Only indexed loads and stores have a non-undef offset operand"); 2070 } 2071 2072 const SDOperand &getChain() const { return getOperand(0); } 2073 const SDOperand &getBasePtr() const { 2074 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2); 2075 } 2076 const SDOperand &getOffset() const { 2077 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3); 2078 } 2079 2080 MVT getMemoryVT() const { return MemoryVT; } 2081 2082 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; } 2083 2084 /// isIndexed - Return true if this is a pre/post inc/dec load/store. 2085 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; } 2086 2087 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store. 2088 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; } 2089 2090 // Implementation for MemSDNode 2091 virtual int getSrcValueOffset() const { return SVOffset; } 2092 virtual bool isVolatile() const { return IsVolatile; } 2093 2094 /// getMemOperand - Return a MachineMemOperand object describing the memory 2095 /// reference performed by this load or store. 2096 virtual MachineMemOperand getMemOperand() const; 2097 2098 static bool classof(const LSBaseSDNode *) { return true; } 2099 static bool classof(const SDNode *N) { 2100 return N->getOpcode() == ISD::LOAD || 2101 N->getOpcode() == ISD::STORE; 2102 } 2103}; 2104 2105/// LoadSDNode - This class is used to represent ISD::LOAD nodes. 2106/// 2107class LoadSDNode : public LSBaseSDNode { 2108 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 2109 2110 // ExtType - non-ext, anyext, sext, zext. 2111 ISD::LoadExtType ExtType; 2112 2113protected: 2114 friend class SelectionDAG; 2115 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs, 2116 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT LVT, 2117 const Value *SV, int O=0, unsigned Align=0, bool Vol=false) 2118 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3, 2119 VTs, AM, LVT, SV, O, Align, Vol), 2120 ExtType(ETy) {} 2121public: 2122 2123 ISD::LoadExtType getExtensionType() const { return ExtType; } 2124 const SDOperand &getBasePtr() const { return getOperand(1); } 2125 const SDOperand &getOffset() const { return getOperand(2); } 2126 2127 static bool classof(const LoadSDNode *) { return true; } 2128 static bool classof(const SDNode *N) { 2129 return N->getOpcode() == ISD::LOAD; 2130 } 2131}; 2132 2133/// StoreSDNode - This class is used to represent ISD::STORE nodes. 2134/// 2135class StoreSDNode : public LSBaseSDNode { 2136 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 2137 2138 // IsTruncStore - True if the op does a truncation before store. 2139 bool IsTruncStore; 2140protected: 2141 friend class SelectionDAG; 2142 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs, 2143 ISD::MemIndexedMode AM, bool isTrunc, MVT SVT, 2144 const Value *SV, int O=0, unsigned Align=0, bool Vol=false) 2145 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4, 2146 VTs, AM, SVT, SV, O, Align, Vol), 2147 IsTruncStore(isTrunc) {} 2148public: 2149 2150 bool isTruncatingStore() const { return IsTruncStore; } 2151 const SDOperand &getValue() const { return getOperand(1); } 2152 const SDOperand &getBasePtr() const { return getOperand(2); } 2153 const SDOperand &getOffset() const { return getOperand(3); } 2154 2155 static bool classof(const StoreSDNode *) { return true; } 2156 static bool classof(const SDNode *N) { 2157 return N->getOpcode() == ISD::STORE; 2158 } 2159}; 2160 2161 2162class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { 2163 SDNode *Node; 2164 unsigned Operand; 2165 2166 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} 2167public: 2168 bool operator==(const SDNodeIterator& x) const { 2169 return Operand == x.Operand; 2170 } 2171 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } 2172 2173 const SDNodeIterator &operator=(const SDNodeIterator &I) { 2174 assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); 2175 Operand = I.Operand; 2176 return *this; 2177 } 2178 2179 pointer operator*() const { 2180 return Node->getOperand(Operand).Val; 2181 } 2182 pointer operator->() const { return operator*(); } 2183 2184 SDNodeIterator& operator++() { // Preincrement 2185 ++Operand; 2186 return *this; 2187 } 2188 SDNodeIterator operator++(int) { // Postincrement 2189 SDNodeIterator tmp = *this; ++*this; return tmp; 2190 } 2191 2192 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } 2193 static SDNodeIterator end (SDNode *N) { 2194 return SDNodeIterator(N, N->getNumOperands()); 2195 } 2196 2197 unsigned getOperand() const { return Operand; } 2198 const SDNode *getNode() const { return Node; } 2199}; 2200 2201template <> struct GraphTraits<SDNode*> { 2202 typedef SDNode NodeType; 2203 typedef SDNodeIterator ChildIteratorType; 2204 static inline NodeType *getEntryNode(SDNode *N) { return N; } 2205 static inline ChildIteratorType child_begin(NodeType *N) { 2206 return SDNodeIterator::begin(N); 2207 } 2208 static inline ChildIteratorType child_end(NodeType *N) { 2209 return SDNodeIterator::end(N); 2210 } 2211}; 2212 2213template<> 2214struct ilist_traits<SDNode> { 2215 static SDNode *getPrev(const SDNode *N) { return N->Prev; } 2216 static SDNode *getNext(const SDNode *N) { return N->Next; } 2217 2218 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; } 2219 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; } 2220 2221 static SDNode *createSentinel() { 2222 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other)); 2223 } 2224 static void destroySentinel(SDNode *N) { delete N; } 2225 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); } 2226 2227 2228 void addNodeToList(SDNode *) {} 2229 void removeNodeFromList(SDNode *) {} 2230 void transferNodesFromList(iplist<SDNode, ilist_traits> &, 2231 const ilist_iterator<SDNode> &, 2232 const ilist_iterator<SDNode> &) {} 2233}; 2234 2235namespace ISD { 2236 /// isNormalLoad - Returns true if the specified node is a non-extending 2237 /// and unindexed load. 2238 inline bool isNormalLoad(const SDNode *N) { 2239 const LoadSDNode *Ld = dyn_cast<LoadSDNode>(N); 2240 return Ld && Ld->getExtensionType() == ISD::NON_EXTLOAD && 2241 Ld->getAddressingMode() == ISD::UNINDEXED; 2242 } 2243 2244 /// isNON_EXTLoad - Returns true if the specified node is a non-extending 2245 /// load. 2246 inline bool isNON_EXTLoad(const SDNode *N) { 2247 return isa<LoadSDNode>(N) && 2248 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD; 2249 } 2250 2251 /// isEXTLoad - Returns true if the specified node is a EXTLOAD. 2252 /// 2253 inline bool isEXTLoad(const SDNode *N) { 2254 return isa<LoadSDNode>(N) && 2255 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD; 2256 } 2257 2258 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD. 2259 /// 2260 inline bool isSEXTLoad(const SDNode *N) { 2261 return isa<LoadSDNode>(N) && 2262 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD; 2263 } 2264 2265 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD. 2266 /// 2267 inline bool isZEXTLoad(const SDNode *N) { 2268 return isa<LoadSDNode>(N) && 2269 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD; 2270 } 2271 2272 /// isUNINDEXEDLoad - Returns true if the specified node is an unindexed load. 2273 /// 2274 inline bool isUNINDEXEDLoad(const SDNode *N) { 2275 return isa<LoadSDNode>(N) && 2276 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED; 2277 } 2278 2279 /// isNormalStore - Returns true if the specified node is a non-truncating 2280 /// and unindexed store. 2281 inline bool isNormalStore(const SDNode *N) { 2282 const StoreSDNode *St = dyn_cast<StoreSDNode>(N); 2283 return St && !St->isTruncatingStore() && 2284 St->getAddressingMode() == ISD::UNINDEXED; 2285 } 2286 2287 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating 2288 /// store. 2289 inline bool isNON_TRUNCStore(const SDNode *N) { 2290 return isa<StoreSDNode>(N) && !cast<StoreSDNode>(N)->isTruncatingStore(); 2291 } 2292 2293 /// isTRUNCStore - Returns true if the specified node is a truncating 2294 /// store. 2295 inline bool isTRUNCStore(const SDNode *N) { 2296 return isa<StoreSDNode>(N) && cast<StoreSDNode>(N)->isTruncatingStore(); 2297 } 2298 2299 /// isUNINDEXEDStore - Returns true if the specified node is an 2300 /// unindexed store. 2301 inline bool isUNINDEXEDStore(const SDNode *N) { 2302 return isa<StoreSDNode>(N) && 2303 cast<StoreSDNode>(N)->getAddressingMode() == ISD::UNINDEXED; 2304 } 2305} 2306 2307 2308} // end llvm namespace 2309 2310#endif 2311