[clang] c69b269 - [pipelines] Require GlobalsAA after sanitizers

Vitaly Buka via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 14 13:34:05 PDT 2022


Author: Vitaly Buka
Date: 2022-09-14T13:33:53-07:00
New Revision: c69b26911168cdcf49c7c7162d7b44ce4ed40c37

URL: https://github.com/llvm/llvm-project/commit/c69b26911168cdcf49c7c7162d7b44ce4ed40c37
DIFF: https://github.com/llvm/llvm-project/commit/c69b26911168cdcf49c7c7162d7b44ce4ed40c37.diff

LOG: [pipelines] Require GlobalsAA after sanitizers

Restore GlobalsAA if sanitizers inserted at early optimize callback.
The analysis can be useful for the following FunctionPassManager.

Reviewed By: aeubanks

Differential Revision: https://reviews.llvm.org/D133537

Added: 
    

Modified: 
    clang/lib/CodeGen/BackendUtil.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp
index 096cf5bd6610..e9f2f5d9d1c6 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -668,7 +668,7 @@ static void addSanitizers(const Triple &TargetTriple,
           // the logic of the original code, but operates on "shadow" values. It
           // can benefit from re-running some general purpose optimization
           // passes.
-          MPM.addPass(RecomputeGlobalsAAPass());
+          MPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
           FunctionPassManager FPM;
           FPM.addPass(EarlyCSEPass(true /* Enable mem-ssa. */));
           FPM.addPass(InstCombinePass());
@@ -723,10 +723,21 @@ static void addSanitizers(const Triple &TargetTriple,
       MPM.addPass(DataFlowSanitizerPass(LangOpts.NoSanitizeFiles));
     }
   };
-  if (ClSanitizeOnOptimizerEarlyEP)
-    PB.registerOptimizerEarlyEPCallback(SanitizersCallback);
-  else
+  if (ClSanitizeOnOptimizerEarlyEP) {
+    PB.registerOptimizerEarlyEPCallback(
+        [SanitizersCallback](ModulePassManager &MPM, OptimizationLevel Level) {
+          ModulePassManager NewMPM;
+          SanitizersCallback(NewMPM, Level);
+          if (!NewMPM.isEmpty()) {
+            // Sanitizers can abandon<GlobalsAA>.
+            NewMPM.addPass(RequireAnalysisPass<GlobalsAA, Module>());
+            MPM.addPass(std::move(NewMPM));
+          }
+        });
+  } else {
+    // LastEP does not need GlobalsAA.
     PB.registerOptimizerLastEPCallback(SanitizersCallback);
+  }
 }
 
 void EmitAssemblyHelper::RunOptimizationPipeline(


        


More information about the cfe-commits mailing list