Add a getContext() utility to the Module/FunctionPass class (NFC)
authorMehdi Amini <aminim@google.com>
Tue, 26 Mar 2019 19:49:08 +0000 (12:49 -0700)
committerjpienaar <jpienaar@google.com>
Sat, 30 Mar 2019 00:42:35 +0000 (17:42 -0700)
This is just a convenience for reducing boilerplate when writing a pass.

PiperOrigin-RevId: 240407564

mlir/include/mlir/Pass/Pass.h

index 53629e0..6874dd9 100644 (file)
@@ -108,6 +108,9 @@ protected:
     return *getPassState().irAndPassFailed.getPointer();
   }
 
+  /// Return the MLIR context for the current function being transformed.
+  MLIRContext &getContext() { return *getFunction().getContext(); }
+
   /// Returns the current pass state.
   PassStateT &getPassState() {
     assert(passState && "pass state was never initialized");
@@ -150,6 +153,9 @@ protected:
   /// Return the current module being transformed.
   Module &getModule() { return *getPassState().irAndPassFailed.getPointer(); }
 
+  /// Return the MLIR context for the current module being transformed.
+  MLIRContext &getContext() { return *getModule().getContext(); }
+
   /// Returns the current pass state.
   PassStateT &getPassState() {
     assert(passState && "pass state was never initialized");