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