[PATCH] D134769: [ASan] Workaround for a performance problem in StackSafetyAnalysis pass.

Kirill Stoimenov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 27 16:11:45 PDT 2022


kstoimenov updated this revision to Diff 463358.
kstoimenov marked an inline comment as done.
kstoimenov retitled this revision from "[ASan] Workaround for a performance problem in StackSafetyAnalysis pass. " to "[ASan] Workaround for a performance problem in StackSafetyAnalysis pass.".
kstoimenov added a comment.

Addressed comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D134769/new/

https://reviews.llvm.org/D134769

Files:
  llvm/lib/Analysis/StackSafetyAnalysis.cpp
  llvm/test/Analysis/StackSafetyAnalysis/stack-safety-max-allocas.ll


Index: llvm/test/Analysis/StackSafetyAnalysis/stack-safety-max-allocas.ll
===================================================================
--- /dev/null
+++ llvm/test/Analysis/StackSafetyAnalysis/stack-safety-max-allocas.ll
@@ -0,0 +1,13 @@
+; REQUIRES: x86-registered-target
+
+; RUN: opt < %s -S -asan-instrumentation-with-call-threshold=0 -passes='asan-pipeline' -asan-use-stack-safety=1 \
+; RUN:   -stack-safety-max-allocas=0 -o - | FileCheck %s --check-prefixes=ALLOCAS
+
+; ALLOCAS-LABEL: define i32 @f
+define i32 @f() sanitize_address {
+  %buf = alloca [10 x i8], align 1
+  ; ALLOCAS: call i64 @__asan_stack_malloc
+  %arrayidx = getelementptr inbounds [10 x i8], [10 x i8]* %buf, i64 0, i64 0
+  %1 = load i8, i8* %arrayidx, align 1
+  ret i32 0
+}
Index: llvm/lib/Analysis/StackSafetyAnalysis.cpp
===================================================================
--- llvm/lib/Analysis/StackSafetyAnalysis.cpp
+++ llvm/lib/Analysis/StackSafetyAnalysis.cpp
@@ -59,6 +59,9 @@
 STATISTIC(NumIndexCalleeMultipleExternal, "Number of index callee non-unique external.");
 
 
+static cl::opt<size_t> StackSafetyMaxAllocas("stack-safety-max-allocas",
+                                             cl::init(250), cl::Hidden);
+
 static cl::opt<int> StackSafetyMaxIterations("stack-safety-max-iterations",
                                              cl::init(20), cl::Hidden);
 
@@ -527,8 +530,15 @@
 
   SmallVector<AllocaInst *, 64> Allocas;
   for (auto &I : instructions(F))
-    if (auto *AI = dyn_cast<AllocaInst>(&I))
+    if (auto *AI = dyn_cast<AllocaInst>(&I)) {
       Allocas.push_back(AI);
+      // Skip stack safety analysis if there are too many allocas.
+      if (Allocas.size() > StackSafetyMaxAllocas) {
+        LLVM_DEBUG(dbgs() << "\n[StackSafety] skipped\n");
+        return Info;
+      }
+    }
+
   StackLifetime SL(F, Allocas, StackLifetime::LivenessType::Must);
   SL.run();
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D134769.463358.patch
Type: text/x-patch
Size: 1916 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220927/09e74d93/attachment.bin>


More information about the llvm-commits mailing list