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