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