9#ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTANALYSIS_H
10#define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTANALYSIS_H
13#include "llvm/ADT/EquivalenceClasses.h"
14#include "llvm/ADT/SmallPtrSet.h"
87 AnalysisState::getOptions());
233 template <
typename Ty,
typename... Args>
236 std::is_base_of<Extension, Ty>::value,
237 "only a class derived from OneShotAnalysisState::Extension is allowed");
238 auto ptr = std::make_unique<Ty>(*
this, std::forward<Args>(args)...);
240 assert(
result.second &&
"extension already added");
241 return *
static_cast<Ty *
>(
result.first->second.get());
245 template <
typename Ty>
248 std::is_base_of<Extension, Ty>::value,
249 "only a class derived from OneShotAnalysisState::Extension is allowed");
251 if (iter == extensions.end())
253 return static_cast<Ty *
>(iter->second.get());
257 template <
typename Ty>
263 using EquivalenceClassRangeType =
266 EquivalenceClassRangeType getAliases(
Value v)
const;
272 bool mayHaveUnstructuredCF =
false;
275 bool mayHaveParallelRegionsFlag =
false;
279 class CFGReachabilityCache;
280 std::unique_ptr<CFGReachabilityCache> cfgReachabilityCache;
283 class OpDominanceBlockCache;
284 std::unique_ptr<OpDominanceBlockCache> opDominanceBlockCache;
299 llvm::EquivalenceClasses<Value> aliasInfo;
307 llvm::EquivalenceClasses<Value> equivalentInfo;
310 int64_t statNumTensorOutOfPlace = 0;
311 int64_t statNumTensorInPlace = 0;
325 OneShotAnalysisState &state);
330 BufferizationStatistics *statistics =
nullptr);
335 BufferizationState &state,
336 BufferizationStatistics *statistics =
nullptr);
static llvm::ManagedStatic< PassManagerOptions > options
#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)
AnalysisState(LatticeAnchor anchor)
Create the analysis state on the given lattice anchor.
Block represents an ordered list of Operations.
A class for computing basic dominance information.
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
static TypeID get()
Construct a type info object for the given type T.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
virtual ~Extension()
Base virtual destructor.
friend class OneShotAnalysisState
Extension(OneShotAnalysisState &state)
Constructs an extension of the given state object.
const OneShotAnalysisState & getAnalysisState() const
Provides read-only access to the parent OneShotAnalysisState object.
State for analysis-enabled bufferization.
void bufferizeOutOfPlace(OpOperand &operand)
Mark the given OpOperand as out-of-place.
bool isWritable(Value value) const
Return true if the buffer of the given tensor value is writable.
const SetVector< Value > & findDefinitionsCached(OpOperand *opOperand)
Find the definitions of the given operand's value or retrieve them from the cache.
bool isReachableCached(Block *from, Block *to, const llvm::SmallPtrSetImpl< Block * > *barriers=nullptr)
Return true if to is reachable from from without crossing barriers.
bool isInPlace(OpOperand &opOperand) const override
Return true if the given OpResult has been decided to bufferize inplace.
bool canUseOpDominanceDueToBlocksCached(Block *readBlock, Block *writeBlock, llvm::ArrayRef< Block * > defBlocks, function_ref< bool()> compute)
Cached canUseOpDominanceDueToBlocks.
LogicalResult analyzeOp(Operation *op, const DominanceInfo &domInfo)
Analyze the given op and its nested ops.
bool isValueWritten(Value value) const
Return true if the buffer of the given tensor value is written to.
void unionEquivalenceClasses(Value v1, Value v2)
Union the equivalence classes of v1 and v2.
OneShotAnalysisState(const OneShotAnalysisState &)=delete
void gatherUndefinedTensorUses(Operation *op)
Find all tensor values in the given operation that have undefined contents and store them in undefine...
void resetCache() override
Reset cached data structures.
Ty & addExtension(Args &&...args)
Adds a new Extension of the type specified as template parameter, constructing it with the arguments ...
const OneShotBufferizationOptions & getOptions() const
Return a reference to the BufferizationOptions.
Ty * getExtension()
Returns the extension of the specified type.
LogicalResult analyzeSingleOp(Operation *op, const DominanceInfo &domInfo)
Analyze a single op (without nested ops).
const Ty * getExtension() const
Returns the extension of the specified type.
void applyOnEquivalenceClass(Value v, function_ref< void(Value)> fun) const
Apply fun to all the members of the equivalence class of v.
int64_t getStatNumTensorOutOfPlace() const
bool mayHaveUnstructuredControlFlow() const
True if any region in the analyzed IR has more than one block.
bool hasUndefinedContents(OpOperand *opOperand) const override
Return true if the given tensor has undefined contents.
bool areNonConflictingSubsetsCached(OpOperand *uRead, OpOperand *uConflictingWrite)
Return whether uRead and uConflictingWrite are non-conflicting subsets, with caching.
static bool classof(const AnalysisState *base)
bool mayHaveParallelRegions() const
True if the analyzed IR may contain a parallel region.
void bufferizeInPlace(OpOperand &operand)
Mark the given OpOperand as in-place and merge the results' and operand's aliasing sets.
void applyOnAliases(Value v, function_ref< void(Value)> fun) const
Apply fun to all aliases of v.
bool areEquivalentBufferizedValues(Value v1, Value v2) const override
Return true if v1 and v2 bufferize to equivalent buffers.
OneShotAnalysisState(Operation *op, const OneShotBufferizationOptions &options)
bool areAliasingBufferizedValues(Value v1, Value v2) const override
Return true if v1 and v2 may bufferize to aliasing buffers.
void unionAliasSets(Value v1, Value v2)
Union the alias sets of v1 and v2.
~OneShotAnalysisState() override
void createAliasInfoEntry(Value v)
Add a new entry for v in the aliasInfo and equivalentInfo.
int64_t getStatNumTensorInPlace() const
LogicalResult analyzeOp(Operation *op, OneShotAnalysisState &state, BufferizationStatistics *statistics=nullptr)
Analyze op and its nested ops.
LogicalResult runOneShotBufferize(Operation *op, const OneShotBufferizationOptions &options, BufferizationState &state, BufferizationStatistics *statistics=nullptr)
Run One-Shot Bufferize on the given op: Analysis + Bufferization.
LogicalResult checkPreBufferizationAssumptions(Operation *op, const DominanceInfo &domInfo, OneShotAnalysisState &state)
Perform various checks on the input IR to see if it contains IR constructs that are unsupported by On...
Include the generated interface declarations.
llvm::DenseSet< ValueT, ValueInfoT > DenseSet
llvm::SetVector< T, Vector, Set, N > SetVector
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap
llvm::function_ref< Fn > function_ref
Bufferization statistics for debugging.
Options for analysis-enabled bufferization.
unsigned analysisFuzzerSeed
Seed for the analysis fuzzer.
std::optional< bool > mayHaveUnstructuredControlFlow
Whether the IR contains a region with more than one block.
bool dumpAliasSets
Specifies whether the tensor IR should be annotated with alias sets.
OneShotBufferizationOptions()=default
bool allowReturnAllocsFromLoops
Specifies whether returning newly allocated memrefs from loops should be allowed.
AnalysisHeuristic analysisHeuristic
The heuristic controls the order in which ops are traversed during the analysis.
@ BottomUpFromTerminators
llvm::ArrayRef< std::string > noAnalysisFuncFilter
Specify the functions that should not be analyzed.