[PATCH] D23734: Add -fprofile-dir= to clang.

2016-10-04 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko closed this revision.
Eugene.Zelenko added a comment.

Committed in https://reviews.llvm.org/rL280306. Please specify "Differential 
revision: " as last line of commit message.


https://reviews.llvm.org/D23734



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-31 Thread Nick Lewycky via cfe-commits
nlewycky updated this revision to Diff 69905.

https://reviews.llvm.org/D23734

Files:
  lib/Transforms/Instrumentation/GCOVProfiling.cpp
  test/Transforms/GCOVProfiling/three-element-mdnode.ll
  tools/clang/include/clang/Driver/CC1Options.td
  tools/clang/include/clang/Driver/Options.td
  tools/clang/include/clang/Frontend/CodeGenOptions.h
  tools/clang/lib/CodeGen/CodeGenModule.cpp
  tools/clang/lib/Driver/Tools.cpp
  tools/clang/lib/Frontend/CompilerInvocation.cpp
  tools/clang/test/CodeGen/code-coverage.c
  tools/clang/test/Driver/clang_f_opts.c
  tools/clang/test/Driver/coverage_no_integrated_as.c

Index: tools/clang/test/Driver/coverage_no_integrated_as.c
===
--- tools/clang/test/Driver/coverage_no_integrated_as.c
+++ tools/clang/test/Driver/coverage_no_integrated_as.c
@@ -17,7 +17,7 @@
 // RUN: %clang -### -c -fprofile-arcs -no-integrated-as %s -o foo/bar.o 2>&1 | FileCheck -check-prefix=CHECK-GCNO-LOCATION-REL-PATH %s
 
 
-// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
-// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
-// CHECK-GCNO-LOCATION: "-coverage-file" "{{.*}}/foo/bar.o"
-// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-file" "{{.*}}{{/|}}foo/bar.o"
+// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-notes-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
+// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-notes-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
+// CHECK-GCNO-LOCATION: "-coverage-notes-file" "{{.*}}/foo/bar.gcno"
+// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-notes-file" "{{.*}}{{/|}}foo/bar.gcno"
Index: tools/clang/test/Driver/clang_f_opts.c
===
--- tools/clang/test/Driver/clang_f_opts.c
+++ tools/clang/test/Driver/clang_f_opts.c
@@ -66,6 +66,16 @@
 // CHECK-PROFILE-ARCS: "-femit-coverage-data"
 // CHECK-NO-PROFILE-ARCS-NOT: "-femit-coverage-data"
 
+// RUN: %clang -### -S -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -ftest-coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -fprofile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S --coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S -fprofile-arcs -fno-profile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-NEITHER %s
+// CHECK-PROFILE-DIR: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-UNUSED: argument unused
+// CHECK-PROFILE-DIR-UNUSED-NOT: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-NEITHER-NOT: argument unused
+
 // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-LLVM %s
 // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s
 // RUN: %clang -### -S -fprofile-generate=/some/dir %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-DIR %s
@@ -212,7 +222,6 @@
 // RUN: -fdefer-pop -fno-defer-pop\
 // RUN: -fprefetch-loop-arrays -fno-prefetch-loop-arrays  \
 // RUN: -fprofile-correction -fno-profile-correction  \
-// RUN: -fprofile-dir=bar \
 // RUN: -fprofile-values -fno-profile-values  \
 // RUN: -frounding-math -fno-rounding-math\
 // RUN: -fsee -fno-see\
@@ -290,7 +299,6 @@
 // RUN: -fkeep-inline-functions   \
 // RUN: -fno-keep-inline-functions\
 // RUN: -freorder-blocks  \
-// RUN: -fprofile-dir=/rand/dir   \
 // RUN: -falign-functions \
 // RUN: -falign-functions=1   \
 // RUN: -ffloat-store \
@@ -357,7 +365,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fprofile-dir=/rand/dir' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions=1' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
Index: tools/clang/test/CodeGen/code-coverage.c
===

Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-30 Thread Saleem Abdulrasool via cfe-commits
compnerd added inline comments.


Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:447
@@ -432,3 +446,3 @@
 return Filename.str();
   }
 }

A quick pass over this yielded something like:

if (N->getNumOperands() != 2 && N->getNumOperands() != 3)
  continue;

bool HasProfileDir = N->getNumOperands() == 3;
unsigned Offset = HasProfileDir ? 1 : 0;

auto *NotesFile = dyn_cast(N->getOperand(Offset + 0));
auto *CovFile = dyn_cast(N->getOperand(Offset + 0));
auto *CompileUnit = dyn_cast(N->getOperand(Offset + 1));

