aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-08-22 19:00:43 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-11-13 20:39:49 +0000
commitfe6060f10f634930ff71b7c50291ddc610da2475 (patch)
tree1483580c790bd4d27b6500a7542b5ee00534d3cc /contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp
parentb61bce17f346d79cecfd8f195a64b10f77be43b1 (diff)
parent344a3780b2e33f6ca763666c380202b18aab72a3 (diff)
Diffstat (limited to 'contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp')
-rw-r--r--contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp324
1 files changed, 194 insertions, 130 deletions
diff --git a/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp b/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp
index 52bcd971dc8c..481f5347d978 100644
--- a/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp
+++ b/contrib/llvm-project/clang/lib/CodeGen/BackendUtil.cpp
@@ -65,6 +65,7 @@
#include "llvm/Transforms/InstCombine/InstCombine.h"
#include "llvm/Transforms/Instrumentation.h"
#include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
+#include "llvm/Transforms/Instrumentation/AddressSanitizerOptions.h"
#include "llvm/Transforms/Instrumentation/BoundsChecking.h"
#include "llvm/Transforms/Instrumentation/DataFlowSanitizer.h"
#include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
@@ -76,14 +77,15 @@
#include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
#include "llvm/Transforms/ObjCARC.h"
#include "llvm/Transforms/Scalar.h"
+#include "llvm/Transforms/Scalar/EarlyCSE.h"
#include "llvm/Transforms/Scalar/GVN.h"
#include "llvm/Transforms/Scalar/LowerMatrixIntrinsics.h"
#include "llvm/Transforms/Utils.h"
#include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/Debugify.h"
#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
#include "llvm/Transforms/Utils/NameAnonGlobals.h"
#include "llvm/Transforms/Utils/SymbolRewriter.h"
-#include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
#include <memory>
using namespace clang;
using namespace llvm;
@@ -243,7 +245,7 @@ static void addSanitizerCoveragePass(const PassManagerBuilder &Builder,
auto Opts = getSancovOptsFromCGOpts(CGOpts);
PM.add(createModuleSanitizerCoverageLegacyPassPass(
Opts, CGOpts.SanitizeCoverageAllowlistFiles,
- CGOpts.SanitizeCoverageBlocklistFiles));
+ CGOpts.SanitizeCoverageIgnorelistFiles));
}
// Check if ASan should use GC-friendly instrumentation for globals.
@@ -286,16 +288,21 @@ static void addAddressSanitizerPasses(const PassManagerBuilder &Builder,
bool UseAfterScope = CGOpts.SanitizeAddressUseAfterScope;
bool UseOdrIndicator = CGOpts.SanitizeAddressUseOdrIndicator;
bool UseGlobalsGC = asanUseGlobalsGC(T, CGOpts);
+ llvm::AsanDtorKind DestructorKind = CGOpts.getSanitizeAddressDtor();
+ llvm::AsanDetectStackUseAfterReturnMode UseAfterReturn =
+ CGOpts.getSanitizeAddressUseAfterReturn();
PM.add(createAddressSanitizerFunctionPass(/*CompileKernel*/ false, Recover,
- UseAfterScope));
+ UseAfterScope, UseAfterReturn));
PM.add(createModuleAddressSanitizerLegacyPassPass(
- /*CompileKernel*/ false, Recover, UseGlobalsGC, UseOdrIndicator));
+ /*CompileKernel*/ false, Recover, UseGlobalsGC, UseOdrIndicator,
+ DestructorKind));
}
static void addKernelAddressSanitizerPasses(const PassManagerBuilder &Builder,
legacy::PassManagerBase &PM) {
PM.add(createAddressSanitizerFunctionPass(
- /*CompileKernel*/ true, /*Recover*/ true, /*UseAfterScope*/ false));
+ /*CompileKernel*/ true, /*Recover*/ true, /*UseAfterScope*/ false,
+ /*UseAfterReturn*/ llvm::AsanDetectStackUseAfterReturnMode::Never));
PM.add(createModuleAddressSanitizerLegacyPassPass(
/*CompileKernel*/ true, /*Recover*/ true, /*UseGlobalsGC*/ true,
/*UseOdrIndicator*/ false));
@@ -307,14 +314,19 @@ static void addHWAddressSanitizerPasses(const PassManagerBuilder &Builder,
static_cast<const PassManagerBuilderWrapper &>(Builder);
const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
bool Recover = CGOpts.SanitizeRecover.has(SanitizerKind::HWAddress);
- PM.add(
- createHWAddressSanitizerLegacyPassPass(/*CompileKernel*/ false, Recover));
+ PM.add(createHWAddressSanitizerLegacyPassPass(
+ /*CompileKernel*/ false, Recover,
+ /*DisableOptimization*/ CGOpts.OptimizationLevel == 0));
}
static void addKernelHWAddressSanitizerPasses(const PassManagerBuilder &Builder,
- legacy::PassManagerBase &PM) {
+ legacy::PassManagerBase &PM) {
+ const PassManagerBuilderWrapper &BuilderWrapper =
+ static_cast<const PassManagerBuilderWrapper &>(Builder);
+ const CodeGenOptions &CGOpts = BuilderWrapper.getCGOpts();
PM.add(createHWAddressSanitizerLegacyPassPass(
- /*CompileKernel*/ true, /*Recover*/ true));
+ /*CompileKernel*/ true, /*Recover*/ true,
+ /*DisableOptimization*/ CGOpts.OptimizationLevel == 0));
}
static void addGeneralOptsForMemorySanitizer(const PassManagerBuilder &Builder,
@@ -361,8 +373,18 @@ static void addDataFlowSanitizerPass(const PassManagerBuilder &Builder,
const PassManagerBuilderWrapper &BuilderWrapper =
static_cast<const PassManagerBuilderWrapper&>(Builder);
const LangOptions &LangOpts = BuilderWrapper.getLangOpts();
- PM.add(
- createDataFlowSanitizerLegacyPassPass(LangOpts.SanitizerBlacklistFiles));
+ PM.add(createDataFlowSanitizerLegacyPassPass(LangOpts.NoSanitizeFiles));
+}
+
+static void addEntryExitInstrumentationPass(const PassManagerBuilder &Builder,
+ legacy::PassManagerBase &PM) {
+ PM.add(createEntryExitInstrumenterPass());
+}
+
+static void
+addPostInlineEntryExitInstrumentationPass(const PassManagerBuilder &Builder,
+ legacy::PassManagerBase &PM) {
+ PM.add(createPostInlineEntryExitInstrumenterPass());
}
static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
@@ -389,6 +411,10 @@ static TargetLibraryInfoImpl *createTLII(llvm::Triple &TargetTriple,
case CodeGenOptions::SVML:
TLII->addVectorizableFunctionsFromVecLib(TargetLibraryInfoImpl::SVML);
break;
+ case CodeGenOptions::Darwin_libsystem_m:
+ TLII->addVectorizableFunctionsFromVecLib(
+ TargetLibraryInfoImpl::DarwinLibSystemM);
+ break;
default:
break;
}
@@ -513,7 +539,6 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.NoNaNsFPMath = LangOpts.NoHonorNaNs;
Options.NoZerosInBSS = CodeGenOpts.NoZeroInitializedInBSS;
Options.UnsafeFPMath = LangOpts.UnsafeFPMath;
- Options.StackAlignmentOverride = CodeGenOpts.StackAlignment;
Options.BBSections =
llvm::StringSwitch<llvm::BasicBlockSection>(CodeGenOpts.BBSections)
@@ -537,23 +562,16 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Options.EnableMachineFunctionSplitter = CodeGenOpts.SplitMachineFunctions;
Options.FunctionSections = CodeGenOpts.FunctionSections;
Options.DataSections = CodeGenOpts.DataSections;
- Options.IgnoreXCOFFVisibility = CodeGenOpts.IgnoreXCOFFVisibility;
+ Options.IgnoreXCOFFVisibility = LangOpts.IgnoreXCOFFVisibility;
Options.UniqueSectionNames = CodeGenOpts.UniqueSectionNames;
Options.UniqueBasicBlockSectionNames =
CodeGenOpts.UniqueBasicBlockSectionNames;
- Options.StackProtectorGuard =
- llvm::StringSwitch<llvm::StackProtectorGuards>(CodeGenOpts
- .StackProtectorGuard)
- .Case("tls", llvm::StackProtectorGuards::TLS)
- .Case("global", llvm::StackProtectorGuards::Global)
- .Default(llvm::StackProtectorGuards::None);
- Options.StackProtectorGuardOffset = CodeGenOpts.StackProtectorGuardOffset;
- Options.StackProtectorGuardReg = CodeGenOpts.StackProtectorGuardReg;
Options.TLSSize = CodeGenOpts.TLSSize;
Options.EmulatedTLS = CodeGenOpts.EmulatedTLS;
Options.ExplicitEmulatedTLS = CodeGenOpts.ExplicitEmulatedTLS;
Options.DebuggerTuning = CodeGenOpts.getDebuggerTuning();
Options.EmitStackSizeSection = CodeGenOpts.StackSizeSection;
+ Options.StackUsageOutput = CodeGenOpts.StackUsageOutput;
Options.EmitAddrsig = CodeGenOpts.Addrsig;
Options.ForceDwarfFrameSection = CodeGenOpts.ForceDwarfFrameSection;
Options.EmitCallSiteInfo = CodeGenOpts.EmitCallSiteInfo;
@@ -585,6 +603,7 @@ static bool initTargetOptions(DiagnosticsEngine &Diags,
Entry.IgnoreSysRoot ? Entry.Path : HSOpts.Sysroot + Entry.Path);
Options.MCOptions.Argv0 = CodeGenOpts.Argv0;
Options.MCOptions.CommandLineArgs = CodeGenOpts.CommandLineArgs;
+ Options.DebugStrictDwarf = CodeGenOpts.DebugStrictDwarf;
return true;
}
@@ -716,9 +735,7 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
addBoundsCheckingPass);
}
- if (CodeGenOpts.SanitizeCoverageType ||
- CodeGenOpts.SanitizeCoverageIndirectCalls ||
- CodeGenOpts.SanitizeCoverageTraceCmp) {
+ if (CodeGenOpts.hasSanitizeCoverage()) {
PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
addSanitizerCoveragePass);
PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
@@ -781,6 +798,20 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
addDataFlowSanitizerPass);
}
+ if (CodeGenOpts.InstrumentFunctions ||
+ CodeGenOpts.InstrumentFunctionEntryBare ||
+ CodeGenOpts.InstrumentFunctionsAfterInlining ||
+ CodeGenOpts.InstrumentForProfiling) {
+ PMBuilder.addExtension(PassManagerBuilder::EP_EarlyAsPossible,
+ addEntryExitInstrumentationPass);
+ PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+ addEntryExitInstrumentationPass);
+ PMBuilder.addExtension(PassManagerBuilder::EP_OptimizerLast,
+ addPostInlineEntryExitInstrumentationPass);
+ PMBuilder.addExtension(PassManagerBuilder::EP_EnabledOnOptLevel0,
+ addPostInlineEntryExitInstrumentationPass);
+ }
+
// Set up the per-function pass manager.
FPM.add(new TargetLibraryInfoWrapperPass(*TLII));
if (CodeGenOpts.VerifyModule)
@@ -790,12 +821,6 @@ void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
if (!CodeGenOpts.RewriteMapFiles.empty())
addSymbolRewriterPass(CodeGenOpts, &MPM);
- // Add UniqueInternalLinkageNames Pass which renames internal linkage symbols
- // with unique names.
- if (CodeGenOpts.UniqueInternalLinkageNames) {
- MPM.add(createUniqueInternalLinkageNamesPass());
- }
-
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts)) {
MPM.add(createGCOVProfilerPass(*Options));
if (CodeGenOpts.getDebugInfo() == codegenoptions::NoDebugInfo)
@@ -850,7 +875,15 @@ static void setCommandLineOpts(const CodeGenOptions &CodeGenOpts) {
BackendArgs.push_back("-limit-float-precision");
BackendArgs.push_back(CodeGenOpts.LimitFloatPrecision.c_str());
}
+ // Check for the default "clang" invocation that won't set any cl::opt values.
+ // Skip trying to parse the command line invocation to avoid the issues
+ // described below.
+ if (BackendArgs.size() == 1)
+ return;
BackendArgs.push_back(nullptr);
+ // FIXME: The command line parser below is not thread-safe and shares a global
+ // state, so this call might crash or overwrite the options of another Clang
+ // instance in the same process.
llvm::cl::ParseCommandLineOptions(BackendArgs.size() - 1,
BackendArgs.data());
}
@@ -925,7 +958,16 @@ void EmitAssemblyHelper::EmitAssembly(BackendAction Action,
if (TM)
TheModule->setDataLayout(TM->createDataLayout());
- legacy::PassManager PerModulePasses;
+ DebugifyCustomPassManager PerModulePasses;
+ DebugInfoPerPassMap DIPreservationMap;
+ if (CodeGenOpts.EnableDIPreservationVerify) {
+ PerModulePasses.setDebugifyMode(DebugifyMode::OriginalDebugInfo);
+ PerModulePasses.setDIPreservationMap(DIPreservationMap);
+
+ if (!CodeGenOpts.DIBugsReportFilePath.empty())
+ PerModulePasses.setOrigDIVerifyBugsReportFilePath(
+ CodeGenOpts.DIBugsReportFilePath);
+ }
PerModulePasses.add(
createTargetTransformInfoWrapperPass(getTargetIRAnalysis()));
@@ -1058,6 +1100,89 @@ static PassBuilder::OptimizationLevel mapToLevel(const CodeGenOptions &Opts) {
}
}
+static void addSanitizers(const Triple &TargetTriple,
+ const CodeGenOptions &CodeGenOpts,
+ const LangOptions &LangOpts, PassBuilder &PB) {
+ PB.registerOptimizerLastEPCallback([&](ModulePassManager &MPM,
+ PassBuilder::OptimizationLevel Level) {
+ if (CodeGenOpts.hasSanitizeCoverage()) {
+ auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
+ MPM.addPass(ModuleSanitizerCoveragePass(
+ SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,
+ CodeGenOpts.SanitizeCoverageIgnorelistFiles));
+ }
+
+ auto MSanPass = [&](SanitizerMask Mask, bool CompileKernel) {
+ if (LangOpts.Sanitize.has(Mask)) {
+ int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
+ bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
+
+ MPM.addPass(
+ MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ FunctionPassManager FPM;
+ FPM.addPass(
+ MemorySanitizerPass({TrackOrigins, Recover, CompileKernel}));
+ if (Level != PassBuilder::OptimizationLevel::O0) {
+ // MemorySanitizer inserts complex instrumentation that mostly
+ // follows the logic of the original code, but operates on
+ // "shadow" values. It can benefit from re-running some
+ // general purpose optimization passes.
+ FPM.addPass(EarlyCSEPass());
+ // TODO: Consider add more passes like in
+ // addGeneralOptsForMemorySanitizer. EarlyCSEPass makes visible
+ // difference on size. It's not clear if the rest is still
+ // usefull. InstCombinePass breakes
+ // compiler-rt/test/msan/select_origin.cpp.
+ }
+ MPM.addPass(createModuleToFunctionPassAdaptor(std::move(FPM)));
+ }
+ };
+ MSanPass(SanitizerKind::Memory, false);
+ MSanPass(SanitizerKind::KernelMemory, true);
+
+ if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
+ MPM.addPass(ThreadSanitizerPass());
+ MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
+ }
+
+ auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
+ if (LangOpts.Sanitize.has(Mask)) {
+ bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
+ bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
+ bool ModuleUseAfterScope = asanUseGlobalsGC(TargetTriple, CodeGenOpts);
+ bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
+ llvm::AsanDtorKind DestructorKind =
+ CodeGenOpts.getSanitizeAddressDtor();
+ llvm::AsanDetectStackUseAfterReturnMode UseAfterReturn =
+ CodeGenOpts.getSanitizeAddressUseAfterReturn();
+ MPM.addPass(RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
+ MPM.addPass(ModuleAddressSanitizerPass(
+ CompileKernel, Recover, ModuleUseAfterScope, UseOdrIndicator,
+ DestructorKind));
+ MPM.addPass(createModuleToFunctionPassAdaptor(AddressSanitizerPass(
+ CompileKernel, Recover, UseAfterScope, UseAfterReturn)));
+ }
+ };
+ ASanPass(SanitizerKind::Address, false);
+ ASanPass(SanitizerKind::KernelAddress, true);
+
+ auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
+ if (LangOpts.Sanitize.has(Mask)) {
+ bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
+ MPM.addPass(HWAddressSanitizerPass(
+ CompileKernel, Recover,
+ /*DisableOptimization=*/CodeGenOpts.OptimizationLevel == 0));
+ }
+ };
+ HWASanPass(SanitizerKind::HWAddress, false);
+ HWASanPass(SanitizerKind::KernelHWAddress, true);
+
+ if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
+ MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles));
+ }
+ });
+}
+
/// A clean version of `EmitAssembly` that uses the new pass manager.
///
/// Not all features are currently supported in this system, but where
@@ -1147,13 +1272,22 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
// Only enable CGProfilePass when using integrated assembler, since
// non-integrated assemblers don't recognize .cgprofile section.
PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
- PTO.Coroutines = LangOpts.Coroutines;
- PTO.UniqueLinkageNames = CodeGenOpts.UniqueInternalLinkageNames;
+ LoopAnalysisManager LAM;
+ FunctionAnalysisManager FAM;
+ CGSCCAnalysisManager CGAM;
+ ModuleAnalysisManager MAM;
+
+ bool DebugPassStructure = CodeGenOpts.DebugPass == "Structure";
PassInstrumentationCallbacks PIC;
- StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
- SI.registerCallbacks(PIC);
- PassBuilder PB(CodeGenOpts.DebugPassManager, TM.get(), PTO, PGOOpt, &PIC);
+ PrintPassOptions PrintPassOpts;
+ PrintPassOpts.Indent = DebugPassStructure;
+ PrintPassOpts.SkipAnalyses = DebugPassStructure;
+ StandardInstrumentations SI(CodeGenOpts.DebugPassManager ||
+ DebugPassStructure,
+ /*VerifyEach*/ false, PrintPassOpts);
+ SI.registerCallbacks(PIC, &FAM);
+ PassBuilder PB(TM.get(), PTO, PGOOpt, &PIC);
// Attempt to load pass plugins and register their callbacks with PB.
for (auto &PluginFN : CodeGenOpts.PassPlugins) {
@@ -1169,11 +1303,6 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
get##Ext##PluginInfo().RegisterPassBuilderCallbacks(PB);
#include "llvm/Support/Extension.def"
- LoopAnalysisManager LAM(CodeGenOpts.DebugPassManager);
- FunctionAnalysisManager FAM(CodeGenOpts.DebugPassManager);
- CGSCCAnalysisManager CGAM(CodeGenOpts.DebugPassManager);
- ModuleAnalysisManager MAM(CodeGenOpts.DebugPassManager);
-
// Register the AA manager first so that our version is the one used.
FAM.registerPass([&] { return PB.buildDefaultAAPipeline(); });
@@ -1191,7 +1320,7 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
PB.registerLoopAnalyses(LAM);
PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
- ModulePassManager MPM(CodeGenOpts.DebugPassManager);
+ ModulePassManager MPM;
if (!CodeGenOpts.DisableLLVMPasses) {
// Map our optimization levels into one of the distinct levels used to
@@ -1222,10 +1351,11 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
// If we reached here with a non-empty index file name, then the index
// file was empty and we are not performing ThinLTO backend compilation
- // (used in testing in a distributed build environment). Drop any the type
- // test assume sequences inserted for whole program vtables so that
- // codegen doesn't complain.
- if (!CodeGenOpts.ThinLTOIndexFile.empty())
+ // (used in testing in a distributed build environment).
+ bool IsThinLTOPostLink = !CodeGenOpts.ThinLTOIndexFile.empty();
+ // If so drop any the type test assume sequences inserted for whole program
+ // vtables so that codegen doesn't complain.
+ if (IsThinLTOPostLink)
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
MPM.addPass(LowerTypeTestsPass(/*ExportSummary=*/nullptr,
@@ -1233,12 +1363,20 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
/*DropTypeTests=*/true));
});
- if (Level != PassBuilder::OptimizationLevel::O0) {
+ if (CodeGenOpts.InstrumentFunctions ||
+ CodeGenOpts.InstrumentFunctionEntryBare ||
+ CodeGenOpts.InstrumentFunctionsAfterInlining ||
+ CodeGenOpts.InstrumentForProfiling) {
PB.registerPipelineStartEPCallback(
[](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
MPM.addPass(createModuleToFunctionPassAdaptor(
EntryExitInstrumenterPass(/*PostInlining=*/false)));
});
+ PB.registerOptimizerLastEPCallback(
+ [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
+ MPM.addPass(createModuleToFunctionPassAdaptor(
+ EntryExitInstrumenterPass(/*PostInlining=*/true)));
+ });
}
// Register callbacks to schedule sanitizer passes at the appropriate part
@@ -1249,81 +1387,10 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
FPM.addPass(BoundsCheckingPass());
});
- if (CodeGenOpts.SanitizeCoverageType ||
- CodeGenOpts.SanitizeCoverageIndirectCalls ||
- CodeGenOpts.SanitizeCoverageTraceCmp) {
- PB.registerOptimizerLastEPCallback(
- [this](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
- auto SancovOpts = getSancovOptsFromCGOpts(CodeGenOpts);
- MPM.addPass(ModuleSanitizerCoveragePass(
- SancovOpts, CodeGenOpts.SanitizeCoverageAllowlistFiles,
- CodeGenOpts.SanitizeCoverageBlocklistFiles));
- });
- }
-
- if (LangOpts.Sanitize.has(SanitizerKind::Memory)) {
- int TrackOrigins = CodeGenOpts.SanitizeMemoryTrackOrigins;
- bool Recover = CodeGenOpts.SanitizeRecover.has(SanitizerKind::Memory);
- PB.registerOptimizerLastEPCallback(
- [TrackOrigins, Recover](ModulePassManager &MPM,
- PassBuilder::OptimizationLevel Level) {
- MPM.addPass(MemorySanitizerPass({TrackOrigins, Recover, false}));
- MPM.addPass(createModuleToFunctionPassAdaptor(
- MemorySanitizerPass({TrackOrigins, Recover, false})));
- });
- }
- if (LangOpts.Sanitize.has(SanitizerKind::Thread)) {
- PB.registerOptimizerLastEPCallback(
- [](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
- MPM.addPass(ThreadSanitizerPass());
- MPM.addPass(
- createModuleToFunctionPassAdaptor(ThreadSanitizerPass()));
- });
- }
-
- auto ASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
- if (LangOpts.Sanitize.has(Mask)) {
- bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
- bool UseAfterScope = CodeGenOpts.SanitizeAddressUseAfterScope;
- bool ModuleUseAfterScope = asanUseGlobalsGC(TargetTriple, CodeGenOpts);
- bool UseOdrIndicator = CodeGenOpts.SanitizeAddressUseOdrIndicator;
- PB.registerOptimizerLastEPCallback(
- [CompileKernel, Recover, UseAfterScope, ModuleUseAfterScope,
- UseOdrIndicator](ModulePassManager &MPM,
- PassBuilder::OptimizationLevel Level) {
- MPM.addPass(
- RequireAnalysisPass<ASanGlobalsMetadataAnalysis, Module>());
- MPM.addPass(ModuleAddressSanitizerPass(CompileKernel, Recover,
- ModuleUseAfterScope,
- UseOdrIndicator));
- MPM.addPass(createModuleToFunctionPassAdaptor(
- AddressSanitizerPass(CompileKernel, Recover, UseAfterScope)));
- });
- }
- };
- ASanPass(SanitizerKind::Address, false);
- ASanPass(SanitizerKind::KernelAddress, true);
-
- auto HWASanPass = [&](SanitizerMask Mask, bool CompileKernel) {
- if (LangOpts.Sanitize.has(Mask)) {
- bool Recover = CodeGenOpts.SanitizeRecover.has(Mask);
- PB.registerOptimizerLastEPCallback(
- [CompileKernel, Recover](ModulePassManager &MPM,
- PassBuilder::OptimizationLevel Level) {
- MPM.addPass(HWAddressSanitizerPass(CompileKernel, Recover));
- });
- }
- };
- HWASanPass(SanitizerKind::HWAddress, false);
- HWASanPass(SanitizerKind::KernelHWAddress, true);
-
- if (LangOpts.Sanitize.has(SanitizerKind::DataFlow)) {
- PB.registerOptimizerLastEPCallback(
- [this](ModulePassManager &MPM, PassBuilder::OptimizationLevel Level) {
- MPM.addPass(
- DataFlowSanitizerPass(LangOpts.SanitizerBlacklistFiles));
- });
- }
+ // Don't add sanitizers if we are here from ThinLTO PostLink. That already
+ // done on PreLink stage.
+ if (!IsThinLTOPostLink)
+ addSanitizers(TargetTriple, CodeGenOpts, LangOpts, PB);
if (Optional<GCOVOptions> Options = getGCOVOptions(CodeGenOpts, LangOpts))
PB.registerPipelineStartEPCallback(
@@ -1455,10 +1522,7 @@ static void runThinLTOBackend(
// we should only invoke this using the individual indexes written out
// via a WriteIndexesThinBackend.
FunctionImporter::ImportMapTy ImportList;
- std::vector<std::unique_ptr<llvm::MemoryBuffer>> OwnedImports;
- MapVector<llvm::StringRef, llvm::BitcodeModule> ModuleMap;
- if (!lto::loadReferencedModules(*M, *CombinedIndex, ImportList, ModuleMap,
- OwnedImports))
+ if (!lto::initImportList(*M, *CombinedIndex, ImportList))
return;
auto AddStream = [&](size_t Task) {
@@ -1535,7 +1599,7 @@ static void runThinLTOBackend(
if (Error E =
thinBackend(Conf, -1, AddStream, *M, *CombinedIndex, ImportList,
ModuleToDefinedGVSummaries[M->getModuleIdentifier()],
- ModuleMap, CGOpts.CmdArgs)) {
+ /* ModuleMap */ nullptr, CGOpts.CmdArgs)) {
handleAllErrors(std::move(E), [&](ErrorInfoBase &EIB) {
errs() << "Error running ThinLTO backend: " << EIB.message() << '\n';
});
@@ -1547,7 +1611,7 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
const CodeGenOptions &CGOpts,
const clang::TargetOptions &TOpts,
const LangOptions &LOpts,
- const llvm::DataLayout &TDesc, Module *M,
+ StringRef TDesc, Module *M,
BackendAction Action,
std::unique_ptr<raw_pwrite_stream> OS) {
@@ -1601,11 +1665,11 @@ void clang::EmitBackendOutput(DiagnosticsEngine &Diags,
// DataLayout.
if (AsmHelper.TM) {
std::string DLDesc = M->getDataLayout().getStringRepresentation();
- if (DLDesc != TDesc.getStringRepresentation()) {
+ if (DLDesc != TDesc) {
unsigned DiagID = Diags.getCustomDiagID(
DiagnosticsEngine::Error, "backend data layout '%0' does not match "
"expected target description '%1'");
- Diags.Report(DiagID) << DLDesc << TDesc.getStringRepresentation();
+ Diags.Report(DiagID) << DLDesc << TDesc;
}
}
}