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