Adding compilation reentrancy tests and new HAL pipeline phases. (#12503)
Two new `--compile-to=` phases are supported:
- `executable-sources`: run just past interface materialization where
`hal.executable` ops with target configurations are present.
- `executable-targets`: run just past executable translation where
`hal.executable.variant` ops have been lowered to their final MLIR form
before linking and serialization (LLVM dialect, SPIR-V dialect, etc).
New tests are added that demonstrate and verify that iree-opt pipelines
can be run piecewise to produce a final output and that `--compile-to=`
at any particular phase can be passed back in and lowered down to a
final output.
A few passes were tweaked to ensure these tests pass.
diff --git a/tools/test/BUILD b/tools/test/BUILD
index 8bd9fa6..f7bf4f8 100644
--- a/tools/test/BUILD
+++ b/tools/test/BUILD
@@ -18,6 +18,8 @@
name = "lit",
srcs = enforce_glob(
[
+ "compile_pipelines.mlir",
+ "compile_to_continuation.mlir",
"compile_to_phase.mlir",
"executable_benchmarks.mlir",
"executable_sources.mlir",
@@ -46,6 +48,7 @@
tools = [
"//tools:iree-benchmark-module",
"//tools:iree-compile",
+ "//tools:iree-opt",
"//tools:iree-run-mlir",
"//tools:iree-run-module",
"@llvm-project//lld",
diff --git a/tools/test/CMakeLists.txt b/tools/test/CMakeLists.txt
index 64a3e22..7c92d9d 100644
--- a/tools/test/CMakeLists.txt
+++ b/tools/test/CMakeLists.txt
@@ -14,6 +14,8 @@
NAME
lit
SRCS
+ "compile_pipelines.mlir"
+ "compile_to_continuation.mlir"
"compile_to_phase.mlir"
"executable_benchmarks.mlir"
"executable_sources.mlir"
@@ -32,6 +34,7 @@
FileCheck
iree-benchmark-module
iree-compile
+ iree-opt
iree-run-mlir
iree-run-module
not
diff --git a/tools/test/compile_pipelines.mlir b/tools/test/compile_pipelines.mlir
new file mode 100644
index 0000000..7275ec9
--- /dev/null
+++ b/tools/test/compile_pipelines.mlir
@@ -0,0 +1,14 @@
+// RUN: iree-opt --iree-common-input-transformation-pipeline %s | \
+// RUN: iree-opt --iree-abi-transformation-pipeline - | \
+// RUN: iree-opt --iree-common-input-transformation-pipeline - | \
+// RUN: iree-opt --iree-flow-transformation-pipeline - | \
+// RUN: iree-opt --iree-stream-transformation-pipeline - | \
+// RUN: iree-opt --iree-hal-transformation-pipeline --iree-hal-target-backends=vmvx - | \
+// RUN: iree-opt --iree-vm-transformation-pipeline - | \
+// RUN: FileCheck %s
+
+// CHECK: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+func.func @abs(%input : tensor<f32>) -> (tensor<f32>) {
+ %result = math.absf %input : tensor<f32>
+ return %result : tensor<f32>
+}
diff --git a/tools/test/compile_to_continuation.mlir b/tools/test/compile_to_continuation.mlir
new file mode 100644
index 0000000..631afca
--- /dev/null
+++ b/tools/test/compile_to_continuation.mlir
@@ -0,0 +1,44 @@
+// RUN: iree-compile --compile-to=input %s | \
+// RUN: iree-compile --output-format=vm-asm --iree-hal-target-backends=vmvx - | \
+// RUN: FileCheck %s --check-prefix=INPUT-PHASE
+// INPUT-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=abi %s | \
+// RUN: iree-compile --output-format=vm-asm --iree-hal-target-backends=vmvx - | \
+// RUN: FileCheck %s --check-prefix=ABI-PHASE
+// ABI-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=flow %s | \
+// RUN: iree-compile --output-format=vm-asm --iree-hal-target-backends=vmvx - | \
+// RUN: FileCheck %s --check-prefix=FLOW-PHASE
+// FLOW-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=stream %s | \
+// RUN: iree-compile --output-format=vm-asm --iree-hal-target-backends=vmvx - | \
+// RUN: FileCheck %s --check-prefix=STREAM-PHASE
+// STREAM-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=executable-sources --iree-hal-target-backends=vmvx %s | \
+// RUN: iree-compile --output-format=vm-asm - | \
+// RUN: FileCheck %s --check-prefix=EXECUTABLE-SOURCES-PHASE
+// EXECUTABLE-SOURCES-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=executable-targets --iree-hal-target-backends=vmvx %s | \
+// RUN: iree-compile --output-format=vm-asm - | \
+// RUN: FileCheck %s --check-prefix=EXECUTABLE-TARGETS-PHASE
+// EXECUTABLE-TARGETS-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=hal --iree-hal-target-backends=vmvx %s | \
+// RUN: iree-compile --output-format=vm-asm - | \
+// RUN: FileCheck %s --check-prefix=HAL-PHASE
+// HAL-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+// RUN: iree-compile --compile-to=vm --iree-hal-target-backends=vmvx %s | \
+// RUN: iree-compile --output-format=vm-asm - | \
+// RUN: FileCheck %s --check-prefix=VM-PHASE
+// VM-PHASE: vm.func private @abs(%arg0: !vm.ref<!hal.buffer_view>) -> !vm.ref<!hal.buffer_view>
+
+func.func @abs(%input : tensor<f32>) -> (tensor<f32>) {
+ %result = math.absf %input : tensor<f32>
+ return %result : tensor<f32>
+}
diff --git a/tools/test/compile_to_phase.mlir b/tools/test/compile_to_phase.mlir
index cb3a8ed..b88dcac 100644
--- a/tools/test/compile_to_phase.mlir
+++ b/tools/test/compile_to_phase.mlir
@@ -1,20 +1,31 @@
-// RUN: iree-compile --compile-to=input --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=INPUT-PHASE
+// RUN: iree-compile --compile-to=input %s | FileCheck %s --check-prefix=INPUT-PHASE
// INPUT-PHASE: func.func @abs(%[[ARG0:.+]]: tensor<f32>)
// INPUT-PHASE: math.absf %[[ARG0]] : tensor<f32>
-// RUN: iree-compile --compile-to=abi --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=ABI-PHASE
+// RUN: iree-compile --compile-to=abi %s | FileCheck %s --check-prefix=ABI-PHASE
// ABI-PHASE: func.func @abs(%[[ARG0:.+]]: !hal.buffer_view)
// ABI-PHASE: %[[INPUT:.+]] = hal.tensor.import %[[ARG0]] : !hal.buffer_view -> tensor<f32>
// ABI-PHASE: math.absf %[[INPUT]] : tensor<f32>
-// RUN: iree-compile --compile-to=flow --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=FLOW-PHASE
+// RUN: iree-compile --compile-to=flow %s | FileCheck %s --check-prefix=FLOW-PHASE
// FLOW-PHASE: flow.executable.export public @abs_dispatch_0
// FLOW-PHASE: flow.dispatch @abs_dispatch_0
-// RUN: iree-compile --compile-to=stream --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=STREAM-PHASE
+// RUN: iree-compile --compile-to=stream %s | FileCheck %s --check-prefix=STREAM-PHASE
// STREAM-PHASE: stream.executable.export public @abs_dispatch_0
// STREAM-PHASE: stream.cmd.dispatch @abs_dispatch_0
+// RUN: iree-compile --compile-to=executable-sources --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=EXECUTABLE-SOURCES-PHASE
+// EXECUTABLE-SOURCES-PHASE: hal.executable private @abs_dispatch_0
+// EXECUTABLE-SOURCES-PHASE: hal.executable.variant
+// EXECUTABLE-SOURCES-PHASE: linalg.generic
+// EXECUTABLE-SOURCES-PHASE: math.absf
+
+// RUN: iree-compile --compile-to=executable-targets --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=EXECUTABLE-TARGETS-PHASE
+// EXECUTABLE-TARGETS-PHASE: hal.executable private @abs_dispatch_0
+// EXECUTABLE-TARGETS-PHASE: hal.executable.variant
+// EXECUTABLE-TARGETS-PHASE: vm.abs.f32
+
// RUN: iree-compile --compile-to=hal --iree-hal-target-backends=vmvx %s | FileCheck %s --check-prefix=HAL-PHASE
// HAL-PHASE: hal.executable private @abs_dispatch_0
// HAL-PHASE: hal.executable.binary