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/MemProfiler.h"
77#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
78#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
79#include "llvm/Transforms/Instrumentation/RemoveTrapsPass.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/Scalar/SimplifyCFG.h"
88#include "llvm/Transforms/Utils/Debugify.h"
89#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
90#include "llvm/Transforms/Utils/ModuleUtils.h"
96#define HANDLE_EXTENSION(Ext) \
97 llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
98#include "llvm/Support/Extension.def"
104 cl::desc(
"Insert remove-traps pass."),
109 "sanitizer-early-opt-ep", cl::Optional,
110 cl::desc(
"Insert sanitizers on OptimizerEarlyEP."), cl::init(
false));
116 "relink-builtin-bitcode-postop", cl::Optional,
117 cl::desc(
"Re-link builtin bitcodes after optimization."), cl::init(
false));
123std::string getDefaultProfileGenName() {
125 ?
"default_%m.proflite"
126 :
"default_%m.profraw";
129class EmitAssemblyHelper {
135 llvm::Module *TheModule;
138 Timer CodeGenerationTime;
140 std::unique_ptr<raw_pwrite_stream> OS;
144 TargetIRAnalysis getTargetIRAnalysis()
const {
146 return TM->getTargetIRAnalysis();
148 return TargetIRAnalysis();
159 void CreateTargetMachine(
bool MustCreateTM);
164 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
165 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
167 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
169 auto F = std::make_unique<llvm::ToolOutputFile>(Path, EC,
170 llvm::sys::fs::OF_None);
172 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
178 void RunOptimizationPipeline(
179 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
180 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC);
182 std::unique_ptr<raw_pwrite_stream> &OS,
183 std::unique_ptr<llvm::ToolOutputFile> &DwoOS);
190 bool shouldEmitRegularLTOSummary()
const {
191 return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
192 TargetTriple.getVendor() != llvm::Triple::Apple;
198 bool shouldEmitUnifiedLTOModueFlag()
const {
199 return CodeGenOpts.UnifiedLTO &&
200 (CodeGenOpts.PrepareForThinLTO || shouldEmitRegularLTOSummary());
210 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
211 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
VFS(
std::move(
VFS)),
212 CodeGenerationTime(
"codegen",
"Code Generation Time"),
213 TargetTriple(TheModule->getTargetTriple()) {}
215 ~EmitAssemblyHelper() {
216 if (CodeGenOpts.DisableFree)
217 BuryPointer(std::move(TM));
220 std::unique_ptr<TargetMachine> TM;
228static SanitizerCoverageOptions
230 SanitizerCoverageOptions Opts;
232 static_cast<SanitizerCoverageOptions::Type
>(CGOpts.SanitizeCoverageType);
233 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
234 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
235 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
236 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
237 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
238 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
239 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
240 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
241 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
242 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
243 Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
244 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
245 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
246 Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
247 Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
248 Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
252static SanitizerBinaryMetadataOptions
254 SanitizerBinaryMetadataOptions Opts;
255 Opts.Covered = CGOpts.SanitizeBinaryMetadataCovered;
256 Opts.Atomics = CGOpts.SanitizeBinaryMetadataAtomics;
257 Opts.UAR = CGOpts.SanitizeBinaryMetadataUAR;
266 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
268 switch (T.getObjectFormat()) {
273 return !CGOpts.DisableIntegratedAS;
275 llvm::report_fatal_error(
"ASan not implemented for GOFF");
277 llvm::report_fatal_error(
"ASan not implemented for XCOFF.");
279 case Triple::DXContainer:
281 case Triple::UnknownObjectFormat:
287static std::optional<llvm::CodeModel::Model>
289 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
290 .Case(
"tiny", llvm::CodeModel::Tiny)
291 .Case(
"small", llvm::CodeModel::Small)
292 .Case(
"kernel", llvm::CodeModel::Kernel)
293 .Case(
"medium", llvm::CodeModel::Medium)
294 .Case(
"large", llvm::CodeModel::Large)
295 .Case(
"default", ~1u)
297 assert(CodeModel != ~0u &&
"invalid code model!");
298 if (CodeModel == ~1u)
300 return static_cast<llvm::CodeModel::Model
>(CodeModel);
305 return CodeGenFileType::ObjectFile;
307 return CodeGenFileType::Null;
310 return CodeGenFileType::AssemblyFile;
320 llvm::TargetOptions &Options,
325 switch (LangOpts.getThreadModel()) {
326 case LangOptions::ThreadModelKind::POSIX:
327 Options.ThreadModel = llvm::ThreadModel::POSIX;
329 case LangOptions::ThreadModelKind::Single:
330 Options.ThreadModel = llvm::ThreadModel::Single;
335 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
337 "Invalid Floating Point ABI!");
338 Options.FloatABIType =
339 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
340 .Case(
"soft", llvm::FloatABI::Soft)
341 .Case(
"softfp", llvm::FloatABI::Soft)
342 .Case(
"hard", llvm::FloatABI::Hard)
343 .Default(llvm::FloatABI::Default);
346 switch (LangOpts.getDefaultFPContractMode()) {
347 case LangOptions::FPM_Off:
350 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
352 case LangOptions::FPM_On:
353 case LangOptions::FPM_FastHonorPragmas:
354 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
356 case LangOptions::FPM_Fast:
357 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
361 Options.BinutilsVersion =
362 llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.
BinutilsVersion);
363 Options.UseInitArray = CodeGenOpts.UseInitArray;
364 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
370 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
372 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
374 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
376 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
378 Options.NoInfsFPMath = LangOpts.NoHonorInfs;
379 Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
380 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
381 Options.UnsafeFPMath = LangOpts.AllowFPReassoc && LangOpts.AllowRecip &&
382 LangOpts.NoSignedZero && LangOpts.ApproxFunc &&
383 (LangOpts.getDefaultFPContractMode() ==
384 LangOptions::FPModeKind::FPM_Fast ||
385 LangOpts.getDefaultFPContractMode() ==
386 LangOptions::FPModeKind::FPM_FastHonorPragmas);
387 Options.ApproxFuncFPMath = LangOpts.ApproxFunc;
389 Options.BBAddrMap = CodeGenOpts.BBAddrMap;
391 llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.
BBSections)
392 .Case(
"all", llvm::BasicBlockSection::All)
393 .Case(
"labels", llvm::BasicBlockSection::Labels)
394 .StartsWith(
"list=", llvm::BasicBlockSection::List)
395 .Case(
"none", llvm::BasicBlockSection::None)
396 .Default(llvm::BasicBlockSection::None);
398 if (Options.BBSections == llvm::BasicBlockSection::List) {
399 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
400 MemoryBuffer::getFile(CodeGenOpts.
BBSections.substr(5));
402 Diags.
Report(diag::err_fe_unable_to_load_basic_block_sections_file)
403 << MBOrErr.getError().message();
406 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
409 Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
410 Options.FunctionSections = CodeGenOpts.FunctionSections;
411 Options.DataSections = CodeGenOpts.DataSections;
412 Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
413 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
414 Options.UniqueBasicBlockSectionNames =
415 CodeGenOpts.UniqueBasicBlockSectionNames;
416 Options.TLSSize = CodeGenOpts.TLSSize;
417 Options.EnableTLSDESC = CodeGenOpts.EnableTLSDESC;
418 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
419 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
420 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
422 Options.EmitAddrsig = CodeGenOpts.Addrsig;
423 Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
424 Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
425 Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
426 Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
427 Options.LoopAlignment = CodeGenOpts.LoopAlignment;
428 Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
430 Options.Hotpatch = CodeGenOpts.HotPatch;
431 Options.JMCInstrument = CodeGenOpts.JMCInstrument;
432 Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
434 switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
435 case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
436 Options.SwiftAsyncFramePointer =
437 SwiftAsyncFramePointerMode::DeploymentBased;
440 case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
441 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
444 case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
445 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
450 Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
451 Options.MCOptions.EmitCompactUnwindNonCanonical =
452 CodeGenOpts.EmitCompactUnwindNonCanonical;
453 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
454 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
455 Options.MCOptions.MCUseDwarfDirectory =
456 CodeGenOpts.NoDwarfDirectoryAsm
457 ? llvm::MCTargetOptions::DisableDwarfDirectory
458 : llvm::MCTargetOptions::EnableDwarfDirectory;
459 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
460 Options.MCOptions.MCIncrementalLinkerCompatible =
461 CodeGenOpts.IncrementalLinkerCompatible;
462 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
463 Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
464 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
465 Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
466 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
467 Options.MCOptions.X86RelaxRelocations = CodeGenOpts.RelaxELFRelocations;
468 Options.MCOptions.CompressDebugSections =
469 CodeGenOpts.getCompressDebugSections();
470 Options.MCOptions.ABIName = TargetOpts.
ABI;
472 if (!Entry.IsFramework &&
473 (Entry.Group == frontend::IncludeDirGroup::Quoted ||
474 Entry.Group == frontend::IncludeDirGroup::Angled ||
475 Entry.Group == frontend::IncludeDirGroup::System))
476 Options.MCOptions.IASSearchPaths.push_back(
477 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
478 Options.MCOptions.Argv0 = CodeGenOpts.
Argv0;
481 Options.MCOptions.PPCUseFullRegisterNames =
482 CodeGenOpts.PPCUseFullRegisterNames;
483 Options.MisExpect = CodeGenOpts.MisExpect;
488static std::optional<GCOVOptions>
499 Options.NoRedZone = CodeGenOpts.DisableRedZone;
502 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
506static std::optional<InstrProfOptions>
511 InstrProfOptions Options;
512 Options.NoRedZone = CodeGenOpts.DisableRedZone;
514 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
520 BackendArgs.push_back(
"clang");
522 BackendArgs.push_back(
"-debug-pass");
523 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
526 BackendArgs.push_back(
"-limit-float-precision");
532 if (BackendArgs.size() == 1)
534 BackendArgs.push_back(
nullptr);
538 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
542void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
545 std::string Triple = TheModule->getTargetTriple();
546 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
549 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
553 std::optional<llvm::CodeModel::Model> CM =
getCodeModel(CodeGenOpts);
554 std::string FeaturesStr =
557 std::optional<CodeGenOptLevel> OptLevelOrNone =
558 CodeGenOpt::getLevel(CodeGenOpts.OptimizationLevel);
559 assert(OptLevelOrNone &&
"Invalid optimization level!");
560 CodeGenOptLevel OptLevel = *OptLevelOrNone;
562 llvm::TargetOptions Options;
566 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
567 Options, RM, CM, OptLevel));
571bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
573 raw_pwrite_stream &OS,
574 raw_pwrite_stream *DwoOS) {
576 std::unique_ptr<TargetLibraryInfoImpl> TLII(
577 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
578 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
587 if (CodeGenOpts.OptimizationLevel > 0)
588 CodeGenPasses.add(createObjCARCContractPass());
590 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
591 !CodeGenOpts.VerifyModule)) {
592 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
600 switch (Opts.OptimizationLevel) {
602 llvm_unreachable(
"Invalid optimization level!");
605 return OptimizationLevel::O0;
608 return OptimizationLevel::O1;
611 switch (Opts.OptimizeSize) {
613 llvm_unreachable(
"Invalid optimization level for size!");
616 return OptimizationLevel::O2;
619 return OptimizationLevel::Os;
622 return OptimizationLevel::Oz;
626 return OptimizationLevel::O3;
633 if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
634 TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
638 PB.registerOptimizerLastEPCallback(
639 [&](ModulePassManager &MPM, OptimizationLevel Level) {
640 if (Level == OptimizationLevel::O0 &&
642 MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass()));
647 PB.registerPeepholeEPCallback(
648 [&](FunctionPassManager &FPM, OptimizationLevel Level) {
649 if (Level != OptimizationLevel::O0 &&
651 FPM.addPass(KCFIPass());
658 auto SanitizersCallback = [&](ModulePassManager &MPM,
659 OptimizationLevel Level) {
662 MPM.addPass(SanitizerCoveragePass(
668 MPM.addPass(SanitizerBinaryMetadataPass(
673 auto MSanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
675 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
678 MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
679 CodeGenOpts.SanitizeMemoryParamRetval);
680 MPM.addPass(MemorySanitizerPass(options));
681 if (Level != OptimizationLevel::O0) {
686 MPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
687 FunctionPassManager FPM;
688 FPM.addPass(EarlyCSEPass(
true ));
689 FPM.addPass(InstCombinePass());
690 FPM.addPass(JumpThreadingPass());
691 FPM.addPass(GVNPass());
692 FPM.addPass(InstCombinePass());
693 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
697 MSanPass(SanitizerKind::Memory,
false);
698 MSanPass(SanitizerKind::KernelMemory,
true);
700 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
701 MPM.addPass(ModuleThreadSanitizerPass());
702 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
705 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
708 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
709 llvm::AsanDtorKind DestructorKind =
710 CodeGenOpts.getSanitizeAddressDtor();
711 AddressSanitizerOptions Opts;
712 Opts.CompileKernel = CompileKernel;
714 Opts.UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
715 Opts.UseAfterReturn = CodeGenOpts.getSanitizeAddressUseAfterReturn();
716 MPM.addPass(AddressSanitizerPass(Opts, UseGlobalGC, UseOdrIndicator,
720 ASanPass(SanitizerKind::Address,
false);
721 ASanPass(SanitizerKind::KernelAddress,
true);
723 auto HWASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
726 MPM.addPass(HWAddressSanitizerPass(
727 {CompileKernel, Recover,
728 CodeGenOpts.OptimizationLevel == 0}));
731 HWASanPass(SanitizerKind::HWAddress,
false);
732 HWASanPass(SanitizerKind::KernelHWAddress,
true);
734 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
739 PB.registerOptimizerEarlyEPCallback(
740 [SanitizersCallback](ModulePassManager &MPM, OptimizationLevel Level) {
741 ModulePassManager NewMPM;
742 SanitizersCallback(NewMPM, Level);
743 if (!NewMPM.isEmpty()) {
745 NewMPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
746 MPM.addPass(std::move(NewMPM));
751 PB.registerOptimizerLastEPCallback(SanitizersCallback);
758 PB.registerScalarOptimizerLateEPCallback(
759 [](FunctionPassManager &FPM, OptimizationLevel Level) {
764 FPM.addPass(SimplifyCFGPass());
765 FPM.addPass(RemoveTrapsPass());
770void EmitAssemblyHelper::RunOptimizationPipeline(
771 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
772 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC) {
773 std::optional<PGOOptions> PGOOpt;
781 PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default,
782 CodeGenOpts.DebugInfoForProfiling,
783 false, CodeGenOpts.AtomicProfileUpdate);
787 : PGOOptions::NoCSAction;
791 PGOOptions::IRUse, CSAction, PGOOptions::ColdFuncOpt::Default,
792 CodeGenOpts.DebugInfoForProfiling);
798 PGOOptions::NoCSAction, PGOOptions::ColdFuncOpt::Default,
799 CodeGenOpts.DebugInfoForProfiling, CodeGenOpts.PseudoProbeForProfiling);
803 PGOOptions::NoAction, PGOOptions::NoCSAction,
804 PGOOptions::ColdFuncOpt::Default,
805 CodeGenOpts.DebugInfoForProfiling);
806 else if (CodeGenOpts.PseudoProbeForProfiling)
808 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
809 PGOOptions::NoAction, PGOOptions::NoCSAction,
810 PGOOptions::ColdFuncOpt::Default,
811 CodeGenOpts.DebugInfoForProfiling,
true);
812 else if (CodeGenOpts.DebugInfoForProfiling)
814 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
815 PGOOptions::NoAction, PGOOptions::NoCSAction,
816 PGOOptions::ColdFuncOpt::Default,
true);
821 "Cannot have both CSProfileUse pass and CSProfileGen pass at "
824 assert(PGOOpt->Action != PGOOptions::IRInstr &&
825 PGOOpt->Action != PGOOptions::SampleUse &&
826 "Cannot run CSProfileGen pass with ProfileGen or SampleUse "
829 ? getDefaultProfileGenName()
830 : CodeGenOpts.InstrProfileOutput;
831 PGOOpt->CSAction = PGOOptions::CSIRInstr;
836 ? getDefaultProfileGenName()
838 "",
"",
nullptr, PGOOptions::NoAction,
839 PGOOptions::CSIRInstr, PGOOptions::ColdFuncOpt::Default,
840 CodeGenOpts.DebugInfoForProfiling);
843 TM->setPGOOption(PGOOpt);
845 PipelineTuningOptions PTO;
846 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
849 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
850 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
851 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
852 PTO.MergeFunctions = CodeGenOpts.MergeFunctions;
855 PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
856 PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO;
858 LoopAnalysisManager LAM;
859 FunctionAnalysisManager FAM;
860 CGSCCAnalysisManager CGAM;
861 ModuleAnalysisManager MAM;
863 bool DebugPassStructure = CodeGenOpts.
DebugPass ==
"Structure";
864 PassInstrumentationCallbacks PIC;
865 PrintPassOptions PrintPassOpts;
866 PrintPassOpts.Indent = DebugPassStructure;
867 PrintPassOpts.SkipAnalyses = DebugPassStructure;
868 StandardInstrumentations SI(
869 TheModule->getContext(),
870 (CodeGenOpts.DebugPassManager || DebugPassStructure),
871 CodeGenOpts.VerifyEach, PrintPassOpts);
872 SI.registerCallbacks(PIC, &MAM);
873 PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
876 switch (CodeGenOpts.getAssignmentTrackingMode()) {
877 case CodeGenOptions::AssignmentTrackingOpts::Forced:
878 PB.registerPipelineStartEPCallback(
879 [&](ModulePassManager &MPM, OptimizationLevel Level) {
880 MPM.addPass(AssignmentTrackingPass());
883 case CodeGenOptions::AssignmentTrackingOpts::Enabled:
886 if (!CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.PrepareForLTO &&
887 CodeGenOpts.getDebuggerTuning() != llvm::DebuggerKind::LLDB) {
888 PB.registerPipelineStartEPCallback(
889 [&](ModulePassManager &MPM, OptimizationLevel Level) {
891 if (Level != OptimizationLevel::O0)
892 MPM.addPass(AssignmentTrackingPass());
896 case CodeGenOptions::AssignmentTrackingOpts::Disabled:
901 DebugifyEachInstrumentation Debugify;
902 DebugInfoPerPass DebugInfoBeforePass;
903 if (CodeGenOpts.EnableDIPreservationVerify) {
904 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
905 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
908 Debugify.setOrigDIVerifyBugsReportFilePath(
910 Debugify.registerCallbacks(PIC, MAM);
914 auto PassPlugin = PassPlugin::Load(PluginFN);
916 PassPlugin->registerPassBuilderCallbacks(PB);
918 Diags.
Report(diag::err_fe_unable_to_load_plugin)
919 << PluginFN <<
toString(PassPlugin.takeError());
924#define HANDLE_EXTENSION(Ext) \
925 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
926#include "llvm/Support/Extension.def"
930 std::unique_ptr<TargetLibraryInfoImpl> TLII(
931 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
932 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
935 PB.registerModuleAnalyses(MAM);
936 PB.registerCGSCCAnalyses(CGAM);
937 PB.registerFunctionAnalyses(FAM);
938 PB.registerLoopAnalyses(LAM);
939 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
941 ModulePassManager MPM;
943 if (CodeGenOpts.VerifyModule)
944 MPM.addPass(VerifierPass());
946 if (!CodeGenOpts.DisableLLVMPasses) {
951 const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
952 const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;
954 if (LangOpts.ObjCAutoRefCount) {
955 PB.registerPipelineStartEPCallback(
956 [](ModulePassManager &MPM, OptimizationLevel Level) {
957 if (Level != OptimizationLevel::O0)
959 createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
961 PB.registerPipelineEarlySimplificationEPCallback(
962 [](ModulePassManager &MPM, OptimizationLevel Level) {
963 if (Level != OptimizationLevel::O0)
964 MPM.addPass(ObjCARCAPElimPass());
966 PB.registerScalarOptimizerLateEPCallback(
967 [](FunctionPassManager &FPM, OptimizationLevel Level) {
968 if (Level != OptimizationLevel::O0)
969 FPM.addPass(ObjCARCOptPass());
979 if (IsThinLTOPostLink)
980 PB.registerPipelineStartEPCallback(
981 [](ModulePassManager &MPM, OptimizationLevel Level) {
982 MPM.addPass(LowerTypeTestsPass(
nullptr,
987 if (CodeGenOpts.InstrumentFunctions ||
988 CodeGenOpts.InstrumentFunctionEntryBare ||
989 CodeGenOpts.InstrumentFunctionsAfterInlining ||
990 CodeGenOpts.InstrumentForProfiling) {
991 PB.registerPipelineStartEPCallback(
992 [](ModulePassManager &MPM, OptimizationLevel Level) {
993 MPM.addPass(createModuleToFunctionPassAdaptor(
994 EntryExitInstrumenterPass(
false)));
996 PB.registerOptimizerLastEPCallback(
997 [](ModulePassManager &MPM, OptimizationLevel Level) {
998 MPM.addPass(createModuleToFunctionPassAdaptor(
999 EntryExitInstrumenterPass(
true)));
1005 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1006 PB.registerScalarOptimizerLateEPCallback(
1007 [](FunctionPassManager &FPM, OptimizationLevel Level) {
1008 FPM.addPass(BoundsCheckingPass());
1013 if (!IsThinLTOPostLink) {
1018 if (std::optional<GCOVOptions> Options =
1020 PB.registerPipelineStartEPCallback(
1021 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1022 MPM.addPass(GCOVProfilerPass(*Options));
1024 if (std::optional<InstrProfOptions> Options =
1026 PB.registerPipelineStartEPCallback(
1027 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
1028 MPM.addPass(InstrProfilingLoweringPass(*Options,
false));
1034 PB.registerOptimizerLastEPCallback(
1035 [](ModulePassManager &MPM, OptimizationLevel Level) {
1036 MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
1037 MPM.addPass(ModuleMemProfilerPass());
1041 if (CodeGenOpts.FatLTO) {
1042 MPM.addPass(PB.buildFatLTODefaultPipeline(
1043 Level, PrepareForThinLTO,
1044 PrepareForThinLTO || shouldEmitRegularLTOSummary()));
1045 }
else if (PrepareForThinLTO) {
1046 MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
1047 }
else if (PrepareForLTO) {
1048 MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(Level));
1050 MPM.addPass(PB.buildPerModuleDefaultPipeline(Level));
1067 MPM.addPass(VerifierPass());
1070 CodeGenOpts.FatLTO) {
1071 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1072 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1073 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1074 CodeGenOpts.EnableSplitLTOUnit);
1081 MPM.addPass(ThinLTOBitcodeWriterPass(
1082 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
1084 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1090 bool EmitLTOSummary = shouldEmitRegularLTOSummary();
1091 if (EmitLTOSummary) {
1092 if (!TheModule->getModuleFlag(
"ThinLTO") && !CodeGenOpts.UnifiedLTO)
1093 TheModule->addModuleFlag(llvm::Module::Error,
"ThinLTO", uint32_t(0));
1094 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1095 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1099 MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
1102 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1107 if (shouldEmitUnifiedLTOModueFlag())
1108 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO", uint32_t(1));
1114 MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
1115 auto PassName = PIC.getPassNameForClassName(ClassName);
1116 return PassName.empty() ? ClassName : PassName;
1122 if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1123 LangOpts.HIPStdParInterposeAlloc)
1124 MPM.addPass(HipStdParAllocationInterpositionPass());
1128 PrettyStackTraceString CrashInfo(
"Optimizer");
1129 llvm::TimeTraceScope TimeScope(
"Optimizer");
1130 MPM.run(*TheModule, MAM);
1134void EmitAssemblyHelper::RunCodegenPipeline(
1135 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
1136 std::unique_ptr<llvm::ToolOutputFile> &DwoOS) {
1140 legacy::PassManager CodeGenPasses;
1148 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1154 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1155 DwoOS ? &DwoOS->os() :
nullptr))
1171 PrettyStackTraceString CrashInfo(
"Code generation");
1172 llvm::TimeTraceScope TimeScope(
"CodeGenPasses");
1173 CodeGenPasses.run(*TheModule);
1178 std::unique_ptr<raw_pwrite_stream> OS,
1180 TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime :
nullptr);
1184 CreateTargetMachine(RequiresCodeGen);
1186 if (RequiresCodeGen && !TM)
1189 TheModule->setDataLayout(TM->createDataLayout());
1192 cl::PrintOptionValues();
1194 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1195 RunOptimizationPipeline(Action, OS, ThinLinkOS, BC);
1196 RunCodegenPipeline(Action, OS, DwoOS);
1208 const LangOptions &LOpts, std::unique_ptr<raw_pwrite_stream> OS,
1209 std::string SampleProfile, std::string ProfileRemapping,
1211 DenseMap<StringRef, DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1212 ModuleToDefinedGVSummaries;
1213 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1220 FunctionImporter::ImportMapTy ImportList;
1221 if (!lto::initImportList(*M, *CombinedIndex, ImportList))
1224 auto AddStream = [&](
size_t Task,
const Twine &ModuleName) {
1225 return std::make_unique<CachedFileStream>(std::move(OS),
1232 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1233 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1238 Conf.CPU = TOpts.
CPU;
1242 std::optional<CodeGenOptLevel> OptLevelOrNone =
1243 CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
1244 assert(OptLevelOrNone &&
"Invalid optimization level!");
1245 Conf.CGOptLevel = *OptLevelOrNone;
1246 Conf.OptLevel = CGOpts.OptimizationLevel;
1248 Conf.SampleProfile = std::move(SampleProfile);
1249 Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
1252 Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
1253 Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
1254 Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1257 Conf.PTO.CallGraphProfile = !CGOpts.DisableIntegratedAS;
1261 Conf.RunCSIRInstr =
true;
1264 Conf.RunCSIRInstr =
false;
1268 Conf.ProfileRemapping = std::move(ProfileRemapping);
1269 Conf.DebugPassManager = CGOpts.DebugPassManager;
1270 Conf.VerifyEach = CGOpts.VerifyEach;
1271 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1279 Conf.PreCodeGenModuleHook = [](
size_t Task,
const llvm::Module &Mod) {
1284 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1285 M->print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1290 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1291 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1300 thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1301 ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
1303 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1304 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1312 const LangOptions &LOpts, StringRef TDesc, llvm::Module *M,
1316 llvm::TimeTraceScope TimeScope(
"Backend");
1318 std::unique_ptr<llvm::Module> EmptyModule;
1323 std::unique_ptr<ModuleSummaryIndex> CombinedIndex;
1324 if (Error E = llvm::getModuleSummaryIndexForFile(
1327 .moveInto(CombinedIndex)) {
1328 logAllUnhandledErrors(std::move(E), errs(),
1329 "Error loading index file '" +
1337 if (CombinedIndex) {
1338 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1350 EmptyModule = std::make_unique<llvm::Module>(
"empty", M->getContext());
1351 EmptyModule->setTargetTriple(M->getTargetTriple());
1352 M = EmptyModule.get();
1356 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M, VFS);
1357 AsmHelper.EmitAssembly(Action, std::move(OS), BC);
1362 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1363 if (DLDesc != TDesc) {
1366 "expected target description '%1'");
1367 Diags.
Report(DiagID) << DLDesc << TDesc;
1375 llvm::MemoryBufferRef Buf) {
1378 llvm::embedBitcodeInModule(
1390 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1391 llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1392 if (ObjectOrErr.getError()) {
1394 "could not open '%0' for embedding");
1395 Diags.
Report(DiagID) << OffloadObject;
1399 llvm::embedBufferInModule(*M, **ObjectOrErr,
".llvm.offloading",
1400 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)
YAML serialization mapping.
cl::opt< bool > PrintPipelinePasses
cl::opt< InstrProfCorrelator::ProfCorrelatorKind > ProfileCorrelate
static cl::opt< bool > ClSanitizeOnOptimizerEarlyEP("sanitizer-early-opt-ep", cl::Optional, cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false))
cl::opt< bool > ClRelinkBuiltinBitcodePostop
cl::opt< bool > ClRemoveTraps("clang-remove-traps", cl::Optional, cl::desc("Insert remove-traps pass."), cl::init(false))
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.