Files
clang-p2996/mlir/test/python/dialects/transform_loop_ext.py
Alex Zinenko 5f0d4f208e [mlir] Introduce Transform ops for loops
Introduce transform ops for "for" loops, in particular for peeling, software
pipelining and unrolling, along with a couple of "IR navigation" ops. These ops
are intended to be generalized to different kinds of loops when possible and
therefore use the "loop" prefix. They currently live in the SCF dialect as
there is no clear place to put transform ops that may span across several
dialects, this decision is postponed until the ops actually need to handle
non-SCF loops.

Additionally refactor some common utilities for transform ops into trait or
interface methods, and change the loop pipelining to be a returning pattern.

Reviewed By: springerm

Differential Revision: https://reviews.llvm.org/D127300
2022-06-09 11:41:55 +02:00

72 lines
1.7 KiB
Python

# RUN: %PYTHON %s | FileCheck %s
from mlir.ir import *
from mlir.dialects import transform
from mlir.dialects import pdl
from mlir.dialects.transform import loop
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 getParentLoop():
sequence = transform.SequenceOp()
with InsertionPoint(sequence.body):
loop.GetParentForOp(sequence.bodyTarget, num_loops=2)
transform.YieldOp()
# CHECK-LABEL: TEST: getParentLoop
# CHECK: = transform.loop.get_parent_for %
# CHECK: num_loops = 2
@run
def loopOutline():
sequence = transform.SequenceOp()
with InsertionPoint(sequence.body):
loop.LoopOutlineOp(sequence.bodyTarget, func_name="foo")
transform.YieldOp()
# CHECK-LABEL: TEST: loopOutline
# CHECK: = transform.loop.outline %
# CHECK: func_name = "foo"
@run
def loopPeel():
sequence = transform.SequenceOp()
with InsertionPoint(sequence.body):
loop.LoopPeelOp(sequence.bodyTarget)
transform.YieldOp()
# CHECK-LABEL: TEST: loopPeel
# CHECK: = transform.loop.peel %
@run
def loopPipeline():
sequence = transform.SequenceOp()
with InsertionPoint(sequence.body):
loop.LoopPipelineOp(sequence.bodyTarget, iteration_interval=3)
transform.YieldOp()
# CHECK-LABEL: TEST: loopPipeline
# CHECK: = transform.loop.pipeline %
# CHECK-DAG: iteration_interval = 3
# CHECK-DAG: read_latency = 10
@run
def loopUnroll():
sequence = transform.SequenceOp()
with InsertionPoint(sequence.body):
loop.LoopUnrollOp(sequence.bodyTarget, factor=42)
transform.YieldOp()
# CHECK-LABEL: TEST: loopUnroll
# CHECK: transform.loop.unroll %
# CHECK: factor = 42