59 #include "llvm/ADT/DenseSet.h"
60 #include "llvm/ADT/SetVector.h"
66 #define DEBUG_TYPE "one-shot-analysis"
85 "__opresult_alias_set_attr__";
95 cast<ArrayAttr>(attr).getAsValueRange<StringAttr>()));
99 if (isa<TensorType>(opOperand.
get().
getType()))
104 OpBuilder(op).getStrArrayAttr(inPlaceVector));
117 if (isa<TensorType>(v.getType()))
120 for (
Block &b : r.getBlocks())
121 for (
auto bbArg : b.getArguments())
122 if (isa<TensorType>(bbArg.getType()))
127 op->
walk([&](BufferizableOpInterface bufferizableOp) {
130 for (
OpOperand &opOperand : bufferizableOp->getOpOperands())
131 if (isa<TensorType>(opOperand.get().getType()))
132 if (bufferizableOp.mustBufferizeInPlace(opOperand, *
this))
140 auto leaderIt = equivalentInfo.findLeader(v);
141 for (
auto mit = leaderIt, meit = equivalentInfo.member_end(); mit != meit;
149 auto leaderIt = aliasInfo.findLeader(v);
150 for (
auto mit = leaderIt, meit = aliasInfo.member_end(); mit != meit; ++mit) {
157 return equivalentInfo.isEquivalent(v1, v2);
162 return aliasInfo.isEquivalent(v1, v2);
166 if (inplaceBufferized.contains(&operand))
168 inplaceBufferized.insert(&operand);
170 aliasInfo.unionSets(alias.value, operand.
get());
171 ++statNumTensorInPlace;
175 assert(!inplaceBufferized.contains(&operand) &&
176 "OpOperand was already decided to bufferize inplace");
177 ++statNumTensorOutOfPlace;
182 equivalentInfo.insert(v);
194 if (!isa<TensorType>(opResult.getType()))
200 for (
OpOperand &use : opResult.getUses())
201 undefinedTensorUses.insert(&use);
209 return undefinedTensorUses.contains(opOperand);
213 return inplaceBufferized.contains(&opOperand);
217 bool isWritten =
false;
229 if (
auto bufferizableOp =
231 return bufferizableOp.isWritable(value, *
this);
238 aliasInfo.unionSets(v1, v2);
242 equivalentInfo.unionSets(v1, v2);
255 if (!state.bufferizesToMemoryWrite(opOperand))
258 return state.isInPlace(opOperand);
355 for (
Value def : definitions) {
358 Region *rDef = state.getEnclosingRepetitiveRegion(def,
options);
369 if (nextRegion == rDef)
371 assert(nextRegion &&
"expected to find another repetitive region");
409 for (
Value def : definitions) {
410 Block *defBlock = def.getParentBlock();
411 if (readBlock->
isReachable(writeBlock, {defBlock}) &&
429 static uint64_t counter = 0;
434 std::string
id =
"C_" + std::to_string(counter++);
436 std::string conflictingWriteAttr =
442 std::string readAttr =
446 if (
auto opResult = dyn_cast<OpResult>(definition)) {
447 std::string defAttr =
448 id +
"[DEF: result " + std::to_string(opResult.getResultNumber()) +
"]";
449 opResult.getDefiningOp()->setAttr(defAttr, b.
getUnitAttr());
451 auto bbArg = cast<BlockArgument>(definition);
452 std::string defAttr =
453 id +
"[DEF: bbArg " + std::to_string(bbArg.getArgNumber()) +
"]";
454 bbArg.getOwner()->getParentOp()->setAttr(defAttr, b.
getUnitAttr());
473 .findValueInReverseUseDefChain(
474 start, [&](
Value v) {
return v == other; }, config)
481 SubsetInsertionOpInterface subsetOp) {
482 auto matchingSubset = [&](
Value val) {
483 if (
auto opResult = dyn_cast<OpResult>(val))
484 if (subsetOp.isEquivalentSubset(opResult, [&](
Value v1,
Value v2) {
485 return state.areEquivalentBufferizedValues(v1, v2);
493 state.findValueInReverseUseDefChain(value, matchingSubset);
494 return static_cast<bool>(llvm::all_of(backwardSlice, matchingSubset));
510 if (
auto subsetOp = dyn_cast<SubsetInsertionOpInterface>(readingOp)) {
518 if (uRead == &subsetOp.getDestinationOperand() &&
534 if (uRead == &subsetOp.getSourceOperand() &&
535 uConflictingWrite == &subsetOp.getDestinationOperand() &&
550 dyn_cast<SubsetInsertionOpInterface>(conflictingWritingOp))
567 if (uConflictingWrite == &subsetOp.getDestinationOperand() &&
568 state.areEquivalentBufferizedValues(
569 uRead->
get(), subsetOp.getSourceOperand().get()) &&
594 if (
options.checkParallelRegions && !usesRead.empty()) {
595 for (
OpOperand *uConflictingWrite : usesWrite) {
603 state.findValueInReverseUseDefChain(
604 uConflictingWrite->get(),
605 [&](
Value v) { return state.bufferizesToMemoryWrite(v); });
606 assert(!definitionsOrLeaves.empty() &&
607 "expected at least one definition or leaf");
611 for (
Value def : definitionsOrLeaves) {
617 <<
"\n- bufferizes out-of-place due to parallel region:\n");
618 LLVM_DEBUG(llvm::dbgs()
619 <<
" unConflictingWrite = operand "
620 << uConflictingWrite->getOperandNumber() <<
" of "
621 << *uConflictingWrite->getOwner() <<
"\n");
629 Operation *readingOp = uRead->getOwner();
630 LLVM_DEBUG(llvm::dbgs() <<
"\n- check conflict:\n");
631 LLVM_DEBUG(llvm::dbgs() <<
" uRead = operand " << uRead->getOperandNumber()
632 <<
" of " << *readingOp <<
"\n");
645 state.findDefinitionsCached(uRead->get());
646 if (definitions.empty()) {
648 LLVM_DEBUG(llvm::dbgs()
649 <<
" no conflict: read value has no definitions\n");
655 for (
OpOperand *uConflictingWrite : usesWrite) {
656 LLVM_DEBUG(llvm::dbgs() <<
" unConflictingWrite = operand "
657 << uConflictingWrite->getOperandNumber() <<
" of "
658 << *uConflictingWrite->getOwner() <<
"\n");
664 LLVM_DEBUG(llvm::dbgs() <<
"\n- useDominance = " << useDominance <<
"\n");
668 Operation *conflictingWritingOp = uConflictingWrite->getOwner();
679 if (
happensBefore(readingOp, conflictingWritingOp, domInfo)) {
680 LLVM_DEBUG(llvm::dbgs()
681 <<
" no conflict: read happens before write\n");
692 if (uConflictingWrite == uRead) {
693 LLVM_DEBUG(llvm::dbgs()
694 <<
" no conflict: read and write are same use\n");
704 LLVM_DEBUG(llvm::dbgs() <<
" no conflict: read and write are in "
705 "mutually exclusive regions\n");
712 if (conflictingWritingOp == readingOp) {
713 if (
auto bufferizableOp =
options.dynCastBufferizableOp(readingOp)) {
714 if (bufferizableOp.bufferizesToElementwiseAccess(
715 state, {uRead, uConflictingWrite})) {
717 state, uRead->get(), uConflictingWrite->get()) ||
719 state, uConflictingWrite->get(), uRead->get())) {
722 <<
" no conflict: op bufferizes to element-wise access\n");
732 LLVM_DEBUG(llvm::dbgs() <<
" no conflict: non-conflicting subsets\n");
737 if (
auto bufferizableOp =
options.dynCastBufferizableOp(readingOp)) {
738 if (bufferizableOp.isNotConflicting(uRead, uConflictingWrite, state)) {
739 LLVM_DEBUG(llvm::dbgs()
740 <<
" no conflict: op interace of reading op says 'no'\n");
745 if (conflictingWritingOp != readingOp) {
746 if (
auto bufferizableOp =
747 options.dynCastBufferizableOp(conflictingWritingOp)) {
748 if (bufferizableOp.isNotConflicting(uRead, uConflictingWrite,
752 <<
" no conflict: op interace of writing op says 'no'\n");
759 for (
Value definition : definitions) {
760 LLVM_DEBUG(llvm::dbgs() <<
" * definition = " << definition <<
"\n");
763 if (
Operation *defOp = definition.getDefiningOp()) {
766 LLVM_DEBUG(llvm::dbgs()
767 <<
" no conflict: write happens before definition\n");
771 if (defOp->isProperAncestor(conflictingWritingOp)) {
774 <<
" no conflict: write is contained in definition\n");
778 auto bbArg = cast<BlockArgument>(definition);
779 Block *block = bbArg.getOwner();
781 LLVM_DEBUG(llvm::dbgs() <<
" no conflict: definition is bbArg "
782 "and write happens outside of block\n");
793 aliases.
getAliases()[0].value == definition) {
794 LLVM_DEBUG(llvm::dbgs()
795 <<
" no conflict: definition and write are same\n");
803 LLVM_DEBUG(llvm::dbgs() <<
" => RaW CONFLICT FOUND\n");
815 state.applyOnAliases(root, [&](
Value alias) {
816 for (
auto &use : alias.
getUses())
826 state.applyOnAliases(root, [&](
Value alias) {
827 for (
auto &use : alias.
getUses()) {
829 if (state.bufferizesToMemoryRead(use)) {
849 if (!state.bufferizesToMemoryWrite(use)) {
850 AliasingValueList aliases = state.getAliasingValues(use);
851 if (llvm::any_of(aliases, [&](AliasingValue a) {
852 return state.isValueRead(a.value);
896 for (
AliasingValue alias : state.getAliasingValues(operand)) {
900 if (!checkConsistencyOnly && state.bufferizesToMemoryWrite(operand))
901 usesWrite.insert(&operand);
908 static int64_t counter = 0;
910 std::string
id =
"W_" + std::to_string(counter++);
911 if (
auto opResult = dyn_cast<OpResult>(value)) {
912 std::string attr =
id +
"[NOT-WRITABLE: result " +
913 std::to_string(opResult.getResultNumber()) +
"]";
914 opResult.getDefiningOp()->setAttr(attr, b.
getUnitAttr());
916 auto bbArg = cast<BlockArgument>(value);
917 std::string attr =
id +
"[NOT-WRITABLE: bbArg " +
918 std::to_string(bbArg.getArgNumber()) +
"]";
919 bbArg.getOwner()->getParentOp()->setAttr(attr, b.
getUnitAttr());
928 bool checkConsistencyOnly =
false) {
930 !checkConsistencyOnly && state.bufferizesToMemoryWrite(operand);
938 foundWrite = !usesWrite.empty();
945 bool foundReadOnly =
false;
946 auto checkReadOnly = [&](
Value v) {
947 if (!state.isWritable(v)) {
948 foundReadOnly =
true;
949 if (state.getOptions().printConflicts)
953 state.applyOnAliases(operand.
get(), checkReadOnly);
955 state.applyOnAliases(alias.value, checkReadOnly);
957 LLVM_DEBUG(llvm::dbgs() <<
"=> NOT WRITABLE\n");
970 OneShotAnalysisState::findDefinitionsCached(
Value value) {
971 if (!cachedDefinitions.count(value))
973 return cachedDefinitions[value];
978 cachedDefinitions.clear();
986 llvm::dbgs() <<
"//===-------------------------------------------===//\n"
988 <<
" of " << *operand.
getOwner() <<
"\n");
990 bool foundInterference =
994 if (foundInterference)
995 state.bufferizeOutOfPlace(operand);
997 state.bufferizeInPlace(operand);
999 LLVM_DEBUG(llvm::dbgs()
1000 <<
"//===-------------------------------------------===//\n");
1008 if (isa<TensorType>(opOperand.get().getType()))
1018 if (
auto bufferizableOp = state.getOptions().dynCastBufferizableOp(op)) {
1019 for (
OpResult opResult : op->getOpResults()) {
1020 if (!isa<TensorType>(opResult.getType()))
1027 Value firstOperand = aliases.
begin()->opOperand->get();
1028 bool allEquivalent =
true;
1031 bool isInPlace = state.isInPlace(*alias.opOperand);
1032 Value operand = alias.opOperand->get();
1033 if (isEquiv && isInPlace && alias.isDefinite) {
1036 state.unionEquivalenceClasses(opResult, operand);
1037 allEquivalent =
false;
1040 if (!isEquiv || !isInPlace)
1041 allEquivalent =
false;
1042 if (!state.areEquivalentBufferizedValues(operand, firstOperand))
1043 allEquivalent =
false;
1056 if (allEquivalent && !bufferizableOp.bufferizesToAllocation(opResult))
1057 state.unionEquivalenceClasses(opResult, firstOperand);
1086 if (!traversedOps.insert(term))
1091 for (
Value v : term->getOperands()) {
1092 if (!isa<TensorType>(v.getType()))
1094 auto opResult = dyn_cast<OpResult>(v);
1097 worklist.push_back(opResult);
1099 while (!worklist.empty()) {
1100 OpResult opResult = worklist.pop_back_val();
1102 if (!traversedOps.insert(defOp))
1104 if (!term->getParentRegion()->findAncestorOpInRegion(*defOp))
1107 for (
auto alias : aliases) {
1108 Value v = alias.opOperand->get();
1109 if (!isa<TensorType>(v.
getType()))
1111 auto opResult = dyn_cast<OpResult>(v);
1114 worklist.push_back(opResult);
1123 result.push_back(op);
1142 orderedOps.push_back(op);
1144 switch (heuristic) {
1147 std::reverse(orderedOps.begin(), orderedOps.end());
1156 "expected that fuzzer seed it set");
1161 std::mt19937 g(
getOptions().analysisFuzzerSeed);
1162 llvm::shuffle(orderedOps.begin(), orderedOps.end(), g);
1166 llvm_unreachable(
"unsupported heuristic");
1182 static LogicalResult
1190 WalkResult walkResult = op->
walk([&](BufferizableOpInterface op) {
1192 if (!
options.isOpAllowed(op.getOperation()))
1196 if (!op.supportsUnstructuredControlFlow()) {
1197 for (Region &r : op->getRegions()) {
1198 if (r.getBlocks().size() > 1) {
1199 op->emitOpError(
"op or BufferizableOpInterface implementation does "
1200 "not support unstructured control flow, but at least "
1201 "one region has multiple blocks");
1202 return WalkResult::interrupt();
1209 if (walkResult.wasInterrupted())
1212 walkResult = op->walk([&](BufferizableOpInterface op) {
1214 if (!
options.isOpAllowed(op.getOperation()))
1220 if (
auto toTensorOp = dyn_cast<ToTensorOp>(op.getOperation())) {
1221 if (!toTensorOp.getRestrict() && !toTensorOp->getUses().empty()) {
1222 op->emitOpError(
"to_tensor ops without `restrict` are not supported by "
1223 "One-Shot Analysis");
1228 for (
OpOperand &opOperand : op->getOpOperands()) {
1229 if (isa<TensorType>(opOperand.get().getType())) {
1231 opOperand, domInfo, state,
1238 op->emitOpError(
"not bufferizable under the given constraints: "
1239 "cannot avoid RaW conflict");
1243 if (state.isInPlace(opOperand) &&
1245 opOperand, state,
true)) {
1246 op->emitOpError(
"not bufferizable under the given constraints: would "
1247 "write to read-only buffer");
1256 return success(!walkResult.wasInterrupted());
1266 if (isa<TensorType>(opOperand.get().getType()))
1276 auto buildAliasesArray = [&](
Value v) {
1278 state.applyOnAliases(v, [&](
Value alias) {
1280 llvm::raw_string_ostream stream(buffer);
1291 if (llvm::isa<TensorType>(opResult.getType())) {
1292 opResultAliasSets.push_back(buildAliasesArray(opResult));
1295 if (!opResultAliasSets.empty())
1300 bool hasTensorBbArg =
false;
1303 for (
Block &block : r.getBlocks()) {
1306 if (llvm::isa<TensorType>(bbArg.getType())) {
1307 bbArgAliasSets.push_back(buildAliasesArray(bbArg));
1308 hasTensorBbArg =
true;
1311 blockAliasSets.push_back(b.
getArrayAttr(bbArgAliasSets));
1313 regionAliasSets.push_back(b.
getArrayAttr(blockAliasSets));
1330 if (failed(state.analyzeOp(op, domInfo)))
1338 bool failedAnalysis =
false;
1341 state.gatherUndefinedTensorUses(op);
1347 if (BufferizableOpInterface bufferizableOp =
1348 options.dynCastBufferizableOp(op))
1349 failedAnalysis |= failed(bufferizableOp.verifyAnalysis(state));
1358 return success(!failedAnalysis);
1368 "invalid combination of bufferization flags");
1370 if (
options.copyBeforeWrite) {
static bool hasReadAfterWriteInterference(const DenseSet< OpOperand * > &usesRead, const DenseSet< OpOperand * > &usesWrite, const DominanceInfo &domInfo, OneShotAnalysisState &state)
Given sets of uses and writes, return true if there is a RaW conflict under the assumption that all g...
static void getAliasingReads(DenseSet< OpOperand * > &res, Value root, const OneShotAnalysisState &state)
static void equivalenceAnalysis(SmallVector< Operation * > &ops, OneShotAnalysisState &state)
Analyze equivalence of tied OpResult/OpOperand pairs of the given ops.
static void setInPlaceOpOperand(OpOperand &opOperand, bool inPlace)
Mark whether OpOperand will be bufferized inplace.
static SmallVector< Operation * > bottomUpFromTerminatorsHeuristic(Operation *op, const OneShotAnalysisState &state)
"Bottom-up from terminators" heuristic.
constexpr StringLiteral kInPlaceOperandsAttrName
Attribute marker to specify op operands that bufferize in-place.
static bool isaTensor(Type t)
static void annotateNonWritableTensor(Value value)
Annotate IR with details about the detected non-writability conflict.
static bool canUseOpDominanceDueToRegions(OpOperand *uRead, OpOperand *uWrite, const SetVector< Value > &definitions, AnalysisState &state)
Return true if op dominance can be used to rule out a read-after-write conflicts based on the orderin...
static LogicalResult bufferizableInPlaceAnalysisImpl(OpOperand &operand, OneShotAnalysisState &state, const DominanceInfo &domInfo)
Determine if operand can be bufferized in-place.
static bool matchesInsertDestination(const AnalysisState &state, Value value, SubsetInsertionOpInterface subsetOp)
Return "true" if value is originating from a subset that is equivalent to the subset that subsetOp in...
constexpr StringLiteral kOpResultAliasSetAttrName
static bool hasEquivalentValueInReverseUseDefChain(AnalysisState &state, Value start, Value other)
Return 'true' if a tensor that is equivalent to other can be found in the reverse use-def chain of st...
static bool happensBefore(Operation *a, Operation *b, const DominanceInfo &domInfo)
Return true if a happens before b, i.e., a or one of its ancestors properly dominates b and b is not ...
static bool canUseOpDominance(OpOperand *uRead, OpOperand *uWrite, const SetVector< Value > &definitions, AnalysisState &state)
static bool wouldCreateWriteToNonWritableBuffer(OpOperand &operand, OneShotAnalysisState &state, bool checkConsistencyOnly=false)
Return true if bufferizing operand inplace would create a write to a non-writable buffer.
static void annotateOpsWithAliasSets(Operation *op, const OneShotAnalysisState &state)
static 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...
static void annotateOpsWithBufferizationMarkers(Operation *op, const OneShotAnalysisState &state)
Annotate the IR with the result of the analysis. For testing/debugging only.
static bool wouldCreateReadAfterWriteInterference(OpOperand &operand, const DominanceInfo &domInfo, OneShotAnalysisState &state, bool checkConsistencyOnly=false)
Return true if bufferizing operand inplace would create a conflict.
constexpr StringLiteral kBbArgAliasSetAttrName
static bool canUseOpDominanceDueToBlocks(OpOperand *uRead, OpOperand *uWrite, const SetVector< Value > &definitions, AnalysisState &state)
Return true if op dominance can be used to rule out a read-after-write conflicts based on the orderin...
static void getAliasingInplaceWrites(DenseSet< OpOperand * > &res, Value root, const OneShotAnalysisState &state)
static bool areNonConflictingSubsets(OpOperand *uRead, OpOperand *uConflictingWrite, const AnalysisState &state)
Return "true" if the given "read" and potentially conflicting "write" are not conflicting due to thei...
static void annotateConflict(OpOperand *uRead, OpOperand *uConflictingWrite, Value definition)
Annotate IR with details about the detected RaW conflict.
static bool isInplaceMemoryWrite(OpOperand &opOperand, const OneShotAnalysisState &state)
Return true if opOperand has been decided to bufferize in-place.
static llvm::ManagedStatic< PassManagerOptions > options
#define MLIR_DEFINE_EXPLICIT_TYPE_ID(CLASS_NAME)
Base class for generic analysis states.
This class provides management for the lifetime of the state used when printing the IR.
This class represents an argument of a Block.
Block represents an ordered list of Operations.
Operation * findAncestorOpInBlock(Operation &op)
Returns 'op' if 'op' lies in this block, or otherwise finds the ancestor operation of 'op' that lies ...
bool isReachable(Block *other, SmallPtrSet< Block *, 16 > &&except={})
Return "true" if there is a path from this block to the given block (according to the successors rela...
This class is a general helper class for creating context-global objects like types,...
StringAttr getStringAttr(const Twine &bytes)
ArrayAttr getArrayAttr(ArrayRef< Attribute > value)
A class for computing basic dominance information.
bool properlyDominates(Operation *a, Operation *b, bool enclosingOpOk=true) const
Return true if operation A properly dominates operation B, i.e.
IRValueT get() const
Return the current value being used by this operand.
This class helps build Operations.
This class represents an operand of an operation.
unsigned getOperandNumber()
Return which operand this is in the OpOperand list of the Operation.
This is a value defined by a result of an operation.
Operation is the basic unit of execution within MLIR.
Attribute getAttr(StringAttr name)
Return the specified attribute if present, null otherwise.
std::enable_if_t< llvm::function_traits< std::decay_t< FnT > >::num_args==1, RetT > walk(FnT &&callback)
Walk the operation by calling the callback for each nested operation (including this one),...
MLIRContext * getContext()
Return the context this operation is associated with.
unsigned getNumOperands()
Operation * getParentOp()
Returns the closest surrounding operation that contains this operation or nullptr if this is a top-le...
Block * getBlock()
Returns the operation block that contains this operation.
void setAttr(StringAttr name, Attribute value)
If the an attribute exists with the specified name, change it to the new value.
MutableArrayRef< Region > getRegions()
Returns the regions held by this operation.
MutableArrayRef< OpOperand > getOpOperands()
result_type_range getResultTypes()
bool isAncestor(Operation *other)
Return true if this operation is an ancestor of the other operation.
result_range getOpResults()
Region * getParentRegion()
Returns the region to which the instruction belongs.
result_range getResults()
bool isProperAncestor(Operation *other)
Return true if this operation is a proper ancestor of the other operation.
This class contains a list of basic blocks and a link to the parent operation it is attached to.
Operation * getParentOp()
Return the parent operation this region is attached to.
This class provides an efficient unique identifier for a specific C++ type.
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class represents an instance of an SSA value in the MLIR system, representing a computable value...
MLIRContext * getContext() const
Utility to get the associated MLIRContext that this value is defined in.
Type getType() const
Return the type of this value.
use_range getUses() const
Returns a range of all uses, which is useful for iterating over all uses.
void printAsOperand(raw_ostream &os, AsmState &state) const
Print this value as if it were an operand.
Operation * getDefiningOp() const
If this value is the result of an operation, return the operation that defines it.
A utility result that is used to signal how to proceed with an ongoing walk:
static WalkResult advance()
static WalkResult interrupt()
size_t getNumAliases() const
ArrayRef< T > getAliases() const
AnalysisState provides a variety of helper functions for dealing with tensor values.
AliasingValueList getAliasingValues(OpOperand &opOperand) const
Determine which Value will alias with opOperand if the op is bufferized in place.
bool bufferizesToMemoryWrite(OpOperand &opOperand) const
Return true if opOperand bufferizes to a memory write.
SetVector< Value > findDefinitions(Value value) const
Find the values that may define the contents of the given value at runtime.
virtual void resetCache()
virtual ~Extension()
Base virtual destructor.
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(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 OneShotBufferizationOptions & getOptions() const
Return a reference to the BufferizationOptions.
void unionEquivalenceClasses(Value v1, Value v2)
Union the equivalence classes of v1 and v2.
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.
bool hasUndefinedContents(OpOperand *opOperand) const override
Return true if the given tensor has undefined contents.
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.
void createAliasInfoEntry(Value v)
Add a new entry for v in the aliasInfo and equivalentInfo.
Operation * getOwner() const
Return the owner of this operand.
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.
Operation * getOwnerOfValue(Value value)
Return the owner of the given value.
LogicalResult bufferizeOp(Operation *op, const BufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Bufferize op and its nested ops that implement BufferizableOpInterface.
LogicalResult insertTensorCopies(Operation *op, const OneShotBufferizationOptions &options, BufferizationStatistics *statistics=nullptr)
Resolve RaW and other conflicts by inserting bufferization.alloc_tensor ops.
Region * getParallelRegion(Region *region, const BufferizationOptions &options)
If region is a parallel region, return region.
Region * getNextEnclosingRepetitiveRegion(Region *region, const BufferizationOptions &options)
Assuming that the given region is repetitive, find the next enclosing repetitive region.
bool hasTensorSemantics(Operation *op)
Return "true" if the given op has tensor semantics and should be bufferized.
Include the generated interface declarations.
bool insideMutuallyExclusiveRegions(Operation *a, Operation *b)
Return true if a and b are in mutually exclusive regions as per RegionBranchOpInterface.
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
This iterator enumerates elements in "reverse" order.
A maybe aliasing OpOperand.
Options for BufferizableOpInterface-based bufferization.
BufferizableOpInterface dynCastBufferizableOp(Operation *op) const
Try to cast the given op to BufferizableOpInterface if the op is allow listed.
bool isOpAllowed(Operation *op) const
Return true if the given op should be bufferized.
Bufferization statistics for debugging.
int64_t numTensorOutOfPlace
Options for analysis-enabled bufferization.
AnalysisHeuristic analysisHeuristic
The heuristic controls the order in which ops are traversed during the analysis.
@ BottomUpFromTerminators
Traversal parameters for findValueInReverseUseDefChain.
bool alwaysIncludeLeaves
Specifies if leaves (that do not have further OpOperands to follow) should be returned even if they d...
bool followSameTypeOrCastsOnly
Specifies whether OpOperands with a different type that are not the result of a CastOpInterface op sh...
bool followEquivalentOnly
Specifies whether non-equivalent OpOperands should be followed.