[clang] [llvm] Make MMIWP not have ownership over MMI + Remove Move Constructor of MMI + Make MMI Only Use and Externally-Created MCContext (PR #105541)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 21 08:55:37 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lto
@llvm/pr-subscribers-tools-llvm-exegesis
Author: Matin Raayai (matinraayai)
<details>
<summary>Changes</summary>
This PR makes the following changes, addressing issues raised in #<!-- -->104834 and #<!-- -->98770:
1. MMIWP behaves like the new PM's analysis Pass; It only takes a reference to an externally created MMI.
2. Removed the move constructor; Disallowed copy construction and copy assignment.
3. MMI does not create its own MCContext, and take a reference to an externally-created context.
As expected, this change touched upon a lot of places in the LLVM monorepo; But I wanted to point out some breaking ones:
1. The `TargetMachine` interface functions `addPassesToEmitFile` and `addPassesToEmitMC` now require a reference to an MMI; This IMO breaks the abstraction of the `TargetMachine`, since an `MMI` requires a `LLVMTargetMachine`, and if you have a `TargetMachine` you should do the dreaded casting to `LLVMTargetMachine` in order to create it. Now I created a factory method for MMIs in the `TargetMachine` interface to remedy this issue, but I still don't like it since again, it is only implemented for `LLVMTargetMachine`.
2. Enforcing an externally created context for every user of MMI requires explicit reseting of the MCContext if it is reused; This can be seen in llc and MCJIt, and I think must be documented explicitly.
4. Some places in the code only created an MMI just to get an MCContext; I've replaced them with a manually constructed MCContext but I think it can be simplified to having a factory method for MCContext in the `TargetMachine` interface.
For now this PR is a WIP; The first two changes are necessary, and will have to be done sometime in the future as a part of the migration effort to the new PM; The 3rd change (only taking external MCContext) makes MMI's code cleaner, but might break code in other places where it relies on the MMIWP implicitly reseting its managed context. It might be possible to break this PR down to two parts instead if it proves to be challenging to merge.
CC: @<!-- -->arsenm @<!-- -->weiweichen
---
Patch is 72.96 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/105541.diff
45 Files Affected:
- (modified) clang/lib/CodeGen/BackendUtil.cpp (+13-3)
- (modified) clang/lib/Interpreter/DeviceOffload.cpp (+9-2)
- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (+7-1)
- (modified) llvm/include/llvm/CodeGen/MachineModuleInfo.h (+12-16)
- (modified) llvm/include/llvm/Target/TargetMachine.h (+29-28)
- (modified) llvm/lib/CodeGen/LLVMTargetMachine.cpp (+15-12)
- (modified) llvm/lib/CodeGen/MachineModuleInfo.cpp (+6-39)
- (modified) llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp (+11-4)
- (modified) llvm/lib/ExecutionEngine/MCJIT/MCJIT.h (+2-1)
- (modified) llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp (+6-2)
- (modified) llvm/lib/LTO/LTOBackend.cpp (+9-1)
- (modified) llvm/lib/LTO/ThinLTOCodeGenerator.cpp (+7-1)
- (modified) llvm/lib/Target/NVPTX/NVPTXTargetMachine.h (+2-2)
- (modified) llvm/lib/Target/TargetMachineC.cpp (+9-1)
- (modified) llvm/tools/llc/NewPMDriver.cpp (+5-1)
- (modified) llvm/tools/llc/llc.cpp (+8-3)
- (modified) llvm/tools/llvm-exegesis/lib/Assembler.cpp (+11-3)
- (modified) llvm/tools/llvm-isel-fuzzer/llvm-isel-fuzzer.cpp (+7-1)
- (modified) llvm/tools/llvm-reduce/ReducerWorkItem.cpp (+11-3)
- (modified) llvm/tools/llvm-reduce/ReducerWorkItem.h (+4-1)
- (modified) llvm/tools/llvm-reduce/TestRunner.cpp (+4-2)
- (modified) llvm/tools/llvm-reduce/TestRunner.h (+5-1)
- (modified) llvm/tools/llvm-reduce/deltas/Delta.cpp (+6-5)
- (modified) llvm/tools/llvm-reduce/llvm-reduce.cpp (+6-4)
- (modified) llvm/unittests/CodeGen/AArch64SelectionDAGTest.cpp (+6-2)
- (modified) llvm/unittests/CodeGen/AMDGPUMetadataTest.cpp (+6-1)
- (modified) llvm/unittests/CodeGen/AsmPrinterDwarfTest.cpp (+10-2)
- (modified) llvm/unittests/CodeGen/GlobalISel/GISelMITest.h (+10-4)
- (modified) llvm/unittests/CodeGen/InstrRefLDVTest.cpp (+7-1)
- (modified) llvm/unittests/CodeGen/MFCommon.inc (+4-2)
- (modified) llvm/unittests/CodeGen/MachineDomTreeUpdaterTest.cpp (+7-1)
- (modified) llvm/unittests/CodeGen/PassManagerTest.cpp (+10-2)
- (modified) llvm/unittests/CodeGen/SelectionDAGAddressAnalysisTest.cpp (+6-1)
- (modified) llvm/unittests/CodeGen/SelectionDAGPatternMatchTest.cpp (+7-2)
- (modified) llvm/unittests/MI/LiveIntervalTest.cpp (+16-11)
- (modified) llvm/unittests/MIR/MachineMetadata.cpp (+24-7)
- (modified) llvm/unittests/Target/AArch64/InstSizes.cpp (+4-1)
- (modified) llvm/unittests/Target/AMDGPU/ExecMayBeModifiedBeforeAnyUse.cpp (+4-2)
- (modified) llvm/unittests/Target/AMDGPU/PALMetadata.cpp (+6-2)
- (modified) llvm/unittests/Target/ARM/InstSizes.cpp (+4-1)
- (modified) llvm/unittests/Target/LoongArch/InstSizes.cpp (+5-1)
- (modified) llvm/unittests/Target/RISCV/RISCVInstrInfoTest.cpp (+5-1)
- (modified) llvm/unittests/Target/WebAssembly/WebAssemblyExceptionInfoTest.cpp (+8-2)
- (modified) llvm/unittests/Target/X86/MachineSizeOptsTest.cpp (+5-1)
- (modified) llvm/unittests/tools/llvm-exegesis/X86/SnippetRepetitorTest.cpp (+5-1)
``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 34c08818dbb9ad..7e5ebe34dc98ba 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -26,6 +26,7 @@
#include "llvm/Bitcode/BitcodeReader.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/Bitcode/BitcodeWriterPass.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/CodeGen/RegAllocRegistry.h"
#include "llvm/CodeGen/SchedulerRegistry.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h"
@@ -167,7 +168,8 @@ class EmitAssemblyHelper {
///
/// \return True on success.
bool AddEmitPasses(legacy::PassManager &CodeGenPasses, BackendAction Action,
- raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
+ MachineModuleInfo &MMI, raw_pwrite_stream &OS,
+ raw_pwrite_stream *DwoOS);
std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
std::error_code EC;
@@ -577,6 +579,7 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
+ MachineModuleInfo &MMI,
raw_pwrite_stream &OS,
raw_pwrite_stream *DwoOS) {
// Add LibraryInfo.
@@ -588,7 +591,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
// this also adds codegenerator level optimization passes.
CodeGenFileType CGFT = getCodeGenFileType(Action);
- if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
+ if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT, MMI,
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
Diags.Report(diag::err_fe_unable_to_interface_with_target);
return false;
@@ -1116,6 +1119,8 @@ 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<llvm::MCContext> MCCtx;
+ std::unique_ptr<llvm::MachineModuleInfo> MMI;
// Append any output we need to the pass manager.
switch (Action) {
@@ -1129,7 +1134,12 @@ void EmitAssemblyHelper::RunCodegenPipeline(
if (!DwoOS)
return;
}
- if (!AddEmitPasses(CodeGenPasses, Action, *OS,
+ MCCtx = std::make_unique<MCContext>(
+ TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
+ TM->getMCSubtargetInfo(), nullptr, &TM->Options.MCOptions, false);
+
+ MMI = TM->createMachineModuleInfo(*MCCtx);
+ if (!AddEmitPasses(CodeGenPasses, Action, *MMI, *OS,
DwoOS ? &DwoOS->os() : nullptr))
// FIXME: Should we handle this error differently?
return;
diff --git a/clang/lib/Interpreter/DeviceOffload.cpp b/clang/lib/Interpreter/DeviceOffload.cpp
index 07c9e3005e5fd3..29a94c372c4df8 100644
--- a/clang/lib/Interpreter/DeviceOffload.cpp
+++ b/clang/lib/Interpreter/DeviceOffload.cpp
@@ -16,8 +16,10 @@
#include "clang/CodeGen/ModuleBuilder.h"
#include "clang/Frontend/CompilerInstance.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/IR/LegacyPassManager.h"
#include "llvm/IR/Module.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Target/TargetMachine.h"
@@ -88,8 +90,13 @@ llvm::Expected<llvm::StringRef> IncrementalCUDADeviceParser::GeneratePTX() {
llvm::raw_svector_ostream dest(PTXCode);
llvm::legacy::PassManager PM;
- if (TargetMachine->addPassesToEmitFile(PM, dest, nullptr,
- llvm::CodeGenFileType::AssemblyFile)) {
+ llvm::MCContext MCCtx(
+ TargetMachine->getTargetTriple(), TargetMachine->getMCAsmInfo(),
+ TargetMachine->getMCRegisterInfo(), TargetMachine->getMCSubtargetInfo(),
+ nullptr, &TargetMachine->Options.MCOptions, false);
+ auto MMI = TargetMachine->createMachineModuleInfo(MCCtx);
+ if (TargetMachine->addPassesToEmitFile(
+ PM, dest, nullptr, llvm::CodeGenFileType::AssemblyFile, *MMI)) {
return llvm::make_error<llvm::StringError>(
"NVPTX backend cannot produce PTX code.",
llvm::inconvertibleErrorCode());
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9fea1fdcd5fb46..797f7b44560400 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -20,6 +20,7 @@
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/CodeGen/CommandFlags.h"
+#include "llvm/CodeGen/MachineModuleInfo.h"
#include "llvm/Frontend/Offloading/OffloadWrapper.h"
#include "llvm/Frontend/Offloading/Utility.h"
#include "llvm/IR/Constants.h"
@@ -27,6 +28,7 @@
#include "llvm/IR/Module.h"
#include "llvm/IRReader/IRReader.h"
#include "llvm/LTO/LTO.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/TargetRegistry.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/ArchiveWriter.h"
@@ -1051,10 +1053,14 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
auto OS = std::make_unique<llvm::raw_fd_ostream>(FD, true);
legacy::PassManager CodeGenPasses;
+ MCContext MCCtx(
+ TM->getTargetTriple(), TM->getMCAsmInfo(), TM->getMCRegisterInfo(),
+ TM->getMCSubtargetInfo(), nullptr, &TM->Options.MCOptions, false);
+ auto MMI = TM->createMachineModuleInfo(MCCtx);
TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple()));
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
if (TM->addPassesToEmitFile(CodeGenPasses, *OS, nullptr,
- CodeGenFileType::ObjectFile))
+ CodeGenFileType::ObjectFile, *MMI))
return createStringError("Failed to execute host backend");
CodeGenPasses.run(M);
diff --git a/llvm/include/llvm/CodeGen/MachineModuleInfo.h b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
index 310cc4b2abb772..3fb0979ec20990 100644
--- a/llvm/include/llvm/CodeGen/MachineModuleInfo.h
+++ b/llvm/include/llvm/CodeGen/MachineModuleInfo.h
@@ -83,13 +83,11 @@ class MachineModuleInfo {
friend class MachineModuleInfoWrapperPass;
friend class MachineModuleAnalysis;
+ /// This is the TargetMachine used for the entire code generator.
const LLVMTargetMachine &TM;
/// This is the MCContext used for the entire code generator.
- MCContext Context;
- // This is an external context, that if assigned, will be used instead of the
- // internal context.
- MCContext *ExternalContext = nullptr;
+ MCContext &Context;
/// This is the LLVM Module being worked on.
const Module *TheModule = nullptr;
@@ -106,15 +104,15 @@ class MachineModuleInfo {
const Function *LastRequest = nullptr; ///< Used for shortcut/cache.
MachineFunction *LastResult = nullptr; ///< Used for shortcut/cache.
- MachineModuleInfo &operator=(MachineModuleInfo &&MMII) = delete;
-
public:
- explicit MachineModuleInfo(const LLVMTargetMachine *TM = nullptr);
+ explicit MachineModuleInfo(const LLVMTargetMachine &TM,
+ MCContext &Context);
- explicit MachineModuleInfo(const LLVMTargetMachine *TM,
- MCContext *ExtContext);
+ /// Deleted copy constructor
+ MachineModuleInfo(MachineModuleInfo &MMI) = delete;
- MachineModuleInfo(MachineModuleInfo &&MMII);
+ /// Deleted copy assignment operator
+ MachineModuleInfo &operator=(MachineModuleInfo &MMII) = delete;
~MachineModuleInfo();
@@ -124,10 +122,10 @@ class MachineModuleInfo {
const LLVMTargetMachine &getTarget() const { return TM; }
const MCContext &getContext() const {
- return ExternalContext ? *ExternalContext : Context;
+ return Context;
}
MCContext &getContext() {
- return ExternalContext ? *ExternalContext : Context;
+ return Context;
}
const Module *getModule() const { return TheModule; }
@@ -169,14 +167,12 @@ class MachineModuleInfo {
}; // End class MachineModuleInfo
class MachineModuleInfoWrapperPass : public ImmutablePass {
- MachineModuleInfo MMI;
+ MachineModuleInfo &MMI;
public:
static char ID; // Pass identification, replacement for typeid
- explicit MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM = nullptr);
- explicit MachineModuleInfoWrapperPass(const LLVMTargetMachine *TM,
- MCContext *ExtContext);
+ explicit MachineModuleInfoWrapperPass(MachineModuleInfo &MMI);
// Initialization and Finalization
bool doInitialization(Module &) override;
diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h
index c3e9d41315f617..2574fb80a5702d 100644
--- a/llvm/include/llvm/Target/TargetMachine.h
+++ b/llvm/include/llvm/Target/TargetMachine.h
@@ -34,7 +34,7 @@ using ModulePassManager = PassManager<Module>;
class Function;
class GlobalValue;
-class MachineModuleInfoWrapperPass;
+class MachineModuleInfo;
class Mangler;
class MCAsmInfo;
class MCContext;
@@ -375,27 +375,27 @@ class TargetMachine {
/// with the new pass manager. Only affects the "default" AAManager.
virtual void registerDefaultAliasAnalyses(AAManager &) {}
+ /// Creates a new instance of \c MachineModuleInfo to be used for code
+ /// generation for this \c TargetMachine
+ virtual std::unique_ptr<MachineModuleInfo>
+ createMachineModuleInfo(MCContext &Ctx) const = 0;
+
/// Add passes to the specified pass manager to get the specified file
- /// emitted. Typically this will involve several steps of code generation.
+ /// emitted. Typically this will involve several steps of code generation.
/// This method should return true if emission of this file type is not
/// supported, or false on success.
- /// \p MMIWP is an optional parameter that, if set to non-nullptr,
- /// will be used to set the MachineModuloInfo for this PM.
- virtual bool
- addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &,
- raw_pwrite_stream *, CodeGenFileType,
- bool /*DisableVerify*/ = true,
- MachineModuleInfoWrapperPass *MMIWP = nullptr) {
+ /// \p MMI must be created externally before being passed to this function
+ virtual bool addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &,
+ raw_pwrite_stream *, CodeGenFileType,
+ MachineModuleInfo &MMI,
+ bool /*DisableVerify*/ = true) {
return true;
}
/// Add passes to the specified pass manager to get machine code emitted with
- /// the MCJIT. This method returns true if machine code is not supported. It
- /// fills the MCContext Ctx pointer which can be used to build custom
- /// MCStreamer.
- ///
- virtual bool addPassesToEmitMC(PassManagerBase &, MCContext *&,
- raw_pwrite_stream &,
+ /// the MCJIT. This method returns true if machine code is not supported.
+ virtual bool addPassesToEmitMC(PassManagerBase &, raw_pwrite_stream &,
+ MachineModuleInfo &,
bool /*DisableVerify*/ = true) {
return true;
}
@@ -459,15 +459,18 @@ class LLVMTargetMachine : public TargetMachine {
/// for generating a pipeline of CodeGen passes.
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
+ /// Creates a new instance of \c MachineModuleInfo to be used for code
+ /// generation for this \c TargetMachine
+ virtual std::unique_ptr<MachineModuleInfo>
+ createMachineModuleInfo(MCContext &Ctx) const override;
+
/// Add passes to the specified pass manager to get the specified file
- /// emitted. Typically this will involve several steps of code generation.
- /// \p MMIWP is an optional parameter that, if set to non-nullptr,
- /// will be used to set the MachineModuloInfo for this PM.
- bool
- addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
- raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
- bool DisableVerify = true,
- MachineModuleInfoWrapperPass *MMIWP = nullptr) override;
+ /// emitted. Typically this will involve several steps of code generation.
+ /// \p MMI must be created externally before being passed to this function
+ bool addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
+ raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
+ MachineModuleInfo &MMI,
+ bool DisableVerify = true) override;
virtual Error buildCodeGenPipeline(ModulePassManager &, raw_pwrite_stream &,
raw_pwrite_stream *, CodeGenFileType,
@@ -478,11 +481,9 @@ class LLVMTargetMachine : public TargetMachine {
}
/// Add passes to the specified pass manager to get machine code emitted with
- /// the MCJIT. This method returns true if machine code is not supported. It
- /// fills the MCContext Ctx pointer which can be used to build custom
- /// MCStreamer.
- bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
- raw_pwrite_stream &Out,
+ /// the MCJIT. This method returns true if machine code is not supported.
+ bool addPassesToEmitMC(PassManagerBase &PM, raw_pwrite_stream &Out,
+ MachineModuleInfo &MMI,
bool DisableVerify = true) override;
/// Returns true if the target is expected to pass all machine verifier
diff --git a/llvm/lib/CodeGen/LLVMTargetMachine.cpp b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
index d0dfafeaef561f..1236c05328fff9 100644
--- a/llvm/lib/CodeGen/LLVMTargetMachine.cpp
+++ b/llvm/lib/CodeGen/LLVMTargetMachine.cpp
@@ -206,13 +206,16 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
return std::move(AsmStreamer);
}
+std::unique_ptr<MachineModuleInfo>
+LLVMTargetMachine::createMachineModuleInfo(MCContext &Ctx) const {
+ return std::make_unique<MachineModuleInfo>(*this, Ctx);
+}
+
bool LLVMTargetMachine::addPassesToEmitFile(
PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
- CodeGenFileType FileType, bool DisableVerify,
- MachineModuleInfoWrapperPass *MMIWP) {
+ CodeGenFileType FileType, MachineModuleInfo &MMI, bool DisableVerify) {
// Add common CodeGen passes.
- if (!MMIWP)
- MMIWP = new MachineModuleInfoWrapperPass(this);
+ auto *MMIWP = new MachineModuleInfoWrapperPass(MMI);
TargetPassConfig *PassConfig =
addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP);
if (!PassConfig)
@@ -233,14 +236,14 @@ bool LLVMTargetMachine::addPassesToEmitFile(
/// addPassesToEmitMC - Add passes to the specified pass manager to get
/// machine code emitted with the MCJIT. This method returns true if machine
-/// code is not supported. It fills the MCContext Ctx pointer which can be
-/// used to build custom MCStreamer.
-///
-bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
+/// code is not supported. It uses the MCContext Ctx of \p MMI so that it
+/// can be used to build custom MCStreamer.
+bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
raw_pwrite_stream &Out,
+ MachineModuleInfo &MMI,
bool DisableVerify) {
// Add common CodeGen passes.
- MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(this);
+ MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(MMI);
TargetPassConfig *PassConfig =
addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP);
if (!PassConfig)
@@ -248,7 +251,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
assert(TargetPassConfig::willCompleteCodeGenPipeline() &&
"Cannot emit MC with limited codegen pipeline");
- Ctx = &MMIWP->getMMI().getContext();
+ auto &Ctx = MMI.getContext();
// libunwind is unable to load compact unwind dynamically, so we must generate
// DWARF unwind info for the JIT.
Options.MCOptions.EmitDwarfUnwind = EmitDwarfUnwindType::Always;
@@ -258,7 +261,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
const MCSubtargetInfo &STI = *getMCSubtargetInfo();
const MCRegisterInfo &MRI = *getMCRegisterInfo();
std::unique_ptr<MCCodeEmitter> MCE(
- getTarget().createMCCodeEmitter(*getMCInstrInfo(), *Ctx));
+ getTarget().createMCCodeEmitter(*getMCInstrInfo(), Ctx));
MCAsmBackend *MAB =
getTarget().createMCAsmBackend(STI, MRI, Options.MCOptions);
if (!MCE || !MAB)
@@ -266,7 +269,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
const Triple &T = getTargetTriple();
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
- T, *Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter(Out),
+ T, Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter(Out),
std::move(MCE), STI));
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.
diff --git a/llvm/lib/CodeGen/MachineModuleInfo.cpp b/llvm/lib/CodeGen/MachineModuleInfo.cpp
index c66495969b4e67..55ef4916cd0101 100644
--- a/llvm/lib/CodeGen/MachineModuleInfo.cpp
+++ b/llvm/lib/CodeGen/MachineModuleInfo.cpp
@@ -30,39 +30,14 @@ void MachineModuleInfo::initialize() {
}
void MachineModuleInfo::finalize() {
- Context.reset();
- // We don't clear the ExternalContext.
-
delete ObjFileMMI;
ObjFileMMI = nullptr;
}
-MachineModuleInfo::MachineModuleInfo(MachineModuleInfo &&MMI)
- : TM(std::move(MMI.TM)),
- Context(TM.getTargetTriple(), TM.getMCAsmInfo(), TM.getMCRegisterInfo(),
- TM.getMCSubtargetInfo(), nullptr, &TM.Options.MCOptions, false),
- MachineFunctions(std::move(MMI.MachineFunctions)) {
+MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine &TM,
+ MCContext &Context)
+ : TM(TM), Context(Context) {
Context.setObjectFileInfo(TM.getObjFileLowering());
- ObjFileMMI = MMI.ObjFileMMI;
- ExternalContext = MMI.ExternalContext;
- TheModule = MMI.TheModule;
-}
-
-MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM)
- : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
- TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),
- nullptr, &TM->Options.MCOptions, false) {
- Context.setObjectFileInfo(TM->getObjFileLowering());
- initialize();
-}
-
-MachineModuleInfo::MachineModuleInfo(const LLVMTargetMachine *TM,
- MCContext *ExtContext)
- : TM(*TM), Context(TM->getTargetTriple(), TM->getMCAsmInfo(),
- TM->getMCRegisterInfo(), TM->getMCSubtargetInfo(),
- nullptr, &TM->Options.MCOptions, false),
- ExternalContext(ExtContext) {
- Context.setObjectFileInfo(TM->getObjFileLowering());
initialize();
}
@@ -137,9 +112,7 @@ class FreeMachineFunction : public FunctionPass {
return true;
}
- StringRef getPassName() const override {
- return "Free MachineFunction";
- }
+ StringRef getPassName() const override { return "Free MachineFunction"; }
};
} // end anonymous namespace
@@ -151,14 +124,8 @@ FunctionPass *llvm::createFreeMachineFunctionPass() {
}
MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
- const LLVMTargetMachine *TM)
- : ImmutablePass(ID), MMI(TM) {
- initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
-}
-
-MachineModuleInfoWrapperPass::MachineModuleInfoWrapperPass(
- const LLVMTargetMachine *TM, MCContext *ExtContext)
- : ImmutablePass(ID), MMI(TM, ExtContext) {
+ MachineModuleInfo &MMI)
+ : ImmutablePass(ID), MMI(MMI) {
initializeMachineModuleInfoWrapperPassPass(*PassRegistry::getPassRegistry());
}
diff --git a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp b/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
index 0d7a51bfe73753..fc9f09c3d3064c 100644
--- a/llvm/lib/ExecutionEngine/MCJIT/MCJIT.cpp
+++ b/llvm/lib/ExecutionEngine/MCJIT/...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/105541
More information about the cfe-commits
mailing list