-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Make Ownership of MachineModuleInfo in Its Wrapper Pass External #110443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ges to a minimum.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Was this already implicitly assumed? IIRC there was some layering reason why this is the way it was. There were previous attempts to merge these before, which were abandoned: https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html https://reviews.llvm.org/D38482 |
@arsenm Initially I was going to move the MC file emission functions to I don't intend on merging the two interfaces together; I only think the MC file emission functions |
…ings in the C-API + linked any libraries that depends on MC file emission to CodeGen.
@MatzeB @arsenm in the latest commit I had to fix the issue you ran into in the following links @arsenm mentioned earlier: https://reviews.llvm.org/D38482 I can live with With this patch, if any library requires MC code emission of any kind, it has to explicitly link to libCodeGen, since it has to be able to access the |
68428e3
to
928014d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still trying to wrap my head around LLVMTargetMachine vs TargetMachine, let me do some reading
@@ -1162,6 +1165,7 @@ void EmitAssemblyHelper::RunCodegenPipeline( | |||
// does not work with the codegen pipeline. | |||
// FIXME: make the new PM work with the codegen pipeline. | |||
legacy::PassManager CodeGenPasses; | |||
std::unique_ptr<MachineModuleInfo> MMI; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can this just be MachineModuleInfo MMI;
below?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it to a normal construction with the TM
.
@@ -106,16 +106,18 @@ class MachineModuleInfo { | |||
const Function *LastRequest = nullptr; ///< Used for shortcut/cache. | |||
MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache. | |||
|
|||
MachineModuleInfo &operator=(MachineModuleInfo &&MMII) = delete; | |||
/// Deleted copy constructor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment is not useful, I'd either say why it's deleted or just remove the comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah there's more context in https://reviews.llvm.org/D123964
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that MMI really is a Codegen concept and not a Target concept, so that's why it takes an LLVMTargetMachine instead of TargetMachine. However, the static_cast
s everywhere are extremely unfortunate. And it doesn't make sense to make the return type of Target::createTargetMachine()
LLVMTargetMachine
instead of TargetMachine
. Perhaps alternatively we make the MMI constructor take TargetMachine
and cast it inside the constructor to LLVMTargetMachine
, so we only pay the cost of this weird distinction in one place rather than everywhere? wdyt?
I dug up the commit that introduced Given the issues faced when joining This is a cause of concern for managing the lifetime of This also relates to a question that I had regarding the new PM codegen interface
To get back to your question @aeubanks I don't think we should force any casts in the |
Following discussions in #110443, and the following earlier discussions in https://lists.llvm.org/pipermail/llvm-dev/2017-October/117907.html, https://reviews.llvm.org/D38482, https://reviews.llvm.org/D38489, this PR attempts to overhaul the `TargetMachine` and `LLVMTargetMachine` interface classes. More specifically: 1. Makes `TargetMachine` the only class implemented under `TargetMachine.h` in the `Target` library. 2. `TargetMachine` contains target-specific interface functions that relate to IR/CodeGen/MC constructs, whereas before (at least on paper) it was supposed to have only IR/MC constructs. Any Target that doesn't want to use the independent code generator simply does not implement them, and returns either `false` or `nullptr`. 3. Renames `LLVMTargetMachine` to `CodeGenCommonTMImpl`. This renaming aims to make the purpose of `LLVMTargetMachine` clearer. Its interface was moved under the CodeGen library, to further emphasis its usage in Targets that use CodeGen directly. 4. Makes `TargetMachine` the only interface used across LLVM and its projects. With these changes, `CodeGenCommonTMImpl` is simply a set of shared function implementations of `TargetMachine`, and CodeGen users don't need to static cast to `LLVMTargetMachine` every time they need a CodeGen-specific feature of the `TargetMachine`. 5. More importantly, does not change any requirements regarding library linking. cc @arsenm @aeubanks
Following up on discussions in #105541, this PR is the first part of #105541, which removes ownership of the
llvm::MachineModuleInfoWrapperPass
over its encapsulatedllvm::MachineModuleInfo
, allowing better control over the MMI's lifetime.After this PR is merged, I plan to:
TargetMachine
toLLVMTargetMachine
. With the changes in this PR, we explicitly assume in bothaddPassesToEmitFile
andaddPassesToEmitMC
that theTargetMachine
is anLLVMTargetMachine
; Hence it does not make sense for these functions to be present in theTargetMachine
interface.cc @aeubanks @arsenm