diff --git a/README.md b/README.md index f8aafb2d..e728f917 100644 --- a/README.md +++ b/README.md @@ -77,7 +77,7 @@ The `emitc-opt` tool supports the following options: | `--convert-scf-to-emitc` | Convert SCF dialect to EmitC dialect, maintaining structured control flow| | `--convert-stablehlo-region-ops-to-emitc ` | Convert StableHLO operations containing regions to EmitC dialect. | | `--convert-stablehlo-to-emitc ` | Convert from StableHLO dialect to EmitC dialect. | -| `--convert-arith-to-emitc ` | Convert arith dialect to EmitC dialect, replacing IndexCastOp. | +| `--convert-arith-to-emitc-ext ` | Convert arith dialect to EmitC dialect (extended). | | `--convert-tensor-to-emitc ` | Convert tensor dialect to EmitC dialect. | | `--convert-tosa-to-emitc ` | Convert TOSA dialect to EmitC dialect. | | `--insert-emitc-stablehlo-include` | Insert an EmitC include for the StableHLO dialect. | diff --git a/build_tools/llvm_version.txt b/build_tools/llvm_version.txt index 4c0b7707..ab3f1291 100644 --- a/build_tools/llvm_version.txt +++ b/build_tools/llvm_version.txt @@ -1 +1 @@ -d592c8ec8f7138dcbde6f0890d048e59cba95041 +e371ada409b225ea990b5ac0d5cafea26a6046e1 diff --git a/docs/arith-op-coverage.md b/docs/arith-op-coverage.md index 33f50ed3..76b69198 100644 --- a/docs/arith-op-coverage.md +++ b/docs/arith-op-coverage.md @@ -6,7 +6,7 @@ SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception The table below shows the supported Arithmetic ops. -| op | supported | comment | -| :-------------------- |:------------------:| :-------------------- | -| constant | :white_check_mark: | via `emitc-translate` | -| index_cast | :heavy_check_mark: | | +| op | supported | comment | +| :-------------------- |:------------------:| :----------------------------------- | +| constant | :heavy_check_mark: | | +| index_cast | :heavy_check_mark: | local extension compared to upstream | diff --git a/include/emitc/Conversion/Passes.td b/include/emitc/Conversion/Passes.td index 4872ab1d..ced19847 100644 --- a/include/emitc/Conversion/Passes.td +++ b/include/emitc/Conversion/Passes.td @@ -23,8 +23,8 @@ def ConvertStablehloToEmitC : Pass<"convert-stablehlo-to-emitc", "func::FuncOp"> let dependentDialects = ["EmitCDialect"]; } -def ConvertArithToEmitC : Pass<"convert-arith-to-emitc", "func::FuncOp"> { - let summary = "Convert arith dialect to EmitC dialect, replacing IndexCastOp."; +def ConvertArithToEmitC : Pass<"convert-arith-to-emitc-ext", "func::FuncOp"> { + let summary = "Convert arith dialect to EmitC dialect (extended)."; let constructor = "createConvertArithToEmitCPass()"; let dependentDialects = ["EmitCDialect"]; } diff --git a/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp b/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp index e54ae1f7..06a93cf6 100644 --- a/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp +++ b/lib/Conversion/ArithToEmitC/ArithToEmitC.cpp @@ -10,6 +10,7 @@ // //===----------------------------------------------------------------------===// +#include "mlir/Conversion/ArithToEmitC/ArithToEmitC.h" #include "mlir/Dialect/Arith/IR/Arith.h" #include "mlir/Dialect/EmitC/IR/EmitC.h" #include "mlir/IR/BuiltinOps.h" @@ -71,7 +72,12 @@ struct ConvertArithToEmitCPass target.addIllegalOp(); RewritePatternSet patterns(&getContext()); + + TypeConverter typeConverter; + typeConverter.addConversion([](Type type) { return type; }); + populateArithToEmitcPatterns(&getContext(), patterns); + populateArithToEmitCPatterns(typeConverter, patterns); if (failed(applyPartialConversion(getOperation(), target, std::move(patterns)))) diff --git a/lib/Conversion/ArithToEmitC/CMakeLists.txt b/lib/Conversion/ArithToEmitC/CMakeLists.txt index 249c0bb1..d4b94b09 100644 --- a/lib/Conversion/ArithToEmitC/CMakeLists.txt +++ b/lib/Conversion/ArithToEmitC/CMakeLists.txt @@ -1,4 +1,4 @@ -add_mlir_library(MLIRArithToEmitC +add_mlir_library(MLIRArithToEmitCExt ArithToEmitC.cpp DEPENDS diff --git a/test/Conversion/arith-to-emitc.mlir b/test/Conversion/arith-to-emitc.mlir index c9fff13f..fdce356d 100644 --- a/test/Conversion/arith-to-emitc.mlir +++ b/test/Conversion/arith-to-emitc.mlir @@ -1,6 +1,6 @@ -// RUN: emitc-opt -convert-arith-to-emitc %s | FileCheck %s -// RUN: emitc-opt -convert-arith-to-emitc %s | emitc-translate --mlir-to-cpp | FileCheck %s -check-prefix=CPP -// RUN: emitc-opt -insert-emitc-arith-include -convert-arith-to-emitc %s | FileCheck %s --check-prefixes=CHECK,CHECK-INCLUDE +// RUN: emitc-opt -convert-arith-to-emitc-ext %s | FileCheck %s +// RUN: emitc-opt -convert-arith-to-emitc-ext %s | emitc-translate --mlir-to-cpp | FileCheck %s -check-prefix=CPP +// RUN: emitc-opt -insert-emitc-arith-include -convert-arith-to-emitc-ext %s | FileCheck %s --check-prefixes=CHECK,CHECK-INCLUDE // RUN: emitc-opt -arith-to-emitc-pipeline %s | FileCheck %s --check-prefixes=CHECK,CHECK-INCLUDE // CHECK-INCLUDE: emitc.include "emitc/arith.h" diff --git a/test/Conversion/tensor-to-emitc.mlir b/test/Conversion/tensor-to-emitc.mlir index 7643dc0f..2ce69409 100644 --- a/test/Conversion/tensor-to-emitc.mlir +++ b/test/Conversion/tensor-to-emitc.mlir @@ -6,19 +6,19 @@ // CHECK-INCLUDE: emitc.include "emitc/tensor.h" func.func @std_extract_element(%arg0: tensor, %arg1: tensor<2xi32> ) -> () { - %0 = arith.constant 0 : index - %1 = arith.constant 1 : index + %0 = "emitc.constant"() {value = 0 : index} : () -> index + %1 = "emitc.constant"() {value = 1 : index} : () -> index %2 = tensor.extract %arg0[] : tensor %3 = tensor.extract %arg1[%0] : tensor<2xi32> %4 = tensor.extract %arg1[%1] : tensor<2xi32> return } // CHECK-LABEL: func @std_extract_element -// CHECK-NEXT: constant 0 : index -// CHECK-NEXT: constant 1 : index +// CHECK-NEXT: "emitc.constant"() <{value = 0 : index}> : () -> index +// CHECK-NEXT: "emitc.constant"() <{value = 1 : index}> : () -> index // CHECK-NEXT: emitc.call_opaque "emitc::tensor::extract"(%arg0) : (tensor) -> i32 -// CHECK-NEXT: emitc.call_opaque "emitc::tensor::extract"(%arg1, %c0) : (tensor<2xi32>, index) -> i32 -// CHECK-NEXT: emitc.call_opaque "emitc::tensor::extract"(%arg1, %c1) : (tensor<2xi32>, index) -> i32 +// CHECK-NEXT: emitc.call_opaque "emitc::tensor::extract"(%arg1, %0) : (tensor<2xi32>, index) -> i32 +// CHECK-NEXT: emitc.call_opaque "emitc::tensor::extract"(%arg1, %1) : (tensor<2xi32>, index) -> i32 // CPP-LABEL: void std_extract_element(Tensor v1, Tensor v2) // CPP-NEXT: size_t v3 = 0; diff --git a/third_party/stablehlo b/third_party/stablehlo index f3b20b3a..aa69baea 160000 --- a/third_party/stablehlo +++ b/third_party/stablehlo @@ -1 +1 @@ -Subproject commit f3b20b3a0558187ee27a9428bc1d3c2a3ba459cf +Subproject commit aa69baea1409d7c341705e0e9342ed62802d8a4d diff --git a/tools/emitc-opt/CMakeLists.txt b/tools/emitc-opt/CMakeLists.txt index 1ac88f93..9ff5418d 100644 --- a/tools/emitc-opt/CMakeLists.txt +++ b/tools/emitc-opt/CMakeLists.txt @@ -37,7 +37,7 @@ set(LIBS MLIRSupport MLIRIR MLIREmitCDialect - MLIRArithToEmitC + MLIRArithToEmitCExt MLIRTensorToEmitC MLIRTosaToEmitC MLIREmitCTransformsLocal