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