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"
20 #include "llvm/CodeGen/SelectionDAGNodes.h"
32 class MachineModuleInfo;
33 class MachineFunction;
34 class MachineConstantPoolValue;
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 MachineModuleInfo *MMI;
52 /// Root - The root of the entire DAG. EntryNode - The starting token.
53 SDOperand Root, EntryNode;
55 /// AllNodes - A linked list of nodes in the current DAG.
56 ilist<SDNode> AllNodes;
58 /// CSEMap - This structure is used to memoize nodes, automatically performing
59 /// CSE with existing nodes with a duplicate is requested.
60 FoldingSet<SDNode> CSEMap;
63 SelectionDAG(TargetLowering &tli, MachineFunction &mf, MachineModuleInfo *mmi)
64 : TLI(tli), MF(mf), MMI(mmi) {
65 EntryNode = Root = getNode(ISD::EntryToken, MVT::Other);
69 MachineFunction &getMachineFunction() const { return MF; }
70 const TargetMachine &getTarget() const;
71 TargetLowering &getTargetLoweringInfo() const { return TLI; }
72 MachineModuleInfo *getMachineModuleInfo() const { return MMI; }
74 /// viewGraph - Pop up a GraphViz/gv window with the DAG rendered using 'dot'.
79 std::map<const SDNode *, std::string> NodeGraphAttrs;
82 /// clearGraphAttrs - Clear all previously defined node graph attributes.
83 /// Intended to be used from a debugging tool (eg. gdb).
84 void clearGraphAttrs();
86 /// setGraphAttrs - Set graph attributes for a node. (eg. "color=red".)
88 void setGraphAttrs(const SDNode *N, const char *Attrs);
90 /// getGraphAttrs - Get graph attributes for a node. (eg. "color=red".)
91 /// Used from getNodeAttributes.
92 const std::string getGraphAttrs(const SDNode *N) const;
94 /// setGraphColor - Convenience for setting node color attribute.
96 void setGraphColor(const SDNode *N, const char *Color);
98 typedef ilist<SDNode>::const_iterator allnodes_const_iterator;
99 allnodes_const_iterator allnodes_begin() const { return AllNodes.begin(); }
100 allnodes_const_iterator allnodes_end() const { return AllNodes.end(); }
101 typedef ilist<SDNode>::iterator allnodes_iterator;
102 allnodes_iterator allnodes_begin() { return AllNodes.begin(); }
103 allnodes_iterator allnodes_end() { return AllNodes.end(); }
105 /// getRoot - Return the root tag of the SelectionDAG.
107 const SDOperand &getRoot() const { return Root; }
109 /// getEntryNode - Return the token chain corresponding to the entry of the
111 const SDOperand &getEntryNode() const { return EntryNode; }
113 /// setRoot - Set the current root tag of the SelectionDAG.
115 const SDOperand &setRoot(SDOperand N) { return Root = N; }
117 /// Combine - This iterates over the nodes in the SelectionDAG, folding
118 /// certain types of nodes together, or eliminating superfluous nodes. When
119 /// the AfterLegalize argument is set to 'true', Combine takes care not to
120 /// generate any nodes that will be illegal on the target.
121 void Combine(bool AfterLegalize, AliasAnalysis &AA);
123 /// LegalizeTypes - This transforms the SelectionDAG into a SelectionDAG that
124 /// only uses types natively supported by the target.
126 /// Note that this is an involved process that may invalidate pointers into
128 void LegalizeTypes();
130 /// Legalize - This transforms the SelectionDAG into a SelectionDAG that is
131 /// compatible with the target instruction selector, as indicated by the
132 /// TargetLowering object.
134 /// Note that this is an involved process that may invalidate pointers into
138 /// RemoveDeadNodes - This method deletes all unreachable nodes in the
140 void RemoveDeadNodes();
142 /// DeleteNode - Remove the specified node from the system. This node must
143 /// have no referrers.
144 void DeleteNode(SDNode *N);
146 /// getVTList - Return an SDVTList that represents the list of values
148 SDVTList getVTList(MVT::ValueType VT);
149 SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2);
150 SDVTList getVTList(MVT::ValueType VT1, MVT::ValueType VT2,MVT::ValueType VT3);
151 SDVTList getVTList(const MVT::ValueType *VTs, unsigned NumVTs);
153 /// getNodeValueTypes - These are obsolete, use getVTList instead.
154 const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT) {
155 return getVTList(VT).VTs;
157 const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,
158 MVT::ValueType VT2) {
159 return getVTList(VT1, VT2).VTs;
161 const MVT::ValueType *getNodeValueTypes(MVT::ValueType VT1,MVT::ValueType VT2,
162 MVT::ValueType VT3) {
163 return getVTList(VT1, VT2, VT3).VTs;
165 const MVT::ValueType *getNodeValueTypes(std::vector<MVT::ValueType> &VTList) {
166 return getVTList(&VTList[0], VTList.size()).VTs;
170 //===--------------------------------------------------------------------===//
171 // Node creation methods.
173 SDOperand getString(const std::string &Val);
174 SDOperand getConstant(uint64_t Val, MVT::ValueType VT, bool isTarget = false);
175 SDOperand getConstant(const APInt &Val, MVT::ValueType VT, bool isTarget = false);
176 SDOperand getIntPtrConstant(uint64_t Val, bool isTarget = false);
177 SDOperand getTargetConstant(uint64_t Val, MVT::ValueType VT) {
178 return getConstant(Val, VT, true);
180 SDOperand getTargetConstant(const APInt &Val, MVT::ValueType VT) {
181 return getConstant(Val, VT, true);
183 SDOperand getConstantFP(double Val, MVT::ValueType VT, bool isTarget = false);
184 SDOperand getConstantFP(const APFloat& Val, MVT::ValueType VT,
185 bool isTarget = false);
186 SDOperand getTargetConstantFP(double Val, MVT::ValueType VT) {
187 return getConstantFP(Val, VT, true);
189 SDOperand getTargetConstantFP(const APFloat& Val, MVT::ValueType VT) {
190 return getConstantFP(Val, VT, true);
192 SDOperand getGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
193 int offset = 0, bool isTargetGA = false);
194 SDOperand getTargetGlobalAddress(const GlobalValue *GV, MVT::ValueType VT,
196 return getGlobalAddress(GV, VT, offset, true);
198 SDOperand getFrameIndex(int FI, MVT::ValueType VT, bool isTarget = false);
199 SDOperand getTargetFrameIndex(int FI, MVT::ValueType VT) {
200 return getFrameIndex(FI, VT, true);
202 SDOperand getJumpTable(int JTI, MVT::ValueType VT, bool isTarget = false);
203 SDOperand getTargetJumpTable(int JTI, MVT::ValueType VT) {
204 return getJumpTable(JTI, VT, true);
206 SDOperand getConstantPool(Constant *C, MVT::ValueType VT,
207 unsigned Align = 0, int Offs = 0, bool isT=false);
208 SDOperand getTargetConstantPool(Constant *C, MVT::ValueType VT,
209 unsigned Align = 0, int Offset = 0) {
210 return getConstantPool(C, VT, Align, Offset, true);
212 SDOperand getConstantPool(MachineConstantPoolValue *C, MVT::ValueType VT,
213 unsigned Align = 0, int Offs = 0, bool isT=false);
214 SDOperand getTargetConstantPool(MachineConstantPoolValue *C,
215 MVT::ValueType VT, unsigned Align = 0,
217 return getConstantPool(C, VT, Align, Offset, true);
219 SDOperand getBasicBlock(MachineBasicBlock *MBB);
220 SDOperand getExternalSymbol(const char *Sym, MVT::ValueType VT);
221 SDOperand getTargetExternalSymbol(const char *Sym, MVT::ValueType VT);
222 SDOperand getArgFlags(ISD::ArgFlagsTy Flags);
223 SDOperand getValueType(MVT::ValueType);
224 SDOperand getRegister(unsigned Reg, MVT::ValueType 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::ValueType *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::ValueType *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::ValueType VT) {
250 const MVT::ValueType *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::ValueType VT,
260 const MVT::ValueType *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::ValueType 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::ValueType *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 Ops.size() - (InFlag.Val == 0 ? 1 : 0));
293 /// getNode - Gets or creates the specified node.
295 SDOperand getNode(unsigned Opcode, MVT::ValueType VT);
296 SDOperand getNode(unsigned Opcode, MVT::ValueType VT, SDOperand N);
297 SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
298 SDOperand N1, SDOperand N2);
299 SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
300 SDOperand N1, SDOperand N2, SDOperand N3);
301 SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
302 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
303 SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
304 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
306 SDOperand getNode(unsigned Opcode, MVT::ValueType VT,
307 const SDOperand *Ops, unsigned NumOps);
308 SDOperand getNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
309 const SDOperand *Ops, unsigned NumOps);
310 SDOperand getNode(unsigned Opcode, const MVT::ValueType *VTs, unsigned NumVTs,
311 const SDOperand *Ops, unsigned NumOps);
312 SDOperand getNode(unsigned Opcode, SDVTList VTs);
313 SDOperand getNode(unsigned Opcode, SDVTList VTs, SDOperand N);
314 SDOperand getNode(unsigned Opcode, SDVTList VTs,
315 SDOperand N1, SDOperand N2);
316 SDOperand getNode(unsigned Opcode, SDVTList VTs,
317 SDOperand N1, SDOperand N2, SDOperand N3);
318 SDOperand getNode(unsigned Opcode, SDVTList VTs,
319 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4);
320 SDOperand getNode(unsigned Opcode, SDVTList VTs,
321 SDOperand N1, SDOperand N2, SDOperand N3, SDOperand N4,
323 SDOperand getNode(unsigned Opcode, SDVTList VTs,
324 const SDOperand *Ops, unsigned NumOps);
326 SDOperand getMemcpy(SDOperand Chain, SDOperand Dst, SDOperand Src,
327 SDOperand Size, unsigned Align,
329 const Value *DstSV, uint64_t DstOff,
330 const Value *SrcSV, uint64_t SrcOff);
332 SDOperand getMemmove(SDOperand Chain, SDOperand Dst, SDOperand Src,
333 SDOperand Size, unsigned Align,
334 const Value *DstSV, uint64_t DstOff,
335 const Value *SrcSV, uint64_t SrcOff);
337 SDOperand getMemset(SDOperand Chain, SDOperand Dst, SDOperand Src,
338 SDOperand Size, unsigned Align,
339 const Value *DstSV, uint64_t DstOff);
341 /// getSetCC - Helper function to make it easier to build SetCC's if you just
342 /// have an ISD::CondCode instead of an SDOperand.
344 SDOperand getSetCC(MVT::ValueType VT, SDOperand LHS, SDOperand RHS,
345 ISD::CondCode Cond) {
346 return getNode(ISD::SETCC, VT, LHS, RHS, getCondCode(Cond));
349 /// getSelectCC - Helper function to make it easier to build SelectCC's if you
350 /// just have an ISD::CondCode instead of an SDOperand.
352 SDOperand getSelectCC(SDOperand LHS, SDOperand RHS,
353 SDOperand True, SDOperand False, ISD::CondCode Cond) {
354 return getNode(ISD::SELECT_CC, True.getValueType(), LHS, RHS, True, False,
358 /// getVAArg - VAArg produces a result and token chain, and takes a pointer
359 /// and a source value as input.
360 SDOperand getVAArg(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
363 /// getAtomic - Gets a node for an atomic op, produces result and chain, takes
365 SDOperand getAtomic(unsigned Opcode, SDOperand Chain, SDOperand Ptr,
366 SDOperand Cmp, SDOperand Swp, MVT::ValueType VT);
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 Val, MVT::ValueType VT);
373 /// getLoad - Loads are not normal binary operators: their result type is not
374 /// determined by their operands, and they produce a value AND a token chain.
376 SDOperand getLoad(MVT::ValueType VT, SDOperand Chain, SDOperand Ptr,
377 const Value *SV, int SVOffset, bool isVolatile=false,
378 unsigned Alignment=0);
379 SDOperand getExtLoad(ISD::LoadExtType ExtType, MVT::ValueType VT,
380 SDOperand Chain, SDOperand Ptr, const Value *SV,
381 int SVOffset, MVT::ValueType EVT, bool isVolatile=false,
382 unsigned Alignment=0);
383 SDOperand getIndexedLoad(SDOperand OrigLoad, SDOperand Base,
384 SDOperand Offset, ISD::MemIndexedMode AM);
385 SDOperand getLoad(ISD::MemIndexedMode AM, ISD::LoadExtType ExtType,
386 MVT::ValueType VT, SDOperand Chain,
387 SDOperand Ptr, SDOperand Offset,
388 const Value *SV, int SVOffset, MVT::ValueType EVT,
389 bool isVolatile=false, unsigned Alignment=0);
391 /// getStore - Helper function to build ISD::STORE nodes.
393 SDOperand getStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
394 const Value *SV, int SVOffset, bool isVolatile=false,
395 unsigned Alignment=0);
396 SDOperand getTruncStore(SDOperand Chain, SDOperand Val, SDOperand Ptr,
397 const Value *SV, int SVOffset, MVT::ValueType TVT,
398 bool isVolatile=false, unsigned Alignment=0);
399 SDOperand getIndexedStore(SDOperand OrigStoe, SDOperand Base,
400 SDOperand Offset, ISD::MemIndexedMode AM);
402 // getSrcValue - Construct a node to track a Value* through the backend.
403 SDOperand getSrcValue(const Value *v);
405 // getMemOperand - Construct a node to track a memory reference
406 // through the backend.
407 SDOperand getMemOperand(const MachineMemOperand &MO);
409 /// UpdateNodeOperands - *Mutate* the specified node in-place to have the
410 /// specified operands. If the resultant node already exists in the DAG,
411 /// this does not modify the specified node, instead it returns the node that
412 /// already exists. If the resultant node does not exist in the DAG, the
413 /// input node is returned. As a degenerate case, if you specify the same
414 /// input operands as the node already has, the input node is returned.
415 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op);
416 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2);
417 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
419 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
420 SDOperand Op3, SDOperand Op4);
421 SDOperand UpdateNodeOperands(SDOperand N, SDOperand Op1, SDOperand Op2,
422 SDOperand Op3, SDOperand Op4, SDOperand Op5);
423 SDOperand UpdateNodeOperands(SDOperand N, SDOperand *Ops, unsigned NumOps);
425 /// SelectNodeTo - These are used for target selectors to *mutate* the
426 /// specified node to have the specified return type, Target opcode, and
427 /// operands. Note that target opcodes are stored as
428 /// ISD::BUILTIN_OP_END+TargetOpcode in the node opcode field. The 0th value
429 /// of the resultant node is returned.
430 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT);
431 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
433 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
434 SDOperand Op1, SDOperand Op2);
435 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
436 SDOperand Op1, SDOperand Op2, SDOperand Op3);
437 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT,
438 const SDOperand *Ops, unsigned NumOps);
439 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
440 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
441 SDNode *SelectNodeTo(SDNode *N, unsigned TargetOpc, MVT::ValueType VT1,
442 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
446 /// getTargetNode - These are used for target selectors to create a new node
447 /// with specified return type(s), target opcode, and operands.
449 /// Note that getTargetNode returns the resultant node. If there is already a
450 /// node of the specified opcode and operands, it returns that node instead of
452 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT);
453 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
455 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
456 SDOperand Op1, SDOperand Op2);
457 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
458 SDOperand Op1, SDOperand Op2, SDOperand Op3);
459 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT,
460 const SDOperand *Ops, unsigned NumOps);
461 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
463 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
464 MVT::ValueType VT2, SDOperand Op1);
465 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
466 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2);
467 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
468 MVT::ValueType VT2, SDOperand Op1, SDOperand Op2,
470 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
472 const SDOperand *Ops, unsigned NumOps);
473 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
474 MVT::ValueType VT2, MVT::ValueType VT3,
475 SDOperand Op1, SDOperand Op2);
476 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
477 MVT::ValueType VT2, MVT::ValueType VT3,
478 SDOperand Op1, SDOperand Op2, SDOperand Op3);
479 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
480 MVT::ValueType VT2, MVT::ValueType VT3,
481 const SDOperand *Ops, unsigned NumOps);
482 SDNode *getTargetNode(unsigned Opcode, MVT::ValueType VT1,
483 MVT::ValueType VT2, MVT::ValueType VT3,
485 const SDOperand *Ops, unsigned NumOps);
486 SDNode *getTargetNode(unsigned Opcode, std::vector<MVT::ValueType> &ResultTys,
487 const SDOperand *Ops, unsigned NumOps);
489 /// getNodeIfExists - Get the specified node if it's already available, or
490 /// else return NULL.
491 SDNode *getNodeIfExists(unsigned Opcode, SDVTList VTs,
492 const SDOperand *Ops, unsigned NumOps);
494 /// DAGUpdateListener - Clients of various APIs that cause global effects on
495 /// the DAG can optionally implement this interface. This allows the clients
496 /// to handle the various sorts of updates that happen.
497 class DAGUpdateListener {
499 virtual ~DAGUpdateListener();
500 virtual void NodeDeleted(SDNode *N) = 0;
501 virtual void NodeUpdated(SDNode *N) = 0;
504 /// RemoveDeadNode - Remove the specified node from the system. If any of its
505 /// operands then becomes dead, remove them as well. Inform UpdateListener
506 /// for each node deleted.
507 void RemoveDeadNode(SDNode *N, DAGUpdateListener *UpdateListener = 0);
509 /// ReplaceAllUsesWith - Modify anything using 'From' to use 'To' instead.
510 /// This can cause recursive merging of nodes in the DAG. Use the first
511 /// version if 'From' is known to have a single result, use the second
512 /// if you have two nodes with identical results, use the third otherwise.
514 /// These methods all take an optional UpdateListener, which (if not null) is
515 /// informed about nodes that are deleted and modified due to recursive
516 /// changes in the dag.
518 void ReplaceAllUsesWith(SDOperand From, SDOperand Op,
519 DAGUpdateListener *UpdateListener = 0);
520 void ReplaceAllUsesWith(SDNode *From, SDNode *To,
521 DAGUpdateListener *UpdateListener = 0);
522 void ReplaceAllUsesWith(SDNode *From, const SDOperand *To,
523 DAGUpdateListener *UpdateListener = 0);
525 /// ReplaceAllUsesOfValueWith - Replace any uses of From with To, leaving
526 /// uses of other values produced by From.Val alone.
527 void ReplaceAllUsesOfValueWith(SDOperand From, SDOperand To,
528 DAGUpdateListener *UpdateListener = 0);
530 /// AssignNodeIds - Assign a unique node id for each node in the DAG based on
531 /// their allnodes order. It returns the maximum id.
532 unsigned AssignNodeIds();
534 /// AssignTopologicalOrder - Assign a unique node id for each node in the DAG
535 /// based on their topological order. It returns the maximum id and a vector
536 /// of the SDNodes* in assigned order by reference.
537 unsigned AssignTopologicalOrder(std::vector<SDNode*> &TopOrder);
539 /// isCommutativeBinOp - Returns true if the opcode is a commutative binary
541 static bool isCommutativeBinOp(unsigned Opcode) {
542 // FIXME: This should get its info from the td file, so that we can include
557 case ISD::ADDE: return true;
558 default: return false;
564 /// CreateStackTemporary - Create a stack temporary, suitable for holding the
565 /// specified value type.
566 SDOperand CreateStackTemporary(MVT::ValueType VT);
568 /// FoldSetCC - Constant fold a setcc to true or false.
569 SDOperand FoldSetCC(MVT::ValueType VT, SDOperand N1,
570 SDOperand N2, ISD::CondCode Cond);
572 /// SignBitIsZero - Return true if the sign bit of Op is known to be zero. We
573 /// use this predicate to simplify operations downstream.
574 bool SignBitIsZero(SDOperand Op, unsigned Depth = 0) const;
576 /// MaskedValueIsZero - Return true if 'Op & Mask' is known to be zero. We
577 /// use this predicate to simplify operations downstream. Op and Mask are
578 /// known to be the same type.
579 bool MaskedValueIsZero(SDOperand Op, const APInt &Mask, unsigned Depth = 0)
582 /// ComputeMaskedBits - Determine which of the bits specified in Mask are
583 /// known to be either zero or one and return them in the KnownZero/KnownOne
584 /// bitsets. This code only analyzes bits in Mask, in order to short-circuit
585 /// processing. Targets can implement the computeMaskedBitsForTargetNode
586 /// method in the TargetLowering class to allow target nodes to be understood.
587 void ComputeMaskedBits(SDOperand Op, const APInt &Mask, APInt &KnownZero,
588 APInt &KnownOne, unsigned Depth = 0) const;
590 /// ComputeNumSignBits - Return the number of times the sign bit of the
591 /// register is replicated into the other bits. We know that at least 1 bit
592 /// is always equal to the sign bit (itself), but other cases can give us
593 /// information. For example, immediately after an "SRA X, 2", we know that
594 /// the top 3 bits are all equal to each other, so we return 3. Targets can
595 /// implement the ComputeNumSignBitsForTarget method in the TargetLowering
596 /// class to allow target nodes to be understood.
597 unsigned ComputeNumSignBits(SDOperand Op, unsigned Depth = 0) const;
599 /// isVerifiedDebugInfoDesc - Returns true if the specified SDOperand has
600 /// been verified as a debug information descriptor.
601 bool isVerifiedDebugInfoDesc(SDOperand Op) const;
604 void RemoveNodeFromCSEMaps(SDNode *N);
605 SDNode *AddNonLeafNodeToCSEMaps(SDNode *N);
606 SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op, void *&InsertPos);
607 SDNode *FindModifiedNodeSlot(SDNode *N, SDOperand Op1, SDOperand Op2,
609 SDNode *FindModifiedNodeSlot(SDNode *N, const SDOperand *Ops, unsigned NumOps,
612 void DeleteNodeNotInCSEMaps(SDNode *N);
614 // List of non-single value types.
615 std::list<std::vector<MVT::ValueType> > VTList;
617 // Maps to auto-CSE operations.
618 std::vector<CondCodeSDNode*> CondCodeNodes;
620 std::vector<SDNode*> ValueTypeNodes;
621 std::map<MVT::ValueType, SDNode*> ExtendedValueTypeNodes;
622 std::map<std::string, SDNode*> ExternalSymbols;
623 std::map<std::string, SDNode*> TargetExternalSymbols;
624 std::map<std::string, StringSDNode*> StringNodes;
627 template <> struct GraphTraits<SelectionDAG*> : public GraphTraits<SDNode*> {
628 typedef SelectionDAG::allnodes_iterator nodes_iterator;
629 static nodes_iterator nodes_begin(SelectionDAG *G) {
630 return G->allnodes_begin();
632 static nodes_iterator nodes_end(SelectionDAG *G) {
633 return G->allnodes_end();
637 } // end namespace llvm