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/PGOInstrumentation.h"
80#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
81#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
82#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
83#include "llvm/Transforms/ObjCARC.h"
84#include "llvm/Transforms/Scalar/EarlyCSE.h"
85#include "llvm/Transforms/Scalar/GVN.h"
86#include "llvm/Transforms/Scalar/JumpThreading.h"
87#include "llvm/Transforms/Utils/Debugify.h"
88#include "llvm/Transforms/Utils/EntryExitInstrumenter.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.")));
126 "relink-builtin-bitcode-postop", cl::Optional,
127 cl::desc(
"Re-link builtin bitcodes after optimization."));
133std::string getDefaultProfileGenName() {
135 ?
"default_%m.proflite"
136 :
"default_%m.profraw";
139class EmitAssemblyHelper {
145 llvm::Module *TheModule;
148 Timer CodeGenerationTime;
150 std::unique_ptr<raw_pwrite_stream> OS;
154 TargetIRAnalysis getTargetIRAnalysis()
const {
156 return TM->getTargetIRAnalysis();
158 return TargetIRAnalysis();
169 void CreateTargetMachine(
bool MustCreateTM);
174 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
175 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
177 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
179 auto F = std::make_unique<llvm::ToolOutputFile>(Path, EC,
180 llvm::sys::fs::OF_None);
182 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
188 void RunOptimizationPipeline(
189 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
190 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC);
192 std::unique_ptr<raw_pwrite_stream> &OS,
193 std::unique_ptr<llvm::ToolOutputFile> &DwoOS);
200 bool shouldEmitRegularLTOSummary()
const {
201 return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
202 TargetTriple.getVendor() != llvm::Triple::Apple;
208 bool shouldEmitUnifiedLTOModueFlag()
const {
209 return CodeGenOpts.UnifiedLTO &&
210 (CodeGenOpts.PrepareForThinLTO || shouldEmitRegularLTOSummary());
220 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
221 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
VFS(
std::move(
VFS)),
222 CodeGenerationTime(
"codegen",
"Code Generation Time"),
223 TargetTriple(TheModule->getTargetTriple()) {}
225 ~EmitAssemblyHelper() {
226 if (CodeGenOpts.DisableFree)
227 BuryPointer(std::move(TM));
230 std::unique_ptr<TargetMachine> TM;
238static SanitizerCoverageOptions
240 SanitizerCoverageOptions Opts;
242 static_cast<SanitizerCoverageOptions::Type
>(CGOpts.SanitizeCoverageType);
243 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
244 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
245 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
246 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
247 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
248 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
249 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
250 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
251 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
252 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
253 Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
254 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
255 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
256 Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
257 Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
258 Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
262static SanitizerBinaryMetadataOptions
264 SanitizerBinaryMetadataOptions Opts;
265 Opts.Covered = CGOpts.SanitizeBinaryMetadataCovered;
266 Opts.Atomics = CGOpts.SanitizeBinaryMetadataAtomics;
267 Opts.UAR = CGOpts.SanitizeBinaryMetadataUAR;
276 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
278 switch (
T.getObjectFormat()) {
283 return !CGOpts.DisableIntegratedAS;
285 llvm::report_fatal_error(
"ASan not implemented for GOFF");
287 llvm::report_fatal_error(
"ASan not implemented for XCOFF.");
289 case Triple::DXContainer:
291 case Triple::UnknownObjectFormat:
297static std::optional<llvm::CodeModel::Model>
299 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
300 .Case(
"tiny", llvm::CodeModel::Tiny)
301 .Case(
"small", llvm::CodeModel::Small)
302 .Case(
"kernel", llvm::CodeModel::Kernel)
303 .Case(
"medium", llvm::CodeModel::Medium)
304 .Case(
"large", llvm::CodeModel::Large)
305 .Case(
"default", ~1u)
307 assert(CodeModel != ~0u &&
"invalid code model!");
308 if (CodeModel == ~1u)
310 return static_cast<llvm::CodeModel::Model
>(CodeModel);
315 return CodeGenFileType::ObjectFile;
317 return CodeGenFileType::Null;
320 return CodeGenFileType::AssemblyFile;
330 llvm::TargetOptions &Options,
335 switch (LangOpts.getThreadModel()) {
336 case LangOptions::ThreadModelKind::POSIX:
337 Options.ThreadModel = llvm::ThreadModel::POSIX;
339 case LangOptions::ThreadModelKind::Single:
340 Options.ThreadModel = llvm::ThreadModel::Single;
345 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
347 "Invalid Floating Point ABI!");
348 Options.FloatABIType =
349 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
350 .Case(
"soft", llvm::FloatABI::Soft)
351 .Case(
"softfp", llvm::FloatABI::Soft)
352 .Case(
"hard", llvm::FloatABI::Hard)
353 .Default(llvm::FloatABI::Default);
356 switch (LangOpts.getDefaultFPContractMode()) {
357 case LangOptions::FPM_Off:
360 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
362 case LangOptions::FPM_On:
363 case LangOptions::FPM_FastHonorPragmas:
364 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
366 case LangOptions::FPM_Fast:
367 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
371 Options.BinutilsVersion =
372 llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.
BinutilsVersion);
373 Options.UseInitArray = CodeGenOpts.UseInitArray;
374 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
380 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
382 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
384 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
386 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
388 Options.NoInfsFPMath = LangOpts.NoHonorInfs;
389 Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
390 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
391 Options.UnsafeFPMath = LangOpts.AllowFPReassoc && LangOpts.AllowRecip &&
392 LangOpts.NoSignedZero && LangOpts.ApproxFunc &&
393 (LangOpts.getDefaultFPContractMode() ==
394 LangOptions::FPModeKind::FPM_Fast ||
395 LangOpts.getDefaultFPContractMode() ==
396 LangOptions::FPModeKind::FPM_FastHonorPragmas);
397 Options.ApproxFuncFPMath = LangOpts.ApproxFunc;
399 Options.BBAddrMap = CodeGenOpts.BBAddrMap;
401 llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.
BBSections)
402 .Case(
"all", llvm::BasicBlockSection::All)
403 .Case(
"labels", llvm::BasicBlockSection::Labels)
404 .StartsWith(
"list=", llvm::BasicBlockSection::List)
405 .Case(
"none", llvm::BasicBlockSection::None)
406 .Default(llvm::BasicBlockSection::None);
408 if (Options.BBSections == llvm::BasicBlockSection::List) {
409 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
410 MemoryBuffer::getFile(CodeGenOpts.
BBSections.substr(5));
412 Diags.
Report(diag::err_fe_unable_to_load_basic_block_sections_file)
413 << MBOrErr.getError().message();
416 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
419 Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
420 Options.FunctionSections = CodeGenOpts.FunctionSections;
421 Options.DataSections = CodeGenOpts.DataSections;
422 Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
423 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
424 Options.UniqueBasicBlockSectionNames =
425 CodeGenOpts.UniqueBasicBlockSectionNames;
426 Options.TLSSize = CodeGenOpts.TLSSize;
427 Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
428 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
429 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
430 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
432 Options.EmitAddrsig = CodeGenOpts.Addrsig;
433 Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
434 Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
435 Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
436 Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
437 Options.LoopAlignment = CodeGenOpts.LoopAlignment;
438 Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
440 Options.Hotpatch = CodeGenOpts.HotPatch;
441 Options.JMCInstrument = CodeGenOpts.JMCInstrument;
442 Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
444 switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
445 case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
446 Options.SwiftAsyncFramePointer =
447 SwiftAsyncFramePointerMode::DeploymentBased;
450 case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
451 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
454 case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
455 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
460 Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
461 Options.MCOptions.EmitCompactUnwindNonCanonical =
462 CodeGenOpts.EmitCompactUnwindNonCanonical;
463 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
464 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
465 Options.MCOptions.MCUseDwarfDirectory =
466 CodeGenOpts.NoDwarfDirectoryAsm
467 ? llvm::MCTargetOptions::DisableDwarfDirectory
468 : llvm::MCTargetOptions::EnableDwarfDirectory;
469 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
470 Options.MCOptions.MCIncrementalLinkerCompatible =
471 CodeGenOpts.IncrementalLinkerCompatible;
472 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
473 Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
474 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
475 Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
476 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
477 Options.MCOptions.X86RelaxRelocations = CodeGenOpts.RelaxELFRelocations;
478 Options.MCOptions.CompressDebugSections =
479 CodeGenOpts.getCompressDebugSections();
480 Options.MCOptions.ABIName = TargetOpts.
ABI;
482 if (!Entry.IsFramework &&
483 (Entry.Group == frontend::IncludeDirGroup::Quoted ||
484 Entry.Group == frontend::IncludeDirGroup::Angled ||
485 Entry.Group == frontend::IncludeDirGroup::System))
486 Options.MCOptions.IASSearchPaths.push_back(
487 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
488 Options.MCOptions.Argv0 = CodeGenOpts.
Argv0;
491 Options.MCOptions.PPCUseFullRegisterNames =
492 CodeGenOpts.PPCUseFullRegisterNames;
493 Options.MisExpect = CodeGenOpts.MisExpect;
498static std::optional<GCOVOptions>
509 Options.NoRedZone = CodeGenOpts.DisableRedZone;
512 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
516static std::optional<InstrProfOptions>
521 InstrProfOptions Options;
522 Options.NoRedZone = CodeGenOpts.DisableRedZone;
524 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
530 BackendArgs.push_back(
"clang");
532 BackendArgs.push_back(
"-debug-pass");
533 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
536 BackendArgs.push_back(
"-limit-float-precision");
542 if (BackendArgs.size() == 1)
544 BackendArgs.push_back(
nullptr);
548 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
552void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
555 std::string Triple = TheModule->getTargetTriple();
556 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
559 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
563 std::optional<llvm::CodeModel::Model> CM =
getCodeModel(CodeGenOpts);
564 std::string FeaturesStr =
567 std::optional<CodeGenOptLevel> OptLevelOrNone =
568 CodeGenOpt::getLevel(CodeGenOpts.OptimizationLevel);
569 assert(OptLevelOrNone &&
"Invalid optimization level!");
570 CodeGenOptLevel OptLevel = *OptLevelOrNone;
572 llvm::TargetOptions Options;
576 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
577 Options, RM, CM, OptLevel));
581bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
583 raw_pwrite_stream &OS,
584 raw_pwrite_stream *DwoOS) {
586 std::unique_ptr<TargetLibraryInfoImpl> TLII(
587 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
588 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
597 if (CodeGenOpts.OptimizationLevel > 0)
598 CodeGenPasses.add(createObjCARCContractPass());
600 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
601 !CodeGenOpts.VerifyModule)) {
602 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
610 switch (Opts.OptimizationLevel) {
612 llvm_unreachable(
"Invalid optimization level!");
615 return OptimizationLevel::O0;
618 return OptimizationLevel::O1;
621 switch (Opts.OptimizeSize) {
623 llvm_unreachable(
"Invalid optimization level for size!");
626 return OptimizationLevel::O2;
629 return OptimizationLevel::Os;
632 return OptimizationLevel::Oz;
636 return OptimizationLevel::O3;
643 if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
644 TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
648 PB.registerOptimizerLastEPCallback(
649 [&](ModulePassManager &MPM, OptimizationLevel Level) {
650 if (Level == OptimizationLevel::O0 &&
652 MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass()));
657 PB.registerPeepholeEPCallback(
658 [&](FunctionPassManager &FPM, OptimizationLevel Level) {
659 if (Level != OptimizationLevel::O0 &&
661 FPM.addPass(KCFIPass());
668 auto SanitizersCallback = [&](ModulePassManager &MPM,
669 OptimizationLevel Level) {
672 MPM.addPass(SanitizerCoveragePass(
678 MPM.addPass(SanitizerBinaryMetadataPass(
683 auto MSanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
685 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
688 MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
689 CodeGenOpts.SanitizeMemoryParamRetval);
690 MPM.addPass(MemorySanitizerPass(options));
691 if (Level != OptimizationLevel::O0) {
696 MPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
697 FunctionPassManager FPM;
698 FPM.addPass(EarlyCSEPass(
true ));
699 FPM.addPass(InstCombinePass());
700 FPM.addPass(JumpThreadingPass());
701 FPM.addPass(GVNPass());
702 FPM.addPass(InstCombinePass());
703 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
707 MSanPass(SanitizerKind::Memory,
false);
708 MSanPass(SanitizerKind::KernelMemory,
true);
710 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
711 MPM.addPass(ModuleThreadSanitizerPass());
712 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
715 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
718 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
719 llvm::AsanDtorKind DestructorKind =
720 CodeGenOpts.getSanitizeAddressDtor();
721 AddressSanitizerOptions Opts;
722 Opts.CompileKernel = CompileKernel;
724 Opts.UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
725 Opts.UseAfterReturn = CodeGenOpts.getSanitizeAddressUseAfterReturn();
726 MPM.addPass(AddressSanitizerPass(Opts, UseGlobalGC, UseOdrIndicator,
730 ASanPass(SanitizerKind::Address,
false);
731 ASanPass(SanitizerKind::KernelAddress,
true);
733 auto HWASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
736 MPM.addPass(HWAddressSanitizerPass(
737 {CompileKernel, Recover,
738 CodeGenOpts.OptimizationLevel == 0}));
741 HWASanPass(SanitizerKind::HWAddress,
false);
742 HWASanPass(SanitizerKind::KernelHWAddress,
true);
744 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
749 PB.registerOptimizerEarlyEPCallback(
750 [SanitizersCallback](ModulePassManager &MPM, OptimizationLevel Level) {
751 ModulePassManager NewMPM;
752 SanitizersCallback(NewMPM, Level);
753 if (!NewMPM.isEmpty()) {
755 NewMPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
756 MPM.addPass(std::move(NewMPM));
761 PB.registerOptimizerLastEPCallback(SanitizersCallback);
764 if (LowerAllowCheckPass::IsRequested()) {
768 PB.registerScalarOptimizerLateEPCallback(
769 [](FunctionPassManager &FPM, OptimizationLevel Level) {
770 FPM.addPass(LowerAllowCheckPass());
775void EmitAssemblyHelper::RunOptimizationPipeline(
776 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
777 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC) {
778 std::optional<PGOOptions> PGOOpt;
787 CodeGenOpts.DebugInfoForProfiling,
788 false, CodeGenOpts.AtomicProfileUpdate);
792 : PGOOptions::NoCSAction;
797 CodeGenOpts.DebugInfoForProfiling);
804 CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
808 PGOOptions::NoAction, PGOOptions::NoCSAction,
810 else if (CodeGenOpts.PseudoProbeForProfiling)
813 PGOOptions(
"",
"",
"",
"",
nullptr,
814 PGOOptions::NoAction, PGOOptions::NoCSAction,
816 else if (CodeGenOpts.DebugInfoForProfiling)
818 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
819 PGOOptions::NoAction, PGOOptions::NoCSAction,
825 "Cannot have both CSProfileUse pass and CSProfileGen pass at "
828 assert(PGOOpt->Action != PGOOptions::IRInstr &&
829 PGOOpt->Action != PGOOptions::SampleUse &&
830 "Cannot run CSProfileGen pass with ProfileGen or SampleUse "
833 ? getDefaultProfileGenName()
834 : CodeGenOpts.InstrProfileOutput;
835 PGOOpt->CSAction = PGOOptions::CSIRInstr;
837 PGOOpt = PGOOptions(
"",
839 ? getDefaultProfileGenName()
842 PGOOptions::NoAction, PGOOptions::CSIRInstr,
846 TM->setPGOOption(PGOOpt);
848 PipelineTuningOptions PTO;
849 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
852 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
853 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
854 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
855 PTO.MergeFunctions = CodeGenOpts.MergeFunctions;
858 PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
859 PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO;
861 LoopAnalysisManager LAM;
862 FunctionAnalysisManager FAM;
863 CGSCCAnalysisManager CGAM;
864 ModuleAnalysisManager MAM;
866 bool DebugPassStructure = CodeGenOpts.
DebugPass ==
"Structure";
867 PassInstrumentationCallbacks PIC;
868 PrintPassOptions PrintPassOpts;
869 PrintPassOpts.Indent = DebugPassStructure;
870 PrintPassOpts.SkipAnalyses = DebugPassStructure;
871 StandardInstrumentations SI(
872 TheModule->getContext(),
873 (CodeGenOpts.DebugPassManager || DebugPassStructure),
874 CodeGenOpts.VerifyEach, PrintPassOpts);
875 SI.registerCallbacks(PIC, &MAM);
876 PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
879 switch (CodeGenOpts.getAssignmentTrackingMode()) {
880 case CodeGenOptions::AssignmentTrackingOpts::Forced:
881 PB.registerPipelineStartEPCallback(
882 [&](ModulePassManager &MPM, OptimizationLevel Level) {
883 MPM.addPass(AssignmentTrackingPass());
886 case CodeGenOptions::AssignmentTrackingOpts::Enabled:
889 if (!CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.PrepareForLTO &&
890 CodeGenOpts.getDebuggerTuning() != llvm::DebuggerKind::LLDB) {
891 PB.registerPipelineStartEPCallback(
892 [&](ModulePassManager &MPM, OptimizationLevel Level) {
894 if (Level != OptimizationLevel::O0)
895 MPM.addPass(AssignmentTrackingPass());
899 case CodeGenOptions::AssignmentTrackingOpts::Disabled:
904 DebugifyEachInstrumentation Debugify;
905 DebugInfoPerPass DebugInfoBeforePass;
906 if (CodeGenOpts.EnableDIPreservationVerify) {
907 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
908 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
911 Debugify.setOrigDIVerifyBugsReportFilePath(
913 Debugify.registerCallbacks(PIC, MAM);
917 auto PassPlugin = PassPlugin::Load(PluginFN);
919 PassPlugin->registerPassBuilderCallbacks(PB);
921 Diags.
Report(diag::err_fe_unable_to_load_plugin)
922 << PluginFN <<
toString(PassPlugin.takeError());
927#define HANDLE_EXTENSION(Ext) \
928 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
929#include "llvm/Support/Extension.def"
933 std::unique_ptr<TargetLibraryInfoImpl> TLII(
934 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
935 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
938 PB.registerModuleAnalyses(MAM);
939 PB.registerCGSCCAnalyses(CGAM);
940 PB.registerFunctionAnalyses(FAM);
941 PB.registerLoopAnalyses(LAM);
942 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
944 ModulePassManager MPM;
946 if (CodeGenOpts.VerifyModule)
947 MPM.addPass(VerifierPass());
949 if (!CodeGenOpts.DisableLLVMPasses) {
954 const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
955 const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;
957 if (LangOpts.ObjCAutoRefCount) {
958 PB.registerPipelineStartEPCallback(
959 [](ModulePassManager &MPM, OptimizationLevel Level) {
960 if (Level != OptimizationLevel::O0)
962 createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
964 PB.registerPipelineEarlySimplificationEPCallback(
965 [](ModulePassManager &MPM, OptimizationLevel Level) {
966 if (Level != OptimizationLevel::O0)
967 MPM.addPass(ObjCARCAPElimPass());
969 PB.registerScalarOptimizerLateEPCallback(
970 [](FunctionPassManager &FPM, OptimizationLevel Level) {
971 if (Level != OptimizationLevel::O0)
972 FPM.addPass(ObjCARCOptPass());
982 if (IsThinLTOPostLink)
983 PB.registerPipelineStartEPCallback(
984 [](ModulePassManager &MPM, OptimizationLevel Level) {
985 MPM.addPass(LowerTypeTestsPass(
nullptr,
990 if (CodeGenOpts.InstrumentFunctions ||
991 CodeGenOpts.InstrumentFunctionEntryBare ||
992 CodeGenOpts.InstrumentFunctionsAfterInlining ||
993 CodeGenOpts.InstrumentForProfiling) {
994 PB.registerPipelineStartEPCallback(
995 [](ModulePassManager &MPM, OptimizationLevel Level) {
996 MPM.addPass(createModuleToFunctionPassAdaptor(
997 EntryExitInstrumenterPass(
false)));
999 PB.registerOptimizerLastEPCallback(
1000 [](ModulePassManager &MPM, OptimizationLevel Level) {
1001 MPM.addPass(createModuleToFunctionPassAdaptor(
1002 EntryExitInstrumenterPass(
true)));
1008 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1009 PB.registerScalarOptimizerLateEPCallback(
1010 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1011 FPM.addPass(BoundsCheckingPass());
1016 if (!IsThinLTOPostLink) {
1021 if (std::optional<GCOVOptions> Options =
1023 PB.registerPipelineStartEPCallback(
1024 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1025 MPM.addPass(GCOVProfilerPass(*Options));
1027 if (std::optional<InstrProfOptions> Options =
1029 PB.registerPipelineStartEPCallback(
1030 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1031 MPM.addPass(InstrProfilingLoweringPass(*Options,
false));
1037 PB.registerOptimizerLastEPCallback(
1038 [](ModulePassManager &MPM, OptimizationLevel Level) {
1039 MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
1040 MPM.addPass(ModuleMemProfilerPass());
1044 if (CodeGenOpts.FatLTO) {
1045 MPM.addPass(PB.buildFatLTODefaultPipeline(
1046 Level, PrepareForThinLTO,
1047 PrepareForThinLTO || shouldEmitRegularLTOSummary()));
1048 }
else if (PrepareForThinLTO) {
1049 MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
1050 }
else if (PrepareForLTO) {
1051 MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(Level));
1053 MPM.addPass(PB.buildPerModuleDefaultPipeline(Level));
1070 MPM.addPass(VerifierPass());
1073 CodeGenOpts.FatLTO) {
1074 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1075 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1076 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1077 CodeGenOpts.EnableSplitLTOUnit);
1084 MPM.addPass(ThinLTOBitcodeWriterPass(
1085 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
1087 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1093 bool EmitLTOSummary = shouldEmitRegularLTOSummary();
1094 if (EmitLTOSummary) {
1095 if (!TheModule->getModuleFlag(
"ThinLTO") && !CodeGenOpts.UnifiedLTO)
1096 TheModule->addModuleFlag(llvm::Module::Error,
"ThinLTO", uint32_t(0));
1097 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1098 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1102 MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
1105 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1110 if (shouldEmitUnifiedLTOModueFlag())
1111 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO", uint32_t(1));
1117 MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
1118 auto PassName = PIC.getPassNameForClassName(ClassName);
1119 return PassName.empty() ? ClassName : PassName;
1125 if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1126 LangOpts.HIPStdParInterposeAlloc)
1127 MPM.addPass(HipStdParAllocationInterpositionPass());
1131 PrettyStackTraceString CrashInfo(
"Optimizer");
1132 llvm::TimeTraceScope TimeScope(
"Optimizer");
1133 MPM.run(*TheModule, MAM);
1137void EmitAssemblyHelper::RunCodegenPipeline(
1138 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
1139 std::unique_ptr<llvm::ToolOutputFile> &DwoOS) {
1143 legacy::PassManager CodeGenPasses;
1151 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1157 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1158 DwoOS ? &DwoOS->os() :
nullptr))
1174 PrettyStackTraceString CrashInfo(
"Code generation");
1175 llvm::TimeTraceScope TimeScope(
"CodeGenPasses");
1176 CodeGenPasses.run(*TheModule);
1181 std::unique_ptr<raw_pwrite_stream> OS,
1183 TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime :
nullptr);
1187 CreateTargetMachine(RequiresCodeGen);
1189 if (RequiresCodeGen && !TM)
1192 TheModule->setDataLayout(TM->createDataLayout());
1195 cl::PrintOptionValues();
1197 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1198 RunOptimizationPipeline(Action, OS, ThinLinkOS, BC);
1199 RunCodegenPipeline(Action, OS, DwoOS);
1211 const LangOptions &LOpts, std::unique_ptr<raw_pwrite_stream> OS,
1212 std::string SampleProfile, std::string ProfileRemapping,
1214 DenseMap<StringRef, DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1215 ModuleToDefinedGVSummaries;
1216 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1223 FunctionImporter::ImportMapTy ImportList;
1224 if (!lto::initImportList(*M, *CombinedIndex, ImportList))
1227 auto AddStream = [&](
size_t Task,
const Twine &ModuleName) {
1228 return std::make_unique<CachedFileStream>(std::move(OS),
1235 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1236 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1241 Conf.CPU = TOpts.
CPU;
1245 std::optional<CodeGenOptLevel> OptLevelOrNone =
1246 CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
1247 assert(OptLevelOrNone &&
"Invalid optimization level!");
1248 Conf.CGOptLevel = *OptLevelOrNone;
1249 Conf.OptLevel = CGOpts.OptimizationLevel;
1251 Conf.SampleProfile = std::move(SampleProfile);
1252 Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
1255 Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
1256 Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
1257 Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1260 Conf.PTO.CallGraphProfile = !CGOpts.DisableIntegratedAS;
1264 Conf.RunCSIRInstr =
true;
1267 Conf.RunCSIRInstr =
false;
1271 Conf.ProfileRemapping = std::move(ProfileRemapping);
1272 Conf.DebugPassManager = CGOpts.DebugPassManager;
1273 Conf.VerifyEach = CGOpts.VerifyEach;
1274 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1282 Conf.PreCodeGenModuleHook = [](
size_t Task,
const llvm::Module &Mod) {
1287 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1288 M->print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1293 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1294 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1303 thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1304 ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
1306 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1307 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1315 const LangOptions &LOpts, StringRef TDesc, llvm::Module *M,
1319 llvm::TimeTraceScope TimeScope(
"Backend");
1321 std::unique_ptr<llvm::Module> EmptyModule;
1326 std::unique_ptr<ModuleSummaryIndex> CombinedIndex;
1327 if (Error E = llvm::getModuleSummaryIndexForFile(
1330 .moveInto(CombinedIndex)) {
1331 logAllUnhandledErrors(std::move(E), errs(),
1332 "Error loading index file '" +
1340 if (CombinedIndex) {
1341 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1353 EmptyModule = std::make_unique<llvm::Module>(
"empty", M->getContext());
1354 EmptyModule->setTargetTriple(M->getTargetTriple());
1355 M = EmptyModule.get();
1359 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M, VFS);
1360 AsmHelper.EmitAssembly(Action, std::move(OS), BC);
1365 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1366 if (DLDesc != TDesc) {
1369 "expected target description '%1'");
1370 Diags.
Report(DiagID) << DLDesc << TDesc;
1378 llvm::MemoryBufferRef Buf) {
1381 llvm::embedBitcodeInModule(
1393 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1394 llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1395 if (ObjectOrErr.getError()) {
1397 "could not open '%0' for embedding");
1398 Diags.
Report(DiagID) << OffloadObject;
1402 llvm::embedBufferInModule(*M, **ObjectOrErr,
".llvm.offloading",
1403 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
cl::opt< bool > ClRelinkBuiltinBitcodePostop
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.