[Mlir-commits] [mlir] 5dc34eb - Reland "[mlir][func] Use the generated pass options in func to llvm."

Tobias Gysi llvmlistbot at llvm.org
Sat Feb 11 03:32:44 PST 2023


Author: Tobias Gysi
Date: 2023-02-11T12:29:10+01:00
New Revision: 5dc34eb379f40614d5c2381d46e5c8d6d6af63fd

URL: https://github.com/llvm/llvm-project/commit/5dc34eb379f40614d5c2381d46e5c8d6d6af63fd
DIFF: https://github.com/llvm/llvm-project/commit/5dc34eb379f40614d5c2381d46e5c8d6d6af63fd.diff

LOG: Reland "[mlir][func] Use the generated pass options in func to llvm."

Update the FuncToLLVM pass to use the generated constructors and
the generated pass option struct. The hand written constructor
got out of sync after some refactorings. Using a generated constructor
and options struct ensures the everything remains in sync.

Reviewed By: zero9178

This reverts commit 39da46826da82c24ca4407c13ad7feb8e5dc32a1
and relands commit 771d9c05afc2515b474fb53db857716dfdfc1dcf

which was originally reverted due to
https://lab.llvm.org/buildbot#builders/61/builds/39694

Differential Revision: https://reviews.llvm.org/D143733

Added: 
    

Modified: 
    mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h
    mlir/include/mlir/Conversion/Passes.td
    mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
    mlir/test/CAPI/execution_engine.c
    mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp

Removed: 
    


################################################################################
diff  --git a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h
index 701c6acac62fe..f6be8a0fcb2b1 100644
--- a/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h
+++ b/mlir/include/mlir/Conversion/FuncToLLVM/ConvertFuncToLLVMPass.h
@@ -13,20 +13,11 @@
 #include <string>
 
 namespace mlir {
-class LowerToLLVMOptions;
-class ModuleOp;
-template <typename T>
-class OperationPass;
 class Pass;
 
-#define GEN_PASS_DECL_CONVERTFUNCTOLLVM
+#define GEN_PASS_DECL_CONVERTFUNCTOLLVMPASS
 #include "mlir/Conversion/Passes.h.inc"
 
-/// Creates a pass to convert the Func dialect into the LLVMIR dialect.
-std::unique_ptr<OperationPass<ModuleOp>> createConvertFuncToLLVMPass();
-std::unique_ptr<OperationPass<ModuleOp>>
-createConvertFuncToLLVMPass(const LowerToLLVMOptions &options);
-
 } // namespace mlir
 
 #endif // MLIR_CONVERSION_FUNCTOLLVM_CONVERTFUNCTOLLVMPASS_H_

