19#include "llvm/ADT/SmallSet.h"
20#include "llvm/ADT/StringExtras.h"
21#include "llvm/ADT/StringSwitch.h"
22#include "llvm/Analysis/AliasAnalysis.h"
23#include "llvm/Analysis/GlobalsModRef.h"
24#include "llvm/Analysis/TargetLibraryInfo.h"
25#include "llvm/Analysis/TargetTransformInfo.h"
26#include "llvm/Bitcode/BitcodeReader.h"
27#include "llvm/Bitcode/BitcodeWriter.h"
28#include "llvm/Bitcode/BitcodeWriterPass.h"
29#include "llvm/CodeGen/RegAllocRegistry.h"
30#include "llvm/CodeGen/SchedulerRegistry.h"
31#include "llvm/CodeGen/TargetSubtargetInfo.h"
32#include "llvm/Frontend/Driver/CodeGenOptions.h"
33#include "llvm/IR/DataLayout.h"
34#include "llvm/IR/DebugInfo.h"
35#include "llvm/IR/LegacyPassManager.h"
36#include "llvm/IR/Module.h"
37#include "llvm/IR/ModuleSummaryIndex.h"
38#include "llvm/IR/PassManager.h"
39#include "llvm/IR/Verifier.h"
40#include "llvm/IRPrinter/IRPrintingPasses.h"
41#include "llvm/LTO/LTOBackend.h"
42#include "llvm/MC/MCAsmInfo.h"
43#include "llvm/MC/TargetRegistry.h"
44#include "llvm/Object/OffloadBinary.h"
45#include "llvm/Passes/PassBuilder.h"
46#include "llvm/Passes/PassPlugin.h"
47#include "llvm/Passes/StandardInstrumentations.h"
48#include "llvm/ProfileData/InstrProfCorrelator.h"
49#include "llvm/Support/BuryPointer.h"
50#include "llvm/Support/CommandLine.h"
51#include "llvm/Support/MemoryBuffer.h"
52#include "llvm/Support/PrettyStackTrace.h"
53#include "llvm/Support/TimeProfiler.h"
54#include "llvm/Support/Timer.h"
55#include "llvm/Support/ToolOutputFile.h"
56#include "llvm/Support/VirtualFileSystem.h"
57#include "llvm/Support/raw_ostream.h"
58#include "llvm/Target/TargetMachine.h"
59#include "llvm/Target/TargetOptions.h"
60#include "llvm/TargetParser/SubtargetFeature.h"
61#include "llvm/TargetParser/Triple.h"
62#include "llvm/Transforms/HipStdPar/HipStdPar.h"
63#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
64#include "llvm/Transforms/IPO/LowerTypeTests.h"
65#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
66#include "llvm/Transforms/InstCombine/InstCombine.h"
67#include "llvm/Transforms/Instrumentation.h"
68#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
69#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
70#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
71#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
72#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
73#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
74#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
75#include "llvm/Transforms/Instrumentation/KCFI.h"
76#include "llvm/Transforms/Instrumentation/LowerAllowCheckPass.h"
77#include "llvm/Transforms/Instrumentation/MemProfiler.h"
78#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
79#include "llvm/Transforms/Instrumentation/NumericalStabilitySanitizer.h"
80#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
81#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
82#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
83#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
84#include "llvm/Transforms/ObjCARC.h"
85#include "llvm/Transforms/Scalar/EarlyCSE.h"
86#include "llvm/Transforms/Scalar/GVN.h"
87#include "llvm/Transforms/Scalar/JumpThreading.h"
88#include "llvm/Transforms/Utils/Debugify.h"
89#include "llvm/Transforms/Utils/ModuleUtils.h"
95#define HANDLE_EXTENSION(Ext) \
96 llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
97#include "llvm/Support/Extension.def"
104 "sanitizer-early-opt-ep", cl::Optional,
105 cl::desc(
"Insert sanitizers on OptimizerEarlyEP."));
110 "pgo-cold-func-opt", cl::init(PGOOptions::ColdFuncOpt::Default), cl::Hidden,
112 "Function attribute to apply to cold functions as determined by PGO"),
113 cl::values(clEnumValN(PGOOptions::ColdFuncOpt::Default,
"default",
114 "Default (no attribute)"),
115 clEnumValN(PGOOptions::ColdFuncOpt::OptSize,
"optsize",
116 "Mark cold functions with optsize."),
117 clEnumValN(PGOOptions::ColdFuncOpt::MinSize,
"minsize",
118 "Mark cold functions with minsize."),
119 clEnumValN(PGOOptions::ColdFuncOpt::OptNone,
"optnone",
120 "Mark cold functions with optnone.")));
128std::string getDefaultProfileGenName() {
130 ?
"default_%m.proflite"
131 :
"default_%m.profraw";
134class EmitAssemblyHelper {
140 llvm::Module *TheModule;
143 Timer CodeGenerationTime;
145 std::unique_ptr<raw_pwrite_stream> OS;
149 TargetIRAnalysis getTargetIRAnalysis()
const {
151 return TM->getTargetIRAnalysis();
153 return TargetIRAnalysis();
164 void CreateTargetMachine(
bool MustCreateTM);
169 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
170 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
172 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef
Path) {
174 auto F = std::make_unique<llvm::ToolOutputFile>(
Path, EC,
175 llvm::sys::fs::OF_None);
177 Diags.
Report(diag::err_fe_unable_to_open_output) <<
Path << EC.message();
183 void RunOptimizationPipeline(
184 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
185 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC);
187 std::unique_ptr<raw_pwrite_stream> &OS,
188 std::unique_ptr<llvm::ToolOutputFile> &DwoOS);
195 bool shouldEmitRegularLTOSummary()
const {
196 return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
197 TargetTriple.getVendor() != llvm::Triple::Apple;
203 bool shouldEmitUnifiedLTOModueFlag()
const {
204 return CodeGenOpts.UnifiedLTO &&
205 (CodeGenOpts.PrepareForThinLTO || shouldEmitRegularLTOSummary());
215 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
216 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
VFS(
std::move(
VFS)),
217 CodeGenerationTime(
"codegen",
"Code Generation Time"),
218 TargetTriple(TheModule->getTargetTriple()) {}
220 ~EmitAssemblyHelper() {
221 if (CodeGenOpts.DisableFree)
222 BuryPointer(std::move(TM));
225 std::unique_ptr<TargetMachine> TM;
233static SanitizerCoverageOptions
235 SanitizerCoverageOptions Opts;
237 static_cast<SanitizerCoverageOptions::Type
>(CGOpts.SanitizeCoverageType);
238 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
239 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
240 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
241 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
242 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
243 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
244 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
245 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
246 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
247 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
248 Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
249 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
250 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
251 Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
252 Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
253 Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
257static SanitizerBinaryMetadataOptions
259 SanitizerBinaryMetadataOptions Opts;
260 Opts.Covered = CGOpts.SanitizeBinaryMetadataCovered;
261 Opts.Atomics = CGOpts.SanitizeBinaryMetadataAtomics;
262 Opts.UAR = CGOpts.SanitizeBinaryMetadataUAR;
271 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
273 switch (
T.getObjectFormat()) {
278 return !CGOpts.DisableIntegratedAS;
280 llvm::report_fatal_error(
"ASan not implemented for GOFF");
282 llvm::report_fatal_error(
"ASan not implemented for XCOFF.");
284 case Triple::DXContainer:
286 case Triple::UnknownObjectFormat:
292static std::optional<llvm::CodeModel::Model>
294 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
295 .Case(
"tiny", llvm::CodeModel::Tiny)
296 .Case(
"small", llvm::CodeModel::Small)
297 .Case(
"kernel", llvm::CodeModel::Kernel)
298 .Case(
"medium", llvm::CodeModel::Medium)
299 .Case(
"large", llvm::CodeModel::Large)
300 .Case(
"default", ~1u)
302 assert(CodeModel != ~0u &&
"invalid code model!");
303 if (CodeModel == ~1u)
305 return static_cast<llvm::CodeModel::Model
>(CodeModel);
310 return CodeGenFileType::ObjectFile;
312 return CodeGenFileType::Null;
315 return CodeGenFileType::AssemblyFile;
325 llvm::TargetOptions &Options,
330 switch (LangOpts.getThreadModel()) {
331 case LangOptions::ThreadModelKind::POSIX:
332 Options.ThreadModel = llvm::ThreadModel::POSIX;
334 case LangOptions::ThreadModelKind::Single:
335 Options.ThreadModel = llvm::ThreadModel::Single;
340 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
342 "Invalid Floating Point ABI!");
343 Options.FloatABIType =
344 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
345 .Case(
"soft", llvm::FloatABI::Soft)
346 .Case(
"softfp", llvm::FloatABI::Soft)
347 .Case(
"hard", llvm::FloatABI::Hard)
348 .Default(llvm::FloatABI::Default);
351 switch (LangOpts.getDefaultFPContractMode()) {
352 case LangOptions::FPM_Off:
355 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
357 case LangOptions::FPM_On:
358 case LangOptions::FPM_FastHonorPragmas:
359 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
361 case LangOptions::FPM_Fast:
362 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
366 Options.BinutilsVersion =
367 llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.
BinutilsVersion);
368 Options.UseInitArray = CodeGenOpts.UseInitArray;
369 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
375 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
377 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
379 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
381 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
383 Options.NoInfsFPMath = LangOpts.NoHonorInfs;
384 Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
385 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
386 Options.UnsafeFPMath = LangOpts.AllowFPReassoc && LangOpts.AllowRecip &&
387 LangOpts.NoSignedZero && LangOpts.ApproxFunc &&
388 (LangOpts.getDefaultFPContractMode() ==
389 LangOptions::FPModeKind::FPM_Fast ||
390 LangOpts.getDefaultFPContractMode() ==
391 LangOptions::FPModeKind::FPM_FastHonorPragmas);
392 Options.ApproxFuncFPMath = LangOpts.ApproxFunc;
394 Options.BBAddrMap = CodeGenOpts.BBAddrMap;
396 llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.
BBSections)
397 .Case(
"all", llvm::BasicBlockSection::All)
398 .Case(
"labels", llvm::BasicBlockSection::Labels)
399 .StartsWith(
"list=", llvm::BasicBlockSection::List)
400 .Case(
"none", llvm::BasicBlockSection::None)
401 .Default(llvm::BasicBlockSection::None);
403 if (Options.BBSections == llvm::BasicBlockSection::List) {
404 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
405 MemoryBuffer::getFile(CodeGenOpts.
BBSections.substr(5));
407 Diags.
Report(diag::err_fe_unable_to_load_basic_block_sections_file)
408 << MBOrErr.getError().message();
411 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
414 Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
415 Options.FunctionSections = CodeGenOpts.FunctionSections;
416 Options.DataSections = CodeGenOpts.DataSections;
417 Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
418 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
419 Options.UniqueBasicBlockSectionNames =
420 CodeGenOpts.UniqueBasicBlockSectionNames;
421 Options.SeparateNamedSections = CodeGenOpts.SeparateNamedSections;
422 Options.TLSSize = CodeGenOpts.TLSSize;
423 Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
424 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
425 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
426 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
428 Options.EmitAddrsig = CodeGenOpts.Addrsig;
429 Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
430 Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
431 Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
432 Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
433 Options.LoopAlignment = CodeGenOpts.LoopAlignment;
434 Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
436 Options.Hotpatch = CodeGenOpts.HotPatch;
437 Options.JMCInstrument = CodeGenOpts.JMCInstrument;
438 Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
440 switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
441 case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
442 Options.SwiftAsyncFramePointer =
443 SwiftAsyncFramePointerMode::DeploymentBased;
446 case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
447 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
450 case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
451 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
456 Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
457 Options.MCOptions.EmitCompactUnwindNonCanonical =
458 CodeGenOpts.EmitCompactUnwindNonCanonical;
459 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
460 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
461 Options.MCOptions.MCUseDwarfDirectory =
462 CodeGenOpts.NoDwarfDirectoryAsm
463 ? llvm::MCTargetOptions::DisableDwarfDirectory
464 : llvm::MCTargetOptions::EnableDwarfDirectory;
465 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
466 Options.MCOptions.MCIncrementalLinkerCompatible =
467 CodeGenOpts.IncrementalLinkerCompatible;
468 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
469 Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
470 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
471 Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
472 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
473 Options.MCOptions.Crel = CodeGenOpts.Crel;
474 Options.MCOptions.X86RelaxRelocations = CodeGenOpts.X86RelaxRelocations;
475 Options.MCOptions.CompressDebugSections =
476 CodeGenOpts.getCompressDebugSections();
477 Options.MCOptions.ABIName = TargetOpts.
ABI;
479 if (!Entry.IsFramework &&
480 (Entry.Group == frontend::IncludeDirGroup::Quoted ||
481 Entry.Group == frontend::IncludeDirGroup::Angled ||
482 Entry.Group == frontend::IncludeDirGroup::System))
483 Options.MCOptions.IASSearchPaths.push_back(
484 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
485 Options.MCOptions.Argv0 = CodeGenOpts.
Argv0;
488 Options.MCOptions.PPCUseFullRegisterNames =
489 CodeGenOpts.PPCUseFullRegisterNames;
490 Options.MisExpect = CodeGenOpts.MisExpect;
495static std::optional<GCOVOptions>
506 Options.NoRedZone = CodeGenOpts.DisableRedZone;
509 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
513static std::optional<InstrProfOptions>
518 InstrProfOptions Options;
519 Options.NoRedZone = CodeGenOpts.DisableRedZone;
521 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
527 BackendArgs.push_back(
"clang");
529 BackendArgs.push_back(
"-debug-pass");
530 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
533 BackendArgs.push_back(
"-limit-float-precision");
539 if (BackendArgs.size() == 1)
541 BackendArgs.push_back(
nullptr);
545 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
549void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
552 std::string Triple = TheModule->getTargetTriple();
553 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
556 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
560 std::optional<llvm::CodeModel::Model> CM =
getCodeModel(CodeGenOpts);
561 std::string FeaturesStr =
564 std::optional<CodeGenOptLevel> OptLevelOrNone =
565 CodeGenOpt::getLevel(CodeGenOpts.OptimizationLevel);
566 assert(OptLevelOrNone &&
"Invalid optimization level!");
567 CodeGenOptLevel OptLevel = *OptLevelOrNone;
569 llvm::TargetOptions Options;
573 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
574 Options, RM, CM, OptLevel));
578bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
580 raw_pwrite_stream &OS,
581 raw_pwrite_stream *DwoOS) {
583 std::unique_ptr<TargetLibraryInfoImpl> TLII(
584 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
585 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
591 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
592 !CodeGenOpts.VerifyModule)) {
593 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
601 switch (Opts.OptimizationLevel) {
603 llvm_unreachable(
"Invalid optimization level!");
606 return OptimizationLevel::O0;
609 return OptimizationLevel::O1;
612 switch (Opts.OptimizeSize) {
614 llvm_unreachable(
"Invalid optimization level for size!");
617 return OptimizationLevel::O2;
620 return OptimizationLevel::Os;
623 return OptimizationLevel::Oz;
627 return OptimizationLevel::O3;
634 if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
635 TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
639 PB.registerOptimizerLastEPCallback(
640 [&](ModulePassManager &MPM, OptimizationLevel Level) {
641 if (Level == OptimizationLevel::O0 &&
643 MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass()));
648 PB.registerPeepholeEPCallback(
649 [&](FunctionPassManager &FPM, OptimizationLevel Level) {
650 if (Level != OptimizationLevel::O0 &&
652 FPM.addPass(KCFIPass());
659 auto SanitizersCallback = [&](ModulePassManager &MPM,
660 OptimizationLevel Level) {
663 MPM.addPass(SanitizerCoveragePass(
669 MPM.addPass(SanitizerBinaryMetadataPass(
674 auto MSanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
676 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
679 MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
680 CodeGenOpts.SanitizeMemoryParamRetval);
681 MPM.addPass(MemorySanitizerPass(options));
682 if (Level != OptimizationLevel::O0) {
687 MPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
688 FunctionPassManager FPM;
689 FPM.addPass(EarlyCSEPass(
true ));
690 FPM.addPass(InstCombinePass());
691 FPM.addPass(JumpThreadingPass());
692 FPM.addPass(GVNPass());
693 FPM.addPass(InstCombinePass());
694 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
698 MSanPass(SanitizerKind::Memory,
false);
699 MSanPass(SanitizerKind::KernelMemory,
true);
701 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
702 MPM.addPass(ModuleThreadSanitizerPass());
703 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
706 if (LangOpts.
Sanitize.
has(SanitizerKind::NumericalStability))
707 MPM.addPass(NumericalStabilitySanitizerPass());
709 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
712 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
713 llvm::AsanDtorKind DestructorKind =
714 CodeGenOpts.getSanitizeAddressDtor();
715 AddressSanitizerOptions Opts;
716 Opts.CompileKernel = CompileKernel;
718 Opts.UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
719 Opts.UseAfterReturn = CodeGenOpts.getSanitizeAddressUseAfterReturn();
720 MPM.addPass(AddressSanitizerPass(Opts, UseGlobalGC, UseOdrIndicator,
724 ASanPass(SanitizerKind::Address,
false);
725 ASanPass(SanitizerKind::KernelAddress,
true);
727 auto HWASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
730 MPM.addPass(HWAddressSanitizerPass(
731 {CompileKernel, Recover,
732 CodeGenOpts.OptimizationLevel == 0}));
735 HWASanPass(SanitizerKind::HWAddress,
false);
736 HWASanPass(SanitizerKind::KernelHWAddress,
true);
738 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
743 PB.registerOptimizerEarlyEPCallback(
744 [SanitizersCallback](ModulePassManager &MPM, OptimizationLevel Level) {
745 ModulePassManager NewMPM;
746 SanitizersCallback(NewMPM, Level);
747 if (!NewMPM.isEmpty()) {
749 NewMPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
750 MPM.addPass(std::move(NewMPM));
755 PB.registerOptimizerLastEPCallback(SanitizersCallback);
758 if (LowerAllowCheckPass::IsRequested()) {
762 PB.registerScalarOptimizerLateEPCallback(
763 [](FunctionPassManager &FPM, OptimizationLevel Level) {
764 FPM.addPass(LowerAllowCheckPass());
769void EmitAssemblyHelper::RunOptimizationPipeline(
770 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
771 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC) {
772 std::optional<PGOOptions> PGOOpt;
781 CodeGenOpts.DebugInfoForProfiling,
782 false, CodeGenOpts.AtomicProfileUpdate);
786 : PGOOptions::NoCSAction;
791 CodeGenOpts.DebugInfoForProfiling);
798 CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
802 PGOOptions::NoAction, PGOOptions::NoCSAction,
804 else if (CodeGenOpts.PseudoProbeForProfiling)
807 PGOOptions(
"",
"",
"",
"",
nullptr,
808 PGOOptions::NoAction, PGOOptions::NoCSAction,
810 else if (CodeGenOpts.DebugInfoForProfiling)
812 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
813 PGOOptions::NoAction, PGOOptions::NoCSAction,
819 "Cannot have both CSProfileUse pass and CSProfileGen pass at "
822 assert(PGOOpt->Action != PGOOptions::IRInstr &&
823 PGOOpt->Action != PGOOptions::SampleUse &&
824 "Cannot run CSProfileGen pass with ProfileGen or SampleUse "
827 ? getDefaultProfileGenName()
828 : CodeGenOpts.InstrProfileOutput;
829 PGOOpt->CSAction = PGOOptions::CSIRInstr;
831 PGOOpt = PGOOptions(
"",
833 ? getDefaultProfileGenName()
836 PGOOptions::NoAction, PGOOptions::CSIRInstr,
840 TM->setPGOOption(PGOOpt);
842 PipelineTuningOptions PTO;
843 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
846 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
847 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
848 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
849 PTO.MergeFunctions = CodeGenOpts.MergeFunctions;
852 PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
853 PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO;
855 LoopAnalysisManager LAM;
856 FunctionAnalysisManager FAM;
857 CGSCCAnalysisManager CGAM;
858 ModuleAnalysisManager MAM;
860 bool DebugPassStructure = CodeGenOpts.
DebugPass ==
"Structure";
861 PassInstrumentationCallbacks PIC;
862 PrintPassOptions PrintPassOpts;
863 PrintPassOpts.Indent = DebugPassStructure;
864 PrintPassOpts.SkipAnalyses = DebugPassStructure;
865 StandardInstrumentations SI(
866 TheModule->getContext(),
867 (CodeGenOpts.DebugPassManager || DebugPassStructure),
868 CodeGenOpts.VerifyEach, PrintPassOpts);
869 SI.registerCallbacks(PIC, &MAM);
870 PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
873 switch (CodeGenOpts.getAssignmentTrackingMode()) {
874 case CodeGenOptions::AssignmentTrackingOpts::Forced:
875 PB.registerPipelineStartEPCallback(
876 [&](ModulePassManager &MPM, OptimizationLevel Level) {
877 MPM.addPass(AssignmentTrackingPass());
880 case CodeGenOptions::AssignmentTrackingOpts::Enabled:
883 if (!CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.PrepareForLTO &&
884 CodeGenOpts.getDebuggerTuning() != llvm::DebuggerKind::LLDB) {
885 PB.registerPipelineStartEPCallback(
886 [&](ModulePassManager &MPM, OptimizationLevel Level) {
888 if (Level != OptimizationLevel::O0)
889 MPM.addPass(AssignmentTrackingPass());
893 case CodeGenOptions::AssignmentTrackingOpts::Disabled:
898 DebugifyEachInstrumentation Debugify;
899 DebugInfoPerPass DebugInfoBeforePass;
900 if (CodeGenOpts.EnableDIPreservationVerify) {
901 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
902 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
905 Debugify.setOrigDIVerifyBugsReportFilePath(
907 Debugify.registerCallbacks(PIC, MAM);
911 auto PassPlugin = PassPlugin::Load(PluginFN);
913 PassPlugin->registerPassBuilderCallbacks(PB);
915 Diags.
Report(diag::err_fe_unable_to_load_plugin)
916 << PluginFN <<
toString(PassPlugin.takeError());
921#define HANDLE_EXTENSION(Ext) \
922 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
923#include "llvm/Support/Extension.def"
927 std::unique_ptr<TargetLibraryInfoImpl> TLII(
928 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
929 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
932 PB.registerModuleAnalyses(MAM);
933 PB.registerCGSCCAnalyses(CGAM);
934 PB.registerFunctionAnalyses(FAM);
935 PB.registerLoopAnalyses(LAM);
936 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
938 ModulePassManager MPM;
940 if (CodeGenOpts.VerifyModule)
941 MPM.addPass(VerifierPass());
943 if (!CodeGenOpts.DisableLLVMPasses) {
948 const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
949 const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;
951 if (LangOpts.ObjCAutoRefCount) {
952 PB.registerPipelineStartEPCallback(
953 [](ModulePassManager &MPM, OptimizationLevel Level) {
954 if (Level != OptimizationLevel::O0)
956 createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
958 PB.registerPipelineEarlySimplificationEPCallback(
959 [](ModulePassManager &MPM, OptimizationLevel Level) {
960 if (Level != OptimizationLevel::O0)
961 MPM.addPass(ObjCARCAPElimPass());
963 PB.registerScalarOptimizerLateEPCallback(
964 [](FunctionPassManager &FPM, OptimizationLevel Level) {
965 if (Level != OptimizationLevel::O0)
966 FPM.addPass(ObjCARCOptPass());
976 if (IsThinLTOPostLink)
977 PB.registerPipelineStartEPCallback(
978 [](ModulePassManager &MPM, OptimizationLevel Level) {
979 MPM.addPass(LowerTypeTestsPass(
nullptr,
986 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
987 PB.registerScalarOptimizerLateEPCallback(
988 [](FunctionPassManager &FPM, OptimizationLevel Level) {
989 FPM.addPass(BoundsCheckingPass());
994 if (!IsThinLTOPostLink) {
999 if (std::optional<GCOVOptions> Options =
1001 PB.registerPipelineStartEPCallback(
1002 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1003 MPM.addPass(GCOVProfilerPass(*Options));
1005 if (std::optional<InstrProfOptions> Options =
1007 PB.registerPipelineStartEPCallback(
1008 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1009 MPM.addPass(InstrProfilingLoweringPass(*Options,
false));
1015 PB.registerOptimizerLastEPCallback(
1016 [](ModulePassManager &MPM, OptimizationLevel Level) {
1017 MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
1018 MPM.addPass(ModuleMemProfilerPass());
1022 if (CodeGenOpts.FatLTO) {
1023 MPM.addPass(PB.buildFatLTODefaultPipeline(
1024 Level, PrepareForThinLTO,
1025 PrepareForThinLTO || shouldEmitRegularLTOSummary()));
1026 }
else if (PrepareForThinLTO) {
1027 MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
1028 }
else if (PrepareForLTO) {
1029 MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(Level));
1031 MPM.addPass(PB.buildPerModuleDefaultPipeline(Level));
1036 if (CodeGenOpts.LinkBitcodePostopt)
1045 MPM.addPass(VerifierPass());
1048 CodeGenOpts.FatLTO) {
1049 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1050 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1051 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1052 CodeGenOpts.EnableSplitLTOUnit);
1059 MPM.addPass(ThinLTOBitcodeWriterPass(
1060 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
1062 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1068 bool EmitLTOSummary = shouldEmitRegularLTOSummary();
1069 if (EmitLTOSummary) {
1070 if (!TheModule->getModuleFlag(
"ThinLTO") && !CodeGenOpts.UnifiedLTO)
1071 TheModule->addModuleFlag(llvm::Module::Error,
"ThinLTO",
uint32_t(0));
1072 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1073 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1077 MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
1080 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1085 if (shouldEmitUnifiedLTOModueFlag())
1086 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO",
uint32_t(1));
1092 MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
1093 auto PassName = PIC.getPassNameForClassName(ClassName);
1094 return PassName.empty() ? ClassName : PassName;
1100 if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1101 LangOpts.HIPStdParInterposeAlloc)
1102 MPM.addPass(HipStdParAllocationInterpositionPass());
1106 PrettyStackTraceString CrashInfo(
"Optimizer");
1107 llvm::TimeTraceScope TimeScope(
"Optimizer");
1108 MPM.run(*TheModule, MAM);
1112void EmitAssemblyHelper::RunCodegenPipeline(
1113 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
1114 std::unique_ptr<llvm::ToolOutputFile> &DwoOS) {
1118 legacy::PassManager CodeGenPasses;
1126 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1132 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1133 DwoOS ? &DwoOS->os() :
nullptr))
1149 PrettyStackTraceString CrashInfo(
"Code generation");
1150 llvm::TimeTraceScope TimeScope(
"CodeGenPasses");
1151 CodeGenPasses.run(*TheModule);
1156 std::unique_ptr<raw_pwrite_stream> OS,
1158 TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime :
nullptr);
1162 CreateTargetMachine(RequiresCodeGen);
1164 if (RequiresCodeGen && !TM)
1167 TheModule->setDataLayout(TM->createDataLayout());
1170 cl::PrintOptionValues();
1172 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1173 RunOptimizationPipeline(Action, OS, ThinLinkOS, BC);
1174 RunCodegenPipeline(Action, OS, DwoOS);
1186 const LangOptions &LOpts, std::unique_ptr<raw_pwrite_stream> OS,
1187 std::string SampleProfile, std::string ProfileRemapping,
1189 DenseMap<StringRef, DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1190 ModuleToDefinedGVSummaries;
1191 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1198 FunctionImporter::ImportMapTy ImportList;
1199 if (!lto::initImportList(*M, *CombinedIndex, ImportList))
1202 auto AddStream = [&](
size_t Task,
const Twine &ModuleName) {
1203 return std::make_unique<CachedFileStream>(std::move(OS),
1210 handleAllErrors(std::move(
E), [&](ErrorInfoBase &EIB) {
1211 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1216 Conf.CPU = TOpts.
CPU;
1220 std::optional<CodeGenOptLevel> OptLevelOrNone =
1221 CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
1222 assert(OptLevelOrNone &&
"Invalid optimization level!");
1223 Conf.CGOptLevel = *OptLevelOrNone;
1224 Conf.OptLevel = CGOpts.OptimizationLevel;
1226 Conf.SampleProfile = std::move(SampleProfile);
1227 Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
1230 Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
1231 Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
1232 Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1235 Conf.PTO.CallGraphProfile = !CGOpts.DisableIntegratedAS;
1239 Conf.RunCSIRInstr =
true;
1242 Conf.RunCSIRInstr =
false;
1246 Conf.ProfileRemapping = std::move(ProfileRemapping);
1247 Conf.DebugPassManager = CGOpts.DebugPassManager;
1248 Conf.VerifyEach = CGOpts.VerifyEach;
1249 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1257 Conf.PreCodeGenModuleHook = [](
size_t Task,
const llvm::Module &Mod) {
1262 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1263 M->print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1268 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1269 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1278 thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1279 ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
1281 handleAllErrors(std::move(
E), [&](ErrorInfoBase &EIB) {
1282 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1290 const LangOptions &LOpts, StringRef TDesc, llvm::Module *M,
1294 llvm::TimeTraceScope TimeScope(
"Backend");
1296 std::unique_ptr<llvm::Module> EmptyModule;
1301 std::unique_ptr<ModuleSummaryIndex> CombinedIndex;
1302 if (Error
E = llvm::getModuleSummaryIndexForFile(
1305 .moveInto(CombinedIndex)) {
1306 logAllUnhandledErrors(std::move(
E), errs(),
1307 "Error loading index file '" +
1315 if (CombinedIndex) {
1316 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1328 EmptyModule = std::make_unique<llvm::Module>(
"empty", M->getContext());
1329 EmptyModule->setTargetTriple(M->getTargetTriple());
1330 M = EmptyModule.get();
1334 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M, VFS);
1335 AsmHelper.EmitAssembly(Action, std::move(OS), BC);
1340 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1341 if (DLDesc != TDesc) {
1344 "expected target description '%1'");
1345 Diags.
Report(DiagID) << DLDesc << TDesc;
1353 llvm::MemoryBufferRef Buf) {
1356 llvm::embedBitcodeInModule(
1368 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1369 llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1370 if (ObjectOrErr.getError()) {
1372 "could not open '%0' for embedding");
1373 Diags.
Report(DiagID) << OffloadObject;
1377 llvm::embedBufferInModule(*M, **ObjectOrErr,
".llvm.offloading",
1378 Align(object::OffloadBinary::getAlignment()));
static bool actionRequiresCodeGen(BackendAction Action)
static void addSanitizers(const Triple &TargetTriple, const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts, PassBuilder &PB)
static std::optional< llvm::CodeModel::Model > getCodeModel(const CodeGenOptions &CodeGenOpts)
static SanitizerBinaryMetadataOptions getSanitizerBinaryMetadataOptions(const CodeGenOptions &CGOpts)
static std::optional< GCOVOptions > getGCOVOptions(const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts)
static bool initTargetOptions(DiagnosticsEngine &Diags, llvm::TargetOptions &Options, const CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, const LangOptions &LangOpts, const HeaderSearchOptions &HSOpts)
static void addKCFIPass(const Triple &TargetTriple, const LangOptions &LangOpts, PassBuilder &PB)
static void runThinLTOBackend(DiagnosticsEngine &Diags, ModuleSummaryIndex *CombinedIndex, llvm::Module *M, const HeaderSearchOptions &HeaderOpts, const CodeGenOptions &CGOpts, const clang::TargetOptions &TOpts, const LangOptions &LOpts, std::unique_ptr< raw_pwrite_stream > OS, std::string SampleProfile, std::string ProfileRemapping, BackendAction Action)
static SanitizerCoverageOptions getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts)
static OptimizationLevel mapToLevel(const CodeGenOptions &Opts)
static std::optional< InstrProfOptions > getInstrProfOptions(const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts)
static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts)
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts)
static CodeGenFileType getCodeGenFileType(BackendAction Action)
Defines the Diagnostic-related interfaces.
Defines the clang::LangOptions interface.
This file provides a pass to link in Modules from a provided BackendConsumer.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
Defines the clang::TargetOptions class.
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
std::string OptRecordFile
The name of the file to which the backend should save YAML optimization records.
std::string InstrProfileOutput
Name of the profile file to use as output for -fprofile-instr-generate, -fprofile-generate,...
std::string BinutilsVersion
bool hasProfileIRUse() const
Check if IR level profile use is on.
char CoverageVersion[4]
The version string to put into coverage files.
std::string FloatABI
The ABI to use for passing floating point arguments.
std::string ThinLinkBitcodeFile
Name of a file that can optionally be written with minimized bitcode to be used as input for the Thin...
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
std::string DebugPass
Enable additional debugging information.
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
std::string CoverageNotesFile
The filename with path we use for coverage notes files.
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
uint64_t LargeDataThreshold
The code model-specific large data threshold to use (-mlarge-data-threshold).
std::string MemoryProfileOutput
Name of the profile file to use as output for with -fmemory-profile.
std::vector< std::function< void(llvm::PassBuilder &)> > PassBuilderCallbacks
List of pass builder callbacks.
std::string LimitFloatPrecision
The float precision limit to use, if non-empty.
std::string CodeModel
The code model to use (-mcmodel).
std::string CoverageDataFile
The filename with path we use for coverage data files.
std::vector< std::string > PassPlugins
List of dynamic shared object files to be loaded as pass plugins.
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
std::string StackUsageOutput
Name of the stack usage file (i.e., .su file) if user passes -fstack-usage.
std::string OptRecordPasses
The regex that filters the passes that should be saved to the optimization records.
std::vector< std::string > SanitizeCoverageAllowlistFiles
Path to allowlist file specifying which objects (files, functions) should exclusively be instrumented...
std::string SaveTempsFilePrefix
Prefix to use for -save-temps output.
std::vector< std::string > SanitizeCoverageIgnorelistFiles
Path to ignorelist file specifying which objects (files, functions) listed for instrumentation by san...
bool hasSanitizeCoverage() const
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
std::vector< std::string > SanitizeMetadataIgnorelistFiles
Path to ignorelist file specifying which objects (files, functions) listed for instrumentation by san...
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
std::string ProfileExcludeFiles
Regexes separated by a semi-colon to filter the files to not instrument.
std::string AsSecureLogFile
The name of a file to use with .secure_log_unique directives.
std::string ProfileRemappingFile
Name of the profile remapping file to apply to the profile data supplied by -fprofile-sample-use or -...
bool hasSanitizeBinaryMetadata() const
std::string ThinLTOIndexFile
Name of the function summary index file to use for ThinLTO function importing.
const char * Argv0
Executable and command-line used to create a given CompilerInvocation.
std::string SplitDwarfFile
The name for the split debug info file used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...
std::vector< uint8_t > CmdArgs
List of backend command-line options for -fembed-bitcode.
std::vector< std::string > CommandLineArgs
std::string MemoryProfileUsePath
Name of the profile file to use as input for -fmemory-profile-use.
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
std::vector< std::string > OffloadObjects
List of filenames passed in using the -fembed-offload-object option.
std::string ProfileFilterFiles
Regexes separated by a semi-colon to filter the files to instrument.
std::string ObjectFilenameForDebug
Output filename used in the COFF debug information.
std::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
std::string DIBugsReportFilePath
The file to use for dumping bug report by Debugify for original debug info.
Concrete class used by the front-end to report problems and issues.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
bool hasWasmExceptions() const
bool hasSjLjExceptions() const
SanitizerSet Sanitize
Set of enabled sanitizers.
bool hasDWARFExceptions() const
bool hasSEHExceptions() const
std::vector< std::string > NoSanitizeFiles
Paths to files specifying which objects (files, functions, variables) should not be instrumented.
Options for controlling the target.
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings starting...
std::string ABI
If given, the name of the target ABI to use.
std::string CPU
If given, the name of the target CPU to generate code for.
llvm::EABI EABIVersion
The EABI version to use.
Create and return a pass that links in Moduels from a provided BackendConsumer to a given primary Mod...
@ EmitAssembly
Emit a .s file.
The JSON file list parser is used to communicate input to InstallAPI.
void EmbedObject(llvm::Module *M, const CodeGenOptions &CGOpts, DiagnosticsEngine &Diags)
void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, const LangOptions &LOpts, StringRef TDesc, llvm::Module *M, BackendAction Action, llvm::IntrusiveRefCntPtr< llvm::vfs::FileSystem > VFS, std::unique_ptr< raw_pwrite_stream > OS, BackendConsumer *BC=nullptr)
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf)
@ Backend_EmitAssembly
Emit native assembly files.
@ Backend_EmitLL
Emit human-readable LLVM assembly.
@ Backend_EmitBC
Emit LLVM bitcode files.
@ Backend_EmitObj
Emit native object files.
@ Backend_EmitMCNull
Run CodeGen, but don't emit anything.
@ Backend_EmitNothing
Don't emit anything (benchmarking mode)
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
cl::opt< bool > PrintPipelinePasses
cl::opt< InstrProfCorrelator::ProfCorrelatorKind > ProfileCorrelate
static cl::opt< PGOOptions::ColdFuncOpt > ClPGOColdFuncAttr("pgo-cold-func-opt", cl::init(PGOOptions::ColdFuncOpt::Default), cl::Hidden, cl::desc("Function attribute to apply to cold functions as determined by PGO"), cl::values(clEnumValN(PGOOptions::ColdFuncOpt::Default, "default", "Default (no attribute)"), clEnumValN(PGOOptions::ColdFuncOpt::OptSize, "optsize", "Mark cold functions with optsize."), clEnumValN(PGOOptions::ColdFuncOpt::MinSize, "minsize", "Mark cold functions with minsize."), clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone", "Mark cold functions with optnone.")))
static cl::opt< bool > ClSanitizeOnOptimizerEarlyEP("sanitizer-early-opt-ep", cl::Optional, cl::desc("Insert sanitizers on OptimizerEarlyEP."))
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.