SelectionDAG.h revision 01d029b82cb08367d81aa10cdc94d05360466649
1c3aae25116e66c177579b0b79182b09340b19753Chris Lattner//===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
2ea61c358720aa6c7a159d51658b34276316aa841Misha Brukman//
36fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//                     The LLVM Compiler Infrastructure
46fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell//
56fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// This file was developed by the LLVM research group and is distributed under
66fbcc26f1460eaee4e0eb8b426fc1ff0c7af11beJohn Criswell// the University of Illinois Open Source 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"
19b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner#include "llvm/ADT/ilist"
20583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey#include "llvm/CodeGen/SelectionDAGNodes.h"
21b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
22109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner#include <list>
235892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector>
24322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
25322812e603705e1c2037313633e72f689524b163Evan Cheng#include <set>
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;
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;
5044c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *MMI;
51cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
52213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// Root - The root of the entire DAG.  EntryNode - The starting token.
53c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand Root, EntryNode;
54cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
55213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
56b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  ilist<SDNode> AllNodes;
57691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
58213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
59213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSE with existing nodes with a duplicate is requested.
60583bd47f777fe3eb8305872fa0eadab31e833dffJim Laskey  FoldingSet<SDNode> CSEMap;
61213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
62cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
6344c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  SelectionDAG(TargetLowering &tli, MachineFunction &mf, MachineModuleInfo *mmi)
6444c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  : TLI(tli), MF(mf), MMI(mmi) {
65c3aae25116e66c177579b0b79182b09340b19753Chris Lattner    EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
66c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  }
67cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ~SelectionDAG();
68cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
69c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &getMachineFunction() const { return MF; }
70063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  const TargetMachine &getTarget() const;
71063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &getTargetLoweringInfo() const { return TLI; }
7244c3b9fdd416c79f4b67cde1aecfced5921efd81Jim Laskey  MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
73cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
74ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
751080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  ///
761080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  void viewGraph();
77ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
78ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG
79ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  std::map<const SDNode *, std::string> NodeGraphAttrs;
80ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif
811080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
82ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// clearGraphAttrs - Clear all previously defined node graph attributes.
83ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Intended to be used from a debugging tool (eg. gdb).
84ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void clearGraphAttrs();
85ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
86ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
87ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
88ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphAttrs(const SDNode *N, const char *Attrs);
89ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
90ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
91ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Used from getNodeAttributes.
92ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  const std::string getGraphAttrs(const SDNode *N) const;
93ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
94ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphColor - Convenience for setting node color attribute.
95ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
96ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphColor(const SDNode *N, const char *Color);
971080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
98b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
99b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
100b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
101b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::iterator allnodes_iterator;
102b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
103b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
104b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
105c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
106cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
107c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getRoot() const { return Root; }
108cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
109c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
110c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
111c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getEntryNode() const { return EntryNode; }
112cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
113c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
114cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
115c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &setRoot(SDOperand N) { return Root = N; }
116cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1171d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
1181d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// certain types of nodes together, or eliminating superfluous nodes.  When
1191d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// the AfterLegalize argument is set to 'true', Combine takes care not to
1201d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// generate any nodes that will be illegal on the target.
121c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  void Combine(bool AfterLegalize, AliasAnalysis &AA);
1221d4d41411190dd9e62764e56713753d4155764ddNate Begeman
12301d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
12401d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// only uses types natively supported by the target.
12501d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  ///
12601d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
12701d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  /// the graph.
12801d029b82cb08367d81aa10cdc94d05360466649Chris Lattner  void LegalizeTypes();
12901d029b82cb08367d81aa10cdc94d05360466649Chris Lattner
130c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
131c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
132c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
133cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
134c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
135c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
136063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  void Legalize();
137c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
138d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
139190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
140190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
141130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
142130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// RemoveDeadNode - Remove the specified node from the system. If any of its
143130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// operands then becomes dead, remove them as well. The vector Deleted is
144130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// populated with nodes that are deleted.
145130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void RemoveDeadNode(SDNode *N, std::vector<SDNode*> &Deleted);
14670046e920fa37989a041af663ada2b2b646e258fChris Lattner
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.
15370046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT);
15470046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2);
15570046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2,MVT::ValueType VT3);
15670046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(const MVT::ValueType *VTs, unsigned NumVTs);
15770046e920fa37989a041af663ada2b2b646e258fChris Lattner
15870046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getNodeValueTypes - These are obsolete, use getVTList instead.
15970046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT) {
16070046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT).VTs;
16170046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16270046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,
16370046e920fa37989a041af663ada2b2b646e258fChris Lattner                                          MVT::ValueType VT2) {
16470046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2).VTs;
16570046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16670046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,MVT::ValueType VT2,
16770046e920fa37989a041af663ada2b2b646e258fChris Lattner                                          MVT::ValueType VT3) {
16870046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2, VT3).VTs;
16970046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
17070046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(std::vector<MVT::ValueType> &VTList) {
17170046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(&VTList[0], VTList.size()).VTs;
17270046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
17370046e920fa37989a041af663ada2b2b646e258fChris Lattner
17470046e920fa37989a041af663ada2b2b646e258fChris Lattner
1751b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
17670046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
17770046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
17847725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  SDOperand getString(const std::string &Val);
179cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  SDOperand getConstant(uint64_t Val, MVT::ValueType VT, bool isTarget = false);
180cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT) {
181cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getConstant(Val, VT, true);
182cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
183c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getConstantFP(double Val, MVT::ValueType VT, bool isTarget = false);
184f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  SDOperand getConstantFP(const APFloat& Val, MVT::ValueType VT,
185f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen                          bool isTarget = false);
186c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetConstantFP(double Val, MVT::ValueType VT) {
187c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
188c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
189f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  SDOperand getTargetConstantFP(const APFloat& Val, MVT::ValueType VT) {
190f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen    return getConstantFP(Val, VT, true);
191f04afdbb48568ef09f11fd10ac03426101f2dbf8Dale Johannesen  }
19214229bb6369c110644c11bc7906b0c1167d3a87aEvan Cheng  SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
193cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                             int offset = 0, bool isTargetGA = false);
19461ca74bc3a29b2af2be7e4bd612289da8aae85b5Evan Cheng  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
195cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                                   int offset = 0) {
196cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getGlobalAddress(GV, VT, offset, true);
197cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
198c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getFrameIndex(int FI, MVT::ValueType VT, bool isTarget = false);
199c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT) {
200c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
201c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
202c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getJumpTable(int JTI, MVT::ValueType VT, bool isTarget = false);
203c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT) {
204c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getJumpTable(JTI, VT, true);
205c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
206b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
207c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                            unsigned Align = 0, int Offs = 0, bool isT=false);
208b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
209c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                                  unsigned Align = 0, int Offset = 0) {
210c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantPool(C, VT, Align, Offset, true);
211c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
212d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getConstantPool(MachineConstantPoolValue *C, MVT::ValueType VT,
213d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                            unsigned Align = 0, int Offs = 0, bool isT=false);
214d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
215d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  MVT::ValueType VT, unsigned Align = 0,
216d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  int Offset = 0) {
217d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return getConstantPool(C, VT, Align, Offset, true);
218d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
219c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getBasicBlock(MachineBasicBlock *MBB);
220c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
2212a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth  SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
22215e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  SDOperand getValueType(MVT::ValueType);
223d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getRegister(unsigned Reg, MVT::ValueType VT);
224c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
225d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
226d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return getNode(ISD::CopyToReg, MVT::Other, Chain,
227d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner                   getRegister(Reg, N.getValueType()), N);
228cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  }
229cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
230e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
231e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
232e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
233e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
234e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                         SDOperand Flag) {
2352fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
236bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
2372fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
238e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
23966a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
24066a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  // Similar to last getCopyToReg() except parameter Reg is a SDOperand
24166a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
24266a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng                         SDOperand Flag) {
2432fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
244bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, Reg, N, Flag };
2452fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
24666a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  }
247e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
248d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT) {
2492fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other);
250f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
2512fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
25218c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner  }
253e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
254e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
255e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
256e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
257e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT,
258e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                           SDOperand Flag) {
2592fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
260f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
2612fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
262e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
26318c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
2647cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getCondCode(ISD::CondCode Cond);
265cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
2661ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
2671ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
2681ccae666f596d5aeca5c9942995763600b622062Chris Lattner  SDOperand getZeroExtendInReg(SDOperand Op, MVT::ValueType SrcTy);
2696a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner
2706a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
2716a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// a flag result (to ensure it's not CSE'd).
2726a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
2732fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
274f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain,  Op };
2752fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
2766a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
2771ccae666f596d5aeca5c9942995763600b622062Chris Lattner
278c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
279cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
280c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT);
281c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N);
282c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
283c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2);
284c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
285c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3);
286c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
2872d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
2882d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
289f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
290f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N5);
291f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
292f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
293f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
294f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
2952fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner  SDOperand getNode(unsigned Opcode, const MVT::ValueType *VTs, unsigned NumVTs,
2962fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
29708ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs);
29808ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N);
29908ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
30008ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2);
30108ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
30208ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3);
30308ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
30408ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
30508ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman  SDOperand getNode(unsigned Opcode, SDVTList VTs,
30608ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
30708ce9769718354e6767d3815e4c255e7c9fc0a46Dan Gohman                    SDOperand N5);
30867bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner  SDOperand getNode(unsigned Opcode, SDVTList VTs,
30967bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
310f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner
3117cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// getSetCC - Helper function to make it easier to build SetCC's if you just
3127cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// have an ISD::CondCode instead of an SDOperand.
3137cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ///
3147cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getSetCC(MVT::ValueType VT, SDOperand LHS, SDOperand RHS,
3157cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner                     ISD::CondCode Cond) {
3167cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
3177cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  }
3189373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
3199373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
3209373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// just have an ISD::CondCode instead of an SDOperand.
3219373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  ///
3229373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
3239373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman                        SDOperand True, SDOperand False, ISD::CondCode Cond) {
3242fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
3252fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                   getCondCode(Cond));
3269373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  }
3277cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
328acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
329acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// and a source value as input.
330acc398c195a697795bff3245943d104eb19192b9Nate Begeman  SDOperand getVAArg(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
331acc398c195a697795bff3245943d104eb19192b9Nate Begeman                     SDOperand SV);
3327cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
333c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getLoad - Loads are not normal binary operators: their result type is not
334c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// determined by their operands, and they produce a value AND a token chain.
335cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
33621074f43ed5165828717ea3606eb2bd222a39b26Chris Lattner  SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
33795c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    const Value *SV, int SVOffset, bool isVolatile=false,
33895c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                    unsigned Alignment=0);
33924446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
34024446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                       SDOperand Chain, SDOperand Ptr, const Value *SV,
34195c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                       int SVOffset, MVT::ValueType EVT, bool isVolatile=false,
34295c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                       unsigned Alignment=0);
3438862ef148100070b7bf28beead3951464250c926Evan Cheng  SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
344144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
3452d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
346ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  /// getStore - Helper function to build ISD::STORE nodes.
347ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  ///
348d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
34995c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     const Value *SV, int SVOffset, bool isVolatile=false,
35095c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                     unsigned Alignment=0);
351d41b30def3181bce4bf87e8bde664d15663165d0Jeff Cohen  SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
3528b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng                          const Value *SV, int SVOffset, MVT::ValueType TVT,
35395c218a83ecf77590b9dc40c636720772d2b5cd7Christopher Lamb                          bool isVolatile=false, unsigned Alignment=0);
3549109fb1eb7d3341727353777c2a4282aa1a0c39aEvan Cheng  SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
355144d8f09e139f691cafadbc17873943ba4c465f3Evan Cheng                           SDOperand Offset, ISD::MemIndexedMode AM);
356ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng
3572d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  // getSrcValue - construct a node to track a Value* through the backend
358691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth  SDOperand getSrcValue(const Value* I, int offset = 0);
359cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
360b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
361b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// specified operands.  If the resultant node already exists in the DAG,
362b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// this does not modify the specified node, instead it returns the node that
363b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// already exists.  If the resultant node does not exist in the DAG, the
364b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input node is returned.  As a degenerate case, if you specify the same
365b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input operands as the node already has, the input node is returned.
366b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
367b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
368b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
369b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3);
370b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
371b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3, SDOperand Op4);
3729b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
3739b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner                               SDOperand Op3, SDOperand Op4, SDOperand Op5);
374f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand *Ops, unsigned NumOps);
3751b95095857b78e12138c22e76c7936611c51355bChris Lattner
3761b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// SelectNodeTo - These are used for target selectors to *mutate* the
3771b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// specified node to have the specified return type, Target opcode, and
3781b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// operands.  Note that target opcodes are stored as
379eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field.  The 0th value
380eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// of the resultant node is returned.
38195514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT);
38295514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
38395514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1);
38495514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
38595514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2);
38695514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
38795514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2, SDOperand Op3);
388694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
389694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        const SDOperand *Ops, unsigned NumOps);
39095514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
39195514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
39295514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
39395514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
39495514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op3);
395694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng
396753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner
3976ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// getTargetNode - These are used for target selectors to create a new node
3986ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// with specified return type(s), target opcode, and operands.
3996ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  ///
4006ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// Note that getTargetNode returns the resultant node.  If there is already a
4016ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// node of the specified opcode and operands, it returns that node instead of
4026ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// the current one.
4036ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT);
4046ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
4056ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1);
4066ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
4076ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
4086ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
4096ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
4106ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
411bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner                        const SDOperand *Ops, unsigned NumOps);
4126ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
4136eaeff29b8a6990107735f7e5f5e49da38f56223Dale Johannesen                        MVT::ValueType VT2);
4146eaeff29b8a6990107735f7e5f5e49da38f56223Dale Johannesen  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
4156ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1);
4166ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
4176ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
4186ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
4196ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
4206ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op3);
421694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
422694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        MVT::ValueType VT2,
423694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        const SDOperand *Ops, unsigned NumOps);
4246ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
4256ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, MVT::ValueType VT3,
4266ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
427b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
428b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio                        MVT::ValueType VT2, MVT::ValueType VT3,
429b3a0417cad8b625acc3033bd5e24afb9ffd0b084Lauro Ramos Venancio                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
4306ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
431694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        MVT::ValueType VT2, MVT::ValueType VT3,
432bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner                        const SDOperand *Ops, unsigned NumOps);
43305e69c1f23f1097530fcbc7be97f99d696c019a2Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
43405e69c1f23f1097530fcbc7be97f99d696c019a2Evan Cheng                        MVT::ValueType VT2, MVT::ValueType VT3,
43505e69c1f23f1097530fcbc7be97f99d696c019a2Evan Cheng                        MVT::ValueType VT4,
43605e69c1f23f1097530fcbc7be97f99d696c019a2Evan Cheng                        const SDOperand *Ops, unsigned NumOps);
43739305cf55363046162c5a992f96f26d607a204e5Evan Cheng  SDNode *getTargetNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
43839305cf55363046162c5a992f96f26d607a204e5Evan Cheng                        const SDOperand *Ops, unsigned NumOps);
4396542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner
4406542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
44126005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// This can cause recursive merging of nodes in the DAG.  Use the first
44226005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// version if 'From' is known to have a single result, use the second
44326005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// if you have two nodes with identical results, use the third otherwise.
4446542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  ///
445fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// These methods all take an optional vector, which (if not null) is
446fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// populated with any nodes that are deleted from the SelectionDAG, due to
447fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// new equivalences that are discovered.
448fde3f3061d665babeb78443119a09876098fc35eChris Lattner  ///
449fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
450fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
451fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
452fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
4538a842cf8287ee957e15b95ceeb6ee5f189caba3dChris Lattner  void ReplaceAllUsesWith(SDNode *From, const SDOperand *To,
454fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
455fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng
45680274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
45780274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// uses of other values produced by From.Val alone.  The Deleted vector is
45880274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// handled the same was as for ReplaceAllUsesWith, but it is required for
45980274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// this method.
46080274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
46101d029b82cb08367d81aa10cdc94d05360466649Chris Lattner                                 std::vector<SDNode*> *Deleted = 0);
46280274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner
463e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
464e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// their allnodes order. It returns the maximum id.
4657c16d776cb827922dd0f8f0a88c5b65a90810c0bEvan Cheng  unsigned AssignNodeIds();
466b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng
467e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
46809fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// based on their topological order. It returns the maximum id and a vector
46909fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// of the SDNodes* in assigned order by reference.
47009fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
471e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng
4721efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
4731efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// operation.
4741efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  static bool isCommutativeBinOp(unsigned Opcode) {
4751efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    switch (Opcode) {
4761efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADD:
4771efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MUL:
4781efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHU:
4791efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHS:
480b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::SMUL_LOHI:
481b6c7437568f0472548ede2710458f52cfad4532eDan Gohman    case ISD::UMUL_LOHI:
4821efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FADD:
4831efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FMUL:
4841efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::AND:
4851efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::OR:
4861efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::XOR:
4871efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDC:
4881efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDE: return true;
4891efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    default: return false;
4901efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    }
4911efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  }
4921efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng
493cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  void dump() const;
494d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner
49551dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  /// FoldSetCC - Constant fold a setcc to true or false.
49651dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  SDOperand FoldSetCC(MVT::ValueType VT, SDOperand N1,
49751dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner                      SDOperand N2, ISD::CondCode Cond);
49851dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner
499ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
500ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// use this predicate to simplify operations downstream.  Op and Mask are
501ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be the same type.
502ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  bool MaskedValueIsZero(SDOperand Op, uint64_t Mask, unsigned Depth = 0)
503ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman    const;
504ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
505ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeMaskedBits - Determine which of the bits specified in Mask are
506ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// known to be either zero or one and return them in the KnownZero/KnownOne
507ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
508ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// processing.  Targets can implement the computeMaskedBitsForTargetNode
509ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// method in the TargetLowering class to allow target nodes to be understood.
510ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  void ComputeMaskedBits(SDOperand Op, uint64_t Mask, uint64_t &KnownZero,
511ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman                         uint64_t &KnownOne, unsigned Depth = 0) const;
512ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
513ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// ComputeNumSignBits - Return the number of times the sign bit of the
514ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// register is replicated into the other bits.  We know that at least 1 bit
515ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// is always equal to the sign bit (itself), but other cases can give us
516ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// information.  For example, immediately after an "SRA X, 2", we know that
517ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// the top 3 bits are all equal to each other, so we return 3.  Targets can
518ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
519ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  /// class to allow target nodes to be understood.
520ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman  unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
521ea859be53ca13a1547c4675549946b74dc3c6f41Dan Gohman
522d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate:
5231b95095857b78e12138c22e76c7936611c51355bChris Lattner  void RemoveNodeFromCSEMaps(SDNode *N);
5246542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
525a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
526a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
527a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
528f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
529a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
530b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner
531fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void DeleteNodeNotInCSEMaps(SDNode *N);
5327cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
533109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  // List of non-single value types.
534109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  std::list<std::vector<MVT::ValueType> > VTList;
535109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
5361cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner  // Maps to auto-CSE operations.
5377cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  std::vector<CondCodeSDNode*> CondCodeNodes;
5381cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner
53915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  std::vector<SDNode*> ValueTypeNodes;
5405f056bf4b862a7c31388a68711dd3b3ed5de2be8Chris Lattner  std::map<std::string, SDNode*> ExternalSymbols;
5412a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth  std::map<std::string, SDNode*> TargetExternalSymbols;
54247725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  std::map<std::string, StringSDNode*> StringNodes;
543cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner};
544cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
5451080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
5461080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SelectionDAG::allnodes_iterator nodes_iterator;
5471080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_begin(SelectionDAG *G) {
5481080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_begin();
5491080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
5501080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_end(SelectionDAG *G) {
5511080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_end();
5521080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
5531080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
5541080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
555b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner}  // end namespace llvm
556cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
557cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif
558