When XDEBUG is enabled, check for SelectionDAG cycles at some key
[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 is distributed under the University of Illinois Open Source
6 // 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/ADT/ilist.h"
19 #include "llvm/ADT/DenseSet.h"
20 #include "llvm/ADT/StringMap.h"
21 #include "llvm/CodeGen/SelectionDAGNodes.h"
22 #include "llvm/Support/RecyclingAllocator.h"
23 #include "llvm/Target/TargetMachine.h"
24 #include <cassert>
25 #include <vector>
26 #include <map>
27 #include <string>
28
29 namespace llvm {
30
31 class AliasAnalysis;
32 class DwarfWriter;
33 class FunctionLoweringInfo;
34 class MachineConstantPoolValue;
35 class MachineFunction;
36 class MachineModuleInfo;
37 class SDNodeOrdering;
38 class TargetLowering;
39
40 template<> struct ilist_traits<SDNode> : public ilist_default_traits<SDNode> {
41 private:
42   mutable ilist_half_node<SDNode> Sentinel;
43 public:
44   SDNode *createSentinel() const {
45     return static_cast<SDNode*>(&Sentinel);
46   }
47   static void destroySentinel(SDNode *) {}
48
49   SDNode *provideInitialHead() const { return createSentinel(); }
50   SDNode *ensureHead(SDNode*) const { return createSentinel(); }
51   static void noteHead(SDNode*, SDNode*) {}
52
53   static void deleteNode(SDNode *) {
54     assert(0 && "ilist_traits<SDNode> shouldn't see a deleteNode call!");
55   }
56 private:
57   static void createNode(const SDNode &);
58 };
59
60 enum CombineLevel {
61   Unrestricted,   // Combine may create illegal operations and illegal types.
62   NoIllegalTypes, // Combine may create illegal operations but no illegal types.
63   NoIllegalOperations // Combine may only create legal operations and types.
64 };
65
66 class SelectionDAG;
67 void checkForCycles(const SDNode *N);
68 void checkForCycles(const SelectionDAG *DAG);
69
70 /// SelectionDAG class - This is used to represent a portion of an LLVM function
71 /// in a low-level Data Dependence DAG representation suitable for instruction
72 /// selection.  This DAG is constructed as the first step of instruction
73 /// selection in order to allow implementation of machine specific optimizations
74 /// and code simplifications.
75 ///
76 /// The representation used by the SelectionDAG is a target-independent
77 /// representation, which has some similarities to the GCC RTL representation,
78 /// but is significantly more simple, powerful, and is a graph form instead of a
79 /// linear form.
80 ///
81 class SelectionDAG {
82   TargetLowering &TLI;
83   MachineFunction *MF;
84   FunctionLoweringInfo &FLI;
85   MachineModuleInfo *MMI;
86   DwarfWriter *DW;
87   LLVMContext* Context;
88
89   /// EntryNode - The starting token.
90   SDNode EntryNode;
91
92   /// Root - The root of the entire DAG.
93   SDValue Root;
94
95   /// AllNodes - A linked list of nodes in the current DAG.
96   ilist<SDNode> AllNodes;
97
98   /// NodeAllocatorType - The AllocatorType for allocating SDNodes. We use
99   /// pool allocation with recycling.
100   typedef RecyclingAllocator<BumpPtrAllocator, SDNode, sizeof(LargestSDNode),
101                              AlignOf<MostAlignedSDNode>::Alignment>
102     NodeAllocatorType;
103
104   /// NodeAllocator - Pool allocation for nodes.
105   NodeAllocatorType NodeAllocator;
106
107   /// CSEMap - This structure is used to memoize nodes, automatically performing
108   /// CSE with existing nodes when a duplicate is requested.
109   FoldingSet<SDNode> CSEMap;
110
111   /// OperandAllocator - Pool allocation for machine-opcode SDNode operands.
112   BumpPtrAllocator OperandAllocator;
113
114   /// Allocator - Pool allocation for misc. objects that are created once per
115   /// SelectionDAG.
116   BumpPtrAllocator Allocator;
117
118   /// SDNodeOrdering - The ordering of the SDNodes. It roughly corresponds to
119   /// the ordering of the original LLVM instructions.
120   SDNodeOrdering *Ordering;
121
122   /// VerifyNode - Sanity check the given node.  Aborts if it is invalid.
123   void VerifyNode(SDNode *N);
124
125   /// setGraphColorHelper - Implementation of setSubgraphColor.
126   /// Return whether we had to truncate the search.
127   ///
128   bool setSubgraphColorHelper(SDNode *N, const char *Color,
129                               DenseSet<SDNode *> &visited,
130                               int level, bool &printed);
131
132   void operator=(const SelectionDAG&); // Do not implement.
133   SelectionDAG(const SelectionDAG&);   // Do not implement.
134
135 public:
136   SelectionDAG(TargetLowering &tli, FunctionLoweringInfo &fli);
137   ~SelectionDAG();
138
139   /// init - Prepare this SelectionDAG to process code in the given
140   /// MachineFunction.
141   ///
142   void init(MachineFunction &mf, MachineModuleInfo *mmi, DwarfWriter *dw);
143
144   /// clear - Clear state and free memory necessary to make this
145   /// SelectionDAG ready to process a new block.
146   ///
147   void clear();
148
149   MachineFunction &getMachineFunction() const { return *MF; }
150   const TargetMachine &getTarget() const;
151   TargetLowering &getTargetLoweringInfo() const { return TLI; }
152   FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; }
153   MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
154   DwarfWriter *getDwarfWriter() const { return DW; }
155   LLVMContext *getContext() const {return Context; }
156
157   /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
158   ///
159   void viewGraph(const std::string &Title);
160   void viewGraph();
161
162 #ifndef NDEBUG
163   std::map<const SDNode *, std::string> NodeGraphAttrs;
164 #endif
165
166   /// clearGraphAttrs - Clear all previously defined node graph attributes.
167   /// Intended to be used from a debugging tool (eg. gdb).
168   void clearGraphAttrs();
169
170   /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
171   ///
172   void setGraphAttrs(const SDNode *N, const char *Attrs);
173
174   /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
175   /// Used from getNodeAttributes.
176   const std::string getGraphAttrs(const SDNode *N) const;
177
178   /// setGraphColor - Convenience for setting node color attribute.
179   ///
180   void setGraphColor(const SDNode *N, const char *Color);
181
182   /// setGraphColor - Convenience for setting subgraph color attribute.
183   ///
184   void setSubgraphColor(SDNode *N, const char *Color);
185
186   typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
187   allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
188   allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
189   typedef ilist<SDNode>::iterator allnodes_iterator;
190   allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
191   allnodes_iterator allnodes_end() { return AllNodes.end(); }
192   ilist<SDNode>::size_type allnodes_size() const {
193     return AllNodes.size();
194   }
195
196   /// getRoot - Return the root tag of the SelectionDAG.
197   ///
198   const SDValue &getRoot() const { return Root; }
199
200   /// getEntryNode - Return the token chain corresponding to the entry of the
201   /// function.
202   SDValue getEntryNode() const {
203     return SDValue(const_cast<SDNode *>(&EntryNode), 0);
204   }
205
206   /// setRoot - Set the current root tag of the SelectionDAG.
207   ///
208   const SDValue &setRoot(SDValue N) {
209     assert((!N.getNode() || N.getValueType() == MVT::Other) &&
210            "DAG root value is not a chain!");
211     if (N.getNode())
212       checkForCycles(N.getNode());
213     Root = N;
214     if (N.getNode())
215       checkForCycles(this);
216     return Root;
217   }
218
219   /// Combine - This iterates over the nodes in the SelectionDAG, folding
220   /// certain types of nodes together, or eliminating superfluous nodes.  The
221   /// Level argument controls whether Combine is allowed to produce nodes and
222   /// types that are illegal on the target.
223   void Combine(CombineLevel Level, AliasAnalysis &AA,
224                CodeGenOpt::Level OptLevel);
225
226   /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
227   /// only uses types natively supported by the target.  Returns "true" if it
228   /// made any changes.
229   ///
230   /// Note that this is an involved process that may invalidate pointers into
231   /// the graph.
232   bool LegalizeTypes();
233
234   /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
235   /// compatible with the target instruction selector, as indicated by the
236   /// TargetLowering object.
237   ///
238   /// Note that this is an involved process that may invalidate pointers into
239   /// the graph.
240   void Legalize(CodeGenOpt::Level OptLevel);
241
242   /// LegalizeVectors - This transforms the SelectionDAG into a SelectionDAG
243   /// that only uses vector math operations supported by the target.  This is
244   /// necessary as a separate step from Legalize because unrolling a vector
245   /// operation can introduce illegal types, which requires running
246   /// LegalizeTypes again.
247   ///
248   /// This returns true if it made any changes; in that case, LegalizeTypes
249   /// is called again before Legalize.
250   ///
251   /// Note that this is an involved process that may invalidate pointers into
252   /// the graph.
253   bool LegalizeVectors();
254
255   /// RemoveDeadNodes - This method deletes all unreachable nodes in the
256   /// SelectionDAG.
257   void RemoveDeadNodes();
258
259   /// DeleteNode - Remove the specified node from the system.  This node must
260   /// have no referrers.
261   void DeleteNode(SDNode *N);
262
263   /// getVTList - Return an SDVTList that represents the list of values
264   /// specified.
265   SDVTList getVTList(EVT VT);
266   SDVTList getVTList(EVT VT1, EVT VT2);
267   SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3);
268   SDVTList getVTList(EVT VT1, EVT VT2, EVT VT3, EVT VT4);
269   SDVTList getVTList(const EVT *VTs, unsigned NumVTs);
270
271   //===--------------------------------------------------------------------===//
272   // Node creation methods.
273   //
274   SDValue getConstant(uint64_t Val, EVT VT, bool isTarget = false);
275   SDValue getConstant(const APInt &Val, EVT VT, bool isTarget = false);
276   SDValue getConstant(const ConstantInt &Val, EVT VT, bool isTarget = false);
277   SDValue getIntPtrConstant(uint64_t Val, bool isTarget = false);
278   SDValue getTargetConstant(uint64_t Val, EVT VT) {
279     return getConstant(Val, VT, true);
280   }
281   SDValue getTargetConstant(const APInt &Val, EVT VT) {
282     return getConstant(Val, VT, true);
283   }
284   SDValue getTargetConstant(const ConstantInt &Val, EVT VT) {
285     return getConstant(Val, VT, true);
286   }
287   SDValue getConstantFP(double Val, EVT VT, bool isTarget = false);
288   SDValue getConstantFP(const APFloat& Val, EVT VT, bool isTarget = false);
289   SDValue getConstantFP(const ConstantFP &CF, EVT VT, bool isTarget = false);
290   SDValue getTargetConstantFP(double Val, EVT VT) {
291     return getConstantFP(Val, VT, true);
292   }
293   SDValue getTargetConstantFP(const APFloat& Val, EVT VT) {
294     return getConstantFP(Val, VT, true);
295   }
296   SDValue getTargetConstantFP(const ConstantFP &Val, EVT VT) {
297     return getConstantFP(Val, VT, true);
298   }
299   SDValue getGlobalAddress(const GlobalValue *GV, EVT VT,
300                            int64_t offset = 0, bool isTargetGA = false,
301                            unsigned char TargetFlags = 0);
302   SDValue getTargetGlobalAddress(const GlobalValue *GV, EVT VT,
303                                  int64_t offset = 0,
304                                  unsigned char TargetFlags = 0) {
305     return getGlobalAddress(GV, VT, offset, true, TargetFlags);
306   }
307   SDValue getFrameIndex(int FI, EVT VT, bool isTarget = false);
308   SDValue getTargetFrameIndex(int FI, EVT VT) {
309     return getFrameIndex(FI, VT, true);
310   }
311   SDValue getJumpTable(int JTI, EVT VT, bool isTarget = false,
312                        unsigned char TargetFlags = 0);
313   SDValue getTargetJumpTable(int JTI, EVT VT, unsigned char TargetFlags = 0) {
314     return getJumpTable(JTI, VT, true, TargetFlags);
315   }
316   SDValue getConstantPool(Constant *C, EVT VT,
317                           unsigned Align = 0, int Offs = 0, bool isT=false,
318                           unsigned char TargetFlags = 0);
319   SDValue getTargetConstantPool(Constant *C, EVT VT,
320                                 unsigned Align = 0, int Offset = 0,
321                                 unsigned char TargetFlags = 0) {
322     return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
323   }
324   SDValue getConstantPool(MachineConstantPoolValue *C, EVT VT,
325                           unsigned Align = 0, int Offs = 0, bool isT=false,
326                           unsigned char TargetFlags = 0);
327   SDValue getTargetConstantPool(MachineConstantPoolValue *C,
328                                   EVT VT, unsigned Align = 0,
329                                   int Offset = 0, unsigned char TargetFlags=0) {
330     return getConstantPool(C, VT, Align, Offset, true, TargetFlags);
331   }
332   // When generating a branch to a BB, we don't in general know enough
333   // to provide debug info for the BB at that time, so keep this one around.
334   SDValue getBasicBlock(MachineBasicBlock *MBB);
335   SDValue getBasicBlock(MachineBasicBlock *MBB, DebugLoc dl);
336   SDValue getExternalSymbol(const char *Sym, EVT VT);
337   SDValue getExternalSymbol(const char *Sym, DebugLoc dl, EVT VT);
338   SDValue getTargetExternalSymbol(const char *Sym, EVT VT,
339                                   unsigned char TargetFlags = 0);
340   SDValue getValueType(EVT);
341   SDValue getRegister(unsigned Reg, EVT VT);
342   SDValue getLabel(unsigned Opcode, DebugLoc dl, SDValue Root,
343                    unsigned LabelID);
344   SDValue getBlockAddress(BlockAddress *BA, EVT VT,
345                           bool isTarget = false, unsigned char TargetFlags = 0);
346
347   SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N) {
348     return getNode(ISD::CopyToReg, dl, MVT::Other, Chain,
349                    getRegister(Reg, N.getValueType()), N);
350   }
351
352   // This version of the getCopyToReg method takes an extra operand, which
353   // indicates that there is potentially an incoming flag value (if Flag is not
354   // null) and that there should be a flag result.
355   SDValue getCopyToReg(SDValue Chain, DebugLoc dl, unsigned Reg, SDValue N,
356                        SDValue Flag) {
357     SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
358     SDValue Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
359     return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
360   }
361
362   // Similar to last getCopyToReg() except parameter Reg is a SDValue
363   SDValue getCopyToReg(SDValue Chain, DebugLoc dl, SDValue Reg, SDValue N,
364                          SDValue Flag) {
365     SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
366     SDValue Ops[] = { Chain, Reg, N, Flag };
367     return getNode(ISD::CopyToReg, dl, VTs, Ops, Flag.getNode() ? 4 : 3);
368   }
369
370   SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, EVT VT) {
371     SDVTList VTs = getVTList(VT, MVT::Other);
372     SDValue Ops[] = { Chain, getRegister(Reg, VT) };
373     return getNode(ISD::CopyFromReg, dl, VTs, Ops, 2);
374   }
375
376   // This version of the getCopyFromReg method takes an extra operand, which
377   // indicates that there is potentially an incoming flag value (if Flag is not
378   // null) and that there should be a flag result.
379   SDValue getCopyFromReg(SDValue Chain, DebugLoc dl, unsigned Reg, EVT VT,
380                            SDValue Flag) {
381     SDVTList VTs = getVTList(VT, MVT::Other, MVT::Flag);
382     SDValue Ops[] = { Chain, getRegister(Reg, VT), Flag };
383     return getNode(ISD::CopyFromReg, dl, VTs, Ops, Flag.getNode() ? 3 : 2);
384   }
385
386   SDValue getCondCode(ISD::CondCode Cond);
387
388   /// Returns the ConvertRndSat Note: Avoid using this node because it may
389   /// disappear in the future and most targets don't support it.
390   SDValue getConvertRndSat(EVT VT, DebugLoc dl, SDValue Val, SDValue DTy,
391                            SDValue STy,
392                            SDValue Rnd, SDValue Sat, ISD::CvtCode Code);
393   
394   /// getVectorShuffle - Return an ISD::VECTOR_SHUFFLE node.  The number of
395   /// elements in VT, which must be a vector type, must match the number of
396   /// mask elements NumElts.  A integer mask element equal to -1 is treated as
397   /// undefined.
398   SDValue getVectorShuffle(EVT VT, DebugLoc dl, SDValue N1, SDValue N2, 
399                            const int *MaskElts);
400
401   /// getSExtOrTrunc - Convert Op, which must be of integer type, to the
402   /// integer type VT, by either sign-extending or truncating it.
403   SDValue getSExtOrTrunc(SDValue Op, DebugLoc DL, EVT VT);
404
405   /// getZExtOrTrunc - Convert Op, which must be of integer type, to the
406   /// integer type VT, by either zero-extending or truncating it.
407   SDValue getZExtOrTrunc(SDValue Op, DebugLoc DL, EVT VT);
408
409   /// getZeroExtendInReg - Return the expression required to zero extend the Op
410   /// value assuming it was the smaller SrcTy value.
411   SDValue getZeroExtendInReg(SDValue Op, DebugLoc DL, EVT SrcTy);
412
413   /// getNOT - Create a bitwise NOT operation as (XOR Val, -1).
414   SDValue getNOT(DebugLoc DL, SDValue Val, EVT VT);
415
416   /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
417   /// a flag result (to ensure it's not CSE'd).  CALLSEQ_START does not have a
418   /// useful DebugLoc.
419   SDValue getCALLSEQ_START(SDValue Chain, SDValue Op) {
420     SDVTList VTs = getVTList(MVT::Other, MVT::Flag);
421     SDValue Ops[] = { Chain,  Op };
422     return getNode(ISD::CALLSEQ_START, DebugLoc::getUnknownLoc(),
423                    VTs, Ops, 2);
424   }
425
426   /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
427   /// flag result (to ensure it's not CSE'd).  CALLSEQ_END does not have
428   /// a useful DebugLoc.
429   SDValue getCALLSEQ_END(SDValue Chain, SDValue Op1, SDValue Op2,
430                            SDValue InFlag) {
431     SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
432     SmallVector<SDValue, 4> Ops;
433     Ops.push_back(Chain);
434     Ops.push_back(Op1);
435     Ops.push_back(Op2);
436     Ops.push_back(InFlag);
437     return getNode(ISD::CALLSEQ_END, DebugLoc::getUnknownLoc(), NodeTys,
438                    &Ops[0],
439                    (unsigned)Ops.size() - (InFlag.getNode() == 0 ? 1 : 0));
440   }
441
442   /// getUNDEF - Return an UNDEF node.  UNDEF does not have a useful DebugLoc.
443   SDValue getUNDEF(EVT VT) {
444     return getNode(ISD::UNDEF, DebugLoc::getUnknownLoc(), VT);
445   }
446
447   /// getGLOBAL_OFFSET_TABLE - Return a GLOBAL_OFFSET_TABLE node.  This does
448   /// not have a useful DebugLoc.
449   SDValue getGLOBAL_OFFSET_TABLE(EVT VT) {
450     return getNode(ISD::GLOBAL_OFFSET_TABLE, DebugLoc::getUnknownLoc(), VT);
451   }
452
453   /// getNode - Gets or creates the specified node.
454   ///
455   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT);
456   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT, SDValue N);
457   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT, SDValue N1, SDValue N2);
458   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
459                   SDValue N1, SDValue N2, SDValue N3);
460   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
461                   SDValue N1, SDValue N2, SDValue N3, SDValue N4);
462   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
463                   SDValue N1, SDValue N2, SDValue N3, SDValue N4,
464                   SDValue N5);
465   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
466                   const SDUse *Ops, unsigned NumOps);
467   SDValue getNode(unsigned Opcode, DebugLoc DL, EVT VT,
468                   const SDValue *Ops, unsigned NumOps);
469   SDValue getNode(unsigned Opcode, DebugLoc DL,
470                   const std::vector<EVT> &ResultTys,
471                   const SDValue *Ops, unsigned NumOps);
472   SDValue getNode(unsigned Opcode, DebugLoc DL, const EVT *VTs, unsigned NumVTs,
473                   const SDValue *Ops, unsigned NumOps);
474   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
475                   const SDValue *Ops, unsigned NumOps);
476   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs);
477   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs, SDValue N);
478   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
479                   SDValue N1, SDValue N2);
480   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
481                   SDValue N1, SDValue N2, SDValue N3);
482   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
483                   SDValue N1, SDValue N2, SDValue N3, SDValue N4);
484   SDValue getNode(unsigned Opcode, DebugLoc DL, SDVTList VTs,
485                   SDValue N1, SDValue N2, SDValue N3, SDValue N4,
486                   SDValue N5);
487
488   /// getStackArgumentTokenFactor - Compute a TokenFactor to force all
489   /// the incoming stack arguments to be loaded from the stack. This is
490   /// used in tail call lowering to protect stack arguments from being
491   /// clobbered.
492   SDValue getStackArgumentTokenFactor(SDValue Chain);
493
494   SDValue getMemcpy(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
495                     SDValue Size, unsigned Align, bool AlwaysInline,
496                     const Value *DstSV, uint64_t DstSVOff,
497                     const Value *SrcSV, uint64_t SrcSVOff);
498
499   SDValue getMemmove(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
500                      SDValue Size, unsigned Align,
501                      const Value *DstSV, uint64_t DstOSVff,
502                      const Value *SrcSV, uint64_t SrcSVOff);
503
504   SDValue getMemset(SDValue Chain, DebugLoc dl, SDValue Dst, SDValue Src,
505                     SDValue Size, unsigned Align,
506                     const Value *DstSV, uint64_t DstSVOff);
507
508   /// getSetCC - Helper function to make it easier to build SetCC's if you just
509   /// have an ISD::CondCode instead of an SDValue.
510   ///
511   SDValue getSetCC(DebugLoc DL, EVT VT, SDValue LHS, SDValue RHS,
512                    ISD::CondCode Cond) {
513     return getNode(ISD::SETCC, DL, VT, LHS, RHS, getCondCode(Cond));
514   }
515
516   /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
517   /// if you just have an ISD::CondCode instead of an SDValue.
518   ///
519   SDValue getVSetCC(DebugLoc DL, EVT VT, SDValue LHS, SDValue RHS,
520                     ISD::CondCode Cond) {
521     return getNode(ISD::VSETCC, DL, VT, LHS, RHS, getCondCode(Cond));
522   }
523
524   /// getSelectCC - Helper function to make it easier to build SelectCC's if you
525   /// just have an ISD::CondCode instead of an SDValue.
526   ///
527   SDValue getSelectCC(DebugLoc DL, SDValue LHS, SDValue RHS,
528                       SDValue True, SDValue False, ISD::CondCode Cond) {
529     return getNode(ISD::SELECT_CC, DL, True.getValueType(),
530                    LHS, RHS, True, False, getCondCode(Cond));
531   }
532
533   /// getVAArg - VAArg produces a result and token chain, and takes a pointer
534   /// and a source value as input.
535   SDValue getVAArg(EVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
536                    SDValue SV);
537
538   /// getAtomic - Gets a node for an atomic op, produces result and chain and
539   /// takes 3 operands
540   SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
541                     SDValue Ptr, SDValue Cmp, SDValue Swp, const Value* PtrVal,
542                     unsigned Alignment=0);
543   SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
544                     SDValue Ptr, SDValue Cmp, SDValue Swp,
545                     MachineMemOperand *MMO);
546
547   /// getAtomic - Gets a node for an atomic op, produces result and chain and
548   /// takes 2 operands.
549   SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
550                     SDValue Ptr, SDValue Val, const Value* PtrVal,
551                     unsigned Alignment = 0);
552   SDValue getAtomic(unsigned Opcode, DebugLoc dl, EVT MemVT, SDValue Chain,
553                     SDValue Ptr, SDValue Val,
554                     MachineMemOperand *MMO);
555
556   /// getMemIntrinsicNode - Creates a MemIntrinsicNode that may produce a
557   /// result and takes a list of operands. Opcode may be INTRINSIC_VOID,
558   /// INTRINSIC_W_CHAIN, or a target-specific opcode with a value not
559   /// less than FIRST_TARGET_MEMORY_OPCODE.
560   SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl,
561                               const EVT *VTs, unsigned NumVTs,
562                               const SDValue *Ops, unsigned NumOps,
563                               EVT MemVT, const Value *srcValue, int SVOff,
564                               unsigned Align = 0, bool Vol = false,
565                               bool ReadMem = true, bool WriteMem = true);
566
567   SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl, SDVTList VTList,
568                               const SDValue *Ops, unsigned NumOps,
569                               EVT MemVT, const Value *srcValue, int SVOff,
570                               unsigned Align = 0, bool Vol = false,
571                               bool ReadMem = true, bool WriteMem = true);
572
573   SDValue getMemIntrinsicNode(unsigned Opcode, DebugLoc dl, SDVTList VTList,
574                               const SDValue *Ops, unsigned NumOps,
575                               EVT MemVT, MachineMemOperand *MMO);
576
577   /// getMergeValues - Create a MERGE_VALUES node from the given operands.
578   SDValue getMergeValues(const SDValue *Ops, unsigned NumOps, DebugLoc dl);
579
580   /// getLoad - Loads are not normal binary operators: their result type is not
581   /// determined by their operands, and they produce a value AND a token chain.
582   ///
583   SDValue getLoad(EVT VT, DebugLoc dl, SDValue Chain, SDValue Ptr,
584                     const Value *SV, int SVOffset, bool isVolatile=false,
585                     unsigned Alignment=0);
586   SDValue getExtLoad(ISD::LoadExtType ExtType, DebugLoc dl, EVT VT,
587                        SDValue Chain, SDValue Ptr, const Value *SV,
588                        int SVOffset, EVT MemVT, bool isVolatile=false,
589                        unsigned Alignment=0);
590   SDValue getIndexedLoad(SDValue OrigLoad, DebugLoc dl, SDValue Base,
591                            SDValue Offset, ISD::MemIndexedMode AM);
592   SDValue getLoad(ISD::MemIndexedMode AM, DebugLoc dl, ISD::LoadExtType ExtType,
593                   EVT VT, SDValue Chain, SDValue Ptr, SDValue Offset,
594                   const Value *SV, int SVOffset, EVT MemVT,
595                   bool isVolatile=false, unsigned Alignment=0);
596   SDValue getLoad(ISD::MemIndexedMode AM, DebugLoc dl, ISD::LoadExtType ExtType,
597                   EVT VT, SDValue Chain, SDValue Ptr, SDValue Offset,
598                   EVT MemVT, MachineMemOperand *MMO);
599
600   /// getStore - Helper function to build ISD::STORE nodes.
601   ///
602   SDValue getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
603                      const Value *SV, int SVOffset, bool isVolatile=false,
604                      unsigned Alignment=0);
605   SDValue getStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
606                    MachineMemOperand *MMO);
607   SDValue getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
608                           const Value *SV, int SVOffset, EVT TVT,
609                           bool isVolatile=false, unsigned Alignment=0);
610   SDValue getTruncStore(SDValue Chain, DebugLoc dl, SDValue Val, SDValue Ptr,
611                         EVT TVT, MachineMemOperand *MMO);
612   SDValue getIndexedStore(SDValue OrigStoe, DebugLoc dl, SDValue Base,
613                            SDValue Offset, ISD::MemIndexedMode AM);
614
615   /// getSrcValue - Construct a node to track a Value* through the backend.
616   SDValue getSrcValue(const Value *v);
617
618   /// getShiftAmountOperand - Return the specified value casted to
619   /// the target's desired shift amount type.
620   SDValue getShiftAmountOperand(SDValue Op);
621
622   /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
623   /// specified operands.  If the resultant node already exists in the DAG,
624   /// this does not modify the specified node, instead it returns the node that
625   /// already exists.  If the resultant node does not exist in the DAG, the
626   /// input node is returned.  As a degenerate case, if you specify the same
627   /// input operands as the node already has, the input node is returned.
628   SDValue UpdateNodeOperands(SDValue N, SDValue Op);
629   SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2);
630   SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
631                                SDValue Op3);
632   SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
633                                SDValue Op3, SDValue Op4);
634   SDValue UpdateNodeOperands(SDValue N, SDValue Op1, SDValue Op2,
635                                SDValue Op3, SDValue Op4, SDValue Op5);
636   SDValue UpdateNodeOperands(SDValue N,
637                                const SDValue *Ops, unsigned NumOps);
638
639   /// SelectNodeTo - These are used for target selectors to *mutate* the
640   /// specified node to have the specified return type, Target opcode, and
641   /// operands.  Note that target opcodes are stored as
642   /// ~TargetOpcode in the node opcode field.  The resultant node is returned.
643   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT);
644   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT, SDValue Op1);
645   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
646                        SDValue Op1, SDValue Op2);
647   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
648                        SDValue Op1, SDValue Op2, SDValue Op3);
649   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT,
650                        const SDValue *Ops, unsigned NumOps);
651   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1, EVT VT2);
652   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
653                        EVT VT2, const SDValue *Ops, unsigned NumOps);
654   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
655                        EVT VT2, EVT VT3, const SDValue *Ops, unsigned NumOps);
656   SDNode *SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT1,
657                        EVT VT2, EVT VT3, EVT VT4, const SDValue *Ops,
658                        unsigned NumOps);
659   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
660                        EVT VT2, SDValue Op1);
661   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
662                        EVT VT2, SDValue Op1, SDValue Op2);
663   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
664                        EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
665   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT1,
666                        EVT VT2, EVT VT3, SDValue Op1, SDValue Op2, SDValue Op3);
667   SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, SDVTList VTs,
668                        const SDValue *Ops, unsigned NumOps);
669
670   /// MorphNodeTo - These *mutate* the specified node to have the specified
671   /// return type, opcode, and operands.
672   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT);
673   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT, SDValue Op1);
674   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT,
675                       SDValue Op1, SDValue Op2);
676   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT,
677                       SDValue Op1, SDValue Op2, SDValue Op3);
678   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT,
679                       const SDValue *Ops, unsigned NumOps);
680   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1, EVT VT2);
681   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1,
682                       EVT VT2, const SDValue *Ops, unsigned NumOps);
683   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1,
684                       EVT VT2, EVT VT3, const SDValue *Ops, unsigned NumOps);
685   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1,
686                       EVT VT2, SDValue Op1);
687   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1,
688                       EVT VT2, SDValue Op1, SDValue Op2);
689   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, EVT VT1,
690                       EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
691   SDNode *MorphNodeTo(SDNode *N, unsigned Opc, SDVTList VTs,
692                       const SDValue *Ops, unsigned NumOps);
693
694   /// getMachineNode - These are used for target selectors to create a new node
695   /// with specified return type(s), MachineInstr opcode, and operands.
696   ///
697   /// Note that getMachineNode returns the resultant node.  If there is already
698   /// a node of the specified opcode and operands, it returns that node instead
699   /// of the current one.
700   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT);
701   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
702                                 SDValue Op1);
703   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
704                                 SDValue Op1, SDValue Op2);
705   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
706                          SDValue Op1, SDValue Op2, SDValue Op3);
707   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT,
708                          const SDValue *Ops, unsigned NumOps);
709   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2);
710   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
711                          SDValue Op1);
712   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1,
713                          EVT VT2, SDValue Op1, SDValue Op2);
714   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1,
715                          EVT VT2, SDValue Op1, SDValue Op2, SDValue Op3);
716   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
717                          const SDValue *Ops, unsigned NumOps);
718   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
719                          EVT VT3, SDValue Op1, SDValue Op2);
720   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
721                          EVT VT3, SDValue Op1, SDValue Op2, SDValue Op3);
722   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
723                          EVT VT3, const SDValue *Ops, unsigned NumOps);
724   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, EVT VT1, EVT VT2,
725                          EVT VT3, EVT VT4, const SDValue *Ops, unsigned NumOps);
726   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl,
727                          const std::vector<EVT> &ResultTys, const SDValue *Ops,
728                          unsigned NumOps);
729   MachineSDNode *getMachineNode(unsigned Opcode, DebugLoc dl, SDVTList VTs,
730                          const SDValue *Ops, unsigned NumOps);
731
732   /// getTargetExtractSubreg - A convenience function for creating
733   /// TargetInstrInfo::EXTRACT_SUBREG nodes.
734   SDValue getTargetExtractSubreg(int SRIdx, DebugLoc DL, EVT VT,
735                                  SDValue Operand);
736
737   /// getTargetInsertSubreg - A convenience function for creating
738   /// TargetInstrInfo::INSERT_SUBREG nodes.
739   SDValue getTargetInsertSubreg(int SRIdx, DebugLoc DL, EVT VT,
740                                 SDValue Operand, SDValue Subreg);
741
742   /// getNodeIfExists - Get the specified node if it's already available, or
743   /// else return NULL.
744   SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
745                           const SDValue *Ops, unsigned NumOps);
746
747   /// DAGUpdateListener - Clients of various APIs that cause global effects on
748   /// the DAG can optionally implement this interface.  This allows the clients
749   /// to handle the various sorts of updates that happen.
750   class DAGUpdateListener {
751   public:
752     virtual ~DAGUpdateListener();
753
754     /// NodeDeleted - The node N that was deleted and, if E is not null, an
755     /// equivalent node E that replaced it.
756     virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
757
758     /// NodeUpdated - The node N that was updated.
759     virtual void NodeUpdated(SDNode *N) = 0;
760   };
761
762   /// RemoveDeadNode - Remove the specified node from the system. If any of its
763   /// operands then becomes dead, remove them as well. Inform UpdateListener
764   /// for each node deleted.
765   void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
766
767   /// RemoveDeadNodes - This method deletes the unreachable nodes in the
768   /// given list, and any nodes that become unreachable as a result.
769   void RemoveDeadNodes(SmallVectorImpl<SDNode *> &DeadNodes,
770                        DAGUpdateListener *UpdateListener = 0);
771
772   /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
773   /// This can cause recursive merging of nodes in the DAG.  Use the first
774   /// version if 'From' is known to have a single result, use the second
775   /// if you have two nodes with identical results (or if 'To' has a superset
776   /// of the results of 'From'), use the third otherwise.
777   ///
778   /// These methods all take an optional UpdateListener, which (if not null) is
779   /// informed about nodes that are deleted and modified due to recursive
780   /// changes in the dag.
781   ///
782   /// These functions only replace all existing uses. It's possible that as
783   /// these replacements are being performed, CSE may cause the From node
784   /// to be given new uses. These new uses of From are left in place, and
785   /// not automatically transfered to To.
786   ///
787   void ReplaceAllUsesWith(SDValue From, SDValue Op,
788                           DAGUpdateListener *UpdateListener = 0);
789   void ReplaceAllUsesWith(SDNode *From, SDNode *To,
790                           DAGUpdateListener *UpdateListener = 0);
791   void ReplaceAllUsesWith(SDNode *From, const SDValue *To,
792                           DAGUpdateListener *UpdateListener = 0);
793
794   /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
795   /// uses of other values produced by From.Val alone.
796   void ReplaceAllUsesOfValueWith(SDValue From, SDValue To,
797                                  DAGUpdateListener *UpdateListener = 0);
798
799   /// ReplaceAllUsesOfValuesWith - Like ReplaceAllUsesOfValueWith, but
800   /// for multiple values at once. This correctly handles the case where
801   /// there is an overlap between the From values and the To values.
802   void ReplaceAllUsesOfValuesWith(const SDValue *From, const SDValue *To,
803                                   unsigned Num,
804                                   DAGUpdateListener *UpdateListener = 0);
805
806   /// AssignTopologicalOrder - Topological-sort the AllNodes list and a
807   /// assign a unique node id for each node in the DAG based on their
808   /// topological order. Returns the number of nodes.
809   unsigned AssignTopologicalOrder();
810
811   /// RepositionNode - Move node N in the AllNodes list to be immediately
812   /// before the given iterator Position. This may be used to update the
813   /// topological ordering when the list of nodes is modified.
814   void RepositionNode(allnodes_iterator Position, SDNode *N) {
815     AllNodes.insert(Position, AllNodes.remove(N));
816   }
817
818   /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
819   /// operation.
820   static bool isCommutativeBinOp(unsigned Opcode) {
821     // FIXME: This should get its info from the td file, so that we can include
822     // target info.
823     switch (Opcode) {
824     case ISD::ADD:
825     case ISD::MUL:
826     case ISD::MULHU:
827     case ISD::MULHS:
828     case ISD::SMUL_LOHI:
829     case ISD::UMUL_LOHI:
830     case ISD::FADD:
831     case ISD::FMUL:
832     case ISD::AND:
833     case ISD::OR:
834     case ISD::XOR:
835     case ISD::SADDO:
836     case ISD::UADDO:
837     case ISD::ADDC:
838     case ISD::ADDE: return true;
839     default: return false;
840     }
841   }
842
843   /// AssignOrdering - Assign an order to the SDNode.
844   void AssignOrdering(SDNode *SD, unsigned Order);
845
846   /// GetOrdering - Get the order for the SDNode.
847   unsigned GetOrdering(const SDNode *SD) const;
848
849   void dump() const;
850
851   /// CreateStackTemporary - Create a stack temporary, suitable for holding the
852   /// specified value type.  If minAlign is specified, the slot size will have
853   /// at least that alignment.
854   SDValue CreateStackTemporary(EVT VT, unsigned minAlign = 1);
855
856   /// CreateStackTemporary - Create a stack temporary suitable for holding
857   /// either of the specified value types.
858   SDValue CreateStackTemporary(EVT VT1, EVT VT2);
859
860   /// FoldConstantArithmetic -
861   SDValue FoldConstantArithmetic(unsigned Opcode,
862                                  EVT VT,
863                                  ConstantSDNode *Cst1,
864                                  ConstantSDNode *Cst2);
865
866   /// FoldSetCC - Constant fold a setcc to true or false.
867   SDValue FoldSetCC(EVT VT, SDValue N1,
868                     SDValue N2, ISD::CondCode Cond, DebugLoc dl);
869
870   /// SignBitIsZero - Return true if the sign bit of Op is known to be zero.  We
871   /// use this predicate to simplify operations downstream.
872   bool SignBitIsZero(SDValue Op, unsigned Depth = 0) const;
873
874   /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero.  We
875   /// use this predicate to simplify operations downstream.  Op and Mask are
876   /// known to be the same type.
877   bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth = 0)
878     const;
879
880   /// ComputeMaskedBits - Determine which of the bits specified in Mask are
881   /// known to be either zero or one and return them in the KnownZero/KnownOne
882   /// bitsets.  This code only analyzes bits in Mask, in order to short-circuit
883   /// processing.  Targets can implement the computeMaskedBitsForTargetNode
884   /// method in the TargetLowering class to allow target nodes to be understood.
885   void ComputeMaskedBits(SDValue Op, const APInt &Mask, APInt &KnownZero,
886                          APInt &KnownOne, unsigned Depth = 0) const;
887
888   /// ComputeNumSignBits - Return the number of times the sign bit of the
889   /// register is replicated into the other bits.  We know that at least 1 bit
890   /// is always equal to the sign bit (itself), but other cases can give us
891   /// information.  For example, immediately after an "SRA X, 2", we know that
892   /// the top 3 bits are all equal to each other, so we return 3.  Targets can
893   /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
894   /// class to allow target nodes to be understood.
895   unsigned ComputeNumSignBits(SDValue Op, unsigned Depth = 0) const;
896
897   /// isKnownNeverNan - Test whether the given SDValue is known to never be NaN.
898   bool isKnownNeverNaN(SDValue Op) const;
899
900   /// isVerifiedDebugInfoDesc - Returns true if the specified SDValue has
901   /// been verified as a debug information descriptor.
902   bool isVerifiedDebugInfoDesc(SDValue Op) const;
903
904   /// getShuffleScalarElt - Returns the scalar element that will make up the ith
905   /// element of the result of the vector shuffle.
906   SDValue getShuffleScalarElt(const ShuffleVectorSDNode *N, unsigned Idx);
907
908   /// UnrollVectorOp - Utility function used by legalize and lowering to
909   /// "unroll" a vector operation by splitting out the scalars and operating
910   /// on each element individually.  If the ResNE is 0, fully unroll the vector
911   /// op. If ResNE is less than the width of the vector op, unroll up to ResNE.
912   /// If the  ResNE is greater than the width of the vector op, unroll the
913   /// vector op and fill the end of the resulting vector with UNDEFS.
914   SDValue UnrollVectorOp(SDNode *N, unsigned ResNE = 0);
915
916   /// isConsecutiveLoad - Return true if LD is loading 'Bytes' bytes from a 
917   /// location that is 'Dist' units away from the location that the 'Base' load 
918   /// is loading from.
919   bool isConsecutiveLoad(LoadSDNode *LD, LoadSDNode *Base,
920                          unsigned Bytes, int Dist) const;
921
922   /// InferPtrAlignment - Infer alignment of a load / store address. Return 0 if
923   /// it cannot be inferred.
924   unsigned InferPtrAlignment(SDValue Ptr) const;
925
926 private:
927   bool RemoveNodeFromCSEMaps(SDNode *N);
928   void AddModifiedNodeToCSEMaps(SDNode *N, DAGUpdateListener *UpdateListener);
929   SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op, void *&InsertPos);
930   SDNode *FindModifiedNodeSlot(SDNode *N, SDValue Op1, SDValue Op2,
931                                void *&InsertPos);
932   SDNode *FindModifiedNodeSlot(SDNode *N, const SDValue *Ops, unsigned NumOps,
933                                void *&InsertPos);
934
935   void DeleteNodeNotInCSEMaps(SDNode *N);
936   void DeallocateNode(SDNode *N);
937
938   unsigned getEVTAlignment(EVT MemoryVT) const;
939
940   void allnodes_clear();
941
942   /// VTList - List of non-single value types.
943   std::vector<SDVTList> VTList;
944
945   /// CondCodeNodes - Maps to auto-CSE operations.
946   std::vector<CondCodeSDNode*> CondCodeNodes;
947
948   std::vector<SDNode*> ValueTypeNodes;
949   std::map<EVT, SDNode*, EVT::compareRawBits> ExtendedValueTypeNodes;
950   StringMap<SDNode*> ExternalSymbols;
951   
952   std::map<std::pair<std::string, unsigned char>,SDNode*> TargetExternalSymbols;
953 };
954
955 template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
956   typedef SelectionDAG::allnodes_iterator nodes_iterator;
957   static nodes_iterator nodes_begin(SelectionDAG *G) {
958     return G->allnodes_begin();
959   }
960   static nodes_iterator nodes_end(SelectionDAG *G) {
961     return G->allnodes_end();
962   }
963 };
964
965 }  // end namespace llvm
966
967 #endif