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