18 #include "llvm/ADT/SmallSet.h" 19 #include "llvm/ADT/StringExtras.h" 20 #include "llvm/ADT/StringSwitch.h" 21 #include "llvm/ADT/Triple.h" 22 #include "llvm/Analysis/TargetLibraryInfo.h" 23 #include "llvm/Analysis/TargetTransformInfo.h" 24 #include "llvm/Bitcode/BitcodeReader.h" 25 #include "llvm/Bitcode/BitcodeWriter.h" 26 #include "llvm/Bitcode/BitcodeWriterPass.h" 27 #include "llvm/CodeGen/RegAllocRegistry.h" 28 #include "llvm/CodeGen/SchedulerRegistry.h" 29 #include "llvm/CodeGen/TargetSubtargetInfo.h" 30 #include "llvm/IR/DataLayout.h" 31 #include "llvm/IR/IRPrintingPasses.h" 32 #include "llvm/IR/LegacyPassManager.h" 33 #include "llvm/IR/Module.h" 34 #include "llvm/IR/ModuleSummaryIndex.h" 35 #include "llvm/IR/Verifier.h" 36 #include "llvm/LTO/LTOBackend.h" 37 #include "llvm/MC/MCAsmInfo.h" 38 #include "llvm/MC/SubtargetFeature.h" 39 #include "llvm/Passes/PassBuilder.h" 40 #include "llvm/Support/BuryPointer.h" 41 #include "llvm/Support/CommandLine.h" 42 #include "llvm/Support/MemoryBuffer.h" 43 #include "llvm/Support/PrettyStackTrace.h" 44 #include "llvm/Support/TargetRegistry.h" 45 #include "llvm/Support/Timer.h" 46 #include "llvm/Support/raw_ostream.h" 47 #include "llvm/Target/TargetMachine.h" 48 #include "llvm/Target/TargetOptions.h" 49 #include "llvm/Transforms/Coroutines.h" 50 #include "llvm/Transforms/IPO.h" 51 #include "llvm/Transforms/IPO/AlwaysInliner.h" 52 #include "llvm/Transforms/IPO/PassManagerBuilder.h" 53 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" 54 #include "llvm/Transforms/InstCombine/InstCombine.h" 55 #include "llvm/Transforms/Instrumentation.h" 56 #include "llvm/Transforms/Instrumentation/BoundsChecking.h" 57 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" 58 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" 59 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" 60 #include "llvm/Transforms/ObjCARC.h" 61 #include "llvm/Transforms/Scalar.h" 62 #include "llvm/Transforms/Scalar/GVN.h" 63 #include "llvm/Transforms/Utils.h" 64 #include "llvm/Transforms/Utils/CanonicalizeAliases.h" 65 #include "llvm/Transforms/Utils/NameAnonGlobals.h" 66 #include "llvm/Transforms/Utils/SymbolRewriter.h" 68 using namespace clang;
74 static constexpr
StringLiteral DefaultProfileGenName =
"default_%m.profraw";
76 class EmitAssemblyHelper {
84 Timer CodeGenerationTime;
86 std::unique_ptr<raw_pwrite_stream>
OS;
88 TargetIRAnalysis getTargetIRAnalysis()
const {
90 return TM->getTargetIRAnalysis();
92 return TargetIRAnalysis();
95 void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM);
105 void CreateTargetMachine(
bool MustCreateTM);
110 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
111 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
113 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
115 auto F = llvm::make_unique<llvm::ToolOutputFile>(Path, EC,
116 llvm::sys::fs::F_None);
118 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
130 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
131 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
132 CodeGenerationTime(
"codegen",
"Code Generation Time") {}
134 ~EmitAssemblyHelper() {
135 if (CodeGenOpts.DisableFree)
136 BuryPointer(std::move(TM));
139 std::unique_ptr<TargetMachine> TM;
142 std::unique_ptr<raw_pwrite_stream> OS);
145 std::unique_ptr<raw_pwrite_stream> OS);
150 class PassManagerBuilderWrapper :
public PassManagerBuilder {
152 PassManagerBuilderWrapper(
const Triple &TargetTriple,
155 : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
156 LangOpts(LangOpts) {}
157 const Triple &getTargetTriple()
const {
return TargetTriple; }
159 const LangOptions &getLangOpts()
const {
return LangOpts; }
162 const Triple &TargetTriple;
169 if (Builder.OptLevel > 0)
170 PM.add(createObjCARCAPElimPass());
174 if (Builder.OptLevel > 0)
175 PM.add(createObjCARCExpandPass());
179 if (Builder.OptLevel > 0)
180 PM.add(createObjCARCOptPass());
184 legacy::PassManagerBase &PM) {
185 PM.add(createAddDiscriminatorsPass());
189 legacy::PassManagerBase &PM) {
190 PM.add(createBoundsCheckingLegacyPass());
194 legacy::PassManagerBase &PM) {
195 const PassManagerBuilderWrapper &BuilderWrapper =
196 static_cast<const PassManagerBuilderWrapper&
>(Builder);
198 SanitizerCoverageOptions Opts;
201 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
202 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
203 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
204 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
205 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
206 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
207 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
208 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
209 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
210 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
211 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
212 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
213 PM.add(createSanitizerCoverageModulePass(Opts));
221 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
223 switch (T.getObjectFormat()) {
228 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
235 legacy::PassManagerBase &PM) {
236 const PassManagerBuilderWrapper &BuilderWrapper =
237 static_cast<const PassManagerBuilderWrapper&
>(Builder);
238 const Triple &T = BuilderWrapper.getTargetTriple();
241 bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
242 bool UseOdrIndicator = CGOpts.SanitizeAddressUseOdrIndicator;
244 PM.add(createAddressSanitizerFunctionPass(
false, Recover,
246 PM.add(createAddressSanitizerModulePass(
false, Recover,
247 UseGlobalsGC, UseOdrIndicator));
251 legacy::PassManagerBase &PM) {
252 PM.add(createAddressSanitizerFunctionPass(
254 PM.add(createAddressSanitizerModulePass(
260 legacy::PassManagerBase &PM) {
261 const PassManagerBuilderWrapper &BuilderWrapper =
262 static_cast<const PassManagerBuilderWrapper &
>(Builder);
265 PM.add(createHWAddressSanitizerPass(
false, Recover));
269 legacy::PassManagerBase &PM) {
270 PM.add(createHWAddressSanitizerPass(
275 legacy::PassManagerBase &PM,
276 bool CompileKernel) {
277 const PassManagerBuilderWrapper &BuilderWrapper =
278 static_cast<const PassManagerBuilderWrapper&
>(Builder);
280 int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
282 PM.add(createMemorySanitizerLegacyPassPass(TrackOrigins, Recover, CompileKernel));
287 if (Builder.OptLevel > 0) {
288 PM.add(createEarlyCSEPass());
289 PM.add(createReassociatePass());
290 PM.add(createLICMPass());
291 PM.add(createGVNPass());
292 PM.add(createInstructionCombiningPass());
293 PM.add(createDeadStoreEliminationPass());
298 legacy::PassManagerBase &PM) {
303 legacy::PassManagerBase &PM) {
308 legacy::PassManagerBase &PM) {
309 PM.add(createThreadSanitizerLegacyPassPass());
313 legacy::PassManagerBase &PM) {
314 const PassManagerBuilderWrapper &BuilderWrapper =
315 static_cast<const PassManagerBuilderWrapper&
>(Builder);
316 const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
321 legacy::PassManagerBase &PM) {
322 const PassManagerBuilderWrapper &BuilderWrapper =
323 static_cast<const PassManagerBuilderWrapper&
>(Builder);
324 const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
325 EfficiencySanitizerOptions Opts;
326 if (LangOpts.
Sanitize.
has(SanitizerKind::EfficiencyCacheFrag))
327 Opts.ToolType = EfficiencySanitizerOptions::ESAN_CacheFrag;
328 else if (LangOpts.
Sanitize.
has(SanitizerKind::EfficiencyWorkingSet))
329 Opts.ToolType = EfficiencySanitizerOptions::ESAN_WorkingSet;
330 PM.add(createEfficiencySanitizerPass(Opts));
333 static TargetLibraryInfoImpl *
createTLII(llvm::Triple &TargetTriple,
335 TargetLibraryInfoImpl *TLII =
new TargetLibraryInfoImpl(TargetTriple);
336 if (!CodeGenOpts.SimplifyLibCalls)
337 TLII->disableAllFunctions();
342 if (TLII->getLibFunc(FuncName, F))
343 TLII->setUnavailable(F);
346 switch (CodeGenOpts.getVecLib()) {
348 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate);
351 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
360 legacy::PassManager *MPM) {
361 llvm::SymbolRewriter::RewriteDescriptorList DL;
363 llvm::SymbolRewriter::RewriteMapParser MapParser;
365 MapParser.parse(MapFile, &DL);
367 MPM->add(createRewriteSymbolsPass(DL));
371 switch (CodeGenOpts.OptimizationLevel) {
373 llvm_unreachable(
"Invalid optimization level!");
381 return CodeGenOpt::Aggressive;
387 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
388 .Case(
"tiny", llvm::CodeModel::Tiny)
389 .Case(
"small", llvm::CodeModel::Small)
390 .Case(
"kernel", llvm::CodeModel::Kernel)
391 .Case(
"medium", llvm::CodeModel::Medium)
392 .Case(
"large", llvm::CodeModel::Large)
393 .Case(
"default", ~1u)
395 assert(CodeModel != ~0u &&
"invalid code model!");
396 if (CodeModel == ~1u)
398 return static_cast<llvm::CodeModel::Model
>(CodeModel);
403 return TargetMachine::CGFT_ObjectFile;
405 return TargetMachine::CGFT_Null;
408 return TargetMachine::CGFT_AssemblyFile;
417 Options.ThreadModel =
418 llvm::StringSwitch<llvm::ThreadModel::Model>(CodeGenOpts.
ThreadModel)
419 .Case(
"posix", llvm::ThreadModel::POSIX)
420 .Case(
"single", llvm::ThreadModel::Single);
423 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
425 "Invalid Floating Point ABI!");
426 Options.FloatABIType =
427 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
428 .Case(
"soft", llvm::FloatABI::Soft)
429 .Case(
"softfp", llvm::FloatABI::Soft)
430 .Case(
"hard", llvm::FloatABI::Hard)
431 .Default(llvm::FloatABI::Default);
434 switch (LangOpts.getDefaultFPContractMode()) {
438 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
441 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
444 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
448 Options.UseInitArray = CodeGenOpts.UseInitArray;
449 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
450 Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
451 Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
456 if (LangOpts.SjLjExceptions)
457 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
458 if (LangOpts.SEHExceptions)
459 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
460 if (LangOpts.DWARFExceptions)
461 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
463 Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath;
464 Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath;
465 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
466 Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
467 Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
468 Options.FunctionSections = CodeGenOpts.FunctionSections;
469 Options.DataSections = CodeGenOpts.DataSections;
470 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
471 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
472 Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
473 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
474 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
475 Options.EmitAddrsig = CodeGenOpts.Addrsig;
479 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
480 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
481 Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
482 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
483 Options.MCOptions.MCIncrementalLinkerCompatible =
484 CodeGenOpts.IncrementalLinkerCompatible;
485 Options.MCOptions.MCPIECopyRelocations = CodeGenOpts.PIECopyRelocations;
486 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
487 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
488 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
489 Options.MCOptions.ABIName = TargetOpts.
ABI;
491 if (!Entry.IsFramework &&
495 Options.MCOptions.IASSearchPaths.push_back(
496 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
499 if (CodeGenOpts.DisableGCov)
501 if (!CodeGenOpts.EmitGcovArcs && !CodeGenOpts.EmitGcovNotes)
506 Options.EmitNotes = CodeGenOpts.EmitGcovNotes;
507 Options.EmitData = CodeGenOpts.EmitGcovArcs;
509 Options.UseCfgChecksum = CodeGenOpts.CoverageExtraChecksum;
510 Options.NoRedZone = CodeGenOpts.DisableRedZone;
511 Options.FunctionNamesInData = !CodeGenOpts.CoverageNoFunctionNamesInData;
514 Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody;
518 void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
519 legacy::FunctionPassManager &FPM) {
522 if (CodeGenOpts.DisableLLVMPasses)
529 Triple TargetTriple(TheModule->getTargetTriple());
530 std::unique_ptr<TargetLibraryInfoImpl> TLII(
533 PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
537 if (CodeGenOpts.OptimizationLevel <= 1) {
538 bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 &&
539 !CodeGenOpts.DisableLifetimeMarkers);
540 PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics);
545 PMBuilder.Inliner = createFunctionInliningPass(
546 CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize,
548 CodeGenOpts.PrepareForThinLTO));
551 PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
552 PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
553 PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
554 PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
556 PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
557 PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
558 PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
559 PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
560 PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
562 MPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
565 TM->adjustPassManager(PMBuilder);
567 if (CodeGenOpts.DebugInfoForProfiling ||
569 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
573 if (LangOpts.ObjCAutoRefCount) {
574 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
576 PMBuilder.addExtension(PassManagerBuilder::EP_ModuleOptimizerEarly,
578 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
582 if (LangOpts.CoroutinesTS)
583 addCoroutinePassesToExtensionPoints(PMBuilder);
585 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds)) {
586 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
588 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
592 if (CodeGenOpts.SanitizeCoverageType ||
593 CodeGenOpts.SanitizeCoverageIndirectCalls ||
594 CodeGenOpts.SanitizeCoverageTraceCmp) {
595 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
597 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
601 if (LangOpts.
Sanitize.
has(SanitizerKind::Address)) {
602 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
604 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
608 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelAddress)) {
609 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
611 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
615 if (LangOpts.
Sanitize.
has(SanitizerKind::HWAddress)) {
616 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
618 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
622 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelHWAddress)) {
623 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
625 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
629 if (LangOpts.
Sanitize.
has(SanitizerKind::Memory)) {
630 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
632 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
636 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelMemory)) {
637 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
639 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
643 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
644 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
646 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
650 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
651 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
653 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
658 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
660 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
665 FPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
666 if (CodeGenOpts.VerifyModule)
667 FPM.add(createVerifierPass());
674 MPM.add(createGCOVProfilerPass(*Options));
676 MPM.add(createStripSymbolsPass(
true));
680 InstrProfOptions Options;
681 Options.NoRedZone = CodeGenOpts.DisableRedZone;
686 Options.Atomic = LangOpts.
Sanitize.
has(SanitizerKind::Thread);
688 MPM.add(createInstrProfilingLegacyPass(Options));
691 PMBuilder.EnablePGOInstrGen =
true;
695 PMBuilder.PGOInstrGen = DefaultProfileGenName;
703 PMBuilder.populateFunctionPassManager(FPM);
704 PMBuilder.populateModulePassManager(MPM);
709 BackendArgs.push_back(
"clang");
711 BackendArgs.push_back(
"-debug-pass");
712 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
715 BackendArgs.push_back(
"-limit-float-precision");
718 BackendArgs.push_back(
nullptr);
719 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
723 void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
726 std::string Triple = TheModule->getTargetTriple();
727 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
730 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
735 std::string FeaturesStr =
740 llvm::TargetOptions Options;
742 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
743 Options, RM, CM, OptLevel));
746 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
748 raw_pwrite_stream &OS,
749 raw_pwrite_stream *DwoOS) {
751 llvm::Triple TargetTriple(TheModule->getTargetTriple());
752 std::unique_ptr<TargetLibraryInfoImpl> TLII(
754 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
763 if (CodeGenOpts.OptimizationLevel > 0)
764 CodeGenPasses.add(createObjCARCContractPass());
766 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
767 !CodeGenOpts.VerifyModule)) {
768 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
776 std::unique_ptr<raw_pwrite_stream> OS) {
784 CreateTargetMachine(UsesCodeGen);
786 if (UsesCodeGen && !TM)
789 TheModule->setDataLayout(TM->createDataLayout());
791 legacy::PassManager PerModulePasses;
793 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
795 legacy::FunctionPassManager PerFunctionPasses(TheModule);
796 PerFunctionPasses.add(
797 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
799 CreatePasses(PerModulePasses, PerFunctionPasses);
801 legacy::PassManager CodeGenPasses;
803 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
805 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
812 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
818 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
819 CodeGenOpts.EnableSplitLTOUnit);
820 PerModulePasses.add(createWriteThinLTOBitcodePass(
821 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
825 bool EmitLTOSummary =
826 (CodeGenOpts.PrepareForLTO &&
827 !CodeGenOpts.DisableLLVMPasses &&
828 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
829 llvm::Triple::Apple);
830 if (EmitLTOSummary) {
831 if (!TheModule->getModuleFlag(
"ThinLTO"))
832 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
833 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
834 CodeGenOpts.EnableSplitLTOUnit);
837 PerModulePasses.add(createBitcodeWriterPass(
838 *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
844 createPrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
854 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
855 DwoOS ? &DwoOS->os() :
nullptr))
860 cl::PrintOptionValues();
866 PrettyStackTraceString CrashInfo(
"Per-function optimization");
868 PerFunctionPasses.doInitialization();
869 for (Function &F : *TheModule)
870 if (!F.isDeclaration())
871 PerFunctionPasses.run(F);
872 PerFunctionPasses.doFinalization();
876 PrettyStackTraceString CrashInfo(
"Per-module optimization passes");
877 PerModulePasses.run(*TheModule);
881 PrettyStackTraceString CrashInfo(
"Code generation");
882 CodeGenPasses.run(*TheModule);
892 switch (Opts.OptimizationLevel) {
894 llvm_unreachable(
"Invalid optimization level!");
897 return PassBuilder::O1;
900 switch (Opts.OptimizeSize) {
902 llvm_unreachable(
"Invalid optimization level for size!");
905 return PassBuilder::O2;
908 return PassBuilder::Os;
911 return PassBuilder::Oz;
915 return PassBuilder::O3;
927 void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
928 BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {
934 CreateTargetMachine(
true);
938 TheModule->setDataLayout(TM->createDataLayout());
945 ? DefaultProfileGenName
948 CodeGenOpts.DebugInfoForProfiling);
953 CodeGenOpts.DebugInfoForProfiling);
958 CodeGenOpts.DebugInfoForProfiling);
959 else if (CodeGenOpts.DebugInfoForProfiling)
961 PGOOpt = PGOOptions(
"",
"",
"",
"",
false,
true);
963 PassBuilder PB(TM.get(), PGOOpt);
965 LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
966 FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
967 CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
968 ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
971 FAM.registerPass([&] {
return PB.buildDefaultAAPipeline(); });
975 Triple TargetTriple(TheModule->getTargetTriple());
976 std::unique_ptr<TargetLibraryInfoImpl> TLII(
978 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
979 MAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
982 PB.registerModuleAnalyses(MAM);
983 PB.registerCGSCCAnalyses(CGAM);
984 PB.registerFunctionAnalyses(FAM);
985 PB.registerLoopAnalyses(LAM);
986 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
988 ModulePassManager MPM(CodeGenOpts.DebugPassManager);
990 if (!CodeGenOpts.DisableLLVMPasses) {
991 bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
992 bool IsLTO = CodeGenOpts.PrepareForLTO;
994 if (CodeGenOpts.OptimizationLevel == 0) {
996 MPM.addPass(GCOVProfilerPass(*Options));
1000 MPM.addPass(AlwaysInlinerPass());
1003 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1004 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
1007 if (IsLTO || IsThinLTO) {
1008 MPM.addPass(CanonicalizeAliasesPass());
1009 MPM.addPass(NameAnonGlobalPass());
1018 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1019 PB.registerScalarOptimizerLateEPCallback(
1020 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1021 FPM.addPass(BoundsCheckingPass());
1024 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
1025 MPM.addPass(GCOVProfilerPass(*Options));
1029 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
1030 Level, CodeGenOpts.DebugPassManager);
1031 MPM.addPass(CanonicalizeAliasesPass());
1032 MPM.addPass(NameAnonGlobalPass());
1034 MPM = PB.buildLTOPreLinkDefaultPipeline(Level,
1035 CodeGenOpts.DebugPassManager);
1036 MPM.addPass(CanonicalizeAliasesPass());
1037 MPM.addPass(NameAnonGlobalPass());
1039 MPM = PB.buildPerModuleDefaultPipeline(Level,
1040 CodeGenOpts.DebugPassManager);
1047 legacy::PassManager CodeGenPasses;
1048 bool NeedCodeGen =
false;
1049 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1057 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1063 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1064 CodeGenOpts.EnableSplitLTOUnit);
1065 MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os()
1070 bool EmitLTOSummary =
1071 (CodeGenOpts.PrepareForLTO &&
1072 !CodeGenOpts.DisableLLVMPasses &&
1073 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
1074 llvm::Triple::Apple);
1075 if (EmitLTOSummary) {
1076 if (!TheModule->getModuleFlag(
"ThinLTO"))
1077 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
1078 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1079 CodeGenOpts.EnableSplitLTOUnit);
1082 BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
1087 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
1095 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1101 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1102 DwoOS ? &DwoOS->os() :
nullptr))
1109 cl::PrintOptionValues();
1113 PrettyStackTraceString CrashInfo(
"Optimizer");
1114 MPM.run(*TheModule, MAM);
1119 PrettyStackTraceString CrashInfo(
"Code generation");
1120 CodeGenPasses.run(*TheModule);
1132 return BMsOrErr.takeError();
1139 return make_error<StringError>(
"Could not find module summary",
1140 inconvertibleErrorCode());
1144 for (BitcodeModule &BM : BMs) {
1146 if (LTOInfo && LTOInfo->IsThinLTO)
1157 std::unique_ptr<raw_pwrite_stream> OS,
1158 std::string SampleProfile,
1159 std::string ProfileRemapping,
1161 StringMap<DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1162 ModuleToDefinedGVSummaries;
1163 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1170 FunctionImporter::ImportMapTy ImportList;
1171 for (
auto &GlobalList : *CombinedIndex) {
1173 if (GlobalList.second.SummaryList.empty())
1176 auto GUID = GlobalList.first;
1177 for (
auto &Summary : GlobalList.second.SummaryList) {
1180 if (Summary->modulePath() == M->getModuleIdentifier())
1183 ImportList[Summary->modulePath()].insert(GUID);
1187 std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;
1188 MapVector<llvm::StringRef, llvm::BitcodeModule>
ModuleMap;
1190 for (
auto &I : ImportList) {
1191 ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MBOrErr =
1192 llvm::MemoryBuffer::getFile(I.first());
1194 errs() <<
"Error loading imported file '" << I.first()
1195 <<
"': " << MBOrErr.getError().message() <<
"\n";
1201 handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {
1202 errs() <<
"Error loading imported file '" << I.first()
1203 <<
"': " << EIB.message() <<
'\n';
1207 ModuleMap.insert({I.first(), *BMOrErr});
1209 OwnedImports.push_back(std::move(*MBOrErr));
1211 auto AddStream = [&](
size_t Task) {
1212 return llvm::make_unique<lto::NativeObjectStream>(std::move(OS));
1218 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1219 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1224 Conf.CPU = TOpts.
CPU;
1230 Conf.SampleProfile = std::move(SampleProfile);
1231 Conf.ProfileRemapping = std::move(ProfileRemapping);
1232 Conf.UseNewPM = CGOpts.ExperimentalNewPassManager;
1233 Conf.DebugPassManager = CGOpts.DebugPassManager;
1234 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1239 Conf.PreCodeGenModuleHook = [](
size_t Task,
const Module &Mod) {
1244 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1245 M->
print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1250 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1251 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1259 if (
Error E = thinBackend(
1260 Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1261 ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) {
1262 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1263 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1273 const llvm::DataLayout &TDesc,
Module *M,
1275 std::unique_ptr<raw_pwrite_stream> OS) {
1276 std::unique_ptr<llvm::Module> EmptyModule;
1285 logAllUnhandledErrors(IndexOrErr.takeError(), errs(),
1286 "Error loading index file '" +
1290 std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr);
1294 if (CombinedIndex) {
1295 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1297 LOpts, std::move(OS), CGOpts.SampleProfileFile,
1298 CGOpts.ProfileRemappingFile, Action);
1307 EmptyModule = llvm::make_unique<llvm::Module>(
"empty", M->getContext());
1308 EmptyModule->setTargetTriple(M->getTargetTriple());
1309 M = EmptyModule.get();
1313 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
1315 if (CGOpts.ExperimentalNewPassManager)
1316 AsmHelper.EmitAssemblyWithNewPassManager(Action, std::move(OS));
1318 AsmHelper.EmitAssembly(Action, std::move(OS));
1323 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1324 if (DLDesc != TDesc.getStringRepresentation()) {
1327 "expected target description '%1'");
1328 Diags.
Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
1334 switch (T.getObjectFormat()) {
1336 return "__LLVM,__bitcode";
1340 case Triple::UnknownObjectFormat:
1343 llvm_unreachable(
"Unimplemented ObjectFormatType");
1347 switch (T.getObjectFormat()) {
1349 return "__LLVM,__cmdline";
1353 case Triple::UnknownObjectFormat:
1356 llvm_unreachable(
"Unimplemented ObjectFormatType");
1362 llvm::MemoryBufferRef Buf) {
1368 SmallPtrSet<GlobalValue*, 4> UsedGlobals;
1369 Type *UsedElementType = Type::getInt8Ty(M->getContext())->getPointerTo(0);
1370 GlobalVariable *
Used = collectUsedGlobalVariables(*M, UsedGlobals,
true);
1371 for (
auto *GV : UsedGlobals) {
1372 if (GV->getName() !=
"llvm.embedded.module" &&
1373 GV->getName() !=
"llvm.cmdline")
1374 UsedArray.push_back(
1375 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1378 Used->eraseFromParent();
1383 Triple T(M->getTargetTriple());
1388 if (!isBitcode((
const unsigned char *)Buf.getBufferStart(),
1389 (
const unsigned char *)Buf.getBufferEnd())) {
1392 llvm::raw_string_ostream OS(Data);
1393 llvm::WriteBitcodeToFile(*M, OS,
true);
1399 Buf.getBufferSize());
1401 llvm::Constant *ModuleConstant =
1402 llvm::ConstantDataArray::get(M->getContext(), ModuleData);
1403 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1404 *M, ModuleConstant->getType(),
true, llvm::GlobalValue::PrivateLinkage,
1407 UsedArray.push_back(
1408 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1409 if (llvm::GlobalVariable *Old =
1410 M->getGlobalVariable(
"llvm.embedded.module",
true)) {
1411 assert(Old->hasOneUse() &&
1412 "llvm.embedded.module can only be used once in llvm.compiler.used");
1414 Old->eraseFromParent();
1416 GV->setName(
"llvm.embedded.module");
1424 llvm::Constant *CmdConstant =
1425 llvm::ConstantDataArray::get(M->getContext(), CmdData);
1426 GV =
new llvm::GlobalVariable(*M, CmdConstant->getType(),
true,
1427 llvm::GlobalValue::PrivateLinkage,
1430 UsedArray.push_back(
1431 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1432 if (llvm::GlobalVariable *Old =
1433 M->getGlobalVariable(
"llvm.cmdline",
true)) {
1434 assert(Old->hasOneUse() &&
1435 "llvm.cmdline can only be used once in llvm.compiler.used");
1437 Old->eraseFromParent();
1439 GV->setName(
"llvm.cmdline");
1443 if (UsedArray.empty())
1447 ArrayType *ATy = ArrayType::get(UsedElementType, UsedArray.size());
1448 auto *NewUsed =
new GlobalVariable(
1449 *M, ATy,
false, llvm::GlobalValue::AppendingLinkage,
1450 llvm::ConstantArray::get(ATy, UsedArray),
"llvm.compiler.used");
1451 NewUsed->setSection(
"llvm.metadata");
std::string ProfileInstrumentUsePath
Name of the profile file to use as input for -fprofile-instr-use.
Paths for '#include <>' added by '-I'.
static void addObjCARCExpandPass(const PassManagerBuilder &Builder, PassManagerBase &PM)
if(T->getSizeExpr()) TRY_TO(TraverseStmt(T -> getSizeExpr()))
std::string SaveTempsFilePrefix
Prefix to use for -save-temps output.
Emit human-readable LLVM assembly.
DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterat...
Run CodeGen, but don't emit anything.
SanitizerSet Sanitize
Set of enabled sanitizers.
The base class of the type hierarchy.
std::string SampleProfileFile
Name of the profile file to use with -fprofile-sample-use.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
Represents an array type, per C99 6.7.5.2 - Array Declarators.
static void addAddressSanitizerPasses(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static Optional< GCOVOptions > getGCOVOptions(const CodeGenOptions &CodeGenOpts)
std::vector< std::string > RewriteMapFiles
Set of files defining the rules for the symbol rewriting.
Don't emit anything (benchmarking mode)
Options for controlling the target.
std::string SplitDwarfFile
The name for the split debug info file that we'll break out.
static void runThinLTOBackend(ModuleSummaryIndex *CombinedIndex, 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)
std::string DebugPass
Enable additional debugging information.
SanitizerSet SanitizeRecover
Set of sanitizer checks that are non-fatal (i.e.
bool hasOneOf(SanitizerMask K) const
Check if one or more sanitizers are enabled.
std::vector< uint8_t > CmdArgs
List of backend command-line options for -fembed-bitcode.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
std::string CodeModel
The code model to use (-mcmodel).
Describes a module or submodule.
Concrete class used by the front-end to report problems and issues.
static void addThreadSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
Defines the Diagnostic-related interfaces.
static CodeGenOpt::Level getCGOptLevel(const CodeGenOptions &CodeGenOpts)
static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts)
static void addSanitizerCoveragePass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
std::string FloatABI
The ABI to use for passing floating point arguments.
std::string ThreadModel
The thread model to use.
std::string ProfileFilterFiles
Regexes separated by a semi-colon to filter the files to instrument.
std::string ProfileRemappingFile
Name of the profile remapping file to apply to the profile data supplied by -fprofile-sample-use or -...
char CoverageVersion[4]
The version string to put into coverage files.
static void addKernelMemorySanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
std::string LimitFloatPrecision
The float precision limit to use, if non-empty.
for(unsigned I=0, E=TL.getNumArgs();I !=E;++I)
Defines the clang::LangOptions interface.
static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static void addObjCARCAPElimPass(const PassManagerBuilder &Builder, PassManagerBase &PM)
void print(raw_ostream &OS, unsigned Indent=0) const
Print the module map for this module to the given stream.
static TargetLibraryInfoImpl * createTLII(llvm::Triple &TargetTriple, const CodeGenOptions &CodeGenOpts)
static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
Emit native object files.
Emit native assembly files.
std::string CPU
If given, the name of the target CPU to generate code for.
std::string ABI
If given, the name of the target ABI to use.
static void addKernelAddressSanitizerPasses(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static void addSymbolRewriterPass(const CodeGenOptions &Opts, legacy::PassManager *MPM)
static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
Defines the clang::TargetOptions class.
std::vector< std::string > Features
The list of target specific features to enable or disable – this should be a list of strings startin...
static void initTargetOptions(llvm::TargetOptions &Options, const CodeGenOptions &CodeGenOpts, const clang::TargetOptions &TargetOpts, const LangOptions &LangOpts, const HeaderSearchOptions &HSOpts)
static bool asanUseGlobalsGC(const Triple &T, const CodeGenOptions &CGOpts)
unsigned getCustomDiagID(Level L, const char(&FormatString)[N])
Return an ID for a diagnostic with the specified format string and level.
llvm::EABI EABIVersion
The EABI version to use.
'#include ""' paths, added by 'gcc -iquote'.
std::string ThinLTOIndexFile
Name of the function summary index file to use for ThinLTO function importing.
Like Angled, but marks system directories.
static TargetMachine::CodeGenFileType getCodeGenFileType(BackendAction Action)
void EmbedBitcode(llvm::Module *M, const CodeGenOptions &CGOpts, llvm::MemoryBufferRef Buf)
Optional< types::ID > Type
Dataflow Directional Tag Classes.
static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM, bool CompileKernel)
bool FrontendTimesIsEnabled
If the user specifies the -ftime-report argument on an Clang command line then the value of this bool...
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
bool hasProfileIRUse() const
Check if IR level profile use is on.
void EmitBackendOutput(DiagnosticsEngine &Diags, const HeaderSearchOptions &, const CodeGenOptions &CGOpts, const TargetOptions &TOpts, const LangOptions &LOpts, const llvm::DataLayout &TDesc, llvm::Module *M, BackendAction Action, std::unique_ptr< raw_pwrite_stream > OS)
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
llvm::Expected< llvm::BitcodeModule > FindThinLTOModule(llvm::MemoryBufferRef MBRef)
static const char * getSectionNameForBitcode(const Triple &T)
static const char * getSectionNameForCommandline(const Triple &T)
Indicates that the tracking object is a descendant of a referenced-counted OSObject, used in the Darwin kernel.
std::string ProfileExcludeFiles
Regexes separated by a semi-colon to filter the files to not instrument.
static void addBoundsCheckingPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static void addEfficiencySanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static Optional< llvm::CodeModel::Model > getCodeModel(const CodeGenOptions &CodeGenOpts)
CodeGenOptions - Track various options which control how the code is optimized and passed to the back...
static void addObjCARCOptPass(const PassManagerBuilder &Builder, PassManagerBase &PM)
bool hasProfileIRInstr() const
Check if IR level profile instrumentation is on.
const std::vector< std::string > & getNoBuiltinFuncs() const
bool has(SanitizerMask K) const
Check if a certain (single) sanitizer is enabled.
StringLiteral - This represents a string literal expression, e.g.
static void addAddDiscriminatorsPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
std::string InstrProfileOutput
Name of the profile file to use as output for -fprofile-instr-generate and -fprofile-generate.
std::string OptRecordFile
The name of the file to which the backend should save YAML optimization records.
std::string ThinLinkBitcodeFile
Name of a file that can optionally be written with minimized bitcode to be used as input for the Thin...
std::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
static void addMemorySanitizerPass(const PassManagerBuilder &Builder, legacy::PassManagerBase &PM)
static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts)