llvmbot wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang-codegen

Author: Chris Apple (cjappl)

<details>
<summary>Changes</summary>

As suggested by @<!-- -->vitalybuka on #<!-- -->118989 

Most of the other sanitizers are now only module level passes. This moves all 
functionality into the module pass, and removes the function pass.

---
Full diff: https://github.com/llvm/llvm-project/pull/119739.diff


6 Files Affected:

- (modified) clang/lib/CodeGen/BackendUtil.cpp (+2-8) 
- (modified) llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h 
(+1-12) 
- (modified) llvm/lib/Passes/PassBuilder.cpp (-5) 
- (modified) llvm/lib/Passes/PassRegistry.def (+1-5) 
- (modified) llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp (+11-16) 
- (modified) llvm/test/Instrumentation/RealtimeSanitizer/rtsan.ll (+1-1) 


``````````diff
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 8cf44592a17475..b3728c478772d3 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1023,14 +1023,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline(
             FPM.addPass(BoundsCheckingPass());
           });
 
-    if (LangOpts.Sanitize.has(SanitizerKind::Realtime)) {
-      PB.registerScalarOptimizerLateEPCallback(
-          [](FunctionPassManager &FPM, OptimizationLevel Level) {
-            RealtimeSanitizerOptions Opts;
-            FPM.addPass(RealtimeSanitizerPass(Opts));
-          });
-      MPM.addPass(ModuleRealtimeSanitizerPass());
-    }
+    if (LangOpts.Sanitize.has(SanitizerKind::Realtime))
+      MPM.addPass(RealtimeSanitizerPass());
 
     // Don't add sanitizers if we are here from ThinLTO PostLink. That already
     // done on PreLink stage.
diff --git a/llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h 
b/llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h
index 151e70e87b294d..5ee1cb0443932a 100644
--- a/llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h
+++ b/llvm/include/llvm/Transforms/Instrumentation/RealtimeSanitizer.h
@@ -23,19 +23,8 @@
 
 namespace llvm {
 
-struct RealtimeSanitizerOptions {};
-
-class RealtimeSanitizerPass : public PassInfoMixin<RealtimeSanitizerPass> {
-public:
-  RealtimeSanitizerPass(const RealtimeSanitizerOptions &Options);
-  PreservedAnalyses run(Function &F, AnalysisManager<Function> &AM);
-
-  static bool isRequired() { return true; }
-};
-
 /// Create ctor and init functions.
-struct ModuleRealtimeSanitizerPass
-    : public PassInfoMixin<ModuleRealtimeSanitizerPass> {
+struct RealtimeSanitizerPass : public PassInfoMixin<RealtimeSanitizerPass> {
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
   static bool isRequired() { return true; }
 };
diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp
index 260a34f2e060d6..6e1cefdb3f4d70 100644
--- a/llvm/lib/Passes/PassBuilder.cpp
+++ b/llvm/lib/Passes/PassBuilder.cpp
@@ -1281,11 +1281,6 @@ parseRegAllocFastPassOptions(PassBuilder &PB, StringRef 
Params) {
   return Opts;
 }
 
-Expected<RealtimeSanitizerOptions> parseRtSanPassOptions(StringRef Params) {
-  RealtimeSanitizerOptions Result;
-  return Result;
-}
-
 } // namespace
 
 /// Tests whether a pass name starts with a valid prefix for a default pipeline
diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def
index 2ddebb07017c2a..5203e9989d1132 100644
--- a/llvm/lib/Passes/PassRegistry.def
+++ b/llvm/lib/Passes/PassRegistry.def
@@ -138,7 +138,7 @@ MODULE_PASS("rel-lookup-table-converter", 
RelLookupTableConverterPass())
 MODULE_PASS("rewrite-statepoints-for-gc", RewriteStatepointsForGC())
 MODULE_PASS("rewrite-symbols", RewriteSymbolPass())
 MODULE_PASS("rpo-function-attrs", ReversePostOrderFunctionAttrsPass())
-MODULE_PASS("rtsan-module", ModuleRealtimeSanitizerPass())
+MODULE_PASS("rtsan", RealtimeSanitizerPass())
 MODULE_PASS("sample-profile", SampleProfileLoaderPass())
 MODULE_PASS("sancov-module", SanitizerCoveragePass())
 MODULE_PASS("sanmd-module", SanitizerBinaryMetadataPass())
@@ -618,10 +618,6 @@ FUNCTION_PASS_WITH_PARAMS(
       return WinEHPreparePass(DemoteCatchSwitchPHIOnly);
     },
     parseWinEHPrepareOptions, "demote-catchswitch-only")
-FUNCTION_PASS_WITH_PARAMS(
-    "rtsan", "RealtimeSanitizerPass",
-    [](RealtimeSanitizerOptions Opts) { return RealtimeSanitizerPass(Opts); },
-    parseRtSanPassOptions, "")
 #undef FUNCTION_PASS_WITH_PARAMS
 
 #ifndef LOOPNEST_PASS
diff --git a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp 
b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
index 890c79ae96718a..5ef6ffb58a7c13 100644
--- a/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/RealtimeSanitizer.cpp
@@ -80,27 +80,22 @@ static PreservedAnalyses 
runSanitizeRealtimeBlocking(Function &Fn) {
   return rtsanPreservedCFGAnalyses();
 }
 
-RealtimeSanitizerPass::RealtimeSanitizerPass(
-    const RealtimeSanitizerOptions &Options) {}
-
-PreservedAnalyses RealtimeSanitizerPass::run(Function &Fn,
-                                             AnalysisManager<Function> &AM) {
-  if (Fn.hasFnAttribute(Attribute::SanitizeRealtime))
-    return runSanitizeRealtime(Fn);
-
-  if (Fn.hasFnAttribute(Attribute::SanitizeRealtimeBlocking))
-    return runSanitizeRealtimeBlocking(Fn);
-
-  return PreservedAnalyses::all();
-}
-
-PreservedAnalyses ModuleRealtimeSanitizerPass::run(Module &M,
-                                                   ModuleAnalysisManager &MAM) 
{
+PreservedAnalyses RealtimeSanitizerPass::run(Module &M,
+                                             ModuleAnalysisManager &MAM) {
   getOrCreateSanitizerCtorAndInitFunctions(
       M, kRtsanModuleCtorName, kRtsanInitName, /*InitArgTypes=*/{},
       /*InitArgs=*/{},
       // This callback is invoked when the functions are created the first
       // time. Hook them into the global ctors list in that case:
       [&](Function *Ctor, FunctionCallee) { appendToGlobalCtors(M, Ctor, 0); 
});
+
+  for (Function &F : M) {
+    if (F.hasFnAttribute(Attribute::SanitizeRealtime))
+      runSanitizeRealtime(F);
+
+    if (F.hasFnAttribute(Attribute::SanitizeRealtimeBlocking))
+      runSanitizeRealtimeBlocking(F);
+  }
+
   return PreservedAnalyses::none();
 }
diff --git a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan.ll 
b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan.ll
index c245a85a9a4856..18d9b4cae95df2 100644
--- a/llvm/test/Instrumentation/RealtimeSanitizer/rtsan.ll
+++ b/llvm/test/Instrumentation/RealtimeSanitizer/rtsan.ll
@@ -1,4 +1,4 @@
-; RUN: opt < %s -passes='function(rtsan),module(rtsan-module)' -S | FileCheck 
%s
+; RUN: opt < %s -passes='rtsan' -S | FileCheck %s
 
 define void @violation() #0 {
   %1 = alloca ptr, align 8

``````````

</details>


https://github.com/llvm/llvm-project/pull/119739
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to