1 //===-- llvm/CodeGen/SelectionDAG.h - InstSelection DAG ---------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file declares the SelectionDAG class, and transitively defines the
11 // SDNode class and subclasses.
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_CODEGEN_SELECTIONDAG_H
16 #define LLVM_CODEGEN_SELECTIONDAG_H
18 #include "llvm/ADT/FoldingSet.h"
19 #include "llvm/ADT/ilist.h"
20 #include "llvm/CodeGen/SelectionDAGNodes.h"
31 class MachineModuleInfo;
32 class MachineFunction;
33 class MachineConstantPoolValue;
34 class FunctionLoweringInfo;
36 /// SelectionDAG class - This is used to represent a portion of an LLVM function
37 /// in a low-level Data Dependence DAG representation suitable for instruction
38 /// selection. This DAG is constructed as the first step of instruction
39 /// selection in order to allow implementation of machine specific optimizations
40 /// and code simplifications.
42 /// The representation used by the SelectionDAG is a target-independent
43 /// representation, which has some similarities to the GCC RTL representation,
44 /// but is significantly more simple, powerful, and is a graph form instead of a
50 FunctionLoweringInfo &FLI;
51 MachineModuleInfo *MMI;
53 /// Root - The root of the entire DAG. EntryNode - The starting token.
54 SDOperand Root, EntryNode;
56 /// AllNodes - A linked list of nodes in the current DAG.
57 ilist<SDNode> AllNodes;
59 /// CSEMap - This structure is used to memoize nodes, automatically performing
60 /// CSE with existing nodes with a duplicate is requested.
61 FoldingSet<SDNode> CSEMap;
64 SelectionDAG(TargetLowering &tli, MachineFunction &mf,
65 FunctionLoweringInfo &fli, MachineModuleInfo *mmi)
66 : TLI(tli), MF(mf), FLI(fli), MMI(mmi) {
67 EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
71 MachineFunction &getMachineFunction() const { return MF; }
72 const TargetMachine &getTarget() const;
73 TargetLowering &getTargetLoweringInfo() const { return TLI; }
74 FunctionLoweringInfo &getFunctionLoweringInfo() const { return FLI; }
75 MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
77 /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
82 std::map<const SDNode *, std::string> NodeGraphAttrs;
85 /// clearGraphAttrs - Clear all previously defined node graph attributes.
86 /// Intended to be used from a debugging tool (eg. gdb).
87 void clearGraphAttrs();
89 /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
91 void setGraphAttrs(const SDNode *N, const char *Attrs);
93 /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
94 /// Used from getNodeAttributes.
95 const std::string getGraphAttrs(const SDNode *N) const;
97 /// setGraphColor - Convenience for setting node color attribute.
99 void setGraphColor(const SDNode *N, const char *Color);
101 typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
102 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
103 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
104 typedef ilist<SDNode>::iterator allnodes_iterator;
105 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
106 allnodes_iterator allnodes_end() { return AllNodes.end(); }
108 /// getRoot - Return the root tag of the SelectionDAG.
110 const SDOperand &getRoot() const { return Root; }
112 /// getEntryNode - Return the token chain corresponding to the entry of the
114 const SDOperand &getEntryNode() const { return EntryNode; }
116 /// setRoot - Set the current root tag of the SelectionDAG.
118 const SDOperand &setRoot(SDOperand N) { return Root = N; }
120 /// Combine - This iterates over the nodes in the SelectionDAG, folding
121 /// certain types of nodes together, or eliminating superfluous nodes. When
122 /// the AfterLegalize argument is set to 'true', Combine takes care not to
123 /// generate any nodes that will be illegal on the target.
124 void Combine(bool AfterLegalize, AliasAnalysis &AA);
126 /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
127 /// only uses types natively supported by the target.
129 /// Note that this is an involved process that may invalidate pointers into
131 void LegalizeTypes();
133 /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
134 /// compatible with the target instruction selector, as indicated by the
135 /// TargetLowering object.
137 /// Note that this is an involved process that may invalidate pointers into
141 /// RemoveDeadNodes - This method deletes all unreachable nodes in the
143 void RemoveDeadNodes();
145 /// DeleteNode - Remove the specified node from the system. This node must
146 /// have no referrers.
147 void DeleteNode(SDNode *N);
149 /// getVTList - Return an SDVTList that represents the list of values
151 SDVTList getVTList(MVT VT);
152 SDVTList getVTList(MVT VT1, MVT VT2);
153 SDVTList getVTList(MVT VT1, MVT VT2, MVT VT3);
154 SDVTList getVTList(const MVT *VTs, unsigned NumVTs);
156 /// getNodeValueTypes - These are obsolete, use getVTList instead.
157 const MVT *getNodeValueTypes(MVT VT) {
158 return getVTList(VT).VTs;
160 const MVT *getNodeValueTypes(MVT VT1, MVT VT2) {
161 return getVTList(VT1, VT2).VTs;
163 const MVT *getNodeValueTypes(MVT VT1, MVT VT2, MVT VT3) {
164 return getVTList(VT1, VT2, VT3).VTs;
166 const MVT *getNodeValueTypes(std::vector<MVT> &vtList) {
167 return getVTList(&vtList[0], (unsigned)vtList.size()).VTs;
171 //===--------------------------------------------------------------------===//
172 // Node creation methods.
174 SDOperand getString(const std::string &Val);
175 SDOperand getConstant(uint64_t Val, MVT VT, bool isTarget = false);
176 SDOperand getConstant(const APInt &Val, MVT VT, bool isTarget = false);
177 SDOperand getIntPtrConstant(uint64_t Val, bool isTarget = false);
178 SDOperand getTargetConstant(uint64_t Val, MVT VT) {
179 return getConstant(Val, VT, true);
181 SDOperand getTargetConstant(const APInt &Val, MVT VT) {
182 return getConstant(Val, VT, true);
184 SDOperand getConstantFP(double Val, MVT VT, bool isTarget = false);
185 SDOperand getConstantFP(const APFloat& Val, MVT VT, bool isTarget = false);
186 SDOperand getTargetConstantFP(double Val, MVT VT) {
187 return getConstantFP(Val, VT, true);
189 SDOperand getTargetConstantFP(const APFloat& Val, MVT VT) {
190 return getConstantFP(Val, VT, true);
192 SDOperand getGlobalAddress(const GlobalValue *GV, MVT VT,
193 int offset = 0, bool isTargetGA = false);
194 SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT VT,
196 return getGlobalAddress(GV, VT, offset, true);
198 SDOperand getFrameIndex(int FI, MVT VT, bool isTarget = false);
199 SDOperand getTargetFrameIndex(int FI, MVT VT) {
200 return getFrameIndex(FI, VT, true);
202 SDOperand getJumpTable(int JTI, MVT VT, bool isTarget = false);
203 SDOperand getTargetJumpTable(int JTI, MVT VT) {
204 return getJumpTable(JTI, VT, true);
206 SDOperand getConstantPool(Constant *C, MVT VT,
207 unsigned Align = 0, int Offs = 0, bool isT=false);
208 SDOperand getTargetConstantPool(Constant *C, MVT VT,
209 unsigned Align = 0, int Offset = 0) {
210 return getConstantPool(C, VT, Align, Offset, true);
212 SDOperand getConstantPool(MachineConstantPoolValue *C, MVT VT,
213 unsigned Align = 0, int Offs = 0, bool isT=false);
214 SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
215 MVT VT, unsigned Align = 0,
217 return getConstantPool(C, VT, Align, Offset, true);
219 SDOperand getBasicBlock(MachineBasicBlock *MBB);
220 SDOperand getExternalSymbol(const char *Sym, MVT VT);
221 SDOperand getTargetExternalSymbol(const char *Sym, MVT VT);
222 SDOperand getArgFlags(ISD::ArgFlagsTy Flags);
223 SDOperand getValueType(MVT);
224 SDOperand getRegister(unsigned Reg, MVT VT);
226 SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N) {
227 return getNode(ISD::CopyToReg, MVT::Other, Chain,
228 getRegister(Reg, N.getValueType()), N);
231 // This version of the getCopyToReg method takes an extra operand, which
232 // indicates that there is potentially an incoming flag value (if Flag is not
233 // null) and that there should be a flag result.
234 SDOperand getCopyToReg(SDOperand Chain, unsigned Reg, SDOperand N,
236 const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
237 SDOperand Ops[] = { Chain, getRegister(Reg, N.getValueType()), N, Flag };
238 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
241 // Similar to last getCopyToReg() except parameter Reg is a SDOperand
242 SDOperand getCopyToReg(SDOperand Chain, SDOperand Reg, SDOperand N,
244 const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
245 SDOperand Ops[] = { Chain, Reg, N, Flag };
246 return getNode(ISD::CopyToReg, VTs, 2, Ops, Flag.Val ? 4 : 3);
249 SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT) {
250 const MVT *VTs = getNodeValueTypes(VT, MVT::Other);
251 SDOperand Ops[] = { Chain, getRegister(Reg, VT) };
252 return getNode(ISD::CopyFromReg, VTs, 2, Ops, 2);
255 // This version of the getCopyFromReg method takes an extra operand, which
256 // indicates that there is potentially an incoming flag value (if Flag is not
257 // null) and that there should be a flag result.
258 SDOperand getCopyFromReg(SDOperand Chain, unsigned Reg, MVT VT,
260 const MVT *VTs = getNodeValueTypes(VT, MVT::Other, MVT::Flag);
261 SDOperand Ops[] = { Chain, getRegister(Reg, VT), Flag };
262 return getNode(ISD::CopyFromReg, VTs, 3, Ops, Flag.Val ? 3 : 2);
265 SDOperand getCondCode(ISD::CondCode Cond);
267 /// getZeroExtendInReg - Return the expression required to zero extend the Op
268 /// value assuming it was the smaller SrcTy value.
269 SDOperand getZeroExtendInReg(SDOperand Op, MVT SrcTy);
271 /// getCALLSEQ_START - Return a new CALLSEQ_START node, which always must have
272 /// a flag result (to ensure it's not CSE'd).
273 SDOperand getCALLSEQ_START(SDOperand Chain, SDOperand Op) {
274 const MVT *VTs = getNodeValueTypes(MVT::Other, MVT::Flag);
275 SDOperand Ops[] = { Chain, Op };
276 return getNode(ISD::CALLSEQ_START, VTs, 2, Ops, 2);
279 /// getCALLSEQ_END - Return a new CALLSEQ_END node, which always must have a
280 /// flag result (to ensure it's not CSE'd).
281 SDOperand getCALLSEQ_END(SDOperand Chain, SDOperand Op1, SDOperand Op2,
283 SDVTList NodeTys = getVTList(MVT::Other, MVT::Flag);
284 SmallVector<SDOperand, 4> Ops;
285 Ops.push_back(Chain);
288 Ops.push_back(InFlag);
289 return getNode(ISD::CALLSEQ_END, NodeTys, &Ops[0],
290 (unsigned)Ops.size() - (InFlag.Val == 0 ? 1 : 0));
293 /// getNode - Gets or creates the specified node.
295 SDOperand getNode(unsigned Opcode, MVT VT);
296 SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N);
297 SDOperand getNode(unsigned Opcode, MVT VT, SDOperand N1, SDOperand N2);
298 SDOperand getNode(unsigned Opcode, MVT VT,
299 SDOperand N1, SDOperand N2, SDOperand N3);
300 SDOperand getNode(unsigned Opcode, MVT VT,
301 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
302 SDOperand getNode(unsigned Opcode, MVT VT,
303 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
305 SDOperand getNode(unsigned Opcode, MVT VT, SDOperandPtr Ops, unsigned NumOps);
306 SDOperand getNode(unsigned Opcode, std::vector<MVT> &ResultTys,
307 SDOperandPtr Ops, unsigned NumOps);
308 SDOperand getNode(unsigned Opcode, const MVT *VTs, unsigned NumVTs,
309 SDOperandPtr Ops, unsigned NumOps);
310 SDOperand getNode(unsigned Opcode, SDVTList VTs);
311 SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N);
312 SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N1, SDOperand N2);
313 SDOperand getNode(unsigned Opcode, SDVTList VTs,
314 SDOperand N1, SDOperand N2, SDOperand N3);
315 SDOperand getNode(unsigned Opcode, SDVTList VTs,
316 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
317 SDOperand getNode(unsigned Opcode, SDVTList VTs,
318 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
320 SDOperand getNode(unsigned Opcode, SDVTList VTs,
321 SDOperandPtr Ops, unsigned NumOps);
323 SDOperand getMemcpy(SDOperand Chain, SDOperand Dst, SDOperand Src,
324 SDOperand Size, unsigned Align,
326 const Value *DstSV, uint64_t DstSVOff,
327 const Value *SrcSV, uint64_t SrcSVOff);
329 SDOperand getMemmove(SDOperand Chain, SDOperand Dst, SDOperand Src,
330 SDOperand Size, unsigned Align,
331 const Value *DstSV, uint64_t DstOSVff,
332 const Value *SrcSV, uint64_t SrcSVOff);
334 SDOperand getMemset(SDOperand Chain, SDOperand Dst, SDOperand Src,
335 SDOperand Size, unsigned Align,
336 const Value *DstSV, uint64_t DstSVOff);
338 /// getSetCC - Helper function to make it easier to build SetCC's if you just
339 /// have an ISD::CondCode instead of an SDOperand.
341 SDOperand getSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
342 ISD::CondCode Cond) {
343 return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
346 /// getVSetCC - Helper function to make it easier to build VSetCC's nodes
347 /// if you just have an ISD::CondCode instead of an SDOperand.
349 SDOperand getVSetCC(MVT VT, SDOperand LHS, SDOperand RHS,
350 ISD::CondCode Cond) {
351 return getNode(ISD::VSETCC, VT, LHS, RHS, getCondCode(Cond));
354 /// getSelectCC - Helper function to make it easier to build SelectCC's if you
355 /// just have an ISD::CondCode instead of an SDOperand.
357 SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
358 SDOperand True, SDOperand False, ISD::CondCode Cond) {
359 return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
363 /// getVAArg - VAArg produces a result and token chain, and takes a pointer
364 /// and a source value as input.
365 SDOperand getVAArg(MVT VT, SDOperand Chain, SDOperand Ptr,
368 /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
370 SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
371 SDOperand Cmp, SDOperand Swp, MVT VT);
373 /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
375 SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
376 SDOperand Val, MVT VT);
378 /// getLoad - Loads are not normal binary operators: their result type is not
379 /// determined by their operands, and they produce a value AND a token chain.
381 SDOperand getLoad(MVT VT, SDOperand Chain, SDOperand Ptr,
382 const Value *SV, int SVOffset, bool isVolatile=false,
383 unsigned Alignment=0);
384 SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT VT,
385 SDOperand Chain, SDOperand Ptr, const Value *SV,
386 int SVOffset, MVT EVT, bool isVolatile=false,
387 unsigned Alignment=0);
388 SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
389 SDOperand Offset, ISD::MemIndexedMode AM);
390 SDOperand getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
391 MVT VT, SDOperand Chain,
392 SDOperand Ptr, SDOperand Offset,
393 const Value *SV, int SVOffset, MVT EVT,
394 bool isVolatile=false, unsigned Alignment=0);
396 /// getStore - Helper function to build ISD::STORE nodes.
398 SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
399 const Value *SV, int SVOffset, bool isVolatile=false,
400 unsigned Alignment=0);
401 SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
402 const Value *SV, int SVOffset, MVT TVT,
403 bool isVolatile=false, unsigned Alignment=0);
404 SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
405 SDOperand Offset, ISD::MemIndexedMode AM);
407 // getSrcValue - Construct a node to track a Value* through the backend.
408 SDOperand getSrcValue(const Value *v);
410 // getMemOperand - Construct a node to track a memory reference
411 // through the backend.
412 SDOperand getMemOperand(const MachineMemOperand &MO);
414 /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
415 /// specified operands. If the resultant node already exists in the DAG,
416 /// this does not modify the specified node, instead it returns the node that
417 /// already exists. If the resultant node does not exist in the DAG, the
418 /// input node is returned. As a degenerate case, if you specify the same
419 /// input operands as the node already has, the input node is returned.
420 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
421 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
422 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
424 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
425 SDOperand Op3, SDOperand Op4);
426 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
427 SDOperand Op3, SDOperand Op4, SDOperand Op5);
428 SDOperand UpdateNodeOperands(SDOperand N, SDOperandPtr Ops, unsigned NumOps);
430 /// SelectNodeTo - These are used for target selectors to *mutate* the
431 /// specified node to have the specified return type, Target opcode, and
432 /// operands. Note that target opcodes are stored as
433 /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field. The 0th value
434 /// of the resultant node is returned.
435 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT);
436 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT, SDOperand Op1);
437 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
438 SDOperand Op1, SDOperand Op2);
439 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
440 SDOperand Op1, SDOperand Op2, SDOperand Op3);
441 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT,
442 SDOperandPtr Ops, unsigned NumOps);
443 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
444 MVT VT2, SDOperand Op1, SDOperand Op2);
445 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT VT1,
446 MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
449 /// getTargetNode - These are used for target selectors to create a new node
450 /// with specified return type(s), target opcode, and operands.
452 /// Note that getTargetNode returns the resultant node. If there is already a
453 /// node of the specified opcode and operands, it returns that node instead of
455 SDNode *getTargetNode(unsigned Opcode, MVT VT);
456 SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1);
457 SDNode *getTargetNode(unsigned Opcode, MVT VT, SDOperand Op1, SDOperand Op2);
458 SDNode *getTargetNode(unsigned Opcode, MVT VT,
459 SDOperand Op1, SDOperand Op2, SDOperand Op3);
460 SDNode *getTargetNode(unsigned Opcode, MVT VT,
461 SDOperandPtr Ops, unsigned NumOps);
462 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2);
463 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, SDOperand Op1);
464 SDNode *getTargetNode(unsigned Opcode, MVT VT1,
465 MVT VT2, SDOperand Op1, SDOperand Op2);
466 SDNode *getTargetNode(unsigned Opcode, MVT VT1,
467 MVT VT2, SDOperand Op1, SDOperand Op2, SDOperand Op3);
468 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2,
469 SDOperandPtr Ops, unsigned NumOps);
470 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
471 SDOperand Op1, SDOperand Op2);
472 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
473 SDOperand Op1, SDOperand Op2, SDOperand Op3);
474 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3,
475 SDOperandPtr Ops, unsigned NumOps);
476 SDNode *getTargetNode(unsigned Opcode, MVT VT1, MVT VT2, MVT VT3, MVT VT4,
477 SDOperandPtr Ops, unsigned NumOps);
478 SDNode *getTargetNode(unsigned Opcode, std::vector<MVT> &ResultTys,
479 SDOperandPtr Ops, unsigned NumOps);
481 /// getNodeIfExists - Get the specified node if it's already available, or
482 /// else return NULL.
483 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
484 SDOperandPtr Ops, unsigned NumOps);
486 /// DAGUpdateListener - Clients of various APIs that cause global effects on
487 /// the DAG can optionally implement this interface. This allows the clients
488 /// to handle the various sorts of updates that happen.
489 class DAGUpdateListener {
491 virtual ~DAGUpdateListener();
493 /// NodeDeleted - The node N that was deleted and, if E is not null, an
494 /// equivalent node E that replaced it.
495 virtual void NodeDeleted(SDNode *N, SDNode *E) = 0;
497 /// NodeUpdated - The node N that was updated.
498 virtual void NodeUpdated(SDNode *N) = 0;
501 /// RemoveDeadNode - Remove the specified node from the system. If any of its
502 /// operands then becomes dead, remove them as well. Inform UpdateListener
503 /// for each node deleted.
504 void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
506 /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
507 /// This can cause recursive merging of nodes in the DAG. Use the first
508 /// version if 'From' is known to have a single result, use the second
509 /// if you have two nodes with identical results, use the third otherwise.
511 /// These methods all take an optional UpdateListener, which (if not null) is
512 /// informed about nodes that are deleted and modified due to recursive
513 /// changes in the dag.
515 void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
516 DAGUpdateListener *UpdateListener = 0);
517 void ReplaceAllUsesWith(SDNode *From, SDNode *To,
518 DAGUpdateListener *UpdateListener = 0);
519 void ReplaceAllUsesWith(SDNode *From, SDOperandPtr To,
520 DAGUpdateListener *UpdateListener = 0);
522 /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
523 /// uses of other values produced by From.Val alone.
524 void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
525 DAGUpdateListener *UpdateListener = 0);
527 /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
528 /// their allnodes order. It returns the maximum id.
529 unsigned AssignNodeIds();
531 /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
532 /// based on their topological order. It returns the maximum id and a vector
533 /// of the SDNodes* in assigned order by reference.
534 unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
536 /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
538 static bool isCommutativeBinOp(unsigned Opcode) {
539 // FIXME: This should get its info from the td file, so that we can include
554 case ISD::ADDE: return true;
555 default: return false;
561 /// CreateStackTemporary - Create a stack temporary, suitable for holding the
562 /// specified value type.
563 SDOperand CreateStackTemporary(MVT VT);
565 /// FoldSetCC - Constant fold a setcc to true or false.
566 SDOperand FoldSetCC(MVT VT, SDOperand N1,
567 SDOperand N2, ISD::CondCode Cond);
569 /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We
570 /// use this predicate to simplify operations downstream.
571 bool SignBitIsZero(SDOperand Op, unsigned Depth = 0) const;
573 /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We
574 /// use this predicate to simplify operations downstream. Op and Mask are
575 /// known to be the same type.
576 bool MaskedValueIsZero(SDOperand Op, const APInt &Mask, unsigned Depth = 0)
579 /// ComputeMaskedBits - Determine which of the bits specified in Mask are
580 /// known to be either zero or one and return them in the KnownZero/KnownOne
581 /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
582 /// processing. Targets can implement the computeMaskedBitsForTargetNode
583 /// method in the TargetLowering class to allow target nodes to be understood.
584 void ComputeMaskedBits(SDOperand Op, const APInt &Mask, APInt &KnownZero,
585 APInt &KnownOne, unsigned Depth = 0) const;
587 /// ComputeNumSignBits - Return the number of times the sign bit of the
588 /// register is replicated into the other bits. We know that at least 1 bit
589 /// is always equal to the sign bit (itself), but other cases can give us
590 /// information. For example, immediately after an "SRA X, 2", we know that
591 /// the top 3 bits are all equal to each other, so we return 3. Targets can
592 /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
593 /// class to allow target nodes to be understood.
594 unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
596 /// isVerifiedDebugInfoDesc - Returns true if the specified SDOperand has
597 /// been verified as a debug information descriptor.
598 bool isVerifiedDebugInfoDesc(SDOperand Op) const;
600 /// getShuffleScalarElt - Returns the scalar element that will make up the ith
601 /// element of the result of the vector shuffle.
602 SDOperand getShuffleScalarElt(const SDNode *N, unsigned Idx);
605 void RemoveNodeFromCSEMaps(SDNode *N);
606 SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
607 SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
608 SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
610 SDNode *FindModifiedNodeSlot(SDNode *N, SDOperandPtr Ops, unsigned NumOps,
613 void DeleteNodeNotInCSEMaps(SDNode *N);
615 // List of non-single value types.
616 std::list<std::vector<MVT> > VTList;
618 // Maps to auto-CSE operations.
619 std::vector<CondCodeSDNode*> CondCodeNodes;
621 std::vector<SDNode*> ValueTypeNodes;
622 std::map<MVT, SDNode*, MVT::compareRawBits> ExtendedValueTypeNodes;
623 std::map<std::string, SDNode*> ExternalSymbols;
624 std::map<std::string, SDNode*> TargetExternalSymbols;
625 std::map<std::string, StringSDNode*> StringNodes;
628 template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
629 typedef SelectionDAG::allnodes_iterator nodes_iterator;
630 static nodes_iterator nodes_begin(SelectionDAG *G) {
631 return G->allnodes_begin();
633 static nodes_iterator nodes_end(SelectionDAG *G) {
634 return G->allnodes_end();
638 } // end namespace llvm