if ((!HasProfileDir || !NotesFile) || !CovFile || !CompileUnit)
  continue;

if (CompileUnit == CU) {
  bool GCNO = OutputType == GCovFileType::GCNO;
  if (HasProfileDir) {
return GCNO ? NotesFile->getString() : CovFile->getString();
  } else {
SmallString<128> FileName = CovFile->getString();
sys::path::replace_extension(FileName, GCNO ? "gcno" : "gcda");
return FileName.str();
  }
}

It does reduce a bit of the duplication, and still accounts for the string 
duplication that you were pointing out.  I think it makes it slightly easier to 
read due to the variable de-duplication (at the slight cost of an extra pointer 
on the stack and an extra lookup).


https://reviews.llvm.org/D23734



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-30 Thread Nick Lewycky via cfe-commits
nlewycky added inline comments.


Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:447
@@ -432,3 +446,3 @@
 return Filename.str();
   }
 }

compnerd wrote:
> It really feels like these two cases can be collapsed.
I don't see a great way to do that, so I picked the one which minimizes the 
cost of the common case. Having an !llvm.gcov node but no CU for the specific 
.o is uncommon: to get here you're building a program with some .bc's built 
with a frontend that emits an !llvm.gcov and some .bc's without, and then you 
llvm-linked them and are running the insert-gcov-profiling pass afterwards. 
Also, I assume that copying SmallString<128>'s around is slow, while looking up 
Value*'s is faster.

If you have a specific idea, I'm happy to try it. I'm not thrilled with the way 
it's written now.


Comment at: test/Transforms/GCOVProfiling/three-element-mdnode.ll:27
@@ +26,2 @@
+
+!10 = !{i32 1, !"Debug Info Version", i32 3}

The way this test was written, !10 would be parsed before !9. Swizzled it 
around to make !9 the !llvm.module.flags and !10 the !llvm.gcov node.


https://reviews.llvm.org/D23734



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-30 Thread Nick Lewycky via cfe-commits
nlewycky updated this revision to Diff 69778.
nlewycky marked 5 inline comments as done.

https://reviews.llvm.org/D23734

Files:
  lib/Transforms/Instrumentation/GCOVProfiling.cpp
  test/Transforms/GCOVProfiling/three-element-mdnode.ll
  tools/clang/include/clang/Driver/CC1Options.td
  tools/clang/include/clang/Driver/Options.td
  tools/clang/include/clang/Frontend/CodeGenOptions.h
  tools/clang/lib/CodeGen/CodeGenModule.cpp
  tools/clang/lib/Driver/Tools.cpp
  tools/clang/lib/Frontend/CompilerInvocation.cpp
  tools/clang/test/CodeGen/code-coverage.c
  tools/clang/test/Driver/clang_f_opts.c
  tools/clang/test/Driver/coverage_no_integrated_as.c

Index: tools/clang/test/Driver/coverage_no_integrated_as.c
===
--- tools/clang/test/Driver/coverage_no_integrated_as.c
+++ tools/clang/test/Driver/coverage_no_integrated_as.c
@@ -17,7 +17,7 @@
 // RUN: %clang -### -c -fprofile-arcs -no-integrated-as %s -o foo/bar.o 2>&1 | FileCheck -check-prefix=CHECK-GCNO-LOCATION-REL-PATH %s
 
 
-// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
-// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
-// CHECK-GCNO-LOCATION: "-coverage-file" "{{.*}}/foo/bar.o"
-// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-file" "{{.*}}{{/|}}foo/bar.o"
+// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-notes-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
+// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-notes-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
+// CHECK-GCNO-LOCATION: "-coverage-notes-file" "{{.*}}/foo/bar.gcno"
+// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-notes-file" "{{.*}}{{/|}}foo/bar.gcno"
Index: tools/clang/test/Driver/clang_f_opts.c
===
--- tools/clang/test/Driver/clang_f_opts.c
+++ tools/clang/test/Driver/clang_f_opts.c
@@ -66,6 +66,16 @@
 // CHECK-PROFILE-ARCS: "-femit-coverage-data"
 // CHECK-NO-PROFILE-ARCS-NOT: "-femit-coverage-data"
 
+// RUN: %clang -### -S -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -ftest-coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -fprofile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S --coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S -fprofile-arcs -fno-profile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-NEITHER %s
+// CHECK-PROFILE-DIR: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-UNUSED: argument unused
+// CHECK-PROFILE-DIR-UNUSED-NOT: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-NEITHER-NOT: argument unused
+
 // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-LLVM %s
 // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s
 // RUN: %clang -### -S -fprofile-generate=/some/dir %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-DIR %s
