Skip to content

Commit

Permalink
[mlir][linalg][bufferize] Store analysis results in BufferizationAlia…
Browse files Browse the repository at this point in the history
…sInfo

* Store inplace bufferization decisions in `inplaceBufferized`.
* Remove `InPlaceSpec`. Use a bool instead.
* Use `BufferizableOpInterface::bufferizesToWritableMemory` and `bufferizesToWritableMemory` instead of `getInPlace(BlockArgument)`. The analysis does not care about inplacability of block arguments. It only cares whether the buffer can be written to or not.
* The `kInPlaceResultsAttrName` op attribute is for testing purposes only.

This commit further decouples BufferizationAliasInfo from other dialects such as SCF.

Differential Revision: https://reviews.llvm.org/D113375
  • Loading branch information
matthias-springer committed Nov 11, 2021
1 parent 4183522 commit 2e0d821
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 162 deletions.
Expand Up @@ -182,17 +182,26 @@ def BufferizableOpInterface : OpInterface<"BufferizableOpInterface"> {
>,
InterfaceMethod<
/*desc=*/[{
Return `true` if the given OpOperand can be written to in-place. This
is the case for most ops, but some ops such as ConstantOp may
bufferize to non-writable (read-only) memory locations. This method
will never be called on OpResults that do not have a tensor type.
Return `true` if the given Value can be written to in-place. Value is
either an OpResult of this operation or a BlockArgument of a block of
this operation.

Most OpResult buffers can be written to, but some ops such as
ConstantOp may bufferize to non-writable (read-only) memory locations.
Therefore, by default, this method returns `true` for OpResults. This
method will never be called on OpResults that do not have a tensor
type.

Whether a BlockArgument can be written to or not depends on the
operation. This method conservatively returns `false`. This method
will never be called on BlockArguments that do not have a tensor type.
}],
/*retType=*/"bool",
/*methodName=*/"isWritable",
/*args=*/(ins "OpResult":$opResult),
/*args=*/(ins "Value":$value),
/*methodBody=*/"",
/*defaultImplementation=*/[{
return true;
return value.isa<OpResult>();
}]
>
];
Expand Down
Expand Up @@ -91,6 +91,12 @@ class BufferizationAliasInfo {
/// Specify that the value is known to bufferize to writable memory.
void setBufferizesToWritableMemory(Value v);

/// Mark a value as in-place bufferized.
void markInPlace(OpResult v) { inplaceBufferized.insert(v); }

/// Return `true` if a value was marked as in-place bufferized.
bool isInPlace(OpResult opResult) const;

/// Print to `os`.
void printAliases(raw_ostream &os) const;
void printEquivalences(raw_ostream &os) const;
Expand All @@ -117,6 +123,9 @@ class BufferizationAliasInfo {
/// Set of tensors that are known to bufferize to writable memory.
llvm::DenseSet<Value> bufferizeToWritableMemory;

/// Set of all OpResults that were decided to bufferize in-place.
llvm::DenseSet<OpResult> inplaceBufferized;

/// Auxiliary structure to store all the values a given value may alias with.
/// Alias information is "may be" conservative: In the presence of branches, a
/// value may alias with one of multiple other values. The concrete aliasing
Expand Down

0 comments on commit 2e0d821

Please sign in to comment.