[all-commits] [llvm/llvm-project] ce54b2: [Clang][CoverageMapping] Fix switch counter codege...

Bruno Cardoso Lopes via All-commits all-commits at lists.llvm.org
Thu May 26 11:11:42 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: ce54b22657f01d1c40de4941ceb6e7119848aecf
      https://github.com/llvm/llvm-project/commit/ce54b22657f01d1c40de4941ceb6e7119848aecf
  Author: Bruno Cardoso Lopes <bruno.cardoso at gmail.com>
  Date:   2022-05-26 (Thu, 26 May 2022)

  Changed paths:
    M clang/lib/CodeGen/CoverageMappingGen.cpp
    M llvm/include/llvm/ProfileData/Coverage/CoverageMapping.h
    M llvm/lib/ProfileData/Coverage/CoverageMapping.cpp

  Log Message:
  -----------
  [Clang][CoverageMapping] Fix switch counter codegen compile time explosion

C++ generated code with huge amount of switch cases chokes badly while emitting
coverage mapping, in our specific testcase (~72k cases), it won't stop after hours.
After this change, the frontend job now finishes in 4.5s and shrinks down `@__covrec_`
by 288k when compared to disabling simplification altogether.

There's probably no good way to create a testcase for this, but it's easy to
reproduce, just add thousands of cases in the below switch, and build with
`-fprofile-instr-generate -fcoverage-mapping`.

```
enum type : int {
 FEATURE_INVALID = 0,
 FEATURE_A = 1,
 ...
};

const char *to_string(type e) {
  switch (e) {
  case type::FEATURE_INVALID: return "FEATURE_INVALID";
  case type::FEATURE_A: return "FEATURE_A";}
  ...
  }

```

Differential Revision: https://reviews.llvm.org/D126345




More information about the All-commits mailing list