[llvm] r323574 - [InstrProfiling] Improve compile time when there is no work

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Fri Jan 26 15:54:24 PST 2018


Author: vedantk
Date: Fri Jan 26 15:54:24 2018
New Revision: 323574

URL: http://llvm.org/viewvc/llvm-project?rev=323574&view=rev
Log:
[InstrProfiling] Improve compile time when there is no work

When there are no uses of profiling intrinsics in a module, and there's
no coverage data to lower, InstrProfiling has no work to do.

Modified:
    llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp

Modified: llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp?rev=323574&r1=323573&r2=323574&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/InstrProfiling.cpp Fri Jan 26 15:54:24 2018
@@ -430,7 +430,27 @@ void InstrProfiling::promoteCounterLoadS
   }
 }
 
+/// Check if the module contains uses of any profiling intrinsics.
+static bool containsProfilingIntrinsics(Module &M) {
+  if (auto *F = M.getFunction(
+          Intrinsic::getName(llvm::Intrinsic::instrprof_increment)))
+    return !F->use_empty();
+  if (auto *F = M.getFunction(
+          Intrinsic::getName(llvm::Intrinsic::instrprof_increment_step)))
+    return !F->use_empty();
+  if (auto *F = M.getFunction(
+          Intrinsic::getName(llvm::Intrinsic::instrprof_value_profile)))
+    return !F->use_empty();
+  return false;
+}
+
 bool InstrProfiling::run(Module &M, const TargetLibraryInfo &TLI) {
+  // Improve compile time by avoiding linear scans when there is no work.
+  GlobalVariable *CoverageNamesVar =
+      M.getNamedGlobal(getCoverageUnusedNamesVarName());
+  if (!containsProfilingIntrinsics(M) && !CoverageNamesVar)
+    return false;
+
   bool MadeChange = false;
 
   this->M = &M;
@@ -464,8 +484,7 @@ bool InstrProfiling::run(Module &M, cons
   for (Function &F : M)
     MadeChange |= lowerIntrinsics(&F);
 
-  if (GlobalVariable *CoverageNamesVar =
-          M.getNamedGlobal(getCoverageUnusedNamesVarName())) {
+  if (CoverageNamesVar) {
     lowerCoverageData(CoverageNamesVar);
     MadeChange = true;
   }




More information about the llvm-commits mailing list