SelectionDAGNodes.h revision c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271
1//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file declares the SDNode class and derived classes, which are used to 11// represent the nodes and operations present in a SelectionDAG. These nodes 12// and operations are machine code level operations, with some similarities to 13// the GCC RTL representation. 14// 15// Clients should include the SelectionDAG.h file instead of this file directly. 16// 17//===----------------------------------------------------------------------===// 18 19#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H 20#define LLVM_CODEGEN_SELECTIONDAGNODES_H 21 22#include "llvm/Value.h" 23#include "llvm/ADT/FoldingSet.h" 24#include "llvm/ADT/GraphTraits.h" 25#include "llvm/ADT/iterator" 26#include "llvm/ADT/APFloat.h" 27#include "llvm/ADT/APInt.h" 28#include "llvm/CodeGen/ValueTypes.h" 29#include "llvm/CodeGen/MemOperand.h" 30#include "llvm/Support/DataTypes.h" 31#include <cassert> 32 33namespace llvm { 34 35class SelectionDAG; 36class GlobalValue; 37class MachineBasicBlock; 38class MachineConstantPoolValue; 39class SDNode; 40template <typename T> struct DenseMapInfo; 41template <typename T> struct simplify_type; 42template <typename T> struct ilist_traits; 43template<typename NodeTy, typename Traits> class iplist; 44template<typename NodeTy> class ilist_iterator; 45 46/// SDVTList - This represents a list of ValueType's that has been intern'd by 47/// a SelectionDAG. Instances of this simple value class are returned by 48/// SelectionDAG::getVTList(...). 49/// 50struct SDVTList { 51 const MVT::ValueType *VTs; 52 unsigned short NumVTs; 53}; 54 55/// ISD namespace - This namespace contains an enum which represents all of the 56/// SelectionDAG node types and value types. 57/// 58namespace ISD { 59 namespace ParamFlags { 60 enum Flags { 61 NoFlagSet = 0, 62 ZExt = 1<<0, ///< Parameter should be zero extended 63 ZExtOffs = 0, 64 SExt = 1<<1, ///< Parameter should be sign extended 65 SExtOffs = 1, 66 InReg = 1<<2, ///< Parameter should be passed in register 67 InRegOffs = 2, 68 StructReturn = 1<<3, ///< Hidden struct-return pointer 69 StructReturnOffs = 3, 70 ByVal = 1<<4, ///< Struct passed by value 71 ByValOffs = 4, 72 Nest = 1<<5, ///< Parameter is nested function static chain 73 NestOffs = 5, 74 ByValAlign = 0xF << 6, //< The alignment of the struct 75 ByValAlignOffs = 6, 76 ByValSize = 0x1ffff << 10, //< The size of the struct 77 ByValSizeOffs = 10, 78 OrigAlignment = 0x1F<<27, 79 OrigAlignmentOffs = 27 80 }; 81 } 82 83 //===--------------------------------------------------------------------===// 84 /// ISD::NodeType enum - This enum defines all of the operators valid in a 85 /// SelectionDAG. 86 /// 87 enum NodeType { 88 // DELETED_NODE - This is an illegal flag value that is used to catch 89 // errors. This opcode is not a legal opcode for any node. 90 DELETED_NODE, 91 92 // EntryToken - This is the marker used to indicate the start of the region. 93 EntryToken, 94 95 // Token factor - This node takes multiple tokens as input and produces a 96 // single token result. This is used to represent the fact that the operand 97 // operators are independent of each other. 98 TokenFactor, 99 100 // AssertSext, AssertZext - These nodes record if a register contains a 101 // value that has already been zero or sign extended from a narrower type. 102 // These nodes take two operands. The first is the node that has already 103 // been extended, and the second is a value type node indicating the width 104 // of the extension 105 AssertSext, AssertZext, 106 107 // Various leaf nodes. 108 STRING, BasicBlock, VALUETYPE, CONDCODE, Register, 109 Constant, ConstantFP, 110 GlobalAddress, GlobalTLSAddress, FrameIndex, 111 JumpTable, ConstantPool, ExternalSymbol, 112 113 // The address of the GOT 114 GLOBAL_OFFSET_TABLE, 115 116 // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and 117 // llvm.returnaddress on the DAG. These nodes take one operand, the index 118 // of the frame or return address to return. An index of zero corresponds 119 // to the current function's frame or return address, an index of one to the 120 // parent's frame or return address, and so on. 121 FRAMEADDR, RETURNADDR, 122 123 // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to 124 // first (possible) on-stack argument. This is needed for correct stack 125 // adjustment during unwind. 126 FRAME_TO_ARGS_OFFSET, 127 128 // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the 129 // address of the exception block on entry to an landing pad block. 130 EXCEPTIONADDR, 131 132 // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents 133 // the selection index of the exception thrown. 134 EHSELECTION, 135 136 // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents 137 // 'eh_return' gcc dwarf builtin, which is used to return from 138 // exception. The general meaning is: adjust stack by OFFSET and pass 139 // execution to HANDLER. Many platform-related details also :) 140 EH_RETURN, 141 142 // TargetConstant* - Like Constant*, but the DAG does not do any folding or 143 // simplification of the constant. 144 TargetConstant, 145 TargetConstantFP, 146 147 // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or 148 // anything else with this node, and this is valid in the target-specific 149 // dag, turning into a GlobalAddress operand. 150 TargetGlobalAddress, 151 TargetGlobalTLSAddress, 152 TargetFrameIndex, 153 TargetJumpTable, 154 TargetConstantPool, 155 TargetExternalSymbol, 156 157 /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) 158 /// This node represents a target intrinsic function with no side effects. 159 /// The first operand is the ID number of the intrinsic from the 160 /// llvm::Intrinsic namespace. The operands to the intrinsic follow. The 161 /// node has returns the result of the intrinsic. 162 INTRINSIC_WO_CHAIN, 163 164 /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) 165 /// This node represents a target intrinsic function with side effects that 166 /// returns a result. The first operand is a chain pointer. The second is 167 /// the ID number of the intrinsic from the llvm::Intrinsic namespace. The 168 /// operands to the intrinsic follow. The node has two results, the result 169 /// of the intrinsic and an output chain. 170 INTRINSIC_W_CHAIN, 171 172 /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) 173 /// This node represents a target intrinsic function with side effects that 174 /// does not return a result. The first operand is a chain pointer. The 175 /// second is the ID number of the intrinsic from the llvm::Intrinsic 176 /// namespace. The operands to the intrinsic follow. 177 INTRINSIC_VOID, 178 179 // CopyToReg - This node has three operands: a chain, a register number to 180 // set to this value, and a value. 181 CopyToReg, 182 183 // CopyFromReg - This node indicates that the input value is a virtual or 184 // physical register that is defined outside of the scope of this 185 // SelectionDAG. The register is available from the RegisterSDNode object. 186 CopyFromReg, 187 188 // UNDEF - An undefined node 189 UNDEF, 190 191 /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node 192 /// represents the formal arguments for a function. CC# is a Constant value 193 /// indicating the calling convention of the function, and ISVARARG is a 194 /// flag that indicates whether the function is varargs or not. This node 195 /// has one result value for each incoming argument, plus one for the output 196 /// chain. It must be custom legalized. See description of CALL node for 197 /// FLAG argument contents explanation. 198 /// 199 FORMAL_ARGUMENTS, 200 201 /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE, 202 /// ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn) 203 /// This node represents a fully general function call, before the legalizer 204 /// runs. This has one result value for each argument / flag pair, plus 205 /// a chain result. It must be custom legalized. Flag argument indicates 206 /// misc. argument attributes. Currently: 207 /// Bit 0 - signness 208 /// Bit 1 - 'inreg' attribute 209 /// Bit 2 - 'sret' attribute 210 /// Bit 4 - 'byval' attribute 211 /// Bit 5 - 'nest' attribute 212 /// Bit 6-9 - alignment of byval structures 213 /// Bit 10-26 - size of byval structures 214 /// Bits 31:27 - argument ABI alignment in the first argument piece and 215 /// alignment '1' in other argument pieces. 216 CALL, 217 218 // EXTRACT_ELEMENT - This is used to get the first or second (determined by 219 // a Constant, which is required to be operand #1), element of the aggregate 220 // value specified as operand #0. This is only for use before legalization, 221 // for values that will be broken into multiple registers. 222 EXTRACT_ELEMENT, 223 224 // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways. Given 225 // two values of the same integer value type, this produces a value twice as 226 // big. Like EXTRACT_ELEMENT, this can only be used before legalization. 227 BUILD_PAIR, 228 229 // MERGE_VALUES - This node takes multiple discrete operands and returns 230 // them all as its individual results. This nodes has exactly the same 231 // number of inputs and outputs, and is only valid before legalization. 232 // This node is useful for some pieces of the code generator that want to 233 // think about a single node with multiple results, not multiple nodes. 234 MERGE_VALUES, 235 236 // Simple integer binary arithmetic operators. 237 ADD, SUB, MUL, SDIV, UDIV, SREM, UREM, 238 239 // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing 240 // a signed/unsigned value of type i[2*N], and return the full value as 241 // two results, each of type iN. 242 SMUL_LOHI, UMUL_LOHI, 243 244 // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and 245 // remainder result. 246 SDIVREM, UDIVREM, 247 248 // CARRY_FALSE - This node is used when folding other nodes, 249 // like ADDC/SUBC, which indicate the carry result is always false. 250 CARRY_FALSE, 251 252 // Carry-setting nodes for multiple precision addition and subtraction. 253 // These nodes take two operands of the same value type, and produce two 254 // results. The first result is the normal add or sub result, the second 255 // result is the carry flag result. 256 ADDC, SUBC, 257 258 // Carry-using nodes for multiple precision addition and subtraction. These 259 // nodes take three operands: The first two are the normal lhs and rhs to 260 // the add or sub, and the third is the input carry flag. These nodes 261 // produce two results; the normal result of the add or sub, and the output 262 // carry flag. These nodes both read and write a carry flag to allow them 263 // to them to be chained together for add and sub of arbitrarily large 264 // values. 265 ADDE, SUBE, 266 267 // Simple binary floating point operators. 268 FADD, FSUB, FMUL, FDIV, FREM, 269 270 // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y. NOTE: This 271 // DAG node does not require that X and Y have the same type, just that they 272 // are both floating point. X and the result must have the same type. 273 // FCOPYSIGN(f32, f64) is allowed. 274 FCOPYSIGN, 275 276 // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point 277 // value as an integer 0/1 value. 278 FGETSIGN, 279 280 /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector 281 /// with the specified, possibly variable, elements. The number of elements 282 /// is required to be a power of two. 283 BUILD_VECTOR, 284 285 /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element 286 /// at IDX replaced with VAL. 287 INSERT_VECTOR_ELT, 288 289 /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR 290 /// identified by the (potentially variable) element number IDX. 291 EXTRACT_VECTOR_ELT, 292 293 /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of 294 /// vector type with the same length and element type, this produces a 295 /// concatenated vector result value, with length equal to the sum of the 296 /// lengths of the input vectors. 297 CONCAT_VECTORS, 298 299 /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an 300 /// vector value) starting with the (potentially variable) element number 301 /// IDX, which must be a multiple of the result vector length. 302 EXTRACT_SUBVECTOR, 303 304 /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same 305 /// type as VEC1/VEC2. SHUFFLEVEC is a BUILD_VECTOR of constant int values 306 /// (regardless of whether its datatype is legal or not) that indicate 307 /// which value each result element will get. The elements of VEC1/VEC2 are 308 /// enumerated in order. This is quite similar to the Altivec 'vperm' 309 /// instruction, except that the indices must be constants and are in terms 310 /// of the element size of VEC1/VEC2, not in terms of bytes. 311 VECTOR_SHUFFLE, 312 313 /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a 314 /// scalar value into element 0 of the resultant vector type. The top 315 /// elements 1 to N-1 of the N-element vector are undefined. 316 SCALAR_TO_VECTOR, 317 318 // EXTRACT_SUBREG - This node is used to extract a sub-register value. 319 // This node takes a superreg and a constant sub-register index as operands. 320 EXTRACT_SUBREG, 321 322 // INSERT_SUBREG - This node is used to insert a sub-register value. 323 // This node takes a superreg, a subreg value, and a constant sub-register 324 // index as operands. 325 INSERT_SUBREG, 326 327 // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing 328 // an unsigned/signed value of type i[2*N], then return the top part. 329 MULHU, MULHS, 330 331 // Bitwise operators - logical and, logical or, logical xor, shift left, 332 // shift right algebraic (shift in sign bits), shift right logical (shift in 333 // zeroes), rotate left, rotate right, and byteswap. 334 AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP, 335 336 // Counting operators 337 CTTZ, CTLZ, CTPOP, 338 339 // Select(COND, TRUEVAL, FALSEVAL) 340 SELECT, 341 342 // Select with condition operator - This selects between a true value and 343 // a false value (ops #2 and #3) based on the boolean result of comparing 344 // the lhs and rhs (ops #0 and #1) of a conditional expression with the 345 // condition code in op #4, a CondCodeSDNode. 346 SELECT_CC, 347 348 // SetCC operator - This evaluates to a boolean (i1) true value if the 349 // condition is true. The operands to this are the left and right operands 350 // to compare (ops #0, and #1) and the condition code to compare them with 351 // (op #2) as a CondCodeSDNode. 352 SETCC, 353 354 // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded 355 // integer shift operations, just like ADD/SUB_PARTS. The operation 356 // ordering is: 357 // [Lo,Hi] = op [LoLHS,HiLHS], Amt 358 SHL_PARTS, SRA_PARTS, SRL_PARTS, 359 360 // Conversion operators. These are all single input single output 361 // operations. For all of these, the result type must be strictly 362 // wider or narrower (depending on the operation) than the source 363 // type. 364 365 // SIGN_EXTEND - Used for integer types, replicating the sign bit 366 // into new bits. 367 SIGN_EXTEND, 368 369 // ZERO_EXTEND - Used for integer types, zeroing the new bits. 370 ZERO_EXTEND, 371 372 // ANY_EXTEND - Used for integer types. The high bits are undefined. 373 ANY_EXTEND, 374 375 // TRUNCATE - Completely drop the high bits. 376 TRUNCATE, 377 378 // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign 379 // depends on the first letter) to floating point. 380 SINT_TO_FP, 381 UINT_TO_FP, 382 383 // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to 384 // sign extend a small value in a large integer register (e.g. sign 385 // extending the low 8 bits of a 32-bit register to fill the top 24 bits 386 // with the 7th bit). The size of the smaller type is indicated by the 1th 387 // operand, a ValueType node. 388 SIGN_EXTEND_INREG, 389 390 /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned 391 /// integer. 392 FP_TO_SINT, 393 FP_TO_UINT, 394 395 /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type 396 /// down to the precision of the destination VT. TRUNC is a flag, which is 397 /// always an integer that is zero or one. If TRUNC is 0, this is a 398 /// normal rounding, if it is 1, this FP_ROUND is known to not change the 399 /// value of Y. 400 /// 401 /// The TRUNC = 1 case is used in cases where we know that the value will 402 /// not be modified by the node, because Y is not using any of the extra 403 /// precision of source type. This allows certain transformations like 404 /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for 405 /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed. 406 FP_ROUND, 407 408 // FLT_ROUNDS_ - Returns current rounding mode: 409 // -1 Undefined 410 // 0 Round to 0 411 // 1 Round to nearest 412 // 2 Round to +inf 413 // 3 Round to -inf 414 FLT_ROUNDS_, 415 416 /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and 417 /// rounds it to a floating point value. It then promotes it and returns it 418 /// in a register of the same size. This operation effectively just 419 /// discards excess precision. The type to round down to is specified by 420 /// the VT operand, a VTSDNode. 421 FP_ROUND_INREG, 422 423 /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type. 424 FP_EXTEND, 425 426 // BIT_CONVERT - Theis operator converts between integer and FP values, as 427 // if one was stored to memory as integer and the other was loaded from the 428 // same address (or equivalently for vector format conversions, etc). The 429 // source and result are required to have the same bit size (e.g. 430 // f32 <-> i32). This can also be used for int-to-int or fp-to-fp 431 // conversions, but that is a noop, deleted by getNode(). 432 BIT_CONVERT, 433 434 // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point 435 // negation, absolute value, square root, sine and cosine, powi, and pow 436 // operations. 437 FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, 438 439 // LOAD and STORE have token chains as their first operand, then the same 440 // operands as an LLVM load/store instruction, then an offset node that 441 // is added / subtracted from the base pointer to form the address (for 442 // indexed memory ops). 443 LOAD, STORE, 444 445 // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned 446 // to a specified boundary. This node always has two return values: a new 447 // stack pointer value and a chain. The first operand is the token chain, 448 // the second is the number of bytes to allocate, and the third is the 449 // alignment boundary. The size is guaranteed to be a multiple of the stack 450 // alignment, and the alignment is guaranteed to be bigger than the stack 451 // alignment (if required) or 0 to get standard stack alignment. 452 DYNAMIC_STACKALLOC, 453 454 // Control flow instructions. These all have token chains. 455 456 // BR - Unconditional branch. The first operand is the chain 457 // operand, the second is the MBB to branch to. 458 BR, 459 460 // BRIND - Indirect branch. The first operand is the chain, the second 461 // is the value to branch to, which must be of the same type as the target's 462 // pointer type. 463 BRIND, 464 465 // BR_JT - Jumptable branch. The first operand is the chain, the second 466 // is the jumptable index, the last one is the jumptable entry index. 467 BR_JT, 468 469 // BRCOND - Conditional branch. The first operand is the chain, 470 // the second is the condition, the third is the block to branch 471 // to if the condition is true. 472 BRCOND, 473 474 // BR_CC - Conditional branch. The behavior is like that of SELECT_CC, in 475 // that the condition is represented as condition code, and two nodes to 476 // compare, rather than as a combined SetCC node. The operands in order are 477 // chain, cc, lhs, rhs, block to branch to if condition is true. 478 BR_CC, 479 480 // RET - Return from function. The first operand is the chain, 481 // and any subsequent operands are pairs of return value and return value 482 // signness for the function. This operation can have variable number of 483 // operands. 484 RET, 485 486 // INLINEASM - Represents an inline asm block. This node always has two 487 // return values: a chain and a flag result. The inputs are as follows: 488 // Operand #0 : Input chain. 489 // Operand #1 : a ExternalSymbolSDNode with a pointer to the asm string. 490 // Operand #2n+2: A RegisterNode. 491 // Operand #2n+3: A TargetConstant, indicating if the reg is a use/def 492 // Operand #last: Optional, an incoming flag. 493 INLINEASM, 494 495 // LABEL - Represents a label in mid basic block used to track 496 // locations needed for debug and exception handling tables. This node 497 // returns a chain. 498 // Operand #0 : input chain. 499 // Operand #1 : module unique number use to identify the label. 500 // Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates 501 // a EH label, 2 indicates unknown label type. 502 LABEL, 503 504 // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track 505 // local variable declarations for debugging information. First operand is 506 // a chain, while the next two operands are first two arguments (address 507 // and variable) of a llvm.dbg.declare instruction. 508 DECLARE, 509 510 // STACKSAVE - STACKSAVE has one operand, an input chain. It produces a 511 // value, the same type as the pointer type for the system, and an output 512 // chain. 513 STACKSAVE, 514 515 // STACKRESTORE has two operands, an input chain and a pointer to restore to 516 // it returns an output chain. 517 STACKRESTORE, 518 519 // MEMSET/MEMCPY/MEMMOVE - The first operand is the chain. The following 520 // correspond to the operands of the LLVM intrinsic functions and the last 521 // one is AlwaysInline. The only result is a token chain. The alignment 522 // argument is guaranteed to be a Constant node. 523 MEMSET, 524 MEMMOVE, 525 MEMCPY, 526 527 // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of 528 // a call sequence, and carry arbitrary information that target might want 529 // to know. The first operand is a chain, the rest are specified by the 530 // target and not touched by the DAG optimizers. 531 CALLSEQ_START, // Beginning of a call sequence 532 CALLSEQ_END, // End of a call sequence 533 534 // VAARG - VAARG has three operands: an input chain, a pointer, and a 535 // SRCVALUE. It returns a pair of values: the vaarg value and a new chain. 536 VAARG, 537 538 // VACOPY - VACOPY has five operands: an input chain, a destination pointer, 539 // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the 540 // source. 541 VACOPY, 542 543 // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a 544 // pointer, and a SRCVALUE. 545 VAEND, VASTART, 546 547 // SRCVALUE - This is a node type that holds a Value* that is used to 548 // make reference to a value in the LLVM IR. 549 SRCVALUE, 550 551 // MEMOPERAND - This is a node that contains a MemOperand which records 552 // information about a memory reference. This is used to make AliasAnalysis 553 // queries from the backend. 554 MEMOPERAND, 555 556 // PCMARKER - This corresponds to the pcmarker intrinsic. 557 PCMARKER, 558 559 // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic. 560 // The only operand is a chain and a value and a chain are produced. The 561 // value is the contents of the architecture specific cycle counter like 562 // register (or other high accuracy low latency clock source) 563 READCYCLECOUNTER, 564 565 // HANDLENODE node - Used as a handle for various purposes. 566 HANDLENODE, 567 568 // LOCATION - This node is used to represent a source location for debug 569 // info. It takes token chain as input, then a line number, then a column 570 // number, then a filename, then a working dir. It produces a token chain 571 // as output. 572 LOCATION, 573 574 // DEBUG_LOC - This node is used to represent source line information 575 // embedded in the code. It takes a token chain as input, then a line 576 // number, then a column then a file id (provided by MachineModuleInfo.) It 577 // produces a token chain as output. 578 DEBUG_LOC, 579 580 // TRAMPOLINE - This corresponds to the init_trampoline intrinsic. 581 // It takes as input a token chain, the pointer to the trampoline, 582 // the pointer to the nested function, the pointer to pass for the 583 // 'nest' parameter, a SRCVALUE for the trampoline and another for 584 // the nested function (allowing targets to access the original 585 // Function*). It produces the result of the intrinsic and a token 586 // chain as output. 587 TRAMPOLINE, 588 589 // TRAP - Trapping instruction 590 TRAP, 591 592 // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load, 593 // store-store, device) 594 // This corresponds to the memory.barrier intrinsic. 595 // it takes an input chain, 4 operands to specify the type of barrier, an 596 // operand specifying if the barrier applies to device and uncached memory 597 // and produces an output chain. 598 MEMBARRIER, 599 600 // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap) 601 // this corresponds to the atomic.lcs intrinsic. 602 // cmp is compared to *ptr, and if equal, swap is stored in *ptr. 603 // the return is always the original value in *ptr 604 ATOMIC_LCS, 605 606 // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt) 607 // this corresponds to the atomic.las intrinsic. 608 // *ptr + amt is stored to *ptr atomically. 609 // the return is always the original value in *ptr 610 ATOMIC_LAS, 611 612 // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt) 613 // this corresponds to the atomic.swap intrinsic. 614 // amt is stored to *ptr atomically. 615 // the return is always the original value in *ptr 616 ATOMIC_SWAP, 617 618 // BUILTIN_OP_END - This must be the last enum value in this list. 619 BUILTIN_OP_END 620 }; 621 622 /// Node predicates 623 624 /// isBuildVectorAllOnes - Return true if the specified node is a 625 /// BUILD_VECTOR where all of the elements are ~0 or undef. 626 bool isBuildVectorAllOnes(const SDNode *N); 627 628 /// isBuildVectorAllZeros - Return true if the specified node is a 629 /// BUILD_VECTOR where all of the elements are 0 or undef. 630 bool isBuildVectorAllZeros(const SDNode *N); 631 632 /// isScalarToVector - Return true if the specified node is a 633 /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low 634 /// element is not an undef. 635 bool isScalarToVector(const SDNode *N); 636 637 /// isDebugLabel - Return true if the specified node represents a debug 638 /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand 639 /// is 0). 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 produces 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_LOADX_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} // end llvm::ISD namespace 792 793 794//===----------------------------------------------------------------------===// 795/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple 796/// values as the result of a computation. Many nodes return multiple values, 797/// from loads (which define a token and a return value) to ADDC (which returns 798/// a result and a carry value), to calls (which may return an arbitrary number 799/// of values). 800/// 801/// As such, each use of a SelectionDAG computation must indicate the node that 802/// computes it as well as which return value to use from that node. This pair 803/// of information is represented with the SDOperand value type. 804/// 805class SDOperand { 806public: 807 SDNode *Val; // The node defining the value we are using. 808 unsigned ResNo; // Which return value of the node we are using. 809 810 SDOperand() : Val(0), ResNo(0) {} 811 SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {} 812 813 bool operator==(const SDOperand &O) const { 814 return Val == O.Val && ResNo == O.ResNo; 815 } 816 bool operator!=(const SDOperand &O) const { 817 return !operator==(O); 818 } 819 bool operator<(const SDOperand &O) const { 820 return Val < O.Val || (Val == O.Val && ResNo < O.ResNo); 821 } 822 823 SDOperand getValue(unsigned R) const { 824 return SDOperand(Val, R); 825 } 826 827 // isOperand - Return true if this node is an operand of N. 828 bool isOperand(SDNode *N) const; 829 830 /// getValueType - Return the ValueType of the referenced return value. 831 /// 832 inline MVT::ValueType getValueType() const; 833 834 // Forwarding methods - These forward to the corresponding methods in SDNode. 835 inline unsigned getOpcode() const; 836 inline unsigned getNumOperands() const; 837 inline const SDOperand &getOperand(unsigned i) const; 838 inline uint64_t getConstantOperandVal(unsigned i) const; 839 inline bool isTargetOpcode() const; 840 inline unsigned getTargetOpcode() const; 841 842 843 /// reachesChainWithoutSideEffects - Return true if this operand (which must 844 /// be a chain) reaches the specified operand without crossing any 845 /// side-effecting instructions. In practice, this looks through token 846 /// factors and non-volatile loads. In order to remain efficient, this only 847 /// looks a couple of nodes in, it does not do an exhaustive search. 848 bool reachesChainWithoutSideEffects(SDOperand Dest, unsigned Depth = 2) const; 849 850 /// hasOneUse - Return true if there is exactly one operation using this 851 /// result value of the defining operator. 852 inline bool hasOneUse() const; 853 854 /// use_empty - Return true if there are no operations using this 855 /// result value of the defining operator. 856 inline bool use_empty() const; 857}; 858 859 860template<> struct DenseMapInfo<SDOperand> { 861 static inline SDOperand getEmptyKey() { return SDOperand((SDNode*)-1, -1U); } 862 static inline SDOperand getTombstoneKey() { return SDOperand((SDNode*)-1, 0);} 863 static unsigned getHashValue(const SDOperand &Val) { 864 return ((unsigned)((uintptr_t)Val.Val >> 4) ^ 865 (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo; 866 } 867 static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) { 868 return LHS == RHS; 869 } 870 static bool isPod() { return true; } 871}; 872 873/// simplify_type specializations - Allow casting operators to work directly on 874/// SDOperands as if they were SDNode*'s. 875template<> struct simplify_type<SDOperand> { 876 typedef SDNode* SimpleType; 877 static SimpleType getSimplifiedValue(const SDOperand &Val) { 878 return static_cast<SimpleType>(Val.Val); 879 } 880}; 881template<> struct simplify_type<const SDOperand> { 882 typedef SDNode* SimpleType; 883 static SimpleType getSimplifiedValue(const SDOperand &Val) { 884 return static_cast<SimpleType>(Val.Val); 885 } 886}; 887 888 889/// SDNode - Represents one node in the SelectionDAG. 890/// 891class SDNode : public FoldingSetNode { 892 /// NodeType - The operation that this node performs. 893 /// 894 unsigned short NodeType; 895 896 /// OperandsNeedDelete - This is true if OperandList was new[]'d. If true, 897 /// then they will be delete[]'d when the node is destroyed. 898 bool OperandsNeedDelete : 1; 899 900 /// NodeId - Unique id per SDNode in the DAG. 901 int NodeId; 902 903 /// OperandList - The values that are used by this operation. 904 /// 905 SDOperand *OperandList; 906 907 /// ValueList - The types of the values this node defines. SDNode's may 908 /// define multiple values simultaneously. 909 const MVT::ValueType *ValueList; 910 911 /// NumOperands/NumValues - The number of entries in the Operand/Value list. 912 unsigned short NumOperands, NumValues; 913 914 /// Prev/Next pointers - These pointers form the linked list of of the 915 /// AllNodes list in the current DAG. 916 SDNode *Prev, *Next; 917 friend struct ilist_traits<SDNode>; 918 919 /// Uses - These are all of the SDNode's that use a value produced by this 920 /// node. 921 SmallVector<SDNode*,3> Uses; 922 923 // Out-of-line virtual method to give class a home. 924 virtual void ANCHOR(); 925public: 926 virtual ~SDNode() { 927 assert(NumOperands == 0 && "Operand list not cleared before deletion"); 928 NodeType = ISD::DELETED_NODE; 929 } 930 931 //===--------------------------------------------------------------------===// 932 // Accessors 933 // 934 unsigned getOpcode() const { return NodeType; } 935 bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; } 936 unsigned getTargetOpcode() const { 937 assert(isTargetOpcode() && "Not a target opcode!"); 938 return NodeType - ISD::BUILTIN_OP_END; 939 } 940 941 size_t use_size() const { return Uses.size(); } 942 bool use_empty() const { return Uses.empty(); } 943 bool hasOneUse() const { return Uses.size() == 1; } 944 945 /// getNodeId - Return the unique node id. 946 /// 947 int getNodeId() const { return NodeId; } 948 949 /// setNodeId - Set unique node id. 950 void setNodeId(int Id) { NodeId = Id; } 951 952 typedef SmallVector<SDNode*,3>::const_iterator use_iterator; 953 use_iterator use_begin() const { return Uses.begin(); } 954 use_iterator use_end() const { return Uses.end(); } 955 956 /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the 957 /// indicated value. This method ignores uses of other values defined by this 958 /// operation. 959 bool hasNUsesOfValue(unsigned NUses, unsigned Value) const; 960 961 /// hasAnyUseOfValue - Return true if there are any use of the indicated 962 /// value. This method ignores uses of other values defined by this operation. 963 bool hasAnyUseOfValue(unsigned Value) const; 964 965 /// isOnlyUse - Return true if this node is the only use of N. 966 /// 967 bool isOnlyUse(SDNode *N) const; 968 969 /// isOperand - Return true if this node is an operand of N. 970 /// 971 bool isOperand(SDNode *N) const; 972 973 /// isPredecessor - Return true if this node is a predecessor of N. This node 974 /// is either an operand of N or it can be reached by recursively traversing 975 /// up the operands. 976 /// NOTE: this is an expensive method. Use it carefully. 977 bool isPredecessor(SDNode *N) const; 978 979 /// getNumOperands - Return the number of values used by this operation. 980 /// 981 unsigned getNumOperands() const { return NumOperands; } 982 983 /// getConstantOperandVal - Helper method returns the integer value of a 984 /// ConstantSDNode operand. 985 uint64_t getConstantOperandVal(unsigned Num) const; 986 987 const SDOperand &getOperand(unsigned Num) const { 988 assert(Num < NumOperands && "Invalid child # of SDNode!"); 989 return OperandList[Num]; 990 } 991 992 typedef const SDOperand* op_iterator; 993 op_iterator op_begin() const { return OperandList; } 994 op_iterator op_end() const { return OperandList+NumOperands; } 995 996 997 SDVTList getVTList() const { 998 SDVTList X = { ValueList, NumValues }; 999 return X; 1000 }; 1001 1002 /// getNumValues - Return the number of values defined/returned by this 1003 /// operator. 1004 /// 1005 unsigned getNumValues() const { return NumValues; } 1006 1007 /// getValueType - Return the type of a specified result. 1008 /// 1009 MVT::ValueType getValueType(unsigned ResNo) const { 1010 assert(ResNo < NumValues && "Illegal result number!"); 1011 return ValueList[ResNo]; 1012 } 1013 1014 typedef const MVT::ValueType* value_iterator; 1015 value_iterator value_begin() const { return ValueList; } 1016 value_iterator value_end() const { return ValueList+NumValues; } 1017 1018 /// getOperationName - Return the opcode of this operation for printing. 1019 /// 1020 std::string getOperationName(const SelectionDAG *G = 0) const; 1021 static const char* getIndexedModeName(ISD::MemIndexedMode AM); 1022 void dump() const; 1023 void dump(const SelectionDAG *G) const; 1024 1025 static bool classof(const SDNode *) { return true; } 1026 1027 /// Profile - Gather unique data for the node. 1028 /// 1029 void Profile(FoldingSetNodeID &ID); 1030 1031protected: 1032 friend class SelectionDAG; 1033 1034 /// getValueTypeList - Return a pointer to the specified value type. 1035 /// 1036 static const MVT::ValueType *getValueTypeList(MVT::ValueType VT); 1037 static SDVTList getSDVTList(MVT::ValueType VT) { 1038 SDVTList Ret = { getValueTypeList(VT), 1 }; 1039 return Ret; 1040 } 1041 1042 SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps) 1043 : NodeType(Opc), NodeId(-1) { 1044 OperandsNeedDelete = true; 1045 NumOperands = NumOps; 1046 OperandList = NumOps ? new SDOperand[NumOperands] : 0; 1047 1048 for (unsigned i = 0; i != NumOps; ++i) { 1049 OperandList[i] = Ops[i]; 1050 Ops[i].Val->Uses.push_back(this); 1051 } 1052 1053 ValueList = VTs.VTs; 1054 NumValues = VTs.NumVTs; 1055 Prev = 0; Next = 0; 1056 } 1057 SDNode(unsigned Opc, SDVTList VTs) : NodeType(Opc), NodeId(-1) { 1058 OperandsNeedDelete = false; // Operands set with InitOperands. 1059 NumOperands = 0; 1060 OperandList = 0; 1061 1062 ValueList = VTs.VTs; 1063 NumValues = VTs.NumVTs; 1064 Prev = 0; Next = 0; 1065 } 1066 1067 /// InitOperands - Initialize the operands list of this node with the 1068 /// specified values, which are part of the node (thus they don't need to be 1069 /// copied in or allocated). 1070 void InitOperands(SDOperand *Ops, unsigned NumOps) { 1071 assert(OperandList == 0 && "Operands already set!"); 1072 NumOperands = NumOps; 1073 OperandList = Ops; 1074 1075 for (unsigned i = 0; i != NumOps; ++i) 1076 Ops[i].Val->Uses.push_back(this); 1077 } 1078 1079 /// MorphNodeTo - This frees the operands of the current node, resets the 1080 /// opcode, types, and operands to the specified value. This should only be 1081 /// used by the SelectionDAG class. 1082 void MorphNodeTo(unsigned Opc, SDVTList L, 1083 const SDOperand *Ops, unsigned NumOps); 1084 1085 void addUser(SDNode *User) { 1086 Uses.push_back(User); 1087 } 1088 void removeUser(SDNode *User) { 1089 // Remove this user from the operand's use list. 1090 for (unsigned i = Uses.size(); ; --i) { 1091 assert(i != 0 && "Didn't find user!"); 1092 if (Uses[i-1] == User) { 1093 Uses[i-1] = Uses.back(); 1094 Uses.pop_back(); 1095 return; 1096 } 1097 } 1098 } 1099}; 1100 1101 1102// Define inline functions from the SDOperand class. 1103 1104inline unsigned SDOperand::getOpcode() const { 1105 return Val->getOpcode(); 1106} 1107inline MVT::ValueType SDOperand::getValueType() const { 1108 return Val->getValueType(ResNo); 1109} 1110inline unsigned SDOperand::getNumOperands() const { 1111 return Val->getNumOperands(); 1112} 1113inline const SDOperand &SDOperand::getOperand(unsigned i) const { 1114 return Val->getOperand(i); 1115} 1116inline uint64_t SDOperand::getConstantOperandVal(unsigned i) const { 1117 return Val->getConstantOperandVal(i); 1118} 1119inline bool SDOperand::isTargetOpcode() const { 1120 return Val->isTargetOpcode(); 1121} 1122inline unsigned SDOperand::getTargetOpcode() const { 1123 return Val->getTargetOpcode(); 1124} 1125inline bool SDOperand::hasOneUse() const { 1126 return Val->hasNUsesOfValue(1, ResNo); 1127} 1128inline bool SDOperand::use_empty() const { 1129 return !Val->hasAnyUseOfValue(ResNo); 1130} 1131 1132/// UnarySDNode - This class is used for single-operand SDNodes. This is solely 1133/// to allow co-allocation of node operands with the node itself. 1134class UnarySDNode : public SDNode { 1135 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1136 SDOperand Op; 1137public: 1138 UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X) 1139 : SDNode(Opc, VTs), Op(X) { 1140 InitOperands(&Op, 1); 1141 } 1142}; 1143 1144/// BinarySDNode - This class is used for two-operand SDNodes. This is solely 1145/// to allow co-allocation of node operands with the node itself. 1146class BinarySDNode : public SDNode { 1147 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1148 SDOperand Ops[2]; 1149public: 1150 BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y) 1151 : SDNode(Opc, VTs) { 1152 Ops[0] = X; 1153 Ops[1] = Y; 1154 InitOperands(Ops, 2); 1155 } 1156}; 1157 1158/// TernarySDNode - This class is used for three-operand SDNodes. This is solely 1159/// to allow co-allocation of node operands with the node itself. 1160class TernarySDNode : public SDNode { 1161 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1162 SDOperand Ops[3]; 1163public: 1164 TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y, 1165 SDOperand Z) 1166 : SDNode(Opc, VTs) { 1167 Ops[0] = X; 1168 Ops[1] = Y; 1169 Ops[2] = Z; 1170 InitOperands(Ops, 3); 1171 } 1172}; 1173 1174 1175/// HandleSDNode - This class is used to form a handle around another node that 1176/// is persistant and is updated across invocations of replaceAllUsesWith on its 1177/// operand. This node should be directly created by end-users and not added to 1178/// the AllNodes list. 1179class HandleSDNode : public SDNode { 1180 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1181 SDOperand Op; 1182public: 1183 explicit HandleSDNode(SDOperand X) 1184 : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)), Op(X) { 1185 InitOperands(&Op, 1); 1186 } 1187 ~HandleSDNode(); 1188 SDOperand getValue() const { return Op; } 1189}; 1190 1191class AtomicSDNode : public SDNode { 1192 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1193 SDOperand Ops[4]; 1194 MVT::ValueType OrigVT; 1195public: 1196 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 1197 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT) 1198 : SDNode(Opc, VTL) { 1199 Ops[0] = Chain; 1200 Ops[1] = Ptr; 1201 Ops[2] = Swp; 1202 Ops[3] = Cmp; 1203 InitOperands(Ops, 4); 1204 OrigVT=VT; 1205 } 1206 AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr, 1207 SDOperand Val, MVT::ValueType VT) 1208 : SDNode(Opc, VTL) { 1209 Ops[0] = Chain; 1210 Ops[1] = Ptr; 1211 Ops[2] = Val; 1212 InitOperands(Ops, 3); 1213 OrigVT=VT; 1214 } 1215 MVT::ValueType getVT() const { return OrigVT; } 1216 bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; } 1217}; 1218 1219class StringSDNode : public SDNode { 1220 std::string Value; 1221 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1222protected: 1223 friend class SelectionDAG; 1224 explicit StringSDNode(const std::string &val) 1225 : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) { 1226 } 1227public: 1228 const std::string &getValue() const { return Value; } 1229 static bool classof(const StringSDNode *) { return true; } 1230 static bool classof(const SDNode *N) { 1231 return N->getOpcode() == ISD::STRING; 1232 } 1233}; 1234 1235class ConstantSDNode : public SDNode { 1236 APInt Value; 1237 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1238protected: 1239 friend class SelectionDAG; 1240 ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT) 1241 : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)), 1242 Value(val) { 1243 } 1244public: 1245 1246 const APInt &getAPIntValue() const { return Value; } 1247 uint64_t getValue() const { return Value.getZExtValue(); } 1248 1249 int64_t getSignExtended() const { 1250 unsigned Bits = MVT::getSizeInBits(getValueType(0)); 1251 return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits); 1252 } 1253 1254 bool isNullValue() const { return Value == 0; } 1255 bool isAllOnesValue() const { 1256 return Value == MVT::getIntVTBitMask(getValueType(0)); 1257 } 1258 1259 static bool classof(const ConstantSDNode *) { return true; } 1260 static bool classof(const SDNode *N) { 1261 return N->getOpcode() == ISD::Constant || 1262 N->getOpcode() == ISD::TargetConstant; 1263 } 1264}; 1265 1266class ConstantFPSDNode : public SDNode { 1267 APFloat Value; 1268 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1269protected: 1270 friend class SelectionDAG; 1271 ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT) 1272 : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP, 1273 getSDVTList(VT)), Value(val) { 1274 } 1275public: 1276 1277 const APFloat& getValueAPF() const { return Value; } 1278 1279 /// isExactlyValue - We don't rely on operator== working on double values, as 1280 /// it returns true for things that are clearly not equal, like -0.0 and 0.0. 1281 /// As such, this method can be used to do an exact bit-for-bit comparison of 1282 /// two floating point values. 1283 1284 /// We leave the version with the double argument here because it's just so 1285 /// convenient to write "2.0" and the like. Without this function we'd 1286 /// have to duplicate its logic everywhere it's called. 1287 bool isExactlyValue(double V) const { 1288 APFloat Tmp(V); 1289 Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven); 1290 return isExactlyValue(Tmp); 1291 } 1292 bool isExactlyValue(const APFloat& V) const; 1293 1294 bool isValueValidForType(MVT::ValueType VT, const APFloat& Val); 1295 1296 static bool classof(const ConstantFPSDNode *) { return true; } 1297 static bool classof(const SDNode *N) { 1298 return N->getOpcode() == ISD::ConstantFP || 1299 N->getOpcode() == ISD::TargetConstantFP; 1300 } 1301}; 1302 1303class GlobalAddressSDNode : public SDNode { 1304 GlobalValue *TheGlobal; 1305 int Offset; 1306 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1307protected: 1308 friend class SelectionDAG; 1309 GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT, 1310 int o = 0); 1311public: 1312 1313 GlobalValue *getGlobal() const { return TheGlobal; } 1314 int getOffset() const { return Offset; } 1315 1316 static bool classof(const GlobalAddressSDNode *) { return true; } 1317 static bool classof(const SDNode *N) { 1318 return N->getOpcode() == ISD::GlobalAddress || 1319 N->getOpcode() == ISD::TargetGlobalAddress || 1320 N->getOpcode() == ISD::GlobalTLSAddress || 1321 N->getOpcode() == ISD::TargetGlobalTLSAddress; 1322 } 1323}; 1324 1325class FrameIndexSDNode : public SDNode { 1326 int FI; 1327 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1328protected: 1329 friend class SelectionDAG; 1330 FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg) 1331 : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)), 1332 FI(fi) { 1333 } 1334public: 1335 1336 int getIndex() const { return FI; } 1337 1338 static bool classof(const FrameIndexSDNode *) { return true; } 1339 static bool classof(const SDNode *N) { 1340 return N->getOpcode() == ISD::FrameIndex || 1341 N->getOpcode() == ISD::TargetFrameIndex; 1342 } 1343}; 1344 1345class JumpTableSDNode : public SDNode { 1346 int JTI; 1347 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1348protected: 1349 friend class SelectionDAG; 1350 JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg) 1351 : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)), 1352 JTI(jti) { 1353 } 1354public: 1355 1356 int getIndex() const { return JTI; } 1357 1358 static bool classof(const JumpTableSDNode *) { return true; } 1359 static bool classof(const SDNode *N) { 1360 return N->getOpcode() == ISD::JumpTable || 1361 N->getOpcode() == ISD::TargetJumpTable; 1362 } 1363}; 1364 1365class ConstantPoolSDNode : public SDNode { 1366 union { 1367 Constant *ConstVal; 1368 MachineConstantPoolValue *MachineCPVal; 1369 } Val; 1370 int Offset; // It's a MachineConstantPoolValue if top bit is set. 1371 unsigned Alignment; 1372 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1373protected: 1374 friend class SelectionDAG; 1375 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, 1376 int o=0) 1377 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1378 getSDVTList(VT)), Offset(o), Alignment(0) { 1379 assert((int)Offset >= 0 && "Offset is too large"); 1380 Val.ConstVal = c; 1381 } 1382 ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o, 1383 unsigned Align) 1384 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1385 getSDVTList(VT)), Offset(o), Alignment(Align) { 1386 assert((int)Offset >= 0 && "Offset is too large"); 1387 Val.ConstVal = c; 1388 } 1389 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, 1390 MVT::ValueType VT, int o=0) 1391 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1392 getSDVTList(VT)), Offset(o), Alignment(0) { 1393 assert((int)Offset >= 0 && "Offset is too large"); 1394 Val.MachineCPVal = v; 1395 Offset |= 1 << (sizeof(unsigned)*8-1); 1396 } 1397 ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v, 1398 MVT::ValueType VT, int o, unsigned Align) 1399 : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool, 1400 getSDVTList(VT)), Offset(o), Alignment(Align) { 1401 assert((int)Offset >= 0 && "Offset is too large"); 1402 Val.MachineCPVal = v; 1403 Offset |= 1 << (sizeof(unsigned)*8-1); 1404 } 1405public: 1406 1407 bool isMachineConstantPoolEntry() const { 1408 return (int)Offset < 0; 1409 } 1410 1411 Constant *getConstVal() const { 1412 assert(!isMachineConstantPoolEntry() && "Wrong constantpool type"); 1413 return Val.ConstVal; 1414 } 1415 1416 MachineConstantPoolValue *getMachineCPVal() const { 1417 assert(isMachineConstantPoolEntry() && "Wrong constantpool type"); 1418 return Val.MachineCPVal; 1419 } 1420 1421 int getOffset() const { 1422 return Offset & ~(1 << (sizeof(unsigned)*8-1)); 1423 } 1424 1425 // Return the alignment of this constant pool object, which is either 0 (for 1426 // default alignment) or log2 of the desired value. 1427 unsigned getAlignment() const { return Alignment; } 1428 1429 const Type *getType() const; 1430 1431 static bool classof(const ConstantPoolSDNode *) { return true; } 1432 static bool classof(const SDNode *N) { 1433 return N->getOpcode() == ISD::ConstantPool || 1434 N->getOpcode() == ISD::TargetConstantPool; 1435 } 1436}; 1437 1438class BasicBlockSDNode : public SDNode { 1439 MachineBasicBlock *MBB; 1440 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1441protected: 1442 friend class SelectionDAG; 1443 explicit BasicBlockSDNode(MachineBasicBlock *mbb) 1444 : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) { 1445 } 1446public: 1447 1448 MachineBasicBlock *getBasicBlock() const { return MBB; } 1449 1450 static bool classof(const BasicBlockSDNode *) { return true; } 1451 static bool classof(const SDNode *N) { 1452 return N->getOpcode() == ISD::BasicBlock; 1453 } 1454}; 1455 1456/// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is 1457/// used when the SelectionDAG needs to make a simple reference to something 1458/// in the LLVM IR representation. 1459/// 1460/// Note that this is not used for carrying alias information; that is done 1461/// with MemOperandSDNode, which includes a Value which is required to be a 1462/// pointer, and several other fields specific to memory references. 1463/// 1464class SrcValueSDNode : public SDNode { 1465 const Value *V; 1466 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1467protected: 1468 friend class SelectionDAG; 1469 /// Create a SrcValue for a general value. 1470 explicit SrcValueSDNode(const Value *v) 1471 : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {} 1472 1473public: 1474 /// getValue - return the contained Value. 1475 const Value *getValue() const { return V; } 1476 1477 static bool classof(const SrcValueSDNode *) { return true; } 1478 static bool classof(const SDNode *N) { 1479 return N->getOpcode() == ISD::SRCVALUE; 1480 } 1481}; 1482 1483 1484/// MemOperandSDNode - An SDNode that holds a MemOperand. This is 1485/// used to represent a reference to memory after ISD::LOAD 1486/// and ISD::STORE have been lowered. 1487/// 1488class MemOperandSDNode : public SDNode { 1489 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1490protected: 1491 friend class SelectionDAG; 1492 /// Create a MemOperand node 1493 explicit MemOperandSDNode(const MemOperand &mo) 1494 : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {} 1495 1496public: 1497 /// MO - The contained MemOperand. 1498 const MemOperand MO; 1499 1500 static bool classof(const MemOperandSDNode *) { return true; } 1501 static bool classof(const SDNode *N) { 1502 return N->getOpcode() == ISD::MEMOPERAND; 1503 } 1504}; 1505 1506 1507class RegisterSDNode : public SDNode { 1508 unsigned Reg; 1509 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1510protected: 1511 friend class SelectionDAG; 1512 RegisterSDNode(unsigned reg, MVT::ValueType VT) 1513 : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) { 1514 } 1515public: 1516 1517 unsigned getReg() const { return Reg; } 1518 1519 static bool classof(const RegisterSDNode *) { return true; } 1520 static bool classof(const SDNode *N) { 1521 return N->getOpcode() == ISD::Register; 1522 } 1523}; 1524 1525class ExternalSymbolSDNode : public SDNode { 1526 const char *Symbol; 1527 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1528protected: 1529 friend class SelectionDAG; 1530 ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT) 1531 : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol, 1532 getSDVTList(VT)), Symbol(Sym) { 1533 } 1534public: 1535 1536 const char *getSymbol() const { return Symbol; } 1537 1538 static bool classof(const ExternalSymbolSDNode *) { return true; } 1539 static bool classof(const SDNode *N) { 1540 return N->getOpcode() == ISD::ExternalSymbol || 1541 N->getOpcode() == ISD::TargetExternalSymbol; 1542 } 1543}; 1544 1545class CondCodeSDNode : public SDNode { 1546 ISD::CondCode Condition; 1547 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1548protected: 1549 friend class SelectionDAG; 1550 explicit CondCodeSDNode(ISD::CondCode Cond) 1551 : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) { 1552 } 1553public: 1554 1555 ISD::CondCode get() const { return Condition; } 1556 1557 static bool classof(const CondCodeSDNode *) { return true; } 1558 static bool classof(const SDNode *N) { 1559 return N->getOpcode() == ISD::CONDCODE; 1560 } 1561}; 1562 1563/// VTSDNode - This class is used to represent MVT::ValueType's, which are used 1564/// to parameterize some operations. 1565class VTSDNode : public SDNode { 1566 MVT::ValueType ValueType; 1567 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1568protected: 1569 friend class SelectionDAG; 1570 explicit VTSDNode(MVT::ValueType VT) 1571 : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) { 1572 } 1573public: 1574 1575 MVT::ValueType getVT() const { return ValueType; } 1576 1577 static bool classof(const VTSDNode *) { return true; } 1578 static bool classof(const SDNode *N) { 1579 return N->getOpcode() == ISD::VALUETYPE; 1580 } 1581}; 1582 1583/// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode 1584/// 1585class LSBaseSDNode : public SDNode { 1586private: 1587 // AddrMode - unindexed, pre-indexed, post-indexed. 1588 ISD::MemIndexedMode AddrMode; 1589 1590 // MemoryVT - VT of in-memory value. 1591 MVT::ValueType MemoryVT; 1592 1593 //! SrcValue - Memory location for alias analysis. 1594 const Value *SrcValue; 1595 1596 //! SVOffset - Memory location offset. 1597 int SVOffset; 1598 1599 //! Alignment - Alignment of memory location in bytes. 1600 unsigned Alignment; 1601 1602 //! IsVolatile - True if the store is volatile. 1603 bool IsVolatile; 1604protected: 1605 //! Operand array for load and store 1606 /*! 1607 \note Moving this array to the base class captures more 1608 common functionality shared between LoadSDNode and 1609 StoreSDNode 1610 */ 1611 SDOperand Ops[4]; 1612public: 1613 LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands, 1614 SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT, 1615 const Value *SV, int SVO, unsigned Align, bool Vol) 1616 : SDNode(NodeTy, VTs), 1617 AddrMode(AM), MemoryVT(VT), 1618 SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) 1619 { 1620 for (unsigned i = 0; i != NumOperands; ++i) 1621 Ops[i] = Operands[i]; 1622 InitOperands(Ops, NumOperands); 1623 assert(Align != 0 && "Loads and stores should have non-zero aligment"); 1624 assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) && 1625 "Only indexed loads and stores have a non-undef offset operand"); 1626 } 1627 1628 const SDOperand getChain() const { 1629 return getOperand(0); 1630 } 1631 const SDOperand getBasePtr() const { 1632 return getOperand(getOpcode() == ISD::LOAD ? 1 : 2); 1633 } 1634 const SDOperand getOffset() const { 1635 return getOperand(getOpcode() == ISD::LOAD ? 2 : 3); 1636 } 1637 const SDOperand getValue() const { 1638 assert(getOpcode() == ISD::STORE); 1639 return getOperand(1); 1640 } 1641 1642 const Value *getSrcValue() const { return SrcValue; } 1643 int getSrcValueOffset() const { return SVOffset; } 1644 unsigned getAlignment() const { return Alignment; } 1645 MVT::ValueType getMemoryVT() const { return MemoryVT; } 1646 bool isVolatile() const { return IsVolatile; } 1647 1648 ISD::MemIndexedMode getAddressingMode() const { return AddrMode; } 1649 1650 /// isIndexed - Return true if this is a pre/post inc/dec load/store. 1651 bool isIndexed() const { return AddrMode != ISD::UNINDEXED; } 1652 1653 /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store. 1654 bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; } 1655 1656 /// getMemOperand - Return a MemOperand object describing the memory 1657 /// reference performed by this load or store. 1658 MemOperand getMemOperand() const; 1659 1660 static bool classof(const LSBaseSDNode *N) { return true; } 1661 static bool classof(const SDNode *N) { 1662 return N->getOpcode() == ISD::LOAD || 1663 N->getOpcode() == ISD::STORE; 1664 } 1665}; 1666 1667/// LoadSDNode - This class is used to represent ISD::LOAD nodes. 1668/// 1669class LoadSDNode : public LSBaseSDNode { 1670 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1671 1672 // ExtType - non-ext, anyext, sext, zext. 1673 ISD::LoadExtType ExtType; 1674 1675protected: 1676 friend class SelectionDAG; 1677 LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs, 1678 ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT, 1679 const Value *SV, int O=0, unsigned Align=0, bool Vol=false) 1680 : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3, 1681 VTs, AM, LVT, SV, O, Align, Vol), 1682 ExtType(ETy) { } 1683public: 1684 1685 ISD::LoadExtType getExtensionType() const { return ExtType; } 1686 1687 static bool classof(const LoadSDNode *) { return true; } 1688 static bool classof(const SDNode *N) { 1689 return N->getOpcode() == ISD::LOAD; 1690 } 1691}; 1692 1693/// StoreSDNode - This class is used to represent ISD::STORE nodes. 1694/// 1695class StoreSDNode : public LSBaseSDNode { 1696 virtual void ANCHOR(); // Out-of-line virtual method to give class a home. 1697 1698 // IsTruncStore - True if the op does a truncation before store. 1699 bool IsTruncStore; 1700protected: 1701 friend class SelectionDAG; 1702 StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs, 1703 ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT, 1704 const Value *SV, int O=0, unsigned Align=0, bool Vol=false) 1705 : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4, 1706 VTs, AM, SVT, SV, O, Align, Vol), 1707 IsTruncStore(isTrunc) { } 1708public: 1709 1710 bool isTruncatingStore() const { return IsTruncStore; } 1711 1712 static bool classof(const StoreSDNode *) { return true; } 1713 static bool classof(const SDNode *N) { 1714 return N->getOpcode() == ISD::STORE; 1715 } 1716}; 1717 1718 1719class SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> { 1720 SDNode *Node; 1721 unsigned Operand; 1722 1723 SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {} 1724public: 1725 bool operator==(const SDNodeIterator& x) const { 1726 return Operand == x.Operand; 1727 } 1728 bool operator!=(const SDNodeIterator& x) const { return !operator==(x); } 1729 1730 const SDNodeIterator &operator=(const SDNodeIterator &I) { 1731 assert(I.Node == Node && "Cannot assign iterators to two different nodes!"); 1732 Operand = I.Operand; 1733 return *this; 1734 } 1735 1736 pointer operator*() const { 1737 return Node->getOperand(Operand).Val; 1738 } 1739 pointer operator->() const { return operator*(); } 1740 1741 SDNodeIterator& operator++() { // Preincrement 1742 ++Operand; 1743 return *this; 1744 } 1745 SDNodeIterator operator++(int) { // Postincrement 1746 SDNodeIterator tmp = *this; ++*this; return tmp; 1747 } 1748 1749 static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); } 1750 static SDNodeIterator end (SDNode *N) { 1751 return SDNodeIterator(N, N->getNumOperands()); 1752 } 1753 1754 unsigned getOperand() const { return Operand; } 1755 const SDNode *getNode() const { return Node; } 1756}; 1757 1758template <> struct GraphTraits<SDNode*> { 1759 typedef SDNode NodeType; 1760 typedef SDNodeIterator ChildIteratorType; 1761 static inline NodeType *getEntryNode(SDNode *N) { return N; } 1762 static inline ChildIteratorType child_begin(NodeType *N) { 1763 return SDNodeIterator::begin(N); 1764 } 1765 static inline ChildIteratorType child_end(NodeType *N) { 1766 return SDNodeIterator::end(N); 1767 } 1768}; 1769 1770template<> 1771struct ilist_traits<SDNode> { 1772 static SDNode *getPrev(const SDNode *N) { return N->Prev; } 1773 static SDNode *getNext(const SDNode *N) { return N->Next; } 1774 1775 static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; } 1776 static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; } 1777 1778 static SDNode *createSentinel() { 1779 return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other)); 1780 } 1781 static void destroySentinel(SDNode *N) { delete N; } 1782 //static SDNode *createNode(const SDNode &V) { return new SDNode(V); } 1783 1784 1785 void addNodeToList(SDNode *NTy) {} 1786 void removeNodeFromList(SDNode *NTy) {} 1787 void transferNodesFromList(iplist<SDNode, ilist_traits> &L2, 1788 const ilist_iterator<SDNode> &X, 1789 const ilist_iterator<SDNode> &Y) {} 1790}; 1791 1792namespace ISD { 1793 /// isNormalLoad - Returns true if the specified node is a non-extending 1794 /// and unindexed load. 1795 inline bool isNormalLoad(const SDNode *N) { 1796 if (N->getOpcode() != ISD::LOAD) 1797 return false; 1798 const LoadSDNode *Ld = cast<LoadSDNode>(N); 1799 return Ld->getExtensionType() == ISD::NON_EXTLOAD && 1800 Ld->getAddressingMode() == ISD::UNINDEXED; 1801 } 1802 1803 /// isNON_EXTLoad - Returns true if the specified node is a non-extending 1804 /// load. 1805 inline bool isNON_EXTLoad(const SDNode *N) { 1806 return N->getOpcode() == ISD::LOAD && 1807 cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD; 1808 } 1809 1810 /// isEXTLoad - Returns true if the specified node is a EXTLOAD. 1811 /// 1812 inline bool isEXTLoad(const SDNode *N) { 1813 return N->getOpcode() == ISD::LOAD && 1814 cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD; 1815 } 1816 1817 /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD. 1818 /// 1819 inline bool isSEXTLoad(const SDNode *N) { 1820 return N->getOpcode() == ISD::LOAD && 1821 cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD; 1822 } 1823 1824 /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD. 1825 /// 1826 inline bool isZEXTLoad(const SDNode *N) { 1827 return N->getOpcode() == ISD::LOAD && 1828 cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD; 1829 } 1830 1831 /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load. 1832 /// 1833 inline bool isUNINDEXEDLoad(const SDNode *N) { 1834 return N->getOpcode() == ISD::LOAD && 1835 cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED; 1836 } 1837 1838 /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating 1839 /// store. 1840 inline bool isNON_TRUNCStore(const SDNode *N) { 1841 return N->getOpcode() == ISD::STORE && 1842 !cast<StoreSDNode>(N)->isTruncatingStore(); 1843 } 1844 1845 /// isTRUNCStore - Returns true if the specified node is a truncating 1846 /// store. 1847 inline bool isTRUNCStore(const SDNode *N) { 1848 return N->getOpcode() == ISD::STORE && 1849 cast<StoreSDNode>(N)->isTruncatingStore(); 1850 } 1851} 1852 1853 1854} // end llvm namespace 1855 1856#endif 1857