Eliminate some malloc traffic by allocating vectors on the stack. Change some
[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 /// SelectionDAG class - This is used to represent a portion of an LLVM function
34 /// in a low-level Data Dependence DAG representation suitable for instruction
35 /// selection.  This DAG is constructed as the first step of instruction
36 /// selection in order to allow implementation of machine specific optimizations
37 /// and code simplifications.
38 ///
39 /// The representation used by the SelectionDAG is a target-independent
40 /// representation, which has some similarities to the GCC RTL representation,
41 /// but is significantly more simple, powerful, and is a graph form instead of a
42 /// linear form.
43 ///
44 class SelectionDAG {
45   TargetLowering &TLI;
46   MachineFunction &MF;
47   MachineDebugInfo *DI;
48
49   // Root - The root of the entire DAG.  EntryNode - The starting token.
50   SDOperand Root, EntryNode;
51
52   // AllNodes - A linked list of nodes in the current DAG.
53   ilist<SDNode> AllNodes;
54
55   // ValueNodes - track SrcValue nodes
56   std::map<std::pair<const Value*, int>, SDNode*> ValueNodes;
57
58 public:
59   SelectionDAG(TargetLowering &tli, MachineFunction &mf, MachineDebugInfo *di)
60   : TLI(tli), MF(mf), DI(di) {
61     EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
62   }
63   ~SelectionDAG();
64
65   MachineFunction &getMachineFunction() const { return MF; }
66   const TargetMachine &getTarget() const;
67   TargetLowering &getTargetLoweringInfo() const { return TLI; }
68   MachineDebugInfo *getMachineDebugInfo() const { return DI; }
69
70   /// viewGraph - Pop up a ghostview window with the DAG rendered using 'dot'.
71   ///
72   void viewGraph();
73
74
75   typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
76   allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
77   allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
78   typedef ilist<SDNode>::iterator allnodes_iterator;
79   allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
80   allnodes_iterator allnodes_end() { return AllNodes.end(); }
81   
82   /// getRoot - Return the root tag of the SelectionDAG.
83   ///
84   const SDOperand &getRoot() const { return Root; }
85
86   /// getEntryNode - Return the token chain corresponding to the entry of the
87   /// function.
88   const SDOperand &getEntryNode() const { return EntryNode; }
89
90   /// setRoot - Set the current root tag of the SelectionDAG.
91   ///
92   const SDOperand &setRoot(SDOperand N) { return Root = N; }
93
94   /// Combine - This iterates over the nodes in the SelectionDAG, folding
95   /// certain types of nodes together, or eliminating superfluous nodes.  When
96   /// the AfterLegalize argument is set to 'true', Combine takes care not to
97   /// generate any nodes that will be illegal on the target.
98   void Combine(bool AfterLegalize);
99   
100   /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
101   /// compatible with the target instruction selector, as indicated by the
102   /// TargetLowering object.
103   ///
104   /// Note that this is an involved process that may invalidate pointers into
105   /// the graph.
106   void Legalize();
107
108   /// RemoveDeadNodes - This method deletes all unreachable nodes in the
109   /// SelectionDAG.
110   void RemoveDeadNodes();
111
112   SDOperand getString(const std::string &Val);
113   SDOperand getConstant(uint64_t Val, MVT::ValueType VT);
114   SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT);
115   SDOperand getConstantFP(double Val, MVT::ValueType VT);
116   SDOperand getTargetConstantFP(double Val, MVT::ValueType VT);
117   SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
118                              int offset = 0);
119   SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
120                                    int offset = 0);
121   SDOperand getFrameIndex(int FI, MVT::ValueType VT);
122   SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT);
123   SDOperand getJumpTable(int JTI, MVT::ValueType VT);
124   SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT);
125   SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
126                            unsigned Alignment=0,  int offset = 0);
127   SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
128                                   unsigned Alignment=0, int offset = 0);
129   SDOperand getBasicBlock(MachineBasicBlock *MBB);
130   SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
131   SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
132   SDOperand getValueType(MVT::ValueType);
133   SDOperand getRegister(unsigned Reg, MVT::ValueType VT);
134
135   SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
136     return getNode(ISD::CopyToReg, MVT::Other, Chain,
137                    getRegister(Reg, N.getValueType()), N);
138   }
139
140   // This version of the getCopyToReg method takes an extra operand, which
141   // indicates that there is potentially an incoming flag value (if Flag is not
142   // null) and that there should be a flag result.
143   SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
144                          SDOperand Flag) {
145     std::vector<MVT::ValueType> VTs;
146     VTs.push_back(MVT::Other);
147     VTs.push_back(MVT::Flag);
148     std::vector<SDOperand> Ops;
149     Ops.push_back(Chain);
150     Ops.push_back(getRegister(Reg, N.getValueType()));
151     Ops.push_back(N);
152     if (Flag.Val) Ops.push_back(Flag);
153     return getNode(ISD::CopyToReg, VTs, Ops);
154   }
155
156   // Similar to last getCopyToReg() except parameter Reg is a SDOperand
157   SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
158                          SDOperand Flag) {
159     std::vector<MVT::ValueType> VTs;
160     VTs.push_back(MVT::Other);
161     VTs.push_back(MVT::Flag);
162     std::vector<SDOperand> Ops;
163     Ops.push_back(Chain);
164     Ops.push_back(Reg);
165     Ops.push_back(N);
166     if (Flag.Val) Ops.push_back(Flag);
167     return getNode(ISD::CopyToReg, VTs, Ops);
168   }
169   
170   SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT) {
171     std::vector<MVT::ValueType> ResultTys;
172     ResultTys.push_back(VT);
173     ResultTys.push_back(MVT::Other);
174     SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
175     return getNode(ISD::CopyFromReg, ResultTys, Ops, 2);
176   }
177   
178   // This version of the getCopyFromReg method takes an extra operand, which
179   // indicates that there is potentially an incoming flag value (if Flag is not
180   // null) and that there should be a flag result.
181   SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT::ValueType VT,
182                            SDOperand Flag) {
183     std::vector<MVT::ValueType> ResultTys;
184     ResultTys.push_back(VT);
185     ResultTys.push_back(MVT::Other);
186     ResultTys.push_back(MVT::Flag);
187     SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
188     return getNode(ISD::CopyFromReg, ResultTys, Ops, Flag.Val ? 3 : 2);
189   }
190
191   SDOperand getCondCode(ISD::CondCode Cond);
192
193   /// getZeroExtendInReg - Return the expression required to zero extend the Op
194   /// value assuming it was the smaller SrcTy value.
195   SDOperand getZeroExtendInReg(SDOperand Op, MVT::ValueType SrcTy);
196   
197   /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
198   /// a flag result (to ensure it's not CSE'd).
199   SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
200     std::vector<MVT::ValueType> ResultTys;
201     ResultTys.push_back(MVT::Other);
202     ResultTys.push_back(MVT::Flag);
203     SDOperand Ops[] = { Chain,  Op };
204     return getNode(ISD::CALLSEQ_START, ResultTys, Ops, 2);
205   }
206
207   /// getNode - Gets or creates the specified node.
208   ///
209   SDOperand getNode(unsigned Opcode, MVT::ValueType VT);
210   SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N);
211   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
212                     SDOperand N1, SDOperand N2);
213   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
214                     SDOperand N1, SDOperand N2, SDOperand N3);
215   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
216                     SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
217   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
218                     SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
219                     SDOperand N5);
220   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
221                     std::vector<SDOperand> &Children);
222   SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
223                     std::vector<SDOperand> &Ops);
224
225   SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
226                     const SDOperand *Ops, unsigned NumOps);
227   SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
228                     const SDOperand *Ops, unsigned NumOps);
229   
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, SDOperand *Ops, unsigned NumOps);
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, void *&InsertPos);
445   SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
446                                void *&InsertPos);
447   SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
448                                void *&InsertPos);
449
450   void DeleteNodeNotInCSEMaps(SDNode *N);
451   MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1);
452   MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1, MVT::ValueType VT2);
453   MVT::ValueType *getNodeValueTypes(std::vector<MVT::ValueType> &RetVals);
454   
455   
456   /// SimplifySetCC - Try to simplify a setcc built with the specified operands 
457   /// and cc.  If unable to simplify it, return a null SDOperand.
458   SDOperand SimplifySetCC(MVT::ValueType VT, SDOperand N1,
459                           SDOperand N2, ISD::CondCode Cond);
460   
461   // List of non-single value types.
462   std::list<std::vector<MVT::ValueType> > VTList;
463   
464   // Maps to auto-CSE operations.
465   std::map<std::pair<unsigned, MVT::ValueType>, SDNode *> NullaryOps;
466
467   std::map<std::pair<unsigned, MVT::ValueType>, RegisterSDNode*> RegNodes;
468   std::vector<CondCodeSDNode*> CondCodeNodes;
469
470   std::map<std::pair<const GlobalValue*, int>, SDNode*> GlobalValues;
471   std::map<std::pair<const GlobalValue*, int>, SDNode*> TargetGlobalValues;
472   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> Constants;
473   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstants;
474   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> ConstantFPs;
475   std::map<std::pair<uint64_t, MVT::ValueType>, SDNode*> TargetConstantFPs;
476   std::map<int, SDNode*> FrameIndices, TargetFrameIndices, JumpTableIndices,
477     TargetJumpTableIndices;
478   std::map<std::pair<Constant *,
479                      std::pair<int, unsigned> >, SDNode*> ConstantPoolIndices;
480   std::map<std::pair<Constant *,
481                  std::pair<int, unsigned> >, SDNode*> TargetConstantPoolIndices;
482   std::map<MachineBasicBlock *, SDNode*> BBNodes;
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   SelectionDAGCSEMap CSEMap;
488 };
489
490 template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
491   typedef SelectionDAG::allnodes_iterator nodes_iterator;
492   static nodes_iterator nodes_begin(SelectionDAG *G) {
493     return G->allnodes_begin();
494   }
495   static nodes_iterator nodes_end(SelectionDAG *G) {
496     return G->allnodes_end();
497   }
498 };
499
500 }  // end namespace llvm
501
502 #endif