@@ -212,7 +222,6 @@
 // RUN: -fdefer-pop -fno-defer-pop\
 // RUN: -fprefetch-loop-arrays -fno-prefetch-loop-arrays  \
 // RUN: -fprofile-correction -fno-profile-correction  \
-// RUN: -fprofile-dir=bar \
 // RUN: -fprofile-values -fno-profile-values  \
 // RUN: -frounding-math -fno-rounding-math\
 // RUN: -fsee -fno-see\
@@ -290,7 +299,6 @@
 // RUN: -fkeep-inline-functions   \
 // RUN: -fno-keep-inline-functions\
 // RUN: -freorder-blocks  \
-// RUN: -fprofile-dir=/rand/dir   \
 // RUN: -falign-functions \
 // RUN: -falign-functions=1   \
 // RUN: -ffloat-store \
@@ -357,7 +365,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fprofile-dir=/rand/dir' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions=1' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
Index: tools/clang/test/CodeGen/code-coverage.c

Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-29 Thread Saleem Abdulrasool via cfe-commits
compnerd added a subscriber: compnerd.


Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:121
@@ -120,2 +120,3 @@
 
-  std::string mangleName(const DICompileUnit *CU, const char *NewStem);
+  enum GCovFileType { GCNO, GCDA };
+  std::string mangleName(const DICompileUnit *CU, GCovFileType NewStem);

Might be nice to use `enum class`.


Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:422
@@ -420,3 +421,3 @@
 std::string GCOVProfiler::mangleName(const DICompileUnit *CU,
- const char *NewStem) {
+ GCovFileType NewStem) {
   if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) {

I think that `NewStem` is no longer appropriate.


Comment at: lib/Transforms/Instrumentation/GCOVProfiling.cpp:447
@@ -432,3 +446,3 @@
 return Filename.str();
   }
 }

It really feels like these two cases can be collapsed.


Comment at: tools/clang/lib/CodeGen/CodeGenModule.cpp:4221
@@ +4220,3 @@
+  llvm::LLVMContext &Ctx = TheModule.getContext();
+  llvm::MDString *CoverageDataFile =
+  llvm::MDString::get(Ctx, getCodeGenOpts().CoverageDataFile);

`auto *CoverageDataFile` perhaps?


Comment at: tools/clang/lib/CodeGen/CodeGenModule.cpp:4223
@@ +4222,3 @@
+  llvm::MDString::get(Ctx, getCodeGenOpts().CoverageDataFile);
+  llvm::MDString *CoverageNotesFile =
+  llvm::MDString::get(Ctx, getCodeGenOpts().CoverageNotesFile);

Similar.


Comment at: tools/clang/lib/Driver/Tools.cpp:3621
@@ -3621,1 +3620,3 @@
+OutputFilename = llvm::sys::path::filename(Output.getBaseInput());
   }
+  SmallString<128> CoverageFilename = OutputFilename;

Unnecessary braces.


https://reviews.llvm.org/D23734



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-29 Thread Nick Lewycky via cfe-commits
nlewycky added a comment.

Ping!

I think the review this patch really needs is a comparison to GCC's 
implementation to double-check that it really does the same thing that GCC 
does. Is there a gcov user who could take a look at this?


https://reviews.llvm.org/D23734



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-19 Thread Nick Lewycky via cfe-commits
nlewycky updated this revision to Diff 68755.
nlewycky added a comment.

Forgot clang changes!


https://reviews.llvm.org/D23734

Files:
  lib/Transforms/Instrumentation/GCOVProfiling.cpp
  test/Transforms/GCOVProfiling/three-element-mdnode.ll
  tools/clang/include/clang/Driver/CC1Options.td
  tools/clang/include/clang/Driver/Options.td
  tools/clang/include/clang/Frontend/CodeGenOptions.h
  tools/clang/lib/CodeGen/CodeGenModule.cpp
  tools/clang/lib/Driver/Tools.cpp
  tools/clang/lib/Frontend/CompilerInvocation.cpp
  tools/clang/test/CodeGen/code-coverage.c
  tools/clang/test/Driver/clang_f_opts.c
  tools/clang/test/Driver/coverage_no_integrated_as.c

