Skip to content

Commit c2d984a

Browse files
committed
Moved the MC pass creation functions from TargetMachine to LLVMTargetMachine.
1 parent 6a78a68 commit c2d984a

File tree

2 files changed

+22
-52
lines changed

2 files changed

+22
-52
lines changed

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -375,31 +375,6 @@ class TargetMachine {
375375
/// with the new pass manager. Only affects the "default" AAManager.
376376
virtual void registerDefaultAliasAnalyses(AAManager &) {}
377377

378-
/// Add passes to the specified pass manager to get the specified file
379-
/// emitted. Typically this will involve several steps of code generation.
380-
/// This method should return true if emission of this file type is not
381-
/// supported, or false on success.
382-
/// \p MMIWP is an optional parameter that, if set to non-nullptr,
383-
/// will be used to set the MachineModuloInfo for this PM.
384-
virtual bool
385-
addPassesToEmitFile(PassManagerBase &, raw_pwrite_stream &,
386-
raw_pwrite_stream *, CodeGenFileType,
387-
bool /*DisableVerify*/ = true,
388-
MachineModuleInfoWrapperPass *MMIWP = nullptr) {
389-
return true;
390-
}
391-
392-
/// Add passes to the specified pass manager to get machine code emitted with
393-
/// the MCJIT. This method returns true if machine code is not supported. It
394-
/// fills the MCContext Ctx pointer which can be used to build custom
395-
/// MCStreamer.
396-
///
397-
virtual bool addPassesToEmitMC(PassManagerBase &, MCContext *&,
398-
raw_pwrite_stream &,
399-
bool /*DisableVerify*/ = true) {
400-
return true;
401-
}
402-
403378
/// True if subtarget inserts the final scheduling pass on its own.
404379
///
405380
/// Branch relaxation, which must happen after block placement, can
@@ -460,14 +435,14 @@ class LLVMTargetMachine : public TargetMachine {
460435
virtual TargetPassConfig *createPassConfig(PassManagerBase &PM);
461436

462437
/// Add passes to the specified pass manager to get the specified file
463-
/// emitted. Typically this will involve several steps of code generation.
464-
/// \p MMIWP is an optional parameter that, if set to non-nullptr,
465-
/// will be used to set the MachineModuloInfo for this PM.
466-
bool
467-
addPassesToEmitFile(PassManagerBase &PM, raw_pwrite_stream &Out,
468-
raw_pwrite_stream *DwoOut, CodeGenFileType FileType,
469-
bool DisableVerify = true,
470-
MachineModuleInfoWrapperPass *MMIWP = nullptr) override;
438+
/// emitted. Typically this will involve several steps of code generation.
439+
/// This method should return true if emission of this file type is not
440+
/// supported, or false on success.
441+
virtual bool addPassesToEmitFile(PassManagerBase &PM, MachineModuleInfo &MMI,
442+
raw_pwrite_stream &Out,
443+
raw_pwrite_stream *DwoOut,
444+
CodeGenFileType FileType,
445+
bool DisableVerify = true);
471446

472447
virtual Error buildCodeGenPipeline(ModulePassManager &, raw_pwrite_stream &,
473448
raw_pwrite_stream *, CodeGenFileType,
@@ -478,12 +453,10 @@ class LLVMTargetMachine : public TargetMachine {
478453
}
479454

480455
/// Add passes to the specified pass manager to get machine code emitted with
481-
/// the MCJIT. This method returns true if machine code is not supported. It
482-
/// fills the MCContext Ctx pointer which can be used to build custom
483-
/// MCStreamer.
484-
bool addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
485-
raw_pwrite_stream &Out,
486-
bool DisableVerify = true) override;
456+
/// the MCJIT. This method returns true if machine code is not supported.
457+
virtual bool addPassesToEmitMC(PassManagerBase &PM, MachineModuleInfo &MMI,
458+
raw_pwrite_stream &Out,
459+
bool DisableVerify = true);
487460

488461
/// Returns true if the target is expected to pass all machine verifier
489462
/// checks. This is a stopgap measure to fix targets one by one. We will

llvm/lib/CodeGen/LLVMTargetMachine.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,12 +209,10 @@ Expected<std::unique_ptr<MCStreamer>> LLVMTargetMachine::createMCStreamer(
209209
}
210210

211211
bool LLVMTargetMachine::addPassesToEmitFile(
212-
PassManagerBase &PM, raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
213-
CodeGenFileType FileType, bool DisableVerify,
214-
MachineModuleInfoWrapperPass *MMIWP) {
212+
PassManagerBase &PM, MachineModuleInfo &MMI, raw_pwrite_stream &Out,
213+
raw_pwrite_stream *DwoOut, CodeGenFileType FileType, bool DisableVerify) {
215214
// Add common CodeGen passes.
216-
if (!MMIWP)
217-
MMIWP = new MachineModuleInfoWrapperPass(this);
215+
auto *MMIWP = new MachineModuleInfoWrapperPass(MMI);
218216
TargetPassConfig *PassConfig =
219217
addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP);
220218
if (!PassConfig)
@@ -235,22 +233,21 @@ bool LLVMTargetMachine::addPassesToEmitFile(
235233

236234
/// addPassesToEmitMC - Add passes to the specified pass manager to get
237235
/// machine code emitted with the MCJIT. This method returns true if machine
238-
/// code is not supported. It fills the MCContext Ctx pointer which can be
239-
/// used to build custom MCStreamer.
240-
///
241-
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
236+
/// code is not supported.
237+
bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM,
238+
MachineModuleInfo &MMI,
242239
raw_pwrite_stream &Out,
243240
bool DisableVerify) {
244241
// Add common CodeGen passes.
245-
MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(this);
242+
MachineModuleInfoWrapperPass *MMIWP = new MachineModuleInfoWrapperPass(MMI);
246243
TargetPassConfig *PassConfig =
247244
addPassesToGenerateCode(*this, PM, DisableVerify, *MMIWP);
248245
if (!PassConfig)
249246
return true;
250247
assert(TargetPassConfig::willCompleteCodeGenPipeline() &&
251248
"Cannot emit MC with limited codegen pipeline");
252249

253-
Ctx = &MMIWP->getMMI().getContext();
250+
auto &Ctx = MMI.getContext();
254251
// libunwind is unable to load compact unwind dynamically, so we must generate
255252
// DWARF unwind info for the JIT.
256253
Options.MCOptions.EmitDwarfUnwind = EmitDwarfUnwindType::Always;
@@ -260,7 +257,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
260257
const MCSubtargetInfo &STI = *getMCSubtargetInfo();
261258
const MCRegisterInfo &MRI = *getMCRegisterInfo();
262259
std::unique_ptr<MCCodeEmitter> MCE(
263-
getTarget().createMCCodeEmitter(*getMCInstrInfo(), *Ctx));
260+
getTarget().createMCCodeEmitter(*getMCInstrInfo(), Ctx));
264261
if (!MCE)
265262
return true;
266263
MCAsmBackend *MAB =
@@ -270,7 +267,7 @@ bool LLVMTargetMachine::addPassesToEmitMC(PassManagerBase &PM, MCContext *&Ctx,
270267

271268
const Triple &T = getTargetTriple();
272269
std::unique_ptr<MCStreamer> AsmStreamer(getTarget().createMCObjectStreamer(
273-
T, *Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter(Out),
270+
T, Ctx, std::unique_ptr<MCAsmBackend>(MAB), MAB->createObjectWriter(Out),
274271
std::move(MCE), STI));
275272

276273
// Create the AsmPrinter, which takes ownership of AsmStreamer if successful.

0 commit comments

Comments
 (0)