[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-31 Thread Taewook Oh via cfe-commits
twoh added a comment.

In https://reviews.llvm.org/D25225#584012, @hfinkel wrote:

> In https://reviews.llvm.org/D25225#584010, @twoh wrote:
>
> > Is there a particular reason why "opt_record_file" is defined in 
> > CC1Options.td, not Options.td? If -opt-record-file= is provided 
> > by the command line, line 829-831 in CompilerInvocation.cpp won't handle it 
> > because opt_record_file is not a CodeGenArg.
>
>
> It is not intended to be used directly. The user should use 
> -fsave-optimization-record (along with -foptimization-record-file= if they 
> don't like the default name selected). We definitely need to write end-user 
> docs for this; it is on my TODO list.


Got it. Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-31 Thread Hal Finkel via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D25225#584010, @twoh wrote:

> Is there a particular reason why "opt_record_file" is defined in 
> CC1Options.td, not Options.td? If -opt-record-file= is provided by 
> the command line, line 829-831 in CompilerInvocation.cpp won't handle it 
> because opt_record_file is not a CodeGenArg.


It is not intended to be used directly. The user should use 
-fsave-optimization-record (along with -foptimization-record-file= if they 
don't like the default name selected). We definitely need to write end-user 
docs for this; it is on my TODO list.


Repository:
  rL LLVM

https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-31 Thread Taewook Oh via cfe-commits
twoh added a comment.

Is there a particular reason why "opt_record_file" is defined in CC1Options.td, 
not Options.td? If -opt-record-file= is provided by the command line, 
line 829-831 in CompilerInvocation.cpp won't handle it because opt_record_file 
is not a CodeGenArg.


Repository:
  rL LLVM

https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-11 Thread Hal Finkel via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL283834: Add an option to save the backend-produced YAML 
optimization record to a file (authored by hfinkel).

Changed prior to commit:
  https://reviews.llvm.org/D25225?vs=74001&id=74214#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D25225

Files:
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.h
  cfe/trunk/lib/CodeGen/CodeGenAction.cpp
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/Inputs/opt-record.proftext
  cfe/trunk/test/CodeGen/opt-record.c
  cfe/trunk/test/Driver/opt-record.c

Index: cfe/trunk/lib/CodeGen/CodeGenAction.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenAction.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenAction.cpp
@@ -33,6 +33,8 @@
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
 #include "llvm/Support/Timer.h"
+#include "llvm/Support/ToolOutputFile.h"
+#include "llvm/Support/YAMLTraits.h"
 #include 
 using namespace clang;
 using namespace llvm;
@@ -181,6 +183,24 @@
   Ctx.setDiagnosticHandler(DiagnosticHandler, this);
   Ctx.setDiagnosticHotnessRequested(CodeGenOpts.DiagnosticsWithHotness);
 
+  std::unique_ptr OptRecordFile;
+  if (!CodeGenOpts.OptRecordFile.empty()) {
+std::error_code EC;
+OptRecordFile =
+  llvm::make_unique(CodeGenOpts.OptRecordFile,
+EC, sys::fs::F_None);
+if (EC) {
+  Diags.Report(diag::err_cannot_open_file) <<
+CodeGenOpts.OptRecordFile << EC.message();
+  return;
+}
+
+Ctx.setDiagnosticsOutputFile(new yaml::Output(OptRecordFile->os()));
+
+if (CodeGenOpts.getProfileUse() != CodeGenOptions::ProfileNone)
+  Ctx.setDiagnosticHotnessRequested(true);
+  }
+
   // Link LinkModule into this module if present, preserving its validity.
   for (auto &I : LinkModules) {
 unsigned LinkFlags = I.first;
@@ -198,6 +218,9 @@
   Ctx.setInlineAsmDiagnosticHandler(OldHandler, OldContext);
 
   Ctx.setDiagnosticHandler(OldDiagnosticHandler, OldDiagnosticContext);
+
+  if (OptRecordFile)
+OptRecordFile->keep();
 }
 
 void HandleTagDeclDefinition(TagDecl *D) override {
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -6080,6 +6080,39 @@
 CmdArgs.push_back("-fno-math-builtin");
   }
 
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_fno_save_optimization_record, false)) {
+CmdArgs.push_back("-opt-record-file");
+
+const Arg *A = Args.getLastArg(options::OPT_foptimization_record_file_EQ);
+if (A) {
+  CmdArgs.push_back(A->getValue());
+} else {
+  SmallString<128> F;
+  if (Output.isFilename() && (Args.hasArg(options::OPT_c) ||
+  Args.hasArg(options::OPT_S))) {
+F = Output.getFilename();
+  } else {
+// Use the compilation directory.
+F = llvm::sys::path::stem(Input.getBaseInput());
+
+// If we're compiling for an offload architecture (i.e. a CUDA device),
+// we need to make the file name for the device compilation different
+// from the host compilation.
+if (!JA.isDeviceOffloading(Action::OFK_None) &&
+!JA.isDeviceOffloading(Action::OFK_Host)) {
+  llvm::sys::path::replace_extension(F, "");
+  F += JA.getOffloadingFileNamePrefix(Triple.normalize());
+  F += "-";
+  F += JA.getOffloadingArch();
+}
+  }
+
+  llvm::sys::path::replace_extension(F, "opt.yaml");
+  CmdArgs.push_back(Args.MakeArgString(F));
+}
+  }
+
 // Default to -fno-builtin-str{cat,cpy} on Darwin for ARM.
 //
 // FIXME: Now that PR4941 has been fixed this can be enabled.
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvocation.cpp
+++ cfe/trunk/lib/Frontend/CompilerInvocation.cpp
@@ -826,6 +826,10 @@
   Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option);
   bool NeedLocTracking = false;
 
