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