5252#include " llvm/Analysis/TargetLibraryInfo.h"
5353#include " llvm/Analysis/TargetTransformInfo.h"
5454#include " llvm/Bitcode/BitcodeWriterPass.h"
55+ #include " llvm/CodeGen/MachineModuleInfo.h"
5556#include " llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
5657#include " llvm/IR/LLVMRemarkStreamer.h"
5758#include " llvm/IR/LegacyPassManager.h"
@@ -919,7 +920,7 @@ getOutputStream(CompilerInstance &ci, llvm::StringRef inFile,
919920// / \param [in] codeGenOpts options configuring codegen pipeline
920921// / \param [out] os Output stream to emit the generated code to
921922static void generateMachineCodeOrAssemblyImpl (clang::DiagnosticsEngine &diags,
922- llvm::TargetMachine &tm,
923+ llvm::LLVMTargetMachine &tm,
923924 BackendActionTy act,
924925 llvm::Module &llvmModule,
925926 const CodeGenOptions &codeGenOpts,
@@ -932,6 +933,7 @@ static void generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine &diags,
932933 // Currently only the legacy pass manager is supported.
933934 // TODO: Switch to the new PM once it's available in the backend.
934935 llvm::legacy::PassManager codeGenPasses;
936+ llvm::MachineModuleInfo mmi (&tm);
935937 codeGenPasses.add (
936938 createTargetTransformInfoWrapperPass (tm.getTargetIRAnalysis ()));
937939
@@ -943,7 +945,7 @@ static void generateMachineCodeOrAssemblyImpl(clang::DiagnosticsEngine &diags,
943945 llvm::CodeGenFileType cgft = (act == BackendActionTy::Backend_EmitAssembly)
944946 ? llvm::CodeGenFileType::AssemblyFile
945947 : llvm::CodeGenFileType::ObjectFile;
946- if (tm.addPassesToEmitFile (codeGenPasses, os, nullptr , cgft)) {
948+ if (tm.addPassesToEmitFile (codeGenPasses, mmi, os, nullptr , cgft)) {
947949 unsigned diagID =
948950 diags.getCustomDiagID (clang::DiagnosticsEngine::Error,
949951 " emission of this file type is not supported" );
@@ -1369,7 +1371,8 @@ void CodeGenAction::executeAction() {
13691371 if (action == BackendActionTy::Backend_EmitAssembly ||
13701372 action == BackendActionTy::Backend_EmitObj) {
13711373 generateMachineCodeOrAssemblyImpl (
1372- diags, targetMachine, action, *llvmModule, codeGenOpts,
1374+ diags, *static_cast <llvm::LLVMTargetMachine *>(&targetMachine), action,
1375+ *llvmModule, codeGenOpts,
13731376 ci.isOutputStreamNull () ? *os : ci.getOutputStream ());
13741377 return ;
13751378 }
0 commit comments