add a new SDVTList type and new SelectionDAG::getVTList methods to streamline
[oota-llvm.git] / include / llvm / CodeGen / SelectionDAG.h
1 //===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file declares the SelectionDAG class, and transitively defines the
11 // SDNode class and subclasses.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef LLVM_CODEGEN_SELECTIONDAG_H
16 #define LLVM_CODEGEN_SELECTIONDAG_H
17
18 #include "llvm/CodeGen/SelectionDAGNodes.h"
19 #include "llvm/CodeGen/SelectionDAGCSEMap.h"
20 #include "llvm/ADT/ilist"
21
22 #include <list>
23 #include <map>
24 #include <set>
25 #include <string>
26
27 namespace llvm {
28   class TargetLowering;
29   class TargetMachine;
30   class MachineDebugInfo;
31   class MachineFunction;
32
33 /// SDVTList - This represents a list of ValueType's that has been intern'd by
34 /// a SelectionDAG.  Instances of this simple value class are returned by
35 /// SelectionDAG::getVTList(...).
36 ///
37 struct SDVTList {
38   const MVT::ValueType *VTs;
39   unsigned short NumVTs;
40 };
41   
42 /// SelectionDAG class - This is used to represent a portion of an LLVM function
43 /// in a low-level Data Dependence DAG representation suitable for instruction
44 /// selection.  This DAG is constructed as the first step of instruction
45 /// selection in order to allow implementation of machine specific optimizations
46 /// and code simplifications.
47 ///
48 /// The representation used by the SelectionDAG is a target-independent
49 /// representation, which has some similarities to the GCC RTL representation,
50 /// but is significantly more simple, powerful, and is a graph form instead of a
51 /// linear form.
52 ///
53 class SelectionDAG {
54   TargetLowering &TLI;
55   MachineFunction &MF;
56   MachineDebugInfo *DI;
57
58   /// Root - The root of the entire DAG.  EntryNode - The starting token.
59   SDOperand Root, EntryNode;
60
61   /// AllNodes - A linked list of nodes in the current DAG.
62   ilist<SDNode> AllNodes;
63
64   /// CSEMap - This structure is used to memoize nodes, automatically performing
65   /// CSE with existing nodes with a duplicate is requested.
66   SelectionDAGCSEMap CSEMap;
67
68 public:
69   SelectionDAG(TargetLowering &tli, MachineFunction &mf, MachineDebugInfo *di)
70   : TLI(tli), MF(mf), DI(di) {
71     EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
72   }
73   ~SelectionDAG();
74
75   MachineFunction &getMachineFunction() const { return MF; }
76   const TargetMachine &getTarget() const;
77   TargetLowering &getTargetLoweringInfo() const { return TLI; }
78   MachineDebugInfo *getMachineDebugInfo() const { return DI; }
79
80   /// viewGraph - Pop up a ghostview window with the DAG rendered using 'dot'.
81   ///
82   void viewGraph();
83
84
85   typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
86   allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
87   allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
88   typedef ilist<SDNode>::iterator allnodes_iterator;
89   allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
90   allnodes_iterator allnodes_end() { return AllNodes.end(); }
91   
92   /// getRoot - Return the root tag of the SelectionDAG.
93   ///
94   const SDOperand &getRoot() const { return Root; }
95
96   /// getEntryNode - Return the token chain corresponding to the entry of the
97   /// function.
98   const SDOperand &getEntryNode() const { return EntryNode; }
99
100   /// setRoot - Set the current root tag of the SelectionDAG.
101   ///
102   const SDOperand &setRoot(SDOperand N) { return Root = N; }
103
104   /// Combine - This iterates over the nodes in the SelectionDAG, folding
105   /// certain types of nodes together, or eliminating superfluous nodes.  When
106   /// the AfterLegalize argument is set to 'true', Combine takes care not to
107   /// generate any nodes that will be illegal on the target.
108   void Combine(bool AfterLegalize);
109   
110   /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
111   /// compatible with the target instruction selector, as indicated by the
112   /// TargetLowering object.
113   ///
114   /// Note that this is an involved process that may invalidate pointers into
115   /// the graph.
116   void Legalize();
117
118   /// RemoveDeadNodes - This method deletes all unreachable nodes in the
119   /// SelectionDAG.
120   void RemoveDeadNodes();
121   
122   /// getVTList - Return an SDVTList that represents the list of values
123   /// specified.
124   SDVTList getVTList(MVT::ValueType VT);
125   SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2);
126   SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2,MVT::ValueType VT3);
127   SDVTList getVTList(const MVT::ValueType *VTs, unsigned NumVTs);
128   
129   /// getNodeValueTypes - These are obsolete, use getVTList instead.
130   const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT) {
131     return getVTList(VT).VTs;
132   }
133   const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1, 
134                                           MVT::ValueType VT2) {
135     return getVTList(VT1, VT2).VTs;
136   }
137   const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,MVT::ValueType VT2,
138                                           MVT::ValueType VT3) {
139     return getVTList(VT1, VT2, VT3).VTs;
140   }
141   const MVT::ValueType *getNodeValueTypes(std::vector<MVT::ValueType> &VTList) {
142     return getVTList(&VTList[0], VTList.size()).VTs;
143   }
144   
145   
146   //===----------------------------------------------------------------------===//
147   // Node creation methods.
148   //
149   SDOperand getString(const std::string &Val);
150   SDOperand getConstant(uint64_t Val, MVT::ValueType VT, bool isTarget = false);
151   SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT) {
152     return getConstant(Val, VT, true);
153   }
154   SDOperand getConstantFP(double Val, MVT::ValueType VT, bool isTarget = false);
155   SDOperand getTargetConstantFP(double Val, MVT::ValueType VT) {
156     return getConstantFP(Val, VT, true);
157   }
158   SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
159                              int offset = 0, bool isTargetGA = false);
160   SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
161                                    int offset = 0) {
162     return getGlobalAddress(GV, VT, offset, true);
163   }
164   SDOperand getFrameIndex(int FI, MVT::ValueType VT, bool isTarget = false);
165   SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT) {
166     return getFrameIndex(FI, VT, true);
167   }
168   SDOperand getJumpTable(int JTI, MVT::ValueType VT, bool isTarget = false);
169   SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT) {
170     return getJumpTable(JTI, VT, true);
171   }
172   SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
173                             unsigned Align = 0, int Offs = 0, bool isT=false);
174   SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
175                                   unsigned Align = 0, int Offset = 0) {
176     return getConstantPool(C, VT, Align, Offset, true);
177   }
178   SDOperand getBasicBlock(MachineBasicBlock *MBB);
179   SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
180   SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
181   SDOperand getValueType(MVT::ValueType);
182   SDOperand getRegister(unsigned Reg, MVT::ValueType VT);
183
184   SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
185     return getNode(ISD::CopyToReg, MVT::Other, Chain,
186                    getRegister(Reg, N.getValueType()), N);
187   }
188
189   // This version of the getCopyToReg method takes an extra operand, which
190   // indicates that there is potentially an incoming flag value (if Flag is not
191   // null) and that there should be a flag result.
192   SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
193                          SDOperand Flag) {
194     const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
195     SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
196     return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
197   }
198
199   // Similar to last getCopyToReg() except parameter Reg is a SDOperand
200   SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
201                          SDOperand Flag) {
202     const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
203     SDOperand Ops[] = { Chain, Reg, N, Flag };
204     return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
205   }
206   
207   SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT) {
208     const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other);
209     SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
210     return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
211   }
212   
213   // This version of the getCopyFromReg method takes an extra operand, which
214   // indicates that there is potentially an incoming flag value (if Flag is not
215   // null) and that there should be a flag result.
216   SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT,
217                            SDOperand Flag) {
218     const MVT::ValueType *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
219     SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
220     return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
221   }
222
223   SDOperand getCondCode(ISD::CondCode Cond);
224
225   /// getZeroExtendInReg - Return the expression required to zero extend the Op
226   /// value assuming it was the smaller SrcTy value.
227   SDOperand getZeroExtendInReg(SDOperand Op, MVT::ValueType SrcTy);
228   
229   /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
230   /// a flag result (to ensure it's not CSE'd).
231   SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
232     const MVT::ValueType *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
233     SDOperand Ops[] = { Chain,  Op };
234     return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
235   }
236
237   /// getNode - Gets or creates the specified node.
238   ///
239   SDOperand getNode(unsigned Opcode, MVT::ValueType VT);
240   SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N);
241   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
242                     SDOperand N1, SDOperand N2);
243   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
244                     SDOperand N1, SDOperand N2, SDOperand N3);
245   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
246                     SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
247   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
248                     SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
249                     SDOperand N5);
250   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
251                     const SDOperand *Ops, unsigned NumOps);
252   SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
253                     const SDOperand *Ops, unsigned NumOps);
254   SDOperand getNode(unsigned Opcode, const MVT::ValueType *VTs, unsigned NumVTs,
255                     const SDOperand *Ops, unsigned NumOps);
256   
257   /// getSetCC - Helper function to make it easier to build SetCC's if you just
258   /// have an ISD::CondCode instead of an SDOperand.
259   ///
260   SDOperand getSetCC(MVT::ValueType VT, SDOperand LHS, SDOperand RHS,
261                      ISD::CondCode Cond) {
262     return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
263   }
264
265   /// getSelectCC - Helper function to make it easier to build SelectCC's if you
266   /// just have an ISD::CondCode instead of an SDOperand.
267   ///
268   SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
269                         SDOperand True, SDOperand False, ISD::CondCode Cond) {
270     return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
271                    getCondCode(Cond));
272   }
273   
274   /// getVAArg - VAArg produces a result and token chain, and takes a pointer
275   /// and a source value as input.
276   SDOperand getVAArg(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
277                      SDOperand SV);
278
279   /// getLoad - Loads are not normal binary operators: their result type is not
280   /// determined by their operands, and they produce a value AND a token chain.
281   ///
282   SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
283                     SDOperand SV);
284   SDOperand getVecLoad(unsigned Count, MVT::ValueType VT, SDOperand Chain, 
285                        SDOperand Ptr, SDOperand SV);
286   SDOperand getExtLoad(unsigned Opcode, MVT::ValueType VT, SDOperand Chain,
287                        SDOperand Ptr, SDOperand SV, MVT::ValueType EVT);
288
289   // getSrcValue - construct a node to track a Value* through the backend
290   SDOperand getSrcValue(const Value* I, int offset = 0);
291
292   /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
293   /// specified operands.  If the resultant node already exists in the DAG,
294   /// this does not modify the specified node, instead it returns the node that
295   /// already exists.  If the resultant node does not exist in the DAG, the
296   /// input node is returned.  As a degenerate case, if you specify the same
297   /// input operands as the node already has, the input node is returned.
298   SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
299   SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
300   SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
301                                SDOperand Op3);
302   SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
303                                SDOperand Op3, SDOperand Op4);
304   SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
305                                SDOperand Op3, SDOperand Op4, SDOperand Op5);
306   SDOperand UpdateNodeOperands(SDOperand N, SDOperand *Ops, unsigned NumOps);
307   
308   /// SelectNodeTo - These are used for target selectors to *mutate* the
309   /// specified node to have the specified return type, Target opcode, and
310   /// operands.  Note that target opcodes are stored as
311   /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field.  The 0th value
312   /// of the resultant node is returned.
313   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT);
314   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
315                          SDOperand Op1);
316   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
317                          SDOperand Op1, SDOperand Op2);
318   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
319                          SDOperand Op1, SDOperand Op2, SDOperand Op3);
320   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
321                          SDOperand Op1, SDOperand Op2, SDOperand Op3, 
322                          SDOperand Op4);
323   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
324                          SDOperand Op1, SDOperand Op2, SDOperand Op3,
325                          SDOperand Op4, SDOperand Op5);
326   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
327                          SDOperand Op1, SDOperand Op2, SDOperand Op3, 
328                          SDOperand Op4, SDOperand Op5, SDOperand Op6);
329   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
330                          SDOperand Op1, SDOperand Op2, SDOperand Op3,
331                          SDOperand Op4, SDOperand Op5, SDOperand Op6,
332                          SDOperand Op7);
333   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT, 
334                          SDOperand Op1, SDOperand Op2, SDOperand Op3,
335                          SDOperand Op4, SDOperand Op5, SDOperand Op6,
336                          SDOperand Op7, SDOperand Op8);
337   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1, 
338                          MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
339   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
340                          MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
341                          SDOperand Op3);
342   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
343                          MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
344                          SDOperand Op3, SDOperand Op4);
345   SDOperand SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
346                          MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
347                          SDOperand Op3, SDOperand Op4, SDOperand Op5);
348
349   /// getTargetNode - These are used for target selectors to create a new node
350   /// with specified return type(s), target opcode, and operands.
351   ///
352   /// Note that getTargetNode returns the resultant node.  If there is already a
353   /// node of the specified opcode and operands, it returns that node instead of
354   /// the current one.
355   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT);
356   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
357                         SDOperand Op1);
358   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
359                         SDOperand Op1, SDOperand Op2);
360   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
361                         SDOperand Op1, SDOperand Op2, SDOperand Op3);
362   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
363                         SDOperand Op1, SDOperand Op2, SDOperand Op3,
364                         SDOperand Op4);
365   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
366                         SDOperand Op1, SDOperand Op2, SDOperand Op3,
367                         SDOperand Op4, SDOperand Op5);
368   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
369                         SDOperand Op1, SDOperand Op2, SDOperand Op3,
370                         SDOperand Op4, SDOperand Op5, SDOperand Op6);
371   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
372                         SDOperand Op1, SDOperand Op2, SDOperand Op3,
373                         SDOperand Op4, SDOperand Op5, SDOperand Op6,
374                         SDOperand Op7);
375   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
376                         SDOperand Op1, SDOperand Op2, SDOperand Op3,
377                         SDOperand Op4, SDOperand Op5, SDOperand Op6,
378                         SDOperand Op7, SDOperand Op8);
379   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
380                         const SDOperand *Ops, unsigned NumOps);
381   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
382                         MVT::ValueType VT2, SDOperand Op1);
383   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
384                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
385   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
386                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
387                         SDOperand Op3);
388   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
389                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
390                         SDOperand Op3, SDOperand Op4);
391   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
392                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
393                         SDOperand Op3, SDOperand Op4, SDOperand Op5);
394   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
395                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
396                         SDOperand Op3, SDOperand Op4, SDOperand Op5,
397                         SDOperand Op6);
398   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
399                         MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
400                         SDOperand Op3, SDOperand Op4, SDOperand Op5,
401                         SDOperand Op6, SDOperand Op7);
402   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
403                         MVT::ValueType VT2, MVT::ValueType VT3,
404                         SDOperand Op1, SDOperand Op2);
405   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
406                         MVT::ValueType VT2, MVT::ValueType VT3,
407                         SDOperand Op1, SDOperand Op2,
408                         SDOperand Op3, SDOperand Op4, SDOperand Op5);
409   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
410                         MVT::ValueType VT2, MVT::ValueType VT3,
411                         SDOperand Op1, SDOperand Op2,
412                         SDOperand Op3, SDOperand Op4, SDOperand Op5,
413                         SDOperand Op6);
414   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
415                         MVT::ValueType VT2, MVT::ValueType VT3,
416                         SDOperand Op1, SDOperand Op2,
417                         SDOperand Op3, SDOperand Op4, SDOperand Op5,
418                         SDOperand Op6, SDOperand Op7);
419   SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1, 
420                         MVT::ValueType VT2,
421                         const SDOperand *Ops, unsigned NumOps);
422   
423   /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
424   /// This can cause recursive merging of nodes in the DAG.  Use the first
425   /// version if 'From' is known to have a single result, use the second
426   /// if you have two nodes with identical results, use the third otherwise.
427   ///
428   /// These methods all take an optional vector, which (if not null) is 
429   /// populated with any nodes that are deleted from the SelectionDAG, due to
430   /// new equivalences that are discovered.
431   ///
432   void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
433                           std::vector<SDNode*> *Deleted = 0);
434   void ReplaceAllUsesWith(SDNode *From, SDNode *To,
435                           std::vector<SDNode*> *Deleted = 0);
436   void ReplaceAllUsesWith(SDNode *From, const SDOperand *To,
437                           std::vector<SDNode*> *Deleted = 0);
438
439   /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
440   /// uses of other values produced by From.Val alone.  The Deleted vector is
441   /// handled the same was as for ReplaceAllUsesWith, but it is required for
442   /// this method.
443   void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
444                                  std::vector<SDNode*> &Deleted);
445
446   /// DeleteNode - Remove the specified node from the system.  This node must
447   /// have no referrers.
448   void DeleteNode(SDNode *N);
449
450   /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
451   /// their allnodes order. It returns the maximum id.
452   unsigned AssignNodeIds();
453
454   /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
455   /// based on their topological order. It returns the maximum id and a vector
456   /// of the SDNodes* in assigned order by reference.
457   unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
458
459   void dump() const;
460
461 private:
462   void RemoveNodeFromCSEMaps(SDNode *N);
463   SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
464   SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
465   SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
466                                void *&InsertPos);
467   SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
468                                void *&InsertPos);
469
470   void DeleteNodeNotInCSEMaps(SDNode *N);
471   
472   /// SimplifySetCC - Try to simplify a setcc built with the specified operands 
473   /// and cc.  If unable to simplify it, return a null SDOperand.
474   SDOperand SimplifySetCC(MVT::ValueType VT, SDOperand N1,
475                           SDOperand N2, ISD::CondCode Cond);
476   
477   // List of non-single value types.
478   std::list<std::vector<MVT::ValueType> > VTList;
479   
480   // Maps to auto-CSE operations.
481   std::vector<CondCodeSDNode*> CondCodeNodes;
482
483   std::vector<SDNode*> ValueTypeNodes;
484   std::map<std::string, SDNode*> ExternalSymbols;
485   std::map<std::string, SDNode*> TargetExternalSymbols;
486   std::map<std::string, StringSDNode*> StringNodes;
487 };
488
489 template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
490   typedef SelectionDAG::allnodes_iterator nodes_iterator;
491   static nodes_iterator nodes_begin(SelectionDAG *G) {
492     return G->allnodes_begin();
493   }
494   static nodes_iterator nodes_end(SelectionDAG *G) {
495     return G->allnodes_end();
496   }
497 };
498
499 }  // end namespace llvm
500
501 #endif