mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-04-04 14:23:00 +00:00

This commit removes the deallocation capabilities of one-shot-bufferization. One-shot-bufferization should never deallocate any memrefs as this should be entirely handled by the ownership-based-buffer-deallocation pass going forward. This means the `allow-return-allocs` pass option will default to true now, `create-deallocs` defaults to false and they, as well as the escape attribute indicating whether a memref escapes the current region, will be removed. A new `allow-return-allocs-from-loops` option is added as a temporary workaround for some bufferization limitations.
108 lines
3.8 KiB
Python
108 lines
3.8 KiB
Python
# RUN: %PYTHON %s | FileCheck %s
|
|
|
|
from mlir.ir import *
|
|
from mlir.dialects import transform
|
|
from mlir.dialects.transform import bufferization
|
|
from mlir.dialects.bufferization import LayoutMapOption
|
|
|
|
|
|
def run(f):
|
|
with Context(), Location.unknown():
|
|
module = Module.create()
|
|
with InsertionPoint(module.body):
|
|
print("\nTEST:", f.__name__)
|
|
f()
|
|
print(module)
|
|
return f
|
|
|
|
|
|
@run
|
|
def testEmptyTensorToAllocTensorOpCompact():
|
|
sequence = transform.SequenceOp(
|
|
transform.FailurePropagationMode.Propagate,
|
|
[],
|
|
transform.OperationType.get("tensor.empty"),
|
|
)
|
|
with InsertionPoint(sequence.body):
|
|
bufferization.EmptyTensorToAllocTensorOp(sequence.bodyTarget)
|
|
transform.YieldOp()
|
|
# CHECK-LABEL: TEST: testEmptyTensorToAllocTensorOpCompact
|
|
# CHECK: = transform.bufferization.empty_tensor_to_alloc_tensor
|
|
# CHECK-SAME: (!transform.op<"tensor.empty">) -> !transform.op<"bufferization.alloc_tensor">
|
|
|
|
|
|
@run
|
|
def testEmptyTensorToAllocTensorOpTyped():
|
|
sequence = transform.SequenceOp(
|
|
transform.FailurePropagationMode.Propagate,
|
|
[],
|
|
transform.OperationType.get("tensor.empty"),
|
|
)
|
|
with InsertionPoint(sequence.body):
|
|
bufferization.EmptyTensorToAllocTensorOp(
|
|
transform.OperationType.get("bufferization.alloc_tensor"),
|
|
sequence.bodyTarget,
|
|
)
|
|
transform.YieldOp()
|
|
# CHECK-LABEL: TEST: testEmptyTensorToAllocTensorOpTyped
|
|
# CHECK: = transform.bufferization.empty_tensor_to_alloc_tensor
|
|
# CHECK-SAME: (!transform.op<"tensor.empty">) -> !transform.op<"bufferization.alloc_tensor">
|
|
|
|
|
|
@run
|
|
def testOneShotBufferizeOpCompact():
|
|
sequence = transform.SequenceOp(
|
|
transform.FailurePropagationMode.Propagate, [], transform.AnyOpType.get()
|
|
)
|
|
with InsertionPoint(sequence.body):
|
|
bufferization.OneShotBufferizeOp(sequence.bodyTarget)
|
|
transform.YieldOp()
|
|
# CHECK-LABEL: TEST: testOneShotBufferizeOpCompact
|
|
# CHECK: = transform.bufferization.one_shot_bufferize
|
|
# CHECK-SAME: (!transform.any_op) -> !transform.any_op
|
|
|
|
|
|
@run
|
|
def testOneShotBufferizeOpTyped():
|
|
sequence = transform.SequenceOp(
|
|
transform.FailurePropagationMode.Propagate, [], transform.AnyOpType.get()
|
|
)
|
|
with InsertionPoint(sequence.body):
|
|
bufferization.OneShotBufferizeOp(
|
|
transform.OperationType.get("test.dummy"),
|
|
sequence.bodyTarget,
|
|
)
|
|
transform.YieldOp()
|
|
# CHECK-LABEL: TEST: testOneShotBufferizeOpTyped
|
|
# CHECK: = transform.bufferization.one_shot_bufferize
|
|
# CHECK-SAME: (!transform.any_op) -> !transform.op<"test.dummy">
|
|
|
|
|
|
@run
|
|
def testOneShotBufferizeOpAttributes():
|
|
sequence = transform.SequenceOp(
|
|
transform.FailurePropagationMode.Propagate, [], transform.AnyOpType.get()
|
|
)
|
|
with InsertionPoint(sequence.body):
|
|
bufferization.OneShotBufferizeOp(
|
|
sequence.bodyTarget,
|
|
allow_return_allocs_from_loops=True,
|
|
allow_unknown_ops=True,
|
|
bufferize_function_boundaries=True,
|
|
function_boundary_type_conversion=LayoutMapOption.IdentityLayoutMap,
|
|
memcpy_op="linalg.copy",
|
|
print_conflicts=True,
|
|
test_analysis_only=True,
|
|
)
|
|
transform.YieldOp()
|
|
# CHECK-LABEL: TEST: testOneShotBufferizeOpAttributes
|
|
# CHECK: = transform.bufferization.one_shot_bufferize
|
|
# CHECK-SAME: layout{IdentityLayoutMap}
|
|
# CHECK-SAME: allow_return_allocs_from_loops = true
|
|
# CHECK-SAME: allow_unknown_ops = true
|
|
# CHECK-SAME: bufferize_function_boundaries = true
|
|
# CHECK-SAME: memcpy_op = "linalg.copy"
|
|
# CHECK-SAME: print_conflicts = true
|
|
# CHECK-SAME: test_analysis_only = true
|
|
# CHECK-SAME: (!transform.any_op) -> !transform.any_op
|