SelectionDAG.h revision 0e5f1306b059b62d7725f324e087efbc8e7a782d
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
18583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/ADT/FoldingSet.h"
194b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman#include "llvm/ADT/StringMap.h"
20583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h"
21b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
22109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner#include <list>
235892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector>
24322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
25eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string>
26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
28c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  class AliasAnalysis;
29c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetLowering;
30c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetMachine;
3144c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  class MachineModuleInfo;
32c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class MachineFunction;
33d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  class MachineConstantPoolValue;
34ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  class FunctionLoweringInfo;
35c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
36c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function
37c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction
38c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection.  This DAG is constructed as the first step of instruction
39c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations
40c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications.
41c3aae25116e66c177579b0b79182b09340b19753Chris Lattner///
42c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent
43c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation,
44c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a
45c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form.
46cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner///
47cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG {
48063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &TLI;
49c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &MF;
50ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  FunctionLoweringInfo &FLI;
5144c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *MMI;
52cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
53213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// Root - The root of the entire DAG.  EntryNode - The starting token.
54c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand Root, EntryNode;
55cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
56213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
570e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  alist<SDNode, LargestSDNode> &AllNodes;
58691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
59213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
60213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSE with existing nodes with a duplicate is requested.
61583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  FoldingSet<SDNode> CSEMap;
62213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
63cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
64ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  SelectionDAG(TargetLowering &tli, MachineFunction &mf,
650e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman               FunctionLoweringInfo &fli, MachineModuleInfo *mmi,
660e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman               alist<SDNode, LargestSDNode> &NodePool)
670e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  : TLI(tli), MF(mf), FLI(fli), MMI(mmi), AllNodes(NodePool) {
68c3aae25116e66c177579b0b79182b09340b19753Chris Lattner    EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
69c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  }
70cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ~SelectionDAG();
71cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
72c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &getMachineFunction() const { return MF; }
73063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  const TargetMachine &getTarget() const;
74063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &getTargetLoweringInfo() const { return TLI; }
75ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; }
7644c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
77cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
78ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
791080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  ///
801080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  void viewGraph();
81ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
82ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG
83ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  std::map<const SDNode *, std::string> NodeGraphAttrs;
84ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif
851080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
86ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// clearGraphAttrs - Clear all previously defined node graph attributes.
87ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Intended to be used from a debugging tool (eg. gdb).
88ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void clearGraphAttrs();
89ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
90ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
91ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
92ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphAttrs(const SDNode *N, const char *Attrs);
93ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
94ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
95ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Used from getNodeAttributes.
96ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  const std::string getGraphAttrs(const SDNode *N) const;
97ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
98ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphColor - Convenience for setting node color attribute.
99ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
100ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphColor(const SDNode *N, const char *Color);
1011080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
1020e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  typedef alist<SDNode, LargestSDNode>::const_iterator allnodes_const_iterator;
103b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
104b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
1050e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  typedef alist<SDNode, LargestSDNode>::iterator allnodes_iterator;
106b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
107b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
1080e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  alist<SDNode, LargestSDNode>::size_type allnodes_size() const {
1090e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman    return AllNodes.size();
1100e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  }
111b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
112c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
113cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
114c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getRoot() const { return Root; }
115cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
116c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
117c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
118c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getEntryNode() const { return EntryNode; }
119cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
120c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
121cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
122c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &setRoot(SDOperand N) { return Root = N; }
123cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1241d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
1251d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// certain types of nodes together, or eliminating superfluous nodes.  When
1261d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// the AfterLegalize argument is set to 'true', Combine takes care not to
1271d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// generate any nodes that will be illegal on the target.
128c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  void Combine(bool AfterLegalize, AliasAnalysis &AA);
1291d4d41411190dd9e62764e56713753d4155764ddNate Begeman
13001d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
13101d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// only uses types natively supported by the target.
13201d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  ///
13301d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
13401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// the graph.
13501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  void LegalizeTypes();
13601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner
137c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
138c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
139c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
140cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
141c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
142c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
143063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  void Legalize();
144c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
145d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
146190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
147190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
148130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
149130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// DeleteNode - Remove the specified node from the system.  This node must
150130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// have no referrers.
151130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void DeleteNode(SDNode *N);
152130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
15370046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getVTList - Return an SDVTList that represents the list of values
15470046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// specified.
15583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT);
15683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2);
15783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3);
15883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(const MVT *VTs, unsigned NumVTs);
15970046e920fa37989a041af663ada2b2b646e258fChris Lattner
16070046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getNodeValueTypes - These are obsolete, use getVTList instead.
16183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT) {
16270046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT).VTs;
16370046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2) {
16570046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2).VTs;
16670046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) {
16870046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2, VT3).VTs;
16970046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
17083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(std::vector<MVT> &vtList) {
17113d57320bd212483463d4f8992d5787b29eda5dfBill Wendling    return getVTList(&vtList[0], (unsigned)vtList.size()).VTs;
17270046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
17370046e920fa37989a041af663ada2b2b646e258fChris Lattner
17470046e920fa37989a041af663ada2b2b646e258fChris Lattner
1751b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
17670046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
17770046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
17883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstant(uint64_t Val, MVT VT, bool isTarget = false);
17983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstant(const APInt &Val, MVT VT, bool isTarget = false);
1800bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner  SDOperand getIntPtrConstant(uint64_t Val, bool isTarget = false);
18183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstant(uint64_t Val, MVT VT) {
182cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getConstant(Val, VT, true);
183cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
18483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstant(const APInt &Val, MVT VT) {
1856394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman    return getConstant(Val, VT, true);
1866394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  }
18783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantFP(double Val, MVT VT, bool isTarget = false);
18883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
18983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantFP(double Val, MVT VT) {
190c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
191c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
19283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantFP(const APFloat& Val, MVT VT) {
193f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen    return getConstantFP(Val, VT, true);
194f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  }
19583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getGlobalAddress(const GlobalValue *GV, MVT VT,
196cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                             int offset = 0, bool isTargetGA = false);
19783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
198cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                                   int offset = 0) {
199cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getGlobalAddress(GV, VT, offset, true);
200cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
20183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getFrameIndex(int FI, MVT VT, bool isTarget = false);
20283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetFrameIndex(int FI, MVT VT) {
203c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
204c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
20583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getJumpTable(int JTI, MVT VT, bool isTarget = false);
20683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetJumpTable(int JTI, MVT VT) {
207c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getJumpTable(JTI, VT, true);
208c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
20983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantPool(Constant *C, MVT VT,
210c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                            unsigned Align = 0, int Offs = 0, bool isT=false);
21183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantPool(Constant *C, MVT VT,
212c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                                  unsigned Align = 0, int Offset = 0) {
213c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantPool(C, VT, Align, Offset, true);
214c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
21583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantPool(MachineConstantPoolValue *C, MVT VT,
216d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                            unsigned Align = 0, int Offs = 0, bool isT=false);
217d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
21883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                                  MVT VT, unsigned Align = 0,
219d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  int Offset = 0) {
220d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return getConstantPool(C, VT, Align, Offset, true);
221d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
222c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getBasicBlock(MachineBasicBlock *MBB);
22383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getExternalSymbol(const char *Sym, MVT VT);
22483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetExternalSymbol(const char *Sym, MVT VT);
225276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  SDOperand getArgFlags(ISD::ArgFlagsTy Flags);
22683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getValueType(MVT);
22783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getRegister(unsigned Reg, MVT VT);
2287f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman  SDOperand getDbgStopPoint(SDOperand Root, unsigned Line, unsigned Col,
2297f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman                            const CompileUnitDesc *CU);
2304406604047423576e36657c7ede266ca42e79642Dan Gohman  SDOperand getLabel(unsigned Opcode, SDOperand Root, unsigned LabelID);
231c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
232d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
233d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return getNode(ISD::CopyToReg, MVT::Other, Chain,
234d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner                   getRegister(Reg, N.getValueType()), N);
235cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  }
236cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
237e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
238e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
239e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
240e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
241e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                         SDOperand Flag) {
24283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
243bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
2442fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
245e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
24666a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
24766a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  // Similar to last getCopyToReg() except parameter Reg is a SDOperand
24866a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
24966a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng                         SDOperand Flag) {
25083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
251bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, Reg, N, Flag };
2522fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
25366a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  }
254e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
25583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT) {
25683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other);
257f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
2582fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
25918c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner  }
260e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
261e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
262e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
263e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
26483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT,
265e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                           SDOperand Flag) {
26683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
267f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
2682fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
269e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
27018c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
2717cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getCondCode(ISD::CondCode Cond);
272cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
2731ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
2741ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
27583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getZeroExtendInReg(SDOperand Op, MVT SrcTy);
2766a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner
2776a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
2786a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// a flag result (to ensure it's not CSE'd).
2796a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
28083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
281f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain,  Op };
2822fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
2836a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
2841ccae666f596d5aeca5c9942995763600b622062Chris Lattner
2850f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
2860f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// flag result (to ensure it's not CSE'd).
2870f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  SDOperand getCALLSEQ_END(SDOperand Chain, SDOperand Op1, SDOperand Op2,
2880f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling                           SDOperand InFlag) {
2890f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
2900f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    SmallVector<SDOperand, 4> Ops;
2910f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Chain);
2920f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op1);
2930f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op2);
2940f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(InFlag);
2950f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0],
29634cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng                   (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0));
2970f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  }
2980f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling
299c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
300cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
30183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT);
30283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N);
30383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N1, SDOperand N2);
30483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
305c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3);
30683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
3072d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
30883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
309f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
310f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N5);
3116d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDOperand getNode(unsigned Opcode, MVT VT,
3126d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDOperand *Ops, unsigned NumOps);
3136d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDOperand getNode(unsigned Opcode, MVT VT,
3146d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDUse *Ops, unsigned NumOps);
31583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, std::vector<MVT> &ResultTys,
3166d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDOperand *Ops, unsigned NumOps);
31783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs,
3186d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDOperand *Ops, unsigned NumOps);
31908ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs);
32008ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N);
32183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N1, SDOperand N2);
32208ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
32308ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3);
32408ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
32508ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
32608ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
32708ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
32808ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N5);
32967bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner  SDOperand getNode(unsigned Opcode, SDVTList VTs,
3306d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                    const SDOperand *Ops, unsigned NumOps);
3315c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
332707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemcpy(SDOperand Chain, SDOperand Dst, SDOperand Src,
333707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      SDOperand Size, unsigned Align,
334707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      bool AlwaysInline,
3351f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff,
3361f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *SrcSV, uint64_t SrcSVOff);
3375c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
338707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemmove(SDOperand Chain, SDOperand Dst, SDOperand Src,
33955888274f21fc1a760679a51591a209758db8cbfDan Gohman                       SDOperand Size, unsigned Align,
3401f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *DstSV, uint64_t DstOSVff,
3411f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *SrcSV, uint64_t SrcSVOff);
3425c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
343707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemset(SDOperand Chain, SDOperand Dst, SDOperand Src,
344707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      SDOperand Size, unsigned Align,
3451f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff);
3465c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
3477cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// getSetCC - Helper function to make it easier to build SetCC's if you just
3487cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// have an ISD::CondCode instead of an SDOperand.
3497cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ///
35083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
3517cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner                     ISD::CondCode Cond) {
3527cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
353b43e9c196542acc80c9e4643809661065710848fNate Begeman  }
354b43e9c196542acc80c9e4643809661065710848fNate Begeman
355b43e9c196542acc80c9e4643809661065710848fNate Begeman  /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
356b43e9c196542acc80c9e4643809661065710848fNate Begeman  /// if you just have an ISD::CondCode instead of an SDOperand.
357b43e9c196542acc80c9e4643809661065710848fNate Begeman  ///
35883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getVSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
359b43e9c196542acc80c9e4643809661065710848fNate Begeman                      ISD::CondCode Cond) {
360b43e9c196542acc80c9e4643809661065710848fNate Begeman    return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond));
3617cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  }
3629373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
3639373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
3649373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// just have an ISD::CondCode instead of an SDOperand.
3659373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  ///
3669373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
3679373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman                        SDOperand True, SDOperand False, ISD::CondCode Cond) {
3682fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
3692fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                   getCondCode(Cond));
3709373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  }
3717cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
372acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
373acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// and a source value as input.
37483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getVAArg(MVT VT, SDOperand Chain, SDOperand Ptr,
375acc398c195a697795bff3245943d104eb19192b9Nate Begeman                     SDOperand SV);
3767cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
377ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
37828873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang  /// 3 operands
379ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
380fd4418fc9b4725c44210c169c4d6500be468ca70Dan Gohman                      SDOperand Cmp, SDOperand Swp, const Value* PtrVal,
38128873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment=0);
382ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
383ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
38428873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang  /// 2 operands
385ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
386fd4418fc9b4725c44210c169c4d6500be468ca70Dan Gohman                      SDOperand Val, const Value* PtrVal,
38728873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment = 0);
388ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
3894bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given operands.
3904bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
3916d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDOperand getMergeValues(const SDOperand *Ops, unsigned NumOps,
3924bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands                           bool Simplify = true);
3934bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands
394f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given types and ops.
395f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
3964bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// May be faster than the above version if VTs is known and NumOps is large.
3976d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDOperand getMergeValues(SDVTList VTs, const SDOperand *Ops, unsigned NumOps,
398f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands                           bool Simplify = true) {
399f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    if (Simplify && NumOps == 1)
400f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands      return Ops[0];
401f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps);
402f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  }
403f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands
404c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getLoad - Loads are not normal binary operators: their result type is not
405c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// determined by their operands, and they produce a value AND a token chain.
406cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
40783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getLoad(MVT VT, SDOperand Chain, SDOperand Ptr,
40895c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    const Value *SV, int SVOffset, bool isVolatile=false,
40995c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    unsigned Alignment=0);
41083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT VT,
41124446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                       SDOperand Chain, SDOperand Ptr, const Value *SV,
41283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       int SVOffset, MVT EVT, bool isVolatile=false,
41395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                       unsigned Alignment=0);
4148862ef148100070b7bf28beead3951464250c926Evan Cheng  SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
415144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
416e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands  SDOperand getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
41783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                    MVT VT, SDOperand Chain,
418e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands                    SDOperand Ptr, SDOperand Offset,
41983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                    const Value *SV, int SVOffset, MVT EVT,
420e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands                    bool isVolatile=false, unsigned Alignment=0);
4212d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
422ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  /// getStore - Helper function to build ISD::STORE nodes.
423ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  ///
424d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
42595c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     const Value *SV, int SVOffset, bool isVolatile=false,
42695c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     unsigned Alignment=0);
427d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
42883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                          const Value *SV, int SVOffset, MVT TVT,
42995c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                          bool isVolatile=false, unsigned Alignment=0);
4309109fb1eb7d3341727353777c2a4282aa1a0c39aEvan Cheng  SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
431144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
432ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng
43369de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getSrcValue - Construct a node to track a Value* through the backend.
43469de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  SDOperand getSrcValue(const Value *v);
43569de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
43669de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getMemOperand - Construct a node to track a memory reference
43769de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // through the backend.
43836b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  SDOperand getMemOperand(const MachineMemOperand &MO);
439cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
440b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
441b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// specified operands.  If the resultant node already exists in the DAG,
442b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// this does not modify the specified node, instead it returns the node that
443b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// already exists.  If the resultant node does not exist in the DAG, the
444b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input node is returned.  As a degenerate case, if you specify the same
445b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input operands as the node already has, the input node is returned.
446b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
447b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
448b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
449b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3);
450b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
451b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3, SDOperand Op4);
4529b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
4539b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner                               SDOperand Op3, SDOperand Op4, SDOperand Op5);
4546d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDOperand UpdateNodeOperands(SDOperand N,
4556d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                               const SDOperand *Ops, unsigned NumOps);
4561b95095857b78e12138c22e76c7936611c51355bChris Lattner
4571b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// SelectNodeTo - These are used for target selectors to *mutate* the
4581b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// specified node to have the specified return type, Target opcode, and
4591b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// operands.  Note that target opcodes are stored as
460eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field.  The 0th value
461eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// of the resultant node is returned.
46283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT);
46383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDOperand Op1);
46483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
46595514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2);
46683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
46795514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2, SDOperand Op3);
46883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
4696d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                       const SDOperand *Ops, unsigned NumOps);
470cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2);
471cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
4726d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                       MVT VT2, const SDOperand *Ops, unsigned NumOps);
473cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
4746d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                       MVT VT2, MVT VT3, const SDOperand *Ops, unsigned NumOps);
475cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
476cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman                       MVT VT2, SDOperand Op1);
47783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
47883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       MVT VT2, SDOperand Op1, SDOperand Op2);
47983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
48083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
481cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
4826d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                       const SDOperand *Ops, unsigned NumOps);
483694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng
484753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner
4856ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// getTargetNode - These are used for target selectors to create a new node
4866ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// with specified return type(s), target opcode, and operands.
4876ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  ///
4886ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// Note that getTargetNode returns the resultant node.  If there is already a
4896ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// node of the specified opcode and operands, it returns that node instead of
4906ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// the current one.
49183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT);
49283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1);
49383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1, SDOperand Op2);
49483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
4956ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
49683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
4976d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                        const SDOperand *Ops, unsigned NumOps);
49883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2);
49983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDOperand Op1);
50083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
50183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                        MVT VT2, SDOperand Op1, SDOperand Op2);
50283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
50383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                        MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
50483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2,
5056d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                        const SDOperand *Ops, unsigned NumOps);
50683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
5076ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
50883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
509b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
51083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
5116d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                        const SDOperand *Ops, unsigned NumOps);
51283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4,
5136d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                        const SDOperand *Ops, unsigned NumOps);
51483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, std::vector<MVT> &ResultTys,
5156d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                        const SDOperand *Ops, unsigned NumOps);
51608b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng
51708b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// getNodeIfExists - Get the specified node if it's already available, or
51808b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// else return NULL.
51908b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
5206d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman                          const SDOperand *Ops, unsigned NumOps);
5216542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner
522f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// DAGUpdateListener - Clients of various APIs that cause global effects on
523f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// the DAG can optionally implement this interface.  This allows the clients
524f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// to handle the various sorts of updates that happen.
525f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  class DAGUpdateListener {
526f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  public:
527f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual ~DAGUpdateListener();
528edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
529edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeDeleted - The node N that was deleted and, if E is not null, an
530edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// equivalent node E that replaced it.
531edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
532edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
533edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeUpdated - The node N that was updated.
534f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual void NodeUpdated(SDNode *N) = 0;
535f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  };
536f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
537f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// RemoveDeadNode - Remove the specified node from the system. If any of its
538f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// operands then becomes dead, remove them as well. Inform UpdateListener
539f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// for each node deleted.
540f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
541f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
5420fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  /// RemoveDeadNodes - This method deletes the unreachable nodes in the
5430fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  /// given list, and any nodes that become unreachable as a result.
5440fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman  void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes,
5450fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman                       DAGUpdateListener *UpdateListener = 0);
5460fe9c6e7babb3c0731d9cb864ec498ec4184760fDan Gohman
5476542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
54826005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// This can cause recursive merging of nodes in the DAG.  Use the first
54926005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// version if 'From' is known to have a single result, use the second
55026005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// if you have two nodes with identical results, use the third otherwise.
5516542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  ///
552f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// These methods all take an optional UpdateListener, which (if not null) is
553f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// informed about nodes that are deleted and modified due to recursive
554f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// changes in the dag.
555fde3f3061d665babeb78443119a09876098fc35eChris Lattner  ///
556fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
557f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
558fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
559f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
5606d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  void ReplaceAllUsesWith(SDNode *From, const SDOperand *To,
561f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
562fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng
56380274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
564f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// uses of other values produced by From.Val alone.
56580274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
566f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                                 DAGUpdateListener *UpdateListener = 0);
56780274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner
568e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
569e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// their allnodes order. It returns the maximum id.
5707c16d776cb827922dd0f8f0a88c5b65a90810c0bEvan Cheng  unsigned AssignNodeIds();
571b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng
572e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
57309fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// based on their topological order. It returns the maximum id and a vector
57409fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// of the SDNodes* in assigned order by reference.
57509fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
576e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng
5771efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
5781efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// operation.
5791efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  static bool isCommutativeBinOp(unsigned Opcode) {
5804ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // FIXME: This should get its info from the td file, so that we can include
5814ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // target info.
5821efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    switch (Opcode) {
5831efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADD:
5841efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MUL:
5851efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHU:
5861efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHS:
587b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::SMUL_LOHI:
588b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::UMUL_LOHI:
5891efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FADD:
5901efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FMUL:
5911efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::AND:
5921efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::OR:
5931efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::XOR:
5941efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDC:
5951efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDE: return true;
5961efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    default: return false;
5971efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    }
5981efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  }
5991efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng
600cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  void dump() const;
601d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner
60237ce9df0da6cddc3b8bfef9b63d33d058a0f2f15Chris Lattner  /// CreateStackTemporary - Create a stack temporary, suitable for holding the
603364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang  /// specified value type.  If minAlign is specified, the slot size will have
604364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang  /// at least that alignment.
605364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang  SDOperand CreateStackTemporary(MVT VT, unsigned minAlign = 1);
606364d73ddab43b699ab90240f11b7a2eb5cf69bd8Mon P Wang
60751dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  /// FoldSetCC - Constant fold a setcc to true or false.
60883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand FoldSetCC(MVT VT, SDOperand N1,
60951dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner                      SDOperand N2, ISD::CondCode Cond);
61051dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner
6112e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// SignBitIsZero - Return true if the sign bit of Op is known to be zero.  We
6122e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// use this predicate to simplify operations downstream.
6132e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  bool SignBitIsZero(SDOperand Op, unsigned Depth = 0) const;
6142e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman
615ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
616ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// use this predicate to simplify operations downstream.  Op and Mask are
617ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be the same type.
6182e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  bool MaskedValueIsZero(SDOperand Op, const APInt &Mask, unsigned Depth = 0)
619ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman    const;
620ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
621ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
622ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be either zero or one and return them in the KnownZero/KnownOne
623ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
624ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// processing.  Targets can implement the computeMaskedBitsForTargetNode
625ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// method in the TargetLowering class to allow target nodes to be understood.
626977a76fbb6ea1b87dfd7fbbe2ae2afb63e982ff3Dan Gohman  void ComputeMaskedBits(SDOperand Op, const APInt &Mask, APInt &KnownZero,
627fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman                         APInt &KnownOne, unsigned Depth = 0) const;
628fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman
629ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeNumSignBits - Return the number of times the sign bit of the
630ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// register is replicated into the other bits.  We know that at least 1 bit
631ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// is always equal to the sign bit (itself), but other cases can give us
632ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// information.  For example, immediately after an "SRA X, 2", we know that
633ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// the top 3 bits are all equal to each other, so we return 3.  Targets can
634ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
635ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// class to allow target nodes to be understood.
636ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
637a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng
638a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  /// isVerifiedDebugInfoDesc - Returns true if the specified SDOperand has
639a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  /// been verified as a debug information descriptor.
640a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  bool isVerifiedDebugInfoDesc(SDOperand Op) const;
64177f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng
64277f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// getShuffleScalarElt - Returns the scalar element that will make up the ith
64377f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// element of the result of the vector shuffle.
64477f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  SDOperand getShuffleScalarElt(const SDNode *N, unsigned Idx);
645ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
646d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate:
6470e5f1306b059b62d7725f324e087efbc8e7a782dDan Gohman  inline alist_traits<SDNode, LargestSDNode>::AllocatorType &getAllocator();
6481b95095857b78e12138c22e76c7936611c51355bChris Lattner  void RemoveNodeFromCSEMaps(SDNode *N);
6496542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
650a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
651a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
652a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
6536d9cdd56173fb915a9e3a8f0f6b5a8ed9bed1098Dan Gohman  SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
654a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
655b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner
656fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void DeleteNodeNotInCSEMaps(SDNode *N);
6577cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
658109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  // List of non-single value types.
65983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  std::list<std::vector<MVT> > VTList;
660109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
6611cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner  // Maps to auto-CSE operations.
6627cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  std::vector<CondCodeSDNode*> CondCodeNodes;
6631cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner
66415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  std::vector<SDNode*> ValueTypeNodes;
6658e4eb09b1e3571965f49edcdfb56b1375b1b7551Duncan Sands  std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes;
6664b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman  StringMap<SDNode*> ExternalSymbols;
6674b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman  StringMap<SDNode*> TargetExternalSymbols;
668cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner};
669cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
6701080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
6711080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SelectionDAG::allnodes_iterator nodes_iterator;
6721080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_begin(SelectionDAG *G) {
6731080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_begin();
6741080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
6751080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_end(SelectionDAG *G) {
6761080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_end();
6771080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
6781080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
6791080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
680b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner}  // end namespace llvm
681cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
682cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif
683