CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
86 lines
3.5 KiB
C++
86 lines
3.5 KiB
C++
//===- BufferDeallocationOpInterfaceImpl.cpp ------------------------------===//
|
|
//
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#include "mlir/Dialect/Arith/Transforms/BufferDeallocationOpInterfaceImpl.h"
|
|
#include "mlir/Dialect/Arith/IR/Arith.h"
|
|
#include "mlir/Dialect/Bufferization/IR/BufferDeallocationOpInterface.h"
|
|
#include "mlir/Dialect/MemRef/IR/MemRef.h"
|
|
#include "mlir/IR/Dialect.h"
|
|
#include "mlir/IR/Operation.h"
|
|
|
|
using namespace mlir;
|
|
using namespace mlir::bufferization;
|
|
|
|
namespace {
|
|
/// Provides custom logic to materialize ownership indicator values for the
|
|
/// result value of 'arith.select'. Instead of cloning or runtime alias
|
|
/// checking, this implementation inserts another `arith.select` to choose the
|
|
/// ownership indicator of the operand in the same way the original
|
|
/// `arith.select` chooses the MemRef operand. If at least one of the operand's
|
|
/// ownerships is 'Unknown', fall back to the default implementation.
|
|
///
|
|
/// Example:
|
|
/// ```mlir
|
|
/// // let ownership(%m0) := %o0
|
|
/// // let ownership(%m1) := %o1
|
|
/// %res = arith.select %cond, %m0, %m1
|
|
/// ```
|
|
/// The default implementation would insert a clone and replace all uses of the
|
|
/// result of `arith.select` with that clone:
|
|
/// ```mlir
|
|
/// %res = arith.select %cond, %m0, %m1
|
|
/// %clone = bufferization.clone %res
|
|
/// // let ownership(%res) := 'Unknown'
|
|
/// // let ownership(%clone) := %true
|
|
/// // replace all uses of %res with %clone
|
|
/// ```
|
|
/// This implementation, on the other hand, materializes the following:
|
|
/// ```mlir
|
|
/// %res = arith.select %cond, %m0, %m1
|
|
/// %res_ownership = arith.select %cond, %o0, %o1
|
|
/// // let ownership(%res) := %res_ownership
|
|
/// ```
|
|
struct SelectOpInterface
|
|
: public BufferDeallocationOpInterface::ExternalModel<SelectOpInterface,
|
|
arith::SelectOp> {
|
|
FailureOr<Operation *> process(Operation *op, DeallocationState &state,
|
|
const DeallocationOptions &options) const {
|
|
return op; // nothing to do
|
|
}
|
|
|
|
std::pair<Value, Value>
|
|
materializeUniqueOwnershipForMemref(Operation *op, DeallocationState &state,
|
|
const DeallocationOptions &options,
|
|
OpBuilder &builder, Value value) const {
|
|
auto selectOp = cast<arith::SelectOp>(op);
|
|
assert(value == selectOp.getResult() &&
|
|
"Value not defined by this operation");
|
|
|
|
Block *block = value.getParentBlock();
|
|
if (!state.getOwnership(selectOp.getTrueValue(), block).isUnique() ||
|
|
!state.getOwnership(selectOp.getFalseValue(), block).isUnique())
|
|
return state.getMemrefWithUniqueOwnership(builder, value,
|
|
value.getParentBlock());
|
|
|
|
Value ownership = arith::SelectOp::create(
|
|
builder, op->getLoc(), selectOp.getCondition(),
|
|
state.getOwnership(selectOp.getTrueValue(), block).getIndicator(),
|
|
state.getOwnership(selectOp.getFalseValue(), block).getIndicator());
|
|
return {selectOp.getResult(), ownership};
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
void mlir::arith::registerBufferDeallocationOpInterfaceExternalModels(
|
|
DialectRegistry ®istry) {
|
|
registry.addExtension(+[](MLIRContext *ctx, ArithDialect *dialect) {
|
|
SelectOp::attachInterface<SelectOpInterface>(*ctx);
|
|
});
|
|
}
|