diff --git a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp --- a/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp +++ b/llvm/lib/Transforms/Instrumentation/MemProfiler.cpp @@ -633,8 +633,6 @@ initializeCallbacks(*F.getParent()); - FunctionModified |= insertDynamicShadowAtFunctionEntry(F); - SmallVector 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 || diff --git a/llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll b/llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll new file mode 100644 --- /dev/null +++ b/llvm/test/Instrumentation/HeapProfiler/no-instrumentation.ll @@ -0,0 +1,17 @@ +;; 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 | FileCheck %s + +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 +} + +;; We should not add any instrumentation related code +; CHECK: define void @_Z3foov +; CHECK-NEXT: entry: +; CHECK-NEXT: ret void