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