13#ifndef LLVM_ANALYSIS_DDG_H
14#define LLVM_ANALYSIS_DDG_H
70 DGNode::operator=(std::move(
N));
122 DDGNode::operator=(std::move(
N));
123 InstList = std::move(
N.InstList);
129 assert(!InstList.empty() &&
"Instruction List is empty.");
134 static_cast<const SimpleDDGNode *
>(
this)->getInstructions());
143 return N->getKind() == NodeKind::SingleInstruction ||
144 N->getKind() == NodeKind::MultiInstruction;
151 setKind((InstList.size() == 0 && Input.size() == 1)
152 ? NodeKind::SingleInstruction
153 : NodeKind::MultiInstruction);
156 void appendInstructions(
const SimpleDDGNode &Input) {
157 appendInstructions(Input.getInstructions());
161 SmallVector<Instruction *, 2> InstList;
184 DDGNode::operator=(std::move(
N));
201 return N->getKind() == NodeKind::PiBlock;
273 assert(
Root &&
"Root node is not available yet. Graph construction may "
274 "still be in progress\n");
288 const NodeType &Dst)
const;
331 bool addNode(NodeType &
N);
338 PiBlockMapType PiBlockMap;
355 assert(RN &&
"Failed to allocate memory for DDG root node.");
361 assert(SN &&
"Failed to allocate memory for simple DDG node.");
367 assert(Pi &&
"Failed to allocate memory for pi-block node.");
372 auto *
E =
new DDGEdge(Tgt, DDGEdge::EdgeKind::RegisterDefUse);
373 assert(
E &&
"Failed to allocate memory for edge");
374 Graph.connect(Src, Tgt, *
E);
378 auto *
E =
new DDGEdge(Tgt, DDGEdge::EdgeKind::MemoryDependence);
379 assert(
E &&
"Failed to allocate memory for edge");
380 Graph.connect(Src, Tgt, *
E);
384 auto *
E =
new DDGEdge(Tgt, DDGEdge::EdgeKind::Rooted);
385 assert(
E &&
"Failed to allocate memory for edge");
386 assert(isa<RootDDGNode>(Src) &&
"Expected root node");
387 Graph.connect(Src, Tgt, *
E);
392 auto *PiNode = dyn_cast<const PiBlockDDGNode>(&
N);
393 assert(PiNode &&
"Expected a pi-block node.");
394 return PiNode->getNodes();
399 bool areNodesMergeable(
const DDGNode &Src,
const DDGNode &Tgt)
const final;
401 bool shouldSimplify()
const final;
402 bool shouldCreatePiBlocks()
const final;
418 using Result = std::unique_ptr<DataDependenceGraph>;
444template <
typename NodeType>
446 const NodeType &Src,
const NodeType &Dst,
DependenceList &Deps)
const {
447 assert(Deps.
empty() &&
"Expected empty output list at the start.");
452 return I->mayReadOrWriteMemory();
454 Src.collectInstructions(isMemoryAccess, SrcIList);
455 Dst.collectInstructions(isMemoryAccess, DstIList);
457 for (
auto *SrcI : SrcIList)
458 for (
auto *DstI : DstIList)
463 return !Deps.
empty();
466template <
typename NodeType>
469 const NodeType &Dst)
const {
473 if (!getDependencies(Src, Dst, Deps))
479 if (Str.back() ==
'\n')
495 return &
P->getTargetNode();
535 return &
P->getTargetNode();
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static GCRegistry::Add< StatepointGC > D("statepoint-example", "an example strategy for statepoint")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file defines the DenseMap class.
SmallVector< Instruction *, 2 > InstructionListType
This file defines the interface and a base class implementation for a directed graph.
This header provides classes for managing per-loop analyses.
This abstract builder class defines a set of high-level steps for creating DDG-like graphs.
A container for analyses that lazily runs them and caches their results.
Textual printer pass for the DDG of a loop.
DDGAnalysisPrinterPass(raw_ostream &OS)
Analysis pass that builds the DDG for a loop.
std::unique_ptr< DataDependenceGraph > Result
Concrete implementation of a pure data dependence graph builder.
DDGNode & createPiBlock(const NodeListType &L) final
Create a pi-block node in the graph representing a group of nodes in an SCC of the graph.
DDGNode & createFineGrainedNode(Instruction &I) final
Create an atomic node in the graph given a single instruction.
DDGBuilder(DataDependenceGraph &G, DependenceInfo &D, const BasicBlockListType &BBs)
DDGEdge & createMemoryEdge(DDGNode &Src, DDGNode &Tgt) final
DDGEdge & createRootedEdge(DDGNode &Src, DDGNode &Tgt) final
DDGNode & createRootNode() final
Create the root node of the graph.
const NodeListType & getNodesInPiBlock(const DDGNode &N) final
DDGEdge & createDefUseEdge(DDGNode &Src, DDGNode &Tgt) final
Data Dependency Graph Edge.
DDGEdge & operator=(DDGEdge &&E)
bool isDefUse() const
Return true if this is a def-use edge, and false otherwise.
bool isRooted() const
Return true if this is an edge stemming from the root node, and false otherwise.
EdgeKind getKind() const
Get the edge kind.
EdgeKind
The kind of edge in the DDG.
bool isMemoryDependence() const
Return true if this is a memory dependence edge, and false otherwise.
DDGEdge(const DDGEdge &E)
DDGEdge(DDGNode &N, EdgeKind K)
DDGEdge(DDGNode &N)=delete
DDGEdge & operator=(const DDGEdge &E)=default
Data Dependence Graph Node The graph can represent the following types of nodes:
DDGNode & operator=(DDGNode &&N)
DDGNode(const DDGNode &N)=default
NodeKind getKind() const
Getter for the kind of this node.
DDGNode(const NodeKind K)
void setKind(NodeKind K)
Setter for the kind of this node.
DDGNode & operator=(const DDGNode &N)
Represent an edge in the directed graph.
DGEdge< NodeType, EdgeType > & operator=(const DGEdge< NodeType, EdgeType > &E)
Represent a node in the directed graph.
typename EdgeListTy::const_iterator const_iterator
typename EdgeListTy::iterator iterator
DataDependenceGraph(DataDependenceGraph &&G)
DataDependenceGraph(const DataDependenceGraph &G)=delete
DataDependenceGraph()=delete
Encapsulate some common data and functionality needed for different variations of data dependence gra...
std::string getDependenceString(const NodeType &Src, const NodeType &Dst) const
Return a string representing the type of dependence that the dependence analysis identified between t...
NodeType & getRoot() const
Return the root node of the graph.
DependenceGraphInfo()=delete
DependenceGraphInfo(DependenceGraphInfo &&G)
StringRef getName() const
Return the label that is used to name this graph.
SmallVector< std::unique_ptr< Dependence >, 1 > DependenceList
DependenceGraphInfo(const DependenceGraphInfo &G)=delete
DependenceGraphInfo(const std::string &N, const DependenceInfo &DepInfo)
virtual ~DependenceGraphInfo()=default
bool getDependencies(const NodeType &Src, const NodeType &Dst, DependenceList &Deps) const
Collect all the data dependency infos coming from any pair of memory accesses from Src to Dst,...
DependenceInfo - This class is the main dependence-analysis driver.
LLVM_ABI std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool UnderRuntimeAssumptions=false)
depends - Tests for a dependence between the Src and Dst instructions.
const_iterator begin() const
const_iterator end() const
typename NodeListTy::iterator iterator
typename NodeListTy::const_iterator const_iterator
This class provides an interface for updating the loop pass manager based on mutations to the loop ne...
Represents a single loop in the control flow graph.
Subclass of DDGNode representing a pi-block.
PiBlockDDGNode & operator=(PiBlockDDGNode &&N)
const PiNodeList & getNodes() const
Get the list of nodes in this pi-block.
static bool classof(const DDGNode *N)
Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
PiBlockDDGNode & operator=(const PiBlockDDGNode &N)=default
A set of analyses that are preserved following a run of a transformation pass.
Subclass of DDGNode representing the root node of the graph.
static bool classof(const DDGNode *N)
Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
RootDDGNode(const RootDDGNode &N)=delete
static bool classof(const RootDDGNode *N)
RootDDGNode(RootDDGNode &&N)
Subclass of DDGNode representing single or multi-instruction nodes.
Instruction * getFirstInstruction() const
Get the first/last instruction in the node.
SimpleDDGNode & operator=(const SimpleDDGNode &N)=default
const InstructionListType & getInstructions() const
Get the list of instructions in this node.
SimpleDDGNode & operator=(SimpleDDGNode &&N)
static bool classof(const DDGNode *N)
Define classof to be able to use isa<>, cast<>, dyn_cast<>, etc.
static bool classof(const SimpleDDGNode *N)
InstructionListType & getInstructions()
Instruction * getLastInstruction() const
void push_back(const T &Elt)
StringRef - Represent a constant reference to a string, i.e.
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
A raw_ostream that writes to an std::string.
This is an optimization pass for GlobalISel generic memory operations.
void append_range(Container &C, Range &&R)
Wrapper function to append range R to container C.
void interleaveComma(const Container &c, StreamT &os, UnaryFunctor each_fn)
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Implement std::hash so that hash_code can be used in STL containers.
Determine the kind of a node from its type.
A CRTP mix-in that provides informational APIs needed for analysis passes.
A special type used by analysis passes to provide an address that identifies that particular analysis...
DDGNode::iterator ChildEdgeIteratorType
static DDGNode * DDGGetTargetNode(DGEdge< DDGNode, DDGEdge > *P)
static ChildIteratorType child_end(NodeRef N)
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
static ChildEdgeIteratorType child_edge_end(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)
static NodeRef getEntryNode(NodeRef N)
static nodes_iterator nodes_end(DataDependenceGraph *DG)
DataDependenceGraph::iterator nodes_iterator
static nodes_iterator nodes_begin(DataDependenceGraph *DG)
static NodeRef getEntryNode(DataDependenceGraph *DG)
static ChildIteratorType child_end(NodeRef N)
static const DDGNode * DDGGetTargetNode(const DGEdge< DDGNode, DDGEdge > *P)
DDGNode::const_iterator ChildEdgeIteratorType
static ChildEdgeIteratorType child_edge_end(NodeRef N)
static ChildEdgeIteratorType child_edge_begin(NodeRef N)
static NodeRef getEntryNode(NodeRef N)
static ChildIteratorType child_begin(NodeRef N)
static nodes_iterator nodes_begin(const DataDependenceGraph *DG)
DataDependenceGraph::const_iterator nodes_iterator
static NodeRef getEntryNode(const DataDependenceGraph *DG)
static nodes_iterator nodes_end(const DataDependenceGraph *DG)
The adaptor from a function pass to a loop pass computes these analyses and makes them available to t...
A CRTP mix-in to automatically provide informational APIs needed for passes.