Index: tools/clang/test/Driver/coverage_no_integrated_as.c
===
--- tools/clang/test/Driver/coverage_no_integrated_as.c
+++ tools/clang/test/Driver/coverage_no_integrated_as.c
@@ -17,7 +17,7 @@
 // RUN: %clang -### -c -fprofile-arcs -no-integrated-as %s -o foo/bar.o 2>&1 | FileCheck -check-prefix=CHECK-GCNO-LOCATION-REL-PATH %s
 
 
-// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
-// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
-// CHECK-GCNO-LOCATION: "-coverage-file" "{{.*}}/foo/bar.o"
-// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-file" "{{.*}}{{/|}}foo/bar.o"
+// CHECK-GCNO-DEFAULT-LOCATION: "-coverage-notes-file" "{{.*}}{{/|}}coverage_no_integrated_as.c"
+// CHECK-GCNO-DEFAULT-LOCATION-NOT: "-coverage-notes-file" "/tmp/{{.*}}/coverage_no_integrated_as.c"
+// CHECK-GCNO-LOCATION: "-coverage-notes-file" "{{.*}}/foo/bar.gcno"
+// CHECK-GCNO-LOCATION-REL-PATH: "-coverage-notes-file" "{{.*}}{{/|}}foo/bar.gcno"
Index: tools/clang/test/Driver/clang_f_opts.c
===
--- tools/clang/test/Driver/clang_f_opts.c
+++ tools/clang/test/Driver/clang_f_opts.c
@@ -66,6 +66,16 @@
 // CHECK-PROFILE-ARCS: "-femit-coverage-data"
 // CHECK-NO-PROFILE-ARCS-NOT: "-femit-coverage-data"
 
+// RUN: %clang -### -S -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -ftest-coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-UNUSED %s
+// RUN: %clang -### -S -fprofile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S --coverage -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR %s
+// RUN: %clang -### -S -fprofile-arcs -fno-profile-arcs -fprofile-dir=abc %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-DIR-NEITHER %s
+// CHECK-PROFILE-DIR: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-UNUSED: argument unused
+// CHECK-PROFILE-DIR-UNUSED-NOT: "-coverage-data-file" "abc
+// CHECK-PROFILE-DIR-NEITHER-NOT: argument unused
+
 // RUN: %clang -### -S -fprofile-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-LLVM %s
 // RUN: %clang -### -S -fprofile-instr-generate %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE %s
 // RUN: %clang -### -S -fprofile-generate=/some/dir %s 2>&1 | FileCheck -check-prefix=CHECK-PROFILE-GENERATE-DIR %s
@@ -212,7 +222,6 @@
 // RUN: -fdefer-pop -fno-defer-pop\
 // RUN: -fprefetch-loop-arrays -fno-prefetch-loop-arrays  \
 // RUN: -fprofile-correction -fno-profile-correction  \
-// RUN: -fprofile-dir=bar \
 // RUN: -fprofile-values -fno-profile-values  \
 // RUN: -frounding-math -fno-rounding-math\
 // RUN: -fsee -fno-see\
@@ -290,7 +299,6 @@
 // RUN: -fkeep-inline-functions   \
 // RUN: -fno-keep-inline-functions\
 // RUN: -freorder-blocks  \
-// RUN: -fprofile-dir=/rand/dir   \
 // RUN: -falign-functions \
 // RUN: -falign-functions=1   \
 // RUN: -ffloat-store \
@@ -357,7 +365,6 @@
 // CHECK-WARNING-DAG: optimization flag '-fkeep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-fno-keep-inline-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-freorder-blocks' is not supported
-// CHECK-WARNING-DAG: optimization flag '-fprofile-dir=/rand/dir' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions' is not supported
 // CHECK-WARNING-DAG: optimization flag '-falign-functions=1' is not supported
 // CHECK-WARNING-DAG: optimization flag '-ffloat-store' is not supported
Index: tools/clang/test/CodeGen/code-cove

[PATCH] D23734: Add -fprofile-dir= to clang.

2016-08-19 Thread Nick Lewycky via cfe-commits
nlewycky created this revision.
nlewycky added subscribers: llvm-commits, cfe-commits.

-fprofile-dir=path allows the user to specify where .gcda files should be 
emitted when the program is run. In particular, this is the first flag that 
causes the .gcno and .o files to have different paths, LLVM is extended to 
support this. -fprofile-dir= does not change the file name in the .gcno (and 
thus where lcov looks for the source) but it does change the name in the .gcda 
(and thus where the runtime library writes the .gcda file). It's different from 
a GCOV_PREFIX because a user can observe that the GCOV_PREFIX_STRIP will strip 
paths off of -fprofile-dir= but not off of a supplied GCOV_PREFIX.

