13#ifndef LLVM_ANALYSIS_DDG_H
14#define LLVM_ANALYSIS_DDG_H
122 InstList = std::move(
N.InstList);
128 assert(!InstList.empty() &&
"Instruction List is empty.");
150 setKind((InstList.size() == 0 && Input.size() == 1)
156 appendInstructions(Input.getInstructions());
160 SmallVector<Instruction *, 2> InstList;
272 assert(
Root &&
"Root node is not available yet. Graph construction may "
273 "still be in progress\n");
287 const NodeType &Dst)
const;
337 PiBlockMapType PiBlockMap;
353 assert(RN &&
"Failed to allocate memory for DDG root node.");
359 assert(SN &&
"Failed to allocate memory for simple DDG node.");
365 assert(Pi &&
"Failed to allocate memory for pi-block node.");
371 assert(
E &&
"Failed to allocate memory for edge");
377 assert(
E &&
"Failed to allocate memory for edge");
383 assert(
E &&
"Failed to allocate memory for edge");
384 assert(isa<RootDDGNode>(Src) &&
"Expected root node");
390 auto *PiNode = dyn_cast<const PiBlockDDGNode>(&
N);
391 assert(PiNode &&
"Expected a pi-block node.");
392 return PiNode->getNodes();
416 using Result = std::unique_ptr<DataDependenceGraph>;
440template <
typename NodeType>
442 const NodeType &Src,
const NodeType &Dst,
DependenceList &Deps)
const {
443 assert(Deps.
empty() &&
"Expected empty output list at the start.");
448 return I->mayReadOrWriteMemory();
450 Src.collectInstructions(isMemoryAccess, SrcIList);
451 Dst.collectInstructions(isMemoryAccess, DstIList);
453 for (
auto *SrcI : SrcIList)
454 for (
auto *DstI : DstIList)
459 return !Deps.
empty();
462template <
typename NodeType>
465 const NodeType &Dst)
const {
469 if (!getDependencies(Src, Dst, Deps))
475 if (Str.back() ==
'\n')
491 return &
P->getTargetNode();
531 return &
P->getTargetNode();
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.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
This abstract builder class defines a set of high-level steps for creating DDG-like graphs.
DependenceInfo & DI
Dependence information used to create memory dependence edges in the graph.
DataDependenceGraph & Graph
Reference to the graph that gets built by a concrete implementation of this builder.
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.
bool areNodesMergeable(const DDGNode &Src, const DDGNode &Tgt) const final
Return true if the two nodes \pSrc and \pTgt are both simple nodes and the consecutive instructions a...
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)
bool shouldCreatePiBlocks() const final
Return true if creation of pi-blocks are supported and desired, and false otherwise.
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
bool shouldSimplify() const final
Return true if graph simplification step is requested, and false otherwise.
void mergeNodes(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)
bool collectInstructions(llvm::function_ref< bool(Instruction *)> const &Pred, InstructionListType &IList) const
Collect a list of instructions, in IList, for which predicate Pred evaluates to true when iterating o...
Represent an edge in the directed graph.
DGEdge< NodeType, EdgeType > & operator=(const DGEdge< NodeType, EdgeType > &E)
Represent a node in the directed graph.
DGNode< NodeType, EdgeType > & operator=(const DGNode< NodeType, EdgeType > &N)
typename EdgeListTy::const_iterator const_iterator
typename EdgeListTy::iterator iterator
const PiBlockDDGNode * getPiBlock(const NodeType &N) const
If node N belongs to a pi-block return a pointer to the pi-block, otherwise return null.
DataDependenceGraph(DataDependenceGraph &&G)
DataDependenceGraph(const DataDependenceGraph &G)=delete
bool addNode(NodeType &N)
Add node N to the graph, if it's not added yet, and keep track of the root node as well as pi-blocks ...
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.
std::unique_ptr< Dependence > depends(Instruction *Src, Instruction *Dst, bool PossiblyLoopIndependent)
depends - Tests for a dependence between the Src and Dst instructions.
bool connect(NodeType &Src, NodeType &Dst, EdgeType &E)
Assuming nodes Src and Dst are already in the graph, connect node Src to node Dst using the provided ...
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
SmallVector< DDGNode *, 4 > PiNodeList
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.