SelectionDAG.h revision cd920d9ecfcefff13c3619a32b58399cac2e3630
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"
2043d1fd449f1a0ac9d9dafa0b9569bb6b2e976198Anton Korobeynikov#include "llvm/ADT/ilist.h"
21583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h"
22b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
23109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner#include <list>
245892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector>
25322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
26eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string>
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
28d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
29c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  class AliasAnalysis;
30c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetLowering;
31c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetMachine;
3244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  class MachineModuleInfo;
33c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class MachineFunction;
34d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  class MachineConstantPoolValue;
35ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  class FunctionLoweringInfo;
36c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
37c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function
38c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction
39c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection.  This DAG is constructed as the first step of instruction
40c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations
41c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications.
42c3aae25116e66c177579b0b79182b09340b19753Chris Lattner///
43c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent
44c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation,
45c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a
46c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form.
47cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner///
48cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG {
49063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &TLI;
50c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &MF;
51ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  FunctionLoweringInfo &FLI;
5244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *MMI;
53cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
54213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// Root - The root of the entire DAG.  EntryNode - The starting token.
55c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand Root, EntryNode;
56cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
57213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
58b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  ilist<SDNode> AllNodes;
59691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
60213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
61213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSE with existing nodes with a duplicate is requested.
62583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  FoldingSet<SDNode> CSEMap;
63213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
64cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
65ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  SelectionDAG(TargetLowering &tli, MachineFunction &mf,
66ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner               FunctionLoweringInfo &fli, MachineModuleInfo *mmi)
67ead0d88ad7659dabd66cc3149af97d98256fca84Chris Lattner  : TLI(tli), MF(mf), FLI(fli), MMI(mmi) {
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
102b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::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(); }
105b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::iterator allnodes_iterator;
106b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
107b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
108be20a88f534325f736830c94fc084c55b4aefdfdDan Gohman  ilist<SDNode>::size_type allnodes_size() const { return AllNodes.size(); }
109b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
110c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
111cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
112c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getRoot() const { return Root; }
113cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
114c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
115c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
116c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getEntryNode() const { return EntryNode; }
117cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
118c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
119cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
120c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &setRoot(SDOperand N) { return Root = N; }
121cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1221d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
1231d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// certain types of nodes together, or eliminating superfluous nodes.  When
1241d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// the AfterLegalize argument is set to 'true', Combine takes care not to
1251d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// generate any nodes that will be illegal on the target.
126c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  void Combine(bool AfterLegalize, AliasAnalysis &AA);
1271d4d41411190dd9e62764e56713753d4155764ddNate Begeman
12801d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
12901d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// only uses types natively supported by the target.
13001d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  ///
13101d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
13201d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// the graph.
13301d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  void LegalizeTypes();
13401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner
135c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
136c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
137c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
138cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
139c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
140c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
141063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  void Legalize();
142c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
143d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
144190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
145190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
146130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
147130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// DeleteNode - Remove the specified node from the system.  This node must
148130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// have no referrers.
149130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void DeleteNode(SDNode *N);
150130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
15170046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getVTList - Return an SDVTList that represents the list of values
15270046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// specified.
15383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT);
15483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2);
15583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3);
15683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDVTList getVTList(const MVT *VTs, unsigned NumVTs);
15770046e920fa37989a041af663ada2b2b646e258fChris Lattner
15870046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getNodeValueTypes - These are obsolete, use getVTList instead.
15983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT) {
16070046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT).VTs;
16170046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2) {
16370046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2).VTs;
16470046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) {
16670046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2, VT3).VTs;
16770046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  const MVT *getNodeValueTypes(std::vector<MVT> &vtList) {
16913d57320bd212483463d4f8992d5787b29eda5dfBill Wendling    return getVTList(&vtList[0], (unsigned)vtList.size()).VTs;
17070046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
17170046e920fa37989a041af663ada2b2b646e258fChris Lattner
17270046e920fa37989a041af663ada2b2b646e258fChris Lattner
1731b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
17470046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
17570046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
17683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstant(uint64_t Val, MVT VT, bool isTarget = false);
17783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstant(const APInt &Val, MVT VT, bool isTarget = false);
1780bd4893a0726889b942405262e53d06cf3fe3be8Chris Lattner  SDOperand getIntPtrConstant(uint64_t Val, bool isTarget = false);
17983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstant(uint64_t Val, MVT VT) {
180cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getConstant(Val, VT, true);
181cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
18283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstant(const APInt &Val, MVT VT) {
1836394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman    return getConstant(Val, VT, true);
1846394b099e836f56a937cdcc7332c9487b504ca68Dan Gohman  }
18583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantFP(double Val, MVT VT, bool isTarget = false);
18683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
18783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantFP(double Val, MVT VT) {
188c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
189c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
19083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantFP(const APFloat& Val, MVT VT) {
191f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen    return getConstantFP(Val, VT, true);
192f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  }
19383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getGlobalAddress(const GlobalValue *GV, MVT VT,
194cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                             int offset = 0, bool isTargetGA = false);
19583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
196cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                                   int offset = 0) {
197cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getGlobalAddress(GV, VT, offset, true);
198cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
19983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getFrameIndex(int FI, MVT VT, bool isTarget = false);
20083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetFrameIndex(int FI, MVT VT) {
201c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
202c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
20383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getJumpTable(int JTI, MVT VT, bool isTarget = false);
20483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetJumpTable(int JTI, MVT VT) {
205c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getJumpTable(JTI, VT, true);
206c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
20783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantPool(Constant *C, MVT VT,
208c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                            unsigned Align = 0, int Offs = 0, bool isT=false);
20983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetConstantPool(Constant *C, MVT VT,
210c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                                  unsigned Align = 0, int Offset = 0) {
211c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantPool(C, VT, Align, Offset, true);
212c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
21383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getConstantPool(MachineConstantPoolValue *C, MVT VT,
214d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                            unsigned Align = 0, int Offs = 0, bool isT=false);
215d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
21683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                                  MVT VT, unsigned Align = 0,
217d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  int Offset = 0) {
218d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return getConstantPool(C, VT, Align, Offset, true);
219d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
220c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getBasicBlock(MachineBasicBlock *MBB);
22183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getExternalSymbol(const char *Sym, MVT VT);
22283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getTargetExternalSymbol(const char *Sym, MVT VT);
223276dcbdc8db6614cfd5004dc7dc35e437ddf9c58Duncan Sands  SDOperand getArgFlags(ISD::ArgFlagsTy Flags);
22483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getValueType(MVT);
22583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getRegister(unsigned Reg, MVT VT);
2267f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman  SDOperand getDbgStopPoint(SDOperand Root, unsigned Line, unsigned Col,
2277f460203b0c5350e9b2c592f438e40f7a7de6e45Dan Gohman                            const CompileUnitDesc *CU);
2284406604047423576e36657c7ede266ca42e79642Dan Gohman  SDOperand getLabel(unsigned Opcode, SDOperand Root, unsigned LabelID);
229c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
230d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
231d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return getNode(ISD::CopyToReg, MVT::Other, Chain,
232d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner                   getRegister(Reg, N.getValueType()), N);
233cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  }
234cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
235e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
236e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
237e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
238e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
239e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                         SDOperand Flag) {
24083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
241bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
2422fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
243e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
24466a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
24566a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  // Similar to last getCopyToReg() except parameter Reg is a SDOperand
24666a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
24766a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng                         SDOperand Flag) {
24883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
249bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, Reg, N, Flag };
2502fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
25166a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  }
252e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
25383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT) {
25483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other);
255f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
2562fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
25718c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner  }
258e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
259e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
260e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
261e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
26283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT,
263e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                           SDOperand Flag) {
26483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
265f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
2662fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
267e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
26818c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
2697cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getCondCode(ISD::CondCode Cond);
270cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
2711ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
2721ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
27383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getZeroExtendInReg(SDOperand Op, MVT SrcTy);
2746a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner
2756a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
2766a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// a flag result (to ensure it's not CSE'd).
2776a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
27883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands    const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
279f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain,  Op };
2802fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
2816a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
2821ccae666f596d5aeca5c9942995763600b622062Chris Lattner
2830f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
2840f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  /// flag result (to ensure it's not CSE'd).
2850f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  SDOperand getCALLSEQ_END(SDOperand Chain, SDOperand Op1, SDOperand Op2,
2860f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling                           SDOperand InFlag) {
2870f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
2880f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    SmallVector<SDOperand, 4> Ops;
2890f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Chain);
2900f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op1);
2910f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(Op2);
2920f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    Ops.push_back(InFlag);
2930f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling    return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0],
29434cd4a484e532cc463fd5a4bf59b88d13c5467c1Evan Cheng                   (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0));
2950f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling  }
2960f8d9c04d9feef86cee35cf5fecfb348a6b3de50Bill Wendling
297c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
298cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
29983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT);
30083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N);
30183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N1, SDOperand N2);
30283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
303c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3);
30483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
3052d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
30683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT,
307f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
308f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N5);
30983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, MVT VT, SDOperandPtr Ops, unsigned NumOps);
31083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, std::vector<MVT> &ResultTys,
3119cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                    SDOperandPtr Ops, unsigned NumOps);
31283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs,
3139cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                    SDOperandPtr Ops, unsigned NumOps);
31408ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs);
31508ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N);
31683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N1, SDOperand N2);
31708ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
31808ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3);
31908ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
32008ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
32108ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
32208ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
32308ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N5);
32467bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner  SDOperand getNode(unsigned Opcode, SDVTList VTs,
3259cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                    SDOperandPtr Ops, unsigned NumOps);
3265c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
327707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemcpy(SDOperand Chain, SDOperand Dst, SDOperand Src,
328707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      SDOperand Size, unsigned Align,
329707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      bool AlwaysInline,
3301f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff,
3311f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *SrcSV, uint64_t SrcSVOff);
3325c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
333707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemmove(SDOperand Chain, SDOperand Dst, SDOperand Src,
33455888274f21fc1a760679a51591a209758db8cbfDan Gohman                       SDOperand Size, unsigned Align,
3351f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *DstSV, uint64_t DstOSVff,
3361f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                       const Value *SrcSV, uint64_t SrcSVOff);
3375c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
338707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman  SDOperand getMemset(SDOperand Chain, SDOperand Dst, SDOperand Src,
339707e0184233f27e0e9f9aee0309f2daab8cfe7f8Dan Gohman                      SDOperand Size, unsigned Align,
3401f13c686df75ddbbe15b208606ece4846d7479a8Dan Gohman                      const Value *DstSV, uint64_t DstSVOff);
3415c0d6ed325417baa5d119af9c2b6790231d8565fRafael Espindola
3427cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// getSetCC - Helper function to make it easier to build SetCC's if you just
3437cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// have an ISD::CondCode instead of an SDOperand.
3447cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ///
34583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
3467cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner                     ISD::CondCode Cond) {
3477cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
348b43e9c196542acc80c9e4643809661065710848fNate Begeman  }
349b43e9c196542acc80c9e4643809661065710848fNate Begeman
350b43e9c196542acc80c9e4643809661065710848fNate Begeman  /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
351b43e9c196542acc80c9e4643809661065710848fNate Begeman  /// if you just have an ISD::CondCode instead of an SDOperand.
352b43e9c196542acc80c9e4643809661065710848fNate Begeman  ///
35383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getVSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
354b43e9c196542acc80c9e4643809661065710848fNate Begeman                      ISD::CondCode Cond) {
355b43e9c196542acc80c9e4643809661065710848fNate Begeman    return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond));
3567cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  }
3579373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
3589373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
3599373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// just have an ISD::CondCode instead of an SDOperand.
3609373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  ///
3619373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
3629373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman                        SDOperand True, SDOperand False, ISD::CondCode Cond) {
3632fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
3642fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                   getCondCode(Cond));
3659373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  }
3667cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
367acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
368acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// and a source value as input.
36983ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getVAArg(MVT VT, SDOperand Chain, SDOperand Ptr,
370acc398c195a697795bff3245943d104eb19192b9Nate Begeman                     SDOperand SV);
3717cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
372ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
37328873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang  /// 3 operands
374ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
375fd4418fc9b4725c44210c169c4d6500be468ca70Dan Gohman                      SDOperand Cmp, SDOperand Swp, const Value* PtrVal,
37628873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment=0);
377ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
378ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
37928873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang  /// 2 operands
380ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth  SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
381fd4418fc9b4725c44210c169c4d6500be468ca70Dan Gohman                      SDOperand Val, const Value* PtrVal,
38228873106309db515d58889a4c4fa3e0a92d1b60eMon P Wang                      unsigned Alignment = 0);
383ab0b949e0e9de452f3b052b11634ab761e008b23Andrew Lenharth
3844bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given operands.
3854bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
3864bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  SDOperand getMergeValues(SDOperandPtr Ops, unsigned NumOps,
3874bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands                           bool Simplify = true);
3884bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands
389f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// getMergeValues - Create a MERGE_VALUES node from the given types and ops.
390f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  /// Allowed to return something different (and simpler) if Simplify is true.
3914bdcb61af33399d4e01fdf3c47ca1f1f5356e370Duncan Sands  /// May be faster than the above version if VTs is known and NumOps is large.
392f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  SDOperand getMergeValues(SDVTList VTs, SDOperandPtr Ops, unsigned NumOps,
393f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands                           bool Simplify = true) {
394f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    if (Simplify && NumOps == 1)
395f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands      return Ops[0];
396f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands    return getNode(ISD::MERGE_VALUES, VTs, Ops, NumOps);
397f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands  }
398f9516208e57364ab1e7d8748af1f59a2ea5fb572Duncan Sands
399c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getLoad - Loads are not normal binary operators: their result type is not
400c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// determined by their operands, and they produce a value AND a token chain.
401cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
40283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getLoad(MVT VT, SDOperand Chain, SDOperand Ptr,
40395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    const Value *SV, int SVOffset, bool isVolatile=false,
40495c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    unsigned Alignment=0);
40583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT VT,
40624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                       SDOperand Chain, SDOperand Ptr, const Value *SV,
40783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       int SVOffset, MVT EVT, bool isVolatile=false,
40895c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                       unsigned Alignment=0);
4098862ef148100070b7bf28beead3951464250c926Evan Cheng  SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
410144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
411e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands  SDOperand getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
41283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                    MVT VT, SDOperand Chain,
413e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands                    SDOperand Ptr, SDOperand Offset,
41483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                    const Value *SV, int SVOffset, MVT EVT,
415e10efce22502d1a1855d25baf1458660f4ba6f33Duncan Sands                    bool isVolatile=false, unsigned Alignment=0);
4162d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
417ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  /// getStore - Helper function to build ISD::STORE nodes.
418ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  ///
419d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
42095c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     const Value *SV, int SVOffset, bool isVolatile=false,
42195c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     unsigned Alignment=0);
422d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
42383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                          const Value *SV, int SVOffset, MVT TVT,
42495c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                          bool isVolatile=false, unsigned Alignment=0);
4259109fb1eb7d3341727353777c2a4282aa1a0c39aEvan Cheng  SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
426144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
427ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng
42869de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getSrcValue - Construct a node to track a Value* through the backend.
42969de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  SDOperand getSrcValue(const Value *v);
43069de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman
43169de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // getMemOperand - Construct a node to track a memory reference
43269de1932b350d7cdfc0ed1f4198d6f78c7822a02Dan Gohman  // through the backend.
43336b5c1338a03453ba1c110b120269ca972fb65a3Dan Gohman  SDOperand getMemOperand(const MachineMemOperand &MO);
434cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
435b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
436b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// specified operands.  If the resultant node already exists in the DAG,
437b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// this does not modify the specified node, instead it returns the node that
438b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// already exists.  If the resultant node does not exist in the DAG, the
439b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input node is returned.  As a degenerate case, if you specify the same
440b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input operands as the node already has, the input node is returned.
441b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
442b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
443b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
444b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3);
445b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
446b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3, SDOperand Op4);
4479b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
4489b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner                               SDOperand Op3, SDOperand Op4, SDOperand Op5);
4499cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDOperand UpdateNodeOperands(SDOperand N, SDOperandPtr Ops, unsigned NumOps);
4501b95095857b78e12138c22e76c7936611c51355bChris Lattner
4511b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// SelectNodeTo - These are used for target selectors to *mutate* the
4521b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// specified node to have the specified return type, Target opcode, and
4531b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// operands.  Note that target opcodes are stored as
454eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field.  The 0th value
455eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// of the resultant node is returned.
45683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT);
45783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDOperand Op1);
45883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
45995514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2);
46083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
46195514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2, SDOperand Op3);
46283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
4639cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                       SDOperandPtr Ops, unsigned NumOps);
464cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1, MVT VT2);
465cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
466cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman                       MVT VT2, SDOperandPtr Ops, unsigned NumOps);
467cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
468cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman                       MVT VT2, MVT VT3, SDOperandPtr Ops, unsigned NumOps);
469cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
470cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman                       MVT VT2, SDOperand Op1);
47183ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
47283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       MVT VT2, SDOperand Op1, SDOperand Op2);
47383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
47483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                       MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
475cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
476cd920d9ecfcefff13c3619a32b58399cac2e3630Dan Gohman                       SDOperandPtr Ops, unsigned NumOps);
477694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng
478753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner
4796ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// getTargetNode - These are used for target selectors to create a new node
4806ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// with specified return type(s), target opcode, and operands.
4816ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  ///
4826ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// Note that getTargetNode returns the resultant node.  If there is already a
4836ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// node of the specified opcode and operands, it returns that node instead of
4846ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// the current one.
48583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT);
48683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1);
48783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1, SDOperand Op2);
48883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
4896ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
49083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT,
4919cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                        SDOperandPtr Ops, unsigned NumOps);
49283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2);
49383ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDOperand Op1);
49483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
49583ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                        MVT VT2, SDOperand Op1, SDOperand Op2);
49683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1,
49783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands                        MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
49883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2,
4999cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                        SDOperandPtr Ops, unsigned NumOps);
50083ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
5016ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
50283ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
503b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
50483ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
5059cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                        SDOperandPtr Ops, unsigned NumOps);
50683ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4,
5079cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                        SDOperandPtr Ops, unsigned NumOps);
50883ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDNode *getTargetNode(unsigned Opcode, std::vector<MVT> &ResultTys,
5099cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                        SDOperandPtr Ops, unsigned NumOps);
51008b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng
51108b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// getNodeIfExists - Get the specified node if it's already available, or
51208b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  /// else return NULL.
51308b1173971a51eb89d7d6ee0992c39170c86994aEvan Cheng  SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
5149cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein                          SDOperandPtr Ops, unsigned NumOps);
5156542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner
516f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// DAGUpdateListener - Clients of various APIs that cause global effects on
517f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// the DAG can optionally implement this interface.  This allows the clients
518f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// to handle the various sorts of updates that happen.
519f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  class DAGUpdateListener {
520f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  public:
521f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual ~DAGUpdateListener();
522edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
523edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeDeleted - The node N that was deleted and, if E is not null, an
524edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// equivalent node E that replaced it.
525edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
526edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands
527edfcf598faab9ce294712551ecf67093acd1c66eDuncan Sands    /// NodeUpdated - The node N that was updated.
528f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner    virtual void NodeUpdated(SDNode *N) = 0;
529f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  };
530f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
531f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// RemoveDeadNode - Remove the specified node from the system. If any of its
532f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// operands then becomes dead, remove them as well. Inform UpdateListener
533f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// for each node deleted.
534f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
535f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner
5366542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
53726005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// This can cause recursive merging of nodes in the DAG.  Use the first
53826005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// version if 'From' is known to have a single result, use the second
53926005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// if you have two nodes with identical results, use the third otherwise.
5406542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  ///
541f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// These methods all take an optional UpdateListener, which (if not null) is
542f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// informed about nodes that are deleted and modified due to recursive
543f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// changes in the dag.
544fde3f3061d665babeb78443119a09876098fc35eChris Lattner  ///
545fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
546f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
547fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
548f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
5499cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  void ReplaceAllUsesWith(SDNode *From, SDOperandPtr To,
550f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                          DAGUpdateListener *UpdateListener = 0);
551fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng
55280274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
553f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner  /// uses of other values produced by From.Val alone.
55480274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
555f8dc0617baceeba8ccd67c8881eb88eb1be2902cChris Lattner                                 DAGUpdateListener *UpdateListener = 0);
55680274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner
557e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
558e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// their allnodes order. It returns the maximum id.
5597c16d776cb827922dd0f8f0a88c5b65a90810c0bEvan Cheng  unsigned AssignNodeIds();
560b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng
561e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
56209fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// based on their topological order. It returns the maximum id and a vector
56309fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// of the SDNodes* in assigned order by reference.
56409fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
565e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng
5661efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
5671efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// operation.
5681efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  static bool isCommutativeBinOp(unsigned Opcode) {
5694ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // FIXME: This should get its info from the td file, so that we can include
5704ae9e0c5301126d7f2d4b2975eb86ed21f7b574dChris Lattner    // target info.
5711efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    switch (Opcode) {
5721efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADD:
5731efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MUL:
5741efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHU:
5751efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHS:
576b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::SMUL_LOHI:
577b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::UMUL_LOHI:
5781efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FADD:
5791efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FMUL:
5801efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::AND:
5811efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::OR:
5821efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::XOR:
5831efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDC:
5841efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDE: return true;
5851efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    default: return false;
5861efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    }
5871efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  }
5881efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng
589cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  void dump() const;
590d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner
59137ce9df0da6cddc3b8bfef9b63d33d058a0f2f15Chris Lattner  /// CreateStackTemporary - Create a stack temporary, suitable for holding the
592bee98c66c0c3d1f43244cdf237e572a9df031e40Mon P Wang  /// specified value type.  If minAlign is specified, the slot size will have
593bee98c66c0c3d1f43244cdf237e572a9df031e40Mon P Wang  /// at least that alignment.
5946ed2d1ecdbac0fe9c34cfc6ab5c985dc0c71a1d7Mon P Wang  SDOperand CreateStackTemporary(MVT VT, unsigned minAlign = 1);
595bee98c66c0c3d1f43244cdf237e572a9df031e40Mon P Wang
59651dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  /// FoldSetCC - Constant fold a setcc to true or false.
59783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  SDOperand FoldSetCC(MVT VT, SDOperand N1,
59851dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner                      SDOperand N2, ISD::CondCode Cond);
59951dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner
6002e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// SignBitIsZero - Return true if the sign bit of Op is known to be zero.  We
6012e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  /// use this predicate to simplify operations downstream.
6022e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  bool SignBitIsZero(SDOperand Op, unsigned Depth = 0) const;
6032e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman
604ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
605ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// use this predicate to simplify operations downstream.  Op and Mask are
606ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be the same type.
6072e68b6f52d0979575b2f02ed29717d907ba0684cDan Gohman  bool MaskedValueIsZero(SDOperand Op, const APInt &Mask, unsigned Depth = 0)
608ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman    const;
609ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
610ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
611ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be either zero or one and return them in the KnownZero/KnownOne
612ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
613ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// processing.  Targets can implement the computeMaskedBitsForTargetNode
614ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// method in the TargetLowering class to allow target nodes to be understood.
615977a76fbb6ea1b87dfd7fbbe2ae2afb63e982ff3Dan Gohman  void ComputeMaskedBits(SDOperand Op, const APInt &Mask, APInt &KnownZero,
616fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman                         APInt &KnownOne, unsigned Depth = 0) const;
617fd29e0eb060ea8b4d490860329234d2ae5f5952eDan Gohman
618ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeNumSignBits - Return the number of times the sign bit of the
619ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// register is replicated into the other bits.  We know that at least 1 bit
620ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// is always equal to the sign bit (itself), but other cases can give us
621ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// information.  For example, immediately after an "SRA X, 2", we know that
622ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// the top 3 bits are all equal to each other, so we return 3.  Targets can
623ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
624ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// class to allow target nodes to be understood.
625ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
626a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng
627a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  /// isVerifiedDebugInfoDesc - Returns true if the specified SDOperand has
628a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  /// been verified as a debug information descriptor.
629a844bdeab31ef04221e7ef59a8467893584cc14dEvan Cheng  bool isVerifiedDebugInfoDesc(SDOperand Op) const;
63077f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng
63177f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// getShuffleScalarElt - Returns the scalar element that will make up the ith
63277f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  /// element of the result of the vector shuffle.
63377f0b7a50a08614b5ffd58f1864b68a9a30d0cb0Evan Cheng  SDOperand getShuffleScalarElt(const SDNode *N, unsigned Idx);
634ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
635d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate:
6361b95095857b78e12138c22e76c7936611c51355bChris Lattner  void RemoveNodeFromCSEMaps(SDNode *N);
6376542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
638a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
639a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
640a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
6419cac5259fe237120a0c347d6d14e549005148f1bRoman Levenstein  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperandPtr Ops, unsigned NumOps,
642a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
643b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner
644fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void DeleteNodeNotInCSEMaps(SDNode *N);
6457cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
646109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  // List of non-single value types.
64783ec4b6711980242ef3c55a4fa36b2d7a39c1bfbDuncan Sands  std::list<std::vector<MVT> > VTList;
648109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
6491cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner  // Maps to auto-CSE operations.
6507cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  std::vector<CondCodeSDNode*> CondCodeNodes;
6511cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner
65215e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  std::vector<SDNode*> ValueTypeNodes;
6538e4eb09b1e3571965f49edcdfb56b1375b1b7551Duncan Sands  std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes;
6544b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman  StringMap<SDNode*> ExternalSymbols;
6554b84086e89d86fb16f562166d9fea8df37db6be7Dan Gohman  StringMap<SDNode*> TargetExternalSymbols;
656cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner};
657cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
6581080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
6591080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SelectionDAG::allnodes_iterator nodes_iterator;
6601080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_begin(SelectionDAG *G) {
6611080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_begin();
6621080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
6631080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_end(SelectionDAG *G) {
6641080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_end();
6651080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
6661080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
6671080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
668b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner}  // end namespace llvm
669cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
670cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif
671