Skip to content

Commit ed40387

Browse files
committed
Migrated BackendUtil.cpp to the new LLVMTargetMachine code emission API.
1 parent c2d984a commit ed40387

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "llvm/Bitcode/BitcodeReader.h"
2727
#include "llvm/Bitcode/BitcodeWriter.h"
2828
#include "llvm/Bitcode/BitcodeWriterPass.h"
29+
#include "llvm/CodeGen/MachineModuleInfo.h"
2930
#include "llvm/CodeGen/RegAllocRegistry.h"
3031
#include "llvm/CodeGen/SchedulerRegistry.h"
3132
#include "llvm/CodeGen/TargetSubtargetInfo.h"
@@ -167,8 +168,9 @@ class EmitAssemblyHelper {
167168
/// Add passes necessary to emit assembly or LLVM IR.
168169
///
169170
/// \return True on success.
170-
bool AddEmitPasses(legacy::PassManager &CodeGenPasses, BackendAction Action,
171-
raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
171+
bool AddEmitPasses(legacy::PassManager &CodeGenPasses, MachineModuleInfo &MMI,
172+
BackendAction Action, raw_pwrite_stream &OS,
173+
raw_pwrite_stream *DwoOS);
172174

173175
std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
174176
std::error_code EC;
@@ -223,7 +225,7 @@ class EmitAssemblyHelper {
223225
BuryPointer(std::move(TM));
224226
}
225227

226-
std::unique_ptr<TargetMachine> TM;
228+
std::unique_ptr<LLVMTargetMachine> TM;
227229

228230
// Emit output using the new pass manager for the optimization pipeline.
229231
void EmitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS,
@@ -607,12 +609,13 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
607609
if (!initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts,
608610
HSOpts))
609611
return;
610-
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
611-
Options, RM, CM, OptLevel));
612+
TM.reset(static_cast<LLVMTargetMachine *>(TheTarget->createTargetMachine(
613+
Triple, TargetOpts.CPU, FeaturesStr, Options, RM, CM, OptLevel)));
612614
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
613615
}
614616

615617
bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
618+
MachineModuleInfo &MMI,
616619
BackendAction Action,
617620
raw_pwrite_stream &OS,
618621
raw_pwrite_stream *DwoOS) {
@@ -625,7 +628,7 @@ bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
625628
// this also adds codegenerator level optimization passes.
626629
CodeGenFileType CGFT = getCodeGenFileType(Action);
627630

628-
if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
631+
if (TM->addPassesToEmitFile(CodeGenPasses, MMI, OS, DwoOS, CGFT,
629632
/*DisableVerify=*/!CodeGenOpts.VerifyModule)) {
630633
Diags.Report(diag::err_fe_unable_to_interface_with_target);
631634
return false;
@@ -1162,6 +1165,7 @@ void EmitAssemblyHelper::RunCodegenPipeline(
11621165
// does not work with the codegen pipeline.
11631166
// FIXME: make the new PM work with the codegen pipeline.
11641167
legacy::PassManager CodeGenPasses;
1168+
std::unique_ptr<MachineModuleInfo> MMI;
11651169

11661170
// Append any output we need to the pass manager.
11671171
switch (Action) {
@@ -1175,7 +1179,8 @@ void EmitAssemblyHelper::RunCodegenPipeline(
11751179
if (!DwoOS)
11761180
return;
11771181
}
1178-
if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1182+
MMI = std::make_unique<MachineModuleInfo>(TM.get());
1183+
if (!AddEmitPasses(CodeGenPasses, *MMI, Action, *OS,
11791184
DwoOS ? &DwoOS->os() : nullptr))
11801185
// FIXME: Should we handle this error differently?
11811186
return;

0 commit comments

Comments
 (0)