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