Hiralo created this revision.
Hiralo added a reviewer: vsk.
Hiralo added a project: clang.
Herald added subscribers: dexonsmith, wenlei, dang.
Herald added a project: All.
Hiralo requested review of this revision.
Herald added a subscriber: cfe-commits.

commit 87f30be546daca55664ded147acceb9f206399e0
Author: Hiral Oza <hiral....@netapp.com>
Date:   Fri Mar 11 09:41:38 2022 +0530

  Add -no-unused-coverage option
  
  Reduce the size of instrumented objects by eliminating counters for code that 
will not be emitted.
  
  Author: thom.h...@netapp.com

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 3301e7587d21..e51261ddcced 100644

- a/clang/include/clang/Basic/CodeGenOptions.def

+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -211,6 +211,8 @@ CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage 
mapping regions to

  ///< enable code coverage analysis.

CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping

  ///< regions.

+CODEGENOPT(NoUnusedCoverage , 1, 0) ///< Turn off coverage mapping for code 
that
+                                    ///< is not emitted.

  /// If -fpcc-struct-return or -freg-struct-return is specified.

ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index fa54d4a7689c..05926e01efb1 100644

- a/clang/include/clang/Driver/Options.td

+++ b/clang/include/clang/Driver/Options.td
@@ -5158,6 +5158,9 @@ def coverage_version_EQ : Joined<["-"], 
"coverage-version=">,
 def dump_coverage_mapping : Flag<["-"], "dump-coverage-mapping">,

  HelpText<"Dump the coverage mapping records, for testing">,
  MarshallingInfoFlag<CodeGenOpts<"DumpCoverageMapping">>;

+def no_unused_coverage : Flag<["-"], "no-unused-coverage">,
+  HelpText<"Turn off coverage mapping for code that is not emitted">,
+  MarshallingInfoFlag<CodeGenOpts<"NoUnusedCoverage">>;
 def fuse_register_sized_bitfield_access: Flag<["-"], 
"fuse-register-sized-bitfield-access">,

  HelpText<"Use register sized accesses to bit-fields, when possible.">,
  MarshallingInfoFlag<CodeGenOpts<"UseRegisterSizedBitfieldAccess">>;

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 9c76648f5f19..bc968d888e11 100644

- a/clang/lib/CodeGen/CodeGenModule.cpp

+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -538,7 +538,9 @@ void CodeGenModule::Release() {

  EmitCtorList(GlobalDtors, "llvm.global_dtors");
  EmitGlobalAnnotations();
  EmitStaticExternCAliases();

- EmitDeferredUnusedCoverageMappings();

+  if (!CodeGenOpts.NoUnusedCoverage) {
+    EmitDeferredUnusedCoverageMappings();
+  }

  CodeGenPGO(*this).setValueProfilingFlag(getModule());
  if (CoverageMapping)
    CoverageMapping->emit();


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D121446

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -538,7 +538,9 @@
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
-  EmitDeferredUnusedCoverageMappings();
+  if (!CodeGenOpts.NoUnusedCoverage) {
+    EmitDeferredUnusedCoverageMappings();
+  }
   CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
     CoverageMapping->emit();
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5158,6 +5158,9 @@
 def dump_coverage_mapping : Flag<["-"], "dump-coverage-mapping">,
   HelpText<"Dump the coverage mapping records, for testing">,
   MarshallingInfoFlag<CodeGenOpts<"DumpCoverageMapping">>;
+def no_unused_coverage : Flag<["-"], "no-unused-coverage">,
+  HelpText<"Turn off coverage mapping for code that is not emitted">,
+  MarshallingInfoFlag<CodeGenOpts<"NoUnusedCoverage">>;
 def fuse_register_sized_bitfield_access: Flag<["-"], 
"fuse-register-sized-bitfield-access">,
   HelpText<"Use register sized accesses to bit-fields, when possible.">,
   MarshallingInfoFlag<CodeGenOpts<"UseRegisterSizedBitfieldAccess">>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -211,6 +211,8 @@
                                    ///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
                                        ///< regions.
+CODEGENOPT(NoUnusedCoverage , 1, 0) ///< Turn off coverage mapping for code 
that
+                                    ///< is not emitted.

   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, 
SRCK_Default)


Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -538,7 +538,9 @@
   EmitCtorList(GlobalDtors, "llvm.global_dtors");
   EmitGlobalAnnotations();
   EmitStaticExternCAliases();
-  EmitDeferredUnusedCoverageMappings();
+  if (!CodeGenOpts.NoUnusedCoverage) {
+    EmitDeferredUnusedCoverageMappings();
+  }
   CodeGenPGO(*this).setValueProfilingFlag(getModule());
   if (CoverageMapping)
     CoverageMapping->emit();
Index: clang/include/clang/Driver/Options.td
===================================================================
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -5158,6 +5158,9 @@
 def dump_coverage_mapping : Flag<["-"], "dump-coverage-mapping">,
   HelpText<"Dump the coverage mapping records, for testing">,
   MarshallingInfoFlag<CodeGenOpts<"DumpCoverageMapping">>;
+def no_unused_coverage : Flag<["-"], "no-unused-coverage">,
+  HelpText<"Turn off coverage mapping for code that is not emitted">,
+  MarshallingInfoFlag<CodeGenOpts<"NoUnusedCoverage">>;
 def fuse_register_sized_bitfield_access: Flag<["-"], "fuse-register-sized-bitfield-access">,
   HelpText<"Use register sized accesses to bit-fields, when possible.">,
   MarshallingInfoFlag<CodeGenOpts<"UseRegisterSizedBitfieldAccess">>;
Index: clang/include/clang/Basic/CodeGenOptions.def
===================================================================
--- clang/include/clang/Basic/CodeGenOptions.def
+++ clang/include/clang/Basic/CodeGenOptions.def
@@ -211,6 +211,8 @@
                                    ///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
                                        ///< regions.
+CODEGENOPT(NoUnusedCoverage , 1, 0) ///< Turn off coverage mapping for code that
+                                    ///< is not emitted.

   /// If -fpcc-struct-return or -freg-struct-return is specified.
 ENUM_CODEGENOPT(StructReturnConvention, StructReturnConventionKind, 2, SRCK_Default)
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to