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/Support/BuryPointer.h"
49#include "llvm/Support/CommandLine.h"
50#include "llvm/Support/MemoryBuffer.h"
51#include "llvm/Support/PrettyStackTrace.h"
52#include "llvm/Support/TimeProfiler.h"
53#include "llvm/Support/Timer.h"
54#include "llvm/Support/ToolOutputFile.h"
55#include "llvm/Support/VirtualFileSystem.h"
56#include "llvm/Support/raw_ostream.h"
57#include "llvm/Target/TargetMachine.h"
58#include "llvm/Target/TargetOptions.h"
59#include "llvm/TargetParser/SubtargetFeature.h"
60#include "llvm/TargetParser/Triple.h"
61#include "llvm/Transforms/HipStdPar/HipStdPar.h"
62#include "llvm/Transforms/IPO/EmbedBitcodePass.h"
63#include "llvm/Transforms/IPO/LowerTypeTests.h"
64#include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h"
65#include "llvm/Transforms/InstCombine/InstCombine.h"
66#include "llvm/Transforms/Instrumentation.h"
67#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
68#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
69#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
70#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
71#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
72#include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h"
73#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
74#include "llvm/Transforms/Instrumentation/KCFI.h"
75#include "llvm/Transforms/Instrumentation/MemProfiler.h"
76#include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
77#include "llvm/Transforms/Instrumentation/PGOInstrumentation.h"
78#include "llvm/Transforms/Instrumentation/SanitizerBinaryMetadata.h"
79#include "llvm/Transforms/Instrumentation/SanitizerCoverage.h"
80#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
81#include "llvm/Transforms/ObjCARC.h"
82#include "llvm/Transforms/Scalar/EarlyCSE.h"
83#include "llvm/Transforms/Scalar/GVN.h"
84#include "llvm/Transforms/Scalar/JumpThreading.h"
85#include "llvm/Transforms/Utils/Debugify.h"
86#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
87#include "llvm/Transforms/Utils/ModuleUtils.h"
93#define HANDLE_EXTENSION(Ext) \
94 llvm::PassPluginLibraryInfo get##Ext##PluginInfo();
95#include "llvm/Support/Extension.def"
102 "sanitizer-early-opt-ep", cl::Optional,
103 cl::desc(
"Insert sanitizers on OptimizerEarlyEP."), cl::init(
false));
107 "relink-builtin-bitcode-postop", cl::Optional,
108 cl::desc(
"Re-link builtin bitcodes after optimization."), cl::init(
false));
114std::string getDefaultProfileGenName() {
115 return DebugInfoCorrelate ?
"default_%m.proflite" :
"default_%m.profraw";
118class EmitAssemblyHelper {
124 llvm::Module *TheModule;
127 Timer CodeGenerationTime;
129 std::unique_ptr<raw_pwrite_stream> OS;
133 TargetIRAnalysis getTargetIRAnalysis()
const {
135 return TM->getTargetIRAnalysis();
137 return TargetIRAnalysis();
148 void CreateTargetMachine(
bool MustCreateTM);
153 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
154 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
156 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
158 auto F = std::make_unique<llvm::ToolOutputFile>(Path, EC,
159 llvm::sys::fs::OF_None);
161 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
167 void RunOptimizationPipeline(
168 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
169 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC);
171 std::unique_ptr<raw_pwrite_stream> &OS,
172 std::unique_ptr<llvm::ToolOutputFile> &DwoOS);
179 bool shouldEmitRegularLTOSummary()
const {
180 return CodeGenOpts.PrepareForLTO && !CodeGenOpts.DisableLLVMPasses &&
181 TargetTriple.getVendor() != llvm::Triple::Apple;
191 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
192 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M), VFS(
std::move(VFS)),
193 CodeGenerationTime(
"codegen",
"Code Generation Time"),
194 TargetTriple(TheModule->getTargetTriple()) {}
196 ~EmitAssemblyHelper() {
197 if (CodeGenOpts.DisableFree)
198 BuryPointer(std::move(TM));
201 std::unique_ptr<TargetMachine> TM;
209static SanitizerCoverageOptions
211 SanitizerCoverageOptions Opts;
213 static_cast<SanitizerCoverageOptions::Type
>(CGOpts.SanitizeCoverageType);
214 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
215 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
216 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
217 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
218 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
219 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
220 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
221 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
222 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
223 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
224 Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
225 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
226 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
227 Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
228 Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
229 Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
233static SanitizerBinaryMetadataOptions
235 SanitizerBinaryMetadataOptions Opts;
236 Opts.Covered = CGOpts.SanitizeBinaryMetadataCovered;
237 Opts.Atomics = CGOpts.SanitizeBinaryMetadataAtomics;
238 Opts.UAR = CGOpts.SanitizeBinaryMetadataUAR;
247 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
249 switch (T.getObjectFormat()) {
254 return !CGOpts.DisableIntegratedAS;
256 llvm::report_fatal_error(
"ASan not implemented for GOFF");
258 llvm::report_fatal_error(
"ASan not implemented for XCOFF.");
260 case Triple::DXContainer:
262 case Triple::UnknownObjectFormat:
268static std::optional<llvm::CodeModel::Model>
270 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
271 .Case(
"tiny", llvm::CodeModel::Tiny)
272 .Case(
"small", llvm::CodeModel::Small)
273 .Case(
"kernel", llvm::CodeModel::Kernel)
274 .Case(
"medium", llvm::CodeModel::Medium)
275 .Case(
"large", llvm::CodeModel::Large)
276 .Case(
"default", ~1u)
278 assert(CodeModel != ~0u &&
"invalid code model!");
279 if (CodeModel == ~1u)
281 return static_cast<llvm::CodeModel::Model
>(CodeModel);
286 return CodeGenFileType::ObjectFile;
288 return CodeGenFileType::Null;
291 return CodeGenFileType::AssemblyFile;
301 llvm::TargetOptions &Options,
306 switch (LangOpts.getThreadModel()) {
307 case LangOptions::ThreadModelKind::POSIX:
308 Options.ThreadModel = llvm::ThreadModel::POSIX;
310 case LangOptions::ThreadModelKind::Single:
311 Options.ThreadModel = llvm::ThreadModel::Single;
316 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
318 "Invalid Floating Point ABI!");
319 Options.FloatABIType =
320 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
321 .Case(
"soft", llvm::FloatABI::Soft)
322 .Case(
"softfp", llvm::FloatABI::Soft)
323 .Case(
"hard", llvm::FloatABI::Hard)
324 .Default(llvm::FloatABI::Default);
327 switch (LangOpts.getDefaultFPContractMode()) {
331 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
335 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
338 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
342 Options.BinutilsVersion =
343 llvm::TargetMachine::parseBinutilsVersion(CodeGenOpts.
BinutilsVersion);
344 Options.UseInitArray = CodeGenOpts.UseInitArray;
345 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
346 Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
347 Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
353 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
355 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
357 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
359 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
361 Options.NoInfsFPMath = LangOpts.NoHonorInfs;
362 Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
363 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
364 Options.UnsafeFPMath = LangOpts.AllowFPReassoc && LangOpts.AllowRecip &&
365 LangOpts.NoSignedZero && LangOpts.ApproxFunc &&
366 (LangOpts.getDefaultFPContractMode() ==
367 LangOptions::FPModeKind::FPM_Fast ||
368 LangOpts.getDefaultFPContractMode() ==
369 LangOptions::FPModeKind::FPM_FastHonorPragmas);
370 Options.ApproxFuncFPMath = LangOpts.ApproxFunc;
373 llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.
BBSections)
374 .Case(
"all", llvm::BasicBlockSection::All)
375 .Case(
"labels", llvm::BasicBlockSection::Labels)
376 .StartsWith(
"list=", llvm::BasicBlockSection::List)
377 .Case(
"none", llvm::BasicBlockSection::None)
378 .Default(llvm::BasicBlockSection::None);
380 if (Options.BBSections == llvm::BasicBlockSection::List) {
381 ErrorOr<std::unique_ptr<MemoryBuffer>> MBOrErr =
382 MemoryBuffer::getFile(CodeGenOpts.
BBSections.substr(5));
384 Diags.
Report(diag::err_fe_unable_to_load_basic_block_sections_file)
385 << MBOrErr.getError().message();
388 Options.BBSectionsFuncListBuf = std::move(*MBOrErr);
391 Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
392 Options.FunctionSections = CodeGenOpts.FunctionSections;
393 Options.DataSections = CodeGenOpts.DataSections;
394 Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
395 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
396 Options.UniqueBasicBlockSectionNames =
397 CodeGenOpts.UniqueBasicBlockSectionNames;
398 Options.TLSSize = CodeGenOpts.TLSSize;
399 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
400 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
401 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
403 Options.EmitAddrsig = CodeGenOpts.Addrsig;
404 Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
405 Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
406 Options.EnableAIXExtendedAltivecABI = LangOpts.EnableAIXExtendedAltivecABI;
407 Options.XRayFunctionIndex = CodeGenOpts.XRayFunctionIndex;
408 Options.LoopAlignment = CodeGenOpts.LoopAlignment;
409 Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
411 Options.Hotpatch = CodeGenOpts.HotPatch;
412 Options.JMCInstrument = CodeGenOpts.JMCInstrument;
413 Options.XCOFFReadOnlyPointers = CodeGenOpts.XCOFFReadOnlyPointers;
415 switch (CodeGenOpts.getSwiftAsyncFramePointer()) {
416 case CodeGenOptions::SwiftAsyncFramePointerKind::Auto:
417 Options.SwiftAsyncFramePointer =
418 SwiftAsyncFramePointerMode::DeploymentBased;
421 case CodeGenOptions::SwiftAsyncFramePointerKind::Always:
422 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Always;
425 case CodeGenOptions::SwiftAsyncFramePointerKind::Never:
426 Options.SwiftAsyncFramePointer = SwiftAsyncFramePointerMode::Never;
431 Options.MCOptions.EmitDwarfUnwind = CodeGenOpts.getEmitDwarfUnwind();
432 Options.MCOptions.EmitCompactUnwindNonCanonical =
433 CodeGenOpts.EmitCompactUnwindNonCanonical;
434 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
435 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
436 Options.MCOptions.MCUseDwarfDirectory =
437 CodeGenOpts.NoDwarfDirectoryAsm
438 ? llvm::MCTargetOptions::DisableDwarfDirectory
439 : llvm::MCTargetOptions::EnableDwarfDirectory;
440 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
441 Options.MCOptions.MCIncrementalLinkerCompatible =
442 CodeGenOpts.IncrementalLinkerCompatible;
443 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
444 Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
445 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
446 Options.MCOptions.Dwarf64 = CodeGenOpts.Dwarf64;
447 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
448 Options.MCOptions.ABIName = TargetOpts.
ABI;
450 if (!Entry.IsFramework &&
451 (Entry.Group == frontend::IncludeDirGroup::Quoted ||
452 Entry.Group == frontend::IncludeDirGroup::Angled ||
453 Entry.Group == frontend::IncludeDirGroup::System))
454 Options.MCOptions.IASSearchPaths.push_back(
455 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
456 Options.MCOptions.Argv0 = CodeGenOpts.
Argv0;
459 Options.MCOptions.PPCUseFullRegisterNames =
460 CodeGenOpts.PPCUseFullRegisterNames;
461 Options.MisExpect = CodeGenOpts.MisExpect;
466static std::optional<GCOVOptions>
477 Options.NoRedZone = CodeGenOpts.DisableRedZone;
480 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
484static std::optional<InstrProfOptions>
489 InstrProfOptions Options;
490 Options.NoRedZone = CodeGenOpts.DisableRedZone;
492 Options.Atomic = CodeGenOpts.AtomicProfileUpdate;
498 BackendArgs.push_back(
"clang");
500 BackendArgs.push_back(
"-debug-pass");
501 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
504 BackendArgs.push_back(
"-limit-float-precision");
510 if (BackendArgs.size() == 1)
512 BackendArgs.push_back(
nullptr);
516 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
520void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
523 std::string Triple = TheModule->getTargetTriple();
524 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
527 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
531 std::optional<llvm::CodeModel::Model> CM =
getCodeModel(CodeGenOpts);
532 std::string FeaturesStr =
535 std::optional<CodeGenOptLevel> OptLevelOrNone =
536 CodeGenOpt::getLevel(CodeGenOpts.OptimizationLevel);
537 assert(OptLevelOrNone &&
"Invalid optimization level!");
538 CodeGenOptLevel OptLevel = *OptLevelOrNone;
540 llvm::TargetOptions Options;
544 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
545 Options, RM, CM, OptLevel));
549bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
551 raw_pwrite_stream &OS,
552 raw_pwrite_stream *DwoOS) {
554 std::unique_ptr<TargetLibraryInfoImpl> TLII(
555 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
556 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
565 if (CodeGenOpts.OptimizationLevel > 0)
566 CodeGenPasses.add(createObjCARCContractPass());
568 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
569 !CodeGenOpts.VerifyModule)) {
570 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
578 switch (Opts.OptimizationLevel) {
580 llvm_unreachable(
"Invalid optimization level!");
583 return OptimizationLevel::O0;
586 return OptimizationLevel::O1;
589 switch (Opts.OptimizeSize) {
591 llvm_unreachable(
"Invalid optimization level for size!");
594 return OptimizationLevel::O2;
597 return OptimizationLevel::Os;
600 return OptimizationLevel::Oz;
604 return OptimizationLevel::O3;
611 if (TargetTriple.getArch() == llvm::Triple::x86_64 ||
612 TargetTriple.isAArch64(64) || TargetTriple.isRISCV())
616 PB.registerOptimizerLastEPCallback(
617 [&](ModulePassManager &MPM, OptimizationLevel Level) {
618 if (Level == OptimizationLevel::O0 &&
620 MPM.addPass(createModuleToFunctionPassAdaptor(KCFIPass()));
625 PB.registerPeepholeEPCallback(
626 [&](FunctionPassManager &FPM, OptimizationLevel Level) {
627 if (Level != OptimizationLevel::O0 &&
629 FPM.addPass(KCFIPass());
636 auto SanitizersCallback = [&](ModulePassManager &MPM,
637 OptimizationLevel Level) {
640 MPM.addPass(SanitizerCoveragePass(
646 MPM.addPass(SanitizerBinaryMetadataPass(
651 auto MSanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
653 int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
656 MemorySanitizerOptions options(TrackOrigins, Recover, CompileKernel,
657 CodeGenOpts.SanitizeMemoryParamRetval);
658 MPM.addPass(MemorySanitizerPass(options));
659 if (Level != OptimizationLevel::O0) {
664 MPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
665 FunctionPassManager FPM;
666 FPM.addPass(EarlyCSEPass(
true ));
667 FPM.addPass(InstCombinePass());
668 FPM.addPass(JumpThreadingPass());
669 FPM.addPass(GVNPass());
670 FPM.addPass(InstCombinePass());
671 MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
675 MSanPass(SanitizerKind::Memory,
false);
676 MSanPass(SanitizerKind::KernelMemory,
true);
678 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
679 MPM.addPass(ModuleThreadSanitizerPass());
680 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
683 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
686 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
687 llvm::AsanDtorKind DestructorKind =
688 CodeGenOpts.getSanitizeAddressDtor();
689 AddressSanitizerOptions Opts;
690 Opts.CompileKernel = CompileKernel;
692 Opts.UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
693 Opts.UseAfterReturn = CodeGenOpts.getSanitizeAddressUseAfterReturn();
694 MPM.addPass(AddressSanitizerPass(Opts, UseGlobalGC, UseOdrIndicator,
698 ASanPass(SanitizerKind::Address,
false);
699 ASanPass(SanitizerKind::KernelAddress,
true);
701 auto HWASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
704 MPM.addPass(HWAddressSanitizerPass(
705 {CompileKernel, Recover,
706 CodeGenOpts.OptimizationLevel == 0}));
709 HWASanPass(SanitizerKind::HWAddress,
false);
710 HWASanPass(SanitizerKind::KernelHWAddress,
true);
712 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
717 PB.registerOptimizerEarlyEPCallback(
718 [SanitizersCallback](ModulePassManager &MPM, OptimizationLevel Level) {
719 ModulePassManager NewMPM;
720 SanitizersCallback(NewMPM, Level);
721 if (!NewMPM.isEmpty()) {
723 NewMPM.addPass(RequireAnalysisPass<GlobalsAA, llvm::Module>());
724 MPM.addPass(std::move(NewMPM));
729 PB.registerOptimizerLastEPCallback(SanitizersCallback);
733void EmitAssemblyHelper::RunOptimizationPipeline(
734 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
735 std::unique_ptr<llvm::ToolOutputFile> &ThinLinkOS,
BackendConsumer *BC) {
736 std::optional<PGOOptions> PGOOpt;
744 PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
745 false, CodeGenOpts.AtomicProfileUpdate);
749 : PGOOptions::NoCSAction;
753 PGOOptions::IRUse, CSAction, CodeGenOpts.DebugInfoForProfiling);
759 PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling,
760 CodeGenOpts.PseudoProbeForProfiling);
764 PGOOptions::NoAction, PGOOptions::NoCSAction,
765 CodeGenOpts.DebugInfoForProfiling);
766 else if (CodeGenOpts.PseudoProbeForProfiling)
768 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
769 PGOOptions::NoAction, PGOOptions::NoCSAction,
770 CodeGenOpts.DebugInfoForProfiling,
true);
771 else if (CodeGenOpts.DebugInfoForProfiling)
773 PGOOpt = PGOOptions(
"",
"",
"",
"",
nullptr,
774 PGOOptions::NoAction, PGOOptions::NoCSAction,
true);
779 "Cannot have both CSProfileUse pass and CSProfileGen pass at "
782 assert(PGOOpt->Action != PGOOptions::IRInstr &&
783 PGOOpt->Action != PGOOptions::SampleUse &&
784 "Cannot run CSProfileGen pass with ProfileGen or SampleUse "
787 ? getDefaultProfileGenName()
788 : CodeGenOpts.InstrProfileOutput;
789 PGOOpt->CSAction = PGOOptions::CSIRInstr;
794 ? getDefaultProfileGenName()
796 "",
"",
nullptr, PGOOptions::NoAction,
797 PGOOptions::CSIRInstr, CodeGenOpts.DebugInfoForProfiling);
800 TM->setPGOOption(PGOOpt);
802 PipelineTuningOptions PTO;
803 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
806 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
807 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
808 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
809 PTO.MergeFunctions = CodeGenOpts.MergeFunctions;
812 PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
813 PTO.UnifiedLTO = CodeGenOpts.UnifiedLTO;
815 LoopAnalysisManager LAM;
816 FunctionAnalysisManager FAM;
817 CGSCCAnalysisManager CGAM;
818 ModuleAnalysisManager MAM;
820 bool DebugPassStructure = CodeGenOpts.
DebugPass ==
"Structure";
821 PassInstrumentationCallbacks PIC;
822 PrintPassOptions PrintPassOpts;
823 PrintPassOpts.Indent = DebugPassStructure;
824 PrintPassOpts.SkipAnalyses = DebugPassStructure;
825 StandardInstrumentations SI(
826 TheModule->getContext(),
827 (CodeGenOpts.DebugPassManager || DebugPassStructure),
828 CodeGenOpts.VerifyEach, PrintPassOpts);
829 SI.registerCallbacks(PIC, &MAM);
830 PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
833 switch (CodeGenOpts.getAssignmentTrackingMode()) {
834 case CodeGenOptions::AssignmentTrackingOpts::Forced:
835 PB.registerPipelineStartEPCallback(
836 [&](ModulePassManager &MPM, OptimizationLevel Level) {
837 MPM.addPass(AssignmentTrackingPass());
840 case CodeGenOptions::AssignmentTrackingOpts::Enabled:
843 if (!CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.PrepareForLTO &&
844 CodeGenOpts.getDebuggerTuning() != llvm::DebuggerKind::LLDB) {
845 PB.registerPipelineStartEPCallback(
846 [&](ModulePassManager &MPM, OptimizationLevel Level) {
848 if (Level != OptimizationLevel::O0)
849 MPM.addPass(AssignmentTrackingPass());
853 case CodeGenOptions::AssignmentTrackingOpts::Disabled:
858 DebugifyEachInstrumentation Debugify;
859 DebugInfoPerPass DebugInfoBeforePass;
860 if (CodeGenOpts.EnableDIPreservationVerify) {
861 Debugify.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
862 Debugify.setDebugInfoBeforePass(DebugInfoBeforePass);
865 Debugify.setOrigDIVerifyBugsReportFilePath(
867 Debugify.registerCallbacks(PIC, MAM);
871 auto PassPlugin = PassPlugin::Load(PluginFN);
873 PassPlugin->registerPassBuilderCallbacks(PB);
875 Diags.
Report(diag::err_fe_unable_to_load_plugin)
876 << PluginFN <<
toString(PassPlugin.takeError());
881#define HANDLE_EXTENSION(Ext) \
882 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
883#include "llvm/Support/Extension.def"
887 std::unique_ptr<TargetLibraryInfoImpl> TLII(
888 llvm::driver::createTLII(TargetTriple, CodeGenOpts.getVecLib()));
889 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
892 PB.registerModuleAnalyses(MAM);
893 PB.registerCGSCCAnalyses(CGAM);
894 PB.registerFunctionAnalyses(FAM);
895 PB.registerLoopAnalyses(LAM);
896 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
898 ModulePassManager MPM;
900 if (CodeGenOpts.VerifyModule)
901 MPM.addPass(VerifierPass());
903 if (!CodeGenOpts.DisableLLVMPasses) {
908 const bool PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
909 const bool PrepareForLTO = CodeGenOpts.PrepareForLTO;
911 if (LangOpts.ObjCAutoRefCount) {
912 PB.registerPipelineStartEPCallback(
913 [](ModulePassManager &MPM, OptimizationLevel Level) {
914 if (Level != OptimizationLevel::O0)
916 createModuleToFunctionPassAdaptor(ObjCARCExpandPass()));
918 PB.registerPipelineEarlySimplificationEPCallback(
919 [](ModulePassManager &MPM, OptimizationLevel Level) {
920 if (Level != OptimizationLevel::O0)
921 MPM.addPass(ObjCARCAPElimPass());
923 PB.registerScalarOptimizerLateEPCallback(
924 [](FunctionPassManager &FPM, OptimizationLevel Level) {
925 if (Level != OptimizationLevel::O0)
926 FPM.addPass(ObjCARCOptPass());
936 if (IsThinLTOPostLink)
937 PB.registerPipelineStartEPCallback(
938 [](ModulePassManager &MPM, OptimizationLevel Level) {
939 MPM.addPass(LowerTypeTestsPass(
nullptr,
944 if (CodeGenOpts.InstrumentFunctions ||
945 CodeGenOpts.InstrumentFunctionEntryBare ||
946 CodeGenOpts.InstrumentFunctionsAfterInlining ||
947 CodeGenOpts.InstrumentForProfiling) {
948 PB.registerPipelineStartEPCallback(
949 [](ModulePassManager &MPM, OptimizationLevel Level) {
950 MPM.addPass(createModuleToFunctionPassAdaptor(
951 EntryExitInstrumenterPass(
false)));
953 PB.registerOptimizerLastEPCallback(
954 [](ModulePassManager &MPM, OptimizationLevel Level) {
955 MPM.addPass(createModuleToFunctionPassAdaptor(
956 EntryExitInstrumenterPass(
true)));
962 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
963 PB.registerScalarOptimizerLateEPCallback(
964 [](FunctionPassManager &FPM, OptimizationLevel Level) {
965 FPM.addPass(BoundsCheckingPass());
970 if (!IsThinLTOPostLink) {
975 if (std::optional<GCOVOptions> Options =
977 PB.registerPipelineStartEPCallback(
978 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
979 MPM.addPass(GCOVProfilerPass(*Options));
981 if (std::optional<InstrProfOptions> Options =
983 PB.registerPipelineStartEPCallback(
984 [Options](ModulePassManager &MPM, OptimizationLevel Level) {
985 MPM.addPass(InstrProfiling(*Options,
false));
991 PB.registerOptimizerLastEPCallback(
992 [](ModulePassManager &MPM, OptimizationLevel Level) {
993 MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
994 MPM.addPass(ModuleMemProfilerPass());
998 if (CodeGenOpts.FatLTO) {
999 assert(CodeGenOpts.UnifiedLTO &&
"FatLTO requires UnifiedLTO");
1000 MPM.addPass(PB.buildFatLTODefaultPipeline(Level));
1001 }
else if (PrepareForThinLTO) {
1002 MPM.addPass(PB.buildThinLTOPreLinkDefaultPipeline(Level));
1003 }
else if (PrepareForLTO) {
1004 MPM.addPass(PB.buildLTOPreLinkDefaultPipeline(Level));
1006 MPM.addPass(PB.buildPerModuleDefaultPipeline(Level));
1023 MPM.addPass(VerifierPass());
1026 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1027 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1028 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1029 CodeGenOpts.EnableSplitLTOUnit);
1036 if (CodeGenOpts.UnifiedLTO)
1037 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO", uint32_t(1));
1038 MPM.addPass(ThinLTOBitcodeWriterPass(
1039 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
1041 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1047 bool EmitLTOSummary = shouldEmitRegularLTOSummary();
1048 if (EmitLTOSummary) {
1049 if (!TheModule->getModuleFlag(
"ThinLTO") && !CodeGenOpts.UnifiedLTO)
1050 TheModule->addModuleFlag(llvm::Module::Error,
"ThinLTO", uint32_t(0));
1051 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1052 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1054 if (CodeGenOpts.UnifiedLTO)
1055 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO", uint32_t(1));
1058 MPM.addPass(BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists,
1061 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists,
1065 if (CodeGenOpts.FatLTO) {
1068 if (!TheModule->getModuleFlag(
"ThinLTO"))
1069 TheModule->addModuleFlag(llvm::Module::Error,
"ThinLTO",
1070 uint32_t(CodeGenOpts.PrepareForThinLTO));
1071 if (!TheModule->getModuleFlag(
"EnableSplitLTOUnit"))
1072 TheModule->addModuleFlag(llvm::Module::Error,
"EnableSplitLTOUnit",
1073 uint32_t(CodeGenOpts.EnableSplitLTOUnit));
1075 if (!TheModule->getModuleFlag(
"UnifiedLTO"))
1076 TheModule->addModuleFlag(llvm::Module::Error,
"UnifiedLTO", uint32_t(1));
1082 MPM.printPipeline(outs(), [&PIC](StringRef ClassName) {
1083 auto PassName = PIC.getPassNameForClassName(ClassName);
1084 return PassName.empty() ? ClassName : PassName;
1090 if (LangOpts.HIPStdPar && !LangOpts.CUDAIsDevice &&
1091 LangOpts.HIPStdParInterposeAlloc)
1092 MPM.addPass(HipStdParAllocationInterpositionPass());
1096 PrettyStackTraceString CrashInfo(
"Optimizer");
1097 llvm::TimeTraceScope TimeScope(
"Optimizer");
1098 MPM.run(*TheModule, MAM);
1102void EmitAssemblyHelper::RunCodegenPipeline(
1103 BackendAction Action, std::unique_ptr<raw_pwrite_stream> &OS,
1104 std::unique_ptr<llvm::ToolOutputFile> &DwoOS) {
1108 legacy::PassManager CodeGenPasses;
1116 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1122 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1123 DwoOS ? &DwoOS->os() :
nullptr))
1139 PrettyStackTraceString CrashInfo(
"Code generation");
1140 llvm::TimeTraceScope TimeScope(
"CodeGenPasses");
1141 CodeGenPasses.run(*TheModule);
1146 std::unique_ptr<raw_pwrite_stream> OS,
1148 TimeRegion Region(CodeGenOpts.TimePasses ? &CodeGenerationTime :
nullptr);
1152 CreateTargetMachine(RequiresCodeGen);
1154 if (RequiresCodeGen && !TM)
1157 TheModule->setDataLayout(TM->createDataLayout());
1160 cl::PrintOptionValues();
1162 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1163 RunOptimizationPipeline(Action, OS, ThinLinkOS, BC);
1164 RunCodegenPipeline(Action, OS, DwoOS);
1176 const LangOptions &LOpts, std::unique_ptr<raw_pwrite_stream> OS,
1177 std::string SampleProfile, std::string ProfileRemapping,
1179 DenseMap<StringRef, DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1180 ModuleToDefinedGVSummaries;
1181 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1188 FunctionImporter::ImportMapTy ImportList;
1189 if (!lto::initImportList(*M, *CombinedIndex, ImportList))
1192 auto AddStream = [&](
size_t Task,
const Twine &ModuleName) {
1193 return std::make_unique<CachedFileStream>(std::move(OS),
1200 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1201 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1206 Conf.CPU = TOpts.
CPU;
1210 std::optional<CodeGenOptLevel> OptLevelOrNone =
1211 CodeGenOpt::getLevel(CGOpts.OptimizationLevel);
1212 assert(OptLevelOrNone &&
"Invalid optimization level!");
1213 Conf.CGOptLevel = *OptLevelOrNone;
1214 Conf.OptLevel = CGOpts.OptimizationLevel;
1216 Conf.SampleProfile = std::move(SampleProfile);
1217 Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
1220 Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
1221 Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
1222 Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1225 Conf.PTO.CallGraphProfile = !CGOpts.DisableIntegratedAS;
1229 Conf.RunCSIRInstr =
true;
1232 Conf.RunCSIRInstr =
false;
1236 Conf.ProfileRemapping = std::move(ProfileRemapping);
1237 Conf.DebugPassManager = CGOpts.DebugPassManager;
1238 Conf.VerifyEach = CGOpts.VerifyEach;
1239 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1247 Conf.PreCodeGenModuleHook = [](
size_t Task,
const llvm::Module &Mod) {
1252 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1253 M->print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1258 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const llvm::Module &Mod) {
1259 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1268 thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1269 ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
1271 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1272 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1280 const LangOptions &LOpts, StringRef TDesc, llvm::Module *M,
1284 llvm::TimeTraceScope TimeScope(
"Backend");
1286 std::unique_ptr<llvm::Module> EmptyModule;
1291 std::unique_ptr<ModuleSummaryIndex> CombinedIndex;
1292 if (Error E = llvm::getModuleSummaryIndexForFile(
1295 .moveInto(CombinedIndex)) {
1296 logAllUnhandledErrors(std::move(E), errs(),
1297 "Error loading index file '" +
1305 if (CombinedIndex) {
1306 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1318 EmptyModule = std::make_unique<llvm::Module>(
"empty", M->getContext());
1319 EmptyModule->setTargetTriple(M->getTargetTriple());
1320 M = EmptyModule.get();
1324 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M, VFS);
1325 AsmHelper.EmitAssembly(Action, std::move(OS), BC);
1330 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1331 if (DLDesc != TDesc) {
1334 "expected target description '%1'");
1335 Diags.
Report(DiagID) << DLDesc << TDesc;
1343 llvm::MemoryBufferRef Buf) {
1346 llvm::embedBitcodeInModule(
1358 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> ObjectOrErr =
1359 llvm::MemoryBuffer::getFileOrSTDIN(OffloadObject);
1360 if (ObjectOrErr.getError()) {
1362 "could not open '%0' for embedding");
1363 Diags.
Report(DiagID) << OffloadObject;
1367 llvm::embedBufferInModule(*M, **ObjectOrErr,
".llvm.offloading",
1368 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.
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
static cl::opt< bool > ClSanitizeOnOptimizerEarlyEP("sanitizer-early-opt-ep", cl::Optional, cl::desc("Insert sanitizers on OptimizerEarlyEP."), cl::init(false))
cl::opt< bool > ClRelinkBuiltinBitcodePostop
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.