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