17 #include "llvm/ADT/SmallSet.h" 18 #include "llvm/ADT/StringExtras.h" 19 #include "llvm/ADT/StringSwitch.h" 20 #include "llvm/ADT/Triple.h" 21 #include "llvm/Analysis/TargetLibraryInfo.h" 22 #include "llvm/Analysis/TargetTransformInfo.h" 23 #include "llvm/Bitcode/BitcodeReader.h" 24 #include "llvm/Bitcode/BitcodeWriter.h" 25 #include "llvm/Bitcode/BitcodeWriterPass.h" 26 #include "llvm/CodeGen/RegAllocRegistry.h" 27 #include "llvm/CodeGen/SchedulerRegistry.h" 28 #include "llvm/CodeGen/TargetSubtargetInfo.h" 29 #include "llvm/IR/DataLayout.h" 30 #include "llvm/IR/IRPrintingPasses.h" 31 #include "llvm/IR/LegacyPassManager.h" 32 #include "llvm/IR/Module.h" 33 #include "llvm/IR/ModuleSummaryIndex.h" 34 #include "llvm/IR/Verifier.h" 35 #include "llvm/LTO/LTOBackend.h" 36 #include "llvm/MC/MCAsmInfo.h" 37 #include "llvm/MC/SubtargetFeature.h" 38 #include "llvm/Passes/PassBuilder.h" 39 #include "llvm/Passes/PassPlugin.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/TimeProfiler.h" 46 #include "llvm/Support/Timer.h" 47 #include "llvm/Support/raw_ostream.h" 48 #include "llvm/Target/TargetMachine.h" 49 #include "llvm/Target/TargetOptions.h" 50 #include "llvm/Transforms/Coroutines.h" 51 #include "llvm/Transforms/IPO.h" 52 #include "llvm/Transforms/IPO/AlwaysInliner.h" 53 #include "llvm/Transforms/IPO/PassManagerBuilder.h" 54 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" 55 #include "llvm/Transforms/InstCombine/InstCombine.h" 56 #include "llvm/Transforms/Instrumentation.h" 57 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" 58 #include "llvm/Transforms/Instrumentation/BoundsChecking.h" 59 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" 60 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" 61 #include "llvm/Transforms/Instrumentation/InstrProfiling.h" 62 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" 63 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" 64 #include "llvm/Transforms/ObjCARC.h" 65 #include "llvm/Transforms/Scalar.h" 66 #include "llvm/Transforms/Scalar/GVN.h" 67 #include "llvm/Transforms/Utils.h" 68 #include "llvm/Transforms/Utils/CanonicalizeAliases.h" 69 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" 70 #include "llvm/Transforms/Utils/NameAnonGlobals.h" 71 #include "llvm/Transforms/Utils/SymbolRewriter.h" 73 using namespace clang;
79 static constexpr
StringLiteral DefaultProfileGenName =
"default_%m.profraw";
81 class EmitAssemblyHelper {
89 Timer CodeGenerationTime;
91 std::unique_ptr<raw_pwrite_stream>
OS;
93 TargetIRAnalysis getTargetIRAnalysis()
const {
95 return TM->getTargetIRAnalysis();
97 return TargetIRAnalysis();
100 void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM);
110 void CreateTargetMachine(
bool MustCreateTM);
115 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
116 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
118 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
120 auto F = llvm::make_unique<llvm::ToolOutputFile>(Path, EC,
121 llvm::sys::fs::F_None);
123 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
135 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
136 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
137 CodeGenerationTime(
"codegen",
"Code Generation Time") {}
139 ~EmitAssemblyHelper() {
140 if (CodeGenOpts.DisableFree)
141 BuryPointer(std::move(TM));
144 std::unique_ptr<TargetMachine> TM;
147 std::unique_ptr<raw_pwrite_stream> OS);
150 std::unique_ptr<raw_pwrite_stream> OS);
155 class PassManagerBuilderWrapper :
public PassManagerBuilder {
157 PassManagerBuilderWrapper(
const Triple &TargetTriple,
160 : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
161 LangOpts(LangOpts) {}
162 const Triple &getTargetTriple()
const {
return TargetTriple; }
164 const LangOptions &getLangOpts()
const {
return LangOpts; }
167 const Triple &TargetTriple;
174 if (Builder.OptLevel > 0)
175 PM.add(createObjCARCAPElimPass());
179 if (Builder.OptLevel > 0)
180 PM.add(createObjCARCExpandPass());
184 if (Builder.OptLevel > 0)
185 PM.add(createObjCARCOptPass());
189 legacy::PassManagerBase &PM) {
190 PM.add(createAddDiscriminatorsPass());
194 legacy::PassManagerBase &PM) {
195 PM.add(createBoundsCheckingLegacyPass());
199 legacy::PassManagerBase &PM) {
200 const PassManagerBuilderWrapper &BuilderWrapper =
201 static_cast<const PassManagerBuilderWrapper&
>(Builder);
203 SanitizerCoverageOptions Opts;
206 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
207 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
208 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
209 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
210 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
211 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
212 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
213 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
214 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
215 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
216 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
217 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
218 PM.add(createSanitizerCoverageModulePass(Opts));
226 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
228 switch (T.getObjectFormat()) {
233 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
240 legacy::PassManagerBase &PM) {
241 const PassManagerBuilderWrapper &BuilderWrapper =
242 static_cast<const PassManagerBuilderWrapper&
>(Builder);
243 const Triple &T = BuilderWrapper.getTargetTriple();
246 bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
247 bool UseOdrIndicator = CGOpts.SanitizeAddressUseOdrIndicator;
249 PM.add(createAddressSanitizerFunctionPass(
false, Recover,
251 PM.add(createModuleAddressSanitizerLegacyPassPass(
252 false, Recover, UseGlobalsGC, UseOdrIndicator));
256 legacy::PassManagerBase &PM) {
257 PM.add(createAddressSanitizerFunctionPass(
259 PM.add(createModuleAddressSanitizerLegacyPassPass(
265 legacy::PassManagerBase &PM) {
266 const PassManagerBuilderWrapper &BuilderWrapper =
267 static_cast<const PassManagerBuilderWrapper &
>(Builder);
271 createHWAddressSanitizerLegacyPassPass(
false, Recover));
275 legacy::PassManagerBase &PM) {
276 PM.add(createHWAddressSanitizerLegacyPassPass(
281 legacy::PassManagerBase &PM,
282 bool CompileKernel) {
283 const PassManagerBuilderWrapper &BuilderWrapper =
284 static_cast<const PassManagerBuilderWrapper&
>(Builder);
286 int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
288 PM.add(createMemorySanitizerLegacyPassPass(
289 MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
294 if (Builder.OptLevel > 0) {
295 PM.add(createEarlyCSEPass());
296 PM.add(createReassociatePass());
297 PM.add(createLICMPass());
298 PM.add(createGVNPass());
299 PM.add(createInstructionCombiningPass());
300 PM.add(createDeadStoreEliminationPass());
305 legacy::PassManagerBase &PM) {
310 legacy::PassManagerBase &PM) {
315 legacy::PassManagerBase &PM) {
316 PM.add(createThreadSanitizerLegacyPassPass());
320 legacy::PassManagerBase &PM) {
321 const PassManagerBuilderWrapper &BuilderWrapper =
322 static_cast<const PassManagerBuilderWrapper&
>(Builder);
323 const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
327 static TargetLibraryInfoImpl *
createTLII(llvm::Triple &TargetTriple,
329 TargetLibraryInfoImpl *TLII =
new TargetLibraryInfoImpl(TargetTriple);
330 if (!CodeGenOpts.SimplifyLibCalls)
331 TLII->disableAllFunctions();
336 if (TLII->getLibFunc(FuncName, F))
337 TLII->setUnavailable(F);
340 switch (CodeGenOpts.getVecLib()) {
342 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate);
345 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::MASSV);
348 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
357 legacy::PassManager *MPM) {
358 llvm::SymbolRewriter::RewriteDescriptorList DL;
360 llvm::SymbolRewriter::RewriteMapParser MapParser;
362 MapParser.parse(MapFile, &DL);
364 MPM->add(createRewriteSymbolsPass(DL));
368 switch (CodeGenOpts.OptimizationLevel) {
370 llvm_unreachable(
"Invalid optimization level!");
378 return CodeGenOpt::Aggressive;
384 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
385 .Case(
"tiny", llvm::CodeModel::Tiny)
386 .Case(
"small", llvm::CodeModel::Small)
387 .Case(
"kernel", llvm::CodeModel::Kernel)
388 .Case(
"medium", llvm::CodeModel::Medium)
389 .Case(
"large", llvm::CodeModel::Large)
390 .Case(
"default", ~1u)
392 assert(CodeModel != ~0u &&
"invalid code model!");
393 if (CodeModel == ~1u)
395 return static_cast<llvm::CodeModel::Model
>(CodeModel);
400 return TargetMachine::CGFT_ObjectFile;
402 return TargetMachine::CGFT_Null;
405 return TargetMachine::CGFT_AssemblyFile;
414 Options.ThreadModel =
415 llvm::StringSwitch<llvm::ThreadModel::Model>(CodeGenOpts.
ThreadModel)
416 .Case(
"posix", llvm::ThreadModel::POSIX)
417 .Case(
"single", llvm::ThreadModel::Single);
420 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
422 "Invalid Floating Point ABI!");
423 Options.FloatABIType =
424 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
425 .Case(
"soft", llvm::FloatABI::Soft)
426 .Case(
"softfp", llvm::FloatABI::Soft)
427 .Case(
"hard", llvm::FloatABI::Hard)
428 .Default(llvm::FloatABI::Default);
431 switch (LangOpts.getDefaultFPContractMode()) {
435 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
438 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
441 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
445 Options.UseInitArray = CodeGenOpts.UseInitArray;
446 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
447 Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
448 Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
453 if (LangOpts.SjLjExceptions)
454 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
455 if (LangOpts.SEHExceptions)
456 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
457 if (LangOpts.DWARFExceptions)
458 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
460 Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath;
461 Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath;
462 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
463 Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
464 Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
465 Options.FunctionSections = CodeGenOpts.FunctionSections;
466 Options.DataSections = CodeGenOpts.DataSections;
467 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
468 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
469 Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
470 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
471 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
472 Options.EmitAddrsig = CodeGenOpts.Addrsig;
473 Options.EnableDebugEntryValues = CodeGenOpts.EnableDebugEntryValues;
476 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
477 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
478 Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
479 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
480 Options.MCOptions.MCIncrementalLinkerCompatible =
481 CodeGenOpts.IncrementalLinkerCompatible;
482 Options.MCOptions.MCPIECopyRelocations = CodeGenOpts.PIECopyRelocations;
483 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
484 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
485 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
486 Options.MCOptions.ABIName = TargetOpts.
ABI;
488 if (!Entry.IsFramework &&
492 Options.MCOptions.IASSearchPaths.push_back(
493 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
496 if (CodeGenOpts.DisableGCov)
498 if (!CodeGenOpts.EmitGcovArcs && !CodeGenOpts.EmitGcovNotes)
503 Options.EmitNotes = CodeGenOpts.EmitGcovNotes;
504 Options.EmitData = CodeGenOpts.EmitGcovArcs;
506 Options.UseCfgChecksum = CodeGenOpts.CoverageExtraChecksum;
507 Options.NoRedZone = CodeGenOpts.DisableRedZone;
508 Options.FunctionNamesInData = !CodeGenOpts.CoverageNoFunctionNamesInData;
511 Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody;
520 InstrProfOptions Options;
521 Options.NoRedZone = CodeGenOpts.DisableRedZone;
526 Options.Atomic = LangOpts.
Sanitize.
has(SanitizerKind::Thread);
530 void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
531 legacy::FunctionPassManager &FPM) {
534 if (CodeGenOpts.DisableLLVMPasses)
541 Triple TargetTriple(TheModule->getTargetTriple());
542 std::unique_ptr<TargetLibraryInfoImpl> TLII(
545 PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
549 if (CodeGenOpts.OptimizationLevel <= 1) {
550 bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 &&
551 !CodeGenOpts.DisableLifetimeMarkers);
552 PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics);
557 PMBuilder.Inliner = createFunctionInliningPass(
558 CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize,
560 CodeGenOpts.PrepareForThinLTO));
563 PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
564 PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
565 PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
566 PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
568 PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
571 PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops;
572 PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
573 PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
574 PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
575 PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
577 MPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
580 TM->adjustPassManager(PMBuilder);
582 if (CodeGenOpts.DebugInfoForProfiling ||
584 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
588 if (LangOpts.ObjCAutoRefCount) {
589 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
591 PMBuilder.addExtension(PassManagerBuilder::EP_ModuleOptimizerEarly,
593 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
597 if (LangOpts.Coroutines)
598 addCoroutinePassesToExtensionPoints(PMBuilder);
600 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds)) {
601 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
603 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
607 if (CodeGenOpts.SanitizeCoverageType ||
608 CodeGenOpts.SanitizeCoverageIndirectCalls ||
609 CodeGenOpts.SanitizeCoverageTraceCmp) {
610 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
612 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
616 if (LangOpts.
Sanitize.
has(SanitizerKind::Address)) {
617 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
619 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
623 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelAddress)) {
624 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
626 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
630 if (LangOpts.
Sanitize.
has(SanitizerKind::HWAddress)) {
631 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
633 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
637 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelHWAddress)) {
638 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
640 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
644 if (LangOpts.
Sanitize.
has(SanitizerKind::Memory)) {
645 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
647 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
651 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelMemory)) {
652 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
654 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
658 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
659 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
661 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
665 if (LangOpts.
Sanitize.
has(SanitizerKind::DataFlow)) {
666 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
668 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
673 FPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
674 if (CodeGenOpts.VerifyModule)
675 FPM.add(createVerifierPass());
682 MPM.add(createGCOVProfilerPass(*Options));
684 MPM.add(createStripSymbolsPass(
true));
689 MPM.add(createInstrProfilingLegacyPass(*Options,
false));
691 bool hasIRInstr =
false;
693 PMBuilder.EnablePGOInstrGen =
true;
698 "Cannot have both CSProfileUse pass and CSProfileGen pass at the " 700 assert(!hasIRInstr &&
701 "Cannot have both ProfileGen pass and CSProfileGen pass at the " 703 PMBuilder.EnablePGOCSInstrGen =
true;
710 PMBuilder.PGOInstrGen = DefaultProfileGenName;
720 PMBuilder.populateFunctionPassManager(FPM);
721 PMBuilder.populateModulePassManager(MPM);
726 BackendArgs.push_back(
"clang");
728 BackendArgs.push_back(
"-debug-pass");
729 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
732 BackendArgs.push_back(
"-limit-float-precision");
735 BackendArgs.push_back(
nullptr);
736 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
740 void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
743 std::string Triple = TheModule->getTargetTriple();
744 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
747 Diags.
Report(diag::err_fe_unable_to_create_target) <<
Error;
752 std::string FeaturesStr =
757 llvm::TargetOptions Options;
759 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.
CPU, FeaturesStr,
760 Options, RM, CM, OptLevel));
763 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
765 raw_pwrite_stream &OS,
766 raw_pwrite_stream *DwoOS) {
768 llvm::Triple TargetTriple(TheModule->getTargetTriple());
769 std::unique_ptr<TargetLibraryInfoImpl> TLII(
771 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
780 if (CodeGenOpts.OptimizationLevel > 0)
781 CodeGenPasses.add(createObjCARCContractPass());
783 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
784 !CodeGenOpts.VerifyModule)) {
785 Diags.
Report(diag::err_fe_unable_to_interface_with_target);
793 std::unique_ptr<raw_pwrite_stream> OS) {
801 CreateTargetMachine(UsesCodeGen);
803 if (UsesCodeGen && !TM)
806 TheModule->setDataLayout(TM->createDataLayout());
808 legacy::PassManager PerModulePasses;
810 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
812 legacy::FunctionPassManager PerFunctionPasses(TheModule);
813 PerFunctionPasses.add(
814 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
816 CreatePasses(PerModulePasses, PerFunctionPasses);
818 legacy::PassManager CodeGenPasses;
820 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
822 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
829 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
835 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
836 CodeGenOpts.EnableSplitLTOUnit);
837 PerModulePasses.add(createWriteThinLTOBitcodePass(
838 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
842 bool EmitLTOSummary =
843 (CodeGenOpts.PrepareForLTO &&
844 !CodeGenOpts.DisableLLVMPasses &&
845 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
846 llvm::Triple::Apple);
847 if (EmitLTOSummary) {
848 if (!TheModule->getModuleFlag(
"ThinLTO"))
849 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
850 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
851 CodeGenOpts.EnableSplitLTOUnit);
854 PerModulePasses.add(createBitcodeWriterPass(
855 *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
861 createPrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
870 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
871 DwoOS ? &DwoOS->os() :
nullptr))
876 cl::PrintOptionValues();
882 PrettyStackTraceString CrashInfo(
"Per-function optimization");
884 PerFunctionPasses.doInitialization();
885 for (Function &F : *TheModule)
886 if (!F.isDeclaration())
887 PerFunctionPasses.run(F);
888 PerFunctionPasses.doFinalization();
892 PrettyStackTraceString CrashInfo(
"Per-module optimization passes");
893 PerModulePasses.run(*TheModule);
897 PrettyStackTraceString CrashInfo(
"Code generation");
898 CodeGenPasses.run(*TheModule);
908 switch (Opts.OptimizationLevel) {
910 llvm_unreachable(
"Invalid optimization level!");
913 return PassBuilder::O1;
916 switch (Opts.OptimizeSize) {
918 llvm_unreachable(
"Invalid optimization level for size!");
921 return PassBuilder::O2;
924 return PassBuilder::Os;
927 return PassBuilder::Oz;
931 return PassBuilder::O3;
936 const Triple &TargetTriple,
939 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
940 MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
942 MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(
943 CompileKernel, Recover, CodeGenOpts.SanitizeAddressUseAfterScope)));
946 ModuleAddressSanitizerPass(CompileKernel, Recover, ModuleUseAfterScope,
947 CodeGenOpts.SanitizeAddressUseOdrIndicator));
950 if (LangOpts.
Sanitize.
has(SanitizerKind::Address)) {
951 ASanPass(SanitizerKind::Address,
false);
954 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelAddress)) {
955 ASanPass(SanitizerKind::KernelAddress,
true);
958 if (LangOpts.
Sanitize.
has(SanitizerKind::Memory)) {
959 MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
962 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelMemory)) {
963 MPM.addPass(createModuleToFunctionPassAdaptor(
964 MemorySanitizerPass({0,
false,
true})));
967 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
968 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
980 void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
981 BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {
988 CreateTargetMachine(RequiresCodeGen);
990 if (RequiresCodeGen && !TM)
993 TheModule->setDataLayout(TM->createDataLayout());
1000 ? DefaultProfileGenName
1002 "",
"", PGOOptions::IRInstr, PGOOptions::NoCSAction,
1003 CodeGenOpts.DebugInfoForProfiling);
1007 : PGOOptions::NoCSAction;
1010 CSAction, CodeGenOpts.DebugInfoForProfiling);
1016 PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
1017 else if (CodeGenOpts.DebugInfoForProfiling)
1019 PGOOpt = PGOOptions(
"",
"",
"", PGOOptions::NoAction,
1020 PGOOptions::NoCSAction,
true);
1025 "Cannot have both CSProfileUse pass and CSProfileGen pass at " 1027 if (PGOOpt.hasValue()) {
1028 assert(PGOOpt->Action != PGOOptions::IRInstr &&
1029 PGOOpt->Action != PGOOptions::SampleUse &&
1030 "Cannot run CSProfileGen pass with ProfileGen or SampleUse " 1033 ? DefaultProfileGenName
1035 PGOOpt->CSAction = PGOOptions::CSIRInstr;
1037 PGOOpt = PGOOptions(
"",
1039 ? DefaultProfileGenName
1041 "", PGOOptions::NoAction, PGOOptions::CSIRInstr,
1042 CodeGenOpts.DebugInfoForProfiling);
1045 PipelineTuningOptions PTO;
1046 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
1049 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
1050 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
1051 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
1053 PassBuilder PB(TM.get(), PTO, PGOOpt);
1057 auto PassPlugin = PassPlugin::Load(PluginFN);
1059 PassPlugin->registerPassBuilderCallbacks(PB);
1061 Diags.
Report(diag::err_fe_unable_to_load_plugin)
1062 << PluginFN <<
toString(PassPlugin.takeError());
1066 LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
1067 FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
1068 CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
1069 ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
1072 FAM.registerPass([&] {
return PB.buildDefaultAAPipeline(); });
1076 Triple TargetTriple(TheModule->getTargetTriple());
1077 std::unique_ptr<TargetLibraryInfoImpl> TLII(
1079 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
1080 MAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
1083 PB.registerModuleAnalyses(MAM);
1084 PB.registerCGSCCAnalyses(CGAM);
1085 PB.registerFunctionAnalyses(FAM);
1086 PB.registerLoopAnalyses(LAM);
1087 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1089 ModulePassManager MPM(CodeGenOpts.DebugPassManager);
1091 if (!CodeGenOpts.DisableLLVMPasses) {
1092 bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
1093 bool IsLTO = CodeGenOpts.PrepareForLTO;
1095 if (CodeGenOpts.OptimizationLevel == 0) {
1097 MPM.addPass(GCOVProfilerPass(*Options));
1100 MPM.addPass(InstrProfiling(*Options,
false));
1106 MPM.addPass(AlwaysInlinerPass(
false));
1109 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1110 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
1113 if (IsLTO || IsThinLTO) {
1114 MPM.addPass(CanonicalizeAliasesPass());
1115 MPM.addPass(NameAnonGlobalPass());
1122 PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
1123 MPM.addPass(createModuleToFunctionPassAdaptor(
1124 EntryExitInstrumenterPass(
false)));
1130 if (LangOpts.
Sanitize.
has(SanitizerKind::LocalBounds))
1131 PB.registerScalarOptimizerLateEPCallback(
1132 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1133 FPM.addPass(BoundsCheckingPass());
1136 PB.registerOptimizerLastEPCallback(
1137 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1138 FPM.addPass(MemorySanitizerPass({}));
1141 PB.registerOptimizerLastEPCallback(
1142 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel
Level) {
1143 FPM.addPass(ThreadSanitizerPass());
1145 if (LangOpts.
Sanitize.
has(SanitizerKind::Address)) {
1146 PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM) {
1148 RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
1151 bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
1152 PB.registerOptimizerLastEPCallback(
1153 [Recover, UseAfterScope](FunctionPassManager &FPM,
1154 PassBuilder::OptimizationLevel Level) {
1155 FPM.addPass(AddressSanitizerPass(
1156 false, Recover, UseAfterScope));
1159 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
1160 PB.registerPipelineStartEPCallback(
1161 [Recover, ModuleUseAfterScope,
1162 UseOdrIndicator](ModulePassManager &MPM) {
1163 MPM.addPass(ModuleAddressSanitizerPass(
1164 false, Recover, ModuleUseAfterScope,
1169 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
1170 MPM.addPass(GCOVProfilerPass(*Options));
1174 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
1175 MPM.addPass(InstrProfiling(*Options,
false));
1179 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
1180 Level, CodeGenOpts.DebugPassManager);
1181 MPM.addPass(CanonicalizeAliasesPass());
1182 MPM.addPass(NameAnonGlobalPass());
1184 MPM = PB.buildLTOPreLinkDefaultPipeline(Level,
1185 CodeGenOpts.DebugPassManager);
1186 MPM.addPass(CanonicalizeAliasesPass());
1187 MPM.addPass(NameAnonGlobalPass());
1189 MPM = PB.buildPerModuleDefaultPipeline(Level,
1190 CodeGenOpts.DebugPassManager);
1194 if (LangOpts.
Sanitize.
has(SanitizerKind::HWAddress)) {
1196 MPM.addPass(HWAddressSanitizerPass(
1199 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelHWAddress)) {
1200 MPM.addPass(HWAddressSanitizerPass(
1204 if (CodeGenOpts.OptimizationLevel == 0)
1210 legacy::PassManager CodeGenPasses;
1211 bool NeedCodeGen =
false;
1212 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1220 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1226 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1227 CodeGenOpts.EnableSplitLTOUnit);
1228 MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os()
1233 bool EmitLTOSummary =
1234 (CodeGenOpts.PrepareForLTO &&
1235 !CodeGenOpts.DisableLLVMPasses &&
1236 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
1237 llvm::Triple::Apple);
1238 if (EmitLTOSummary) {
1239 if (!TheModule->getModuleFlag(
"ThinLTO"))
1240 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
1241 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1242 CodeGenOpts.EnableSplitLTOUnit);
1245 BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
1250 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
1258 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1264 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1265 DwoOS ? &DwoOS->os() :
nullptr))
1272 cl::PrintOptionValues();
1276 PrettyStackTraceString CrashInfo(
"Optimizer");
1277 MPM.run(*TheModule, MAM);
1282 PrettyStackTraceString CrashInfo(
"Code generation");
1283 CodeGenPasses.run(*TheModule);
1295 return BMsOrErr.takeError();
1302 return make_error<StringError>(
"Could not find module summary",
1303 inconvertibleErrorCode());
1307 for (BitcodeModule &BM : BMs) {
1309 if (LTOInfo && LTOInfo->IsThinLTO)
1320 std::unique_ptr<raw_pwrite_stream> OS,
1321 std::string SampleProfile,
1322 std::string ProfileRemapping,
1324 StringMap<DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1325 ModuleToDefinedGVSummaries;
1326 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1333 FunctionImporter::ImportMapTy ImportList;
1334 for (
auto &GlobalList : *CombinedIndex) {
1336 if (GlobalList.second.SummaryList.empty())
1339 auto GUID = GlobalList.first;
1340 for (
auto &Summary : GlobalList.second.SummaryList) {
1343 if (Summary->modulePath() == M->getModuleIdentifier())
1346 ImportList[Summary->modulePath()].insert(GUID);
1350 std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;
1351 MapVector<llvm::StringRef, llvm::BitcodeModule>
ModuleMap;
1353 for (
auto &I : ImportList) {
1354 ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MBOrErr =
1355 llvm::MemoryBuffer::getFile(I.first());
1357 errs() <<
"Error loading imported file '" << I.first()
1358 <<
"': " << MBOrErr.getError().message() <<
"\n";
1364 handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {
1365 errs() <<
"Error loading imported file '" << I.first()
1366 <<
"': " << EIB.message() <<
'\n';
1370 ModuleMap.insert({I.first(), *BMOrErr});
1372 OwnedImports.push_back(std::move(*MBOrErr));
1374 auto AddStream = [&](
size_t Task) {
1375 return llvm::make_unique<lto::NativeObjectStream>(std::move(OS));
1381 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1382 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1387 Conf.CPU = TOpts.
CPU;
1392 Conf.OptLevel = CGOpts.OptimizationLevel;
1394 Conf.SampleProfile = std::move(SampleProfile);
1398 Conf.RunCSIRInstr =
true;
1401 Conf.RunCSIRInstr =
false;
1405 Conf.ProfileRemapping = std::move(ProfileRemapping);
1406 Conf.UseNewPM = CGOpts.ExperimentalNewPassManager;
1407 Conf.DebugPassManager = CGOpts.DebugPassManager;
1408 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1416 Conf.PreCodeGenModuleHook = [](
size_t Task,
const Module &Mod) {
1421 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1422 M->
print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1427 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1428 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1436 if (
Error E = thinBackend(
1437 Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1438 ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) {
1439 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1440 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1450 const llvm::DataLayout &TDesc,
Module *M,
1452 std::unique_ptr<raw_pwrite_stream> OS) {
1454 llvm::TimeTraceScope TimeScope(
"Backend", StringRef(
""));
1456 std::unique_ptr<llvm::Module> EmptyModule;
1465 logAllUnhandledErrors(IndexOrErr.takeError(), errs(),
1466 "Error loading index file '" +
1470 std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr);
1474 if (CombinedIndex) {
1475 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1477 LOpts, std::move(OS), CGOpts.SampleProfileFile,
1478 CGOpts.ProfileRemappingFile, Action);
1487 EmptyModule = llvm::make_unique<llvm::Module>(
"empty", M->getContext());
1488 EmptyModule->setTargetTriple(M->getTargetTriple());
1489 M = EmptyModule.get();
1493 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
1495 if (CGOpts.ExperimentalNewPassManager)
1496 AsmHelper.EmitAssemblyWithNewPassManager(Action, std::move(OS));
1498 AsmHelper.EmitAssembly(Action, std::move(OS));
1503 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1504 if (DLDesc != TDesc.getStringRepresentation()) {
1507 "expected target description '%1'");
1508 Diags.
Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
1514 switch (T.getObjectFormat()) {
1516 return "__LLVM,__bitcode";
1520 case Triple::UnknownObjectFormat:
1523 llvm_unreachable(
"XCOFF is not yet implemented");
1526 llvm_unreachable(
"Unimplemented ObjectFormatType");
1530 switch (T.getObjectFormat()) {
1532 return "__LLVM,__cmdline";
1536 case Triple::UnknownObjectFormat:
1539 llvm_unreachable(
"XCOFF is not yet implemented");
1542 llvm_unreachable(
"Unimplemented ObjectFormatType");
1548 llvm::MemoryBufferRef Buf) {
1554 SmallPtrSet<GlobalValue*, 4> UsedGlobals;
1555 Type *UsedElementType = Type::getInt8Ty(M->getContext())->getPointerTo(0);
1556 GlobalVariable *
Used = collectUsedGlobalVariables(*M, UsedGlobals,
true);
1557 for (
auto *GV : UsedGlobals) {
1558 if (GV->getName() !=
"llvm.embedded.module" &&
1559 GV->getName() !=
"llvm.cmdline")
1560 UsedArray.push_back(
1561 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1564 Used->eraseFromParent();
1569 Triple T(M->getTargetTriple());
1574 if (!isBitcode((
const unsigned char *)Buf.getBufferStart(),
1575 (
const unsigned char *)Buf.getBufferEnd())) {
1578 llvm::raw_string_ostream OS(Data);
1579 llvm::WriteBitcodeToFile(*M, OS,
true);
1585 Buf.getBufferSize());
1587 llvm::Constant *ModuleConstant =
1588 llvm::ConstantDataArray::get(M->getContext(), ModuleData);
1589 llvm::GlobalVariable *GV =
new llvm::GlobalVariable(
1590 *M, ModuleConstant->getType(),
true, llvm::GlobalValue::PrivateLinkage,
1593 UsedArray.push_back(
1594 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1595 if (llvm::GlobalVariable *Old =
1596 M->getGlobalVariable(
"llvm.embedded.module",
true)) {
1597 assert(Old->hasOneUse() &&
1598 "llvm.embedded.module can only be used once in llvm.compiler.used");
1600 Old->eraseFromParent();
1602 GV->setName(
"llvm.embedded.module");
1610 llvm::Constant *CmdConstant =
1611 llvm::ConstantDataArray::get(M->getContext(), CmdData);
1612 GV =
new llvm::GlobalVariable(*M, CmdConstant->getType(),
true,
1613 llvm::GlobalValue::PrivateLinkage,
1616 UsedArray.push_back(
1617 ConstantExpr::getPointerBitCastOrAddrSpaceCast(GV, UsedElementType));
1618 if (llvm::GlobalVariable *Old =
1619 M->getGlobalVariable(
"llvm.cmdline",
true)) {
1620 assert(Old->hasOneUse() &&
1621 "llvm.cmdline can only be used once in llvm.compiler.used");
1623 Old->eraseFromParent();
1625 GV->setName(
"llvm.cmdline");
1629 if (UsedArray.empty())
1633 ArrayType *ATy = ArrayType::get(UsedElementType, UsedArray.size());
1634 auto *NewUsed =
new GlobalVariable(
1635 *M, ATy,
false, llvm::GlobalValue::AppendingLinkage,
1636 llvm::ConstantArray::get(ATy, UsedArray),
"llvm.compiler.used");
1637 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)
std::string SaveTempsFilePrefix
Prefix to use for -save-temps output.
Emit human-readable LLVM assembly.
Specialize PointerLikeTypeTraits to allow LazyGenerationalUpdatePtr to be placed into a PointerUnion...
Run CodeGen, but don't emit anything.
SanitizerSet Sanitize
Set of enabled sanitizers.
std::string OptRecordPasses
The regex that filters the passes that should be saved to the optimization records.
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 used for the DW_AT_[GNU_]dwo_name attribute in the skeleton CU...
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.
static std::string toString(const clang::SanitizerSet &Sanitizers)
Produce a string containing comma-separated names of sanitizers in Sanitizers set.
std::string SplitDwarfOutput
Output filename for the split debug info, not used in the skeleton CU.
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.
bool hasProfileCSIRUse() const
Check if CSIR profile use is on.
std::vector< std::string > PassPlugins
List of dynamic shared object files to be loaded as pass plugins.
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.
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.
std::string OptRecordFormat
The format used for serializing remarks (default: YAML)
Emit native assembly files.
static void addSanitizersAtO0(ModulePassManager &MPM, const Triple &TargetTriple, const LangOptions &LangOpts, const CodeGenOptions &CodeGenOpts)
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.
bool hasProfileCSIRInstr() const
Check if CS IR level profile instrumentation is on.
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 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, -fprofile-generate, and -fcs-profile-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 Optional< InstrProfOptions > getInstrProfOptions(const CodeGenOptions &CodeGenOpts, const LangOptions &LangOpts)
static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts)