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