From 8f8616655c4d643d73601c6bf4b492fb9d3b52c8 Mon Sep 17 00:00:00 2001 From: Bjorn Pettersson Date: Wed, 15 Sep 2021 22:26:22 +0200 Subject: [PATCH] [NewPM] Use a separate struct for ModuleThreadSanitizerPass Split ThreadSanitizerPass into ThreadSanitizerPass (as a function pass) and ModuleThreadSanitizerPass (as a module pass). Main reason is to make sure that we have a unique mapping from ClassName to PassName in the new passmanager framework, making it possible to correctly identify the passes when dealing with options such as -print-after and -print-pipeline-passes. This is a follow-up to D105006 and D105007. --- clang/lib/CodeGen/BackendUtil.cpp | 2 +- .../llvm/Transforms/Instrumentation/ThreadSanitizer.h | 8 ++++++++ llvm/lib/Passes/PassRegistry.def | 2 +- llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 3867ecfd4dab..2fdad81241c6 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1142,7 +1142,7 @@ static void addSanitizers(const Triple &TargetTriple, MSanPass(SanitizerKind::KernelMemory, true); if (LangOpts.Sanitize.has(SanitizerKind::Thread)) { - MPM.addPass(ThreadSanitizerPass()); + MPM.addPass(ModuleThreadSanitizerPass()); MPM.addPass(createModuleToFunctionPassAdaptor(ThreadSanitizerPass())); } diff --git a/llvm/include/llvm/Transforms/Instrumentation/ThreadSanitizer.h b/llvm/include/llvm/Transforms/Instrumentation/ThreadSanitizer.h index f9c507624e6d..e795043630d5 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/ThreadSanitizer.h +++ b/llvm/include/llvm/Transforms/Instrumentation/ThreadSanitizer.h @@ -27,6 +27,14 @@ FunctionPass *createThreadSanitizerLegacyPassPass(); /// yet, the pass inserts the declarations. Otherwise the existing globals are struct ThreadSanitizerPass : public PassInfoMixin { PreservedAnalyses run(Function &F, FunctionAnalysisManager &FAM); + static bool isRequired() { return true; } +}; + +/// A module pass for tsan instrumentation. +/// +/// Create ctor and init functions. +struct ModuleThreadSanitizerPass + : public PassInfoMixin { PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM); static bool isRequired() { return true; } }; diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 6f107c35e607..689ae6263466 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -111,7 +111,7 @@ MODULE_PASS("wholeprogramdevirt", WholeProgramDevirtPass()) MODULE_PASS("dfsan", DataFlowSanitizerPass()) MODULE_PASS("asan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/false, false, true, false)) MODULE_PASS("msan-module", ModuleMemorySanitizerPass({})) -MODULE_PASS("tsan-module", ThreadSanitizerPass()) +MODULE_PASS("tsan-module", ModuleThreadSanitizerPass()) MODULE_PASS("kasan-module", ModuleAddressSanitizerPass(/*CompileKernel=*/true, false, true, false)) MODULE_PASS("sancov-module", ModuleSanitizerCoveragePass()) MODULE_PASS("memprof-module", ModuleMemProfilerPass()) diff --git a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp index 714e21dc82bb..b967b37b4fda 100644 --- a/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp +++ b/llvm/lib/Transforms/Instrumentation/ThreadSanitizer.cpp @@ -206,8 +206,8 @@ PreservedAnalyses ThreadSanitizerPass::run(Function &F, return PreservedAnalyses::all(); } -PreservedAnalyses ThreadSanitizerPass::run(Module &M, - ModuleAnalysisManager &MAM) { +PreservedAnalyses ModuleThreadSanitizerPass::run(Module &M, + ModuleAnalysisManager &MAM) { insertModuleCtor(M); return PreservedAnalyses::none(); }