[llvm] A MMIWP Constructor Initialized with the move constructor of MMI (PR #98770)
Matin Raayai via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 13 13:13:51 PDT 2024
https://github.com/matinraayai created https://github.com/llvm/llvm-project/pull/98770
This PR exposes the move constructor of `MachineModuleInfo` as a way to initialize the `MachineModuleInfoWrapperPasss`.
This is useful for running passes over an externally initialized MMI, and then moving it back to its original storage for further processing/inspection, as shown in the following example:
```c++
llvm::legacy::PassManager PM;
auto MMI = std::make_unique<llvm::MachineModuleInfo>(TM);
... (Modify/inspect MMI)
/// Initialize a MMIWP using the external MMI
auto * MMIWP = new llvm::MachineModuleInfoWrapperPass(std::move(*MMI));
PM.add(MMIWP);
... (Add more passes)
PM.run(M);
/// Move the MMI back to its original place prevent it from being destroyed after PM goes out of scope
MMI = std::make_unique<llvm::MachineModuleInfo>(std::move(MMIWP->getMMI()));
.. (Inspect the MMI)
```
>From 5ed07a26ccf7f208af12d5acf73e64f3c92d4315 Mon Sep 17 00:00:00 2001
From: matinraayai <30674652+matinraayai at users.noreply.github.com>
Date: Sat, 13 Jul 2024 14:33:08 -0400
Subject: [PATCH] Added forwarding the MMI move constructor for MMIWP.
---
llvm/include/llvm/CodeGen/MachineModuleInfo.h | 2 ++
llvm/lib/CodeGen/MachineModuleInfo.cpp | 5 +++++
2 files changed, 7 insertions(+)
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
index 92ea3c902ce95..6c8c94117625c 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
@@ -208,6 +208,8 @@ class MachineModuleInfoWrapperPass : public ImmutablePass {
explicit MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM,
MCContext *ExtContext);
+ explicit MachineModuleInfoWrapperPass(MachineModuleInfo &&MMI);
+
// Initialization and Finalization
bool doInitialization(Module &) override;
bool doFinalization(Module &) override;
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index b950f4fdbcf79..83364fc380fad 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -180,6 +180,11 @@ MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
}
+MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
+ MachineModuleInfo &&MMI): ImmutablePass(ID), MMI(std::move(MMI)) {
+ initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
+}
+
// Handle the Pass registration stuff necessary to use DataLayout's.
INITIALIZE_PASS(MachineModuleInfoWrapperPass, "machinemoduleinfo",
"Machine Module Information", false, false)
More information about the llvm-commits
mailing list