diff --git a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h --- a/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h +++ b/mlir/include/mlir/Conversion/StandardToLLVM/ConvertStandardToLLVMPass.h @@ -58,7 +58,8 @@ /// 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> -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 --- a/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp +++ b/mlir/lib/Conversion/StandardToLLVM/ConvertStandardToLLVM.cpp @@ -36,25 +36,6 @@ #define PASS_NAME "convert-std-to-llvm" -static llvm::cl::OptionCategory - clOptionsCategory("Standard to LLVM lowering options"); - -static llvm::cl::opt - clUseAlloca(PASS_NAME "-use-alloca", - llvm::cl::desc("Replace emission of malloc/free by alloca"), - llvm::cl::init(false)); - -static llvm::cl::opt - clEmitCWrappers(PASS_NAME "-emit-c-wrappers", - llvm::cl::desc("Emit C-compatible wrapper functions"), - llvm::cl::init(false)); - -static llvm::cl::opt 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 @@ /// A pass converting MLIR operations into the LLVM IR dialect. struct LLVMLoweringPass : public ModulePass { /// 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 @@ } /// Use `alloca` instead of `call @malloc` for converting std.alloc. - bool useAlloca; + Option 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 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 emitCWrappers{ + *this, "emit-c-wrappers", + llvm::cl::desc("Emit C-compatible wrapper functions"), + llvm::cl::init(false)}; }; } // end namespace std::unique_ptr> -mlir::createLowerToLLVMPass(bool useAlloca, bool emitCWrappers) { - return std::make_unique(useAlloca, emitCWrappers); +mlir::createLowerToLLVMPass(bool useAlloca, bool useBarePtrCallConv, + bool emitCWrappers) { + return std::make_unique(useAlloca, useBarePtrCallConv, + emitCWrappers); } static PassRegistration - pass(PASS_NAME, - "Convert scalar and vector operations from the " - "Standard to the LLVM dialect", - [] { - return std::make_unique( - 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 --- 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 --- 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 --- 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