diff  --git a/mlir/include/mlir/Conversion/Passes.td b/mlir/include/mlir/Conversion/Passes.td
index 60c28bed55910..dacad1adcd730 100644
--- a/mlir/include/mlir/Conversion/Passes.td
+++ b/mlir/include/mlir/Conversion/Passes.td
@@ -276,7 +276,7 @@ def ConvertControlFlowToSPIRV : Pass<"convert-cf-to-spirv"> {
 // FuncToLLVM
 //===----------------------------------------------------------------------===//
 
-def ConvertFuncToLLVM : Pass<"convert-func-to-llvm", "ModuleOp"> {
+def ConvertFuncToLLVMPass : Pass<"convert-func-to-llvm", "ModuleOp"> {
   let summary = "Convert from the Func dialect to the LLVM dialect";
   let description = [{
     Convert Func dialect operations into the LLVM IR dialect operations.
@@ -300,7 +300,6 @@ def ConvertFuncToLLVM : Pass<"convert-func-to-llvm", "ModuleOp"> {
     returns are updated accordingly. Block argument types are updated to use
     LLVM IR types.
   }];
-  let constructor = "mlir::createConvertFuncToLLVMPass()";
   let dependentDialects = ["LLVM::LLVMDialect"];
   let options = [
     Option<"useBarePtrCallConv", "use-bare-ptr-memref-call-conv", "bool",

diff  --git a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
index 724b690f1008b..80f0bbbfb46ae 100644
--- a/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
+++ b/mlir/lib/Conversion/FuncToLLVM/FuncToLLVM.cpp
@@ -48,7 +48,7 @@
 #include <functional>
 
 namespace mlir {
-#define GEN_PASS_DEF_CONVERTFUNCTOLLVM
+#define GEN_PASS_DEF_CONVERTFUNCTOLLVMPASS
 #include "mlir/Conversion/Passes.h.inc"
 } // namespace mlir
 
@@ -711,15 +711,8 @@ void mlir::populateFuncToLLVMConversionPatterns(LLVMTypeConverter &converter,
 namespace {
 /// A pass converting Func operations into the LLVM IR dialect.
 struct ConvertFuncToLLVMPass
-    : public impl::ConvertFuncToLLVMBase<ConvertFuncToLLVMPass> {
-  ConvertFuncToLLVMPass() = default;
-  ConvertFuncToLLVMPass(bool useBarePtrCallConv, unsigned indexBitwidth,
-                        bool useAlignedAlloc,
-                        const llvm::DataLayout &dataLayout) {
-    this->useBarePtrCallConv = useBarePtrCallConv;
-    this->indexBitwidth = indexBitwidth;
-    this->dataLayout = dataLayout.getStringRepresentation();
-  }
+    : public impl::ConvertFuncToLLVMPassBase<ConvertFuncToLLVMPass> {
+  using Base::Base;
 
   /// Run the dialect converter on the module.
   void runOnOperation() override {
@@ -761,21 +754,3 @@ struct ConvertFuncToLLVMPass
   }
 };
 } // namespace
-
-std::unique_ptr<OperationPass<ModuleOp>> mlir::createConvertFuncToLLVMPass() {
-  return std::make_unique<ConvertFuncToLLVMPass>();
-}
-
-std::unique_ptr<OperationPass<ModuleOp>>
-mlir::createConvertFuncToLLVMPass(const LowerToLLVMOptions &options) {
-  auto allocLowering = options.allocLowering;
-  // There is no way to provide additional patterns for pass, so
-  // AllocLowering::None will always fail.
-  assert(allocLowering != LowerToLLVMOptions::AllocLowering::None &&
-         "ConvertFuncToLLVMPass doesn't support AllocLowering::None");
-  bool useAlignedAlloc =
-      (allocLowering == LowerToLLVMOptions::AllocLowering::AlignedAlloc);
-  return std::make_unique<ConvertFuncToLLVMPass>(
-      options.useBarePtrCallConv, options.getIndexBitwidth(), useAlignedAlloc,
-      options.dataLayout);
-}

diff  --git a/mlir/test/CAPI/execution_engine.c b/mlir/test/CAPI/execution_engine.c
index 96ad8eb1a4029..582b2f8fe2223 100644
--- a/mlir/test/CAPI/execution_engine.c
+++ b/mlir/test/CAPI/execution_engine.c
@@ -34,7 +34,7 @@ void lowerModuleToLLVM(MlirContext ctx, MlirModule module) {
   MlirPassManager pm = mlirPassManagerCreate(ctx);
   MlirOpPassManager opm = mlirPassManagerGetNestedUnder(
       pm, mlirStringRefCreateFromCString("func.func"));
-  mlirPassManagerAddOwnedPass(pm, mlirCreateConversionConvertFuncToLLVM());
+  mlirPassManagerAddOwnedPass(pm, mlirCreateConversionConvertFuncToLLVMPass());
   mlirOpPassManagerAddOwnedPass(
       opm, mlirCreateConversionArithToLLVMConversionPass());
   MlirLogicalResult status = mlirPassManagerRun(pm, module);

diff  --git a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
index ca3248a5992dd..caec6439ec747 100644
--- a/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
+++ b/mlir/tools/mlir-vulkan-runner/mlir-vulkan-runner.cpp
@@ -69,11 +69,13 @@ static LogicalResult runMLIRPasses(Operation *op,
     modulePM.addPass(spirv::createSPIRVWebGPUPreparePass());
 
   passManager.addPass(createConvertGpuLaunchFuncToVulkanLaunchFuncPass());
-  LowerToLLVMOptions llvmOptions(module.getContext(), DataLayout(module));
   passManager.addPass(createFinalizeMemRefToLLVMConversionPass());
   passManager.addPass(createConvertVectorToLLVMPass());
   passManager.nest<func::FuncOp>().addPass(LLVM::createRequestCWrappersPass());
-  passManager.addPass(createConvertFuncToLLVMPass(llvmOptions));
+  ConvertFuncToLLVMPassOptions funcToLLVMOptions{};
+  funcToLLVMOptions.indexBitwidth =
+      DataLayout(module).getTypeSizeInBits(IndexType::get(module.getContext()));
+  passManager.addPass(createConvertFuncToLLVMPass(funcToLLVMOptions));
   passManager.addPass(createReconcileUnrealizedCastsPass());
   passManager.addPass(createConvertVulkanLaunchFuncToVulkanCallsPass());
 


        


More information about the Mlir-commits mailing list