SelectionDAG.h revision 8be6bbe5bfd50945ac6c5542e0f54a0924a5db8d
1c3aae25116e66c177579b0b79182b09340b19753Chris Lattner//===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
57ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// This file is distributed under the University of Illinois Open Source
67ed47a13356daed2a34cd2209a31f92552e3bdd8Chris Lattner// License. See LICENSE.TXT for details.
7ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
86fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//===----------------------------------------------------------------------===//
9ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
10c3aae25116e66c177579b0b79182b09340b19753Chris Lattner// This file declares the SelectionDAG class, and transitively defines the
11c3aae25116e66c177579b0b79182b09340b19753Chris Lattner// SDNode class and subclasses.
12ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
13cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner//===----------------------------------------------------------------------===//
14cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
15cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#ifndef LLVM_CODEGEN_SELECTIONDAG_H
16cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#define LLVM_CODEGEN_SELECTIONDAG_H
17cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
18fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman#include "llvm/ADT/ilist.h"
19c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene#include "llvm/ADT/DenseSet.h"
20583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/ADT/FoldingSet.h"
214b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman#include "llvm/ADT/StringMap.h"
22583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h"
23b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
24acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman#include <cassert>
255892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector>
26322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
27eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string>
28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
29d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
30fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
31fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass AliasAnalysis;
32fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass TargetLowering;
33fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass TargetMachine;
34fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineModuleInfo;
35fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineFunction;
36fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass MachineConstantPoolValue;
37fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanclass FunctionLoweringInfo;
38fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
398e4018e2de52c534405d7155c7009d0b35afb861Cedric Venettemplate<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
408e4018e2de52c534405d7155c7009d0b35afb861Cedric Venetprivate:
41fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  mutable SDNode Sentinel;
42fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanpublic:
43fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  ilist_traits() : Sentinel(ISD::DELETED_NODE, SDVTList()) {}
44fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
45fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  SDNode *createSentinel() const {
46fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman    return &Sentinel;
47fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  }
48fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void destroySentinel(SDNode *) {}
49fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
50fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void deleteNode(SDNode *) {
51fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman    assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!");
52fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  }
53fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohmanprivate:
54fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  static void createNode(const SDNode &);
55fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman};
56c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
57c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function
58c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction
59c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection.  This DAG is constructed as the first step of instruction
60c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations
61c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications.
62c3aae25116e66c177579b0b79182b09340b19753Chris Lattner///
63c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent
64c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation,
65c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a
66c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form.
67cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner///
68cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG {
69063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &TLI;
707c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  MachineFunction *MF;
71ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  FunctionLoweringInfo &FLI;
7244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *MMI;
73cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
74f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// EntryNode - The starting token.
75f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDNode EntryNode;
76f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
77f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// Root - The root of the entire DAG.
78f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDValue Root;
79cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
80213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
81fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  ilist<SDNode> AllNodes;
82fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman
83f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use
84f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// pool allocation with recycling.
85f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
86f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman                             AlignOf<MostAlignedSDNode>::Alignment>
87f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman    NodeAllocatorType;
88f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
89f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// NodeAllocator - Pool allocation for nodes.
90f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  NodeAllocatorType NodeAllocator;
91691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
92213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
93213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSE with existing nodes with a duplicate is requested.
94583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  FoldingSet<SDNode> CSEMap;
95213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
96f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// OperandAllocator - Pool allocation for machine-opcode SDNode operands.
97f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  BumpPtrAllocator OperandAllocator;
98f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
99e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// Allocator - Pool allocation for misc. objects that are created once per
100e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// SelectionDAG.
101e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  BumpPtrAllocator Allocator;
102e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman
103d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands  /// VerifyNode - Sanity check the given node.  Aborts if it is invalid.
104d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands  void VerifyNode(SDNode *N);
105d038e04188047eca4749d025ef1f05f7ae660bcaDuncan Sands
106c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// setGraphColorHelper - Implementation of setSubgraphColor.
107c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// Return whether we had to truncate the search.
108c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  ///
109c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  bool setSubgraphColorHelper(SDNode *N, const char *Color, DenseSet<SDNode *> &visited,
110c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene                              int level, bool &printed);
111c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene
112cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
1137c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli);
114cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ~SelectionDAG();
115cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1167c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// init - Prepare this SelectionDAG to process code in the given
1177c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// MachineFunction.
1187c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  ///
1197c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  void init(MachineFunction &mf, MachineModuleInfo *mmi);
1207c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman
1217c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  /// clear - Clear state and free memory necessary to make this
122f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  /// SelectionDAG ready to process a new block.
123f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  ///
1247c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  void clear();
125f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
1267c3234c6be0dc0bdf4b5d6f848cd728a77f349d7Dan Gohman  MachineFunction &getMachineFunction() const { return *MF; }
127063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  const TargetMachine &getTarget() const;
128063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &getTargetLoweringInfo() const { return TLI; }
129ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; }
13044c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
131cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
132ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
1331080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  ///
134462dc7f4960e5074ddf4769ec8b2ef1ba7a4d2c8Dan Gohman  void viewGraph(const std::string &Title);
1350b12aef49087b57d276ed760a83525d1e2602144Dan Gohman  void viewGraph();
136ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
137ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG
138ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  std::map<const SDNode *, std::string> NodeGraphAttrs;
139ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif
1401080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
141ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// clearGraphAttrs - Clear all previously defined node graph attributes.
142ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Intended to be used from a debugging tool (eg. gdb).
143ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void clearGraphAttrs();
144ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
145ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
146ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
147ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphAttrs(const SDNode *N, const char *Attrs);
148ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
149ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
150ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Used from getNodeAttributes.
151ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  const std::string getGraphAttrs(const SDNode *N) const;
152ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
153ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphColor - Convenience for setting node color attribute.
154ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
155ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphColor(const SDNode *N, const char *Color);
1561080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
157c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  /// setGraphColor - Convenience for setting subgraph color attribute.
158c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  ///
159c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene  void setSubgraphColor(SDNode *N, const char *Color);
160c5e7e8d87d4a3b10edd5ac93ba1f3cdb4d1b449aDavid Greene
161fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
162b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
163b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
164fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  typedef ilist<SDNode>::iterator allnodes_iterator;
165b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
166b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
167fed90b6d097d50881afb45e4d79f430db66dd741Dan Gohman  ilist<SDNode>::size_type allnodes_size() const {
1680e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman    return AllNodes.size();
1690e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  }
170b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
171c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
172cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
173475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  const SDValue &getRoot() const { return Root; }
174cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
175c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
176c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
177f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  SDValue getEntryNode() const {
178f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman    return SDValue(const_cast<SDNode *>(&EntryNode), 0);
179f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  }
180cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
181c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
182cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
183475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  const SDValue &setRoot(SDValue N) {
184ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif    assert((!N.getNode() || N.getValueType() == MVT::Other) &&
185acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman           "DAG root value is not a chain!");
186acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman    return Root = N;
187acaf09dbe4a6781163857db1321bbd5795e7d410Dan Gohman  }
188cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1891d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
1901d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// certain types of nodes together, or eliminating superfluous nodes.  When
1911d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// the AfterLegalize argument is set to 'true', Combine takes care not to
1921d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// generate any nodes that will be illegal on the target.
193a267651b7ec4f96e01b31f541d446758bf8da8a9Dan Gohman  void Combine(bool AfterLegalize, AliasAnalysis &AA, bool Fast);
1941d4d41411190dd9e62764e56713753d4155764ddNate Begeman
19501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
19601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// only uses types natively supported by the target.
19701d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  ///
19801d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
19901d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// the graph.
20001d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  void LegalizeTypes();
20101d029b82cb08367d81aa10cdc94d05360466649Chris Lattner
202c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
203c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
204c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
205cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
206c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
207c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
208063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  void Legalize();
209c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
210d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
211190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
212190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
213130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
214130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// DeleteNode - Remove the specified node from the system.  This node must
215130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// have no referrers.
216130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void DeleteNode(SDNode *N);
217130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
21870046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getVTList - Return an SDVTList that represents the list of values
21970046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// specified.
22083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT);
22183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2);
22283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3);
22383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(const MVT *VTs, unsigned NumVTs);
22470046e920fa37989a041af663ada2b2b646e258fChris Lattner
22570046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getNodeValueTypes - These are obsolete, use getVTList instead.
22683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT) {
22770046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT).VTs;
22870046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
22983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2) {
23070046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2).VTs;
23170046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
23283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) {
23370046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2, VT3).VTs;
23470046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
235f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman  const MVT *getNodeValueTypes(const std::vector<MVT> &vtList) {
23613d57320bd212483463d4f8992d5787b29eda5dfBill Wendling    return getVTList(&vtList[0], (unsigned)vtList.size()).VTs;
23770046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
23870046e920fa37989a041af663ada2b2b646e258fChris Lattner
23970046e920fa37989a041af663ada2b2b646e258fChris Lattner
2401b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
24170046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
24270046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
243475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstant(uint64_t Val, MVT VT, bool isTarget = false);
244475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstant(const APInt &Val, MVT VT, bool isTarget = false);
2454fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  SDValue getConstant(const ConstantInt &Val, MVT VT, bool isTarget = false);
246475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
247475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstant(uint64_t Val, MVT VT) {
248cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getConstant(Val, VT, true);
249cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
250475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstant(const APInt &Val, MVT VT) {
2516394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman    return getConstant(Val, VT, true);
2526394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  }
2534fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  SDValue getTargetConstant(const ConstantInt &Val, MVT VT) {
2544fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman    return getConstant(Val, VT, true);
2554fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  }
256475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstantFP(double Val, MVT VT, bool isTarget = false);
257475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
2584fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  SDValue getConstantFP(const ConstantFP &CF, MVT VT, bool isTarget = false);
259475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstantFP(double Val, MVT VT) {
260c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
261c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
262475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstantFP(const APFloat& Val, MVT VT) {
263f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen    return getConstantFP(Val, VT, true);
264f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  }
2654fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  SDValue getTargetConstantFP(const ConstantFP &Val, MVT VT) {
2664fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman    return getConstantFP(Val, VT, true);
2674fbd796a1251a27e6590765a0a34876f436a0af9Dan Gohman  }
268475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getGlobalAddress(const GlobalValue *GV, MVT VT,
2696520e20e4fb31f2e65e25c38b372b19d33a83df4Dan Gohman                           int64_t offset = 0, bool isTargetGA = false);
270475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
2716520e20e4fb31f2e65e25c38b372b19d33a83df4Dan Gohman                                 int64_t offset = 0) {
272cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getGlobalAddress(GV, VT, offset, true);
273cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
274475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getFrameIndex(int FI, MVT VT, bool isTarget = false);
275475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetFrameIndex(int FI, MVT VT) {
276c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
277c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
278475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getJumpTable(int JTI, MVT VT, bool isTarget = false);
279475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetJumpTable(int JTI, MVT VT) {
280c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getJumpTable(JTI, VT, true);
281c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
282475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstantPool(Constant *C, MVT VT,
283c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                            unsigned Align = 0, int Offs = 0, bool isT=false);
284475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstantPool(Constant *C, MVT VT,
285c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                                  unsigned Align = 0, int Offset = 0) {
286c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantPool(C, VT, Align, Offset, true);
287c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
288475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getConstantPool(MachineConstantPoolValue *C, MVT VT,
289d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                            unsigned Align = 0, int Offs = 0, bool isT=false);
290475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTargetConstantPool(MachineConstantPoolValue *C,
29183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                                  MVT VT, unsigned Align = 0,
292d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  int Offset = 0) {
293d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return getConstantPool(C, VT, Align, Offset, true);
294d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
295475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getBasicBlock(MachineBasicBlock *MBB);
296056292fd738924f3f7703725d8f630983794b5a5Bill Wendling  SDValue getExternalSymbol(const char *Sym, MVT VT);
297056292fd738924f3f7703725d8f630983794b5a5Bill Wendling  SDValue getTargetExternalSymbol(const char *Sym, MVT VT);
298475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getArgFlags(ISD::ArgFlagsTy Flags);
299475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getValueType(MVT);
300475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getRegister(unsigned Reg, MVT VT);
301475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getDbgStopPoint(SDValue Root, unsigned Line, unsigned Col,
3027f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman                            const CompileUnitDesc *CU);
303475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getLabel(unsigned Opcode, SDValue Root, unsigned LabelID);
304c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
305475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N) {
306d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return getNode(ISD::CopyToReg, MVT::Other, Chain,
307d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner                   getRegister(Reg, N.getValueType()), N);
308cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  }
309cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
310e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
311e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
312e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
313475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCopyToReg(SDValue Chain, unsigned Reg, SDValue N,
314475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                         SDValue Flag) {
31583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
316475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
317ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3);
318e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
31966a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
320475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  // Similar to last getCopyToReg() except parameter Reg is a SDValue
321475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCopyToReg(SDValue Chain, SDValue Reg, SDValue N,
322475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                         SDValue Flag) {
32383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
324475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain, Reg, N, Flag };
325ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.getNode() ? 4 : 3);
32666a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  }
327e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
328475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT) {
32983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other);
330475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain, getRegister(Reg, VT) };
3312fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
33218c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner  }
333e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
334e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
335e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
336e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
337475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCopyFromReg(SDValue Chain, unsigned Reg, MVT VT,
338475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                           SDValue Flag) {
33983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
340475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag };
341ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif    return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.getNode() ? 3 : 2);
342e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
34318c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
344475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCondCode(ISD::CondCode Cond);
345cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
3461ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
3471ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
348475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getZeroExtendInReg(SDValue Op, MVT SrcTy);
3496a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner
3506a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
3516a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// a flag result (to ensure it's not CSE'd).
352475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) {
35383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
354475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SDValue Ops[] = { Chain,  Op };
3552fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
3566a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
3571ccae666f596d5aeca5c9942995763600b622062Chris Lattner
3580f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
3590f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// flag result (to ensure it's not CSE'd).
360475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
361475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                           SDValue InFlag) {
3620f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
363475871a144eb604ddaf37503397ba0941442e5fbDan Gohman    SmallVector<SDValue, 4> Ops;
3640f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Chain);
3650f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op1);
3660f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op2);
3670f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(InFlag);
3680f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0],
369ba36cb5242eb02b12b277f82b9efe497f7da4d7fGabor Greif                   (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0));
3700f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  }
3710f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling
372c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
373cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
374475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT);
375475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT, SDValue N);
376475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT, SDValue N1, SDValue N2);
377475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT,
378475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3);
379475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT,
380475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3, SDValue N4);
381475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT,
382475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3, SDValue N4,
383475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N5);
384475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT,
385475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    const SDValue *Ops, unsigned NumOps);
386475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, MVT VT,
3876d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDUse *Ops, unsigned NumOps);
388475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, const std::vector<MVT> &ResultTys,
389475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    const SDValue *Ops, unsigned NumOps);
390475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs,
391475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    const SDValue *Ops, unsigned NumOps);
392475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs);
393475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N);
394475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs, SDValue N1, SDValue N2);
395475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs,
396475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3);
397475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs,
398475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3, SDValue N4);
399475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs,
400475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N1, SDValue N2, SDValue N3, SDValue N4,
401475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue N5);
402475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getNode(unsigned Opcode, SDVTList VTs,
403475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    const SDValue *Ops, unsigned NumOps);
404475871a144eb604ddaf37503397ba0941442e5fbDan Gohman
405475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMemcpy(SDValue Chain, SDValue Dst, SDValue Src,
406475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Size, unsigned Align,
407707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      bool AlwaysInline,
4081f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff,
4091f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *SrcSV, uint64_t SrcSVOff);
4105c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
411475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMemmove(SDValue Chain, SDValue Dst, SDValue Src,
412475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       SDValue Size, unsigned Align,
4131f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *DstSV, uint64_t DstOSVff,
4141f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *SrcSV, uint64_t SrcSVOff);
4155c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
416475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMemset(SDValue Chain, SDValue Dst, SDValue Src,
417475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Size, unsigned Align,
4181f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff);
4195c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
4207cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// getSetCC - Helper function to make it easier to build SetCC's if you just
421475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  /// have an ISD::CondCode instead of an SDValue.
4227cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ///
423475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getSetCC(MVT VT, SDValue LHS, SDValue RHS,
4247cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner                     ISD::CondCode Cond) {
4257cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
426b43e9c196542acc80c9e4643809661065710848fNate Begeman  }
427b43e9c196542acc80c9e4643809661065710848fNate Begeman
428b43e9c196542acc80c9e4643809661065710848fNate Begeman  /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
429475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  /// if you just have an ISD::CondCode instead of an SDValue.
430b43e9c196542acc80c9e4643809661065710848fNate Begeman  ///
431475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getVSetCC(MVT VT, SDValue LHS, SDValue RHS,
432b43e9c196542acc80c9e4643809661065710848fNate Begeman                      ISD::CondCode Cond) {
433b43e9c196542acc80c9e4643809661065710848fNate Begeman    return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond));
4347cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  }
4359373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
4369373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
437475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  /// just have an ISD::CondCode instead of an SDValue.
4389373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  ///
439475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getSelectCC(SDValue LHS, SDValue RHS,
440475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        SDValue True, SDValue False, ISD::CondCode Cond) {
4412fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
4422fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                   getCondCode(Cond));
4439373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  }
4447cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
445acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
446acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// and a source value as input.
447475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getVAArg(MVT VT, SDValue Chain, SDValue Ptr,
448475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                     SDValue SV);
4497cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
450c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// getAtomic - Gets a node for an atomic op, produces result and chain and
451c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// takes 3 operands
452475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr,
453475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Cmp, SDValue Swp, const Value* PtrVal,
45428873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment=0);
455ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
456c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// getAtomic - Gets a node for an atomic op, produces result and chain and
457c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// takes 2 operands.
458475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getAtomic(unsigned Opcode, SDValue Chain, SDValue Ptr,
459475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Val, const Value* PtrVal,
46028873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment = 0);
461ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
462c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// getMemIntrinsicNode - Creates a MemIntrinsicNode that may produce a
463c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  /// result and takes a list of operands.
464c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  SDValue getMemIntrinsicNode(unsigned Opcode,
465c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              const MVT *VTs, unsigned NumVTs,
466c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              const SDValue *Ops, unsigned NumOps,
467c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              MVT MemVT, const Value *srcValue, int SVOff,
468c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              unsigned Align = 0, bool Vol = false,
469c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              bool ReadMem = true, bool WriteMem = true);
470c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang
471c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang  SDValue getMemIntrinsicNode(unsigned Opcode, SDVTList VTList,
472c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              const SDValue *Ops, unsigned NumOps,
473c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              MVT MemVT, const Value *srcValue, int SVOff,
474c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              unsigned Align = 0, bool Vol = false,
475c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang                              bool ReadMem = true, bool WriteMem = true);
476c4d1021ead43cfa7da08a8f7ddc9a059a8ba14c5Mon P Wang
4774bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given operands.
4784bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
479475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMergeValues(const SDValue *Ops, unsigned NumOps,
4804bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands                           bool Simplify = true);
4814bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands
482f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given types and ops.
483f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
4844bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// May be faster than the above version if VTs is known and NumOps is large.
485475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMergeValues(SDVTList VTs, const SDValue *Ops, unsigned NumOps,
486f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands                           bool Simplify = true) {
487f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    if (Simplify && NumOps == 1)
488f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands      return Ops[0];
489f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps);
490f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  }
491f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands
492095cc29f321382e1f7d295e262a28197f92c5491Dan Gohman  /// getCall - Create a CALL node from the given information.
493095cc29f321382e1f7d295e262a28197f92c5491Dan Gohman  ///
494095cc29f321382e1f7d295e262a28197f92c5491Dan Gohman  SDValue getCall(unsigned CallingConv, bool IsVarArgs, bool IsTailCall,
49586098bd6a63d2cdf0c9be9ef3151bd2728281fd7Dale Johannesen                  bool isInreg, SDVTList VTs, const SDValue *Operands,
49686098bd6a63d2cdf0c9be9ef3151bd2728281fd7Dale Johannesen                  unsigned NumOperands);
497095cc29f321382e1f7d295e262a28197f92c5491Dan Gohman
498c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getLoad - Loads are not normal binary operators: their result type is not
499c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// determined by their operands, and they produce a value AND a token chain.
500cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
501475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getLoad(MVT VT, SDValue Chain, SDValue Ptr,
50295c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    const Value *SV, int SVOffset, bool isVolatile=false,
50395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    unsigned Alignment=0);
504475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getExtLoad(ISD::LoadExtType ExtType, MVT VT,
505475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       SDValue Chain, SDValue Ptr, const Value *SV,
50683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       int SVOffset, MVT EVT, bool isVolatile=false,
50795c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                       unsigned Alignment=0);
508475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getIndexedLoad(SDValue OrigLoad, SDValue Base,
509475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                           SDValue Offset, ISD::MemIndexedMode AM);
510475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
511475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    MVT VT, SDValue Chain,
512475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                    SDValue Ptr, SDValue Offset,
51383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                    const Value *SV, int SVOffset, MVT EVT,
514e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands                    bool isVolatile=false, unsigned Alignment=0);
5152d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
516ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  /// getStore - Helper function to build ISD::STORE nodes.
517ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  ///
518475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getStore(SDValue Chain, SDValue Val, SDValue Ptr,
51995c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     const Value *SV, int SVOffset, bool isVolatile=false,
52095c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     unsigned Alignment=0);
521475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getTruncStore(SDValue Chain, SDValue Val, SDValue Ptr,
52283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                          const Value *SV, int SVOffset, MVT TVT,
52395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                          bool isVolatile=false, unsigned Alignment=0);
524475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getIndexedStore(SDValue OrigStoe, SDValue Base,
525475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                           SDValue Offset, ISD::MemIndexedMode AM);
526ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng
52769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getSrcValue - Construct a node to track a Value* through the backend.
528475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getSrcValue(const Value *v);
52969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
53069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getMemOperand - Construct a node to track a memory reference
53169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // through the backend.
532475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getMemOperand(const MachineMemOperand &MO);
533cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
534b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
535b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// specified operands.  If the resultant node already exists in the DAG,
536b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// this does not modify the specified node, instead it returns the node that
537b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// already exists.  If the resultant node does not exist in the DAG, the
538b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input node is returned.  As a degenerate case, if you specify the same
539b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input operands as the node already has, the input node is returned.
540475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N, SDValue Op);
541475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2);
542475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
543475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                               SDValue Op3);
544475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
545475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                               SDValue Op3, SDValue Op4);
546475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
547475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                               SDValue Op3, SDValue Op4, SDValue Op5);
548475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue UpdateNodeOperands(SDValue N,
549475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                               const SDValue *Ops, unsigned NumOps);
5501b95095857b78e12138c22e76c7936611c51355bChris Lattner
5511b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// SelectNodeTo - These are used for target selectors to *mutate* the
5521b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// specified node to have the specified return type, Target opcode, and
5531b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// operands.  Note that target opcodes are stored as
554e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// ~TargetOpcode in the node opcode field.  The resultant node is returned.
55583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT);
556475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDValue Op1);
55783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
558475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       SDValue Op1, SDValue Op2);
55983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
560475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       SDValue Op1, SDValue Op2, SDValue Op3);
56183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
562475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       const SDValue *Ops, unsigned NumOps);
563cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2);
564cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
565475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       MVT VT2, const SDValue *Ops, unsigned NumOps);
566cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
567475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps);
568cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
569475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       MVT VT2, SDValue Op1);
57083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
571475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       MVT VT2, SDValue Op1, SDValue Op2);
57283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
573475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
574cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
575475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                       const SDValue *Ops, unsigned NumOps);
576694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng
577e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// MorphNodeTo - These *mutate* the specified node to have the specified
578e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// return type, opcode, and operands.
579e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT);
580475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT, SDValue Op1);
581e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
582475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Op1, SDValue Op2);
583e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
584475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      SDValue Op1, SDValue Op2, SDValue Op3);
585e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT,
586475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      const SDValue *Ops, unsigned NumOps);
587e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1, MVT VT2);
588e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
589475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      MVT VT2, const SDValue *Ops, unsigned NumOps);
590e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
591475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      MVT VT2, MVT VT3, const SDValue *Ops, unsigned NumOps);
592e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
593475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      MVT VT2, SDValue Op1);
594e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
595475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      MVT VT2, SDValue Op1, SDValue Op2);
596e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, MVT VT1,
597475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
598e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
599475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                      const SDValue *Ops, unsigned NumOps);
600753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner
6016ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// getTargetNode - These are used for target selectors to create a new node
6026ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// with specified return type(s), target opcode, and operands.
6036ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  ///
6046ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// Note that getTargetNode returns the resultant node.  If there is already a
6056ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// node of the specified opcode and operands, it returns that node instead of
6066ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// the current one.
60783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT);
608475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1);
609475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDValue Op1, SDValue Op2);
61083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
611475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        SDValue Op1, SDValue Op2, SDValue Op3);
61283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
613475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        const SDValue *Ops, unsigned NumOps);
61483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2);
615475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDValue Op1);
61683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
617475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        MVT VT2, SDValue Op1, SDValue Op2);
61883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
619475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        MVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
62083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2,
621475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        const SDValue *Ops, unsigned NumOps);
62283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
623475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        SDValue Op1, SDValue Op2);
62483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
625475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        SDValue Op1, SDValue Op2, SDValue Op3);
62683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
627475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        const SDValue *Ops, unsigned NumOps);
62883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4,
629475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        const SDValue *Ops, unsigned NumOps);
630f877b735ad4987f26cafcbaf22aa4c2199458b5dDan Gohman  SDNode *getTargetNode(unsigned Opcode, const std::vector<MVT> &ResultTys,
631475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                        const SDValue *Ops, unsigned NumOps);
63208b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng
63308b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// getNodeIfExists - Get the specified node if it's already available, or
63408b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// else return NULL.
63508b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
636475871a144eb604ddaf37503397ba0941442e5fbDan Gohman                          const SDValue *Ops, unsigned NumOps);
6376542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner
638f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// DAGUpdateListener - Clients of various APIs that cause global effects on
639f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// the DAG can optionally implement this interface.  This allows the clients
640f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// to handle the various sorts of updates that happen.
641f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  class DAGUpdateListener {
642f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  public:
643f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual ~DAGUpdateListener();
644edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
645edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeDeleted - The node N that was deleted and, if E is not null, an
646edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// equivalent node E that replaced it.
647edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
648edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
649edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeUpdated - The node N that was updated.
650f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual void NodeUpdated(SDNode *N) = 0;
651f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  };
652f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
653f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// RemoveDeadNode - Remove the specified node from the system. If any of its
654f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// operands then becomes dead, remove them as well. Inform UpdateListener
655f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// for each node deleted.
656f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
657f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
6580fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  /// RemoveDeadNodes - This method deletes the unreachable nodes in the
6590fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  /// given list, and any nodes that become unreachable as a result.
6600fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes,
6610fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman                       DAGUpdateListener *UpdateListener = 0);
6620fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman
6636542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
66426005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// This can cause recursive merging of nodes in the DAG.  Use the first
66526005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// version if 'From' is known to have a single result, use the second
66626005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// if you have two nodes with identical results, use the third otherwise.
6676542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  ///
668f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// These methods all take an optional UpdateListener, which (if not null) is
669f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// informed about nodes that are deleted and modified due to recursive
670f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// changes in the dag.
671fde3f3061d665babeb78443119a09876098fc35eChris Lattner  ///
672475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  void ReplaceAllUsesWith(SDValue From, SDValue Op,
673f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
674fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
675f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
676475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  void ReplaceAllUsesWith(SDNode *From, const SDValue *To,
677f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
678fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng
67980274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
680f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// uses of other values produced by From.Val alone.
681475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  void ReplaceAllUsesOfValueWith(SDValue From, SDValue To,
682f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                                 DAGUpdateListener *UpdateListener = 0);
68380274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner
684e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// ReplaceAllUsesOfValuesWith - Like ReplaceAllUsesOfValueWith, but
685e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// for multiple values at once. This correctly handles the case where
686e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  /// there is an overlap between the From values and the To values.
687475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
688e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman                                  unsigned Num,
689e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman                                  DAGUpdateListener *UpdateListener = 0);
690e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman
691f06c835f769aa1cf67801ed1f6bd366a447c18b1Dan Gohman  /// AssignTopologicalOrder - Topological-sort the AllNodes list and a
692f06c835f769aa1cf67801ed1f6bd366a447c18b1Dan Gohman  /// assign a unique node id for each node in the DAG based on their
693f06c835f769aa1cf67801ed1f6bd366a447c18b1Dan Gohman  /// topological order. Returns the number of nodes.
694f06c835f769aa1cf67801ed1f6bd366a447c18b1Dan Gohman  unsigned AssignTopologicalOrder();
695e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng
6968be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman  /// RepositionNode - Move node N in the AllNodes list to be immediately
6978be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman  /// before the given iterator Position. This may be used to update the
6988be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman  /// topological ordering when the list of nodes is modified.
6998be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman  void RepositionNode(allnodes_iterator Position, SDNode *N) {
7008be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman    AllNodes.insert(Position, AllNodes.remove(N));
7018be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman  }
7028be6bbe5bfd50945ac6c5542e0f54a0924a5db8dDan Gohman
7031efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
7041efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// operation.
7051efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  static bool isCommutativeBinOp(unsigned Opcode) {
7064ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // FIXME: This should get its info from the td file, so that we can include
7074ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // target info.
7081efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    switch (Opcode) {
7091efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADD:
7101efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MUL:
7111efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHU:
7121efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHS:
713b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::SMUL_LOHI:
714b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::UMUL_LOHI:
7151efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FADD:
7161efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FMUL:
7171efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::AND:
7181efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::OR:
7191efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::XOR:
7201efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDC:
7211efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDE: return true;
7221efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    default: return false;
7231efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    }
7241efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  }
7251efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng
726cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  void dump() const;
727d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner
72837ce9df0da6cddc3b8bfef9b63d33d058a0f2f15Chris Lattner  /// CreateStackTemporary - Create a stack temporary, suitable for holding the
729364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang  /// specified value type.  If minAlign is specified, the slot size will have
730364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang  /// at least that alignment.
731475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue CreateStackTemporary(MVT VT, unsigned minAlign = 1);
732364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang
733f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling  /// FoldConstantArithmetic -
734f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling  SDValue FoldConstantArithmetic(unsigned Opcode,
735f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling                                 MVT VT,
736f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling                                 ConstantSDNode *Cst1,
737f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling                                 ConstantSDNode *Cst2);
738f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling
73951dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  /// FoldSetCC - Constant fold a setcc to true or false.
740475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue FoldSetCC(MVT VT, SDValue N1,
741f3cbca279db891403659208a99f8e1cceb8c9ea6Bill Wendling                    SDValue N2, ISD::CondCode Cond);
74251dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner
7432e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// SignBitIsZero - Return true if the sign bit of Op is known to be zero.  We
7442e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// use this predicate to simplify operations downstream.
745475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
7462e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman
747ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
748ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// use this predicate to simplify operations downstream.  Op and Mask are
749ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be the same type.
750475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
751ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman    const;
752ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
753ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
754ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be either zero or one and return them in the KnownZero/KnownOne
755ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
756ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// processing.  Targets can implement the computeMaskedBitsForTargetNode
757ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// method in the TargetLowering class to allow target nodes to be understood.
758475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero,
759fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman                         APInt &KnownOne, unsigned Depth = 0) const;
760fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman
761ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeNumSignBits - Return the number of times the sign bit of the
762ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// register is replicated into the other bits.  We know that at least 1 bit
763ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// is always equal to the sign bit (itself), but other cases can give us
764ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// information.  For example, immediately after an "SRA X, 2", we know that
765ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// the top 3 bits are all equal to each other, so we return 3.  Targets can
766ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
767ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// class to allow target nodes to be understood.
768475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
769a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng
770475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  /// isVerifiedDebugInfoDesc - Returns true if the specified SDValue has
771a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  /// been verified as a debug information descriptor.
772475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  bool isVerifiedDebugInfoDesc(SDValue Op) const;
77377f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng
77477f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// getShuffleScalarElt - Returns the scalar element that will make up the ith
77577f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// element of the result of the vector shuffle.
776475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDValue getShuffleScalarElt(const SDNode *N, unsigned Idx);
777ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
778d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate:
779095cc29f321382e1f7d295e262a28197f92c5491Dan Gohman  bool RemoveNodeFromCSEMaps(SDNode *N);
7806542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
781475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
782475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
783a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
784475871a144eb604ddaf37503397ba0941442e5fbDan Gohman  SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps,
785a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
786b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner
787fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void DeleteNodeNotInCSEMaps(SDNode *N);
7889c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman
7899c6e70eca9a49c146b26621cbcbb9464ceeac024Dan Gohman  unsigned getMVTAlignment(MVT MemoryVT) const;
790f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman
791f350b277f32d7d47f86c0e54f4aec4d470500618Dan Gohman  void allnodes_clear();
7927cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
793109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  // List of non-single value types.
794e8be6c63915e0389f1eef6b53c64300d13b2ce99Dan Gohman  std::vector<SDVTList> VTList;
795109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
7961cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner  // Maps to auto-CSE operations.
7977cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  std::vector<CondCodeSDNode*> CondCodeNodes;
7981cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner
79915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  std::vector<SDNode*> ValueTypeNodes;
8008e4eb09b1e3571965f49edcdfb56b1375b1b7551Duncan Sands  std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes;
801056292fd738924f3f7703725d8f630983794b5a5Bill Wendling  StringMap<SDNode*> ExternalSymbols;
802056292fd738924f3f7703725d8f630983794b5a5Bill Wendling  StringMap<SDNode*> TargetExternalSymbols;
803cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner};
804cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
8051080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
8061080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SelectionDAG::allnodes_iterator nodes_iterator;
8071080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_begin(SelectionDAG *G) {
8081080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_begin();
8091080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
8101080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_end(SelectionDAG *G) {
8111080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_end();
8121080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
8131080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
8141080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
815b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner}  // end namespace llvm
816cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
817cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif
818