[PATCH] D124797: [memprof] Only insert dynamic shadow load when needed

Teresa Johnson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 2 12:53:39 PDT 2022


tejohnson updated this revision to Diff 426495.
tejohnson added a comment.

Address comment


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D124797

Files:
  llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
  llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll


Index: llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll
===================================================================
--- /dev/null
+++ llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll
@@ -0,0 +1,23 @@
+;; Test that we don't add any instrumentation code to functions without
+;; interesting memory accesses.
+;
+; RUN: opt < %s -passes='function(memprof),module(memprof-module)' -S -debug 2>&1 | FileCheck %s
+
+;; Require asserts for -debug
+; REQUIRES: asserts
+
+target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
+target triple = "x86_64-unknown-linux-gnu"
+
+define void @_Z3foov() {
+entry:
+  ret void
+}
+
+;; Confirm we ran memprof and decided not to instrument
+; CHECK: MEMPROF done instrumenting: 0 define void @_Z3foov
+
+;; We should not add any instrumentation related code
+; CHECK: define void @_Z3foov
+; CHECK-NEXT: entry:
+; CHECK-NEXT:  ret void
Index: llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
===================================================================
--- llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
+++ llvm/lib/Transforms/Instrumentation/MemProfiler.cpp
@@ -633,8 +633,6 @@
 
   initializeCallbacks(*F.getParent());
 
-  FunctionModified |= insertDynamicShadowAtFunctionEntry(F);
-
   SmallVector<Instruction *, 16> ToInstrument;
 
   // Fill the set of memory operations to instrument.
@@ -645,6 +643,15 @@
     }
   }
 
+  if (ToInstrument.empty()) {
+    LLVM_DEBUG(dbgs() << "MEMPROF done instrumenting: " << FunctionModified
+                      << " " << F << "\n");
+
+    return FunctionModified;
+  }
+
+  FunctionModified |= insertDynamicShadowAtFunctionEntry(F);
+
   int NumInstrumented = 0;
   for (auto *Inst : ToInstrument) {
     if (ClDebugMin < 0 || ClDebugMax < 0 ||


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D124797.426495.patch
Type: text/x-patch
Size: 1882 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220502/07341580/attachment.bin>


More information about the llvm-commits mailing list