llvm.org GIT mirror llvm / 4f349ac
[asan] Speed up compilation of large C++ stringmaps (tons of allocas) with ASan This addresses PR30746, <https://llvm.org/bugs/show_bug.cgi?id=30746>. The ASan pass iterates over entry-block instructions and checks each alloca whether it's in NonInstrumentedStaticAllocaVec, which is apparently slow. This patch gathers the instructions to move during visitAllocaInst. Differential Revision: https://reviews.llvm.org/D26380 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286296 91177308-0d34-0410-b5e6-96231b3b80d8 Kuba Brecka 4 years ago
2 changed file(s) with 33 addition(s) and 6 deletion(s). Raw diff Collapse all Expand all
637637 ShadowMapping Mapping;
638638
639639 SmallVector AllocaVec;
640 SmallSetVector NonInstrumentedStaticAllocaVec;
640 SmallVector StaticAllocasToMoveUp;
641641 SmallVector RetVec;
642642 unsigned StackAlignment;
643643
765765 /// \brief Collect Alloca instructions we want (and can) handle.
766766 void visitAllocaInst(AllocaInst &AI) {
767767 if (!ASan.isInterestingAlloca(AI)) {
768 if (AI.isStaticAlloca()) NonInstrumentedStaticAllocaVec.insert(&AI);
768 if (AI.isStaticAlloca()) {
769 // Skip over allocas that are present *before* the first instrumented
770 // alloca, we don't want to move those around.
771 if (AllocaVec.empty())
772 return;
773
774 StaticAllocasToMoveUp.push_back(&AI);
775 }
769776 return;
770777 }
771778
22302237 // regular stack slots.
22312238 auto InsBeforeB = InsBefore->getParent();
22322239 assert(InsBeforeB == &F.getEntryBlock());
2233 for (BasicBlock::iterator I(InsBefore); I != InsBeforeB->end(); ++I)
2234 if (auto *AI = dyn_cast(I))
2235 if (NonInstrumentedStaticAllocaVec.count(AI) > 0)
2236 AI->moveBefore(InsBefore);
2240 for (auto *AI : StaticAllocasToMoveUp)
2241 if (AI->getParent() == InsBeforeB)
2242 AI->moveBefore(InsBefore);
22372243
22382244 // If we have a call to llvm.localescape, keep it in the entry block.
22392245 if (LocalEscapeCall) LocalEscapeCall->moveBefore(InsBefore);
0 ; Make sure we don't break the IR when moving non-instrumented allocas
1
2 ; RUN: opt < %s -asan -asan-module -S | FileCheck %s
3 ; RUN: opt < %s -asan -asan-module -asan-instrument-dynamic-allocas -S | FileCheck %s
4
5 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 target triple = "x86_64-apple-macosx10.10.0"
7
8 define i32 @foo() sanitize_address {
9 entry:
10 %non_instrumented1 = alloca i32, align 4
11 %t = load i32, i32* %non_instrumented1, align 4
12 %instrumented = alloca i32, align 4
13 %ptr = ptrtoint i32* %instrumented to i32
14 ret i32 %t
15 }
16
17 ; CHECK: entry:
18 ; CHECK: %non_instrumented1 = alloca i32, align 4
19 ; CHECK: load i32, i32* %non_instrumented1
20 ; CHECK: load i32, i32* @__asan_option_detect_stack_use_after_return