aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDiego Caballero <diego.caballero@intel.com>2020-02-11 09:38:34 -0800
committerDiego Caballero <diego.caballero@intel.com>2020-02-11 10:28:30 -0800
commit696f80736b861dfab5a7330dd009fd1d53b60356 (patch)
treed036887fe37508f16b496aba4ae2531cf35938ab
parent734f086b42c7e2d7aaee41cc4babad7ef8dcdb9c (diff)
downloadllvm-696f80736b861dfab5a7330dd009fd1d53b60356.zip
llvm-696f80736b861dfab5a7330dd009fd1d53b60356.tar.gz
llvm-696f80736b861dfab5a7330dd009fd1d53b60356.tar.bz2
[mlir] Turn flags in ConvertStandardToLLVM into pass flags
Follow-up on D72802. Turn -convert-std-to-llvm-use-alloca and -convert-std-to-llvm-bare-ptr-memref-call-conv into pass flags of LLVMLoweringPass. Reviewed By: mehdi_amini Differential Revision: https://reviews.llvm.org/D73912
-rw-r--r--mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h3
-rw-r--r--mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp64
-rw-r--r--mlir/test/Conversion/StandardToLLVM/calling-convention.mlir2
-rw-r--r--mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir4
-rw-r--r--mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir2
5 files changed, 33 insertions, 42 deletions
diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
index 8f31902..7d2a076 100644
--- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
+++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h
@@ -58,7 +58,8 @@ void populateStdToLLVMBarePtrConversionPatterns(
/// Specifying `useAlloca-true` emits stack allocations instead. In the future
/// this may become an enum when we have concrete uses for other options.
std::unique_ptr<OpPassBase<ModuleOp>>
-createLowerToLLVMPass(bool useAlloca = false, bool emitCWrappers = false);
+createLowerToLLVMPass(bool useAlloca = false, bool useBarePtrCallConv = false,
+ bool emitCWrappers = false);
namespace LLVM {
/// Make argument-taking successors of each block distinct. PHI nodes in LLVM
diff --git a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
index 36c98d0e..17209c7 100644
--- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
+++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp
@@ -36,25 +36,6 @@ using namespace mlir;
#define PASS_NAME "convert-std-to-llvm"
-static llvm::cl::OptionCategory
- clOptionsCategory("Standard to LLVM lowering options");
-
-static llvm::cl::opt<bool>
- clUseAlloca(PASS_NAME "-use-alloca",
- llvm::cl::desc("Replace emission of malloc/free by alloca"),
- llvm::cl::init(false));
-
-static llvm::cl::opt<bool>
- clEmitCWrappers(PASS_NAME "-emit-c-wrappers",
- llvm::cl::desc("Emit C-compatible wrapper functions"),
- llvm::cl::init(false));
-
-static llvm::cl::opt<bool> clUseBarePtrCallConv(
- PASS_NAME "-use-bare-ptr-memref-call-conv",
- llvm::cl::desc("Replace FuncOp's MemRef arguments with "
- "bare pointers to the MemRef element types"),
- llvm::cl::init(false));
-
// Extract an LLVM IR type from the LLVM IR dialect type.
static LLVM::LLVMType unwrap(Type type) {
if (!type)
@@ -2730,11 +2711,14 @@ namespace {
/// A pass converting MLIR operations into the LLVM IR dialect.
struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
/// Creates an LLVM lowering pass.
- explicit LLVMLoweringPass(bool useAlloca = false,
- bool useBarePtrCallConv = false,
- bool emitCWrappers = false)
- : useAlloca(useAlloca), useBarePtrCallConv(useBarePtrCallConv),
- emitCWrappers(emitCWrappers) {}
+ explicit LLVMLoweringPass(bool useAlloca, bool useBarePtrCallConv,
+ bool emitCWrappers) {
+ this->useAlloca = useAlloca;
+ this->useBarePtrCallConv = useBarePtrCallConv;
+ this->emitCWrappers = emitCWrappers;
+ }
+ explicit LLVMLoweringPass() {}
+ LLVMLoweringPass(const LLVMLoweringPass &pass) {}
/// Run the dialect converter on the module.
void runOnModule() override {
@@ -2769,27 +2753,33 @@ struct LLVMLoweringPass : public ModulePass<LLVMLoweringPass> {
}
/// Use `alloca` instead of `call @malloc` for converting std.alloc.
- bool useAlloca;
+ Option<bool> useAlloca{
+ *this, "use-alloca",
+ llvm::cl::desc("Replace emission of malloc/free by alloca"),
+ llvm::cl::init(false)};
/// Convert memrefs to bare pointers in function signatures.
- bool useBarePtrCallConv;
+ Option<bool> useBarePtrCallConv{
+ *this, "use-bare-ptr-memref-call-conv",
+ llvm::cl::desc("Replace FuncOp's MemRef arguments with "
+ "bare pointers to the MemRef element types"),
+ llvm::cl::init(false)};
/// Emit wrappers for C-compatible pointer-to-struct memref descriptors.
- bool emitCWrappers;
+ Option<bool> emitCWrappers{
+ *this, "emit-c-wrappers",
+ llvm::cl::desc("Emit C-compatible wrapper functions"),
+ llvm::cl::init(false)};
};
} // end namespace
std::unique_ptr<OpPassBase<ModuleOp>>
-mlir::createLowerToLLVMPass(bool useAlloca, bool emitCWrappers) {
- return std::make_unique<LLVMLoweringPass>(useAlloca, emitCWrappers);
+mlir::createLowerToLLVMPass(bool useAlloca, bool useBarePtrCallConv,
+ bool emitCWrappers) {
+ return std::make_unique<LLVMLoweringPass>(useAlloca, useBarePtrCallConv,
+ emitCWrappers);
}
static PassRegistration<LLVMLoweringPass>
- pass(PASS_NAME,
- "Convert scalar and vector operations from the "
- "Standard to the LLVM dialect",
- [] {
- return std::make_unique<LLVMLoweringPass>(
- clUseAlloca.getValue(), clUseBarePtrCallConv.getValue(),
- clEmitCWrappers.getValue());
- });
+ pass(PASS_NAME, "Convert scalar and vector operations from the "
+ "Standard to the LLVM dialect");
diff --git a/mlir/test/Conversion/StandardToLLVM/calling-convention.mlir b/mlir/test/Conversion/StandardToLLVM/calling-convention.mlir
index d9b5b94..348afff 100644
--- a/mlir/test/Conversion/StandardToLLVM/calling-convention.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/calling-convention.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt -convert-std-to-llvm -convert-std-to-llvm-emit-c-wrappers %s | FileCheck %s
+// RUN: mlir-opt -convert-std-to-llvm='emit-c-wrappers=1' %s | FileCheck %s
// This tests the default memref calling convention and the emission of C
// wrappers. We don't need to separate runs because the wrapper-emission
diff --git a/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir b/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
index c25d8a2..cc8cfc3 100644
--- a/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
+++ b/mlir/test/Conversion/StandardToLLVM/convert-static-memref-ops.mlir
@@ -1,6 +1,6 @@
// RUN: mlir-opt -convert-std-to-llvm %s | FileCheck %s
-// RUN: mlir-opt -convert-std-to-llvm -convert-std-to-llvm-use-alloca=1 %s | FileCheck %s --check-prefix=ALLOCA
-// RUN: mlir-opt -convert-std-to-llvm -split-input-file -convert-std-to-llvm-use-bare-ptr-memref-call-conv=1 %s | FileCheck %s --check-prefix=BAREPTR
+// RUN: mlir-opt -convert-std-to-llvm='use-alloca=1' %s | FileCheck %s --check-prefix=ALLOCA
+// RUN: mlir-opt -convert-std-to-llvm='use-bare-ptr-memref-call-conv=1' -split-input-file %s | FileCheck %s --check-prefix=BAREPTR
// BAREPTR-LABEL: func @check_noalias
// BAREPTR-SAME: %{{.*}}: !llvm<"float*"> {llvm.noalias = true}
diff --git a/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir b/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir
index 59fd969..a0022af 100644
--- a/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir
+++ b/mlir/test/mlir-cpu-runner/bare_ptr_call_conv.mlir
@@ -1,4 +1,4 @@
-// RUN: mlir-opt %s -convert-loop-to-std -convert-std-to-llvm -convert-std-to-llvm-use-bare-ptr-memref-call-conv | mlir-cpu-runner -shared-libs=%linalg_test_lib_dir/libmlir_runner_utils%shlibext -entry-point-result=void | FileCheck %s
+// RUN: mlir-opt %s -convert-loop-to-std -convert-std-to-llvm='use-bare-ptr-memref-call-conv=1' | mlir-cpu-runner -shared-libs=%linalg_test_lib_dir/libmlir_runner_utils%shlibext -entry-point-result=void | FileCheck %s
// Verify bare pointer memref calling convention. `simple_add1_add2_test`
// gets two 2xf32 memrefs, adds 1.0f to the first one and 2.0f to the second