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