SelectionDAGNodes.h revision ef02b815cb37017d8dbac2f18c75bff0aa317163
163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//===-- llvm/CodeGen/SelectionDAGNodes.h - SelectionDAG Nodes ---*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//                     The LLVM Compiler Infrastructure
463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//===----------------------------------------------------------------------===//
9ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
1063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner// This file declares the SDNode class and derived classes, which are used to
1163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner// represent the nodes and operations present in a SelectionDAG.  These nodes
1263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner// and operations are machine code level operations, with some similarities to
1363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner// the GCC RTL representation.
1463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//
1563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner// Clients should include the SelectionDAG.h file instead of this file directly.
1663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//
1763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//===----------------------------------------------------------------------===//
1863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner#ifndef LLVM_CODEGEN_SELECTIONDAGNODES_H
2063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner#define LLVM_CODEGEN_SELECTIONDAGNODES_H
2163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
222d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth#include "llvm/Value.h"
23583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/ADT/FoldingSet.h"
241080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner#include "llvm/ADT/GraphTraits.h"
251080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner#include "llvm/ADT/iterator"
268bb369b8072c919ef5802f639a52b17620201190Dale Johannesen#include "llvm/ADT/APFloat.h"
276394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman#include "llvm/ADT/APInt.h"
28d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng#include "llvm/CodeGen/ValueTypes.h"
2936b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman#include "llvm/CodeGen/MachineMemOperand.h"
3039931a3dbac1aa2fe2ec14f26001c8c29102940cJeff Cohen#include "llvm/Support/DataTypes.h"
3163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner#include <cassert>
3263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
3363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnernamespace llvm {
3463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
3563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass SelectionDAG;
3663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass GlobalValue;
3763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass MachineBasicBlock;
38d6594ae54cfde4db4d30272192645c0a45fb9902Evan Chengclass MachineConstantPoolValue;
3963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass SDNode;
4076c1b97e4020faace8c95a127f1eab66c278fb58Chris Lattnertemplate <typename T> struct DenseMapInfo;
4163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnertemplate <typename T> struct simplify_type;
42b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattnertemplate <typename T> struct ilist_traits;
43b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattnertemplate<typename NodeTy, typename Traits> class iplist;
44b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattnertemplate<typename NodeTy> class ilist_iterator;
4563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
460b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner/// SDVTList - This represents a list of ValueType's that has been intern'd by
470b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner/// a SelectionDAG.  Instances of this simple value class are returned by
480b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner/// SelectionDAG::getVTList(...).
490b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner///
500b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattnerstruct SDVTList {
510b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner  const MVT::ValueType *VTs;
520b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner  unsigned short NumVTs;
530b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner};
540b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner
5563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// ISD namespace - This namespace contains an enum which represents all of the
5663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// SelectionDAG node types and value types.
5763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner///
5863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnernamespace ISD {
59d0b82b301d700217a716526f9329bb031e0d6578Anton Korobeynikov
6063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  //===--------------------------------------------------------------------===//
6163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// ISD::NodeType enum - This enum defines all of the operators valid in a
6263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// SelectionDAG.
6363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
6463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  enum NodeType {
653258ed6a361bf405a89f7af0b1885841d9909516Chris Lattner    // DELETED_NODE - This is an illegal flag value that is used to catch
663258ed6a361bf405a89f7af0b1885841d9909516Chris Lattner    // errors.  This opcode is not a legal opcode for any node.
673258ed6a361bf405a89f7af0b1885841d9909516Chris Lattner    DELETED_NODE,
683258ed6a361bf405a89f7af0b1885841d9909516Chris Lattner
698a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    // EntryToken - This is the marker used to indicate the start of the region.
708a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    EntryToken,
718a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner
728c4bde36a339b1c538002e819daff84caae4cbadReid Spencer    // Token factor - This node takes multiple tokens as input and produces a
738a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    // single token result.  This is used to represent the fact that the operand
748a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    // operators are independent of each other.
758a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    TokenFactor,
76f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman
77f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    // AssertSext, AssertZext - These nodes record if a register contains a
78f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    // value that has already been zero or sign extended from a narrower type.
79f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    // These nodes take two operands.  The first is the node that has already
80f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    // been extended, and the second is a value type node indicating the width
81f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    // of the extension
82f7f3d321916c1ef3a82b2a175a368a148b1ede46Nate Begeman    AssertSext, AssertZext,
83ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
848a496fcffdcba757412fc5cc6c772260ccfde000Chris Lattner    // Various leaf nodes.
85276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    STRING, BasicBlock, VALUETYPE, ARG_FLAGS, CONDCODE, Register,
861ab7d859cf5c490612799d7e132c0b1c39f8f497Evan Cheng    Constant, ConstantFP,
87b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio    GlobalAddress, GlobalTLSAddress, FrameIndex,
88b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio    JumpTable, ConstantPool, ExternalSymbol,
891ab7d859cf5c490612799d7e132c0b1c39f8f497Evan Cheng
9082c3d8f81ab20dc7571f29ffc46a5bb1b7ed8323Andrew Lenharth    // The address of the GOT
9182c3d8f81ab20dc7571f29ffc46a5bb1b7ed8323Andrew Lenharth    GLOBAL_OFFSET_TABLE,
92bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman
93bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    // FRAMEADDR, RETURNADDR - These nodes represent llvm.frameaddress and
94bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    // llvm.returnaddress on the DAG.  These nodes take one operand, the index
95bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    // of the frame or return address to return.  An index of zero corresponds
96bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    // to the current function's frame or return address, an index of one to the
97bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    // parent's frame or return address, and so on.
98bcc5f36765e8111c13873a0c0dc874c92385d808Nate Begeman    FRAMEADDR, RETURNADDR,
992365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov
1002365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // FRAME_TO_ARGS_OFFSET - This node represents offset from frame pointer to
1012365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // first (possible) on-stack argument. This is needed for correct stack
1022365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // adjustment during unwind.
1032365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    FRAME_TO_ARGS_OFFSET,
104f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey
105f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    // RESULT, OUTCHAIN = EXCEPTIONADDR(INCHAIN) - This node represents the
106f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    // address of the exception block on entry to an landing pad block.
107f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    EXCEPTIONADDR,
108f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey
109f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    // RESULT, OUTCHAIN = EHSELECTION(INCHAIN, EXCEPTION) - This node represents
110f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    // the selection index of the exception thrown.
111f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey    EHSELECTION,
112beec30eaf301bd6882cd06800b5175b94f033f9dAndrew Lenharth
1132365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // OUTCHAIN = EH_RETURN(INCHAIN, OFFSET, HANDLER) - This node represents
1142365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // 'eh_return' gcc dwarf builtin, which is used to return from
1152365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // exception. The general meaning is: adjust stack by OFFSET and pass
1162365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    // execution to HANDLER. Many platform-related details also :)
1172365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov    EH_RETURN,
1182365f51ed03afe6993bae962fdc2e5a956a64cd5Anton Korobeynikov
119ac0d7238258defe72b1aad53d7f48201b91df795Chris Lattner    // TargetConstant* - Like Constant*, but the DAG does not do any folding or
120ac0d7238258defe72b1aad53d7f48201b91df795Chris Lattner    // simplification of the constant.
121056f9f61d071c6c583951678f2bf543a1316efccChris Lattner    TargetConstant,
122ac0d7238258defe72b1aad53d7f48201b91df795Chris Lattner    TargetConstantFP,
123f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner
124f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner    // TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or
125f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner    // anything else with this node, and this is valid in the target-specific
126f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner    // dag, turning into a GlobalAddress operand.
127f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner    TargetGlobalAddress,
128b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio    TargetGlobalTLSAddress,
129afb2dd43de61f4585e75d1f3ab93a9ac4b3b7592Chris Lattner    TargetFrameIndex,
13037efe6764568a3829fee26aba532283131d1a104Nate Begeman    TargetJumpTable,
131aaaaf79d4aaa172c2f2ae0e327bbae523a045bf5Chris Lattner    TargetConstantPool,
1322a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth    TargetExternalSymbol,
13372601cac6051a9571ca4db3b32d6a73e40b40bd1Chris Lattner
134ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...)
135ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// This node represents a target intrinsic function with no side effects.
136ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// The first operand is the ID number of the intrinsic from the
137ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// llvm::Intrinsic namespace.  The operands to the intrinsic follow.  The
138ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// node has returns the result of the intrinsic.
139ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    INTRINSIC_WO_CHAIN,
140ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner
141ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...)
142ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// This node represents a target intrinsic function with side effects that
143ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// returns a result.  The first operand is a chain pointer.  The second is
144ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// the ID number of the intrinsic from the llvm::Intrinsic namespace.  The
145ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// operands to the intrinsic follow.  The node has two results, the result
146ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// of the intrinsic and an output chain.
147ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    INTRINSIC_W_CHAIN,
14863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
149ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...)
150ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// This node represents a target intrinsic function with side effects that
151ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// does not return a result.  The first operand is a chain pointer.  The
152ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// second is the ID number of the intrinsic from the llvm::Intrinsic
153ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    /// namespace.  The operands to the intrinsic follow.
154ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner    INTRINSIC_VOID,
155ef8ef916348ad0da964687358e8be614e2470d67Chris Lattner
156d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    // CopyToReg - This node has three operands: a chain, a register number to
157d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    // set to this value, and a value.
15863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    CopyToReg,
15963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
16063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // CopyFromReg - This node indicates that the input value is a virtual or
16163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // physical register that is defined outside of the scope of this
162ab2a7542546bf781fa373e20095be0e344f5b3ccDan Gohman    // SelectionDAG.  The register is available from the RegisterSDNode object.
16363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    CopyFromReg,
16463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
165fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman    // UNDEF - An undefined node
166fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman    UNDEF,
167681ee1c1c3f7c3558c29a5bf3a668c1d0784c399Chris Lattner
168b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// FORMAL_ARGUMENTS(CHAIN, CC#, ISVARARG, FLAG0, ..., FLAGn) - This node
169b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// represents the formal arguments for a function.  CC# is a Constant value
170b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// indicating the calling convention of the function, and ISVARARG is a
171b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// flag that indicates whether the function is varargs or not. This node
172b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// has one result value for each incoming argument, plus one for the output
173b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// chain. It must be custom legalized. See description of CALL node for
174b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// FLAG argument contents explanation.
175c1a8ad71e11123f1e3c8d9913a7f51978b9967d5Chris Lattner    ///
176681ee1c1c3f7c3558c29a5bf3a668c1d0784c399Chris Lattner    FORMAL_ARGUMENTS,
1776c0bfc723779366698d3936b63dcddc6164c2d33Chris Lattner
1786c0bfc723779366698d3936b63dcddc6164c2d33Chris Lattner    /// RV1, RV2...RVn, CHAIN = CALL(CHAIN, CC#, ISVARARG, ISTAILCALL, CALLEE,
179b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    ///                              ARG0, FLAG0, ARG1, FLAG1, ... ARGn, FLAGn)
1806c0bfc723779366698d3936b63dcddc6164c2d33Chris Lattner    /// This node represents a fully general function call, before the legalizer
181b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// runs.  This has one result value for each argument / flag pair, plus
182b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// a chain result. It must be custom legalized. Flag argument indicates
183b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// misc. argument attributes. Currently:
184b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// Bit 0 - signness
185b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// Bit 1 - 'inreg' attribute
186b10308e440c80dd6ffb4b478f741ff7e5f30cb48Anton Korobeynikov    /// Bit 2 - 'sret' attribute
187594d37e21aea4ef841d9ee5d9c328c4bf1c6bed7Rafael Espindola    /// Bit 4 - 'byval' attribute
188594d37e21aea4ef841d9ee5d9c328c4bf1c6bed7Rafael Espindola    /// Bit 5 - 'nest' attribute
189594d37e21aea4ef841d9ee5d9c328c4bf1c6bed7Rafael Espindola    /// Bit 6-9 - alignment of byval structures
190594d37e21aea4ef841d9ee5d9c328c4bf1c6bed7Rafael Espindola    /// Bit 10-26 - size of byval structures
19113a3cee13133711eb95174a004dca4421ccd1cd9Lauro Ramos Venancio    /// Bits 31:27 - argument ABI alignment in the first argument piece and
19213a3cee13133711eb95174a004dca4421ccd1cd9Lauro Ramos Venancio    /// alignment '1' in other argument pieces.
1936c0bfc723779366698d3936b63dcddc6164c2d33Chris Lattner    CALL,
194fc1b1dad88a256ab5ab16dd548ad82df8efa2ca9Nate Begeman
19525eb043759c23b61769108f78382eb9701c41db2Duncan Sands    // EXTRACT_ELEMENT - This is used to get the lower or upper (determined by
19625eb043759c23b61769108f78382eb9701c41db2Duncan Sands    // a Constant, which is required to be operand #1) half of the integer value
19725eb043759c23b61769108f78382eb9701c41db2Duncan Sands    // specified as operand #0.  This is only for use before legalization, for
19825eb043759c23b61769108f78382eb9701c41db2Duncan Sands    // values that will be broken into multiple registers.
19963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    EXTRACT_ELEMENT,
20063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
20163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.  Given
20263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // two values of the same integer value type, this produces a value twice as
20363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // big.  Like EXTRACT_ELEMENT, this can only be used before legalization.
20463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    BUILD_PAIR,
205006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner
206006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    // MERGE_VALUES - This node takes multiple discrete operands and returns
207006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    // them all as its individual results.  This nodes has exactly the same
208006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    // number of inputs and outputs, and is only valid before legalization.
209006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    // This node is useful for some pieces of the code generator that want to
210006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    // think about a single node with multiple results, not multiple nodes.
211006e3e3649b2e19762b7bc134292b781569685b0Chris Lattner    MERGE_VALUES,
21263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
213615c2d0920862ae7d4d766ee3da660ecf2197308Chris Lattner    // Simple integer binary arithmetic operators.
214bede0b7dd7c70792b09f6d38f6f2dfe7c1feb1d1Chris Lattner    ADD, SUB, MUL, SDIV, UDIV, SREM, UREM,
215fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman
216fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    // SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing
217b36904be918b72cc4c714552d42d6a713f27bbf5Duncan Sands    // a signed/unsigned value of type i[2*N], and return the full value as
218fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    // two results, each of type iN.
219fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    SMUL_LOHI, UMUL_LOHI,
220fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman
221fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    // SDIVREM/UDIVREM - Divide two integers and produce both a quotient and
222fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    // remainder result.
223fdd04d5ddecb1d1f3030839520109308137b73dcDan Gohman    SDIVREM, UDIVREM,
224615c2d0920862ae7d4d766ee3da660ecf2197308Chris Lattner
22555e34eb31741f7902445cfa94fddde7a6910c408Chris Lattner    // CARRY_FALSE - This node is used when folding other nodes,
22655e34eb31741f7902445cfa94fddde7a6910c408Chris Lattner    // like ADDC/SUBC, which indicate the carry result is always false.
22755e34eb31741f7902445cfa94fddde7a6910c408Chris Lattner    CARRY_FALSE,
22855e34eb31741f7902445cfa94fddde7a6910c408Chris Lattner
229551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // Carry-setting nodes for multiple precision addition and subtraction.
230551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // These nodes take two operands of the same value type, and produce two
231551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // results.  The first result is the normal add or sub result, the second
232551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // result is the carry flag result.
233551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    ADDC, SUBC,
234551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman
235551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // Carry-using nodes for multiple precision addition and subtraction.  These
236551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // nodes take three operands: The first two are the normal lhs and rhs to
237551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // the add or sub, and the third is the input carry flag.  These nodes
238551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // produce two results; the normal result of the add or sub, and the output
239551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // carry flag.  These nodes both read and write a carry flag to allow them
240551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // to them to be chained together for add and sub of arbitrarily large
241551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    // values.
242551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman    ADDE, SUBE,
243551bf3f80058a026b6a128dffd5530019e1df1b9Nate Begeman
244615c2d0920862ae7d4d766ee3da660ecf2197308Chris Lattner    // Simple binary floating point operators.
245615c2d0920862ae7d4d766ee3da660ecf2197308Chris Lattner    FADD, FSUB, FMUL, FDIV, FREM,
24638bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner
24738bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner    // FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.  NOTE: This
24838bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner    // DAG node does not require that X and Y have the same type, just that they
24938bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner    // are both floating point.  X and the result must have the same type.
25038bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner    // FCOPYSIGN(f32, f64) is allowed.
25138bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner    FCOPYSIGN,
252fa984b61e42c94ad7e66cf2880ca826dba488d30Chris Lattner
2531a3048bb8e0f3de0b4e56704c15c556c71565f4bChris Lattner    // INT = FGETSIGN(FP) - Return the sign bit of the specified floating point
2541a3048bb8e0f3de0b4e56704c15c556c71565f4bChris Lattner    // value as an integer 0/1 value.
2551a3048bb8e0f3de0b4e56704c15c556c71565f4bChris Lattner    FGETSIGN,
2561a3048bb8e0f3de0b4e56704c15c556c71565f4bChris Lattner
257664e9546d674096c5a012536f1a424b1681ece51Dan Gohman    /// BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector
25822232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner    /// with the specified, possibly variable, elements.  The number of elements
25922232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner    /// is required to be a power of two.
26022232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner    BUILD_VECTOR,
26122232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner
2627f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element
2634f069e6db1772a7e6cd8bfc360d819b56557badcDuncan Sands    /// at IDX replaced with VAL.  If the type of VAL is larger than the vector
2644f069e6db1772a7e6cd8bfc360d819b56557badcDuncan Sands    /// element type then VAL is truncated before replacement.
26522232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner    INSERT_VECTOR_ELT,
2664b8db6c453fd3a7b07bc7c0e8092018530701ffdChris Lattner
2674b8db6c453fd3a7b07bc7c0e8092018530701ffdChris Lattner    /// EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR
2687f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// identified by the (potentially variable) element number IDX.
2694b8db6c453fd3a7b07bc7c0e8092018530701ffdChris Lattner    EXTRACT_VECTOR_ELT,
27022232f659bec0f4c23ec46445d3bd3c4deb68686Chris Lattner
2717f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of
2727f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// vector type with the same length and element type, this produces a
2737f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// concatenated vector result value, with length equal to the sum of the
274b6f5b00c3bad3415d3f2ee1a6d5ee5a6f66a4540Dan Gohman    /// lengths of the input vectors.
2757f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    CONCAT_VECTORS,
2766595635175764f402e7a5e53216c8d46bdce8c28Dan Gohman
2777f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an
2787f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// vector value) starting with the (potentially variable) element number
2797f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    /// IDX, which must be a multiple of the result vector length.
2807f32156bb9c017b71971c52fac892fa7b9b06dd2Dan Gohman    EXTRACT_SUBVECTOR,
28159c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands
28249c6d3eba8869cf945f6c55ea243466e2b406fe8Chris Lattner    /// VECTOR_SHUFFLE(VEC1, VEC2, SHUFFLEVEC) - Returns a vector, of the same
28349c6d3eba8869cf945f6c55ea243466e2b406fe8Chris Lattner    /// type as VEC1/VEC2.  SHUFFLEVEC is a BUILD_VECTOR of constant int values
28459c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands    /// (maybe of an illegal datatype) or undef that indicate which value each
28559c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands    /// result element will get.  The elements of VEC1/VEC2 are enumerated in
28659c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands    /// order.  This is quite similar to the Altivec 'vperm' instruction, except
28759c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands    /// that the indices must be constants and are in terms of the element size
28859c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands    /// of VEC1/VEC2, not in terms of bytes.
28949c6d3eba8869cf945f6c55ea243466e2b406fe8Chris Lattner    VECTOR_SHUFFLE,
29059c2e868ff15d77e00c89ad9591a87e84bd0665aDuncan Sands
291210721aecc0916315f61660dc387a96b89ec423bChris Lattner    /// SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a
292a95afe2b5fb7a716ff4cc7bb623995a0a4c56411Nate Begeman    /// scalar value into element 0 of the resultant vector type.  The top
293a95afe2b5fb7a716ff4cc7bb623995a0a4c56411Nate Begeman    /// elements 1 to N-1 of the N-element vector are undefined.
294210721aecc0916315f61660dc387a96b89ec423bChris Lattner    SCALAR_TO_VECTOR,
295210721aecc0916315f61660dc387a96b89ec423bChris Lattner
296557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb    // EXTRACT_SUBREG - This node is used to extract a sub-register value.
297557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb    // This node takes a superreg and a constant sub-register index as operands.
298709d19fb6677d8f31c7c9d2457f3647cb09b1941Evan Cheng    // Note sub-register indices must be increasing. That is, if the
299709d19fb6677d8f31c7c9d2457f3647cb09b1941Evan Cheng    // sub-register index of a 8-bit sub-register is N, then the index for a
300709d19fb6677d8f31c7c9d2457f3647cb09b1941Evan Cheng    // 16-bit sub-register must be at least N+1.
301557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb    EXTRACT_SUBREG,
302557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb
3034499e495eabe8de7d595416a03c56af4688df507Evan Cheng    // INSERT_SUBREG - This node is used to insert a sub-register value.
304557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb    // This node takes a superreg, a subreg value, and a constant sub-register
3054499e495eabe8de7d595416a03c56af4688df507Evan Cheng    // index as operands.
306557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb    INSERT_SUBREG,
307557c3631d320c5731e55b6f818a1c7b2d4d97176Christopher Lamb
308bede0b7dd7c70792b09f6d38f6f2dfe7c1feb1d1Chris Lattner    // MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing
309b36904be918b72cc4c714552d42d6a713f27bbf5Duncan Sands    // an unsigned/signed value of type i[2*N], then return the top part.
310bede0b7dd7c70792b09f6d38f6f2dfe7c1feb1d1Chris Lattner    MULHU, MULHS,
31163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
31235ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman    // Bitwise operators - logical and, logical or, logical xor, shift left,
31335ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman    // shift right algebraic (shift in sign bits), shift right logical (shift in
31435ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman    // zeroes), rotate left, rotate right, and byteswap.
31535ef913ec21de0f4f1b39c811b4335438717a9b8Nate Begeman    AND, OR, XOR, SHL, SRA, SRL, ROTL, ROTR, BSWAP,
31663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
317691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth    // Counting operators
318691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth    CTTZ, CTLZ, CTPOP,
319691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
320fa984b61e42c94ad7e66cf2880ca826dba488d30Chris Lattner    // Select(COND, TRUEVAL, FALSEVAL)
3219373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    SELECT,
3229373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
3239373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    // Select with condition operator - This selects between a true value and
3249373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    // a false value (ops #2 and #3) based on the boolean result of comparing
3259373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    // the lhs and rhs (ops #0 and #1) of a conditional expression with the
3269373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    // condition code in op #4, a CondCodeSDNode.
3279373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman    SELECT_CC,
32863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
32963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // SetCC operator - This evaluates to a boolean (i1) true value if the
3307cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    // condition is true.  The operands to this are the left and right operands
3317cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    // to compare (ops #0, and #1) and the condition code to compare them with
3327cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    // (op #2) as a CondCodeSDNode.
33363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETCC,
33463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
33514c5b53c037a6a175118ed1a7d7e0e74153d56c4Chris Lattner    // SHL_PARTS/SRA_PARTS/SRL_PARTS - These operators are used for expanded
33614c5b53c037a6a175118ed1a7d7e0e74153d56c4Chris Lattner    // integer shift operations, just like ADD/SUB_PARTS.  The operation
33714c5b53c037a6a175118ed1a7d7e0e74153d56c4Chris Lattner    // ordering is:
3386b8f2d649c1e96e0222be9de1e5d6c79e3eef021Chris Lattner    //       [Lo,Hi] = op [LoLHS,HiLHS], Amt
33914c5b53c037a6a175118ed1a7d7e0e74153d56c4Chris Lattner    SHL_PARTS, SRA_PARTS, SRL_PARTS,
34014c5b53c037a6a175118ed1a7d7e0e74153d56c4Chris Lattner
34163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // Conversion operators.  These are all single input single output
34263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // operations.  For all of these, the result type must be strictly
34363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // wider or narrower (depending on the operation) than the source
34463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // type.
34563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
34663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // SIGN_EXTEND - Used for integer types, replicating the sign bit
34763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // into new bits.
34863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SIGN_EXTEND,
34963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
35063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // ZERO_EXTEND - Used for integer types, zeroing the new bits.
35163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    ZERO_EXTEND,
35263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
3537e122db776d9731dfe5acb7faa9da4f3c33ee5a1Chris Lattner    // ANY_EXTEND - Used for integer types.  The high bits are undefined.
3547e122db776d9731dfe5acb7faa9da4f3c33ee5a1Chris Lattner    ANY_EXTEND,
3557e122db776d9731dfe5acb7faa9da4f3c33ee5a1Chris Lattner
35663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // TRUNCATE - Completely drop the high bits.
35763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    TRUNCATE,
35863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
3591645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    // [SU]INT_TO_FP - These operators convert integers (whose interpreted sign
3601645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    // depends on the first letter) to floating point.
3611645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    SINT_TO_FP,
3621645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    UINT_TO_FP,
3631645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner
364ea5761068956b157832d67bcc9d5e8ba706f545cChris Lattner    // SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to
365ea5761068956b157832d67bcc9d5e8ba706f545cChris Lattner    // sign extend a small value in a large integer register (e.g. sign
366ea5761068956b157832d67bcc9d5e8ba706f545cChris Lattner    // extending the low 8 bits of a 32-bit register to fill the top 24 bits
36715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner    // with the 7th bit).  The size of the smaller type is indicated by the 1th
36815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner    // operand, a ValueType node.
369859157daee6a4b49e99921832e1dde065167b317Chris Lattner    SIGN_EXTEND_INREG,
370859157daee6a4b49e99921832e1dde065167b317Chris Lattner
3710bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// FP_TO_[US]INT - Convert a floating point value to a signed or unsigned
3720bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// integer.
3731645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    FP_TO_SINT,
3741645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner    FP_TO_UINT,
3751645ed0b93901ec678cd54024c8b09bca632b296Chris Lattner
3760bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type
3770bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// down to the precision of the destination VT.  TRUNC is a flag, which is
3780bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// always an integer that is zero or one.  If TRUNC is 0, this is a
3790bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// normal rounding, if it is 1, this FP_ROUND is known to not change the
3800bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// value of Y.
3810bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    ///
3820bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// The TRUNC = 1 case is used in cases where we know that the value will
3830bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// not be modified by the node, because Y is not using any of the extra
3840bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// precision of source type.  This allows certain transformations like
3850bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// FP_EXTEND(FP_ROUND(X,1)) -> X which are not safe for
3860bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// FP_EXTEND(FP_ROUND(X,0)) because the extra bits aren't removed.
38763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    FP_ROUND,
3880bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner
3891a0248690aaa9f7baaf1247e5f65a1c0c9e3783cDan Gohman    // FLT_ROUNDS_ - Returns current rounding mode:
390917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov    // -1 Undefined
391917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov    //  0 Round to 0
392917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov    //  1 Round to nearest
393917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov    //  2 Round to +inf
394917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov    //  3 Round to -inf
3951a0248690aaa9f7baaf1247e5f65a1c0c9e3783cDan Gohman    FLT_ROUNDS_,
396917c2a6ff2cfcd1263a5dd80c54336754c553aceAnton Korobeynikov
3970bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// X = FP_ROUND_INREG(Y, VT) - This operator takes an FP register, and
3980bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// rounds it to a floating point value.  It then promotes it and returns it
3990bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// in a register of the same size.  This operation effectively just
4000bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// discards excess precision.  The type to round down to is specified by
4010bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// the VT operand, a VTSDNode.
402859157daee6a4b49e99921832e1dde065167b317Chris Lattner    FP_ROUND_INREG,
403859157daee6a4b49e99921832e1dde065167b317Chris Lattner
4040bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner    /// X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
40563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    FP_EXTEND,
40663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
4071ac1c4b9d2877bd2d15bcf578bc617a605d815b0Chris Lattner    // BIT_CONVERT - Theis operator converts between integer and FP values, as
4081ac1c4b9d2877bd2d15bcf578bc617a605d815b0Chris Lattner    // if one was stored to memory as integer and the other was loaded from the
40980f55abf009c86bc03821e10746832f88f8a735fChris Lattner    // same address (or equivalently for vector format conversions, etc).  The
41080f55abf009c86bc03821e10746832f88f8a735fChris Lattner    // source and result are required to have the same bit size (e.g.
41180f55abf009c86bc03821e10746832f88f8a735fChris Lattner    // f32 <-> i32).  This can also be used for int-to-int or fp-to-fp
41280f55abf009c86bc03821e10746832f88f8a735fChris Lattner    // conversions, but that is a noop, deleted by getNode().
4131ac1c4b9d2877bd2d15bcf578bc617a605d815b0Chris Lattner    BIT_CONVERT,
4141ac1c4b9d2877bd2d15bcf578bc617a605d815b0Chris Lattner
41507f04fd574a59c690f297fd10c2e0dd14093675eDan Gohman    // FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW - Perform unary floating point
41607f04fd574a59c690f297fd10c2e0dd14093675eDan Gohman    // negation, absolute value, square root, sine and cosine, powi, and pow
417dd2afb0e1f65bc41d2c0053468fcddfd696a8231Chris Lattner    // operations.
41807f04fd574a59c690f297fd10c2e0dd14093675eDan Gohman    FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW,
41938bf3bffe3abfd00169d6dcf4fad7e2197808dbfChris Lattner
4208862ef148100070b7bf28beead3951464250c926Evan Cheng    // LOAD and STORE have token chains as their first operand, then the same
4218862ef148100070b7bf28beead3951464250c926Evan Cheng    // operands as an LLVM load/store instruction, then an offset node that
4228862ef148100070b7bf28beead3951464250c926Evan Cheng    // is added / subtracted from the base pointer to form the address (for
4238862ef148100070b7bf28beead3951464250c926Evan Cheng    // indexed memory ops).
42463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    LOAD, STORE,
425ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
42663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned
42757fc00d5cf47343ba762493b8781ca0b14489c35Anton Korobeynikov    // to a specified boundary.  This node always has two return values: a new
42857fc00d5cf47343ba762493b8781ca0b14489c35Anton Korobeynikov    // stack pointer value and a chain. The first operand is the token chain,
42957fc00d5cf47343ba762493b8781ca0b14489c35Anton Korobeynikov    // the second is the number of bytes to allocate, and the third is the
43057fc00d5cf47343ba762493b8781ca0b14489c35Anton Korobeynikov    // alignment boundary.  The size is guaranteed to be a multiple of the stack
43157fc00d5cf47343ba762493b8781ca0b14489c35Anton Korobeynikov    // alignment, and the alignment is guaranteed to be bigger than the stack
43274fe063e90045931eefaba561730e6a9175ced78Chris Lattner    // alignment (if required) or 0 to get standard stack alignment.
43363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    DYNAMIC_STACKALLOC,
43463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
43563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // Control flow instructions.  These all have token chains.
436ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
43763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // BR - Unconditional branch.  The first operand is the chain
43863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // operand, the second is the MBB to branch to.
43963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    BR,
44063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
44137efe6764568a3829fee26aba532283131d1a104Nate Begeman    // BRIND - Indirect branch.  The first operand is the chain, the second
44237efe6764568a3829fee26aba532283131d1a104Nate Begeman    // is the value to branch to, which must be of the same type as the target's
44337efe6764568a3829fee26aba532283131d1a104Nate Begeman    // pointer type.
44437efe6764568a3829fee26aba532283131d1a104Nate Begeman    BRIND,
445c41cd9c391f1f69adf416145a5a1308d7ce342fcEvan Cheng
446c41cd9c391f1f69adf416145a5a1308d7ce342fcEvan Cheng    // BR_JT - Jumptable branch. The first operand is the chain, the second
447c41cd9c391f1f69adf416145a5a1308d7ce342fcEvan Cheng    // is the jumptable index, the last one is the jumptable entry index.
448c41cd9c391f1f69adf416145a5a1308d7ce342fcEvan Cheng    BR_JT,
44937efe6764568a3829fee26aba532283131d1a104Nate Begeman
45063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // BRCOND - Conditional branch.  The first operand is the chain,
45163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // the second is the condition, the third is the block to branch
45263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // to if the condition is true.
45363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    BRCOND,
45463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
4557cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman    // BR_CC - Conditional branch.  The behavior is like that of SELECT_CC, in
4567cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman    // that the condition is represented as condition code, and two nodes to
4577cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman    // compare, rather than as a combined SetCC node.  The operands in order are
4587cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman    // chain, cc, lhs, rhs, block to branch to if condition is true.
4597cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman    BR_CC,
4607cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
46163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // RET - Return from function.  The first operand is the chain,
4628e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng    // and any subsequent operands are pairs of return value and return value
4638e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng    // signness for the function.  This operation can have variable number of
4648e7d056bc5c0688501f6721994c8f4074d699c69Evan Cheng    // operands.
46563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    RET,
46663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
4677572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    // INLINEASM - Represents an inline asm block.  This node always has two
4687572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    // return values: a chain and a flag result.  The inputs are as follows:
4697572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    //   Operand #0   : Input chain.
4707572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    //   Operand #1   : a ExternalSymbolSDNode with a pointer to the asm string.
4717572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    //   Operand #2n+2: A RegisterNode.
4727572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    //   Operand #2n+3: A TargetConstant, indicating if the reg is a use/def
4737572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    //   Operand #last: Optional, an incoming flag.
4747572eb81eee93b0c666ddc5f5ff0ff72f17574fdChris Lattner    INLINEASM,
4751ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey
4761ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    // LABEL - Represents a label in mid basic block used to track
4771ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    // locations needed for debug and exception handling tables.  This node
4781ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    // returns a chain.
4791ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    //   Operand #0 : input chain.
4801ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    //   Operand #1 : module unique number use to identify the label.
481bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng    //   Operand #2 : 0 indicates a debug label (e.g. stoppoint), 1 indicates
482bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng    //                a EH label, 2 indicates unknown label type.
4831ee29257428960fede862fcfdbe80d5d007927e9Jim Laskey    LABEL,
484a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng
485a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng    // DECLARE - Represents a llvm.dbg.declare intrinsic. It's used to track
486a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng    // local variable declarations for debugging information. First operand is
487a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng    // a chain, while the next two operands are first two arguments (address
488a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng    // and variable) of a llvm.dbg.declare instruction.
489a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng    DECLARE,
490f09f2e304dc82010d2e02a9b40a8c5fb0091490cJim Laskey
4915a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    // STACKSAVE - STACKSAVE has one operand, an input chain.  It produces a
4925a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    // value, the same type as the pointer type for the system, and an output
4935a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    // chain.
4945a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    STACKSAVE,
4955a67afc118d47a0061ca9809c763451ea3125306Chris Lattner
4965a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    // STACKRESTORE has two operands, an input chain and a pointer to restore to
4975a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    // it returns an output chain.
4985a67afc118d47a0061ca9809c763451ea3125306Chris Lattner    STACKRESTORE,
4995a67afc118d47a0061ca9809c763451ea3125306Chris Lattner
50016cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    // CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of
50116cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    // a call sequence, and carry arbitrary information that target might want
50216cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    // to know.  The first operand is a chain, the rest are specified by the
50316cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    // target and not touched by the DAG optimizers.
5040ea0356dff38dfd0420b8c0a2fdf2fae7898c024Dale Johannesen    // CALLSEQ_START..CALLSEQ_END pairs may not be nested.
50516cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    CALLSEQ_START,  // Beginning of a call sequence
50616cd04d26c53c6f81313cafb85f6c0e7a07cdff6Chris Lattner    CALLSEQ_END,    // End of a call sequence
507acc398c195a697795bff3245943d104eb19192b9Nate Begeman
508acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // VAARG - VAARG has three operands: an input chain, a pointer, and a
509acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // SRCVALUE.  It returns a pair of values: the vaarg value and a new chain.
510acc398c195a697795bff3245943d104eb19192b9Nate Begeman    VAARG,
511acc398c195a697795bff3245943d104eb19192b9Nate Begeman
512acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // VACOPY - VACOPY has five operands: an input chain, a destination pointer,
513acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // a source pointer, a SRCVALUE for the destination, and a SRCVALUE for the
514acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // source.
515acc398c195a697795bff3245943d104eb19192b9Nate Begeman    VACOPY,
516acc398c195a697795bff3245943d104eb19192b9Nate Begeman
517acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // VAEND, VASTART - VAEND and VASTART have three operands: an input chain, a
518acc398c195a697795bff3245943d104eb19192b9Nate Begeman    // pointer, and a SRCVALUE.
519acc398c195a697795bff3245943d104eb19192b9Nate Begeman    VAEND, VASTART,
52063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
52169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    // SRCVALUE - This is a node type that holds a Value* that is used to
52269de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    // make reference to a value in the LLVM IR.
52321074f43ed5165828717ea3606eb2bd222a39b26Chris Lattner    SRCVALUE,
52421074f43ed5165828717ea3606eb2bd222a39b26Chris Lattner
52536b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman    // MEMOPERAND - This is a node that contains a MachineMemOperand which
52636b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman    // records information about a memory reference. This is used to make
52736b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman    // AliasAnalysis queries from the backend.
52869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    MEMOPERAND,
52969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
530e3f570c3f9048bc71a9f5841343eae63719e439bMisha Brukman    // PCMARKER - This corresponds to the pcmarker intrinsic.
53195762124a1d781cc0f8cbc4c22e9c5c1358d7ea0Andrew Lenharth    PCMARKER,
53263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
533aeef8fc5c6124a34bd2a723071a3982b559c26f2Andrew Lenharth    // READCYCLECOUNTER - This corresponds to the readcyclecounter intrinsic.
5348b91c77385a055474d271aa8c10f0382fdeaafebAndrew Lenharth    // The only operand is a chain and a value and a chain are produced.  The
5358b91c77385a055474d271aa8c10f0382fdeaafebAndrew Lenharth    // value is the contents of the architecture specific cycle counter like
5368b91c77385a055474d271aa8c10f0382fdeaafebAndrew Lenharth    // register (or other high accuracy low latency clock source)
537aeef8fc5c6124a34bd2a723071a3982b559c26f2Andrew Lenharth    READCYCLECOUNTER,
538aeef8fc5c6124a34bd2a723071a3982b559c26f2Andrew Lenharth
539d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner    // HANDLENODE node - Used as a handle for various purposes.
540d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner    HANDLENODE,
5412d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
54247725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    // LOCATION - This node is used to represent a source location for debug
54347725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    // info.  It takes token chain as input, then a line number, then a column
54447725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    // number, then a filename, then a working dir.  It produces a token chain
54547725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    // as output.
54647725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    LOCATION,
54747725d059b259f8a0c145478300c9e9caa006b59Chris Lattner
548f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey    // DEBUG_LOC - This node is used to represent source line information
549abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey    // embedded in the code.  It takes a token chain as input, then a line
55044c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey    // number, then a column then a file id (provided by MachineModuleInfo.) It
551abf6d1784b2d4bbcb7d20ab64881f77d755059f6Jim Laskey    // produces a token chain as output.
552f5395cee6a24699a016b2e379cf4804b09ce5030Jim Laskey    DEBUG_LOC,
55336397f50343639ce9a25996f2d790c656791ab92Duncan Sands
55436397f50343639ce9a25996f2d790c656791ab92Duncan Sands    // TRAMPOLINE - This corresponds to the init_trampoline intrinsic.
55536397f50343639ce9a25996f2d790c656791ab92Duncan Sands    // It takes as input a token chain, the pointer to the trampoline,
55636397f50343639ce9a25996f2d790c656791ab92Duncan Sands    // the pointer to the nested function, the pointer to pass for the
55736397f50343639ce9a25996f2d790c656791ab92Duncan Sands    // 'nest' parameter, a SRCVALUE for the trampoline and another for
55836397f50343639ce9a25996f2d790c656791ab92Duncan Sands    // the nested function (allowing targets to access the original
559f7331b3dd72409e644833ecaf62a0f6db03c97eeDuncan Sands    // Function*).  It produces the result of the intrinsic and a token
560f7331b3dd72409e644833ecaf62a0f6db03c97eeDuncan Sands    // chain as output.
56136397f50343639ce9a25996f2d790c656791ab92Duncan Sands    TRAMPOLINE,
56236397f50343639ce9a25996f2d790c656791ab92Duncan Sands
56366fac79b899904ddd82e5ee354a6d370d80230f6Anton Korobeynikov    // TRAP - Trapping instruction
56466fac79b899904ddd82e5ee354a6d370d80230f6Anton Korobeynikov    TRAP,
56566fac79b899904ddd82e5ee354a6d370d80230f6Anton Korobeynikov
56627b7db549e4c5bff4579d209304de5628513edebEvan Cheng    // PREFETCH - This corresponds to a prefetch intrinsic. It takes chains are
56727b7db549e4c5bff4579d209304de5628513edebEvan Cheng    // their first operand. The other operands are the address to prefetch,
56827b7db549e4c5bff4579d209304de5628513edebEvan Cheng    // read / write specifier, and locality specifier.
56927b7db549e4c5bff4579d209304de5628513edebEvan Cheng    PREFETCH,
57027b7db549e4c5bff4579d209304de5628513edebEvan Cheng
57122c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    // OUTCHAIN = MEMBARRIER(INCHAIN, load-load, load-store, store-load,
57222c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    //                       store-store, device)
573ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // This corresponds to the memory.barrier intrinsic.
57422c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    // it takes an input chain, 4 operands to specify the type of barrier, an
57522c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    // operand specifying if the barrier applies to device and uncached memory
57622c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    // and produces an output chain.
57722c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth    MEMBARRIER,
57822c5c1b2dfcb1da6a7ebfebea903401fc77d56e6Andrew Lenharth
579ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // Val, OUTCHAIN = ATOMIC_LCS(INCHAIN, ptr, cmp, swap)
580ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // this corresponds to the atomic.lcs intrinsic.
581ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // cmp is compared to *ptr, and if equal, swap is stored in *ptr.
582ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // the return is always the original value in *ptr
583ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    ATOMIC_LCS,
584ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
585ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // Val, OUTCHAIN = ATOMIC_LAS(INCHAIN, ptr, amt)
586ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // this corresponds to the atomic.las intrinsic.
587ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // *ptr + amt is stored to *ptr atomically.
588ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // the return is always the original value in *ptr
589ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    ATOMIC_LAS,
590ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
591ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // Val, OUTCHAIN = ATOMIC_SWAP(INCHAIN, ptr, amt)
592ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // this corresponds to the atomic.swap intrinsic.
593ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // amt is stored to *ptr atomically.
594ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    // the return is always the original value in *ptr
595ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    ATOMIC_SWAP,
596ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
59763307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // Val, OUTCHAIN = ATOMIC_LSS(INCHAIN, ptr, amt)
59863307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // this corresponds to the atomic.lss intrinsic.
59963307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // *ptr - amt is stored to *ptr atomically.
60063307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // the return is always the original value in *ptr
60163307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LSS,
60263307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang
60363307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // Val, OUTCHAIN = ATOMIC_L[OpName]S(INCHAIN, ptr, amt)
60463307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // this corresponds to the atomic.[OpName] intrinsic.
60563307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // op(*ptr, amt) is stored to *ptr atomically.
60663307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    // the return is always the original value in *ptr
60763307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_AND,
60863307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_OR,
60963307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_XOR,
61063307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_MIN,
61163307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_MAX,
61263307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_UMIN,
61363307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang    ATOMIC_LOAD_UMAX,
61463307c335aa08b0d6a75f81d64d79af7e90eb78bMon P Wang
61563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // BUILTIN_OP_END - This must be the last enum value in this list.
616410354fe0c052141dadeca939395743f8dd58e38Chris Lattner    BUILTIN_OP_END
61763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  };
61863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
619322dcd379eb19ea8d01478a661920ea1ce62fa0dChris Lattner  /// Node predicates
620322dcd379eb19ea8d01478a661920ea1ce62fa0dChris Lattner
621a8df166fbef047c90adba3c673162a1b1f6681c4Evan Cheng  /// isBuildVectorAllOnes - Return true if the specified node is a
622322dcd379eb19ea8d01478a661920ea1ce62fa0dChris Lattner  /// BUILD_VECTOR where all of the elements are ~0 or undef.
623a8df166fbef047c90adba3c673162a1b1f6681c4Evan Cheng  bool isBuildVectorAllOnes(const SDNode *N);
6244a147842eb24a7611fcd7bfb37c55185b4664927Evan Cheng
6254a147842eb24a7611fcd7bfb37c55185b4664927Evan Cheng  /// isBuildVectorAllZeros - Return true if the specified node is a
6264a147842eb24a7611fcd7bfb37c55185b4664927Evan Cheng  /// BUILD_VECTOR where all of the elements are 0 or undef.
6274a147842eb24a7611fcd7bfb37c55185b4664927Evan Cheng  bool isBuildVectorAllZeros(const SDNode *N);
628bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng
629efec751a1b786724862ceff52748df94873a807eEvan Cheng  /// isScalarToVector - Return true if the specified node is a
630efec751a1b786724862ceff52748df94873a807eEvan Cheng  /// ISD::SCALAR_TO_VECTOR node or a BUILD_VECTOR node where only the low
631efec751a1b786724862ceff52748df94873a807eEvan Cheng  /// element is not an undef.
632efec751a1b786724862ceff52748df94873a807eEvan Cheng  bool isScalarToVector(const SDNode *N);
633efec751a1b786724862ceff52748df94873a807eEvan Cheng
634bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng  /// isDebugLabel - Return true if the specified node represents a debug
635fc718542a3e73558af9c0272b0eea67a189e5397Evan Cheng  /// label (i.e. ISD::LABEL or TargetInstrInfo::LABEL node and third operand
636bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng  /// is 0).
637bb81d97feb396a8bb21d074db1c57e9f66525f40Evan Cheng  bool isDebugLabel(const SDNode *N);
638322dcd379eb19ea8d01478a661920ea1ce62fa0dChris Lattner
63963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  //===--------------------------------------------------------------------===//
640144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng  /// MemIndexedMode enum - This enum defines the load / store indexed
641144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng  /// addressing modes.
64224446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///
64324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// UNINDEXED    "Normal" load / store. The effective address is already
64424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///              computed and is available in the base pointer. The offset
64581c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              operand is always undefined. In addition to producing a
64681c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              chain, an unindexed load produces one value (result of the
647276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  ///              load); an unindexed store does not produce a value.
64824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///
64935acd30a2e96a5a4ad9fa837971af2cc583bcd1fEvan Cheng  /// PRE_INC      Similar to the unindexed mode where the effective address is
6508862ef148100070b7bf28beead3951464250c926Evan Cheng  /// PRE_DEC      the value of the base pointer add / subtract the offset.
6518862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              It considers the computation as being folded into the load /
65224446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///              store operation (i.e. the load / store does the address
65324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///              computation as well as performing the memory transaction).
65481c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              The base operand is always undefined. In addition to
65581c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              producing a chain, pre-indexed load produces two values
65681c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              (result of the load and the result of the address
65781c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              computation); a pre-indexed store produces one value (result
65881c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ///              of the address computation).
65924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///
66035acd30a2e96a5a4ad9fa837971af2cc583bcd1fEvan Cheng  /// POST_INC     The effective address is the value of the base pointer. The
6618862ef148100070b7bf28beead3951464250c926Evan Cheng  /// POST_DEC     value of the offset operand is then added to / subtracted
6628862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              from the base after memory transaction. In addition to
6638862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              producing a chain, post-indexed load produces two values
6648862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              (the result of the load and the result of the base +/- offset
6658862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              computation); a post-indexed store produces one value (the
6668862ef148100070b7bf28beead3951464250c926Evan Cheng  ///              the result of the base +/- offset computation).
66724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///
668144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng  enum MemIndexedMode {
66924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    UNINDEXED = 0,
67035acd30a2e96a5a4ad9fa837971af2cc583bcd1fEvan Cheng    PRE_INC,
67135acd30a2e96a5a4ad9fa837971af2cc583bcd1fEvan Cheng    PRE_DEC,
67235acd30a2e96a5a4ad9fa837971af2cc583bcd1fEvan Cheng    POST_INC,
673144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng    POST_DEC,
674144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng    LAST_INDEXED_MODE
67524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  };
67624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
67724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  //===--------------------------------------------------------------------===//
678c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// LoadExtType enum - This enum defines the three variants of LOADEXT
679c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// (load with extension).
680c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  ///
68124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// SEXTLOAD loads the integer operand and sign extends it to a larger
68224446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///          integer result type.
68324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// ZEXTLOAD loads the integer operand and zero extends it to a larger
68424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///          integer result type.
68524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// EXTLOAD  is used for three things: floating point extending loads,
68624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///          integer extending loads [the top bits are undefined], and vector
68724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///          extending loads [load into low elt].
68824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ///
689c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  enum LoadExtType {
69024446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    NON_EXTLOAD = 0,
691c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng    EXTLOAD,
692c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng    SEXTLOAD,
693c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng    ZEXTLOAD,
694c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng    LAST_LOADX_TYPE
695c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  };
696c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
697c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  //===--------------------------------------------------------------------===//
69863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// ISD::CondCode enum - These are ordered carefully to make the bitfields
69963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// below work out, when considering SETFALSE (something that never exists
70063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// dynamically) as 0.  "U" -> Unsigned (for integer operands) or Unordered
70163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// (for floating point), "L" -> Less than, "G" -> Greater than, "E" -> Equal
70263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// to.  If the "N" column is 1, the result of the comparison is undefined if
70363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// the input is a NAN.
70463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
70563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// All of these (except for the 'always folded ops') should be handled for
70663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// floating point.  For integer, only the SETEQ,SETNE,SETLT,SETLE,SETGT,
70763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// SETGE,SETULT,SETULE,SETUGT, and SETUGE opcodes are used.
70863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
70963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// Note that these are laid out in a specific order to allow bit-twiddling
71063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// to transform conditions.
71163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  enum CondCode {
71263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // Opcode          N U L G E       Intuitive operation
71363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETFALSE,      //    0 0 0 0       Always false (always folded)
71463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETOEQ,        //    0 0 0 1       True if ordered and equal
71563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETOGT,        //    0 0 1 0       True if ordered and greater than
71663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETOGE,        //    0 0 1 1       True if ordered and greater than or equal
71763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETOLT,        //    0 1 0 0       True if ordered and less than
71863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETOLE,        //    0 1 0 1       True if ordered and less than or equal
71963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETONE,        //    0 1 1 0       True if ordered and operands are unequal
72063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETO,          //    0 1 1 1       True if ordered (no nans)
72163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETUO,         //    1 0 0 0       True if unordered: isnan(X) | isnan(Y)
72263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETUEQ,        //    1 0 0 1       True if unordered or equal
72363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETUGT,        //    1 0 1 0       True if unordered or greater than
72463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETUGE,        //    1 0 1 1       True if unordered, greater than, or equal
72563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETULT,        //    1 1 0 0       True if unordered or less than
726ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman    SETULE,        //    1 1 0 1       True if unordered, less than, or equal
72763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETUNE,        //    1 1 1 0       True if unordered or not equal
72863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETTRUE,       //    1 1 1 1       Always true (always folded)
72963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    // Don't care operations: undefined if the input is a nan.
73063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETFALSE2,     //  1 X 0 0 0       Always false (always folded)
73163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETEQ,         //  1 X 0 0 1       True if equal
73263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETGT,         //  1 X 0 1 0       True if greater than
73363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETGE,         //  1 X 0 1 1       True if greater than or equal
73463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETLT,         //  1 X 1 0 0       True if less than
735ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman    SETLE,         //  1 X 1 0 1       True if less than or equal
73663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETNE,         //  1 X 1 1 0       True if not equal
73763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    SETTRUE2,      //  1 X 1 1 1       Always true (always folded)
73863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
739410354fe0c052141dadeca939395743f8dd58e38Chris Lattner    SETCC_INVALID       // Marker value.
74063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  };
74163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
74263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// isSignedIntSetCC - Return true if this is a setcc instruction that
74363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// performs a signed comparison when used with integer operands.
74463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline bool isSignedIntSetCC(CondCode Code) {
74563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return Code == SETGT || Code == SETGE || Code == SETLT || Code == SETLE;
74663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
74763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
74863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// isUnsignedIntSetCC - Return true if this is a setcc instruction that
74963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// performs an unsigned comparison when used with integer operands.
75063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline bool isUnsignedIntSetCC(CondCode Code) {
75163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return Code == SETUGT || Code == SETUGE || Code == SETULT || Code == SETULE;
75263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
75363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
75463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// isTrueWhenEqual - Return true if the specified condition returns true if
75563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// the two operands to the condition are equal.  Note that if one of the two
75663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// operands is a NaN, this value is meaningless.
75763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline bool isTrueWhenEqual(CondCode Cond) {
75863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return ((int)Cond & 1) != 0;
75963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
76063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
76163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getUnorderedFlavor - This function returns 0 if the condition is always
76263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// false if an operand is a NaN, 1 if the condition is always true if the
76363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// operand is a NaN, and 2 if the condition is undefined if the operand is a
76463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// NaN.
76563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline unsigned getUnorderedFlavor(CondCode Cond) {
76663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return ((int)Cond >> 3) & 3;
76763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
76863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
76963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getSetCCInverse - Return the operation corresponding to !(X op Y), where
77063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// 'op' is a valid SetCC operation.
77163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  CondCode getSetCCInverse(CondCode Operation, bool isInteger);
77263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
77363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getSetCCSwappedOperands - Return the operation corresponding to (Y op X)
77463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// when given the operation for (X op Y).
77563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  CondCode getSetCCSwappedOperands(CondCode Operation);
77663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
77763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getSetCCOrOperation - Return the result of a logical OR between different
77863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// comparisons of identical values: ((X op1 Y) | (X op2 Y)).  This
77963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// function returns SETCC_INVALID if it is not possible to represent the
78063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// resultant comparison.
78163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  CondCode getSetCCOrOperation(CondCode Op1, CondCode Op2, bool isInteger);
78263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
78363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getSetCCAndOperation - Return the result of a logical AND between
78463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// different comparisons of identical values: ((X op1 Y) & (X op2 Y)).  This
78563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// function returns SETCC_INVALID if it is not possible to represent the
78663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// resultant comparison.
78763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  CondCode getSetCCAndOperation(CondCode Op1, CondCode Op2, bool isInteger);
78863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner}  // end llvm::ISD namespace
78963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
79063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
79163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner//===----------------------------------------------------------------------===//
7929cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// SDOperand - Unlike LLVM values, Selection DAG nodes may return multiple
79363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// values as the result of a computation.  Many nodes return multiple values,
79463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// from loads (which define a token and a return value) to ADDC (which returns
79563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// a result and a carry value), to calls (which may return an arbitrary number
79663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// of values).
79763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner///
79863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// As such, each use of a SelectionDAG computation must indicate the node that
79963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// computes it as well as which return value to use from that node.  This pair
8009cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// of information is represented with the SDOperand value type.
80163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner///
8029cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteinclass SDOperand {
803f26bc8ef4827cf0023a7052b62b920b41813d473Chris Lattnerpublic:
80463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  SDNode *Val;        // The node defining the value we are using.
80563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  unsigned ResNo;     // Which return value of the node we are using.
80663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
8079cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand() : Val(0), ResNo(0) {}
8089cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand(SDNode *val, unsigned resno) : Val(val), ResNo(resno) {}
80963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
8109cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator==(const SDOperand &O) const {
81163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return Val == O.Val && ResNo == O.ResNo;
81263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
8139cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator!=(const SDOperand &O) const {
81463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return !operator==(O);
81563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
8169cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator<(const SDOperand &O) const {
81763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return Val < O.Val || (Val == O.Val && ResNo < O.ResNo);
81863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
81963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
8209cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand getValue(unsigned R) const {
8219cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return SDOperand(Val, R);
82263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
82363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
824917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  // isOperandOf - Return true if this node is an operand of N.
825917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  bool isOperandOf(SDNode *N) const;
826bfa284f69752c54f81bffc2b0d15d5c1e618a659Evan Cheng
82763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getValueType - Return the ValueType of the referenced return value.
82863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
82963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline MVT::ValueType getValueType() const;
830ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
8314fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType()).
8324fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  ///
8334fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  unsigned getValueSizeInBits() const {
8344fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman    return MVT::getSizeInBits(getValueType());
8354fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  }
8364fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman
83763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  // Forwarding methods - These forward to the corresponding methods in SDNode.
83863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline unsigned getOpcode() const;
83963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  inline unsigned getNumOperands() const;
8409cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  inline const SDOperand &getOperand(unsigned i) const;
841c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  inline uint64_t getConstantOperandVal(unsigned i) const;
8420f66a9172175aa7c3055333358170581c999219bNate Begeman  inline bool isTargetOpcode() const;
8430f66a9172175aa7c3055333358170581c999219bNate Begeman  inline unsigned getTargetOpcode() const;
844a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner
845572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner
846572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner  /// reachesChainWithoutSideEffects - Return true if this operand (which must
847572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner  /// be a chain) reaches the specified operand without crossing any
848572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner  /// side-effecting instructions.  In practice, this looks through token
849572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner  /// factors and non-volatile loads.  In order to remain efficient, this only
850572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner  /// looks a couple of nodes in, it does not do an exhaustive search.
8519cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool reachesChainWithoutSideEffects(SDOperand Dest,
852dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein                                      unsigned Depth = 2) const;
853572dee71af1313e6742e1dfd5274fff326b9ef1cChris Lattner
854a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner  /// hasOneUse - Return true if there is exactly one operation using this
855a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner  /// result value of the defining operator.
856a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner  inline bool hasOneUse() const;
857e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman
858e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman  /// use_empty - Return true if there are no operations using this
859e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman  /// result value of the defining operator.
860e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman  inline bool use_empty() const;
86163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
86263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
86363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
8649cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteintemplate<> struct DenseMapInfo<SDOperand> {
8659cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static inline SDOperand getEmptyKey() {
8669cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return SDOperand((SDNode*)-1, -1U);
867dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
8689cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static inline SDOperand getTombstoneKey() {
8699cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return SDOperand((SDNode*)-1, 0);
870dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
8719cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static unsigned getHashValue(const SDOperand &Val) {
872ae9f3a3b7c915f725aef5a7250e88eaeddda03c6Anton Korobeynikov    return ((unsigned)((uintptr_t)Val.Val >> 4) ^
873ae9f3a3b7c915f725aef5a7250e88eaeddda03c6Anton Korobeynikov            (unsigned)((uintptr_t)Val.Val >> 9)) + Val.ResNo;
874c63d391c9a886d58c6a53a7f565fbd544b076d9fEvan Cheng  }
8759cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static bool isEqual(const SDOperand &LHS, const SDOperand &RHS) {
87676c1b97e4020faace8c95a127f1eab66c278fb58Chris Lattner    return LHS == RHS;
87776c1b97e4020faace8c95a127f1eab66c278fb58Chris Lattner  }
878c63d391c9a886d58c6a53a7f565fbd544b076d9fEvan Cheng  static bool isPod() { return true; }
879c63d391c9a886d58c6a53a7f565fbd544b076d9fEvan Cheng};
880c63d391c9a886d58c6a53a7f565fbd544b076d9fEvan Cheng
88163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// simplify_type specializations - Allow casting operators to work directly on
88263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// SDOperands as if they were SDNode*'s.
8839cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteintemplate<> struct simplify_type<SDOperand> {
884dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  typedef SDNode* SimpleType;
8859cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static SimpleType getSimplifiedValue(const SDOperand &Val) {
886dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    return static_cast<SimpleType>(Val.Val);
887dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
888dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein};
8899cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteintemplate<> struct simplify_type<const SDOperand> {
890dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  typedef SDNode* SimpleType;
8919cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static SimpleType getSimplifiedValue(const SDOperand &Val) {
892dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    return static_cast<SimpleType>(Val.Val);
893dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
894dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein};
895dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
8969cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// SDUse - Represents a use of the SDNode referred by
8979cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// the SDOperand.
8989cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteinclass SDUse {
8999cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand Operand;
90002819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein  /// User - Parent node of this operand.
90102819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein  SDNode    *User;
902dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// Prev, next - Pointers to the uses list of the SDNode referred by
903dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// this operand.
9049cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse **Prev, *Next;
905dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levensteinpublic:
906dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  friend class SDNode;
90702819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein  SDUse(): Operand(), User(NULL), Prev(NULL), Next(NULL) {}
908dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
9099cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse(SDNode *val, unsigned resno) :
91002819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein    Operand(val,resno), User(NULL), Prev(NULL), Next(NULL) {}
911dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
9129cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse& operator= (const SDOperand& Op) {
9139cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      Operand = Op;
914dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Next = NULL;
915dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Prev = NULL;
916dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return *this;
917dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
918dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
9199cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse& operator= (const SDUse& Op) {
9209cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      Operand = Op;
921dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Next = NULL;
922dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Prev = NULL;
923dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return *this;
924dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
925dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
9269cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse * getNext() { return Next; }
927dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
92802819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein  SDNode *getUser() { return User; }
9299cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
93002819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein  void setUser(SDNode *p) { User = p; }
931dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
9329cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  operator SDOperand() const { return Operand; }
9339cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9349cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  const SDOperand& getSDOperand() const { return Operand; }
9359cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9369cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDNode* &getVal () { return Operand.Val; }
9379cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9389cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator==(const SDOperand &O) const {
9399cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return Operand == O;
9409cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
9419cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9429cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator!=(const SDOperand &O) const {
9439cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return !(Operand == O);
9449cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
9459cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9469cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  bool operator<(const SDOperand &O) const {
9479cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return Operand < O;
9489cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
9499cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
950dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levensteinprotected:
9519cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  void addToList(SDUse **List) {
952dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    Next = *List;
953dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    if (Next) Next->Prev = &Next;
954dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    Prev = List;
955dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    *List = this;
956dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
957dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
958dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  void removeFromList() {
959dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    *Prev = Next;
960dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    if (Next) Next->Prev = Prev;
961dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
962dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein};
963dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
964dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
965dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein/// simplify_type specializations - Allow casting operators to work directly on
966dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein/// SDOperands as if they were SDNode*'s.
9679cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteintemplate<> struct simplify_type<SDUse> {
96863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  typedef SDNode* SimpleType;
9699cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static SimpleType getSimplifiedValue(const SDUse &Val) {
9709cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return static_cast<SimpleType>(Val.getSDOperand().Val);
97163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
97263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
9739cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteintemplate<> struct simplify_type<const SDUse> {
97463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  typedef SDNode* SimpleType;
9759cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  static SimpleType getSimplifiedValue(const SDUse &Val) {
9769cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return static_cast<SimpleType>(Val.getSDOperand().Val);
97763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
97863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
97963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
98063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
98102819257a625d0d9a186845354baadd6e8f1890bRoman Levenstein/// SDOperandPtr - A helper SDOperand pointer class, that can handle
9829cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// arrays of SDUse and arrays of SDOperand objects. This is required
9839cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein/// in many places inside the SelectionDAG.
9849cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein///
9859cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteinclass SDOperandPtr {
9869cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  const SDOperand *ptr; // The pointer to the SDOperand object
9879cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  int object_size;      // The size of the object containg the SDOperand
9889cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteinpublic:
98935b31bea0dc9e16d4c384a6a78404bdd791b6693Dan Gohman  SDOperandPtr() : ptr(0), object_size(0) {}
99035b31bea0dc9e16d4c384a6a78404bdd791b6693Dan Gohman
9919cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperandPtr(SDUse * use_ptr) {
9929cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    ptr = &use_ptr->getSDOperand();
99334cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng    object_size = (int)sizeof(SDUse);
9949cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
9959cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
9969cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperandPtr(const SDOperand * op_ptr) {
9979cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    ptr = op_ptr;
99834cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng    object_size = (int)sizeof(SDOperand);
9999cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
10009cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
10019cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  const SDOperand operator *() { return *ptr; }
10029cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  const SDOperand *operator ->() { return ptr; }
10039cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperandPtr operator ++ () {
10049cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    ptr = (SDOperand*)((char *)ptr + object_size);
10059cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return *this;
10069cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
10079cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
10089cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperandPtr operator ++ (int) {
10099cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    SDOperandPtr tmp = *this;
10109cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    ptr = (SDOperand*)((char *)ptr + object_size);
10119cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return tmp;
10129cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
10139cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
10149cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand operator[] (int idx) const {
10159cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return *(SDOperand*)((char*) ptr + object_size * idx);
10169cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
10179cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein};
10189cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
101963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner/// SDNode - Represents one node in the SelectionDAG.
102063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner///
1021583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskeyclass SDNode : public FoldingSetNode {
1022dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levensteinprivate:
10230442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner  /// NodeType - The operation that this node performs.
10240442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner  ///
10250442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner  unsigned short NodeType;
102663e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner
102763e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  /// OperandsNeedDelete - This is true if OperandList was new[]'d.  If true,
102863e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  /// then they will be delete[]'d when the node is destroyed.
102963e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  bool OperandsNeedDelete : 1;
10300442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner
1031b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng  /// NodeId - Unique id per SDNode in the DAG.
1032b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng  int NodeId;
10330442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner
1034f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  /// OperandList - The values that are used by this operation.
10350442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner  ///
10369cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse *OperandList;
1037f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner
1038f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  /// ValueList - The types of the values this node defines.  SDNode's may
1039f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  /// define multiple values simultaneously.
10402fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner  const MVT::ValueType *ValueList;
104163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1042f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  /// NumOperands/NumValues - The number of entries in the Operand/Value list.
1043f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  unsigned short NumOperands, NumValues;
1044b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
1045b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  /// Prev/Next pointers - These pointers form the linked list of of the
1046b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  /// AllNodes list in the current DAG.
1047b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  SDNode *Prev, *Next;
1048b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  friend struct ilist_traits<SDNode>;
104963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1050dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// UsesSize - The size of the uses list.
1051dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  unsigned UsesSize;
1052dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1053dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// Uses - List of uses for this SDNode.
10549cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse *Uses;
1055dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
10569cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  /// addUse - add SDUse to the list of uses.
10579cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  void addUse(SDUse &U) { U.addToList(&Uses); }
1058dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1059917d2c9dc2cc8879ed97533e7f75f3f92fa26b61Chris Lattner  // Out-of-line virtual method to give class a home.
1060917d2c9dc2cc8879ed97533e7f75f3f92fa26b61Chris Lattner  virtual void ANCHOR();
106163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
1062b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  virtual ~SDNode() {
1063b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner    assert(NumOperands == 0 && "Operand list not cleared before deletion");
10643258ed6a361bf405a89f7af0b1885841d9909516Chris Lattner    NodeType = ISD::DELETED_NODE;
1065b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  }
1066b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
106763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  //===--------------------------------------------------------------------===//
106863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  //  Accessors
106963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  //
107063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  unsigned getOpcode()  const { return NodeType; }
10710f66a9172175aa7c3055333358170581c999219bNate Begeman  bool isTargetOpcode() const { return NodeType >= ISD::BUILTIN_OP_END; }
10720f66a9172175aa7c3055333358170581c999219bNate Begeman  unsigned getTargetOpcode() const {
10730f66a9172175aa7c3055333358170581c999219bNate Begeman    assert(isTargetOpcode() && "Not a target opcode!");
10740f66a9172175aa7c3055333358170581c999219bNate Begeman    return NodeType - ISD::BUILTIN_OP_END;
10750f66a9172175aa7c3055333358170581c999219bNate Begeman  }
107663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1077dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  size_t use_size() const { return UsesSize; }
1078dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  bool use_empty() const { return Uses == NULL; }
1079dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  bool hasOneUse() const { return use_size() == 1; }
108063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1081b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng  /// getNodeId - Return the unique node id.
1082b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng  ///
1083b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng  int getNodeId() const { return NodeId; }
10840442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner
10852e07d33f04c513f3c2da3d7b1acfc098f02c7a6eEvan Cheng  /// setNodeId - Set unique node id.
10862e07d33f04c513f3c2da3d7b1acfc098f02c7a6eEvan Cheng  void setNodeId(int Id) { NodeId = Id; }
10872e07d33f04c513f3c2da3d7b1acfc098f02c7a6eEvan Cheng
10889cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  /// use_iterator - This class provides iterator support for SDUse
1089dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// operands that use a specific SDNode.
1090dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  class use_iterator
10919cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    : public forward_iterator<SDUse, ptrdiff_t> {
10929cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    SDUse *Op;
10939cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    explicit use_iterator(SDUse *op) : Op(op) {
1094dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1095dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    friend class SDNode;
1096dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  public:
10979cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    typedef forward_iterator<SDUse, ptrdiff_t>::reference reference;
10989cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    typedef forward_iterator<SDUse, ptrdiff_t>::pointer pointer;
1099dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1100dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    use_iterator(const use_iterator &I) : Op(I.Op) {}
1101dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    use_iterator() : Op(0) {}
1102dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1103dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    bool operator==(const use_iterator &x) const {
1104dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return Op == x.Op;
1105dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1106dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    bool operator!=(const use_iterator &x) const {
1107dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return !operator==(x);
1108dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1109dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1110dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    /// atEnd - return true if this iterator is at the end of uses list.
1111dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    bool atEnd() const { return Op == 0; }
1112dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1113dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    // Iterator traversal: forward iteration only.
1114dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    use_iterator &operator++() {          // Preincrement
1115dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      assert(Op && "Cannot increment end iterator!");
1116dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Op = Op->getNext();
1117dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return *this;
1118dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1119dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1120dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    use_iterator operator++(int) {        // Postincrement
1121dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      use_iterator tmp = *this; ++*this; return tmp;
1122dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1123dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1124dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1125dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    /// getOperandNum - Retrive a number of a current operand.
1126dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    unsigned getOperandNum() const {
1127dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      assert(Op && "Cannot dereference end iterator!");
112834cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng      return (unsigned)(Op - Op->getUser()->OperandList);
1129dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1130dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1131dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    /// Retrieve a reference to the current operand.
11329cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    SDUse &operator*() const {
1133dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      assert(Op && "Cannot dereference end iterator!");
1134dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return *Op;
1135dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1136dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1137dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    /// Retrieve a pointer to the current operand.
11389cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    SDUse *operator->() const {
1139dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      assert(Op && "Cannot dereference end iterator!");
1140dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      return Op;
1141dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1142dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  };
1143dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1144dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// use_begin/use_end - Provide iteration support to walk over all uses
1145dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  /// of an SDNode.
1146dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1147dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  use_iterator use_begin(SDNode *node) const {
1148dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    return use_iterator(node->Uses);
1149dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
1150dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1151dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  use_iterator use_begin() const {
1152dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    return use_iterator(Uses);
1153dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  }
1154dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1155dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  static use_iterator use_end() { return use_iterator(0); }
1156dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
11577ece380440238ad0630a225b85a09a2dbed1165aChris Lattner
1158b18a2f816cc9d1351ca8e380a6db5c5ef981943eChris Lattner  /// hasNUsesOfValue - Return true if there are exactly NUSES uses of the
1159b18a2f816cc9d1351ca8e380a6db5c5ef981943eChris Lattner  /// indicated value.  This method ignores uses of other values defined by this
1160b18a2f816cc9d1351ca8e380a6db5c5ef981943eChris Lattner  /// operation.
11614ee621125876cc954cba5280dd9395552755a871Evan Cheng  bool hasNUsesOfValue(unsigned NUses, unsigned Value) const;
11624ee621125876cc954cba5280dd9395552755a871Evan Cheng
116333d5595d667ba4a880bd7fe785724e8197bef70cEvan Cheng  /// hasAnyUseOfValue - Return true if there are any use of the indicated
116433d5595d667ba4a880bd7fe785724e8197bef70cEvan Cheng  /// value. This method ignores uses of other values defined by this operation.
116533d5595d667ba4a880bd7fe785724e8197bef70cEvan Cheng  bool hasAnyUseOfValue(unsigned Value) const;
116633d5595d667ba4a880bd7fe785724e8197bef70cEvan Cheng
1167917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  /// isOnlyUseOf - Return true if this node is the only use of N.
1168e6e97e66a366cc7d2d103ac58db56e4bfd700b10Evan Cheng  ///
1169917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  bool isOnlyUseOf(SDNode *N) const;
1170b18a2f816cc9d1351ca8e380a6db5c5ef981943eChris Lattner
1171917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  /// isOperandOf - Return true if this node is an operand of N.
1172e6e97e66a366cc7d2d103ac58db56e4bfd700b10Evan Cheng  ///
1173917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  bool isOperandOf(SDNode *N) const;
117480d8eaae05d9bcb25abf6c6f0385ec2554355f26Evan Cheng
1175917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  /// isPredecessorOf - Return true if this node is a predecessor of N. This
1176917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  /// node is either an operand of N or it can be reached by recursively
1177917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  /// traversing up the operands.
1178e6e97e66a366cc7d2d103ac58db56e4bfd700b10Evan Cheng  /// NOTE: this is an expensive method. Use it carefully.
1179917be6814e0a4e529d290be5d806a054bbbc4a27Evan Cheng  bool isPredecessorOf(SDNode *N) const;
11807ceebb437ebb18efefe72d8d2d0e9c762c3aa6b3Evan Cheng
118163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getNumOperands - Return the number of values used by this operation.
118263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
1183f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  unsigned getNumOperands() const { return NumOperands; }
118463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1185c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// getConstantOperandVal - Helper method returns the integer value of a
1186c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// ConstantSDNode operand.
1187c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  uint64_t getConstantOperandVal(unsigned Num) const;
1188c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
118963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  const SDOperand &getOperand(unsigned Num) const {
1190f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner    assert(Num < NumOperands && "Invalid child # of SDNode!");
11919cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    return OperandList[Num].getSDOperand();
119263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
1193c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
11949cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  typedef SDUse* op_iterator;
1195f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  op_iterator op_begin() const { return OperandList; }
1196f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  op_iterator op_end() const { return OperandList+NumOperands; }
119750f5a51f41d36c519de68ff11fbf7c7c76f45416Chris Lattner
119863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
11990b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner  SDVTList getVTList() const {
12000b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner    SDVTList X = { ValueList, NumValues };
12010b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner    return X;
12020b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner  };
12030b3e525a3a6b55b66dc5676675712b26e4c1ed9fChris Lattner
120463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getNumValues - Return the number of values defined/returned by this
120563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// operator.
120663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
1207f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  unsigned getNumValues() const { return NumValues; }
120863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
120963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// getValueType - Return the type of a specified result.
121063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ///
121163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  MVT::ValueType getValueType(unsigned ResNo) const {
1212f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner    assert(ResNo < NumValues && "Illegal result number!");
1213f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner    return ValueList[ResNo];
121463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
12159eb59ec548b861d6ede05b4e6dc22aabf645e665Jeff Cohen
12164fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  /// getValueSizeInBits - Returns MVT::getSizeInBits(getValueType(ResNo)).
12174fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  ///
12184fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  unsigned getValueSizeInBits(unsigned ResNo) const {
12194fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman    return MVT::getSizeInBits(getValueType(ResNo));
12204fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman  }
12214fc3d5dac255120e2f0c0b537044fcf56a30fa34Dan Gohman
1222f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  typedef const MVT::ValueType* value_iterator;
1223f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  value_iterator value_begin() const { return ValueList; }
1224f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  value_iterator value_end() const { return ValueList+NumValues; }
122563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
12266e6e3ceb080e5a8bdfd3258d883a06ebbd8a1965Chris Lattner  /// getOperationName - Return the opcode of this operation for printing.
12276e6e3ceb080e5a8bdfd3258d883a06ebbd8a1965Chris Lattner  ///
1228ded5ed873fa7cd85f0b9d7c677b81dddf9a61eaaReid Spencer  std::string getOperationName(const SelectionDAG *G = 0) const;
1229144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng  static const char* getIndexedModeName(ISD::MemIndexedMode AM);
123063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  void dump() const;
1231efe58694050e48b61584b8454434dcd1ad886a71Chris Lattner  void dump(const SelectionDAG *G) const;
123263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
123363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *) { return true; }
123463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1235583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  /// Profile - Gather unique data for the node.
1236583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  ///
1237583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  void Profile(FoldingSetNodeID &ID);
1238583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey
123963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
124063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1241109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
1242109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  /// getValueTypeList - Return a pointer to the specified value type.
1243109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  ///
1244547ca537b638c8fd5c8f4729e4c74898f8371e4eDan Gohman  static const MVT::ValueType *getValueTypeList(MVT::ValueType VT);
124563e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  static SDVTList getSDVTList(MVT::ValueType VT) {
124663e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner    SDVTList Ret = { getValueTypeList(VT), 1 };
124763e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner    return Ret;
12482d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  }
124963e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner
1250ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner  SDNode(unsigned Opc, SDVTList VTs, const SDOperand *Ops, unsigned NumOps)
1251dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
125263e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner    OperandsNeedDelete = true;
1253f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    NumOperands = NumOps;
12549cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    OperandList = NumOps ? new SDUse[NumOperands] : 0;
12559cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
12569cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    for (unsigned i = 0; i != NumOps; ++i) {
12579cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      OperandList[i] = Ops[i];
12589cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      OperandList[i].setUser(this);
12599cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      Ops[i].Val->addUse(OperandList[i]);
12609cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      ++Ops[i].Val->UsesSize;
12619cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    }
12629cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
12639cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    ValueList = VTs.VTs;
12649cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    NumValues = VTs.NumVTs;
12659cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    Prev = 0; Next = 0;
12669cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  }
12679cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein
12689cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDNode(unsigned Opc, SDVTList VTs, SDOperandPtr Ops, unsigned NumOps)
12699cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
12709cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    OperandsNeedDelete = true;
12719cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    NumOperands = NumOps;
12729cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    OperandList = NumOps ? new SDUse[NumOperands] : 0;
1273f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner
1274bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    for (unsigned i = 0; i != NumOps; ++i) {
1275f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner      OperandList[i] = Ops[i];
1276dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      OperandList[i].setUser(this);
1277dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      Ops[i].Val->addUse(OperandList[i]);
1278dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      ++Ops[i].Val->UsesSize;
12790442fbfadbeea21eee9df88dc466d95e040dde6bChris Lattner    }
1280bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
1281ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    ValueList = VTs.VTs;
1282ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    NumValues = VTs.NumVTs;
1283b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner    Prev = 0; Next = 0;
1284f71e843f651ad94e19f85daa947fe24312b40d11Chris Lattner  }
1285dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1286dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  SDNode(unsigned Opc, SDVTList VTs)
1287dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    : NodeType(Opc), NodeId(-1), UsesSize(0), Uses(NULL) {
1288bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    OperandsNeedDelete = false;  // Operands set with InitOperands.
1289bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    NumOperands = 0;
1290bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    OperandList = 0;
1291bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    ValueList = VTs.VTs;
1292bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    NumValues = VTs.NumVTs;
1293bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    Prev = 0; Next = 0;
1294bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  }
1295bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
1296bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  /// InitOperands - Initialize the operands list of this node with the
1297bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  /// specified values, which are part of the node (thus they don't need to be
1298bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  /// copied in or allocated).
12999cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  void InitOperands(SDUse *Ops, unsigned NumOps) {
1300bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    assert(OperandList == 0 && "Operands already set!");
1301bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    NumOperands = NumOps;
1302bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    OperandList = Ops;
1303dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    UsesSize = 0;
1304dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    Uses = NULL;
1305bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
1306dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    for (unsigned i = 0; i != NumOps; ++i) {
1307dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein      OperandList[i].setUser(this);
13089cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      Ops[i].getVal()->addUse(OperandList[i]);
13099cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein      ++Ops[i].getVal()->UsesSize;
1310dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    }
1311bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  }
1312bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
1313d429bcd4ac734540ebbc15a0ee37d154ae1daf73Chris Lattner  /// MorphNodeTo - This frees the operands of the current node, resets the
1314d429bcd4ac734540ebbc15a0ee37d154ae1daf73Chris Lattner  /// opcode, types, and operands to the specified value.  This should only be
1315d429bcd4ac734540ebbc15a0ee37d154ae1daf73Chris Lattner  /// used by the SelectionDAG class.
1316d429bcd4ac734540ebbc15a0ee37d154ae1daf73Chris Lattner  void MorphNodeTo(unsigned Opc, SDVTList L,
131735b31bea0dc9e16d4c384a6a78404bdd791b6693Dan Gohman                   SDOperandPtr Ops, unsigned NumOps);
13181b95095857b78e12138c22e76c7936611c51355bChris Lattner
1319dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  void addUser(unsigned i, SDNode *User) {
1320dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    assert(User->OperandList[i].getUser() && "Node without parent");
1321dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    addUse(User->OperandList[i]);
1322dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    ++UsesSize;
13231b95095857b78e12138c22e76c7936611c51355bChris Lattner  }
1324dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein
1325dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein  void removeUser(unsigned i, SDNode *User) {
1326dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    assert(User->OperandList[i].getUser() && "Node without parent");
13279cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    SDUse &Op = User->OperandList[i];
1328dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    Op.removeFromList();
1329dc1adac582fa120861f18ae7221bfe1421fea59fRoman Levenstein    --UsesSize;
1330d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  }
133163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
133263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
133363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
13349cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein// Define inline functions from the SDOperand class.
133563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
13369cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline unsigned SDOperand::getOpcode() const {
133763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  return Val->getOpcode();
133863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner}
13399cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline MVT::ValueType SDOperand::getValueType() const {
134063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  return Val->getValueType(ResNo);
134163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner}
13429cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline unsigned SDOperand::getNumOperands() const {
134363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  return Val->getNumOperands();
134463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner}
13459cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline const SDOperand &SDOperand::getOperand(unsigned i) const {
134663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  return Val->getOperand(i);
134763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner}
13489cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline uint64_t SDOperand::getConstantOperandVal(unsigned i) const {
1349c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  return Val->getConstantOperandVal(i);
1350c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng}
13519cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline bool SDOperand::isTargetOpcode() const {
13520f66a9172175aa7c3055333358170581c999219bNate Begeman  return Val->isTargetOpcode();
13530f66a9172175aa7c3055333358170581c999219bNate Begeman}
13549cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline unsigned SDOperand::getTargetOpcode() const {
13550f66a9172175aa7c3055333358170581c999219bNate Begeman  return Val->getTargetOpcode();
13560f66a9172175aa7c3055333358170581c999219bNate Begeman}
13579cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline bool SDOperand::hasOneUse() const {
1358a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner  return Val->hasNUsesOfValue(1, ResNo);
1359a44f4aeca77c6c1627568fe68e92af9c7e33dc7eChris Lattner}
13609cac5259fe237120a0c347d6d14e549005148f1bRoman Levensteininline bool SDOperand::use_empty() const {
1361e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman  return !Val->hasAnyUseOfValue(ResNo);
1362e1b50639a860934685dff840e1826b16dbe6a344Dan Gohman}
136363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
13643f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// UnarySDNode - This class is used for single-operand SDNodes.  This is solely
13653f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// to allow co-allocation of node operands with the node itself.
13663f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerclass UnarySDNode : public SDNode {
13673f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
13689cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Op;
13693f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerpublic:
13703f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  UnarySDNode(unsigned Opc, SDVTList VTs, SDOperand X)
13719cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    : SDNode(Opc, VTs) {
13729cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    Op = X;
13733f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    InitOperands(&Op, 1);
13743f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  }
13753f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner};
13763f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner
13773f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// BinarySDNode - This class is used for two-operand SDNodes.  This is solely
13783f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// to allow co-allocation of node operands with the node itself.
13793f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerclass BinarySDNode : public SDNode {
13803f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
13819cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Ops[2];
13823f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerpublic:
13833f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  BinarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y)
13843f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    : SDNode(Opc, VTs) {
13853f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    Ops[0] = X;
13863f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    Ops[1] = Y;
13873f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    InitOperands(Ops, 2);
13883f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  }
13893f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner};
13903f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner
13913f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// TernarySDNode - This class is used for three-operand SDNodes. This is solely
13923f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner/// to allow co-allocation of node operands with the node itself.
13933f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerclass TernarySDNode : public SDNode {
13943f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
13959cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Ops[3];
13963f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattnerpublic:
13973f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  TernarySDNode(unsigned Opc, SDVTList VTs, SDOperand X, SDOperand Y,
13983f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner                SDOperand Z)
13993f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    : SDNode(Opc, VTs) {
14003f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    Ops[0] = X;
14013f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    Ops[1] = Y;
14023f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    Ops[2] = Z;
14033f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner    InitOperands(Ops, 3);
14043f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner  }
14053f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner};
14063f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner
14073f97eb449b08069e3370d4ba7566c60bdbf0babdChris Lattner
1408d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner/// HandleSDNode - This class is used to form a handle around another node that
1409d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner/// is persistant and is updated across invocations of replaceAllUsesWith on its
1410d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner/// operand.  This node should be directly created by end-users and not added to
1411d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner/// the AllNodes list.
1412d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattnerclass HandleSDNode : public SDNode {
1413c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
14149cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Op;
1415d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattnerpublic:
1416ef02b815cb37017d8dbac2f18c75bff0aa317163Bill Wendling  // FIXME: Remove the "noinline" attribute once <rdar://problem/5852746> is
1417ef02b815cb37017d8dbac2f18c75bff0aa317163Bill Wendling  // fixed.
1418ef02b815cb37017d8dbac2f18c75bff0aa317163Bill Wendling  explicit __attribute__((__noinline__)) HandleSDNode(SDOperand X)
14199cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    : SDNode(ISD::HANDLENODE, getSDVTList(MVT::Other)) {
14209cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein    Op = X;
1421bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    InitOperands(&Op, 1);
1422bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner  }
142348b85926524f9d29ae600123c90194cd73fd629eChris Lattner  ~HandleSDNode();
14249cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse getValue() const { return Op; }
1425d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner};
1426d623e953fc5f46b013994dfa4651cff4d17af159Chris Lattner
1427ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharthclass AtomicSDNode : public SDNode {
1428ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
14299cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Ops[4];
1430ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  MVT::ValueType OrigVT;
1431ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharthpublic:
1432c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth  AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1433c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth               SDOperand Cmp, SDOperand Swp, MVT::ValueType VT)
1434ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    : SDNode(Opc, VTL) {
1435ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    Ops[0] = Chain;
1436c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth    Ops[1] = Ptr;
1437c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth    Ops[2] = Swp;
1438c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth    Ops[3] = Cmp;
1439ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    InitOperands(Ops, 4);
1440ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    OrigVT=VT;
1441ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  }
1442c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth  AtomicSDNode(unsigned Opc, SDVTList VTL, SDOperand Chain, SDOperand Ptr,
1443c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth               SDOperand Val, MVT::ValueType VT)
1444ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    : SDNode(Opc, VTL) {
1445ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    Ops[0] = Chain;
1446c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth    Ops[1] = Ptr;
1447c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth    Ops[2] = Val;
1448ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    InitOperands(Ops, 3);
1449ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth    OrigVT=VT;
1450ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  }
1451ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  MVT::ValueType getVT() const { return OrigVT; }
1452c1c7bd610a1647d8e7eaeb4cc38ca1a85ae5e271Andrew Lenharth  bool isCompareAndSwap() const { return getOpcode() == ISD::ATOMIC_LCS; }
1453ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth};
1454ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
145547725d059b259f8a0c145478300c9e9caa006b59Chris Lattnerclass StringSDNode : public SDNode {
145647725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  std::string Value;
1457c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
145847725d059b259f8a0c145478300c9e9caa006b59Chris Lattnerprotected:
145947725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  friend class SelectionDAG;
1460423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman  explicit StringSDNode(const std::string &val)
1461bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(ISD::STRING, getSDVTList(MVT::Other)), Value(val) {
146247725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  }
146347725d059b259f8a0c145478300c9e9caa006b59Chris Lattnerpublic:
146447725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  const std::string &getValue() const { return Value; }
146547725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  static bool classof(const StringSDNode *) { return true; }
146647725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  static bool classof(const SDNode *N) {
146747725d059b259f8a0c145478300c9e9caa006b59Chris Lattner    return N->getOpcode() == ISD::STRING;
146847725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  }
146947725d059b259f8a0c145478300c9e9caa006b59Chris Lattner};
147063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
147163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass ConstantSDNode : public SDNode {
14726394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  APInt Value;
1473c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
147463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
147563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
14766394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  ConstantSDNode(bool isTarget, const APInt &val, MVT::ValueType VT)
1477bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(isTarget ? ISD::TargetConstant : ISD::Constant, getSDVTList(VT)),
1478bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner      Value(val) {
147963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
148063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
148163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
14826394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  const APInt &getAPIntValue() const { return Value; }
14836394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  uint64_t getValue() const { return Value.getZExtValue(); }
148463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
148563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  int64_t getSignExtended() const {
148663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    unsigned Bits = MVT::getSizeInBits(getValueType(0));
14876394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman    return ((int64_t)Value.getZExtValue() << (64-Bits)) >> (64-Bits);
148863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
148963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
149063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  bool isNullValue() const { return Value == 0; }
149163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  bool isAllOnesValue() const {
1492885a87ef8512a184a58a0ebe39705ccb221749efChris Lattner    return Value == MVT::getIntVTBitMask(getValueType(0));
149363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
149463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
149563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const ConstantSDNode *) { return true; }
149663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1497056f9f61d071c6c583951678f2bf543a1316efccChris Lattner    return N->getOpcode() == ISD::Constant ||
1498056f9f61d071c6c583951678f2bf543a1316efccChris Lattner           N->getOpcode() == ISD::TargetConstant;
149963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
150063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
150163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
150263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass ConstantFPSDNode : public SDNode {
15038bb369b8072c919ef5802f639a52b17620201190Dale Johannesen  APFloat Value;
1504c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
150563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
150663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1507e6c1742914149d44360fbf05a653041a672282afDale Johannesen  ConstantFPSDNode(bool isTarget, const APFloat& val, MVT::ValueType VT)
150887503a63d5756f1836f66f4c9723ec0ea30ec3caDale Johannesen    : SDNode(isTarget ? ISD::TargetConstantFP : ISD::ConstantFP,
150987503a63d5756f1836f66f4c9723ec0ea30ec3caDale Johannesen             getSDVTList(VT)), Value(val) {
151063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
151163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
151263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1513e6c1742914149d44360fbf05a653041a672282afDale Johannesen  const APFloat& getValueAPF() const { return Value; }
151463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
151563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// isExactlyValue - We don't rely on operator== working on double values, as
151663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// it returns true for things that are clearly not equal, like -0.0 and 0.0.
151763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// As such, this method can be used to do an exact bit-for-bit comparison of
151863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  /// two floating point values.
1519c4dd3c3b519aa2c2ed26ce03a4b1fbb992efeacaDale Johannesen
1520c4dd3c3b519aa2c2ed26ce03a4b1fbb992efeacaDale Johannesen  /// We leave the version with the double argument here because it's just so
1521c4dd3c3b519aa2c2ed26ce03a4b1fbb992efeacaDale Johannesen  /// convenient to write "2.0" and the like.  Without this function we'd
1522c4dd3c3b519aa2c2ed26ce03a4b1fbb992efeacaDale Johannesen  /// have to duplicate its logic everywhere it's called.
15239dd2ce46c58dd05f0835df77f308396715890d66Dale Johannesen  bool isExactlyValue(double V) const {
15249dd2ce46c58dd05f0835df77f308396715890d66Dale Johannesen    // convert is not supported on this type
15259dd2ce46c58dd05f0835df77f308396715890d66Dale Johannesen    if (&Value.getSemantics() == &APFloat::PPCDoubleDouble)
15269dd2ce46c58dd05f0835df77f308396715890d66Dale Johannesen      return false;
152784cd0e7fa30af43c47ad9533d84debb144596e48Chris Lattner    APFloat Tmp(V);
152884cd0e7fa30af43c47ad9533d84debb144596e48Chris Lattner    Tmp.convert(Value.getSemantics(), APFloat::rmNearestTiesToEven);
152984cd0e7fa30af43c47ad9533d84debb144596e48Chris Lattner    return isExactlyValue(Tmp);
153087503a63d5756f1836f66f4c9723ec0ea30ec3caDale Johannesen  }
1531e6c1742914149d44360fbf05a653041a672282afDale Johannesen  bool isExactlyValue(const APFloat& V) const;
153263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1533f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  bool isValueValidForType(MVT::ValueType VT, const APFloat& Val);
1534f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen
153563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const ConstantFPSDNode *) { return true; }
153663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1537ac0d7238258defe72b1aad53d7f48201b91df795Chris Lattner    return N->getOpcode() == ISD::ConstantFP ||
1538ac0d7238258defe72b1aad53d7f48201b91df795Chris Lattner           N->getOpcode() == ISD::TargetConstantFP;
153963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
154063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
154163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
154263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass GlobalAddressSDNode : public SDNode {
154363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  GlobalValue *TheGlobal;
1544404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng  int Offset;
1545c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
154663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
154763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
154861ca74bc3a29b2af2be7e4bd612289da8aae85b5Evan Cheng  GlobalAddressSDNode(bool isTarget, const GlobalValue *GA, MVT::ValueType VT,
15492c5c111b6c144b05718404c85b9dfcc76b1619e7Lauro Ramos Venancio                      int o = 0);
155063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
155163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
155263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  GlobalValue *getGlobal() const { return TheGlobal; }
1553404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng  int getOffset() const { return Offset; }
155463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
155563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const GlobalAddressSDNode *) { return true; }
155663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1557f6b184981e429ff03742d66cf7111debd9e2bc61Chris Lattner    return N->getOpcode() == ISD::GlobalAddress ||
1558b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio           N->getOpcode() == ISD::TargetGlobalAddress ||
1559b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio           N->getOpcode() == ISD::GlobalTLSAddress ||
1560b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio           N->getOpcode() == ISD::TargetGlobalTLSAddress;
156163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
156263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
156363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
156463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass FrameIndexSDNode : public SDNode {
156563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  int FI;
1566c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
156763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
156863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1569afb2dd43de61f4585e75d1f3ab93a9ac4b3b7592Chris Lattner  FrameIndexSDNode(int fi, MVT::ValueType VT, bool isTarg)
1570bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(isTarg ? ISD::TargetFrameIndex : ISD::FrameIndex, getSDVTList(VT)),
1571bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner      FI(fi) {
157263e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
157363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
157463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
157563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  int getIndex() const { return FI; }
157663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
157763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const FrameIndexSDNode *) { return true; }
157863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1579afb2dd43de61f4585e75d1f3ab93a9ac4b3b7592Chris Lattner    return N->getOpcode() == ISD::FrameIndex ||
1580afb2dd43de61f4585e75d1f3ab93a9ac4b3b7592Chris Lattner           N->getOpcode() == ISD::TargetFrameIndex;
158163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
158263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
158363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
158437efe6764568a3829fee26aba532283131d1a104Nate Begemanclass JumpTableSDNode : public SDNode {
158537efe6764568a3829fee26aba532283131d1a104Nate Begeman  int JTI;
1586c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
158737efe6764568a3829fee26aba532283131d1a104Nate Begemanprotected:
158837efe6764568a3829fee26aba532283131d1a104Nate Begeman  friend class SelectionDAG;
158937efe6764568a3829fee26aba532283131d1a104Nate Begeman  JumpTableSDNode(int jti, MVT::ValueType VT, bool isTarg)
1590bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(isTarg ? ISD::TargetJumpTable : ISD::JumpTable, getSDVTList(VT)),
1591bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner      JTI(jti) {
159263e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
159337efe6764568a3829fee26aba532283131d1a104Nate Begemanpublic:
159437efe6764568a3829fee26aba532283131d1a104Nate Begeman
159559a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  int getIndex() const { return JTI; }
159637efe6764568a3829fee26aba532283131d1a104Nate Begeman
159737efe6764568a3829fee26aba532283131d1a104Nate Begeman  static bool classof(const JumpTableSDNode *) { return true; }
159837efe6764568a3829fee26aba532283131d1a104Nate Begeman  static bool classof(const SDNode *N) {
159937efe6764568a3829fee26aba532283131d1a104Nate Begeman    return N->getOpcode() == ISD::JumpTable ||
160037efe6764568a3829fee26aba532283131d1a104Nate Begeman           N->getOpcode() == ISD::TargetJumpTable;
160137efe6764568a3829fee26aba532283131d1a104Nate Begeman  }
160237efe6764568a3829fee26aba532283131d1a104Nate Begeman};
160337efe6764568a3829fee26aba532283131d1a104Nate Begeman
160463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass ConstantPoolSDNode : public SDNode {
1605d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  union {
1606d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Constant *ConstVal;
1607d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    MachineConstantPoolValue *MachineCPVal;
1608d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  } Val;
1609baf4500b3ab128c78932e36f96086c0487c8c7d1Evan Cheng  int Offset;  // It's a MachineConstantPoolValue if top bit is set.
1610b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  unsigned Alignment;
1611c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
161263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
161363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1614404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT,
1615404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng                     int o=0)
1616ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1617bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner             getSDVTList(VT)), Offset(o), Alignment(0) {
1618d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert((int)Offset >= 0 && "Offset is too large");
1619d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Val.ConstVal = c;
1620d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1621404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng  ConstantPoolSDNode(bool isTarget, Constant *c, MVT::ValueType VT, int o,
1622404cb4f9fa2df50eac4d84b8a77c84a92188c6d5Evan Cheng                     unsigned Align)
1623ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1624bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner             getSDVTList(VT)), Offset(o), Alignment(Align) {
1625d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert((int)Offset >= 0 && "Offset is too large");
1626d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Val.ConstVal = c;
1627d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1628d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1629d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                     MVT::ValueType VT, int o=0)
1630ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1631bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner             getSDVTList(VT)), Offset(o), Alignment(0) {
1632d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert((int)Offset >= 0 && "Offset is too large");
1633d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Val.MachineCPVal = v;
1634d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Offset |= 1 << (sizeof(unsigned)*8-1);
1635d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1636d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  ConstantPoolSDNode(bool isTarget, MachineConstantPoolValue *v,
1637d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                     MVT::ValueType VT, int o, unsigned Align)
1638ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    : SDNode(isTarget ? ISD::TargetConstantPool : ISD::ConstantPool,
1639bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner             getSDVTList(VT)), Offset(o), Alignment(Align) {
1640d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert((int)Offset >= 0 && "Offset is too large");
1641d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Val.MachineCPVal = v;
1642d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    Offset |= 1 << (sizeof(unsigned)*8-1);
1643d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
164463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
164563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1646d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  bool isMachineConstantPoolEntry() const {
1647d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return (int)Offset < 0;
1648d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1649d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng
1650d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  Constant *getConstVal() const {
1651d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert(!isMachineConstantPoolEntry() && "Wrong constantpool type");
1652d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return Val.ConstVal;
1653d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1654d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng
1655d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  MachineConstantPoolValue *getMachineCPVal() const {
1656d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    assert(isMachineConstantPoolEntry() && "Wrong constantpool type");
1657d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return Val.MachineCPVal;
1658d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
1659d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng
1660baf4500b3ab128c78932e36f96086c0487c8c7d1Evan Cheng  int getOffset() const {
1661baf4500b3ab128c78932e36f96086c0487c8c7d1Evan Cheng    return Offset & ~(1 << (sizeof(unsigned)*8-1));
1662baf4500b3ab128c78932e36f96086c0487c8c7d1Evan Cheng  }
1663ef3640aded552279f65bd6d18633e15ffb245157Chris Lattner
1664ef3640aded552279f65bd6d18633e15ffb245157Chris Lattner  // Return the alignment of this constant pool object, which is either 0 (for
1665ef3640aded552279f65bd6d18633e15ffb245157Chris Lattner  // default alignment) or log2 of the desired value.
1666b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  unsigned getAlignment() const { return Alignment; }
166763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1668d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  const Type *getType() const;
1669d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng
167063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const ConstantPoolSDNode *) { return true; }
167163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1672aaaaf79d4aaa172c2f2ae0e327bbae523a045bf5Chris Lattner    return N->getOpcode() == ISD::ConstantPool ||
1673aaaaf79d4aaa172c2f2ae0e327bbae523a045bf5Chris Lattner           N->getOpcode() == ISD::TargetConstantPool;
167463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
167563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
167663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
167763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass BasicBlockSDNode : public SDNode {
167863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  MachineBasicBlock *MBB;
1679c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
168063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
168163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1682423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman  explicit BasicBlockSDNode(MachineBasicBlock *mbb)
1683bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(ISD::BasicBlock, getSDVTList(MVT::Other)), MBB(mbb) {
168463e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
168563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
168663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
168763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  MachineBasicBlock *getBasicBlock() const { return MBB; }
168863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
168963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const BasicBlockSDNode *) { return true; }
169063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
169163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner    return N->getOpcode() == ISD::BasicBlock;
169263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
169363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
169463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
169514471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// SrcValueSDNode - An SDNode that holds an arbitrary LLVM IR Value. This is
169614471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// used when the SelectionDAG needs to make a simple reference to something
169714471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// in the LLVM IR representation.
169814471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman///
169914471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// Note that this is not used for carrying alias information; that is done
170014471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// with MemOperandSDNode, which includes a Value which is required to be a
170114471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman/// pointer, and several other fields specific to memory references.
170214471be9ab531cb677658704ea73b06d4f0b7585Dan Gohman///
17032d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharthclass SrcValueSDNode : public SDNode {
17042d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  const Value *V;
1705c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
17062d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharthprotected:
17072d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  friend class SelectionDAG;
170869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  /// Create a SrcValue for a general value.
170969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  explicit SrcValueSDNode(const Value *v)
171069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    : SDNode(ISD::SRCVALUE, getSDVTList(MVT::Other)), V(v) {}
17112d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
17122d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharthpublic:
171369de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  /// getValue - return the contained Value.
17142d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  const Value *getValue() const { return V; }
17152d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
17162d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  static bool classof(const SrcValueSDNode *) { return true; }
17172d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  static bool classof(const SDNode *N) {
17182d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth    return N->getOpcode() == ISD::SRCVALUE;
17192d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  }
17202d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth};
17212d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
172263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
172336b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman/// MemOperandSDNode - An SDNode that holds a MachineMemOperand. This is
172469de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman/// used to represent a reference to memory after ISD::LOAD
172569de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman/// and ISD::STORE have been lowered.
172669de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman///
172769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohmanclass MemOperandSDNode : public SDNode {
172869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
172969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohmanprotected:
173069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  friend class SelectionDAG;
173136b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  /// Create a MachineMemOperand node
173236b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  explicit MemOperandSDNode(const MachineMemOperand &mo)
173369de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    : SDNode(ISD::MEMOPERAND, getSDVTList(MVT::Other)), MO(mo) {}
173469de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
173569de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohmanpublic:
173636b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  /// MO - The contained MachineMemOperand.
173736b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  const MachineMemOperand MO;
173869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
173969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  static bool classof(const MemOperandSDNode *) { return true; }
174069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  static bool classof(const SDNode *N) {
174169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman    return N->getOpcode() == ISD::MEMOPERAND;
174269de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  }
174369de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman};
174469de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
174569de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
1746d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattnerclass RegisterSDNode : public SDNode {
174763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  unsigned Reg;
1748c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
174963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
175063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1751d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  RegisterSDNode(unsigned reg, MVT::ValueType VT)
1752bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(ISD::Register, getSDVTList(VT)), Reg(reg) {
175363e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
175463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
175563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
175663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  unsigned getReg() const { return Reg; }
175763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1758d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  static bool classof(const RegisterSDNode *) { return true; }
175963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
1760d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return N->getOpcode() == ISD::Register;
176163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
176263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
176363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
176463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerclass ExternalSymbolSDNode : public SDNode {
176563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  const char *Symbol;
1766c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
176763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
176863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
17692a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth  ExternalSymbolSDNode(bool isTarget, const char *Sym, MVT::ValueType VT)
1770ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner    : SDNode(isTarget ? ISD::TargetExternalSymbol : ISD::ExternalSymbol,
1771bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner             getSDVTList(VT)), Symbol(Sym) {
177263e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
177363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
177463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
177563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  const char *getSymbol() const { return Symbol; }
177663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
177763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const ExternalSymbolSDNode *) { return true; }
177863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
17792a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth    return N->getOpcode() == ISD::ExternalSymbol ||
17802a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth           N->getOpcode() == ISD::TargetExternalSymbol;
178163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
178263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
178363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
17847cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattnerclass CondCodeSDNode : public SDNode {
178563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  ISD::CondCode Condition;
1786c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
178763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerprotected:
178863b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  friend class SelectionDAG;
1789423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman  explicit CondCodeSDNode(ISD::CondCode Cond)
1790bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(ISD::CONDCODE, getSDVTList(MVT::Other)), Condition(Cond) {
179163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
179263b570d49b7bf205d48749aae1467ef96152ea7aChris Lattnerpublic:
179363b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
17947cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ISD::CondCode get() const { return Condition; }
179563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
17967cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  static bool classof(const CondCodeSDNode *) { return true; }
179763b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  static bool classof(const SDNode *N) {
17987cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return N->getOpcode() == ISD::CONDCODE;
179963b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner  }
180063b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner};
180163b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
1802276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sandsnamespace ISD {
1803276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  struct ArgFlagsTy {
1804276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  private:
1805276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t NoFlagSet      = 0ULL;
1806276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ZExt           = 1ULL<<0;  ///< Zero extended
1807276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ZExtOffs       = 0;
1808276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t SExt           = 1ULL<<1;  ///< Sign extended
1809276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t SExtOffs       = 1;
1810276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t InReg          = 1ULL<<2;  ///< Passed in register
1811276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t InRegOffs      = 2;
1812276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t SRet           = 1ULL<<3;  ///< Hidden struct-ret ptr
1813276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t SRetOffs       = 3;
1814276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByVal          = 1ULL<<4;  ///< Struct passed by value
1815276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByValOffs      = 4;
1816276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t Nest           = 1ULL<<5;  ///< Nested fn static chain
1817276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t NestOffs       = 5;
1818276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByValAlign     = 0xFULL << 6; //< Struct alignment
1819276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByValAlignOffs = 6;
18206ccbbd89906157187ac04b2b3237c4aee7acd095Nicolas Geoffray    static const uint64_t Split          = 1ULL << 10;
18216ccbbd89906157187ac04b2b3237c4aee7acd095Nicolas Geoffray    static const uint64_t SplitOffs      = 10;
1822276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t OrigAlign      = 0x1FULL<<27;
1823276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t OrigAlignOffs  = 27;
1824276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByValSize      = 0xffffffffULL << 32; //< Struct size
1825276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t ByValSizeOffs  = 32;
1826276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1827276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    static const uint64_t One            = 1ULL; //< 1 of this type, for shifts
1828276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1829276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    uint64_t Flags;
1830276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  public:
1831276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    ArgFlagsTy() : Flags(0) { }
1832276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1833276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isZExt()   const { return Flags & ZExt; }
1834276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setZExt()  { Flags |= One << ZExtOffs; }
1835276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1836276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isSExt()   const { return Flags & SExt; }
1837276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setSExt()  { Flags |= One << SExtOffs; }
1838276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1839276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isInReg()  const { return Flags & InReg; }
1840276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setInReg() { Flags |= One << InRegOffs; }
1841276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1842276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isSRet()   const { return Flags & SRet; }
1843276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setSRet()  { Flags |= One << SRetOffs; }
1844276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1845276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isByVal()  const { return Flags & ByVal; }
1846276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setByVal() { Flags |= One << ByValOffs; }
1847276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1848276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    bool isNest()   const { return Flags & Nest; }
1849276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setNest()  { Flags |= One << NestOffs; }
1850276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1851276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    unsigned getByValAlign() const {
185294bef327aa8ea769cafe310b91bd94d768d2bf85Dale Johannesen      return (unsigned)
185394bef327aa8ea769cafe310b91bd94d768d2bf85Dale Johannesen        ((One << ((Flags & ByValAlign) >> ByValAlignOffs)) / 2);
1854276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1855276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setByValAlign(unsigned A) {
1856276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands      Flags = (Flags & ~ByValAlign) |
1857276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands        (uint64_t(Log2_32(A) + 1) << ByValAlignOffs);
1858276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1859c0cb28fd3abee9a8b40856990e04f1af2f9bd7b8Nicolas Geoffray
18606ccbbd89906157187ac04b2b3237c4aee7acd095Nicolas Geoffray    bool isSplit()   const { return Flags & Split; }
18616ccbbd89906157187ac04b2b3237c4aee7acd095Nicolas Geoffray    void setSplit()  { Flags |= One << SplitOffs; }
1862276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1863276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    unsigned getOrigAlign() const {
186494bef327aa8ea769cafe310b91bd94d768d2bf85Dale Johannesen      return (unsigned)
186594bef327aa8ea769cafe310b91bd94d768d2bf85Dale Johannesen        ((One << ((Flags & OrigAlign) >> OrigAlignOffs)) / 2);
1866276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1867276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setOrigAlign(unsigned A) {
1868276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands      Flags = (Flags & ~OrigAlign) |
1869276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands        (uint64_t(Log2_32(A) + 1) << OrigAlignOffs);
1870276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1871276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1872276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    unsigned getByValSize() const {
187394bef327aa8ea769cafe310b91bd94d768d2bf85Dale Johannesen      return (unsigned)((Flags & ByValSize) >> ByValSizeOffs);
1874276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1875276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    void setByValSize(unsigned S) {
1876276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands      Flags = (Flags & ~ByValSize) | (uint64_t(S) << ByValSizeOffs);
1877276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    }
1878276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1879276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    /// getArgFlagsString - Returns the flags as a string, eg: "zext align:4".
1880276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    std::string getArgFlagsString();
1881276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1882276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    /// getRawBits - Represent the flags as a bunch of bits.
1883276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    uint64_t getRawBits() const { return Flags; }
1884276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  };
1885276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands}
1886276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1887276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands/// ARG_FLAGSSDNode - Leaf node holding parameter flags.
1888276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sandsclass ARG_FLAGSSDNode : public SDNode {
1889276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  ISD::ArgFlagsTy TheFlags;
1890276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
1891276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sandsprotected:
1892276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  friend class SelectionDAG;
1893276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  explicit ARG_FLAGSSDNode(ISD::ArgFlagsTy Flags)
1894276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    : SDNode(ISD::ARG_FLAGS, getSDVTList(MVT::Other)), TheFlags(Flags) {
1895276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  }
1896276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sandspublic:
1897276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  ISD::ArgFlagsTy getArgFlags() const { return TheFlags; }
1898276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
1899276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  static bool classof(const ARG_FLAGSSDNode *) { return true; }
1900276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  static bool classof(const SDNode *N) {
1901276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands    return N->getOpcode() == ISD::ARG_FLAGS;
1902276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  }
1903276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands};
1904276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands
190515e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner/// VTSDNode - This class is used to represent MVT::ValueType's, which are used
190615e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner/// to parameterize some operations.
190715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattnerclass VTSDNode : public SDNode {
190815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  MVT::ValueType ValueType;
1909c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
191015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattnerprotected:
191115e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  friend class SelectionDAG;
1912423c2260f95883f7c84ac962e58ac66c3a11efacDan Gohman  explicit VTSDNode(MVT::ValueType VT)
1913bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    : SDNode(ISD::VALUETYPE, getSDVTList(MVT::Other)), ValueType(VT) {
191463e3f14df6cf76f1a12de1153e1114f4b20b15a9Chris Lattner  }
191515e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattnerpublic:
191615e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner
191715e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  MVT::ValueType getVT() const { return ValueType; }
191815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner
191915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  static bool classof(const VTSDNode *) { return true; }
192015e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  static bool classof(const SDNode *N) {
192115e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner    return N->getOpcode() == ISD::VALUETYPE;
192215e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  }
192315e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner};
192415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner
19259de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel/// LSBaseSDNode - Base class for LoadSDNode and StoreSDNode
19269de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel///
19279de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelclass LSBaseSDNode : public SDNode {
19289de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelprivate:
1929b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  // AddrMode - unindexed, pre-indexed, post-indexed.
1930b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  ISD::MemIndexedMode AddrMode;
1931b625f2f8960de32bc973092aaee8ac62863006feDan Gohman
1932b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  // MemoryVT - VT of in-memory value.
1933b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  MVT::ValueType MemoryVT;
1934b625f2f8960de32bc973092aaee8ac62863006feDan Gohman
19359de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  //! SrcValue - Memory location for alias analysis.
19369de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  const Value *SrcValue;
19379de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
19389de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  //! SVOffset - Memory location offset.
19399de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  int SVOffset;
19409de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
19419de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  //! Alignment - Alignment of memory location in bytes.
19429de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  unsigned Alignment;
19439de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
19449de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  //! IsVolatile - True if the store is volatile.
19459de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  bool IsVolatile;
19469de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelprotected:
19479de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  //! Operand array for load and store
19489de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  /*!
19499de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel    \note Moving this array to the base class captures more
19509de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel    common functionality shared between LoadSDNode and
19519de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel    StoreSDNode
19529de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel   */
19539cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDUse Ops[4];
19549de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelpublic:
1955b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  LSBaseSDNode(ISD::NodeType NodeTy, SDOperand *Operands, unsigned NumOperands,
1956b625f2f8960de32bc973092aaee8ac62863006feDan Gohman               SDVTList VTs, ISD::MemIndexedMode AM, MVT::ValueType VT,
1957b625f2f8960de32bc973092aaee8ac62863006feDan Gohman               const Value *SV, int SVO, unsigned Align, bool Vol)
19589de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel    : SDNode(NodeTy, VTs),
1959b625f2f8960de32bc973092aaee8ac62863006feDan Gohman      AddrMode(AM), MemoryVT(VT),
196059a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner      SrcValue(SV), SVOffset(SVO), Alignment(Align), IsVolatile(Vol) {
1961b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    for (unsigned i = 0; i != NumOperands; ++i)
1962b625f2f8960de32bc973092aaee8ac62863006feDan Gohman      Ops[i] = Operands[i];
1963b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    InitOperands(Ops, NumOperands);
1964b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    assert(Align != 0 && "Loads and stores should have non-zero aligment");
1965437d452adbc1ec58e73d9fd0dbfe345c69289a23Dan Gohman    assert((getOffset().getOpcode() == ISD::UNDEF || isIndexed()) &&
1966437d452adbc1ec58e73d9fd0dbfe345c69289a23Dan Gohman           "Only indexed loads and stores have a non-undef offset operand");
1967b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  }
19689de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
196959a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getChain() const { return getOperand(0); }
197059a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getBasePtr() const {
19719de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel    return getOperand(getOpcode() == ISD::LOAD ? 1 : 2);
19729de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  }
197363602b8a69b2729f0789cd3c920aceef0ece64cbChris Lattner  const SDOperand &getOffset() const {
197463602b8a69b2729f0789cd3c920aceef0ece64cbChris Lattner    return getOperand(getOpcode() == ISD::LOAD ? 2 : 3);
197563602b8a69b2729f0789cd3c920aceef0ece64cbChris Lattner  }
19769de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
19779de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  const Value *getSrcValue() const { return SrcValue; }
19789de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  int getSrcValueOffset() const { return SVOffset; }
19799de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  unsigned getAlignment() const { return Alignment; }
1980b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  MVT::ValueType getMemoryVT() const { return MemoryVT; }
19819de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  bool isVolatile() const { return IsVolatile; }
19829de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
1983b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  ISD::MemIndexedMode getAddressingMode() const { return AddrMode; }
1984b625f2f8960de32bc973092aaee8ac62863006feDan Gohman
1985b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  /// isIndexed - Return true if this is a pre/post inc/dec load/store.
1986b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  bool isIndexed() const { return AddrMode != ISD::UNINDEXED; }
1987b625f2f8960de32bc973092aaee8ac62863006feDan Gohman
1988b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  /// isUnindexed - Return true if this is NOT a pre/post inc/dec load/store.
1989b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  bool isUnindexed() const { return AddrMode == ISD::UNINDEXED; }
1990b625f2f8960de32bc973092aaee8ac62863006feDan Gohman
199136b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  /// getMemOperand - Return a MachineMemOperand object describing the memory
199269de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  /// reference performed by this load or store.
199336b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  MachineMemOperand getMemOperand() const;
199469de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
19959de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel  static bool classof(const LSBaseSDNode *N) { return true; }
1996b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  static bool classof(const SDNode *N) {
1997b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    return N->getOpcode() == ISD::LOAD ||
1998b625f2f8960de32bc973092aaee8ac62863006feDan Gohman           N->getOpcode() == ISD::STORE;
1999b625f2f8960de32bc973092aaee8ac62863006feDan Gohman  }
20009de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel};
20019de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michel
200224446e253a17720f6462288255ab5ebd13b8491fEvan Cheng/// LoadSDNode - This class is used to represent ISD::LOAD nodes.
200324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng///
20049de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelclass LoadSDNode : public LSBaseSDNode {
2005c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2006bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
200781c384578828dde08f63a4f030f4860a92391cddEvan Cheng  // ExtType - non-ext, anyext, sext, zext.
200881c384578828dde08f63a4f030f4860a92391cddEvan Cheng  ISD::LoadExtType ExtType;
200981c384578828dde08f63a4f030f4860a92391cddEvan Cheng
201024446e253a17720f6462288255ab5ebd13b8491fEvan Chengprotected:
201124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  friend class SelectionDAG;
2012ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner  LoadSDNode(SDOperand *ChainPtrOff, SDVTList VTs,
2013144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng             ISD::MemIndexedMode AM, ISD::LoadExtType ETy, MVT::ValueType LVT,
201495c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb             const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2015b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    : LSBaseSDNode(ISD::LOAD, ChainPtrOff, 3,
2016b625f2f8960de32bc973092aaee8ac62863006feDan Gohman                   VTs, AM, LVT, SV, O, Align, Vol),
2017437d452adbc1ec58e73d9fd0dbfe345c69289a23Dan Gohman      ExtType(ETy) {}
201824446e253a17720f6462288255ab5ebd13b8491fEvan Chengpublic:
201924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
202024446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  ISD::LoadExtType getExtensionType() const { return ExtType; }
202159a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getBasePtr() const { return getOperand(1); }
202259a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getOffset() const { return getOperand(2); }
202339354cb743c5a1473de7a80b957c61e92cf76852Chris Lattner
202424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  static bool classof(const LoadSDNode *) { return true; }
202524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  static bool classof(const SDNode *N) {
202624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::LOAD;
202724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  }
202824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng};
202924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
203024446e253a17720f6462288255ab5ebd13b8491fEvan Cheng/// StoreSDNode - This class is used to represent ISD::STORE nodes.
203124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng///
20329de5d0dd42463f61c4ee2f9db5f3d08153c0dacfScott Michelclass StoreSDNode : public LSBaseSDNode {
2033c76e3c86026b9fa44bfbb0888881b52955078011Chris Lattner  virtual void ANCHOR();  // Out-of-line virtual method to give class a home.
2034bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner
20353ec81c0ee73462b7b9acd355b0013827d06ad93cDuncan Sands  // IsTruncStore - True if the op does a truncation before store.
203681c384578828dde08f63a4f030f4860a92391cddEvan Cheng  bool IsTruncStore;
203724446e253a17720f6462288255ab5ebd13b8491fEvan Chengprotected:
203824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  friend class SelectionDAG;
2039ab4ed595385d0b9421c0d45c809ec6324cf11f11Chris Lattner  StoreSDNode(SDOperand *ChainValuePtrOff, SDVTList VTs,
2040144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng              ISD::MemIndexedMode AM, bool isTrunc, MVT::ValueType SVT,
204124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng              const Value *SV, int O=0, unsigned Align=0, bool Vol=false)
2042b625f2f8960de32bc973092aaee8ac62863006feDan Gohman    : LSBaseSDNode(ISD::STORE, ChainValuePtrOff, 4,
2043b625f2f8960de32bc973092aaee8ac62863006feDan Gohman                   VTs, AM, SVT, SV, O, Align, Vol),
2044437d452adbc1ec58e73d9fd0dbfe345c69289a23Dan Gohman      IsTruncStore(isTrunc) {}
204524446e253a17720f6462288255ab5ebd13b8491fEvan Chengpublic:
204624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
204724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  bool isTruncatingStore() const { return IsTruncStore; }
204859a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getValue() const { return getOperand(1); }
204959a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getBasePtr() const { return getOperand(2); }
205059a8cdd36d644fd5d0d7c78c3c02b31f1ba29a95Chris Lattner  const SDOperand &getOffset() const { return getOperand(3); }
205139354cb743c5a1473de7a80b957c61e92cf76852Chris Lattner
20526d0b3295777f0e9e9cce27f3473c19f78e88f700Evan Cheng  static bool classof(const StoreSDNode *) { return true; }
205324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  static bool classof(const SDNode *N) {
205424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::STORE;
205524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  }
205624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng};
205724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
205815e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner
20591080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnerclass SDNodeIterator : public forward_iterator<SDNode, ptrdiff_t> {
20601080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  SDNode *Node;
20611080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  unsigned Operand;
2062ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
20631080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  SDNodeIterator(SDNode *N, unsigned Op) : Node(N), Operand(Op) {}
20641080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnerpublic:
20651080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  bool operator==(const SDNodeIterator& x) const {
20661080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return Operand == x.Operand;
20671080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
20681080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  bool operator!=(const SDNodeIterator& x) const { return !operator==(x); }
20691080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
20701080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  const SDNodeIterator &operator=(const SDNodeIterator &I) {
20711080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    assert(I.Node == Node && "Cannot assign iterators to two different nodes!");
20721080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    Operand = I.Operand;
20731080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return *this;
20741080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
2075ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
20761080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  pointer operator*() const {
20771080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return Node->getOperand(Operand).Val;
20781080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
20791080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  pointer operator->() const { return operator*(); }
2080ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman
20811080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  SDNodeIterator& operator++() {                // Preincrement
20821080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    ++Operand;
20831080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return *this;
20841080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
20851080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  SDNodeIterator operator++(int) { // Postincrement
2086ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman    SDNodeIterator tmp = *this; ++*this; return tmp;
20871080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
20881080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
20891080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static SDNodeIterator begin(SDNode *N) { return SDNodeIterator(N, 0); }
20901080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static SDNodeIterator end  (SDNode *N) {
20911080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return SDNodeIterator(N, N->getNumOperands());
20921080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
20931080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
20941080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  unsigned getOperand() const { return Operand; }
20951080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  const SDNode *getNode() const { return Node; }
20961080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
20971080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
20981080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SDNode*> {
20991080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SDNode NodeType;
21001080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SDNodeIterator ChildIteratorType;
21011080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static inline NodeType *getEntryNode(SDNode *N) { return N; }
2102ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_begin(NodeType *N) {
21031080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return SDNodeIterator::begin(N);
21041080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
2105ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman  static inline ChildIteratorType child_end(NodeType *N) {
21061080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return SDNodeIterator::end(N);
21071080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
21081080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
21091080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
2110b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattnertemplate<>
2111b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattnerstruct ilist_traits<SDNode> {
2112b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static SDNode *getPrev(const SDNode *N) { return N->Prev; }
2113b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static SDNode *getNext(const SDNode *N) { return N->Next; }
2114b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
2115b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static void setPrev(SDNode *N, SDNode *Prev) { N->Prev = Prev; }
2116b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static void setNext(SDNode *N, SDNode *Next) { N->Next = Next; }
2117b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
2118b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static SDNode *createSentinel() {
2119bc2e26241d507ecd6c79598e5175f90852b716b3Chris Lattner    return new SDNode(ISD::EntryToken, SDNode::getSDVTList(MVT::Other));
2120b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  }
2121b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  static void destroySentinel(SDNode *N) { delete N; }
2122b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  //static SDNode *createNode(const SDNode &V) { return new SDNode(V); }
2123b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
2124b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
2125b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  void addNodeToList(SDNode *NTy) {}
2126b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  void removeNodeFromList(SDNode *NTy) {}
2127b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  void transferNodesFromList(iplist<SDNode, ilist_traits> &L2,
2128b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner                             const ilist_iterator<SDNode> &X,
2129b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner                             const ilist_iterator<SDNode> &Y) {}
2130b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner};
2131b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
2132c548428c5d7328592f4db6f6cd815af18b3152a3Evan Chengnamespace ISD {
2133186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng  /// isNormalLoad - Returns true if the specified node is a non-extending
2134186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng  /// and unindexed load.
2135186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng  inline bool isNormalLoad(const SDNode *N) {
2136186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng    if (N->getOpcode() != ISD::LOAD)
2137186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng      return false;
2138186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng    const LoadSDNode *Ld = cast<LoadSDNode>(N);
2139186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng    return Ld->getExtensionType() == ISD::NON_EXTLOAD &&
2140186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng      Ld->getAddressingMode() == ISD::UNINDEXED;
2141186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng  }
2142186edc8fa13d0e02d3c17563ad2bd78ac5963a67Evan Cheng
214324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// isNON_EXTLoad - Returns true if the specified node is a non-extending
214424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  /// load.
214524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  inline bool isNON_EXTLoad(const SDNode *N) {
214624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::LOAD &&
214724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng      cast<LoadSDNode>(N)->getExtensionType() == ISD::NON_EXTLOAD;
214824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  }
214924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng
2150c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// isEXTLoad - Returns true if the specified node is a EXTLOAD.
2151c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  ///
2152c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  inline bool isEXTLoad(const SDNode *N) {
215324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::LOAD &&
215424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng      cast<LoadSDNode>(N)->getExtensionType() == ISD::EXTLOAD;
2155c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  }
2156c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
2157c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// isSEXTLoad - Returns true if the specified node is a SEXTLOAD.
2158c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  ///
2159c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  inline bool isSEXTLoad(const SDNode *N) {
216024446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::LOAD &&
216124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng      cast<LoadSDNode>(N)->getExtensionType() == ISD::SEXTLOAD;
2162c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  }
2163c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
2164c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  /// isZEXTLoad - Returns true if the specified node is a ZEXTLOAD.
2165c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  ///
2166c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  inline bool isZEXTLoad(const SDNode *N) {
216724446e253a17720f6462288255ab5ebd13b8491fEvan Cheng    return N->getOpcode() == ISD::LOAD &&
216824446e253a17720f6462288255ab5ebd13b8491fEvan Cheng      cast<LoadSDNode>(N)->getExtensionType() == ISD::ZEXTLOAD;
2169c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng  }
21708b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng
217102c50e4891841c28b2a743731dfc60744bb78879Evan Cheng  /// isUNINDEXEDLoad - Returns true if the specified node is a unindexed load.
217202c50e4891841c28b2a743731dfc60744bb78879Evan Cheng  ///
217302c50e4891841c28b2a743731dfc60744bb78879Evan Cheng  inline bool isUNINDEXEDLoad(const SDNode *N) {
217402c50e4891841c28b2a743731dfc60744bb78879Evan Cheng    return N->getOpcode() == ISD::LOAD &&
217502c50e4891841c28b2a743731dfc60744bb78879Evan Cheng      cast<LoadSDNode>(N)->getAddressingMode() == ISD::UNINDEXED;
217602c50e4891841c28b2a743731dfc60744bb78879Evan Cheng  }
217702c50e4891841c28b2a743731dfc60744bb78879Evan Cheng
21788b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  /// isNON_TRUNCStore - Returns true if the specified node is a non-truncating
21798b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  /// store.
21808b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  inline bool isNON_TRUNCStore(const SDNode *N) {
21818b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng    return N->getOpcode() == ISD::STORE &&
21828b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng      !cast<StoreSDNode>(N)->isTruncatingStore();
21838b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  }
21848b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng
21858b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  /// isTRUNCStore - Returns true if the specified node is a truncating
21868b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  /// store.
21878b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  inline bool isTRUNCStore(const SDNode *N) {
21888b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng    return N->getOpcode() == ISD::STORE &&
21898b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng      cast<StoreSDNode>(N)->isTruncatingStore();
21908b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  }
2191c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng}
2192c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
2193c548428c5d7328592f4db6f6cd815af18b3152a3Evan Cheng
219463b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner} // end llvm namespace
219563b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner
219663b570d49b7bf205d48749aae1467ef96152ea7aChris Lattner#endif
2197