Add a getContext() utility to the Module/FunctionPass class (NFC)
This is just a convenience for reducing boilerplate when writing a pass.
PiperOrigin-RevId: 240407564
diff --git a/include/mlir/Pass/Pass.h b/include/mlir/Pass/Pass.h
index 53629e0..6874dd9 100644
--- a/include/mlir/Pass/Pass.h
+++ b/include/mlir/Pass/Pass.h
@@ -108,6 +108,9 @@
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 @@
/// 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");