9 #ifndef MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTANALYSIS_H
10 #define MLIR_DIALECT_BUFFERIZATION_TRANSFORMS_ONESHOTANALYSIS_H
13 #include "llvm/ADT/EquivalenceClasses.h"
19 namespace bufferization {
21 struct OneShotBufferizationOptions;
22 struct BufferizationStatistics;
23 class OneShotAnalysisState;
72 return base->
getType() == TypeID::get<OneShotAnalysisState>();
197 template <
typename Ty,
typename... Args>
200 std::is_base_of<Extension, Ty>::value,
201 "only a class derived from OneShotAnalysisState::Extension is allowed");
202 auto ptr = std::make_unique<Ty>(*
this, std::forward<Args>(args)...);
203 auto result = extensions.try_emplace(TypeID::get<Ty>(), std::move(ptr));
204 assert(result.second &&
"extension already added");
205 return *
static_cast<Ty *
>(result.first->second.get());
209 template <
typename Ty>
212 std::is_base_of<Extension, Ty>::value,
213 "only a class derived from OneShotAnalysisState::Extension is allowed");
214 auto iter = extensions.find(TypeID::get<Ty>());
215 if (iter == extensions.end())
217 return static_cast<Ty *
>(iter->second.get());
221 template <
typename Ty>
231 bool operator()(
const Value &lhs,
const Value &rhs)
const {
237 llvm::EquivalenceClasses<Value, ValueComparator>::member_iterator>;
239 EquivalenceClassRangeType getAliases(Value v)
const;
242 DenseMap<Value, SetVector<Value>> cachedDefinitions;
252 llvm::EquivalenceClasses<Value, ValueComparator> aliasInfo;
260 llvm::EquivalenceClasses<Value, ValueComparator> equivalentInfo;
263 int64_t statNumTensorOutOfPlace = 0;
264 int64_t statNumTensorInPlace = 0;
267 DenseSet<OpOperand *> undefinedTensorUses;
271 DenseMap<TypeID, std::unique_ptr<Extension>> extensions;
276 LogicalResult
analyzeOp(Operation *op, OneShotAnalysisState &state,
277 BufferizationStatistics *statistics =
nullptr);
282 BufferizationStatistics *statistics =
nullptr);
static llvm::ManagedStatic< PassManagerOptions > options
#define MLIR_DECLARE_EXPLICIT_TYPE_ID(CLASS_NAME)
A class for computing basic dominance information.
This class represents an operand of an operation.
Operation is the basic unit of execution within MLIR.
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
detail::ValueImpl * getImpl() const
AnalysisState provides a variety of helper functions for dealing with tensor values.
const BufferizationOptions & getOptions() const
Return a reference to the BufferizationOptions.
Base class for OneShotAnalysisState extensions that allow OneShotAnalysisState to contain user-specif...
virtual ~Extension()
Base virtual destructor.
const OneShotAnalysisState & getAnalysisState() const
Provides read-only access to the parent OneShotAnalysisState object.
Extension(OneShotAnalysisState &state)
Constructs an extension of the given state 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.
~OneShotAnalysisState() override=default
const SetVector< Value > & findDefinitionsCached(Value value)
Find the definitions of the given tensor value or retrieve them from the cache.
bool isInPlace(OpOperand &opOperand) const override
Return true if the given OpResult has been decided to bufferize inplace.
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.
const Ty * getExtension() const
Returns the extension of the specified type.
const OneShotBufferizationOptions & getOptions() const
Return a reference to the BufferizationOptions.
Ty & addExtension(Args &&...args)
Adds a new Extension of the type specified as template parameter, constructing it with the arguments ...
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.
LogicalResult analyzeSingleOp(Operation *op, const DominanceInfo &domInfo)
Analyze a single op (without nested ops).
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 hasUndefinedContents(OpOperand *opOperand) const override
Return true if the given tensor has undefined contents.
static bool classof(const AnalysisState *base)
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.
Ty * getExtension()
Returns the extension of the specified type.
void createAliasInfoEntry(Value v)
Add a new entry for v in the aliasInfo and equivalentInfo.
int64_t getStatNumTensorInPlace() const
LogicalResult runOneShotBufferize(Operation *op, const OneShotBufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Run One-Shot Bufferize on the given op: Analysis + Bufferization.
LogicalResult analyzeOp(Operation *op, OneShotAnalysisState &state, BufferizationStatistics *statistics=nullptr)
Analyze op and its nested ops.
Include the generated interface declarations.
Options for BufferizableOpInterface-based bufferization.
Options for analysis-enabled bufferization.
unsigned analysisFuzzerSeed
Seed for the analysis fuzzer.
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.
Compare two SSA values in a deterministic manner.