+  Opts.OptRecordFile = Args.getLastArgValue(OPT_opt_record_file);
+  if (!Opts.OptRecordFile.empty())
+NeedLocTracking = true;
+
   if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
 Opts.OptimizationRemarkPattern =
 GenerateOptimizationRemarkRegex(Diags, Args, A);
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -1192,6 +1192,15 @@
   

[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-10 Thread Hal Finkel via cfe-commits
hfinkel added a comment.

In https://reviews.llvm.org/D25225#566854, @rsmith wrote:

> As discussed on IRC, I have a mild concern about using 
> `-fsave-optimization-record` (with no argument) to enable the feature, and 
> `-fsave-optimization-record=X` to enable the feature and specify a filename; 
> in most (but not all) cases, `-option arg` and `-option=arg` mean the same 
> thing. Other than that, this looks good to me.


For the record (pun intended, I suppose), we discussed on IRC adding a separate 
-foptimization-record-file=filename to set the file name.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-10 Thread Richard Smith via cfe-commits
rsmith added a comment.

As discussed on IRC, I have a mild concern about using 
`-fsave-optimization-record` (with no argument) to enable the feature, and 
`-fsave-optimization-record=X` to enable the feature and specify a filename; in 
most (but not all) cases, `-option arg` and `-option=arg` mean the same thing. 
Other than that, this looks good to me.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-07 Thread Adam Nemet via cfe-commits
anemet added a comment.

LGTM, thanks.  I also like the option name but will let the the other reviewers 
official approve that part.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-07 Thread Hal Finkel via cfe-commits
hfinkel updated this revision to Diff 74001.
hfinkel added a comment.
Herald added a subscriber: mehdi_amini.

Addressed review comments (DebugLoc is tested, and we enable hotness 
computation when saving the optimization record and also using PGO).


https://reviews.llvm.org/D25225

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenAction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/opt-record.proftext
  test/CodeGen/opt-record.c
  test/Driver/opt-record.c

Index: test/Driver/opt-record.c
===
--- /dev/null
+++ test/Driver/opt-record.c
@@ -0,0 +1,18 @@
+// RUN: %clang -### -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
+// RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
+// RUN: %clang -### -S -o FOO -fsave-optimization-record=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+
+// CHECK: "-cc1"
+// CHECK: "-opt-record-file" "FOO.opt.yaml"
+
+// CHECK-NO-O: "-cc1"
+// CHECK-NO-O-DAG: "-opt-record-file" "opt-record.opt.yaml"
+// CHECK-CUDA-DEV-DAG: "-opt-record-file" "opt-record-device-cuda-nvptx64-nvidia-cuda-sm_20.opt.yaml"
+
+// CHECK-EQ: "-cc1"
+// CHECK-EQ: "-opt-record-file" "BAR.txt"
+
Index: test/CodeGen/opt-record.c
===
--- /dev/null
+++ test/CodeGen/opt-record.c
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 %s -o %t -dwarf-column-info -opt-record-file %t.yaml -emit-obj
+// RUN: cat %t.yaml | FileCheck %s
+// RUN: llvm-profdata merge %S/Inputs/opt-record.proftext -o %t.profdata
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 -fprofile-instrument-use-path=%t.profdata %s -o %t -dwarf-column-info -opt-record-file %t.yaml -emit-obj
+// RUN: cat %t.yaml | FileCheck -check-prefix=CHECK -check-prefix=CHECK-PGO %s
+// REQUIRES: x86-registered-target
+
+void bar();
+void foo() { bar(); }
+
+void Test(int *res, int *c, int *d, int *p, int n) {
+  int i;
+
+#pragma clang loop vectorize(assume_safety)
+  for (i = 0; i < 1600; i++) {
+res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
+  }
+}
+
+// CHECK: --- !Missed
+// CHECK: Pass:inline
+// CHECK: Name:NoDefinition
+// CHECK: DebugLoc:
+// CHECK: Function:foo
+// CHECK-PGO: Hotness:
+
+// CHECK: --- !Passed
+// CHECK: Pass:loop-vectorize
+// CHECK: Name:Vectorized
+// CHECK: DebugLoc:
+// CHECK: Function:Test
+// CHECK-PGO: Hotness:
+
Index: test/CodeGen/Inputs/opt-record.proftext
===
--- /dev/null
+++ test/CodeGen/Inputs/opt-record.proftext
@@ -0,0 +1,26 @@
+foo
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+30
+
+bar
+# Func Hash:
+0
+# Num Counters:
+1
+# Counter Values:
+30
+
+Test
+# Func Hash:
+269
+# Num Counters:
+3
+# Counter Values:
+1
+30
+15
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -823,6 +823,10 @@
   Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option);
   bool NeedLocTracking = false;
 
