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/Passes/StandardInstrumentations.h" 41 #include "llvm/Support/BuryPointer.h" 42 #include "llvm/Support/CommandLine.h" 43 #include "llvm/Support/MemoryBuffer.h" 44 #include "llvm/Support/PrettyStackTrace.h" 45 #include "llvm/Support/TargetRegistry.h" 46 #include "llvm/Support/TimeProfiler.h" 47 #include "llvm/Support/Timer.h" 48 #include "llvm/Support/raw_ostream.h" 49 #include "llvm/Target/TargetMachine.h" 50 #include "llvm/Target/TargetOptions.h" 51 #include "llvm/Transforms/Coroutines.h" 52 #include "llvm/Transforms/IPO.h" 53 #include "llvm/Transforms/IPO/AlwaysInliner.h" 54 #include "llvm/Transforms/IPO/PassManagerBuilder.h" 55 #include "llvm/Transforms/IPO/ThinLTOBitcodeWriter.h" 56 #include "llvm/Transforms/InstCombine/InstCombine.h" 57 #include "llvm/Transforms/Instrumentation.h" 58 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h" 59 #include "llvm/Transforms/Instrumentation/BoundsChecking.h" 60 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h" 61 #include "llvm/Transforms/Instrumentation/HWAddressSanitizer.h" 62 #include "llvm/Transforms/Instrumentation/InstrProfiling.h" 63 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h" 64 #include "llvm/Transforms/Instrumentation/SanitizerCoverage.h" 65 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h" 66 #include "llvm/Transforms/ObjCARC.h" 67 #include "llvm/Transforms/Scalar.h" 68 #include "llvm/Transforms/Scalar/GVN.h" 69 #include "llvm/Transforms/Utils.h" 70 #include "llvm/Transforms/Utils/CanonicalizeAliases.h" 71 #include "llvm/Transforms/Utils/EntryExitInstrumenter.h" 72 #include "llvm/Transforms/Utils/NameAnonGlobals.h" 73 #include "llvm/Transforms/Utils/SymbolRewriter.h" 75 using namespace clang;
78 #define HANDLE_EXTENSION(Ext) \ 79 llvm::PassPluginLibraryInfo get##Ext##PluginInfo(); 80 #include "llvm/Support/Extension.def" 85 static constexpr
StringLiteral DefaultProfileGenName =
"default_%m.profraw";
87 class EmitAssemblyHelper {
95 Timer CodeGenerationTime;
97 std::unique_ptr<raw_pwrite_stream> OS;
99 TargetIRAnalysis getTargetIRAnalysis()
const {
101 return TM->getTargetIRAnalysis();
103 return TargetIRAnalysis();
106 void CreatePasses(legacy::PassManager &MPM, legacy::FunctionPassManager &FPM);
116 void CreateTargetMachine(
bool MustCreateTM);
121 bool AddEmitPasses(legacy::PassManager &CodeGenPasses,
BackendAction Action,
122 raw_pwrite_stream &OS, raw_pwrite_stream *DwoOS);
124 std::unique_ptr<llvm::ToolOutputFile> openOutputFile(StringRef Path) {
126 auto F = std::make_unique<llvm::ToolOutputFile>(Path, EC,
127 llvm::sys::fs::OF_None);
129 Diags.
Report(diag::err_fe_unable_to_open_output) << Path << EC.message();
141 : Diags(_Diags), HSOpts(HeaderSearchOpts), CodeGenOpts(CGOpts),
142 TargetOpts(TOpts), LangOpts(LOpts), TheModule(M),
143 CodeGenerationTime(
"codegen",
"Code Generation Time") {}
145 ~EmitAssemblyHelper() {
146 if (CodeGenOpts.DisableFree)
147 BuryPointer(std::move(TM));
150 std::unique_ptr<TargetMachine> TM;
153 std::unique_ptr<raw_pwrite_stream> OS);
156 std::unique_ptr<raw_pwrite_stream> OS);
161 class PassManagerBuilderWrapper :
public PassManagerBuilder {
163 PassManagerBuilderWrapper(
const Triple &TargetTriple,
166 : PassManagerBuilder(), TargetTriple(TargetTriple), CGOpts(CGOpts),
167 LangOpts(LangOpts) {}
168 const Triple &getTargetTriple()
const {
return TargetTriple; }
170 const LangOptions &getLangOpts()
const {
return LangOpts; }
173 const Triple &TargetTriple;
180 if (Builder.OptLevel > 0)
181 PM.add(createObjCARCAPElimPass());
185 if (Builder.OptLevel > 0)
186 PM.add(createObjCARCExpandPass());
190 if (Builder.OptLevel > 0)
191 PM.add(createObjCARCOptPass());
195 legacy::PassManagerBase &PM) {
196 PM.add(createAddDiscriminatorsPass());
200 legacy::PassManagerBase &PM) {
201 PM.add(createBoundsCheckingLegacyPass());
204 static SanitizerCoverageOptions
206 SanitizerCoverageOptions Opts;
209 Opts.IndirectCalls = CGOpts.SanitizeCoverageIndirectCalls;
210 Opts.TraceBB = CGOpts.SanitizeCoverageTraceBB;
211 Opts.TraceCmp = CGOpts.SanitizeCoverageTraceCmp;
212 Opts.TraceDiv = CGOpts.SanitizeCoverageTraceDiv;
213 Opts.TraceGep = CGOpts.SanitizeCoverageTraceGep;
214 Opts.Use8bitCounters = CGOpts.SanitizeCoverage8bitCounters;
215 Opts.TracePC = CGOpts.SanitizeCoverageTracePC;
216 Opts.TracePCGuard = CGOpts.SanitizeCoverageTracePCGuard;
217 Opts.NoPrune = CGOpts.SanitizeCoverageNoPrune;
218 Opts.Inline8bitCounters = CGOpts.SanitizeCoverageInline8bitCounters;
219 Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
220 Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
225 legacy::PassManagerBase &PM) {
226 const PassManagerBuilderWrapper &BuilderWrapper =
227 static_cast<const PassManagerBuilderWrapper &
>(Builder);
230 PM.add(createModuleSanitizerCoverageLegacyPassPass(Opts));
238 if (!CGOpts.SanitizeAddressGlobalsDeadStripping)
240 switch (T.getObjectFormat()) {
245 return CGOpts.DataSections && !CGOpts.DisableIntegratedAS;
247 llvm::report_fatal_error(
"ASan not implemented for XCOFF.");
249 case Triple::UnknownObjectFormat:
256 legacy::PassManagerBase &PM) {
257 const PassManagerBuilderWrapper &BuilderWrapper =
258 static_cast<const PassManagerBuilderWrapper&
>(Builder);
259 const Triple &T = BuilderWrapper.getTargetTriple();
262 bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
263 bool UseOdrIndicator = CGOpts.SanitizeAddressUseOdrIndicator;
265 PM.add(createAddressSanitizerFunctionPass(
false, Recover,
267 PM.add(createModuleAddressSanitizerLegacyPassPass(
268 false, Recover, UseGlobalsGC, UseOdrIndicator));
272 legacy::PassManagerBase &PM) {
273 PM.add(createAddressSanitizerFunctionPass(
275 PM.add(createModuleAddressSanitizerLegacyPassPass(
281 legacy::PassManagerBase &PM) {
282 const PassManagerBuilderWrapper &BuilderWrapper =
283 static_cast<const PassManagerBuilderWrapper &
>(Builder);
287 createHWAddressSanitizerLegacyPassPass(
false, Recover));
291 legacy::PassManagerBase &PM) {
292 PM.add(createHWAddressSanitizerLegacyPassPass(
297 legacy::PassManagerBase &PM,
298 bool CompileKernel) {
299 const PassManagerBuilderWrapper &BuilderWrapper =
300 static_cast<const PassManagerBuilderWrapper&
>(Builder);
302 int TrackOrigins = CGOpts.SanitizeMemoryTrackOrigins;
304 PM.add(createMemorySanitizerLegacyPassPass(
305 MemorySanitizerOptions{TrackOrigins, Recover, CompileKernel}));
310 if (Builder.OptLevel > 0) {
311 PM.add(createEarlyCSEPass());
312 PM.add(createReassociatePass());
313 PM.add(createLICMPass());
314 PM.add(createGVNPass());
315 PM.add(createInstructionCombiningPass());
316 PM.add(createDeadStoreEliminationPass());
321 legacy::PassManagerBase &PM) {
326 legacy::PassManagerBase &PM) {
331 legacy::PassManagerBase &PM) {
332 PM.add(createThreadSanitizerLegacyPassPass());
336 legacy::PassManagerBase &PM) {
337 const PassManagerBuilderWrapper &BuilderWrapper =
338 static_cast<const PassManagerBuilderWrapper&
>(Builder);
339 const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
343 static TargetLibraryInfoImpl *
createTLII(llvm::Triple &TargetTriple,
345 TargetLibraryInfoImpl *TLII =
new TargetLibraryInfoImpl(TargetTriple);
347 switch (CodeGenOpts.getVecLib()) {
349 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::Accelerate);
352 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::MASSV);
355 TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
364 legacy::PassManager *MPM) {
365 llvm::SymbolRewriter::RewriteDescriptorList DL;
367 llvm::SymbolRewriter::RewriteMapParser MapParser;
369 MapParser.parse(MapFile, &DL);
371 MPM->add(createRewriteSymbolsPass(DL));
375 switch (CodeGenOpts.OptimizationLevel) {
377 llvm_unreachable(
"Invalid optimization level!");
385 return CodeGenOpt::Aggressive;
391 unsigned CodeModel = llvm::StringSwitch<unsigned>(CodeGenOpts.
CodeModel)
392 .Case(
"tiny", llvm::CodeModel::Tiny)
393 .Case(
"small", llvm::CodeModel::Small)
394 .Case(
"kernel", llvm::CodeModel::Kernel)
395 .Case(
"medium", llvm::CodeModel::Medium)
396 .Case(
"large", llvm::CodeModel::Large)
397 .Case(
"default", ~1u)
399 assert(CodeModel != ~0u &&
"invalid code model!");
400 if (CodeModel == ~1u)
402 return static_cast<llvm::CodeModel::Model
>(CodeModel);
407 return CGFT_ObjectFile;
412 return CGFT_AssemblyFile;
421 Options.ThreadModel =
422 llvm::StringSwitch<llvm::ThreadModel::Model>(CodeGenOpts.
ThreadModel)
423 .Case(
"posix", llvm::ThreadModel::POSIX)
424 .Case(
"single", llvm::ThreadModel::Single);
427 assert((CodeGenOpts.
FloatABI ==
"soft" || CodeGenOpts.
FloatABI ==
"softfp" ||
429 "Invalid Floating Point ABI!");
430 Options.FloatABIType =
431 llvm::StringSwitch<llvm::FloatABI::ABIType>(CodeGenOpts.
FloatABI)
432 .Case(
"soft", llvm::FloatABI::Soft)
433 .Case(
"softfp", llvm::FloatABI::Soft)
434 .Case(
"hard", llvm::FloatABI::Hard)
435 .Default(llvm::FloatABI::Default);
438 switch (LangOpts.getDefaultFPContractMode()) {
442 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
445 Options.AllowFPOpFusion = llvm::FPOpFusion::Standard;
448 Options.AllowFPOpFusion = llvm::FPOpFusion::Fast;
452 Options.UseInitArray = CodeGenOpts.UseInitArray;
453 Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
454 Options.CompressDebugSections = CodeGenOpts.getCompressDebugSections();
455 Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
460 if (LangOpts.SjLjExceptions)
461 Options.ExceptionModel = llvm::ExceptionHandling::SjLj;
462 if (LangOpts.SEHExceptions)
463 Options.ExceptionModel = llvm::ExceptionHandling::WinEH;
464 if (LangOpts.DWARFExceptions)
465 Options.ExceptionModel = llvm::ExceptionHandling::DwarfCFI;
466 if (LangOpts.WasmExceptions)
467 Options.ExceptionModel = llvm::ExceptionHandling::Wasm;
469 Options.NoInfsFPMath = CodeGenOpts.NoInfsFPMath;
470 Options.NoNaNsFPMath = CodeGenOpts.NoNaNsFPMath;
471 Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
472 Options.UnsafeFPMath = CodeGenOpts.UnsafeFPMath;
473 Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
474 Options.FunctionSections = CodeGenOpts.FunctionSections;
475 Options.DataSections = CodeGenOpts.DataSections;
476 Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
477 Options.TLSSize = CodeGenOpts.TLSSize;
478 Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
479 Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
480 Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
481 Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
482 Options.EmitAddrsig = CodeGenOpts.Addrsig;
483 Options.EnableDebugEntryValues = CodeGenOpts.EnableDebugEntryValues;
484 Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
487 Options.MCOptions.MCRelaxAll = CodeGenOpts.RelaxAll;
488 Options.MCOptions.MCSaveTempLabels = CodeGenOpts.SaveTempLabels;
489 Options.MCOptions.MCUseDwarfDirectory = !CodeGenOpts.NoDwarfDirectoryAsm;
490 Options.MCOptions.MCNoExecStack = CodeGenOpts.NoExecStack;
491 Options.MCOptions.MCIncrementalLinkerCompatible =
492 CodeGenOpts.IncrementalLinkerCompatible;
493 Options.MCOptions.MCFatalWarnings = CodeGenOpts.FatalWarnings;
494 Options.MCOptions.MCNoWarn = CodeGenOpts.NoWarn;
495 Options.MCOptions.AsmVerbose = CodeGenOpts.AsmVerbose;
496 Options.MCOptions.PreserveAsmComments = CodeGenOpts.PreserveAsmComments;
497 Options.MCOptions.ABIName = TargetOpts.
ABI;
499 if (!Entry.IsFramework &&
503 Options.MCOptions.IASSearchPaths.push_back(
504 Entry.IgnoreSysRoot ? Entry.Path : HSOpts.
Sysroot + Entry.Path);
507 if (CodeGenOpts.DisableGCov)
509 if (!CodeGenOpts.EmitGcovArcs && !CodeGenOpts.EmitGcovNotes)
514 Options.EmitNotes = CodeGenOpts.EmitGcovNotes;
515 Options.EmitData = CodeGenOpts.EmitGcovArcs;
517 Options.UseCfgChecksum = CodeGenOpts.CoverageExtraChecksum;
518 Options.NoRedZone = CodeGenOpts.DisableRedZone;
519 Options.FunctionNamesInData = !CodeGenOpts.CoverageNoFunctionNamesInData;
522 Options.ExitBlockBeforeBody = CodeGenOpts.CoverageExitBlockBeforeBody;
531 InstrProfOptions Options;
532 Options.NoRedZone = CodeGenOpts.DisableRedZone;
537 Options.Atomic = LangOpts.
Sanitize.
has(SanitizerKind::Thread);
541 void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
542 legacy::FunctionPassManager &FPM) {
545 if (CodeGenOpts.DisableLLVMPasses)
552 Triple TargetTriple(TheModule->getTargetTriple());
553 std::unique_ptr<TargetLibraryInfoImpl> TLII(
556 PassManagerBuilderWrapper PMBuilder(TargetTriple, CodeGenOpts, LangOpts);
560 if (CodeGenOpts.OptimizationLevel <= 1) {
561 bool InsertLifetimeIntrinsics = (CodeGenOpts.OptimizationLevel != 0 &&
562 !CodeGenOpts.DisableLifetimeMarkers);
563 PMBuilder.Inliner = createAlwaysInlinerLegacyPass(InsertLifetimeIntrinsics);
568 PMBuilder.Inliner = createFunctionInliningPass(
569 CodeGenOpts.OptimizationLevel, CodeGenOpts.OptimizeSize,
570 (!CodeGenOpts.SampleProfileFile.empty() &&
571 CodeGenOpts.PrepareForThinLTO));
574 PMBuilder.OptLevel = CodeGenOpts.OptimizationLevel;
575 PMBuilder.SizeLevel = CodeGenOpts.OptimizeSize;
576 PMBuilder.SLPVectorize = CodeGenOpts.VectorizeSLP;
577 PMBuilder.LoopVectorize = CodeGenOpts.VectorizeLoop;
579 PMBuilder.DisableUnrollLoops = !CodeGenOpts.UnrollLoops;
582 PMBuilder.LoopsInterleaved = CodeGenOpts.UnrollLoops;
583 PMBuilder.MergeFunctions = CodeGenOpts.MergeFunctions;
584 PMBuilder.PrepareForThinLTO = CodeGenOpts.PrepareForThinLTO;
585 PMBuilder.PrepareForLTO = CodeGenOpts.PrepareForLTO;
586 PMBuilder.RerollLoops = CodeGenOpts.RerollLoops;
588 MPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
591 TM->adjustPassManager(PMBuilder);
593 if (CodeGenOpts.DebugInfoForProfiling ||
594 !CodeGenOpts.SampleProfileFile.empty())
595 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
599 if (LangOpts.ObjCAutoRefCount) {
600 PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
602 PMBuilder.addExtension(PassManagerBuilder::EP_ModuleOptimizerEarly,
604 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
608 if (LangOpts.Coroutines)
609 addCoroutinePassesToExtensionPoints(PMBuilder);
611 if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) {
612 PMBuilder.addExtension(PassManagerBuilder::EP_ScalarOptimizerLate,
614 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
618 if (CodeGenOpts.SanitizeCoverageType ||
619 CodeGenOpts.SanitizeCoverageIndirectCalls ||
620 CodeGenOpts.SanitizeCoverageTraceCmp) {
621 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
623 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
627 if (LangOpts.Sanitize.has(SanitizerKind::Address)) {
628 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
630 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
634 if (LangOpts.Sanitize.has(SanitizerKind::KernelAddress)) {
635 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
637 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
641 if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
642 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
644 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
648 if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) {
649 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
651 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
655 if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
656 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
658 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
662 if (LangOpts.Sanitize.has(SanitizerKind::KernelMemory)) {
663 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
665 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
669 if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
670 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
672 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
676 if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
677 PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
679 PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
684 FPM.add(
new TargetLibraryInfoWrapperPass(*TLII));
685 if (CodeGenOpts.VerifyModule)
686 FPM.add(createVerifierPass());
689 if (!CodeGenOpts.RewriteMapFiles.empty())
693 MPM.add(createGCOVProfilerPass(*Options));
695 MPM.add(createStripSymbolsPass(
true));
700 MPM.add(createInstrProfilingLegacyPass(*Options,
false));
702 bool hasIRInstr =
false;
703 if (CodeGenOpts.hasProfileIRInstr()) {
704 PMBuilder.EnablePGOInstrGen =
true;
707 if (CodeGenOpts.hasProfileCSIRInstr()) {
708 assert(!CodeGenOpts.hasProfileCSIRUse() &&
709 "Cannot have both CSProfileUse pass and CSProfileGen pass at the " 711 assert(!hasIRInstr &&
712 "Cannot have both ProfileGen pass and CSProfileGen pass at the " 714 PMBuilder.EnablePGOCSInstrGen =
true;
718 if (!CodeGenOpts.InstrProfileOutput.empty())
719 PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
721 PMBuilder.PGOInstrGen = DefaultProfileGenName;
723 if (CodeGenOpts.hasProfileIRUse()) {
724 PMBuilder.PGOInstrUse = CodeGenOpts.ProfileInstrumentUsePath;
725 PMBuilder.EnablePGOCSInstrUse = CodeGenOpts.hasProfileCSIRUse();
728 if (!CodeGenOpts.SampleProfileFile.empty())
729 PMBuilder.PGOSampleUse = CodeGenOpts.SampleProfileFile;
731 PMBuilder.populateFunctionPassManager(FPM);
732 PMBuilder.populateModulePassManager(MPM);
737 BackendArgs.push_back(
"clang");
739 BackendArgs.push_back(
"-debug-pass");
740 BackendArgs.push_back(CodeGenOpts.
DebugPass.c_str());
743 BackendArgs.push_back(
"-limit-float-precision");
746 BackendArgs.push_back(
nullptr);
747 llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
751 void EmitAssemblyHelper::CreateTargetMachine(
bool MustCreateTM) {
754 std::string Triple = TheModule->getTargetTriple();
755 const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Triple, Error);
758 Diags.Report(diag::err_fe_unable_to_create_target) <<
Error;
763 std::string FeaturesStr =
764 llvm::join(TargetOpts.Features.begin(), TargetOpts.Features.end(),
",");
765 llvm::Reloc::Model RM = CodeGenOpts.RelocationModel;
768 llvm::TargetOptions Options;
770 TM.reset(TheTarget->createTargetMachine(Triple, TargetOpts.CPU, FeaturesStr,
771 Options, RM, CM, OptLevel));
774 bool EmitAssemblyHelper::AddEmitPasses(legacy::PassManager &CodeGenPasses,
776 raw_pwrite_stream &OS,
777 raw_pwrite_stream *DwoOS) {
779 llvm::Triple TargetTriple(TheModule->getTargetTriple());
780 std::unique_ptr<TargetLibraryInfoImpl> TLII(
782 CodeGenPasses.add(
new TargetLibraryInfoWrapperPass(*TLII));
791 if (CodeGenOpts.OptimizationLevel > 0)
792 CodeGenPasses.add(createObjCARCContractPass());
794 if (TM->addPassesToEmitFile(CodeGenPasses, OS, DwoOS, CGFT,
795 !CodeGenOpts.VerifyModule)) {
796 Diags.Report(diag::err_fe_unable_to_interface_with_target);
804 std::unique_ptr<raw_pwrite_stream> OS) {
812 CreateTargetMachine(UsesCodeGen);
814 if (UsesCodeGen && !TM)
817 TheModule->setDataLayout(TM->createDataLayout());
819 legacy::PassManager PerModulePasses;
821 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
823 legacy::FunctionPassManager PerFunctionPasses(TheModule);
824 PerFunctionPasses.add(
825 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
827 CreatePasses(PerModulePasses, PerFunctionPasses);
829 legacy::PassManager CodeGenPasses;
831 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
833 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
840 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
841 if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
842 ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
846 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
847 CodeGenOpts.EnableSplitLTOUnit);
848 PerModulePasses.add(createWriteThinLTOBitcodePass(
849 *OS, ThinLinkOS ? &ThinLinkOS->os() :
nullptr));
853 bool EmitLTOSummary =
854 (CodeGenOpts.PrepareForLTO &&
855 !CodeGenOpts.DisableLLVMPasses &&
856 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
857 llvm::Triple::Apple);
858 if (EmitLTOSummary) {
859 if (!TheModule->getModuleFlag(
"ThinLTO"))
860 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
861 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
865 PerModulePasses.add(createBitcodeWriterPass(
866 *OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
872 createPrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
876 if (!CodeGenOpts.SplitDwarfOutput.empty()) {
877 DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
881 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
882 DwoOS ? &DwoOS->os() :
nullptr))
887 cl::PrintOptionValues();
893 PrettyStackTraceString CrashInfo(
"Per-function optimization");
894 llvm::TimeTraceScope TimeScope(
"PerFunctionPasses");
896 PerFunctionPasses.doInitialization();
897 for (Function &F : *TheModule)
898 if (!F.isDeclaration())
899 PerFunctionPasses.run(F);
900 PerFunctionPasses.doFinalization();
904 PrettyStackTraceString CrashInfo(
"Per-module optimization passes");
905 llvm::TimeTraceScope TimeScope(
"PerModulePasses");
906 PerModulePasses.run(*TheModule);
910 PrettyStackTraceString CrashInfo(
"Code generation");
911 llvm::TimeTraceScope TimeScope(
"CodeGenPasses");
912 CodeGenPasses.run(*TheModule);
922 switch (Opts.OptimizationLevel) {
924 llvm_unreachable(
"Invalid optimization level!");
927 return PassBuilder::O1;
930 switch (Opts.OptimizeSize) {
932 llvm_unreachable(
"Invalid optimization level for size!");
935 return PassBuilder::O2;
938 return PassBuilder::Os;
941 return PassBuilder::Oz;
945 return PassBuilder::O3;
950 const Triple &TargetTriple,
953 auto ASanPass = [&](
SanitizerMask Mask,
bool CompileKernel) {
954 MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
956 MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(
957 CompileKernel, Recover, CodeGenOpts.SanitizeAddressUseAfterScope)));
960 ModuleAddressSanitizerPass(CompileKernel, Recover, ModuleUseAfterScope,
961 CodeGenOpts.SanitizeAddressUseOdrIndicator));
964 if (LangOpts.
Sanitize.
has(SanitizerKind::Address)) {
965 ASanPass(SanitizerKind::Address,
false);
968 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelAddress)) {
969 ASanPass(SanitizerKind::KernelAddress,
true);
972 if (LangOpts.
Sanitize.
has(SanitizerKind::Memory)) {
973 MPM.addPass(MemorySanitizerPass({}));
974 MPM.addPass(createModuleToFunctionPassAdaptor(MemorySanitizerPass({})));
977 if (LangOpts.
Sanitize.
has(SanitizerKind::KernelMemory)) {
978 MPM.addPass(createModuleToFunctionPassAdaptor(
979 MemorySanitizerPass({0,
false,
true})));
982 if (LangOpts.
Sanitize.
has(SanitizerKind::Thread)) {
983 MPM.addPass(ThreadSanitizerPass());
984 MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
996 void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
997 BackendAction Action, std::unique_ptr<raw_pwrite_stream> OS) {
1004 CreateTargetMachine(RequiresCodeGen);
1006 if (RequiresCodeGen && !TM)
1009 TheModule->setDataLayout(TM->createDataLayout());
1013 if (CodeGenOpts.hasProfileIRInstr())
1015 PGOOpt = PGOOptions(CodeGenOpts.InstrProfileOutput.empty()
1016 ? DefaultProfileGenName
1017 : CodeGenOpts.InstrProfileOutput,
1018 "",
"", PGOOptions::IRInstr, PGOOptions::NoCSAction,
1019 CodeGenOpts.DebugInfoForProfiling);
1020 else if (CodeGenOpts.hasProfileIRUse()) {
1022 auto CSAction = CodeGenOpts.hasProfileCSIRUse() ? PGOOptions::CSIRUse
1023 : PGOOptions::NoCSAction;
1024 PGOOpt = PGOOptions(CodeGenOpts.ProfileInstrumentUsePath,
"",
1025 CodeGenOpts.ProfileRemappingFile, PGOOptions::IRUse,
1026 CSAction, CodeGenOpts.DebugInfoForProfiling);
1027 }
else if (!CodeGenOpts.SampleProfileFile.empty())
1030 PGOOptions(CodeGenOpts.SampleProfileFile,
"",
1031 CodeGenOpts.ProfileRemappingFile, PGOOptions::SampleUse,
1032 PGOOptions::NoCSAction, CodeGenOpts.DebugInfoForProfiling);
1033 else if (CodeGenOpts.DebugInfoForProfiling)
1035 PGOOpt = PGOOptions(
"",
"",
"", PGOOptions::NoAction,
1036 PGOOptions::NoCSAction,
true);
1039 if (CodeGenOpts.hasProfileCSIRInstr()) {
1040 assert(!CodeGenOpts.hasProfileCSIRUse() &&
1041 "Cannot have both CSProfileUse pass and CSProfileGen pass at " 1043 if (PGOOpt.hasValue()) {
1044 assert(PGOOpt->Action != PGOOptions::IRInstr &&
1045 PGOOpt->Action != PGOOptions::SampleUse &&
1046 "Cannot run CSProfileGen pass with ProfileGen or SampleUse " 1048 PGOOpt->CSProfileGenFile = CodeGenOpts.InstrProfileOutput.empty()
1049 ? DefaultProfileGenName
1050 : CodeGenOpts.InstrProfileOutput;
1051 PGOOpt->CSAction = PGOOptions::CSIRInstr;
1053 PGOOpt = PGOOptions(
"",
1054 CodeGenOpts.InstrProfileOutput.empty()
1055 ? DefaultProfileGenName
1056 : CodeGenOpts.InstrProfileOutput,
1057 "", PGOOptions::NoAction, PGOOptions::CSIRInstr,
1058 CodeGenOpts.DebugInfoForProfiling);
1061 PipelineTuningOptions PTO;
1062 PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;
1065 PTO.LoopInterleaving = CodeGenOpts.UnrollLoops;
1066 PTO.LoopVectorization = CodeGenOpts.VectorizeLoop;
1067 PTO.SLPVectorization = CodeGenOpts.VectorizeSLP;
1069 PassInstrumentationCallbacks PIC;
1070 StandardInstrumentations SI;
1071 SI.registerCallbacks(PIC);
1072 PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
1075 for (
auto &PluginFN : CodeGenOpts.PassPlugins) {
1078 PassPlugin->registerPassBuilderCallbacks(PB);
1080 Diags.Report(diag::err_fe_unable_to_load_plugin)
1081 << PluginFN <<
toString(PassPlugin.takeError());
1084 #define HANDLE_EXTENSION(Ext) \ 1085 get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB); 1086 #include "llvm/Support/Extension.def" 1088 LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
1089 FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
1090 CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
1091 ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
1094 FAM.registerPass([&] {
return PB.buildDefaultAAPipeline(); });
1098 Triple TargetTriple(TheModule->getTargetTriple());
1099 std::unique_ptr<TargetLibraryInfoImpl> TLII(
1101 FAM.registerPass([&] {
return TargetLibraryAnalysis(*TLII); });
1104 PB.registerModuleAnalyses(MAM);
1105 PB.registerCGSCCAnalyses(CGAM);
1106 PB.registerFunctionAnalyses(FAM);
1107 PB.registerLoopAnalyses(LAM);
1108 PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
1110 ModulePassManager MPM(CodeGenOpts.DebugPassManager);
1112 if (!CodeGenOpts.DisableLLVMPasses) {
1113 bool IsThinLTO = CodeGenOpts.PrepareForThinLTO;
1114 bool IsLTO = CodeGenOpts.PrepareForLTO;
1116 if (CodeGenOpts.OptimizationLevel == 0) {
1118 MPM.addPass(GCOVProfilerPass(*Options));
1121 MPM.addPass(InstrProfiling(*Options,
false));
1127 MPM.addPass(AlwaysInlinerPass(
false));
1131 if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
1132 PGOOpt->Action == PGOOptions::IRUse))
1133 PB.addPGOInstrPassesForO0(
1134 MPM, CodeGenOpts.DebugPassManager,
1135 (PGOOpt->Action == PGOOptions::IRInstr),
1136 false, PGOOpt->ProfileFile,
1137 PGOOpt->ProfileRemappingFile);
1140 if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
1141 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));
1144 if (IsLTO || IsThinLTO) {
1145 MPM.addPass(CanonicalizeAliasesPass());
1146 MPM.addPass(NameAnonGlobalPass());
1153 PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
1154 MPM.addPass(createModuleToFunctionPassAdaptor(
1155 EntryExitInstrumenterPass(
false)));
1161 if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
1162 PB.registerScalarOptimizerLateEPCallback(
1163 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1164 FPM.addPass(BoundsCheckingPass());
1166 if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
1167 PB.registerPipelineStartEPCallback([](ModulePassManager &MPM) {
1168 MPM.addPass(MemorySanitizerPass({}));
1170 PB.registerOptimizerLastEPCallback(
1171 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1172 FPM.addPass(MemorySanitizerPass({}));
1175 if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
1176 PB.registerPipelineStartEPCallback(
1177 [](ModulePassManager &MPM) { MPM.addPass(ThreadSanitizerPass()); });
1178 PB.registerOptimizerLastEPCallback(
1179 [](FunctionPassManager &FPM, PassBuilder::OptimizationLevel Level) {
1180 FPM.addPass(ThreadSanitizerPass());
1183 if (LangOpts.Sanitize.has(SanitizerKind::Address)) {
1184 PB.registerPipelineStartEPCallback([&](ModulePassManager &MPM) {
1186 RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
1188 bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Address);
1189 bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
1190 PB.registerOptimizerLastEPCallback(
1191 [Recover, UseAfterScope](FunctionPassManager &FPM,
1192 PassBuilder::OptimizationLevel Level) {
1193 FPM.addPass(AddressSanitizerPass(
1194 false, Recover, UseAfterScope));
1197 bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
1198 PB.registerPipelineStartEPCallback(
1199 [Recover, ModuleUseAfterScope,
1200 UseOdrIndicator](ModulePassManager &MPM) {
1201 MPM.addPass(ModuleAddressSanitizerPass(
1202 false, Recover, ModuleUseAfterScope,
1207 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
1208 MPM.addPass(GCOVProfilerPass(*Options));
1212 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
1213 MPM.addPass(InstrProfiling(*Options,
false));
1217 MPM = PB.buildThinLTOPreLinkDefaultPipeline(
1218 Level, CodeGenOpts.DebugPassManager);
1219 MPM.addPass(CanonicalizeAliasesPass());
1220 MPM.addPass(NameAnonGlobalPass());
1222 MPM = PB.buildLTOPreLinkDefaultPipeline(Level,
1223 CodeGenOpts.DebugPassManager);
1224 MPM.addPass(CanonicalizeAliasesPass());
1225 MPM.addPass(NameAnonGlobalPass());
1227 MPM = PB.buildPerModuleDefaultPipeline(Level,
1228 CodeGenOpts.DebugPassManager);
1232 if (CodeGenOpts.SanitizeCoverageType ||
1233 CodeGenOpts.SanitizeCoverageIndirectCalls ||
1234 CodeGenOpts.SanitizeCoverageTraceCmp) {
1236 MPM.addPass(ModuleSanitizerCoveragePass(SancovOpts));
1239 if (LangOpts.Sanitize.has(SanitizerKind::HWAddress)) {
1240 bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
1241 MPM.addPass(HWAddressSanitizerPass(
1244 if (LangOpts.Sanitize.has(SanitizerKind::KernelHWAddress)) {
1245 MPM.addPass(HWAddressSanitizerPass(
1249 if (CodeGenOpts.OptimizationLevel == 0) {
1256 legacy::PassManager CodeGenPasses;
1257 bool NeedCodeGen =
false;
1258 std::unique_ptr<llvm::ToolOutputFile> ThinLinkOS, DwoOS;
1266 if (CodeGenOpts.PrepareForThinLTO && !CodeGenOpts.DisableLLVMPasses) {
1267 if (!CodeGenOpts.ThinLinkBitcodeFile.empty()) {
1268 ThinLinkOS = openOutputFile(CodeGenOpts.ThinLinkBitcodeFile);
1272 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1273 CodeGenOpts.EnableSplitLTOUnit);
1274 MPM.addPass(ThinLTOBitcodeWriterPass(*OS, ThinLinkOS ? &ThinLinkOS->os()
1279 bool EmitLTOSummary =
1280 (CodeGenOpts.PrepareForLTO &&
1281 !CodeGenOpts.DisableLLVMPasses &&
1282 llvm::Triple(TheModule->getTargetTriple()).getVendor() !=
1283 llvm::Triple::Apple);
1284 if (EmitLTOSummary) {
1285 if (!TheModule->getModuleFlag(
"ThinLTO"))
1286 TheModule->addModuleFlag(
Module::Error,
"ThinLTO", uint32_t(0));
1287 TheModule->addModuleFlag(
Module::Error,
"EnableSplitLTOUnit",
1291 BitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists, EmitLTOSummary));
1296 MPM.addPass(PrintModulePass(*OS,
"", CodeGenOpts.EmitLLVMUseLists));
1304 createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
1305 if (!CodeGenOpts.SplitDwarfOutput.empty()) {
1306 DwoOS = openOutputFile(CodeGenOpts.SplitDwarfOutput);
1310 if (!AddEmitPasses(CodeGenPasses, Action, *OS,
1311 DwoOS ? &DwoOS->os() :
nullptr))
1318 cl::PrintOptionValues();
1322 PrettyStackTraceString CrashInfo(
"Optimizer");
1323 MPM.run(*TheModule, MAM);
1328 PrettyStackTraceString CrashInfo(
"Code generation");
1329 CodeGenPasses.run(*TheModule);
1341 return BMsOrErr.takeError();
1348 return make_error<StringError>(
"Could not find module summary",
1349 inconvertibleErrorCode());
1353 for (BitcodeModule &BM : BMs) {
1355 if (LTOInfo && LTOInfo->IsThinLTO)
1366 std::unique_ptr<raw_pwrite_stream> OS,
1367 std::string SampleProfile,
1368 std::string ProfileRemapping,
1370 StringMap<DenseMap<GlobalValue::GUID, GlobalValueSummary *>>
1371 ModuleToDefinedGVSummaries;
1372 CombinedIndex->collectDefinedGVSummariesPerModule(ModuleToDefinedGVSummaries);
1379 FunctionImporter::ImportMapTy ImportList;
1380 for (
auto &GlobalList : *CombinedIndex) {
1382 if (GlobalList.second.SummaryList.empty())
1385 auto GUID = GlobalList.first;
1386 for (
auto &Summary : GlobalList.second.SummaryList) {
1389 if (Summary->modulePath() == M->getModuleIdentifier())
1392 ImportList[Summary->modulePath()].insert(GUID);
1396 std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;
1397 MapVector<llvm::StringRef, llvm::BitcodeModule>
ModuleMap;
1399 for (
auto &I : ImportList) {
1400 ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> MBOrErr =
1401 llvm::MemoryBuffer::getFile(I.first());
1403 errs() <<
"Error loading imported file '" << I.first()
1404 <<
"': " << MBOrErr.getError().message() <<
"\n";
1410 handleAllErrors(BMOrErr.takeError(), [&](ErrorInfoBase &EIB) {
1411 errs() <<
"Error loading imported file '" << I.first()
1412 <<
"': " << EIB.message() <<
'\n';
1416 ModuleMap.insert({I.first(), *BMOrErr});
1418 OwnedImports.push_back(std::move(*MBOrErr));
1420 auto AddStream = [&](
size_t Task) {
1421 return std::make_unique<lto::NativeObjectStream>(std::move(OS));
1427 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1428 errs() <<
"Error setting up ThinLTO save-temps: " << EIB.message()
1433 Conf.CPU = TOpts.
CPU;
1438 Conf.OptLevel = CGOpts.OptimizationLevel;
1440 Conf.SampleProfile = std::move(SampleProfile);
1441 Conf.PTO.LoopUnrolling = CGOpts.UnrollLoops;
1444 Conf.PTO.LoopInterleaving = CGOpts.UnrollLoops;
1445 Conf.PTO.LoopVectorization = CGOpts.VectorizeLoop;
1446 Conf.PTO.SLPVectorization = CGOpts.VectorizeSLP;
1450 Conf.RunCSIRInstr =
true;
1453 Conf.RunCSIRInstr =
false;
1457 Conf.ProfileRemapping = std::move(ProfileRemapping);
1458 Conf.UseNewPM = CGOpts.ExperimentalNewPassManager;
1459 Conf.DebugPassManager = CGOpts.DebugPassManager;
1460 Conf.RemarksWithHotness = CGOpts.DiagnosticsWithHotness;
1468 Conf.PreCodeGenModuleHook = [](
size_t Task,
const Module &Mod) {
1473 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1474 M->
print(*OS,
nullptr, CGOpts.EmitLLVMUseLists);
1479 Conf.PreCodeGenModuleHook = [&](
size_t Task,
const Module &Mod) {
1480 WriteBitcodeToFile(*M, *OS, CGOpts.EmitLLVMUseLists);
1488 if (
Error E = thinBackend(
1489 Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
1490 ModuleToDefinedGVSummaries[M->getModuleIdentifier()], ModuleMap)) {
1491 handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
1492 errs() <<
"Error running ThinLTO backend: " << EIB.message() <<
'\n';
1502 const llvm::DataLayout &TDesc,
Module *M,
1504 std::unique_ptr<raw_pwrite_stream> OS) {
1506 llvm::TimeTraceScope TimeScope(
"Backend");
1508 std::unique_ptr<llvm::Module> EmptyModule;
1517 logAllUnhandledErrors(IndexOrErr.takeError(), errs(),
1518 "Error loading index file '" +
1522 std::unique_ptr<ModuleSummaryIndex> CombinedIndex = std::move(*IndexOrErr);
1526 if (CombinedIndex) {
1527 if (!CombinedIndex->skipModuleByDistributedBackend()) {
1529 LOpts, std::move(OS), CGOpts.SampleProfileFile,
1530 CGOpts.ProfileRemappingFile, Action);
1539 EmptyModule = std::make_unique<llvm::Module>(
"empty", M->getContext());
1540 EmptyModule->setTargetTriple(M->getTargetTriple());
1541 M = EmptyModule.get();
1545 EmitAssemblyHelper AsmHelper(Diags, HeaderOpts, CGOpts, TOpts, LOpts, M);
1547 if (CGOpts.ExperimentalNewPassManager)
1548 AsmHelper.EmitAssemblyWithNewPassManager(Action, std::move(OS));
1550 AsmHelper.EmitAssembly(Action, std::move(OS));
1555 std::string DLDesc = M->getDataLayout().getStringRepresentation();
1556 if (DLDesc != TDesc.getStringRepresentation()) {
1559 "expected target description '%1'");
1560 Diags.
Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
1568 llvm::MemoryBufferRef Buf) {
1571 llvm::EmbedBitcodeInModule(
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.
DiagnosticBuilder Report(SourceLocation Loc, unsigned DiagID)
Issue the message to the client.
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.
Don't generate debug info.
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.
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.
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.
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...
static CodeGenFileType getCodeGenFileType(BackendAction Action)
llvm::Reloc::Model RelocationModel
The name of the relocation model to use.
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)
static SanitizerCoverageOptions getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts)
bool hasProfileClangInstr() const
Check if Clang profile instrumenation is on.
llvm::Expected< llvm::BitcodeModule > FindThinLTOModule(llvm::MemoryBufferRef MBRef)
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 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::vector< std::string > SanitizerBlacklistFiles
Paths to blacklist files specifying which objects (files, functions, variables) should not be instrum...
bool Load(InterpState &S, CodePtr OpPC)
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)