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