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