Moving hal.check_success -> util.status.check_ok.
This makes it easier to insert these checks at any layer of the IR and sets us up for adding more.
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/BUILD b/iree/compiler/Dialect/HAL/Conversion/HALToVM/BUILD
index 1feec91..c61e512 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/BUILD
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/BUILD
@@ -18,7 +18,6 @@
"ConvertBufferViewOps.cpp",
"ConvertCommandBufferOps.cpp",
"ConvertConstantOps.cpp",
- "ConvertControlFlowOps.cpp",
"ConvertDeviceOps.cpp",
"ConvertExecutableOps.cpp",
"ConvertExperimentalOps.cpp",
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/CMakeLists.txt b/iree/compiler/Dialect/HAL/Conversion/HALToVM/CMakeLists.txt
index b25c310..dcdf5a4 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/CMakeLists.txt
@@ -21,7 +21,6 @@
"ConvertBufferViewOps.cpp"
"ConvertCommandBufferOps.cpp"
"ConvertConstantOps.cpp"
- "ConvertControlFlowOps.cpp"
"ConvertDeviceOps.cpp"
"ConvertExecutableOps.cpp"
"ConvertExperimentalOps.cpp"
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertControlFlowOps.cpp b/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertControlFlowOps.cpp
deleted file mode 100644
index 67321f6..0000000
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertControlFlowOps.cpp
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed 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 "iree/compiler/Dialect/HAL/IR/HALOps.h"
-#include "iree/compiler/Dialect/VM/IR/VMOps.h"
-#include "mlir/Transforms/DialectConversion.h"
-
-namespace mlir {
-namespace iree_compiler {
-
-class CheckSuccessOpConversion
- : public OpConversionPattern<IREE::HAL::CheckSuccessOp> {
- public:
- CheckSuccessOpConversion(MLIRContext *context, SymbolTable &importSymbols,
- TypeConverter &typeConverter, StringRef importName)
- : OpConversionPattern(context) {}
-
- LogicalResult matchAndRewrite(
- IREE::HAL::CheckSuccessOp op, llvm::ArrayRef<Value> operands,
- ConversionPatternRewriter &rewriter) const override {
- // If status value is non-zero, fail.
- rewriter.replaceOpWithNewOp<IREE::VM::CondFailOp>(
- op, op.status(), op.message().getValueOr(""));
- return success();
- }
-};
-
-void populateHALControlFlowToVMPatterns(MLIRContext *context,
- SymbolTable &importSymbols,
- TypeConverter &typeConverter,
- OwningRewritePatternList &patterns) {
- patterns.insert<CheckSuccessOpConversion>(context, importSymbols,
- typeConverter, "hal.check_success");
-}
-
-} // namespace iree_compiler
-} // namespace mlir
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertHALToVM.cpp b/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertHALToVM.cpp
index bc39e14..7b81274 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertHALToVM.cpp
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/ConvertHALToVM.cpp
@@ -45,9 +45,6 @@
SymbolTable &importSymbols,
TypeConverter &typeConverter,
OwningRewritePatternList &patterns);
-extern void populateHALControlFlowToVMPatterns(
- MLIRContext *context, SymbolTable &importSymbols,
- TypeConverter &typeConverter, OwningRewritePatternList &patterns);
extern void populateHALDeviceToVMPatterns(MLIRContext *context,
SymbolTable &importSymbols,
TypeConverter &typeConverter,
@@ -75,8 +72,6 @@
patterns);
populateHALConstantToVMPatterns(context, importSymbols, typeConverter,
patterns);
- populateHALControlFlowToVMPatterns(context, importSymbols, typeConverter,
- patterns);
populateHALDeviceToVMPatterns(context, importSymbols, typeConverter,
patterns);
populateHALExecutableToVMPatterns(context, importSymbols, typeConverter,
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
index a086112..8d4b760 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/BUILD
@@ -22,7 +22,6 @@
"buffer_view_ops.mlir",
"command_buffer_ops.mlir",
"constant_ops.mlir",
- "control_flow_ops.mlir",
"device_ops.mlir",
"executable_ops.mlir",
],
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/CMakeLists.txt b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/CMakeLists.txt
index a94b043..4b424f6 100644
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/CMakeLists.txt
+++ b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/CMakeLists.txt
@@ -19,7 +19,6 @@
"buffer_view_ops.mlir"
"command_buffer_ops.mlir"
"constant_ops.mlir"
- "control_flow_ops.mlir"
"device_ops.mlir"
"executable_ops.mlir"
DATA
diff --git a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/control_flow_ops.mlir b/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/control_flow_ops.mlir
deleted file mode 100644
index e427275..0000000
--- a/iree/compiler/Dialect/HAL/Conversion/HALToVM/test/control_flow_ops.mlir
+++ /dev/null
@@ -1,21 +0,0 @@
-// RUN: iree-opt -split-input-file -iree-convert-hal-to-vm %s | IreeFileCheck %s
-
-// CHECK-LABEL: vm.func private @check_success
-func @check_success() {
- // CHECK: %[[CODE:.+]] =
- %statusCode = constant 1 : i32
- // CHECK: vm.cond_fail %[[CODE]]
- hal.check_success %statusCode
- return
-}
-
-// -----
-
-// CHECK-LABEL: vm.func private @check_success_with_message
-func @check_success_with_message() {
- // CHECK: %[[CODE:.+]] =
- %statusCode = constant 1 : i32
- // CHECK: vm.cond_fail %[[CODE]], "failure message"
- hal.check_success %statusCode, "failure message"
- return
-}
diff --git a/iree/compiler/Dialect/HAL/IR/HALOps.td b/iree/compiler/Dialect/HAL/IR/HALOps.td
index 8f6dbaa..c987084 100644
--- a/iree/compiler/Dialect/HAL/IR/HALOps.td
+++ b/iree/compiler/Dialect/HAL/IR/HALOps.td
@@ -108,44 +108,6 @@
}
//===----------------------------------------------------------------------===//
-// Control flow
-//===----------------------------------------------------------------------===//
-
-def HAL_CheckSuccessOp : HAL_Op<"check_success"> {
- let summary = [{raises a global failure if a status is not 'ok'}];
- let description = [{
- When the status is not 'ok' this signals a runtime failure that causes the
- entire active invocation - and possibly *all* in-flight and pending
- invocations - to fail with the given status. The status will be propagated
- back via the available runtime error handling mechanisms such as semaphores
- or synchronous invocation results.
-
- As the IREE execution model is deeply pipelined it's possible that failures
- have a latency between when they are emitted and when the application can
- observe the failure. It's also possible that other work that is in-flight
- or pending when the failure occurs will complete.
- }];
-
- let arguments = (ins
- Util_Status:$status,
- OptionalAttr<StrAttr>:$message
- );
-
- let assemblyFormat = [{
- $status (`,` $message^)? attr-dict
- }];
-
- let builders = [
- OpBuilder<(ins "Value":$status, CArg<"StringRef", [{""}]>:$message),
- [{
- build(
- $_builder, $_state, status,
- message.empty() ? StringAttr{} : $_builder.getStringAttr(message));
- }]>,
- ];
-}
-
-//===----------------------------------------------------------------------===//
// !hal.allocator / iree_hal_allocator_t
//===----------------------------------------------------------------------===//
diff --git a/iree/compiler/Dialect/Util/IR/UtilOps.td b/iree/compiler/Dialect/Util/IR/UtilOps.td
index 2a7efd2..1b8eb82 100644
--- a/iree/compiler/Dialect/Util/IR/UtilOps.td
+++ b/iree/compiler/Dialect/Util/IR/UtilOps.td
@@ -455,4 +455,42 @@
let verifier = [{ return verify$cppClass(*this); }];
}
+//===----------------------------------------------------------------------===//
+// Status
+//===----------------------------------------------------------------------===//
+
+def Util_StatusCheckOkOp : Util_Op<"status.check_ok"> {
+ let summary = [{raises a global failure if a status is not 'ok'}];
+ let description = [{
+ When the status is not 'ok' this signals a runtime failure that causes the
+ entire active invocation - and possibly *all* in-flight and pending
+ invocations - to fail with the given status. The status will be propagated
+ back via the available runtime error handling mechanisms such as semaphores
+ or synchronous invocation results.
+
+ As the IREE execution model is deeply pipelined it's possible that failures
+ have a latency between when they are emitted and when the application can
+ observe the failure. It's also possible that other work that is in-flight
+ or pending when the failure occurs will complete.
+ }];
+
+ let arguments = (ins
+ Util_Status:$status,
+ OptionalAttr<StrAttr>:$message
+ );
+
+ let assemblyFormat = [{
+ $status (`,` $message^)? attr-dict
+ }];
+
+ let builders = [
+ OpBuilder<(ins "Value":$status, CArg<"StringRef", [{""}]>:$message),
+ [{
+ build(
+ $_builder, $_state, status,
+ message.empty() ? StringAttr{} : $_builder.getStringAttr(message));
+ }]>,
+ ];
+}
+
#endif // IREE_DIALECT_UTIL_IR_UTIL_OPS
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/BUILD b/iree/compiler/Dialect/VM/Conversion/UtilToVM/BUILD
index d9b05b8..fb0ef51 100644
--- a/iree/compiler/Dialect/VM/Conversion/UtilToVM/BUILD
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/BUILD
@@ -15,6 +15,7 @@
srcs = [
"ConvertGlobalOps.cpp",
"ConvertListOps.cpp",
+ "ConvertStatusOps.cpp",
"ConvertUtilToVM.cpp",
],
hdrs = [
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/CMakeLists.txt b/iree/compiler/Dialect/VM/Conversion/UtilToVM/CMakeLists.txt
index b9946b7..d5a2d5a 100644
--- a/iree/compiler/Dialect/VM/Conversion/UtilToVM/CMakeLists.txt
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/CMakeLists.txt
@@ -18,6 +18,7 @@
SRCS
"ConvertGlobalOps.cpp"
"ConvertListOps.cpp"
+ "ConvertStatusOps.cpp"
"ConvertUtilToVM.cpp"
DEPS
MLIRIR
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertStatusOps.cpp b/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertStatusOps.cpp
new file mode 100644
index 0000000..c57db63
--- /dev/null
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertStatusOps.cpp
@@ -0,0 +1,40 @@
+// Copyright 2020 The IREE Authors
+//
+// Licensed 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 "iree/compiler/Dialect/Util/IR/UtilOps.h"
+#include "iree/compiler/Dialect/VM/IR/VMOps.h"
+#include "mlir/Transforms/DialectConversion.h"
+
+namespace mlir {
+namespace iree_compiler {
+
+class StatusCheckOkOpConversion
+ : public OpConversionPattern<IREE::Util::StatusCheckOkOp> {
+ public:
+ StatusCheckOkOpConversion(MLIRContext *context, TypeConverter &typeConverter)
+ : OpConversionPattern(context) {}
+
+ LogicalResult matchAndRewrite(
+ IREE::Util::StatusCheckOkOp op, llvm::ArrayRef<Value> newOperands,
+ ConversionPatternRewriter &rewriter) const override {
+ IREE::Util::StatusCheckOkOp::Adaptor operands(newOperands);
+ // If status value is non-zero, fail.
+ rewriter.replaceOpWithNewOp<IREE::VM::CondFailOp>(
+ op, operands.status(), op.message().getValueOr(""));
+ return success();
+ }
+};
+
+void populateUtilStatusToVMPatterns(MLIRContext *context,
+ ConversionTarget &conversionTarget,
+ TypeConverter &typeConverter,
+ OwningRewritePatternList &patterns) {
+ conversionTarget.addIllegalOp<IREE::Util::StatusCheckOkOp>();
+ patterns.insert<StatusCheckOkOpConversion>(context, typeConverter);
+}
+
+} // namespace iree_compiler
+} // namespace mlir
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertUtilToVM.cpp b/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertUtilToVM.cpp
index d08e885..f4d09ee 100644
--- a/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertUtilToVM.cpp
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/ConvertUtilToVM.cpp
@@ -27,6 +27,10 @@
void populateUtilListToVMPatterns(MLIRContext *context,
TypeConverter &typeConverter,
OwningRewritePatternList &patterns);
+void populateUtilStatusToVMPatterns(MLIRContext *context,
+ ConversionTarget &conversionTarget,
+ TypeConverter &typeConverter,
+ OwningRewritePatternList &patterns);
namespace {
@@ -111,6 +115,8 @@
populateUtilGlobalToVMPatterns(context, conversionTarget, typeConverter,
patterns);
populateUtilListToVMPatterns(context, typeConverter, patterns);
+ populateUtilStatusToVMPatterns(context, conversionTarget, typeConverter,
+ patterns);
}
} // namespace iree_compiler
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/BUILD b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/BUILD
index 38e1d21..7a28f5c 100644
--- a/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/BUILD
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/BUILD
@@ -21,6 +21,7 @@
"global_ops.mlir",
"hint_ops.mlir",
"list_ops.mlir",
+ "status_ops.mlir",
],
include = ["*.mlir"],
),
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/CMakeLists.txt b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/CMakeLists.txt
index 56b0767..fce34b6 100644
--- a/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/CMakeLists.txt
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/CMakeLists.txt
@@ -18,6 +18,7 @@
"global_ops.mlir"
"hint_ops.mlir"
"list_ops.mlir"
+ "status_ops.mlir"
DATA
iree::tools::IreeFileCheck
iree::tools::iree-opt
diff --git a/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/status_ops.mlir b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/status_ops.mlir
new file mode 100644
index 0000000..925e9fd
--- /dev/null
+++ b/iree/compiler/Dialect/VM/Conversion/UtilToVM/test/status_ops.mlir
@@ -0,0 +1,21 @@
+// RUN: iree-opt -split-input-file -iree-vm-conversion %s | IreeFileCheck %s
+
+// CHECK-LABEL: vm.func private @status_check_ok
+func @status_check_ok() {
+ // CHECK: %[[CODE:.+]] =
+ %statusCode = constant 1 : i32
+ // CHECK: vm.cond_fail %[[CODE]]
+ util.status.check_ok %statusCode
+ return
+}
+
+// -----
+
+// CHECK-LABEL: vm.func private @status_check_ok_with_message
+func @status_check_ok_with_message() {
+ // CHECK: %[[CODE:.+]] =
+ %statusCode = constant 1 : i32
+ // CHECK: vm.cond_fail %[[CODE]], "failure message"
+ util.status.check_ok %statusCode, "failure message"
+ return
+}