]> granicus.if.org Git - clang/commitdiff
Wire up the -ftest-coverage and -fprofile-arcs flags to .gcno file emission (at
authorNick Lewycky <nicholas@mxc.ca>
Thu, 21 Apr 2011 23:44:07 +0000 (23:44 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Thu, 21 Apr 2011 23:44:07 +0000 (23:44 +0000)
compile time) and .gcda emission (at runtime). --coverage enables both.

This does not yet add the profile_rt library to the link step if -fprofile-arcs
is enabled when linking.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@129956 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/CC1Options.td
include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.h
lib/CodeGen/BackendUtil.cpp
lib/CodeGen/CMakeLists.txt
lib/CodeGen/CodeGenModule.cpp
lib/Driver/Tools.cpp
lib/Frontend/CompilerInvocation.cpp
tools/driver/CMakeLists.txt
tools/driver/Makefile

index 3457a20d015546e52abcf88b441fd6ddf14a8eec..0c2a077a93fef7d71cc1232870aff29e40403477 100644 (file)
@@ -135,6 +135,10 @@ def fdata_sections : Flag<"-fdata-sections">,
   HelpText<"Place each data in its own section (ELF Only)">;
 def funroll_loops : Flag<"-funroll-loops">,
   HelpText<"Turn on loop unroller">;
+def femit_coverage_notes : Flag<"-femit-coverage-notes">,
+  HelpText<"Emit a gcov coverage notes file when compiling.">;
+def femit_coverage_data: Flag<"-femit-coverage-data">,
+  HelpText<"Instrument the program to emit gcov coverage data when run.">;
 def relaxed_aliasing : Flag<"-relaxed-aliasing">,
   HelpText<"Turn off Type Based Alias Analysis">;
 def masm_verbose : Flag<"-masm-verbose">,
index ed891c067afcb753b19c80021039a318626e5f02..542728f2f11826967bad6875a6a1cd35f2e9df8e 100644 (file)
@@ -423,6 +423,7 @@ def ftabstop_EQ : Joined<"-ftabstop=">, Group<f_Group>;
 def ftemplate_depth_ : Joined<"-ftemplate-depth-">, Group<f_Group>;
 def ftemplate_backtrace_limit_EQ : Joined<"-ftemplate-backtrace-limit=">,
                                    Group<f_Group>;
+def ftest_coverage : Flag<"-ftest-coverage">, Group<f_Group>;
 def Wlarge_by_value_copy_def : Flag<"-Wlarge-by-value-copy">;
 def Wlarge_by_value_copy_EQ : Joined<"-Wlarge-by-value-copy=">;
 
index 60a639826259228b3ead46544b3bf62632798d86..cede010199736f49b9194ad36c85c8977e499a56 100644 (file)
@@ -52,6 +52,8 @@ public:
                                   /// Decl* various IR entities came from.  Only
                                   /// useful when running CodeGen as a
                                   /// subroutine.
+  unsigned EmitGcovArcs      : 1; /// Emit coverage data files, aka. GCDA.
+  unsigned EmitGcovNotes     : 1; /// Emit coverage "notes" files, aka GCNO.
   unsigned ForbidGuardVariables : 1; /// Issue errors if C++ guard variables
                                   /// are required
   unsigned FunctionSections  : 1; /// Set when -ffunction-sections is enabled
@@ -135,6 +137,8 @@ public:
     DisableLLVMOpts = 0;
     DisableRedZone = 0;
     EmitDeclMetadata = 0;
+    EmitGcovArcs = 0;
+    EmitGcovNotes = 0;
     ForbidGuardVariables = 0;
     FunctionSections = 0;
     HiddenWeakTemplateVTables = 0;
index f3d79cb1e0e14d7338e6d60fa0af1f86e222b3fd..9bd4bfd70c78b2f03acd50f93392139eafb2c574 100644 (file)
@@ -30,6 +30,7 @@
 #include "llvm/Target/TargetMachine.h"
 #include "llvm/Target/TargetOptions.h"
 #include "llvm/Target/TargetRegistry.h"
+#include "llvm/Transforms/Instrumentation.h"
 using namespace clang;
 using namespace llvm;
 
@@ -152,6 +153,13 @@ void EmitAssemblyHelper::CreatePasses() {
     TLI->disableAllFunctions();
   MPM->add(TLI);
 
+  if (CodeGenOpts.EmitGcovArcs || CodeGenOpts.EmitGcovNotes) {
+    MPM->add(createGCOVProfilerPass(CodeGenOpts.EmitGcovNotes,
+                                    CodeGenOpts.EmitGcovArcs));
+    if (!CodeGenOpts.DebugInfo)
+      MPM->add(createStripSymbolsPass(true));
+  }
+
   // For now we always create per module passes.
   llvm::createStandardModulePasses(MPM, OptLevel,
                                    CodeGenOpts.OptimizeSize,
index 0a51b85e3aa67a035c0f05a3b9696e8babd1ceec..80e46d2be7042ff045a0ded6799ff452bb46d182 100644 (file)
@@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS
   asmparser
   bitreader
   bitwriter
+  instrumentation
   ipo
   )
 
index 603e8c196b3f019f1a9f7cf1d226810744084c9a..e73a0cffdb12b446c6a879aaea286d638df00788 100644 (file)
@@ -64,7 +64,7 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
     ABI(createCXXABI(*this)), 
     Types(C, M, TD, getTargetCodeGenInfo().getABIInfo(), ABI),
     TBAA(0),
-    VTables(*this), Runtime(0),
+    VTables(*this), Runtime(0), DebugInfo(0),
     CFConstantStringClassRef(0), ConstantStringClassRef(0),
     VMContext(M.getContext()),
     NSConcreteGlobalBlockDecl(0), NSConcreteStackBlockDecl(0),
@@ -80,8 +80,11 @@ CodeGenModule::CodeGenModule(ASTContext &C, const CodeGenOptions &CGO,
     TBAA = new CodeGenTBAA(Context, VMContext, getLangOptions(),
                            ABI.getMangleContext());
 
-  // If debug info generation is enabled, create the CGDebugInfo object.
-  DebugInfo = CodeGenOpts.DebugInfo ? new CGDebugInfo(*this) : 0;
+  // If debug info or coverage generation is enabled, create the CGDebugInfo
+  // object.
+  if (CodeGenOpts.DebugInfo || CodeGenOpts.EmitGcovArcs ||
+      CodeGenOpts.EmitGcovNotes)
+    DebugInfo = new CGDebugInfo(*this);
 
   Block.GlobalUniqueCount = 0;
 
index 7cc1059678de65b4b7511d1f58781bb5353e5763..c1f7e15c88e049b563d92a3b73ebe4aa8ba3d5c6 100644 (file)
@@ -1277,6 +1277,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
 
   Args.AddAllArgs(CmdArgs, options::OPT_finstrument_functions);
 
+  if (Args.hasArg(options::OPT_ftest_coverage) ||
+      Args.hasArg(options::OPT_coverage))
+    CmdArgs.push_back("-femit-coverage-notes");
+  if (Args.hasArg(options::OPT_fprofile_arcs) ||
+      Args.hasArg(options::OPT_coverage))
+    CmdArgs.push_back("-femit-coverage-data");
+
   Args.AddLastArg(CmdArgs, options::OPT_nostdinc);
   Args.AddLastArg(CmdArgs, options::OPT_nostdincxx);
   Args.AddLastArg(CmdArgs, options::OPT_nobuiltininc);
index bf863d7feaec3efc30d3f1acc3ffbaf9e4cf6f85..5449df2b03ee015300b5e7ccc0a504e4f996a8cf 100644 (file)
@@ -123,6 +123,10 @@ static void CodeGenOptsToArgs(const CodeGenOptions &Opts,
     Res.push_back("-dwarf-debug-flags");
     Res.push_back(Opts.DwarfDebugFlags);
   }
+  if (Opts.EmitGcovArcs)
+    Res.push_back("-femit-coverage-data");
+  if (Opts.EmitGcovNotes)
+    Res.push_back("-femit-coverage-notes");
   if (!Opts.MergeAllConstants)
     Res.push_back("-fno-merge-all-constants");
   if (Opts.NoCommon)
@@ -960,6 +964,8 @@ static void ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
 
   Opts.InstrumentFunctions = Args.hasArg(OPT_finstrument_functions);
   Opts.InstrumentForProfiling = Args.hasArg(OPT_pg);
+  Opts.EmitGcovArcs = Args.hasArg(OPT_femit_coverage_data);
+  Opts.EmitGcovNotes = Args.hasArg(OPT_femit_coverage_notes);
 
   if (Arg *A = Args.getLastArg(OPT_fobjc_dispatch_method_EQ)) {
     llvm::StringRef Name = A->getValue(Args);
index 552e7a53442794549bfa36e41084b5e0bfecd61d..0c41490175e9001ca3b9a0f829ae4b81659b4b17 100644 (file)
@@ -23,6 +23,7 @@ set( LLVM_LINK_COMPONENTS
   bitreader
   bitwriter
   codegen
+  instrumentation
   ipo
   selectiondag
   )
index d96f9505ffe51249024a6559f9405d93b7ef88d4..abe70983df42e0bf8b8fe3f8d3bc8eb71ae2b2db 100644 (file)
@@ -36,7 +36,7 @@ TOOL_INFO_PLIST := Info.plist
 include $(CLANG_LEVEL)/../../Makefile.config
 
 LINK_COMPONENTS := $(TARGETS_TO_BUILD) asmparser bitreader bitwriter codegen \
-                   ipo selectiondag
+                   instrumentation ipo selectiondag
 USEDLIBS = clangFrontendTool.a clangFrontend.a clangDriver.a \
            clangSerialization.a clangCodeGen.a clangParse.a clangSema.a \
            clangStaticAnalyzerFrontend.a clangStaticAnalyzerCheckers.a \