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