SelectionDAG.h revision c7c3f110eda0ff8040e4bd99e38d3112b910810f
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
18a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner#include "llvm/CodeGen/SelectionDAGCSEMap.h"
19b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner#include "llvm/ADT/ilist"
20b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
21109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner#include <list>
225892d47a625638a90afeb31dd4f6f80a2f9bacdeChris Lattner#include <vector>
23322812e603705e1c2037313633e72f689524b163Evan Cheng#include <map>
24322812e603705e1c2037313633e72f689524b163Evan Cheng#include <set>
25eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner#include <string>
26d0fde30ce850b78371fd1386338350591f9ff494Brian Gaeke
27d0fde30ce850b78371fd1386338350591f9ff494Brian Gaekenamespace llvm {
28c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  class AliasAnalysis;
29c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetLowering;
30c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class TargetMachine;
31b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey  class MachineDebugInfo;
32c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  class MachineFunction;
33d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  class MachineConstantPoolValue;
34c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
35c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// SelectionDAG class - This is used to represent a portion of an LLVM function
36c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// in a low-level Data Dependence DAG representation suitable for instruction
37c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection.  This DAG is constructed as the first step of instruction
38c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// selection in order to allow implementation of machine specific optimizations
39c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// and code simplifications.
40c3aae25116e66c177579b0b79182b09340b19753Chris Lattner///
41c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// The representation used by the SelectionDAG is a target-independent
42c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// representation, which has some similarities to the GCC RTL representation,
43c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// but is significantly more simple, powerful, and is a graph form instead of a
44c3aae25116e66c177579b0b79182b09340b19753Chris Lattner/// linear form.
45cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner///
46cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerclass SelectionDAG {
47063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &TLI;
48c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &MF;
49b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey  MachineDebugInfo *DI;
50cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
51213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// Root - The root of the entire DAG.  EntryNode - The starting token.
52c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand Root, EntryNode;
53cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
54213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// AllNodes - A linked list of nodes in the current DAG.
55b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  ilist<SDNode> AllNodes;
56691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth
57213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSEMap - This structure is used to memoize nodes, automatically performing
58213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  /// CSE with existing nodes with a duplicate is requested.
59213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner  SelectionDAGCSEMap CSEMap;
60213a16c637926bfc38ba373d3aba6778e181e3ecChris Lattner
61cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattnerpublic:
62b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey  SelectionDAG(TargetLowering &tli, MachineFunction &mf, MachineDebugInfo *di)
63b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey  : TLI(tli), MF(mf), DI(di) {
64c3aae25116e66c177579b0b79182b09340b19753Chris Lattner    EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
65c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  }
66cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ~SelectionDAG();
67cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
68c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  MachineFunction &getMachineFunction() const { return MF; }
69063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  const TargetMachine &getTarget() const;
70063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  TargetLowering &getTargetLoweringInfo() const { return TLI; }
71b2efb853f00d45b1c8d57f92acd0028fbdeffda6Jim Laskey  MachineDebugInfo *getMachineDebugInfo() const { return DI; }
72cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
73ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
741080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  ///
751080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  void viewGraph();
76ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
77ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#ifndef NDEBUG
78ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  std::map<const SDNode *, std::string> NodeGraphAttrs;
79ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey#endif
801080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
81ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// clearGraphAttrs - Clear all previously defined node graph attributes.
82ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Intended to be used from a debugging tool (eg. gdb).
83ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void clearGraphAttrs();
84ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
85ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
86ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
87ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphAttrs(const SDNode *N, const char *Attrs);
88ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
89ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
90ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// Used from getNodeAttributes.
91ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  const std::string getGraphAttrs(const SDNode *N) const;
92ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey
93ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  /// setGraphColor - Convenience for setting node color attribute.
94ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  ///
95ec20402c90b605afeedbcf0e3aabe6f8054f23ddJim Laskey  void setGraphColor(const SDNode *N, const char *Color);
961080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
97b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
98b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
99b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
100b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  typedef ilist<SDNode>::iterator allnodes_iterator;
101b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
102b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner  allnodes_iterator allnodes_end() { return AllNodes.end(); }
103b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner
104c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getRoot - Return the root tag of the SelectionDAG.
105cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
106c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getRoot() const { return Root; }
107cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
108c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getEntryNode - Return the token chain corresponding to the entry of the
109c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// function.
110c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &getEntryNode() const { return EntryNode; }
111cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
112c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// setRoot - Set the current root tag of the SelectionDAG.
113cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
114c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  const SDOperand &setRoot(SDOperand N) { return Root = N; }
115cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
1161d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// Combine - This iterates over the nodes in the SelectionDAG, folding
1171d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// certain types of nodes together, or eliminating superfluous nodes.  When
1181d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// the AfterLegalize argument is set to 'true', Combine takes care not to
1191d4d41411190dd9e62764e56713753d4155764ddNate Begeman  /// generate any nodes that will be illegal on the target.
120c7c3f110eda0ff8040e4bd99e38d3112b910810fJim Laskey  void Combine(bool AfterLegalize, AliasAnalysis &AA);
1211d4d41411190dd9e62764e56713753d4155764ddNate Begeman
122c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
123c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// compatible with the target instruction selector, as indicated by the
124c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// TargetLowering object.
125cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
126c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// Note that this is an involved process that may invalidate pointers into
127c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// the graph.
128063287a76b5d1486f498fcf674a26d1155471a3fChris Lattner  void Legalize();
129c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
130d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner  /// RemoveDeadNodes - This method deletes all unreachable nodes in the
131190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  /// SelectionDAG.
132190a418bf6b49a4ef1c1980229a2f0d516e8a2cdChris Lattner  void RemoveDeadNodes();
133130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
134130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// RemoveDeadNode - Remove the specified node from the system. If any of its
135130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// operands then becomes dead, remove them as well. The vector Deleted is
136130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// populated with nodes that are deleted.
137130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void RemoveDeadNode(SDNode *N, std::vector<SDNode*> &Deleted);
13870046e920fa37989a041af663ada2b2b646e258fChris Lattner
139130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// DeleteNode - Remove the specified node from the system.  This node must
140130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  /// have no referrers.
141130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng  void DeleteNode(SDNode *N);
142130a6471b90f66e99b1f9f42877fdf611c330ac6Evan Cheng
14370046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getVTList - Return an SDVTList that represents the list of values
14470046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// specified.
14570046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT);
14670046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2);
14770046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2,MVT::ValueType VT3);
14870046e920fa37989a041af663ada2b2b646e258fChris Lattner  SDVTList getVTList(const MVT::ValueType *VTs, unsigned NumVTs);
14970046e920fa37989a041af663ada2b2b646e258fChris Lattner
15070046e920fa37989a041af663ada2b2b646e258fChris Lattner  /// getNodeValueTypes - These are obsolete, use getVTList instead.
15170046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT) {
15270046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT).VTs;
15370046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
15470046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,
15570046e920fa37989a041af663ada2b2b646e258fChris Lattner                                          MVT::ValueType VT2) {
15670046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2).VTs;
15770046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
15870046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,MVT::ValueType VT2,
15970046e920fa37989a041af663ada2b2b646e258fChris Lattner                                          MVT::ValueType VT3) {
16070046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(VT1, VT2, VT3).VTs;
16170046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16270046e920fa37989a041af663ada2b2b646e258fChris Lattner  const MVT::ValueType *getNodeValueTypes(std::vector<MVT::ValueType> &VTList) {
16370046e920fa37989a041af663ada2b2b646e258fChris Lattner    return getVTList(&VTList[0], VTList.size()).VTs;
16470046e920fa37989a041af663ada2b2b646e258fChris Lattner  }
16570046e920fa37989a041af663ada2b2b646e258fChris Lattner
16670046e920fa37989a041af663ada2b2b646e258fChris Lattner
1671b1a49714ef26225a42199cf2930529f31868322Chris Lattner  //===--------------------------------------------------------------------===//
16870046e920fa37989a041af663ada2b2b646e258fChris Lattner  // Node creation methods.
16970046e920fa37989a041af663ada2b2b646e258fChris Lattner  //
17047725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  SDOperand getString(const std::string &Val);
171cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  SDOperand getConstant(uint64_t Val, MVT::ValueType VT, bool isTarget = false);
172cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT) {
173cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getConstant(Val, VT, true);
174cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
175c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getConstantFP(double Val, MVT::ValueType VT, bool isTarget = false);
176c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetConstantFP(double Val, MVT::ValueType VT) {
177c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantFP(Val, VT, true);
178c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
17914229bb6369c110644c11bc7906b0c1167d3a87aEvan Cheng  SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
180cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                             int offset = 0, bool isTargetGA = false);
18161ca74bc3a29b2af2be7e4bd612289da8aae85b5Evan Cheng  SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
182cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner                                   int offset = 0) {
183cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner    return getGlobalAddress(GV, VT, offset, true);
184cbea3045ce0bdd061c494a831d0ce2d5834211ccChris Lattner  }
185c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getFrameIndex(int FI, MVT::ValueType VT, bool isTarget = false);
186c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT) {
187c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getFrameIndex(FI, VT, true);
188c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
189c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getJumpTable(int JTI, MVT::ValueType VT, bool isTarget = false);
190c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT) {
191c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getJumpTable(JTI, VT, true);
192c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
193b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
194c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                            unsigned Align = 0, int Offs = 0, bool isT=false);
195b8973bd8f50d7321635e1e07b81a880a0828d185Evan Cheng  SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
196c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner                                  unsigned Align = 0, int Offset = 0) {
197c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner    return getConstantPool(C, VT, Align, Offset, true);
198c9f8f416800784ca6453222b307bc44ad24739b0Chris Lattner  }
199d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getConstantPool(MachineConstantPoolValue *C, MVT::ValueType VT,
200d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                            unsigned Align = 0, int Offs = 0, bool isT=false);
201d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
202d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  MVT::ValueType VT, unsigned Align = 0,
203d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng                                  int Offset = 0) {
204d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng    return getConstantPool(C, VT, Align, Offset, true);
205d6594ae54cfde4db4d30272192645c0a45fb9902Evan Cheng  }
206c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getBasicBlock(MachineBasicBlock *MBB);
207c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
2082a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth  SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
20915e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  SDOperand getValueType(MVT::ValueType);
210d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getRegister(unsigned Reg, MVT::ValueType VT);
211c3aae25116e66c177579b0b79182b09340b19753Chris Lattner
212d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
213d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner    return getNode(ISD::CopyToReg, MVT::Other, Chain,
214d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner                   getRegister(Reg, N.getValueType()), N);
215cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  }
216cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
217e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyToReg method takes an extra operand, which
218e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
219e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
220e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
221e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                         SDOperand Flag) {
2222fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
223bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
2242fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
225e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
22666a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng
22766a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  // Similar to last getCopyToReg() except parameter Reg is a SDOperand
22866a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
22966a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng                         SDOperand Flag) {
2302fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
231bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner    SDOperand Ops[] = { Chain, Reg, N, Flag };
2322fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
23366a48bbc3565b40ea0e6f2d58cf5e3a8e64802efEvan Cheng  }
234e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
235d5d0f9bd20d9df07d6b4d41b7e8ed6d33b6a649dChris Lattner  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT) {
2362fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other);
237f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
2382fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
23918c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner  }
240e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner
241e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // This version of the getCopyFromReg method takes an extra operand, which
242e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // indicates that there is potentially an incoming flag value (if Flag is not
243e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  // null) and that there should be a flag result.
244e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT,
245e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner                           SDOperand Flag) {
2462fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
247f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
2482fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
249e3f1026683c38f6605ccaf698b7082f1b0a0f8c8Chris Lattner  }
25018c2f13e0f9d0e5d6227cf6d1881e9ee3d1b6109Chris Lattner
2517cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getCondCode(ISD::CondCode Cond);
252cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
2531ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// getZeroExtendInReg - Return the expression required to zero extend the Op
2541ccae666f596d5aeca5c9942995763600b622062Chris Lattner  /// value assuming it was the smaller SrcTy value.
2551ccae666f596d5aeca5c9942995763600b622062Chris Lattner  SDOperand getZeroExtendInReg(SDOperand Op, MVT::ValueType SrcTy);
2566a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner
2576a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
2586a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  /// a flag result (to ensure it's not CSE'd).
2596a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
2602fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
261f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner    SDOperand Ops[] = { Chain,  Op };
2622fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
2636a5b6d7633c96c72ca7d5f8ba0c855e4690ada04Chris Lattner  }
2641ccae666f596d5aeca5c9942995763600b622062Chris Lattner
265c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getNode - Gets or creates the specified node.
266cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
267c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT);
268c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N);
269c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
270c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2);
271c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
272c3aae25116e66c177579b0b79182b09340b19753Chris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3);
273c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
2742d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
2752d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
276f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
277f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner                    SDOperand N5);
278f7db8c69a12582c7d1ff7c5f25c948dca2dbf7dcChris Lattner  SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
279f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
280f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
281f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
2822fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner  SDOperand getNode(unsigned Opcode, const MVT::ValueType *VTs, unsigned NumVTs,
2832fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
28467bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner  SDOperand getNode(unsigned Opcode, SDVTList VTs,
28567bb42aa5957bb24c0604cc08243cde9fe938e94Chris Lattner                    const SDOperand *Ops, unsigned NumOps);
286f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner
2877cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// getSetCC - Helper function to make it easier to build SetCC's if you just
2887cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  /// have an ISD::CondCode instead of an SDOperand.
2897cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  ///
2907cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  SDOperand getSetCC(MVT::ValueType VT, SDOperand LHS, SDOperand RHS,
2917cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner                     ISD::CondCode Cond) {
2927cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner    return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
2937cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  }
2949373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman
2959373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// getSelectCC - Helper function to make it easier to build SelectCC's if you
2969373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  /// just have an ISD::CondCode instead of an SDOperand.
2979373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  ///
2989373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
2999373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman                        SDOperand True, SDOperand False, ISD::CondCode Cond) {
3002fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner    return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
3012fa6d3b1fcadbde90eaee0e8e89aebd81630b662Chris Lattner                   getCondCode(Cond));
3029373a81e53ce5f9f2c06c4209b8b886605aece08Nate Begeman  }
3037cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
304acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// getVAArg - VAArg produces a result and token chain, and takes a pointer
305acc398c195a697795bff3245943d104eb19192b9Nate Begeman  /// and a source value as input.
306acc398c195a697795bff3245943d104eb19192b9Nate Begeman  SDOperand getVAArg(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
307acc398c195a697795bff3245943d104eb19192b9Nate Begeman                     SDOperand SV);
3087cbd525ba85ebe440d15fa359ec940e404d14906Nate Begeman
309c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// getLoad - Loads are not normal binary operators: their result type is not
310c3aae25116e66c177579b0b79182b09340b19753Chris Lattner  /// determined by their operands, and they produce a value AND a token chain.
311cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  ///
31221074f43ed5165828717ea3606eb2bd222a39b26Chris Lattner  SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
31324446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                    const Value *SV, int SVOffset, bool isVolatile=false);
31424446e253a17720f6462288255ab5ebd13b8491fEvan Cheng  SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
31524446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                       SDOperand Chain, SDOperand Ptr, const Value *SV,
31624446e253a17720f6462288255ab5ebd13b8491fEvan Cheng                       int SVOffset, MVT::ValueType EVT, bool isVolatile=false);
3175fbb5d2459a5410590f285250faa604576308a93Nate Begeman  SDOperand getVecLoad(unsigned Count, MVT::ValueType VT, SDOperand Chain,
3185fbb5d2459a5410590f285250faa604576308a93Nate Begeman                       SDOperand Ptr, SDOperand SV);
3192d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth
320ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  /// getStore - Helper function to build ISD::STORE nodes.
321ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  ///
322ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng  SDOperand getStore(SDOperand Chain, SDOperand Value, SDOperand Ptr,
3238b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng                     const Value *SV, int SVOffset, bool isVolatile=false);
3248b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng  SDOperand getTruncStore(SDOperand Chain, SDOperand Value, SDOperand Ptr,
3258b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng                          const Value *SV, int SVOffset, MVT::ValueType TVT,
3268b2794aeff151be8cdbd44786c1d0f94f8f2e427Evan Cheng                          bool isVolatile=false);
327ad071e1cd1a4b880019f1b2e827ee81867815f82Evan Cheng
3282d86ea21dd76647cb054fd5d27df9e49efc672b6Andrew Lenharth  // getSrcValue - construct a node to track a Value* through the backend
329691ef2ba066dda14ae4ac0ad645054fbc967785aAndrew Lenharth  SDOperand getSrcValue(const Value* I, int offset = 0);
330cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
331b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
332b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// specified operands.  If the resultant node already exists in the DAG,
333b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// this does not modify the specified node, instead it returns the node that
334b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// already exists.  If the resultant node does not exist in the DAG, the
335b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input node is returned.  As a degenerate case, if you specify the same
336b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  /// input operands as the node already has, the input node is returned.
337b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
338b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
339b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
340b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3);
341b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
342b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner                               SDOperand Op3, SDOperand Op4);
3439b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
3449b88361befd2a94202dc60ccfb3e31756916a9caChris Lattner                               SDOperand Op3, SDOperand Op4, SDOperand Op5);
345f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDOperand UpdateNodeOperands(SDOperand N, SDOperand *Ops, unsigned NumOps);
3461b95095857b78e12138c22e76c7936611c51355bChris Lattner
3471b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// SelectNodeTo - These are used for target selectors to *mutate* the
3481b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// specified node to have the specified return type, Target opcode, and
3491b95095857b78e12138c22e76c7936611c51355bChris Lattner  /// operands.  Note that target opcodes are stored as
350eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field.  The 0th value
351eb19e40efbd3cae80c908a30cdf4d33450733c45Chris Lattner  /// of the resultant node is returned.
35295514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT);
35395514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
35495514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1);
35595514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
35695514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2);
35795514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
35895514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op1, SDOperand Op2, SDOperand Op3);
359694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
360694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        const SDOperand *Ops, unsigned NumOps);
36195514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
36295514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
36395514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng  SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
36495514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
36595514bae7309ffacfc0a79b267159dcfde2b7720Evan Cheng                       SDOperand Op3);
366694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng
367753c8f20e45f6e4198c7cf4096ecc8948a029e9cChris Lattner
3686ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// getTargetNode - These are used for target selectors to create a new node
3696ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// with specified return type(s), target opcode, and operands.
3706ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  ///
3716ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// Note that getTargetNode returns the resultant node.  If there is already a
3726ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// node of the specified opcode and operands, it returns that node instead of
3736ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  /// the current one.
3746ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT);
3756ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
3766ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1);
3776ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
3786ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
3796ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
3806ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2, SDOperand Op3);
3816ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
382bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner                        const SDOperand *Ops, unsigned NumOps);
3836ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
3846ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1);
3856ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
3866ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
3876ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
3886ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
3896ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op3);
390694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
391694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        MVT::ValueType VT2,
392694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        const SDOperand *Ops, unsigned NumOps);
3936ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
3946ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        MVT::ValueType VT2, MVT::ValueType VT3,
3956ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng                        SDOperand Op1, SDOperand Op2);
3966ae46c4c8757237bca2b78b589c96c37015bc356Evan Cheng  SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
397694481ee01bfe507c6e37de0dc1c64cff455eefdEvan Cheng                        MVT::ValueType VT2, MVT::ValueType VT3,
398bd564bfc63163e31f320c3da9749db70992dc35eChris Lattner                        const SDOperand *Ops, unsigned NumOps);
3996542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner
4006542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
40126005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// This can cause recursive merging of nodes in the DAG.  Use the first
40226005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// version if 'From' is known to have a single result, use the second
40326005b1b672aebd437edc561d381c5dd19a03ddbChris Lattner  /// if you have two nodes with identical results, use the third otherwise.
4046542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  ///
405fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// These methods all take an optional vector, which (if not null) is
406fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// populated with any nodes that are deleted from the SelectionDAG, due to
407fde3f3061d665babeb78443119a09876098fc35eChris Lattner  /// new equivalences that are discovered.
408fde3f3061d665babeb78443119a09876098fc35eChris Lattner  ///
409fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
410fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
411fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void ReplaceAllUsesWith(SDNode *From, SDNode *To,
412fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
4138a842cf8287ee957e15b95ceeb6ee5f189caba3dChris Lattner  void ReplaceAllUsesWith(SDNode *From, const SDOperand *To,
414fde3f3061d665babeb78443119a09876098fc35eChris Lattner                          std::vector<SDNode*> *Deleted = 0);
415fae9f1cb34d6d2c4dbd007f2d748a70b67776a82Evan Cheng
41680274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
41780274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// uses of other values produced by From.Val alone.  The Deleted vector is
41880274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// handled the same was as for ReplaceAllUsesWith, but it is required for
41980274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  /// this method.
42080274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner  void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
42180274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner                                 std::vector<SDNode*> &Deleted);
42280274268b99e5a066825c8cc5aba58dbc5ad0a52Chris Lattner
423e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
424e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// their allnodes order. It returns the maximum id.
4257c16d776cb827922dd0f8f0a88c5b65a90810c0bEvan Cheng  unsigned AssignNodeIds();
426b9ee9e60a905b90fa3e84c5c6091af6e5a0382d2Evan Cheng
427e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng  /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
42809fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// based on their topological order. It returns the maximum id and a vector
42909fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  /// of the SDNodes* in assigned order by reference.
43009fd736058ec3f69b856ae3ad65177bc31904a8cEvan Cheng  unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
431e6f35d8a5cc92d776cf460200e2b815e8c301b14Evan Cheng
4321efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
4331efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  /// operation.
4341efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  static bool isCommutativeBinOp(unsigned Opcode) {
4351efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    switch (Opcode) {
4361efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADD:
4371efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MUL:
4381efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHU:
4391efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::MULHS:
4401efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FADD:
4411efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::FMUL:
4421efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::AND:
4431efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::OR:
4441efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::XOR:
4451efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDC:
4461efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    case ISD::ADDE: return true;
4471efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    default: return false;
4481efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng    }
4491efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng  }
4501efba0ecb4d0b3807c48e6e0f74e3ce5c9fad809Evan Cheng
451cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner  void dump() const;
452d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattner
45351dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  /// FoldSetCC - Constant fold a setcc to true or false.
45451dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner  SDOperand FoldSetCC(MVT::ValueType VT, SDOperand N1,
45551dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner                      SDOperand N2, ISD::CondCode Cond);
45651dabfb28375be7bc5848806ae31cd068b6133f8Chris Lattner
457d1fc96499b7619356c7542200d32da898b79f7c1Chris Lattnerprivate:
4581b95095857b78e12138c22e76c7936611c51355bChris Lattner  void RemoveNodeFromCSEMaps(SDNode *N);
4596542d950609208de3e1cde704c5f89aad864c0d9Chris Lattner  SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
460a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
461a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
462a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
463f06f35e30b4c4d7db304f717a3d4dc6595fbd078Chris Lattner  SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
464a5682853b9921bbb0dd2ee175c9bd44142d4819eChris Lattner                               void *&InsertPos);
465b9aff659e82e4ec1a507e6e7fe7969379a431613Chris Lattner
466fde3f3061d665babeb78443119a09876098fc35eChris Lattner  void DeleteNodeNotInCSEMaps(SDNode *N);
4677cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner
468109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  // List of non-single value types.
469109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner  std::list<std::vector<MVT::ValueType> > VTList;
470109654fae9c5b8b96bd3a829824cdbceb27ced06Chris Lattner
4711cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner  // Maps to auto-CSE operations.
4727cf7e3f33f25544d08492d47cc8a1cbba25dc8d7Chris Lattner  std::vector<CondCodeSDNode*> CondCodeNodes;
4731cff05c7c216eea0e9173738c2a60b70c2b3c013Chris Lattner
47415e4b01920d6a0ffbe35d3e5aa88a4b42970b6a7Chris Lattner  std::vector<SDNode*> ValueTypeNodes;
4755f056bf4b862a7c31388a68711dd3b3ed5de2be8Chris Lattner  std::map<std::string, SDNode*> ExternalSymbols;
4762a2de66db2093a5bc1fd620d1b6ae7992a552b24Andrew Lenharth  std::map<std::string, SDNode*> TargetExternalSymbols;
47747725d059b259f8a0c145478300c9e9caa006b59Chris Lattner  std::map<std::string, StringSDNode*> StringNodes;
478cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner};
479cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
4801080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattnertemplate <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
4811080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  typedef SelectionDAG::allnodes_iterator nodes_iterator;
4821080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_begin(SelectionDAG *G) {
4831080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_begin();
4841080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
4851080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  static nodes_iterator nodes_end(SelectionDAG *G) {
4861080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner    return G->allnodes_end();
4871080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner  }
4881080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner};
4891080b9ee534579c67f7c99364cc6fa11edbcd919Chris Lattner
490b80e2be8894db9f843f32ebaffb9b7fd6b57d206Chris Lattner}  // end namespace llvm
491cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner
492cacf462915344c2af25eef1af1f3ee2c7280ff56Chris Lattner#endif
493