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