1 //===-LTOCodeGenerator.cpp - LLVM Link Time Optimizer ---------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file implements the Link Time Optimization library. This library is
10 // intended to be used by linker to optimize code at link time.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/LTO/legacy/LTOCodeGenerator.h"
16 #include "llvm/ADT/Statistic.h"
17 #include "llvm/ADT/StringExtras.h"
18 #include "llvm/Analysis/Passes.h"
19 #include "llvm/Analysis/TargetLibraryInfo.h"
20 #include "llvm/Analysis/TargetTransformInfo.h"
21 #include "llvm/Bitcode/BitcodeWriter.h"
22 #include "llvm/CodeGen/ParallelCG.h"
23 #include "llvm/CodeGen/TargetSubtargetInfo.h"
24 #include "llvm/Config/config.h"
25 #include "llvm/IR/Constants.h"
26 #include "llvm/IR/DataLayout.h"
27 #include "llvm/IR/DebugInfo.h"
28 #include "llvm/IR/DerivedTypes.h"
29 #include "llvm/IR/DiagnosticInfo.h"
30 #include "llvm/IR/DiagnosticPrinter.h"
31 #include "llvm/IR/LLVMContext.h"
32 #include "llvm/IR/LegacyPassManager.h"
33 #include "llvm/IR/Mangler.h"
34 #include "llvm/IR/Module.h"
35 #include "llvm/IR/PassTimingInfo.h"
36 #include "llvm/IR/RemarkStreamer.h"
37 #include "llvm/IR/Verifier.h"
38 #include "llvm/InitializePasses.h"
39 #include "llvm/LTO/LTO.h"
40 #include "llvm/LTO/legacy/LTOModule.h"
41 #include "llvm/LTO/legacy/UpdateCompilerUsed.h"
42 #include "llvm/Linker/Linker.h"
43 #include "llvm/MC/MCAsmInfo.h"
44 #include "llvm/MC/MCContext.h"
45 #include "llvm/MC/SubtargetFeature.h"
46 #include "llvm/Support/CommandLine.h"
47 #include "llvm/Support/FileSystem.h"
48 #include "llvm/Support/Host.h"
49 #include "llvm/Support/MemoryBuffer.h"
50 #include "llvm/Support/Signals.h"
51 #include "llvm/Support/TargetRegistry.h"
52 #include "llvm/Support/TargetSelect.h"
53 #include "llvm/Support/ToolOutputFile.h"
54 #include "llvm/Support/YAMLTraits.h"
55 #include "llvm/Support/raw_ostream.h"
56 #include "llvm/Target/TargetOptions.h"
57 #include "llvm/Transforms/IPO.h"
58 #include "llvm/Transforms/IPO/Internalize.h"
59 #include "llvm/Transforms/IPO/PassManagerBuilder.h"
60 #include "llvm/Transforms/ObjCARC.h"
61 #include "llvm/Transforms/Utils/ModuleUtils.h"
62 #include <system_error>
65 const char* LTOCodeGenerator::getVersionString() {
66 #ifdef LLVM_VERSION_INFO
67 return PACKAGE_NAME
" version " PACKAGE_VERSION
", " LLVM_VERSION_INFO
;
69 return PACKAGE_NAME
" version " PACKAGE_VERSION
;
74 cl::opt
<bool> LTODiscardValueNames(
75 "lto-discard-value-names",
76 cl::desc("Strip names from Value during LTO (other than GlobalValue)."),
84 cl::opt
<bool> RemarksWithHotness(
85 "lto-pass-remarks-with-hotness",
86 cl::desc("With PGO, include profile count in optimization remarks"),
90 RemarksFilename("lto-pass-remarks-output",
91 cl::desc("Output filename for pass remarks"),
92 cl::value_desc("filename"));
95 RemarksPasses("lto-pass-remarks-filter",
96 cl::desc("Only record optimization remarks from passes whose "
97 "names match the given regular expression"),
98 cl::value_desc("regex"));
100 cl::opt
<std::string
> RemarksFormat(
101 "lto-pass-remarks-format",
102 cl::desc("The format used for serializing remarks (default: YAML)"),
103 cl::value_desc("format"), cl::init("yaml"));
105 cl::opt
<std::string
> LTOStatsFile(
107 cl::desc("Save statistics to the specified file"),
111 LTOCodeGenerator::LTOCodeGenerator(LLVMContext
&Context
)
112 : Context(Context
), MergedModule(new Module("ld-temp.o", Context
)),
113 TheLinker(new Linker(*MergedModule
)) {
114 Context
.setDiscardValueNames(LTODiscardValueNames
);
115 Context
.enableDebugTypeODRUniquing();
116 initializeLTOPasses();
119 LTOCodeGenerator::~LTOCodeGenerator() {}
121 // Initialize LTO passes. Please keep this function in sync with
122 // PassManagerBuilder::populateLTOPassManager(), and make sure all LTO
123 // passes are initialized.
124 void LTOCodeGenerator::initializeLTOPasses() {
125 PassRegistry
&R
= *PassRegistry::getPassRegistry();
127 initializeInternalizeLegacyPassPass(R
);
128 initializeIPSCCPLegacyPassPass(R
);
129 initializeGlobalOptLegacyPassPass(R
);
130 initializeConstantMergeLegacyPassPass(R
);
131 initializeDAHPass(R
);
132 initializeInstructionCombiningPassPass(R
);
133 initializeSimpleInlinerPass(R
);
134 initializePruneEHPass(R
);
135 initializeGlobalDCELegacyPassPass(R
);
136 initializeArgPromotionPass(R
);
137 initializeJumpThreadingPass(R
);
138 initializeSROALegacyPassPass(R
);
139 initializeAttributorLegacyPassPass(R
);
140 initializePostOrderFunctionAttrsLegacyPassPass(R
);
141 initializeReversePostOrderFunctionAttrsLegacyPassPass(R
);
142 initializeGlobalsAAWrapperPassPass(R
);
143 initializeLegacyLICMPassPass(R
);
144 initializeMergedLoadStoreMotionLegacyPassPass(R
);
145 initializeGVNLegacyPassPass(R
);
146 initializeMemCpyOptLegacyPassPass(R
);
147 initializeDCELegacyPassPass(R
);
148 initializeCFGSimplifyPassPass(R
);
151 void LTOCodeGenerator::setAsmUndefinedRefs(LTOModule
*Mod
) {
152 const std::vector
<StringRef
> &undefs
= Mod
->getAsmUndefinedRefs();
153 for (int i
= 0, e
= undefs
.size(); i
!= e
; ++i
)
154 AsmUndefinedRefs
.insert(undefs
[i
]);
157 bool LTOCodeGenerator::addModule(LTOModule
*Mod
) {
158 assert(&Mod
->getModule().getContext() == &Context
&&
159 "Expected module in same context");
161 bool ret
= TheLinker
->linkInModule(Mod
->takeModule());
162 setAsmUndefinedRefs(Mod
);
164 // We've just changed the input, so let's make sure we verify it.
165 HasVerifiedInput
= false;
170 void LTOCodeGenerator::setModule(std::unique_ptr
<LTOModule
> Mod
) {
171 assert(&Mod
->getModule().getContext() == &Context
&&
172 "Expected module in same context");
174 AsmUndefinedRefs
.clear();
176 MergedModule
= Mod
->takeModule();
177 TheLinker
= std::make_unique
<Linker
>(*MergedModule
);
178 setAsmUndefinedRefs(&*Mod
);
180 // We've just changed the input, so let's make sure we verify it.
181 HasVerifiedInput
= false;
184 void LTOCodeGenerator::setTargetOptions(const TargetOptions
&Options
) {
185 this->Options
= Options
;
188 void LTOCodeGenerator::setDebugInfo(lto_debug_model Debug
) {
190 case LTO_DEBUG_MODEL_NONE
:
191 EmitDwarfDebugInfo
= false;
194 case LTO_DEBUG_MODEL_DWARF
:
195 EmitDwarfDebugInfo
= true;
198 llvm_unreachable("Unknown debug format!");
201 void LTOCodeGenerator::setOptLevel(unsigned Level
) {
205 CGOptLevel
= CodeGenOpt::None
;
208 CGOptLevel
= CodeGenOpt::Less
;
211 CGOptLevel
= CodeGenOpt::Default
;
214 CGOptLevel
= CodeGenOpt::Aggressive
;
217 llvm_unreachable("Unknown optimization level!");
220 bool LTOCodeGenerator::writeMergedModules(StringRef Path
) {
221 if (!determineTarget())
224 // We always run the verifier once on the merged module.
225 verifyMergedModuleOnce();
227 // mark which symbols can not be internalized
228 applyScopeRestrictions();
230 // create output file
232 ToolOutputFile
Out(Path
, EC
, sys::fs::OF_None
);
234 std::string ErrMsg
= "could not open bitcode file for writing: ";
235 ErrMsg
+= Path
.str() + ": " + EC
.message();
240 // write bitcode to it
241 WriteBitcodeToFile(*MergedModule
, Out
.os(), ShouldEmbedUselists
);
244 if (Out
.os().has_error()) {
245 std::string ErrMsg
= "could not write bitcode file: ";
246 ErrMsg
+= Path
.str() + ": " + Out
.os().error().message();
248 Out
.os().clear_error();
256 bool LTOCodeGenerator::compileOptimizedToFile(const char **Name
) {
257 // make unique temp output file to put generated code
258 SmallString
<128> Filename
;
262 (FileType
== TargetMachine::CGFT_AssemblyFile
? "s" : "o");
265 sys::fs::createTemporaryFile("lto-llvm", Extension
, FD
, Filename
);
267 emitError(EC
.message());
271 // generate object file
272 ToolOutputFile
objFile(Filename
, FD
);
274 bool genResult
= compileOptimized(&objFile
.os());
275 objFile
.os().close();
276 if (objFile
.os().has_error()) {
277 emitError((Twine("could not write object file: ") + Filename
+ ": " +
278 objFile
.os().error().message())
280 objFile
.os().clear_error();
281 sys::fs::remove(Twine(Filename
));
287 sys::fs::remove(Twine(Filename
));
291 NativeObjectPath
= Filename
.c_str();
292 *Name
= NativeObjectPath
.c_str();
296 std::unique_ptr
<MemoryBuffer
>
297 LTOCodeGenerator::compileOptimized() {
299 if (!compileOptimizedToFile(&name
))
302 // read .o file into memory buffer
303 ErrorOr
<std::unique_ptr
<MemoryBuffer
>> BufferOrErr
=
304 MemoryBuffer::getFile(name
, -1, false);
305 if (std::error_code EC
= BufferOrErr
.getError()) {
306 emitError(EC
.message());
307 sys::fs::remove(NativeObjectPath
);
312 sys::fs::remove(NativeObjectPath
);
314 return std::move(*BufferOrErr
);
317 bool LTOCodeGenerator::compile_to_file(const char **Name
, bool DisableVerify
,
319 bool DisableGVNLoadPRE
,
320 bool DisableVectorization
) {
321 if (!optimize(DisableVerify
, DisableInline
, DisableGVNLoadPRE
,
322 DisableVectorization
))
325 return compileOptimizedToFile(Name
);
328 std::unique_ptr
<MemoryBuffer
>
329 LTOCodeGenerator::compile(bool DisableVerify
, bool DisableInline
,
330 bool DisableGVNLoadPRE
, bool DisableVectorization
) {
331 if (!optimize(DisableVerify
, DisableInline
, DisableGVNLoadPRE
,
332 DisableVectorization
))
335 return compileOptimized();
338 bool LTOCodeGenerator::determineTarget() {
342 TripleStr
= MergedModule
->getTargetTriple();
343 if (TripleStr
.empty()) {
344 TripleStr
= sys::getDefaultTargetTriple();
345 MergedModule
->setTargetTriple(TripleStr
);
347 llvm::Triple
Triple(TripleStr
);
349 // create target machine from info for merged modules
351 MArch
= TargetRegistry::lookupTarget(TripleStr
, ErrMsg
);
357 // Construct LTOModule, hand over ownership of module and target. Use MAttr as
358 // the default set of features.
359 SubtargetFeatures
Features(MAttr
);
360 Features
.getDefaultSubtargetFeatures(Triple
);
361 FeatureStr
= Features
.getString();
362 // Set a default CPU for Darwin triples.
363 if (MCpu
.empty() && Triple
.isOSDarwin()) {
364 if (Triple
.getArch() == llvm::Triple::x86_64
)
366 else if (Triple
.getArch() == llvm::Triple::x86
)
368 else if (Triple
.getArch() == llvm::Triple::aarch64
||
369 Triple
.getArch() == llvm::Triple::aarch64_32
)
373 TargetMach
= createTargetMachine();
377 std::unique_ptr
<TargetMachine
> LTOCodeGenerator::createTargetMachine() {
378 return std::unique_ptr
<TargetMachine
>(MArch
->createTargetMachine(
379 TripleStr
, MCpu
, FeatureStr
, Options
, RelocModel
, None
, CGOptLevel
));
382 // If a linkonce global is present in the MustPreserveSymbols, we need to make
383 // sure we honor this. To force the compiler to not drop it, we add it to the
384 // "llvm.compiler.used" global.
385 void LTOCodeGenerator::preserveDiscardableGVs(
387 llvm::function_ref
<bool(const GlobalValue
&)> mustPreserveGV
) {
388 std::vector
<GlobalValue
*> Used
;
389 auto mayPreserveGlobal
= [&](GlobalValue
&GV
) {
390 if (!GV
.isDiscardableIfUnused() || GV
.isDeclaration() ||
393 if (GV
.hasAvailableExternallyLinkage())
395 (Twine("Linker asked to preserve available_externally global: '") +
396 GV
.getName() + "'").str());
397 if (GV
.hasInternalLinkage())
398 return emitWarning((Twine("Linker asked to preserve internal global: '") +
399 GV
.getName() + "'").str());
402 for (auto &GV
: TheModule
)
403 mayPreserveGlobal(GV
);
404 for (auto &GV
: TheModule
.globals())
405 mayPreserveGlobal(GV
);
406 for (auto &GV
: TheModule
.aliases())
407 mayPreserveGlobal(GV
);
412 appendToCompilerUsed(TheModule
, Used
);
415 void LTOCodeGenerator::applyScopeRestrictions() {
416 if (ScopeRestrictionsDone
)
419 // Declare a callback for the internalize pass that will ask for every
420 // candidate GlobalValue if it can be internalized or not.
422 SmallString
<64> MangledName
;
423 auto mustPreserveGV
= [&](const GlobalValue
&GV
) -> bool {
424 // Unnamed globals can't be mangled, but they can't be preserved either.
428 // Need to mangle the GV as the "MustPreserveSymbols" StringSet is filled
429 // with the linker supplied name, which on Darwin includes a leading
432 MangledName
.reserve(GV
.getName().size() + 1);
433 Mang
.getNameWithPrefix(MangledName
, &GV
, /*CannotUsePrivateLabel=*/false);
434 return MustPreserveSymbols
.count(MangledName
);
437 // Preserve linkonce value on linker request
438 preserveDiscardableGVs(*MergedModule
, mustPreserveGV
);
440 if (!ShouldInternalize
)
443 if (ShouldRestoreGlobalsLinkage
) {
444 // Record the linkage type of non-local symbols so they can be restored
446 // to module splitting.
447 auto RecordLinkage
= [&](const GlobalValue
&GV
) {
448 if (!GV
.hasAvailableExternallyLinkage() && !GV
.hasLocalLinkage() &&
450 ExternalSymbols
.insert(std::make_pair(GV
.getName(), GV
.getLinkage()));
452 for (auto &GV
: *MergedModule
)
454 for (auto &GV
: MergedModule
->globals())
456 for (auto &GV
: MergedModule
->aliases())
460 // Update the llvm.compiler_used globals to force preserving libcalls and
461 // symbols referenced from asm
462 updateCompilerUsed(*MergedModule
, *TargetMach
, AsmUndefinedRefs
);
464 internalizeModule(*MergedModule
, mustPreserveGV
);
466 MergedModule
->addModuleFlag(Module::Error
, "LTOPostLink", 1);
468 ScopeRestrictionsDone
= true;
471 /// Restore original linkage for symbols that may have been internalized
472 void LTOCodeGenerator::restoreLinkageForExternals() {
473 if (!ShouldInternalize
|| !ShouldRestoreGlobalsLinkage
)
476 assert(ScopeRestrictionsDone
&&
477 "Cannot externalize without internalization!");
479 if (ExternalSymbols
.empty())
482 auto externalize
= [this](GlobalValue
&GV
) {
483 if (!GV
.hasLocalLinkage() || !GV
.hasName())
486 auto I
= ExternalSymbols
.find(GV
.getName());
487 if (I
== ExternalSymbols
.end())
490 GV
.setLinkage(I
->second
);
493 llvm::for_each(MergedModule
->functions(), externalize
);
494 llvm::for_each(MergedModule
->globals(), externalize
);
495 llvm::for_each(MergedModule
->aliases(), externalize
);
498 void LTOCodeGenerator::verifyMergedModuleOnce() {
499 // Only run on the first call.
500 if (HasVerifiedInput
)
502 HasVerifiedInput
= true;
504 bool BrokenDebugInfo
= false;
505 if (verifyModule(*MergedModule
, &dbgs(), &BrokenDebugInfo
))
506 report_fatal_error("Broken module found, compilation aborted!");
507 if (BrokenDebugInfo
) {
508 emitWarning("Invalid debug info found, debug info will be stripped");
509 StripDebugInfo(*MergedModule
);
513 void LTOCodeGenerator::finishOptimizationRemarks() {
514 if (DiagnosticOutputFile
) {
515 DiagnosticOutputFile
->keep();
516 // FIXME: LTOCodeGenerator dtor is not invoked on Darwin
517 DiagnosticOutputFile
->os().flush();
521 /// Optimize merged modules using various IPO passes
522 bool LTOCodeGenerator::optimize(bool DisableVerify
, bool DisableInline
,
523 bool DisableGVNLoadPRE
,
524 bool DisableVectorization
) {
525 if (!this->determineTarget())
529 lto::setupOptimizationRemarks(Context
, RemarksFilename
, RemarksPasses
,
530 RemarksFormat
, RemarksWithHotness
);
531 if (!DiagFileOrErr
) {
532 errs() << "Error: " << toString(DiagFileOrErr
.takeError()) << "\n";
533 report_fatal_error("Can't get an output file for the remarks");
535 DiagnosticOutputFile
= std::move(*DiagFileOrErr
);
537 // Setup output file to emit statistics.
538 auto StatsFileOrErr
= lto::setupStatsFile(LTOStatsFile
);
539 if (!StatsFileOrErr
) {
540 errs() << "Error: " << toString(StatsFileOrErr
.takeError()) << "\n";
541 report_fatal_error("Can't get an output file for the statistics");
543 StatsFile
= std::move(StatsFileOrErr
.get());
545 // We always run the verifier once on the merged module, the `DisableVerify`
546 // parameter only applies to subsequent verify.
547 verifyMergedModuleOnce();
549 // Mark which symbols can not be internalized
550 this->applyScopeRestrictions();
552 // Instantiate the pass manager to organize the passes.
553 legacy::PassManager passes
;
555 // Add an appropriate DataLayout instance for this module...
556 MergedModule
->setDataLayout(TargetMach
->createDataLayout());
559 createTargetTransformInfoWrapperPass(TargetMach
->getTargetIRAnalysis()));
561 Triple
TargetTriple(TargetMach
->getTargetTriple());
562 PassManagerBuilder PMB
;
563 PMB
.DisableGVNLoadPRE
= DisableGVNLoadPRE
;
564 PMB
.LoopVectorize
= !DisableVectorization
;
565 PMB
.SLPVectorize
= !DisableVectorization
;
567 PMB
.Inliner
= createFunctionInliningPass();
568 PMB
.LibraryInfo
= new TargetLibraryInfoImpl(TargetTriple
);
570 PMB
.LibraryInfo
->disableAllFunctions();
571 PMB
.OptLevel
= OptLevel
;
572 PMB
.VerifyInput
= !DisableVerify
;
573 PMB
.VerifyOutput
= !DisableVerify
;
575 PMB
.populateLTOPassManager(passes
);
577 // Run our queue of passes all at once now, efficiently.
578 passes
.run(*MergedModule
);
583 bool LTOCodeGenerator::compileOptimized(ArrayRef
<raw_pwrite_stream
*> Out
) {
584 if (!this->determineTarget())
587 // We always run the verifier once on the merged module. If it has already
588 // been called in optimize(), this call will return early.
589 verifyMergedModuleOnce();
591 legacy::PassManager preCodeGenPasses
;
593 // If the bitcode files contain ARC code and were compiled with optimization,
594 // the ObjCARCContractPass must be run, so do it unconditionally here.
595 preCodeGenPasses
.add(createObjCARCContractPass());
596 preCodeGenPasses
.run(*MergedModule
);
598 // Re-externalize globals that may have been internalized to increase scope
600 restoreLinkageForExternals();
602 // Do code generation. We need to preserve the module in case the client calls
603 // writeMergedModules() after compilation, but we only need to allow this at
604 // parallelism level 1. This is achieved by having splitCodeGen return the
605 // original module at parallelism level 1 which we then assign back to
607 MergedModule
= splitCodeGen(std::move(MergedModule
), Out
, {},
608 [&]() { return createTargetMachine(); }, FileType
,
609 ShouldRestoreGlobalsLinkage
);
611 // If statistics were requested, save them to the specified file or
612 // print them out after codegen.
614 PrintStatisticsJSON(StatsFile
->os());
615 else if (AreStatisticsEnabled())
618 reportAndResetTimings();
620 finishOptimizationRemarks();
625 /// setCodeGenDebugOptions - Set codegen debugging options to aid in debugging
627 void LTOCodeGenerator::setCodeGenDebugOptions(StringRef Options
) {
628 for (std::pair
<StringRef
, StringRef
> o
= getToken(Options
); !o
.first
.empty();
629 o
= getToken(o
.second
))
630 CodegenOptions
.push_back(o
.first
);
633 void LTOCodeGenerator::parseCodeGenDebugOptions() {
634 // if options were requested, set them
635 if (!CodegenOptions
.empty()) {
636 // ParseCommandLineOptions() expects argv[0] to be program name.
637 std::vector
<const char *> CodegenArgv(1, "libLLVMLTO");
638 for (std::string
&Arg
: CodegenOptions
)
639 CodegenArgv
.push_back(Arg
.c_str());
640 cl::ParseCommandLineOptions(CodegenArgv
.size(), CodegenArgv
.data());
645 void LTOCodeGenerator::DiagnosticHandler(const DiagnosticInfo
&DI
) {
646 // Map the LLVM internal diagnostic severity to the LTO diagnostic severity.
647 lto_codegen_diagnostic_severity_t Severity
;
648 switch (DI
.getSeverity()) {
650 Severity
= LTO_DS_ERROR
;
653 Severity
= LTO_DS_WARNING
;
656 Severity
= LTO_DS_REMARK
;
659 Severity
= LTO_DS_NOTE
;
662 // Create the string that will be reported to the external diagnostic handler.
663 std::string MsgStorage
;
664 raw_string_ostream
Stream(MsgStorage
);
665 DiagnosticPrinterRawOStream
DP(Stream
);
669 // If this method has been called it means someone has set up an external
670 // diagnostic handler. Assert on that.
671 assert(DiagHandler
&& "Invalid diagnostic handler");
672 (*DiagHandler
)(Severity
, MsgStorage
.c_str(), DiagContext
);
676 struct LTODiagnosticHandler
: public DiagnosticHandler
{
677 LTOCodeGenerator
*CodeGenerator
;
678 LTODiagnosticHandler(LTOCodeGenerator
*CodeGenPtr
)
679 : CodeGenerator(CodeGenPtr
) {}
680 bool handleDiagnostics(const DiagnosticInfo
&DI
) override
{
681 CodeGenerator
->DiagnosticHandler(DI
);
688 LTOCodeGenerator::setDiagnosticHandler(lto_diagnostic_handler_t DiagHandler
,
690 this->DiagHandler
= DiagHandler
;
691 this->DiagContext
= Ctxt
;
693 return Context
.setDiagnosticHandler(nullptr);
694 // Register the LTOCodeGenerator stub in the LLVMContext to forward the
695 // diagnostic to the external DiagHandler.
696 Context
.setDiagnosticHandler(std::make_unique
<LTODiagnosticHandler
>(this),
701 class LTODiagnosticInfo
: public DiagnosticInfo
{
704 LTODiagnosticInfo(const Twine
&DiagMsg
, DiagnosticSeverity Severity
=DS_Error
)
705 : DiagnosticInfo(DK_Linker
, Severity
), Msg(DiagMsg
) {}
706 void print(DiagnosticPrinter
&DP
) const override
{ DP
<< Msg
; }
710 void LTOCodeGenerator::emitError(const std::string
&ErrMsg
) {
712 (*DiagHandler
)(LTO_DS_ERROR
, ErrMsg
.c_str(), DiagContext
);
714 Context
.diagnose(LTODiagnosticInfo(ErrMsg
));
717 void LTOCodeGenerator::emitWarning(const std::string
&ErrMsg
) {
719 (*DiagHandler
)(LTO_DS_WARNING
, ErrMsg
.c_str(), DiagContext
);
721 Context
.diagnose(LTODiagnosticInfo(ErrMsg
, DS_Warning
));