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
246 lines
7.0 KiB
Python
246 lines
7.0 KiB
Python
# RUN: %PYTHON %s | FileCheck %s
|
|
|
|
import gc
|
|
from mlir.ir import *
|
|
|
|
|
|
def run(f):
|
|
print("\nTEST:", f.__name__)
|
|
f()
|
|
gc.collect()
|
|
assert Context._get_live_count() == 0
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_block_end
|
|
def test_insert_at_block_end():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
ip = InsertionPoint(entry_block)
|
|
assert ip.block == entry_block
|
|
assert ip.ref_operation is None
|
|
ip.insert(Operation.create("custom.op2"))
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op2"
|
|
module.operation.print()
|
|
|
|
|
|
run(test_insert_at_block_end)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_before_operation
|
|
def test_insert_before_operation():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
"custom.op2"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
ip = InsertionPoint(entry_block.operations[1])
|
|
assert ip.block == entry_block
|
|
assert ip.ref_operation == entry_block.operations[1]
|
|
ip.insert(Operation.create("custom.op3"))
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op3"
|
|
# CHECK: "custom.op2"
|
|
module.operation.print()
|
|
|
|
|
|
run(test_insert_before_operation)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_after_operation
|
|
def test_insert_after_operation():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
"custom.op2"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
custom_op1 = entry_block.operations[0]
|
|
custom_op2 = entry_block.operations[1]
|
|
InsertionPoint.after(custom_op1).insert(Operation.create("custom.op3"))
|
|
InsertionPoint.after(custom_op2).insert(Operation.create("custom.op4"))
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op3"
|
|
# CHECK: "custom.op2"
|
|
# CHECK: "custom.op4"
|
|
module.operation.print()
|
|
|
|
|
|
run(test_insert_after_operation)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_block_begin
|
|
def test_insert_at_block_begin():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op2"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
ip = InsertionPoint.at_block_begin(entry_block)
|
|
assert ip.block == entry_block
|
|
assert ip.ref_operation == entry_block.operations[0]
|
|
ip.insert(Operation.create("custom.op1"))
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op2"
|
|
module.operation.print()
|
|
|
|
|
|
run(test_insert_at_block_begin)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_block_begin_empty
|
|
def test_insert_at_block_begin_empty():
|
|
# TODO: Write this test case when we can create such a situation.
|
|
pass
|
|
|
|
|
|
run(test_insert_at_block_begin_empty)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_terminator
|
|
def test_insert_at_terminator():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
return
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
return_op = entry_block.operations[1]
|
|
ip = InsertionPoint.at_block_terminator(entry_block)
|
|
assert ip.block == entry_block
|
|
assert ip.ref_operation == return_op
|
|
custom_op2 = Operation.create("custom.op2")
|
|
ip.insert(custom_op2)
|
|
InsertionPoint.after(custom_op2).insert(Operation.create("custom.op3"))
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op2"
|
|
# CHECK: "custom.op3"
|
|
module.operation.print()
|
|
|
|
try:
|
|
InsertionPoint.after(return_op).insert(Operation.create("custom.op4"))
|
|
except IndexError as e:
|
|
# CHECK: ERROR: Cannot insert operation at the end of a block that already has a terminator.
|
|
print(f"ERROR: {e}")
|
|
|
|
|
|
run(test_insert_at_terminator)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_block_terminator_missing
|
|
def test_insert_at_block_terminator_missing():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with ctx:
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
try:
|
|
ip = InsertionPoint.at_block_terminator(entry_block)
|
|
except ValueError as e:
|
|
# CHECK: Block has no terminator
|
|
print(e)
|
|
else:
|
|
assert False, "Expected exception"
|
|
|
|
|
|
run(test_insert_at_block_terminator_missing)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insert_at_end_with_terminator_errors
|
|
def test_insert_at_end_with_terminator_errors():
|
|
with Context() as ctx, Location.unknown():
|
|
ctx.allow_unregistered_dialects = True
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
return
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
with InsertionPoint(entry_block):
|
|
try:
|
|
Operation.create("custom.op1", results=[], operands=[])
|
|
except IndexError as e:
|
|
# CHECK: ERROR: Cannot insert operation at the end of a block that already has a terminator.
|
|
print(f"ERROR: {e}")
|
|
|
|
|
|
run(test_insert_at_end_with_terminator_errors)
|
|
|
|
|
|
# CHECK-LABEL: TEST: test_insertion_point_context
|
|
def test_insertion_point_context():
|
|
ctx = Context()
|
|
ctx.allow_unregistered_dialects = True
|
|
with Location.unknown(ctx):
|
|
module = Module.parse(
|
|
r"""
|
|
func.func @foo() -> () {
|
|
"custom.op1"() : () -> ()
|
|
}
|
|
"""
|
|
)
|
|
entry_block = module.body.operations[0].regions[0].blocks[0]
|
|
with InsertionPoint(entry_block):
|
|
Operation.create("custom.op2")
|
|
with InsertionPoint.at_block_begin(entry_block):
|
|
custom_opa = Operation.create("custom.opa")
|
|
Operation.create("custom.opb")
|
|
Operation.create("custom.op3")
|
|
with InsertionPoint.after(custom_opa):
|
|
Operation.create("custom.op4")
|
|
Operation.create("custom.op5")
|
|
|
|
# CHECK: "custom.opa"
|
|
# CHECK: "custom.op4"
|
|
# CHECK: "custom.op5"
|
|
# CHECK: "custom.opb"
|
|
# CHECK: "custom.op1"
|
|
# CHECK: "custom.op2"
|
|
# CHECK: "custom.op3"
|
|
module.operation.print()
|
|
|
|
|
|
run(test_insertion_point_context)
|