Skip to content

Commit 4cfc73e

Browse files
committed
Moved the MC emission APIs to TargetMachine again to keep the PR changes to a minimum.
1 parent e8e81db commit 4cfc73e

File tree

5 files changed

+37
-19
lines changed

5 files changed

+37
-19
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class EmitAssemblyHelper {
225225
BuryPointer(std::move(TM));
226226
}
227227

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

230230
// Emit output using the new pass manager for the optimization pipeline.
231231
void EmitAssembly(BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS,
@@ -609,8 +609,8 @@ void EmitAssemblyHelper::CreateTargetMachine(bool MustCreateTM) {
609609
if (!initTargetOptions(Diags, Options, CodeGenOpts, TargetOpts, LangOpts,
610610
HSOpts))
611611
return;
612-
TM.reset(static_cast<LLVMTargetMachine *>(TheTarget->createTargetMachine(
613-
Triple, TargetOpts.CPU, FeaturesStr, Options, RM, CM, OptLevel)));
612+
TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
613+
Options, RM, CM, OptLevel));
614614
TM->setLargeDataThreshold(CodeGenOpts.LargeDataThreshold);
615615
}
616616

@@ -1179,7 +1179,8 @@ void EmitAssemblyHelper::RunCodegenPipeline(
11791179
if (!DwoOS)
11801180
return;
11811181
}
1182-
MMI = std::make_unique<MachineModuleInfo>(TM.get());
1182+
MMI = std::make_unique<MachineModuleInfo>(
1183+
static_cast<LLVMTargetMachine *>(TM.get()));
11831184
if (!AddEmitPasses(CodeGenPasses, *MMI, Action, *OS,
11841185
DwoOS ? &DwoOS->os() : nullptr))
11851186
// FIXME: Should we handle this error differently?

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ getOutputStream(CompilerInstance &ci, llvm::StringRef inFile,
920920
/// \param [in] codeGenOpts options configuring codegen pipeline
921921
/// \param [out] os Output stream to emit the generated code to
922922
static void generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine &diags,
923-
llvm::LLVMTargetMachine &tm,
923+
llvm::TargetMachine &tm,
924924
BackendActionTy act,
925925
llvm::Module &llvmModule,
926926
const CodeGenOptions &codeGenOpts,
@@ -933,7 +933,7 @@ static void generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine &diags,
933933
// Currently only the legacy pass manager is supported.
934934
// TODO: Switch to the new PM once it's available in the backend.
935935
llvm::legacy::PassManager codeGenPasses;
936-
llvm::MachineModuleInfo mmi(&tm);
936+
llvm::MachineModuleInfo mmi(static_cast<llvm::LLVMTargetMachine *>(&tm));
937937
codeGenPasses.add(
938938
createTargetTransformInfoWrapperPass(tm.getTargetIRAnalysis()));
939939

@@ -1371,8 +1371,7 @@ void CodeGenAction::executeAction() {
13711371
if (action == BackendActionTy::Backend_EmitAssembly ||
13721372
action == BackendActionTy::Backend_EmitObj) {
13731373
generateMachineCodeOrAssemblyImpl(
1374-
diags, *static_cast<llvm::LLVMTargetMachine *>(&targetMachine), action,
1375-
*llvmModule, codeGenOpts,
1374+
diags, targetMachine, action, *llvmModule, codeGenOpts,
13761375
ci.isOutputStreamNull() ? *os : ci.getOutputStream());
13771376
return;
13781377
}

llvm/include/llvm/Target/TargetMachine.h

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,25 @@ 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+
virtual bool addPassesToEmitFile(PassManagerBase &, MachineModuleInfo &,
383+
raw_pwrite_stream &, raw_pwrite_stream *,
384+
CodeGenFileType,
385+
bool /*DisableVerify*/ = true) {
386+
return true;
387+
}
388+
389+
/// Add passes to the specified pass manager to get machine code emitted with
390+
/// the MCJIT. This method returns true if machine code is not supported.
391+
virtual bool addPassesToEmitMC(PassManagerBase &, MachineModuleInfo &,
392+
raw_pwrite_stream &,
393+
bool /*DisableVerify*/ = true) {
394+
return true;
395+
}
396+
378397
/// True if subtarget inserts the final scheduling pass on its own.
379398
///
380399
/// Branch relaxation, which must happen after block placement, can
@@ -438,11 +457,10 @@ class LLVMTargetMachine : public TargetMachine {
438457
/// emitted. Typically this will involve several steps of code generation.
439458
/// This method should return true if emission of this file type is not
440459
/// 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);
460+
bool addPassesToEmitFile(PassManagerBase &PM, MachineModuleInfo &MMI,
461+
raw_pwrite_stream &Out, raw_pwrite_stream *DwoOut,
462+
CodeGenFileType FileType,
463+
bool DisableVerify = true) override;
446464

447465
virtual Error buildCodeGenPipeline(ModulePassManager &, raw_pwrite_stream &,
448466
raw_pwrite_stream *, CodeGenFileType,
@@ -454,9 +472,9 @@ class LLVMTargetMachine : public TargetMachine {
454472

455473
/// Add passes to the specified pass manager to get machine code emitted with
456474
/// 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);
475+
bool addPassesToEmitMC(PassManagerBase &PM, MachineModuleInfo &MMI,
476+
raw_pwrite_stream &Out,
477+
bool DisableVerify = true) override;
460478

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

llvm/lib/ExecutionEngine/Orc/CompileUtils.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ Expected<SimpleCompiler::CompileResult> SimpleCompiler::operator()(Module &M) {
4747
raw_svector_ostream ObjStream(ObjBufferSV);
4848

4949
legacy::PassManager PM;
50-
auto *LLVMTM = static_cast<LLVMTargetMachine *>(&TM);
51-
MachineModuleInfo MMI(LLVMTM);
52-
if (LLVMTM->addPassesToEmitMC(PM, MMI, ObjStream))
50+
MachineModuleInfo MMI(static_cast<LLVMTargetMachine *>(&TM));
51+
if (TM.addPassesToEmitMC(PM, MMI, ObjStream))
5352
return make_error<StringError>("Target does not support MC emission",
5453
inconvertibleErrorCode());
5554
PM.run(M);

llvm/lib/LTO/LTOBackend.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "llvm/Analysis/TargetLibraryInfo.h"
2121
#include "llvm/Bitcode/BitcodeReader.h"
2222
#include "llvm/Bitcode/BitcodeWriter.h"
23+
#include "llvm/CodeGen/MachineModuleInfo.h"
2324
#include "llvm/IR/LLVMRemarkStreamer.h"
2425
#include "llvm/IR/LegacyPassManager.h"
2526
#include "llvm/IR/PassManager.h"

0 commit comments

Comments
 (0)