[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 17:13:26 PST 2018


Let's see...

With the bitcode for X86FastISel.cpp as input (-O0), I see about a 3% drop in the wall time for opt:

pre-patch

$ ../llvm.org-combines-RA/bin/opt -instrprof test.bc -o /dev/null -time-passes
===-------------------------------------------------------------------------===
                      ... Pass execution timing report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.1236 seconds (0.1236 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   0.0763 ( 65.4%)   0.0055 ( 79.9%)   0.0818 ( 66.2%)   0.0818 ( 66.2%)  Bitcode Writer
   0.0369 ( 31.7%)   0.0014 ( 19.8%)   0.0383 ( 31.0%)   0.0384 ( 31.0%)  Module Verifier
   0.0035 (  3.0%)   0.0000 (  0.4%)   0.0035 (  2.8%)   0.0035 (  2.8%)  Frontend instrumentation-based coverage lowering
   0.1167 (100.0%)   0.0069 (100.0%)   0.1236 (100.0%)   0.1236 (100.0%)  Total

post-patch

$ ./bin/opt -instrprof test.bc -o /dev/null -time-passes
===-------------------------------------------------------------------------===
                      ... Pass execution timing report ...
===-------------------------------------------------------------------------===
  Total Execution Time: 0.1161 seconds (0.1161 wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  --- Name ---
   0.0761 ( 69.7%)   0.0057 ( 81.1%)   0.0818 ( 70.4%)   0.0818 ( 70.5%)  Bitcode Writer
   0.0330 ( 30.2%)   0.0013 ( 18.8%)   0.0343 ( 29.6%)   0.0343 ( 29.5%)  Module Verifier
   0.0000 (  0.0%)   0.0000 (  0.1%)   0.0000 (  0.0%)   0.0000 (  0.0%)  Frontend instrumentation-based coverage lowering
   0.1091 (100.0%)   0.0070 (100.0%)   0.1161 (100.0%)   0.1161 (100.0%)  Total

The real motivation is that we might consider always enabling -instrprof in Swift, because when you import a swiftmodule, it can contained arbitrary serialized SIL, including profiling intrinsics. For now we have a simpler solution: https://github.com/apple/swift/pull/14206 <https://github.com/apple/swift/pull/14206>. This is just a bit of future-proofing.

vedant

> On Jan 26, 2018, at 4:52 PM, Davide Italiano <davide at freebsd.org> wrote:
> 
> This is good. Do you happen to have numbers for my own intellectual
> curiosity? (and for the archives)
> 
> On Fri, Jan 26, 2018 at 3:54 PM, Vedant Kumar via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> 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;
>>   }
>> 
>> 
>> _______________________________________________
>> llvm-commits mailing list
>> llvm-commits at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
> 
> 
> 
> -- 
> Davide
> 
> "There are no solved problems; there are only problems that are more
> or less solved" -- Henri Poincare

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180126/03086075/attachment.html>


More information about the llvm-commits mailing list