To implement this we split -coverage-file into -coverage-data-file and 
-coverage-notes-file to specify the two different names. The !llvm.gcov 
metadata node grows from a 2-element form {string coverage-file, node dbg.cu} 
to 3-elements, {string coverage-notes-file, string coverage-data-file, node 
dbg.cu}. In the 3-element form, the file name is already "mangled" with 
.gcno/.gcda suffixes, while the 2-element form left that to the middle end pass.

https://reviews.llvm.org/D23734

Files:
  lib/Transforms/Instrumentation/GCOVProfiling.cpp
  test/Transforms/GCOVProfiling/three-element-mdnode.ll

Index: test/Transforms/GCOVProfiling/three-element-mdnode.ll
===
--- test/Transforms/GCOVProfiling/three-element-mdnode.ll
+++ test/Transforms/GCOVProfiling/three-element-mdnode.ll
@@ -0,0 +1,27 @@
+; RUN: echo '!9 = !{!"%T/aaa.gcno", !"%T/bbb.gcda", !0}' > %t1
+; RUN: cat %s %t1 > %t2
+; RUN: opt -insert-gcov-profiling -S -o %t3 < %t2
+; RUN: grep _Z3foov %T/aaa.gcno
+; RUN: grep bbb.gcda %t3
+; RUN: rm %T/aaa.gcno
+
+define void @_Z3foov() !dbg !5 {
+entry:
+  ret void, !dbg !8
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!10}
+!llvm.gcov = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.3 (trunk 177323)", isOptimized: false, emissionKind: FullDebug, file: !2, enums: !3, retainedTypes: !3, globals: !3, imports:  !3)
+!1 = !DIFile(filename: "hello.cc", directory: "/home/nlewycky")
+!2 = !DIFile(filename: "hello.cc", directory: "/home/nlewycky")
+!3 = !{}
+!5 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", line: 1, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, unit: !0, scopeLine: 1, file: !1, scope: !1, type: !6, variables: !3)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !DILocation(line: 1, scope: !5)
+
+
+!10 = !{i32 1, !"Debug Info Version", i32 3}
Index: lib/Transforms/Instrumentation/GCOVProfiling.cpp
===
--- lib/Transforms/Instrumentation/GCOVProfiling.cpp
+++ lib/Transforms/Instrumentation/GCOVProfiling.cpp
@@ -118,7 +118,8 @@
   Function *insertFlush(ArrayRef>);
   void insertIndirectCounterIncrement();
 
-  std::string mangleName(const DICompileUnit *CU, const char *NewStem);
+  enum GCovFileType { GCNO, GCDA };
+  std::string mangleName(const DICompileUnit *CU, GCovFileType NewStem);
 
   GCOVOptions Options;
 
@@ -418,24 +419,37 @@
 }
 
 std::string GCOVProfiler::mangleName(const DICompileUnit *CU,
- const char *NewStem) {
+ GCovFileType NewStem) {
   if (NamedMDNode *GCov = M->getNamedMetadata("llvm.gcov")) {
 for (int i = 0, e = GCov->getNumOperands(); i != e; ++i) {
   MDNode *N = GCov->getOperand(i);
+  if (N->getNumOperands() == 3) {
+// These nodes have no mangling to apply, it's stored mangled in the
+// bitcode.
+MDString *NotesFile = dyn_cast(N->getOperand(0));
+MDString *DataFile = dyn_cast(N->getOperand(1));
+MDNode *CompileUnit = dyn_cast(N->getOperand(2));
+if (!NotesFile || !DataFile || !CompileUnit) continue;
+if (CompileUnit == CU)
+  return NewStem == GCNO ? NotesFile->getString()
+ : DataFile->getString();
+  }
   if (N->getNumOperands() != 2) continue;
   MDString *GCovFile = dyn_cast(N->getOperand(0));
   MDNode *CompileUnit = dyn_cast(N->getOperand(1));
   if (!GCovFile || !CompileUnit) continue;
   if (CompileUnit == CU) {
-SmallString<128> Filename = GCovFile->getString();
-sys::path::replace_extension(Filename, NewStem);
+SmallString<128> Filename;
+Filename = GCovFile->getString();
+sys::path::replace_extension(Filename,
+ NewStem == GCNO ? "gcno" : "gcda");
 return Filename.str();
   }
 }
   }
 
   SmallString<128> Filename = CU->getFilename();
-  sys::path::replace_extension(Filename, NewStem);
+  sys::path::replace_extension(Filename, NewStem == GCNO ? "gcno" : "gcda");
   StringRef FName = sys::path::filename(Filename);
   SmallString<128>