+  Opts.OptRecordFile = Args.getLastArgValue(OPT_opt_record_file);
+  if (!Opts.OptRecordFile.empty())
+NeedLocTracking = true;
+
   if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
 Opts.OptimizationRemarkPattern =
 GenerateOptimizationRemarkRegex(Diags, Args, A);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6068,6 +6068,40 @@
 CmdArgs.push_back("-fno-math-builtin");
   }
 
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_fsave_optimization_record_EQ,
+   options::OPT_fno_save_optimization_record, false)) {
+CmdArgs.push_back("-opt-record-file");
+
+const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ);
+if (A) {
+  CmdArgs.push_back(A->getValue());
+} else {
+  SmallString<128> F;
+  if (Output.isFilename() && (Args.hasArg(options::OPT_c) ||
+  Args.hasArg(options::OPT_S))) {
+F = Output.getFilename();
+  } else {
+   

[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-07 Thread Hal Finkel via cfe-commits
hfinkel added inline comments.



Comment at: lib/CodeGen/CodeGenAction.cpp:198
+
+Ctx.setDiagnosticsOutputFile(new yaml::Output(OptRecordFile->os()));
+  }

anemet wrote:
> Sorry, one more thing: if PGO is available, I think we want to set 
> Ctx.setDiagnosticHotnessRequested as well.  Without that, you'd have to pass 
> -fsave-optimization-record and -fdiagnostics-show-hotness to get hotness info 
> into the YAML file which feels strange.  I am certainly fine if we do this 
> later but I wanted to bring it up since it's seems related.
I agree. We shouldn't require -fdiagnostics-show-hotness for that to work.



Comment at: test/CodeGen/opt-record.c:17-25
+// CHECK: --- !Missed
+// CHECK: Pass:inline
+// CHECK: Name:NoDefinition
+// CHECK: Function:foo
+
+// CHECK: --- !Passed
+// CHECK: Pass:loop-vectorize

anemet wrote:
> Wouldn't this be a good place to also check that we have -gline-tables-only 
> properly hooked up, i.e. CHECK for DebugLoc: as well?
Yes; will do.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-07 Thread Adam Nemet via cfe-commits
anemet added inline comments.



Comment at: lib/CodeGen/CodeGenAction.cpp:198
+
+Ctx.setDiagnosticsOutputFile(new yaml::Output(OptRecordFile->os()));
+  }

Sorry, one more thing: if PGO is available, I think we want to set 
Ctx.setDiagnosticHotnessRequested as well.  Without that, you'd have to pass 
-fsave-optimization-record and -fdiagnostics-show-hotness to get hotness info 
into the YAML file which feels strange.  I am certainly fine if we do this 
later but I wanted to bring it up since it's seems related.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-07 Thread Adam Nemet via cfe-commits
anemet added inline comments.



Comment at: test/CodeGen/opt-record.c:17-25
+// CHECK: --- !Missed
+// CHECK: Pass:inline
+// CHECK: Name:NoDefinition
+// CHECK: Function:foo
+
+// CHECK: --- !Passed
+// CHECK: Pass:loop-vectorize

Wouldn't this be a good place to also check that we have -gline-tables-only 
properly hooked up, i.e. CHECK for DebugLoc: as well?


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-06 Thread Hal Finkel via cfe-commits
hfinkel updated this revision to Diff 73874.
hfinkel added a comment.
Herald added a subscriber: fhahn.

I reworked the way that the automatic file-name selection works so that it will 
work with offloading (e.g. CUDA), and added more tests for the automatic 
file-name selection. It now also bases the file name on the output file name if 
you use -S (not just -c).  When using an offload device, it makes the output 
file name for the device different from the host in a way that mirrors other 
parts of the driver.

I also changed the default extension from .yaml to .opt.yaml to make it a 
little more descriptive (there are obviously lots of different kinds of yaml 
files).


https://reviews.llvm.org/D25225

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenAction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/opt-record.c
  test/Driver/opt-record.c

Index: test/Driver/opt-record.c
===
--- /dev/null
+++ test/Driver/opt-record.c
@@ -0,0 +1,18 @@
+// RUN: %clang -### -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -c -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -fsave-optimization-record %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O
+// RUN: %clang -### -S -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
+// RUN: %clang -### -fsave-optimization-record -x cuda -nocudainc -nocudalib %s 2>&1 | FileCheck %s -check-prefix=CHECK-NO-O -check-prefix=CHECK-CUDA-DEV
+// RUN: %clang -### -S -o FOO -fsave-optimization-record=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+
+// CHECK: "-cc1"
+// CHECK: "-opt-record-file" "FOO.opt.yaml"
+
+// CHECK-NO-O: "-cc1"
+// CHECK-NO-O-DAG: "-opt-record-file" "opt-record.opt.yaml"
+// CHECK-CUDA-DEV-DAG: "-opt-record-file" "opt-record-device-cuda-nvptx64-nvidia-cuda-sm_20.opt.yaml"
+
+// CHECK-EQ: "-cc1"
+// CHECK-EQ: "-opt-record-file" "BAR.txt"
+
Index: test/CodeGen/opt-record.c
===
--- /dev/null
+++ test/CodeGen/opt-record.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 %s -o %t -dwarf-column-info -opt-record-file %t.yaml -emit-obj
+// RUN: cat %t.yaml | FileCheck %s
+// REQUIRES: x86-registered-target
+
+void bar();
+void foo() { bar(); }
+
+void Test(int *res, int *c, int *d, int *p, int n) {
+  int i;
+
+#pragma clang loop vectorize(assume_safety)
+  for (i = 0; i < 1600; i++) {
+res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
+  }
+}
+
+// CHECK: --- !Missed
+// CHECK: Pass:inline
+// CHECK: Name:NoDefinition
+// CHECK: Function:foo
+
+// CHECK: --- !Passed
+// CHECK: Pass:loop-vectorize
+// CHECK: Name:Vectorized
+// CHECK: Function:Test
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -823,6 +823,10 @@
   Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option);
   bool NeedLocTracking = false;
 
