[PATCH] D139840: [mlir][NFC] Make test-lower-to-llvm a named pipeline

Quentin Colombet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 12 06:44:20 PST 2022


qcolombet created this revision.
qcolombet added reviewers: nicolasvasilache, ftynse, springerm.
qcolombet added a project: MLIR.
Herald added subscribers: Moerafaat, zero9178, bzcheeseman, awarzynski, sdasgup3, wenzhicui, wrengr, cota, teijeong, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, rriddle, mehdi_amini.
Herald added a project: All.
qcolombet requested review of this revision.
Herald added a subscriber: stephenneuendorffer.
Herald added a reviewer: dcaballe.

This patch changes the `test-lower-to-llvm` pass into a named pipeline.
The functionality is unchanged but thanks to this change, we don't have to pull the dependencies of all the passes that this pass calls.
In other words, `TestLowerToLLVMPass::getDependDialects` was supposed to transitively declare all the dialects that were used in the union of all the invoked passes.

NFC


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139840

Files:
  mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp


Index: mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
===================================================================
--- mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
+++ mlir/test/lib/Dialect/LLVM/TestLowerToLLVM.cpp
@@ -27,43 +27,26 @@
 #include "mlir/IR/DialectRegistry.h"
 #include "mlir/Pass/Pass.h"
 #include "mlir/Pass/PassManager.h"
+#include "mlir/Pass/PassOptions.h"
 #include "mlir/Transforms/Passes.h"
 
 using namespace mlir;
 
 namespace {
-struct TestLowerToLLVM
-    : public PassWrapper<TestLowerToLLVM, OperationPass<ModuleOp>> {
-  MLIR_DEFINE_EXPLICIT_INTERNAL_INLINE_TYPE_ID(TestLowerToLLVM)
-
-  TestLowerToLLVM() = default;
-  TestLowerToLLVM(const TestLowerToLLVM &pass) : PassWrapper(pass) {}
-
-  StringRef getArgument() const final { return "test-lower-to-llvm"; }
-  StringRef getDescription() const final {
-    return "Test lowering to LLVM as a generally usable sink pass";
-  }
-  void getDependentDialects(DialectRegistry &registry) const override {
-    registry.insert<LLVM::LLVMDialect>();
-  }
-
-  Option<bool> reassociateFPReductions{
+struct TestLowerToLLVMOptions
+    : public PassPipelineOptions<TestLowerToLLVMOptions> {
+  PassOptions::Option<bool> reassociateFPReductions{
       *this, "reassociate-fp-reductions",
       llvm::cl::desc("Allow reassociation og FP reductions"),
       llvm::cl::init(false)};
-
-  void runOnOperation() final;
 };
-} // namespace
 
-void TestLowerToLLVM::runOnOperation() {
-  MLIRContext *context = &this->getContext();
-  RewritePatternSet patterns(context);
+void buildTestLowerToLLVM(OpPassManager &pm,
+                          const TestLowerToLLVMOptions &options) {
 
   // TODO: it is feasible to scope lowering at arbitrary level and introduce
   // unrealized casts, but there needs to be the final module-wise cleanup in
   // the end. Keep module-level for now.
-  PassManager pm(&getContext());
 
   // Blanket-convert any remaining high-level vector ops to loops if any remain.
   pm.addNestedPass<func::FuncOp>(createConvertVectorToSCFPass());
@@ -82,7 +65,7 @@
   pm.addPass(createConvertVectorToLLVMPass(
       // TODO: add more options on a per-need basis.
       LowerVectorToLLVMOptions().enableReassociateFPReductions(
-          reassociateFPReductions)));
+          options.reassociateFPReductions)));
   // Convert Math to LLVM (always needed).
   pm.addNestedPass<func::FuncOp>(createConvertMathToLLVMPass());
   // Convert MemRef to LLVM (always needed).
@@ -93,14 +76,17 @@
   pm.addPass(createConvertIndexToLLVMPass());
   // Convert remaining unrealized_casts (always needed).
   pm.addPass(createReconcileUnrealizedCastsPass());
-  if (failed(pm.run(getOperation()))) {
-    getOperation()->dump();
-    return signalPassFailure();
-  }
 }
+} // namespace
 
 namespace mlir {
 namespace test {
-void registerTestLowerToLLVM() { PassRegistration<TestLowerToLLVM>(); }
+void registerTestLowerToLLVM() {
+  PassPipelineRegistration<TestLowerToLLVMOptions>(
+      "test-lower-to-llvm",
+      "An example of pipeline to lower the main dialects (arith, linalg, "
+      "memref, scf, vector) down to LLVM.",
+      buildTestLowerToLLVM);
+}
 } // namespace test
 } // namespace mlir


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139840.482104.patch
Type: text/x-patch
Size: 3199 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20221212/5e4ef182/attachment.bin>


More information about the llvm-commits mailing list