[PATCH] D52088: [GCOV] Don't add a useless block in the entry

Eli Friedman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 17 16:50:43 PDT 2018


efriedma added a comment.

I'm not really familiar with the gcov file format, but this change looks reasonable.



================
Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:670
 
-          TerminatorInst *TI = BB.getTerminator();
-          if (isa<ReturnInst>(TI)) {
-            auto It = EdgeToCounter.find({&BB, nullptr});
-            assert(It != EdgeToCounter.end());
-            const unsigned Edge = It->second;
-            Value *Counter =
-                Builder.CreateConstInBoundsGEP2_64(Counters, 0, Edge);
-            Value *Count = Builder.CreateLoad(Counter);
-            Count = Builder.CreateAdd(Count, Builder.getInt64(1));
-            Builder.CreateStore(Count, Counter);
-          }
+        if (succ_begin(&BB) == succ_end(&BB)) {
+          IRBuilder<> Builder(&*BB.getFirstInsertionPt());
----------------
succ_empty()

There are four possible terminators for a block with no successors: `ret`, `unreachable`, `resume`, and `cleanupret`.  Writing good testcases for exception handling is probably hard, but it would be nice to at least ensure we generate something sane for a function that explicitly calls `exit()`.


================
Comment at: test/Transforms/GCOVProfiling/multiple-cus.ll:5
+; RUN: opt -S -insert-gcov-profiling %t.lto.bc -o -
+; TODO: Check that the IR is correct.
----------------
(Needs to be fixed.)


Repository:
  rL LLVM

https://reviews.llvm.org/D52088





More information about the llvm-commits mailing list