+  Opts.OptRecordFile = Args.getLastArgValue(OPT_opt_record_file);
+  if (!Opts.OptRecordFile.empty())
+NeedLocTracking = true;
+
   if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
 Opts.OptimizationRemarkPattern =
 GenerateOptimizationRemarkRegex(Diags, Args, A);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -6068,6 +6068,40 @@
 CmdArgs.push_back("-fno-math-builtin");
   }
 
+  if (Args.hasFlag(options::OPT_fsave_optimization_record,
+   options::OPT_fsave_optimization_record_EQ,
+   options::OPT_fno_save_optimization_record, false)) {
+CmdArgs.push_back("-opt-record-file");
+
+const Arg *A = Args.getLastArg(options::OPT_fsave_optimization_record_EQ);
+if (A) {
+  CmdArgs.push_back(A->getValue());
+} else {
+  SmallString<128> F;
+  if (Output.isFilename() && (Args.hasArg(options::OPT_c) ||
+  Args.hasArg(options::OPT_S))) {
+F = Output.getFilename();
+  } else {
+// Use the compilation directory.
+F = llvm::sys::path::stem(Input.getBaseInput());
+
+// If we're compiling for an offload architecture (i.e. a CUDA device),
+// we need to make the file name for the device compilation different
+// from the host compilation.
+if (!JA.isDeviceOffloading(Action::OFK_None) &&
+!JA.isDeviceOffloading(Action::OFK_Host)) {
+  llvm::sys::path::re

[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-05 Thread Hal Finkel via cfe-commits
hfinkel added a comment.

@rsmith  @rjmccall - I chatted with @anemet about this on IRC, and he's happy 
with it. Please look this over, in part to make sure you're happy with the 
option name.

On the name, two of my thoughts behind using -fsave-optimization-record were: 
1) I did not want to call it a "report", because it is YAML output and not 
something for a human to use directly and 2) I thought that record, the noun, 
fit well, but not necessarily the verb, and by putting 'save' in the name it 
seems clear (at least to me) that record is the noun.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-03 Thread Hal Finkel via cfe-commits
hfinkel added a dependency: D25224: Don't filter diagnostics written as YAML to 
the output file.
hfinkel added a comment.

Note: This depends on https://reviews.llvm.org/D25224.


https://reviews.llvm.org/D25225



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


[PATCH] D25225: Add an option to save the backend-produced YAML optimization record to a file

2016-10-03 Thread Hal Finkel via cfe-commits
hfinkel created this revision.
hfinkel added reviewers: anemet, rsmith, rjmccall.
hfinkel added a subscriber: cfe-commits.
Herald added a subscriber: mcrosier.

The backend now has the capability to save information from optimizations, the 
same information that can be used to generate optimization diagnostics but in 
machine-consumable form, into an output file. This can be enabled when using 
opt (see r282539), and this patch will enable it when using clang. The idea is 
that other tools will be able to consume these files, and perhaps in 
combination with the original source code, produce various kinds of 
optimization reports for users (and for compiler developers).

This patch proposes the name -fsave-optimization-record (and 
-fsave-optimization-record=filename). Bikeshedding welcome.


https://reviews.llvm.org/D25225

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/CodeGenAction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/opt-record.c
  test/Driver/opt-record.c

Index: test/Driver/opt-record.c
===
--- /dev/null
+++ test/Driver/opt-record.c
@@ -0,0 +1,9 @@
+// RUN: %clang -### -S -o FOO -fsave-optimization-record %s 2>&1 | FileCheck %s
+// RUN: %clang -### -S -o FOO -fsave-optimization-record=BAR.txt %s 2>&1 | FileCheck %s -check-prefix=CHECK-EQ
+
+// CHECK: "-cc1"
+// CHECK: "-opt-record-file" "opt-record.yaml"
+
+// CHECK-EQ: "-cc1"
+// CHECK-EQ: "-opt-record-file" "BAR.txt"
+
Index: test/CodeGen/opt-record.c
===
--- /dev/null
+++ test/CodeGen/opt-record.c
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -O3 -triple x86_64-unknown-linux-gnu -target-cpu x86-64 %s -o %t -dwarf-column-info -opt-record-file %t.yaml -emit-obj
+// RUN: cat %t.yaml | FileCheck %s
+// REQUIRES: x86-registered-target
+
+void bar();
+void foo() { bar(); }
+
+void Test(int *res, int *c, int *d, int *p, int n) {
+  int i;
+
+#pragma clang loop vectorize(assume_safety)
+  for (i = 0; i < 1600; i++) {
+res[i] = (p[i] == 0) ? res[i] : res[i] + d[i];
+  }
+}
+
+// CHECK: --- !Missed
+// CHECK: Pass:inline
+// CHECK: Name:NoDefinition
+// CHECK: Function:foo
+
+// CHECK: --- !Passed
+// CHECK: Pass:loop-vectorize
+// CHECK: Name:Vectorized
+// CHECK: Function:Test
+
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -823,6 +823,10 @@
   Opts.LinkerOptions = Args.getAllArgValues(OPT_linker_option);
   bool NeedLocTracking = false;
 
+  Opts.OptRecordFile = Args.getLastArgValue(OPT_opt_record_file);
+  if (!Opts.OptRecordFile.empty())
+NeedLocTracking = true;
+
   if (Arg *A = Args.getLastArg(OPT_Rpass_EQ)) {
 Opts.OptimizationRemarkPattern =
 GenerateOptimizationRemarkRegex(Diags, Args, A);
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3336,23 +3336,29 @@
   }
 }
 
-static const char *SplitDebugName(const ArgList &Args, const InputInfo &Input) {
+static const char *getAltExtOutputName(const ArgList &Args,
+   const InputInfo &Input,
+   const char *Ext) {
   Arg *FinalOutput = Args.getLastArg(options::OPT_o);
   if (FinalOutput && Args.hasArg(options::OPT_c)) {
 SmallString<128> T(FinalOutput->getValue());
-llvm::sys::path::replace_extension(T, "dwo");
+llvm::sys::path::replace_extension(T, Ext);
 return Args.MakeArgString(T);
   } else {
 // Use the compilation dir.
 SmallString<128> T(
 Args.getLastArgValue(options::OPT_fdebug_compilation_dir));
 SmallString<128> F(llvm::sys::path::stem(Input.getBaseInput()));
-llvm::sys::path::replace_extension(F, "dwo");
+llvm::sys::path::replace_extension(F, Ext);
 T += F;
 return Args.MakeArgString(F);
   }
 }
 
+static const char *SplitDebugName(const ArgList &Args, const InputInfo &Input) {
+  return getAltExtOutputName(Args, Input, "dwo");
+}
+
 static void SplitDebugInfo(const ToolChain &TC, Compilation &C, const Tool &T,
const JobAction &JA, const ArgList &Args,
const InputInfo &Output, const char *OutFile) {
@@ -3377,6 +3383,10 @@
   C.addCommand(llvm::make_unique(JA, T, Exec, StripArgs, II));
 }
 
+static const char *getOptRecordName(const ArgList &Args, const InputInfo &Input) {
+  return getAltExtOutputName(Args, Input, "yaml");
+}
+
 /// \brief Vectorize at all optimization levels greater than 1 except for -Oz.
 /// For -Oz the loop vectorizer is disable, while the slp vectorizer is enabled.
 static bool shouldEnableVectorizerAtOLevel(const ArgList