13#ifndef LLVM_ANALYSIS_DDG_H
14#define LLVM_ANALYSIS_DDG_H
123 InstList = std::move(
N.InstList);
129 assert(!InstList.empty() &&
"Instruction List is empty.");
134 static_cast<const SimpleDDGNode *
>(
this)->getInstructions());
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;
185 NodeList = std::move(
N.NodeList);
191 assert(!NodeList.empty() &&
"Node list is empty.");
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.");
373 assert(
E &&
"Failed to allocate memory for edge");
374 Graph.connect(Src, Tgt, *
E);
379 assert(
E &&
"Failed to allocate memory for edge");
380 Graph.connect(Src, Tgt, *
E);
385 assert(
E &&
"Failed to allocate memory for edge");
387 Graph.connect(Src, Tgt, *
E);
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 {
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.
SmallVectorImpl< BasicBlock * > BasicBlockListType
AbstractDependenceGraphBuilder(DataDependenceGraph &G, DependenceInfo &D, const BasicBlockListType &BBs)
SmallVector< NodeType *, 4 > NodeListType
DataDependenceGraph & Graph
DDGAnalysisPrinterPass(raw_ostream &OS)
Analysis pass that builds the DDG for a loop.
LLVM_ABI Result run(Loop &L, LoopAnalysisManager &AM, LoopStandardAnalysisResults &AR)
DDG as a loop pass.
std::unique_ptr< DataDependenceGraph > Result
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
Create a memory dependence edge going from Src to Tgt.
DDGEdge & createRootedEdge(DDGNode &Src, DDGNode &Tgt) final
Create a rooted edge going from Src to Tgt .
DDGNode & createRootNode() final
Create the root node of the graph.
const NodeListType & getNodesInPiBlock(const DDGNode &N) final
Given a pi-block node, return a vector of all the nodes contained within it.
DDGEdge & createDefUseEdge(DDGNode &Src, DDGNode &Tgt) final
Create a def-use edge going from Src to Tgt.
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
SmallVectorImpl< Instruction * > InstructionListType
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< DDGNode, DDGEdge > & operator=(const DGEdge< DDGNode, DDGEdge > &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
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.
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
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
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.
DGEdge< DDGNode, DDGEdge > DDGEdgeBase
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
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)
DirectedGraph< DDGNode, DDGEdge > DDGBase
AnalysisManager< Loop, LoopStandardAnalysisResults & > LoopAnalysisManager
The loop analysis manager.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
DGNode< DDGNode, DDGEdge > DDGNodeBase
DependenceGraphInfo< DDGNode > DDGInfo
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
mapped_iterator< DDGNode::iterator, decltype(&DDGGetTargetNode)> ChildIteratorType
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)
mapped_iterator< DDGNode::const_iterator, decltype(&DDGGetTargetNode)> ChildIteratorType
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)
typename DataDependenceGraph *::UnknownGraphTypeError NodeRef
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.