NFC: Make DialectConversion not directly inherit from ModulePass. It is now just...
authorRiver Riddle <riverriddle@google.com>
Fri, 22 Feb 2019 16:10:29 +0000 (08:10 -0800)
committerjpienaar <jpienaar@google.com>
Fri, 29 Mar 2019 23:38:57 +0000 (16:38 -0700)
PiperOrigin-RevId: 235194067

mlir/include/mlir/Transforms/DialectConversion.h
mlir/lib/LLVMIR/Transforms/ConvertToLLVMDialect.cpp
mlir/lib/Transforms/DialectConversion.cpp

index b1e87e7223e840187459468fc9f9e36db08c67d9..d0ffb3485d770cd2910985b85b02b4d9ddef6bd6 100644 (file)
@@ -122,12 +122,12 @@ template <typename Arg> struct ConversionListBuilder<Arg> {
   }
 };
 
-/// Base class for dialect conversion passes.  Specific passes must derive this
-/// class and implement the pure virtual functions.
+/// Base class for dialect conversion interface.  Specific converters must
+/// derive this class and implement the pure virtual functions.
 ///
-/// The module pass proceeds as follows.
+/// The module conversion proceeds as follows.
 /// 1. Call `initConverters` to obtain a set of conversions to apply, given the
-/// current MLIR context.
+///    current MLIR context.
 /// 2. For each function in the module do the following.
 //    a. Create a new function with the same name and convert its signature
 //    using `convertType`.
@@ -145,16 +145,17 @@ template <typename Arg> struct ConversionListBuilder<Arg> {
 /// If any error happend during the conversion, the pass fails as soon as
 /// possible.
 ///
-/// If the pass fails, the module is not modified.
-class DialectConversion : public ModulePass {
+/// If the conversion fails, the module is not modified.
+class DialectConversion {
   friend class impl::FunctionConversion;
 
 public:
-  /// Construct a pass given its unique identifier.
-  DialectConversion(const PassID *passID) : ModulePass(passID) {}
+  virtual ~DialectConversion() = default;
 
-  /// Run the pass on the module.
-  PassResult runOnModule(Module *m) override;
+  /// Run the converter on the provided module. This function returns
+  /// true if the module was unsuccessfully converted. Otherwise, it returns
+  /// false for success.
+  bool convert(Module *m);
 
 protected:
   /// Derived classes must implement this hook to produce a set of conversion
index ba3619e38b6f251f507accd835688102f83fb7c0..bcbbaff300b01b6652e31325029ee85b56f26f05 100644 (file)
@@ -1026,12 +1026,16 @@ struct CondBranchOpLowering
 
 /// A pass converting MLIR Standard and Builtin operations into the LLVM IR
 /// dialect.
-class LLVMLowering : public DialectConversion {
+class LLVMLowering : public ModulePass, public DialectConversion {
 public:
-  LLVMLowering() : DialectConversion(&passID) {}
+  LLVMLowering() : ModulePass(&passID) {}
 
   constexpr static PassID passID = {};
 
+  PassResult runOnModule(Module *m) override {
+    return DialectConversion::convert(m) ? failure() : success();
+  }
+
 protected:
   // Create a set of converters that live in the pass object by passing them a
   // reference to the LLVM IR dialect.  Store the module associated with the
index 60e7b11cf389265d406953e6b123ea4a1fa3d5ae..b4581ed061612e80b866aa67fd4a0ba89e054e8a 100644 (file)
@@ -323,6 +323,6 @@ DialectConversion::convertFunctionSignatureType(FunctionType type) {
   return FunctionType::get(arguments, results, type.getContext());
 }
 
-PassResult DialectConversion::runOnModule(Module *m) {
-  return impl::FunctionConversion::convert(this, m) ? failure() : success();
+bool DialectConversion::convert(Module *m) {
+  return impl::FunctionConversion::convert(this, m);
 }