r355209 - [PGO] Use the explicit parameter in ProfileSummary API. NFC

2019-03-01 Thread Rong Xu via cfe-commits
Author: xur
Date: Fri Mar  1 09:50:20 2019
New Revision: 355209

URL: http://llvm.org/viewvc/llvm-project?rev=355209&view=rev
Log:
[PGO] Use the explicit parameter in ProfileSummary API. NFC

Use the explicit parameter in setProfileSummary() and getSummary().
This is a follow-up of r355131.

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=355209&r1=355208&r2=355209&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Mar  1 09:50:20 2019
@@ -52,6 +52,7 @@
 #include "llvm/IR/Intrinsics.h"
 #include "llvm/IR/LLVMContext.h"
 #include "llvm/IR/Module.h"
+#include "llvm/IR/ProfileSummary.h"
 #include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/ConvertUTF.h"
@@ -417,7 +418,9 @@ void CodeGenModule::Release() {
 OpenMPRuntime->clear();
   }
   if (PGOReader) {
-getModule().setProfileSummary(PGOReader->getSummary().getMD(VMContext));
+getModule().setProfileSummary(
+PGOReader->getSummary(/* UseCS */ false).getMD(VMContext),
+llvm::ProfileSummary::PSK_Instr);
 if (PGOStats.hasDiagnostics())
   PGOStats.reportDiagnostics(getDiags(), getCodeGenOpts().MainFileName);
   }


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


r355331 - [PGO] Clang part of change for context-sensitive PGO (part1)

2019-03-04 Thread Rong Xu via cfe-commits
Author: xur
Date: Mon Mar  4 12:21:31 2019
New Revision: 355331

URL: http://llvm.org/viewvc/llvm-project?rev=355331&view=rev
Log:
[PGO] Clang part of change for context-sensitive PGO (part1)

Part 1 of CSPGO change in Clang. This includes changes in clang options
and calls to llvm PassManager. Tests will be committed in part2.
This change needs the PassManager change in llvm.

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


Modified:
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/CodeGenOptions.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/lib/Driver/ToolChains/Clang.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=355331&r1=355330&r2=355331&view=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Mon Mar  4 12:21:31 2019
@@ -1745,7 +1745,8 @@ controlled by the GCC-compatible flags `
 ``-fprofile-use``. Although these flags are semantically equivalent to
 their GCC counterparts, they *do not* handle GCC-compatible profiles.
 They are only meant to implement GCC's semantics with respect to
-profile creation and use.
+profile creation and use. Flag ``-fcs-profile-generate`` also instruments
+programs using the same instrumentation method as ``-fprofile-generate``.
 
 .. option:: -fprofile-generate[=]
 
@@ -1778,6 +1779,45 @@ profile creation and use.
  ``LLVM_PROFILE_FILE`` can still be used to override
  the directory and filename for the profile file at runtime.
 
+.. option:: -fcs-profile-generate[=]
+
+  The ``-fcs-profile-generate`` and ``-fcs-profile-generate=`` flags will use
+  the same instrumentation method, and generate the same profile as in the
+  ``-fprofile-generate`` and ``-fprofile-generate=`` flags. The difference is
+  that the instrumentation is performed after inlining so that the resulted
+  profile has a better context sensitive information. They cannot be used
+  together with ``-fprofile-generate`` and ``-fprofile-generate=`` flags.
+  They are typically used in conjunction with ``-fprofile-use`` flag.
+  The profile generated by ``-fcs-profile-generate`` and ``-fprofile-generate``
+  can be merged by llvm-profdata. A use example:
+
+  .. code-block:: console
+
+$ clang++ -O2 -fprofile-generate=yyy/zzz code.cc -o code
+$ ./code
+$ llvm-profdata merge -output=code.profdata yyy/zzz/
+
+  The first few steps are the same as that in ``-fprofile-generate``
+  compilation. Then perform a second round of instrumentation.
+
+  .. code-block:: console
+
+$ clang++ -O2 -fprofile-use=code.profdata -fcs-profile-generate=sss/ttt \
+  -o cs_code
+$ ./cs_code
+$ llvm-profdata merge -output=cs_code.profdata sss/ttt code.profdata
+
+  The resulted ``cs_code.prodata`` combines ``code.profdata`` and the profile
+  generated from binary ``cs_code``. Profile ``cs_code.profata`` can be used by
+  ``-fprofile-use`` compilaton.
+
+  .. code-block:: console
+
+$ clang++ -O2 -fprofile-use=cs_code.profdata
+
+  The above command will read both profiles to the compiler at the identical
+  point of instrumenations.
+
 .. option:: -fprofile-use[=]
 
   Without any other arguments, ``-fprofile-use`` behaves identically to

Modified: cfe/trunk/include/clang/Basic/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/CodeGenOptions.h?rev=355331&r1=355330&r2=355331&view=diff
==
--- cfe/trunk/include/clang/Basic/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Basic/CodeGenOptions.h Mon Mar  4 12:21:31 2019
@@ -100,6 +100,7 @@ public:
 ProfileClangInstr, // Clang instrumentation to generate execution counts
// to use with PGO.
 ProfileIRInstr,// IR level PGO instrumentation in LLVM.
+ProfileCSIRInstr, // IR level PGO context sensitive instrumentation in 
LLVM.
   };
 
   enum EmbedBitcodeKind {
@@ -203,8 +204,8 @@ public:
   /// A list of linker options to embed in the object file.
   std::vector LinkerOptions;
 
-  /// Name of the profile file to use as output for -fprofile-instr-generate
-  /// and -fprofile-generate.
+  /// Name of the profile file to use as output for -fprofile-instr-generate,
+  /// -fprofile-generate, and -fcs-profile-generate.
   std::string InstrProfileOutput;
 
   /// Name of the profile file to use with -fprofile-sample-use.
@@ -318,6 +319,11 @@ public:
 return getProfileInstr() == ProfileIRInstr;
   }
 
+  /// Check if CS IR level profile instrumentation is on.
+  bool hasProfileCSIRInstr() const {
+return getProfileInstr() == ProfileCSIRInstr;
+  }
+
   /// Check if Clang profile use is

r355432 - [PGO] Clang part of change for context-sensitive PGO (part2)

2019-03-05 Thread Rong Xu via cfe-commits
Author: xur
Date: Tue Mar  5 11:09:56 2019
New Revision: 355432

URL: http://llvm.org/viewvc/llvm-project?rev=355432&view=rev
Log:
[PGO] Clang part of change for context-sensitive PGO (part2)

Part 2 of CSPGO change in Clang: Add test cases.

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


Added:
cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
cfe/trunk/test/CodeGen/cspgo-instrumentation.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_lto.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_thinlto.c

Added: cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext?rev=355432&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext (added)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext Tue Mar  5 11:09:56 2019
@@ -0,0 +1,2 @@
+# IR level Instrumentation Flag
+:ir

Added: cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext?rev=355432&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext (added)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext Tue Mar  5 11:09:56 2019
@@ -0,0 +1,2 @@
+# IR level Instrumentation Flag with CS
+:csir

Added: cfe/trunk/test/CodeGen/cspgo-instrumentation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cspgo-instrumentation.c?rev=355432&view=auto
==
--- cfe/trunk/test/CodeGen/cspgo-instrumentation.c (added)
+++ cfe/trunk/test/CodeGen/cspgo-instrumentation.c Tue Mar  5 11:09:56 2019
@@ -0,0 +1,41 @@
+// Test if CSPGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN
+// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -fexperimental-new-pass-manager 
-fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGen on
+//
+// RUN: rm -rf %t && mkdir %t
+// RUN: llvm-profdata merge -o %t/noncs.profdata %S/Inputs/pgotestir.proftext
+//
+// Ensure Pass PGOInstrumentationUsePass and PGOInstrumentationGenPass are 
invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-fexperimental-new-pass-manager -fdebug-pass-manager  -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationUsePass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationUse
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGen on
+
+// Ensure Pass PGOInstrumentationUsePass is invoked only once.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-NEWPM
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationGenCreateVarPass
+// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationUsePass
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM: Running pass: PGOInstrumentationUse
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: 
PGOInstrumentationGenCreateVar
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: PGOInstrumentationUse
+//
+// Ensure Pass PGOInstrumentationUse

r355454 - Revert r355432 for buildbot failures in ppc64be-linux and s390x-linux

2019-03-05 Thread Rong Xu via cfe-commits
Author: xur
Date: Tue Mar  5 15:02:06 2019
New Revision: 355454

URL: http://llvm.org/viewvc/llvm-project?rev=355454&view=rev
Log:
Revert r355432 for buildbot failures in ppc64be-linux and s390x-linux

Removed:
cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
cfe/trunk/test/CodeGen/cspgo-instrumentation.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_lto.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_thinlto.c

Removed: cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext?rev=355453&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext (original)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext (removed)
@@ -1,2 +0,0 @@
-# IR level Instrumentation Flag
-:ir

Removed: cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext?rev=355453&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext (original)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext (removed)
@@ -1,2 +0,0 @@
-# IR level Instrumentation Flag with CS
-:csir

Removed: cfe/trunk/test/CodeGen/cspgo-instrumentation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cspgo-instrumentation.c?rev=355453&view=auto
==
--- cfe/trunk/test/CodeGen/cspgo-instrumentation.c (original)
+++ cfe/trunk/test/CodeGen/cspgo-instrumentation.c (removed)
@@ -1,41 +0,0 @@
-// Test if CSPGO instrumentation and use pass are invoked.
-//
-// Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN
-// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -fexperimental-new-pass-manager 
-fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenCreateVarPass
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGen on
-//
-// RUN: rm -rf %t && mkdir %t
-// RUN: llvm-profdata merge -o %t/noncs.profdata %S/Inputs/pgotestir.proftext
-//
-// Ensure Pass PGOInstrumentationUsePass and PGOInstrumentationGenPass are 
invoked.
-// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2
-// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-fexperimental-new-pass-manager -fdebug-pass-manager  -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationUsePass
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenCreateVarPass
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenPass
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationUse
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
-// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGen on
-
-// Ensure Pass PGOInstrumentationUsePass is invoked only once.
-// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
-// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-NEWPM
-// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
-// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationGenCreateVarPass
-// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationUsePass
-// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM: Running pass: PGOInstrumentationUse
-// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: 
PGOInstrumentationGenCreateVar
-// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: PGOInstrumentationUse
-//
-// Ensure Pass PGOInstrumentationUsePass is invoked twice.
-// RUN: llvm-profdata merge -o %t/cs.profdata %S/Inputs/pgotestir_cs.proftext
-// RUN: %clang_cc1 -O2 

r355563 - [PGO] Re-submit: Clang part of change for context-sensitive PGO (part2)

2019-03-06 Thread Rong Xu via cfe-commits
Author: xur
Date: Wed Mar  6 15:00:38 2019
New Revision: 355563

URL: http://llvm.org/viewvc/llvm-project?rev=355563&view=rev
Log:
[PGO] Re-submit: Clang part of change for context-sensitive PGO (part2)

Part 2 of CSPGO change in Clang: Add test cases.

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


Added:
cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
cfe/trunk/test/CodeGen/cspgo-instrumentation.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_lto.c
cfe/trunk/test/CodeGen/cspgo-instrumentation_thinlto.c

Added: cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext?rev=355563&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext (added)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir.proftext Wed Mar  6 15:00:38 2019
@@ -0,0 +1,2 @@
+# IR level Instrumentation Flag
+:ir

Added: cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext?rev=355563&view=auto
==
--- cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext (added)
+++ cfe/trunk/test/CodeGen/Inputs/pgotestir_cs.proftext Wed Mar  6 15:00:38 2019
@@ -0,0 +1,2 @@
+# IR level Instrumentation Flag with CS
+:csir

Added: cfe/trunk/test/CodeGen/cspgo-instrumentation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/cspgo-instrumentation.c?rev=355563&view=auto
==
--- cfe/trunk/test/CodeGen/cspgo-instrumentation.c (added)
+++ cfe/trunk/test/CodeGen/cspgo-instrumentation.c Wed Mar  6 15:00:38 2019
@@ -0,0 +1,41 @@
+// Test if CSPGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -mllvm -debug-pass=Structure 
-emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN
+// RUN: %clang_cc1 -O2 -fprofile-instrument=csllvm 
-fprofile-instrument-path=default.profraw  %s -fexperimental-new-pass-manager 
-fdebug-pass-manager -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN-NEWPM: Running pass: 
PGOInstrumentationGen on
+//
+// RUN: rm -rf %t && mkdir %t
+// RUN: llvm-profdata merge -o %t/noncs.profdata %S/Inputs/pgotestir.proftext
+//
+// Ensure Pass PGOInstrumentationUsePass and PGOInstrumentationGenPass are 
invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata 
-fprofile-instrument=csllvm -fprofile-instrument-path=default.profraw  %s 
-fexperimental-new-pass-manager -fdebug-pass-manager  -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationUsePass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenCreateVarPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2: PGOInstrumentationGenPass
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationUse
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGenCreateVar on
+// CHECK-CSPGOGENPASS-INVOKED-INSTR-GEN2-NEWPM: Running pass: 
PGOInstrumentationGen on
+
+// Ensure Pass PGOInstrumentationUsePass is invoked only once.
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// RUN: %clang_cc1 -O2 -fprofile-instrument-use-path=%t/noncs.profdata %s 
-fexperimental-new-pass-manager -fdebug-pass-manager -emit-llvm -o - 2>&1 | 
FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-NEWPM
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationGenCreateVarPass
+// CHECK-PGOUSEPASS-INVOKED-USE-NOT: PGOInstrumentationUsePass
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM: Running pass: PGOInstrumentationUse
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: 
PGOInstrumentationGenCreateVar
+// CHECK-PGOUSEPASS-INVOKED-USE-NEWPM-NOT: Running pass: PGOInstrumentationUse
+//
+// Ensure Pass PGOInstrum

r359215 - [PGO] Enable InstrProf lowering for Clang PGO instrumentation in the new pass manager

2019-04-25 Thread Rong Xu via cfe-commits
Author: xur
Date: Thu Apr 25 10:52:43 2019
New Revision: 359215

URL: http://llvm.org/viewvc/llvm-project?rev=359215&view=rev
Log:
[PGO] Enable InstrProf lowering for Clang PGO instrumentation in the new pass 
manager
Currently InstrProf lowering is not enabled for Clang PGO instrumentation in
the new pass manager. The following command
"-fprofile-instr-generate -fexperimental-new-pass-manager ..." is broken.

This CL enables InstrProf lowering pass for Clang PGO instrumentation in the
new pass manager.

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

Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CodeGen/pgo-instrumentation.c
cfe/trunk/test/Profile/c-general.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=359215&r1=359214&r2=359215&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Apr 25 10:52:43 2019
@@ -57,6 +57,7 @@
 #include "llvm/Transforms/Instrumentation/AddressSanitizer.h"
 #include "llvm/Transforms/Instrumentation/BoundsChecking.h"
 #include "llvm/Transforms/Instrumentation/GCOVProfiler.h"
+#include "llvm/Transforms/Instrumentation/InstrProfiling.h"
 #include "llvm/Transforms/Instrumentation/MemorySanitizer.h"
 #include "llvm/Transforms/Instrumentation/ThreadSanitizer.h"
 #include "llvm/Transforms/ObjCARC.h"
@@ -505,6 +506,21 @@ static Optional getGCOVOpti
   return Options;
 }
 
+static Optional
+getInstrProfOptions(const CodeGenOptions &CodeGenOpts,
+const LangOptions &LangOpts) {
+  if (!CodeGenOpts.hasProfileClangInstr())
+return None;
+  InstrProfOptions Options;
+  Options.NoRedZone = CodeGenOpts.DisableRedZone;
+  Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
+
+  // TODO: Surface the option to emit atomic profile counter increments at
+  // the driver level.
+  Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
+  return Options;
+}
+
 void EmitAssemblyHelper::CreatePasses(legacy::PassManager &MPM,
   legacy::FunctionPassManager &FPM) {
   // Handle disabling of all LLVM passes, where we want to preserve the
@@ -659,17 +675,10 @@ void EmitAssemblyHelper::CreatePasses(le
   MPM.add(createStripSymbolsPass(true));
   }
 
-  if (CodeGenOpts.hasProfileClangInstr()) {
-InstrProfOptions Options;
-Options.NoRedZone = CodeGenOpts.DisableRedZone;
-Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
-
-// TODO: Surface the option to emit atomic profile counter increments at
-// the driver level.
-Options.Atomic = LangOpts.Sanitize.has(SanitizerKind::Thread);
+  if (Optional Options =
+  getInstrProfOptions(CodeGenOpts, LangOpts))
+MPM.add(createInstrProfilingLegacyPass(*Options, false));
 
-MPM.add(createInstrProfilingLegacyPass(Options, false));
-  }
   bool hasIRInstr = false;
   if (CodeGenOpts.hasProfileIRInstr()) {
 PMBuilder.EnablePGOInstrGen = true;
@@ -1056,6 +1065,9 @@ void EmitAssemblyHelper::EmitAssemblyWit
 if (CodeGenOpts.OptimizationLevel == 0) {
   if (Optional Options = getGCOVOptions(CodeGenOpts))
 MPM.addPass(GCOVProfilerPass(*Options));
+  if (Optional Options =
+  getInstrProfOptions(CodeGenOpts, LangOpts))
+MPM.addPass(InstrProfiling(*Options, false));
 
   // Build a minimal pipeline based on the semantics required by Clang,
   // which is just that always inlining occurs.
@@ -1120,6 +1132,11 @@ void EmitAssemblyHelper::EmitAssemblyWit
 PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
   MPM.addPass(GCOVProfilerPass(*Options));
 });
+  if (Optional Options =
+  getInstrProfOptions(CodeGenOpts, LangOpts))
+PB.registerPipelineStartEPCallback([Options](ModulePassManager &MPM) {
+  MPM.addPass(InstrProfiling(*Options, false));
+});
 
   if (IsThinLTO) {
 MPM = PB.buildThinLTOPreLinkDefaultPipeline(

Modified: cfe/trunk/test/CodeGen/pgo-instrumentation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-instrumentation.c?rev=359215&r1=359214&r2=359215&view=diff
==
--- cfe/trunk/test/CodeGen/pgo-instrumentation.c (original)
+++ cfe/trunk/test/CodeGen/pgo-instrumentation.c Thu Apr 25 10:52:43 2019
@@ -1,20 +1,36 @@
 // Test if PGO instrumentation and use pass are invoked.
 //
 // Ensure Pass PGOInstrumentationGenPass is invoked.
-// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm 
-debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm 
-debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOGENPASS-INVOKED-

r359241 - [PGO] Fix buildbot failure in 359215

2019-04-25 Thread Rong Xu via cfe-commits
Author: xur
Date: Thu Apr 25 14:16:41 2019
New Revision: 359241

URL: http://llvm.org/viewvc/llvm-project?rev=359241&view=rev
Log:
[PGO] Fix buildbot failure in 359215

Revert the part of changes in r359215 that failing in some platforms.
I will re-enable them later.

Modified:
cfe/trunk/test/Profile/c-general.c

Modified: cfe/trunk/test/Profile/c-general.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/c-general.c?rev=359241&r1=359240&r2=359241&view=diff
==
--- cfe/trunk/test/Profile/c-general.c (original)
+++ cfe/trunk/test/Profile/c-general.c Thu Apr 25 14:16:41 2019
@@ -1,12 +1,10 @@
 // Test instrumentation of general constructs in C.
 
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm -fprofile-instrument=clang | FileCheck 
-allow-deprecated-dag-overlap  -check-prefix=PGOGEN %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm -fprofile-instrument=clang -fexperimental-new-pass-manager | 
FileCheck -allow-deprecated-dag-overlap  -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/c-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata | FileCheck 
-allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm 
-fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 | FileCheck 
-allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm 
-fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v3 
-fexperimental-new-pass-manager | FileCheck -allow-deprecated-dag-overlap  
-check-prefix=PGOUSE %s
 // Also check compatibility with older profiles.
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name c-general.c 
%s -o - -emit-llvm 
-fprofile-instrument-use-path=%S/Inputs/c-general.profdata.v1 | FileCheck 
-allow-deprecated-dag-overlap  -check-prefix=PGOUSE %s
 


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


r367628 - [PGO] Add PGO support at -O0 in the experimental new pass manager

2019-08-01 Thread Rong Xu via cfe-commits
Author: xur
Date: Thu Aug  1 15:36:34 2019
New Revision: 367628

URL: http://llvm.org/viewvc/llvm-project?rev=367628&view=rev
Log:
[PGO] Add PGO support at -O0 in the experimental new pass manager

Add PGO support at -O0 in the experimental new pass manager to sync the
behavior of the legacy pass manager.

Also change the test of gcc-flag-compatibility.c for more complete test:
(1) change the match string to "profc" and "profd" to ensure the
instrumentation is happening.
(2) add IR format proftext so that PGO use compilation is tested.

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

Added:
cfe/trunk/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/Profile/gcc-flag-compatibility.c

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=367628&r1=367627&r2=367628&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Thu Aug  1 15:36:34 2019
@@ -1117,6 +1117,16 @@ void EmitAssemblyHelper::EmitAssemblyWit
   // code generation.
   MPM.addPass(AlwaysInlinerPass(/*InsertLifetimeIntrinsics=*/false));
 
+  // At -O0, we can still do PGO. Add all the requested passes for
+  // instrumentation PGO, if requested.
+  if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
+ PGOOpt->Action == PGOOptions::IRUse))
+PB.addPGOInstrPassesForO0(
+MPM, CodeGenOpts.DebugPassManager,
+/* RunProfileGen */ (PGOOpt->Action == PGOOptions::IRInstr),
+/* IsCS */ false, PGOOpt->ProfileFile,
+PGOOpt->ProfileRemappingFile);
+
   // At -O0 we directly run necessary sanitizer passes.
   if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds))
 MPM.addPass(createModuleToFunctionPassAdaptor(BoundsCheckingPass()));

Added: cfe/trunk/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext?rev=367628&view=auto
==
--- cfe/trunk/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext (added)
+++ cfe/trunk/test/Profile/Inputs/gcc-flag-compatibility_IR.proftext Thu Aug  1 
15:36:34 2019
@@ -0,0 +1,11 @@
+# IR level Instrumentation Flag
+:ir
+main
+# Func Hash:
+34137660316
+# Num Counters:
+2
+# Counter Values:
+100
+1
+

Modified: cfe/trunk/test/Profile/gcc-flag-compatibility.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/gcc-flag-compatibility.c?rev=367628&r1=367627&r2=367628&view=diff
==
--- cfe/trunk/test/Profile/gcc-flag-compatibility.c (original)
+++ cfe/trunk/test/Profile/gcc-flag-compatibility.c Thu Aug  1 15:36:34 2019
@@ -7,26 +7,50 @@
 // -fprofile-use=Uses the profile file /default.profdata
 // -fprofile-use=/file   Uses the profile file /file
 
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate | FileCheck 
-check-prefix=PROFILE-GEN %s
-// PROFILE-GEN: __llvm_profile_filename
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
+// PROFILE-GEN: @__profc_main = private global [2 x i64] zeroinitializer, 
section "__llvm_prf_cnts", align 8
+// PROFILE-GEN: @__profd_main = private global
 
 // Check that -fprofile-generate=/path/to generates /path/to/default.profraw
-// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to | 
FileCheck -check-prefix=PROFILE-GEN-EQ %s
+// RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fno-experimental-new-pass-manager | FileCheck 
-check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ %s
+// RxUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fexperimental-new-pass-manager | FileCheck 
-check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ %s
 // PROFILE-GEN-EQ: constant [{{.*}} x i8] c"/path/to{{/|\\5C}}{{.*}}\00"
 
 // Check that -fprofile-use=some/path reads some/path/default.profdata
+// This uses Clang FE format profile.
 // RUN: rm -rf %t.dir
 // RUN: mkdir -p %t.dir/some/path
 // RUN: llvm-profdata merge %S/Inputs/gcc-flag-compatibility.proftext -o 
%t.dir/some/path/default.profdata
-// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path | FileCheck -check-prefix=PROFILE-USE-2 %s
-// PROFILE-USE-2: = !{!"branch_weights", i32 101, i32 2}
+// RUN: %clang %s -o - -Xclang -disable-llvm-passes -emit-llvm -S 
-fprofile-use=%t.dir/some/path -fno-experimental-new-pass-manager | FileCheck 
-check-prefix=PROFILE-USE %s
+// RUN: %clang %s -

Re: [PATCH] D64029: [PGO] Add PGO support at -O0 in the experimental new pass manager

2019-08-02 Thread Rong Xu via cfe-commits
yes. I already know this issue as this also breaks windows bolt.
The fix should be simple.

-Rong

On Thu, Aug 1, 2019 at 11:52 PM Petr Hosek via Phabricator <
revi...@reviews.llvm.org> wrote:

> phosek added a comment.
>
> Looks like this change broke `Profile/gcc-flag-compatibility.c` test on
> macOS:
>
>    TEST 'Clang :: Profile/gcc-flag-compatibility.c'
> FAILED 
>   Script:
>   --
>   : 'RUN: at line 10';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
> -o - -emit-llvm -fprofile-generate -fno-experimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefix=PROFILE-GEN
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 11';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
> -o - -emit-llvm -fprofile-generate -fexperimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefix=PROFILE-GEN
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 16';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
> -o - -emit-llvm -fprofile-generate=/path/to
> -fno-experimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 22';   rm -rf
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir
>   : 'RUN: at line 23';   mkdir -p
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>   : 'RUN: at line 24';   llvm-profdata merge
> /b/s/w/ir/k/llvm-project/clang/test/Profile/Inputs/gcc-flag-compatibility.proftext
> -o
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/default.profdata
>   : 'RUN: at line 25';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
> -Xclang -disable-llvm-passes -emit-llvm -S
> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
> -fno-experimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefix=PROFILE-USE
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 26';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
> -Xclang -disable-llvm-passes -emit-llvm -S
> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
> -fexperimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefix=PROFILE-USE
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 30';   rm -rf
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir
>   : 'RUN: at line 31';   mkdir -p
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>   : 'RUN: at line 32';   llvm-profdata merge
> /b/s/w/ir/k/llvm-project/clang/test/Profile/Inputs/gcc-flag-compatibility.proftext
> -o
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/file.prof
>   : 'RUN: at line 33';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
> -Xclang -disable-llvm-passes -emit-llvm -S
> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/file.prof
> -fno-experimental-new-pass-manager |
> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
> -check-prefix=PROFILE-USE
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>   : 'RUN: at line 34';
>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
> -Xclang -disable-llvm-passes -emit-llvm -S
> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/file.prof
> -fexperimental-new-pass-ma

r367657 - [PGO] Fix bolt failures from r367628

2019-08-02 Thread Rong Xu via cfe-commits
Author: xur
Date: Fri Aug  2 00:21:50 2019
New Revision: 367657

URL: http://llvm.org/viewvc/llvm-project?rev=367657&view=rev
Log:
[PGO] Fix bolt failures from r367628

Relaxed the check in a test because the windows bolt generates different
profile variables.

Modified:
cfe/trunk/test/Profile/gcc-flag-compatibility.c

Modified: cfe/trunk/test/Profile/gcc-flag-compatibility.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/gcc-flag-compatibility.c?rev=367657&r1=367656&r2=367657&view=diff
==
--- cfe/trunk/test/Profile/gcc-flag-compatibility.c (original)
+++ cfe/trunk/test/Profile/gcc-flag-compatibility.c Fri Aug  2 00:21:50 2019
@@ -9,8 +9,8 @@
 
 // RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fno-experimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
 // RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate 
-fexperimental-new-pass-manager | FileCheck -check-prefix=PROFILE-GEN %s
-// PROFILE-GEN: @__profc_main = private global [2 x i64] zeroinitializer, 
section "__llvm_prf_cnts", align 8
-// PROFILE-GEN: @__profd_main = private global
+// PROFILE-GEN: @__profc_main = {{(private|internal)}} global [2 x i64] 
zeroinitializer, section
+// PROFILE-GEN: @__profd_main =
 
 // Check that -fprofile-generate=/path/to generates /path/to/default.profraw
 // RUN: %clang %s -c -S -o - -emit-llvm -fprofile-generate=/path/to 
-fno-experimental-new-pass-manager | FileCheck 
-check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ %s


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


Re: [PATCH] D64029: [PGO] Add PGO support at -O0 in the experimental new pass manager

2019-08-02 Thread Rong Xu via cfe-commits
r367657 should fix this.

On Fri, Aug 2, 2019 at 12:20 AM Rong Xu  wrote:

> yes. I already know this issue as this also breaks windows bolt.
> The fix should be simple.
>
> -Rong
>
> On Thu, Aug 1, 2019 at 11:52 PM Petr Hosek via Phabricator <
> revi...@reviews.llvm.org> wrote:
>
>> phosek added a comment.
>>
>> Looks like this change broke `Profile/gcc-flag-compatibility.c` test on
>> macOS:
>>
>>    TEST 'Clang :: Profile/gcc-flag-compatibility.c'
>> FAILED 
>>   Script:
>>   --
>>   : 'RUN: at line 10';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
>> -o - -emit-llvm -fprofile-generate -fno-experimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefix=PROFILE-GEN
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 11';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
>> -o - -emit-llvm -fprofile-generate -fexperimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefix=PROFILE-GEN
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 16';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -c -S
>> -o - -emit-llvm -fprofile-generate=/path/to
>> -fno-experimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefixes=PROFILE-GEN,PROFILE-GEN-EQ
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 22';   rm -rf
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir
>>   : 'RUN: at line 23';   mkdir -p
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>>   : 'RUN: at line 24';   llvm-profdata merge
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/Inputs/gcc-flag-compatibility.proftext
>> -o
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/default.profdata
>>   : 'RUN: at line 25';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
>> -Xclang -disable-llvm-passes -emit-llvm -S
>> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>> -fno-experimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefix=PROFILE-USE
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 26';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
>> -Xclang -disable-llvm-passes -emit-llvm -S
>> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>> -fexperimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefix=PROFILE-USE
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 30';   rm -rf
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir
>>   : 'RUN: at line 31';   mkdir -p
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path
>>   : 'RUN: at line 32';   llvm-profdata merge
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/Inputs/gcc-flag-compatibility.proftext
>> -o
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/file.prof
>>   : 'RUN: at line 33';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
>> -Xclang -disable-llvm-passes -emit-llvm -S
>> -fprofile-use=/b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/tools/clang/test/Profile/Output/gcc-flag-compatibility.c.tmp.dir/some/path/file.prof
>> -fno-experimental-new-pass-manager |
>> /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/FileCheck
>> -check-prefix=PROFILE-USE
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c
>>   : 'RUN: at line 34';
>>  /b/s/w/ir/k/recipe_cleanup/clangOLc9jG/llvm_build_dir/bin/clang
>> /b/s/w/ir/k/llvm-project/clang/test/Profile/gcc-flag-compatibility.c -o -
>> -Xclang -disable-llvm-passes -emit-llvm -S
>> -fprofile-use=

Re: [PATCH] D63155: [clang][NewPM] Fix broken profile test

2019-06-28 Thread Rong Xu via cfe-commits
they are not doing the exacly the same thing for old pass manager and new
pass manger: old pass manger is doing instrumentation, while the new pass
manager with this change is NOT.
the test is not check instrumentation, (it only check the variables that
generates by InstroProfiling pass).
In this sense, the test is not well written.

I can draft a patch for this.

On Fri, Jun 28, 2019 at 4:53 PM Chandler Carruth via Phabricator <
revi...@reviews.llvm.org> wrote:

> chandlerc added a comment.
>
> In D63155#1563229 , @xur wrote:
>
> > This patch does not make sense to me.
> >
> > The reason of failing with -fexperimental-new-pass-manager is because we
> don't do PGO instrumentation at -O0. This is due to the fact that PGO
> instrumentation/use passes are under
> PassBuilder::buildPerModuleDefaultPipeline.
> >
> > This patch add a pass
> >
> >   MPM.addPass(PGOInstrumentationGenCreateVar(PGOOpt->ProfileFile));
> >
> > which only gives you the wrong signal  of instrumentation is done.
> >
> > I wrote pass PGOInstrumentationGenCreateVar only for some trick
> interactions for thinlto under ldd for CSPGO.
> >  Regular FDO should not use it.
> >
> > The right fix is to enable PGO instrumentation and use in pass builder
> for O0.
> >
> > I would like to request to revert this patch.
>
>
> I mean, I'm happy for the patch to be reverted, but I still really don't
> understand why this fixes the test to work *exactly* the same as w/ the old
> pass manager and doesn't break any other tests if it is completely wrong?
> It seems like there must be something strange with the test coverage if
> this is so far off of correct without any failures...
>
> I also don't understand what fix you are suggesting instead, but maybe you
> can show a patch?
>
>
> Repository:
>   rL LLVM
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D63155/new/
>
> https://reviews.llvm.org/D63155
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D63155: [clang][NewPM] Fix broken profile test

2019-07-01 Thread Rong Xu via cfe-commits
On Fri, Jun 28, 2019 at 5:28 PM Xinliang David Li 
wrote:

> I agree that the  test coverage needs to be improved eg better check etc.
>
PGO is rarely run under -O0.  But I agree that we should improve the test.

I sent out https://reviews.llvm.org/D64029. Chanlder: could you take a look?

Thanks,

-Rong


>
> David
>
>
> On Fri, Jun 28, 2019 at 5:21 PM Chandler Carruth via Phabricator via
> llvm-commits  wrote:
>
>> chandlerc added a comment.
>>
>> In D63155#1563275 , @xur wrote:
>>
>> > In D63155#1563266 ,
>> @chandlerc wrote:
>> >
>> > > I just think we also need to understand why *no other test failed*,
>> and why the only test we have for doing PGO at O0 is this one and it could
>> be "fixed" but such a deeply unrelated change
>> >
>> >
>> > We have special code to do PGO at O0 in old pass manager. This is not
>> done in the new pass manager.
>>
>>
>> I'm not sure how this addresses my question about test coverage.
>>
>>
>> Repository:
>>   rL LLVM
>>
>> CHANGES SINCE LAST ACTION
>>   https://reviews.llvm.org/D63155/new/
>>
>> https://reviews.llvm.org/D63155
>>
>>
>>
>> ___
>> llvm-commits mailing list
>> llvm-comm...@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 50da55a - [PGO] Supporting code for always instrumenting entry block

2020-07-22 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-07-22T15:01:53-07:00
New Revision: 50da55a58534e9207d8d5e31c8b4b5cf0c624175

URL: 
https://github.com/llvm/llvm-project/commit/50da55a58534e9207d8d5e31c8b4b5cf0c624175
DIFF: 
https://github.com/llvm/llvm-project/commit/50da55a58534e9207d8d5e31c8b4b5cf0c624175.diff

LOG: [PGO] Supporting code for always instrumenting entry block

This patch includes the supporting code that enables always
instrumenting the function entry block by default.

This patch will NOT the default behavior.

It adds a variant bit in the profile version, adds new directives in
text profile format, and changes llvm-profdata tool accordingly.

This patch is a split of D83024 (https://reviews.llvm.org/D83024)
Many test changes from D83024 are also included.

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

Added: 
clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext
clang/test/Profile/Inputs/gcc-flag-compatibility_IR_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/branch2_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/criticaledge_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/indirectbr_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/irreducible_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/landingpad_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/loop1_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/loop2_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/misexpect-branch_entry.proftext

llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch-correct_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/misexpect-switch_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/switch_entry.proftext
llvm/test/tools/llvm-profdata/Inputs/header-directives-1.proftext
llvm/test/tools/llvm-profdata/Inputs/header-directives-2.proftext
llvm/test/tools/llvm-profdata/Inputs/header-directives-3.proftext
llvm/test/tools/llvm-profdata/header-directives.test

Modified: 
clang/test/CodeGenCXX/profile-remap.cpp
clang/test/Profile/gcc-flag-compatibility.c
llvm/include/llvm/ProfileData/InstrProf.h
llvm/include/llvm/ProfileData/InstrProfData.inc
llvm/include/llvm/ProfileData/InstrProfReader.h
llvm/include/llvm/ProfileData/InstrProfWriter.h
llvm/lib/ProfileData/InstrProf.cpp
llvm/lib/ProfileData/InstrProfReader.cpp
llvm/lib/ProfileData/InstrProfWriter.cpp
llvm/lib/Transforms/Instrumentation/CFGMST.h
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Transforms/PGOProfile/Inputs/func_entry.proftext
llvm/test/Transforms/PGOProfile/Inputs/select1.proftext
llvm/test/Transforms/PGOProfile/Inputs/select2.proftext
llvm/test/Transforms/PGOProfile/branch2.ll
llvm/test/Transforms/PGOProfile/counter_promo_exit_catchswitch.ll
llvm/test/Transforms/PGOProfile/criticaledge.ll
llvm/test/Transforms/PGOProfile/cspgo_profile_summary.ll
llvm/test/Transforms/PGOProfile/indirectbr.ll
llvm/test/Transforms/PGOProfile/irreducible.ll
llvm/test/Transforms/PGOProfile/landingpad.ll
llvm/test/Transforms/PGOProfile/loop1.ll
llvm/test/Transforms/PGOProfile/loop2.ll
llvm/test/Transforms/PGOProfile/misexpect-branch-stripped.ll
llvm/test/Transforms/PGOProfile/misexpect-branch.ll
llvm/test/Transforms/PGOProfile/misexpect-switch-default.ll
llvm/test/Transforms/PGOProfile/misexpect-switch.ll
llvm/test/Transforms/PGOProfile/switch.ll
llvm/test/Transforms/PGOProfile/thinlto_cspgo_use.ll
llvm/tools/llvm-profdata/llvm-profdata.cpp

Removed: 




diff  --git a/clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext 
b/clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext
new file mode 100644
index ..65bc6ff46711
--- /dev/null
+++ b/clang/test/CodeGenCXX/Inputs/profile-remap_entry.proftext
@@ -0,0 +1,8 @@
+:ir
+:entry_first
+_ZN3Foo8functionENS_1XE
+29667547796
+2
+100
+90
+

diff  --git a/clang/test/CodeGenCXX/profile-remap.cpp 
b/clang/test/CodeGenCXX/profile-remap.cpp
index 0fc7c7b40033..b519e55d2112 100644
--- a/clang/test/CodeGenCXX/profile-remap.cpp
+++ b/clang/test/CodeGenCXX/profile-remap.cpp
@@ -3,6 +3,8 @@
 // RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-sample-use=%S/Inputs/profile-remap.samples 
-fprofile-remapping-file=%S/Inputs/profile-remap.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-SAMPLES
 // RUN: llvm-profdata merge -output %T.profdata 
%S/Inputs/profile-remap.proftext
 // RUN: %clang_cc1 -triple x86_64-linux-gnu 
-fprofile-instrument-use-path=%T.profdata 
-fprofile-remapping-file=%S/Inputs/profile-remap.map 
-fexperimental-new-pass-manager -O2 %s -emit-llvm -o - | FileCheck %s 
--check-prefixes=CHECK,CHECK-INSTR
+// RUN: llvm-profdata merge -output %T.profdata 
%S/Inputs/profile-remap_entry.proftext
+// RUN: %clang_cc1 -tripl

[clang] db18f26 - [llvm-profdata] Handle internal linkage functions in profile supplementation

2022-08-29 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2022-08-29T16:15:12-07:00
New Revision: db18f26567be47ec1da7fba48179a3001f0d34ab

URL: 
https://github.com/llvm/llvm-project/commit/db18f26567be47ec1da7fba48179a3001f0d34ab
DIFF: 
https://github.com/llvm/llvm-project/commit/db18f26567be47ec1da7fba48179a3001f0d34ab.diff

LOG: [llvm-profdata] Handle internal linkage functions in profile 
supplementation

This patch has the following changes:
(1) Handling of internal linkage functions (static functions)
Static functions in FDO have a prefix of source file name, while they do not
have one in SampleFDO. Current implementation does not handle this and we are
not updating the profile for static functions. This patch fixes this.

(2) Handling of -funique-internal-linakge-symbols
Again this is for the internal linkage functions. Option
-funique-internal-linakge-symbols can now be applied to both FDO and SampleFDO
compilation. When it is used, it demangles internal linkage function names and
adds a hash value as the postfix.

When both SampleFDO and FDO profiles use this option, or both
not use this option, changes in (1) should handle this.

Here we also handle when the SampleFDO profile using this option while FDO
profile not using this option, or vice versa.

There is one case where this patch won't work: If one of the profiles used
mangled name and the other does not. For example, if the SampleFDO profile
uses clang c-compiler and without -funique-internal-linakge-symbols, while
the FDO profile uses -funique-internal-linakge-symbols. The SampleFDO profile
contains unmangled names while the FDO profile contains mangled names. If
both profiles use c++ compiler, this won't happen. We think this use case
is rare and does not justify the effort to fix.

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

Added: 
llvm/test/tools/llvm-profdata/Inputs/FUnique.afdotext
llvm/test/tools/llvm-profdata/Inputs/FUnique.proftext
llvm/test/tools/llvm-profdata/Inputs/NoFUnique.afdotext
llvm/test/tools/llvm-profdata/Inputs/NoFUnique.proftext
llvm/test/tools/llvm-profdata/suppl-instr-with-sample-static-func.test

Modified: 
clang/lib/CodeGen/CodeGenModule.cpp
llvm/include/llvm/ProfileData/SampleProf.h
llvm/tools/llvm-profdata/llvm-profdata.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 62e906a87af48..bb0970e3e36fa 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -60,12 +60,12 @@
 #include "llvm/IR/Module.h"
 #include "llvm/IR/ProfileSummary.h"
 #include "llvm/ProfileData/InstrProfReader.h"
+#include "llvm/ProfileData/SampleProf.h"
 #include "llvm/Support/CRC.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/CommandLine.h"
 #include "llvm/Support/ConvertUTF.h"
 #include "llvm/Support/ErrorHandling.h"
-#include "llvm/Support/MD5.h"
 #include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/X86TargetParser.h"
 #include "llvm/Support/xxhash.h"
@@ -208,22 +208,7 @@ CodeGenModule::CodeGenModule(ASTContext &C,
 Path = Entry.second + Path.substr(Entry.first.size());
 break;
   }
-llvm::MD5 Md5;
-Md5.update(Path);
-llvm::MD5::MD5Result R;
-Md5.final(R);
-SmallString<32> Str;
-llvm::MD5::stringifyResult(R, Str);
-// Convert MD5hash to Decimal. Demangler suffixes can either contain
-// numbers or characters but not both.
-llvm::APInt IntHash(128, Str.str(), 16);
-// Prepend "__uniq" before the hash for tools like profilers to understand
-// that this symbol is of internal linkage type.  The "__uniq" is the
-// pre-determined prefix that is used to tell tools that this symbol was
-// created with -funique-internal-linakge-symbols and the tools can strip 
or
-// keep the prefix as needed.
-ModuleNameHash = (Twine(".__uniq.") +
-Twine(toString(IntHash, /* Radix = */ 10, /* Signed = */false))).str();
+ModuleNameHash = llvm::getUniqueInternalLinkagePostfix(Path);
   }
 }
 

diff  --git a/llvm/include/llvm/ProfileData/SampleProf.h 
b/llvm/include/llvm/ProfileData/SampleProf.h
index 1ad83c2f5b5af..a82b4544199fc 100644
--- a/llvm/include/llvm/ProfileData/SampleProf.h
+++ b/llvm/include/llvm/ProfileData/SampleProf.h
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/IR/Function.h"
@@ -1331,6 +1332,26 @@ template <> struct DenseMapInfo {
 return LHS == RHS;
   }
 };
+
+// Prepend "__uniq" before the hash for tools like profilers to understand
+// that this symbol is of internal linkage type.  The "__uniq" is the
+// pre-determined prefix that is used to tell tools that this symbol was
+// created with -funique-internal-linakge-symbols and the tools can strip or
+// keep the prefix as neede

Re: [PATCH] D72523: [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-14 Thread Rong Xu via cfe-commits
Thanks for reviewing this.

The new constructor is to avoid initializing the "OS" field (which is not
used by the empty BackendConsumer. Setting this field will affect the
output). I will add a comment there.

-Rong

On Mon, Jan 13, 2020 at 4:50 PM Teresa Johnson via Phabricator <
revi...@reviews.llvm.org> wrote:

> tejohnson accepted this revision.
> tejohnson added a comment.
> This revision is now accepted and ready to land.
>
> LGTM. One more request for a comment below that I forgot to add earlier.
>
>
>
> 
> Comment at: clang/lib/CodeGen/CodeGenAction.cpp:154
>  }
> +BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
> +const HeaderSearchOptions &HeaderSearchOpts,
> 
> Add comment as to what specific case this new constructor is for.
>
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D72523/new/
>
> https://reviews.llvm.org/D72523
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 60d3947 - [remark][diagnostics] Using clang diagnostic handler for IR input files

2020-01-14 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-01-14T15:44:57-08:00
New Revision: 60d39479221d6bc09060f7816bcd7c54eb286603

URL: 
https://github.com/llvm/llvm-project/commit/60d39479221d6bc09060f7816bcd7c54eb286603
DIFF: 
https://github.com/llvm/llvm-project/commit/60d39479221d6bc09060f7816bcd7c54eb286603.diff

LOG: [remark][diagnostics] Using clang diagnostic handler for IR input files

For IR input files, we currently use LLVM diagnostic handler even the
compilation is from clang. As a result, we are not able to use -Rpass
to get the transformation reports. Some warnings are not handled
properly either: We found many mysterious warnings in our ThinLTO backend
compilations in SamplePGO and CSPGO. An example of the warning:
"warning: net/proto2/public/metadata_lite.h:51:21: 0.02% (1 / 4999)"

This turns out to be a warning by Wmisexpect, which is supposed to be
filtered out by default. But since the filter is in clang's
diagnostic hander, we emit these incomplete warnings from LLVM's
diagnostic handler.

This patch uses clang diagnostic handler for IR input files. We create
a fake backendconsumer just to install the diagnostic handler.

With this change, we will have proper handling of all the warnings and we can
use -Rpass* options in IR input files compilation.
Also note that with is patch, LLVM's diagnostic options, like
"-mllvm -pass-remarks=*", are no longer be able to get optimization remarks.

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

Added: 
clang/test/CodeGen/Inputs/thinlto_expect1.proftext
clang/test/CodeGen/Inputs/thinlto_expect2.proftext
clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c

Modified: 
clang/lib/CodeGen/CodeGenAction.cpp
clang/test/CodeGen/thinlto-diagnostic-handler-remarks-with-hotness.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 7f3f358d3d98..7065e78f19a2 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -151,6 +151,29 @@ namespace clang {
   FrontendTimesIsEnabled = TimePasses;
   llvm::TimePassesIsEnabled = TimePasses;
 }
+
+// This constructor is used in installing an empty BackendConsumer
+// to use the clang diagnostic handler for IR input files. It avoids
+// initializing the OS field.
+BackendConsumer(BackendAction Action, DiagnosticsEngine &Diags,
+const HeaderSearchOptions &HeaderSearchOpts,
+const PreprocessorOptions &PPOpts,
+const CodeGenOptions &CodeGenOpts,
+const TargetOptions &TargetOpts,
+const LangOptions &LangOpts, bool TimePasses,
+SmallVector LinkModules, LLVMContext &C,
+CoverageSourceInfo *CoverageInfo = nullptr)
+: Diags(Diags), Action(Action), HeaderSearchOpts(HeaderSearchOpts),
+  CodeGenOpts(CodeGenOpts), TargetOpts(TargetOpts), LangOpts(LangOpts),
+  Context(nullptr),
+  LLVMIRGeneration("irgen", "LLVM IR Generation Time"),
+  LLVMIRGenerationRefCount(0),
+  Gen(CreateLLVMCodeGen(Diags, "", HeaderSearchOpts, PPOpts,
+CodeGenOpts, C, CoverageInfo)),
+  LinkModules(std::move(LinkModules)) {
+  FrontendTimesIsEnabled = TimePasses;
+  llvm::TimePassesIsEnabled = TimePasses;
+}
 llvm::Module *getModule() const { return Gen->GetModule(); }
 std::unique_ptr takeModule() {
   return std::unique_ptr(Gen->ReleaseModule());
@@ -616,10 +639,20 @@ void BackendConsumer::UnsupportedDiagHandler(
   StringRef Filename;
   unsigned Line, Column;
   bool BadDebugInfo = false;
-  FullSourceLoc Loc =
-  getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
+  FullSourceLoc Loc;
+  std::string Msg;
+  raw_string_ostream MsgStream(Msg);
 
-  Diags.Report(Loc, diag::err_fe_backend_unsupported) << D.getMessage().str();
+  // Context will be nullptr for IR input files, we will construct the diag
+  // message from llvm::DiagnosticInfoUnsupported.
+  if (Context != nullptr) {
+Loc = getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
+MsgStream << D.getMessage();
+  } else {
+DiagnosticPrinterRawOStream DP(MsgStream);
+D.print(DP);
+  }
+  Diags.Report(Loc, diag::err_fe_backend_unsupported) << MsgStream.str();
 
   if (BadDebugInfo)
 // If we were not able to translate the file:line:col information
@@ -635,10 +668,21 @@ void BackendConsumer::MisExpectDiagHandler(
   StringRef Filename;
   unsigned Line, Column;
   bool BadDebugInfo = false;
-  FullSourceLoc Loc =
-  getBestLocationFromDebugLoc(D, BadDebugInfo, Filename, Line, Column);
+  FullSourceLoc Loc;
+  std::string Msg;
+  raw_string_ostream MsgStream(Msg);
+  DiagnosticPrinterRawOStream DP(MsgStream);
 
-  Diags.Report(Loc, diag::warn_profile_data_misexpect) << D.getMsg

[clang] c9ee5e9 - Fix windows bot failures in c410adb092c9cb51ddb0b55862b70f2aa8c5b16f

2020-01-14 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-01-14T16:32:17-08:00
New Revision: c9ee5e996e3c89a751a35e8b771870e0ec24f3c0

URL: 
https://github.com/llvm/llvm-project/commit/c9ee5e996e3c89a751a35e8b771870e0ec24f3c0
DIFF: 
https://github.com/llvm/llvm-project/commit/c9ee5e996e3c89a751a35e8b771870e0ec24f3c0.diff

LOG: Fix windows bot failures in c410adb092c9cb51ddb0b55862b70f2aa8c5b16f
(clang diagnostic handler for IR input files)

Added: 


Modified: 
clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c

Removed: 




diff  --git a/clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c 
b/clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
index 3c410571a90b..389d24425cc4 100644
--- a/clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
+++ b/clang/test/CodeGen/thinlto-clang-diagnostic-handler-in-be.c
@@ -20,5 +20,5 @@ __attribute__((noinline)) void foo(int m) {
 bar();
 }
 // CHECK-REMARK: remark: {{.*}}.c:
-// CHECK-WARNING: warning: Potential performance regression from use of 
__builtin_expect(): Annotation was correct on {{.*}}.c:{{[0-9]*}}:26: 50.00% 
(12 / 24) of profiled executions.
+// CHECK-WARNING: warning: Potential performance regression from use of 
__builtin_expect(): Annotation was correct on {{.*}}.c:{{[0-9]*}}:{{[0-9]*}}: 
50.00% (12 / 24) of profiled executions.
 // CHECK-NOWARNING-NOT: warning: {{.*}}.c:{{[0-9]*}}:26: 50.00% (12 / 24)



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


[clang] 54e03d0 - [PGO] Verify BFI counts after loading profile data

2020-12-14 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-12-14T15:56:10-08:00
New Revision: 54e03d03a7a4d47f09d40bcbcfe484066a52a077

URL: 
https://github.com/llvm/llvm-project/commit/54e03d03a7a4d47f09d40bcbcfe484066a52a077
DIFF: 
https://github.com/llvm/llvm-project/commit/54e03d03a7a4d47f09d40bcbcfe484066a52a077.diff

LOG: [PGO] Verify BFI counts after loading profile data

This patch adds the functionality to compare BFI counts with real
profile
counts right after reading the profile. It will print remarks under
-Rpass-analysis=pgo, or the internal option -pass-remarks-analysis=pgo.

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

Added: 
llvm/test/Transforms/PGOProfile/Inputs/bfi_verification.proftext
llvm/test/Transforms/PGOProfile/bfi_verification.ll

Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 73194be922dd..ced287643c28 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1943,6 +1943,11 @@ void CodeGenModule::ConstructAttributeList(
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::Cold);
+if (TargetDecl->hasAttr()) {
+  // xur
+  fprintf(stderr, "hihi 2\n");
+  //  FuncAttrs.addAttribute(llvm::Attribute::Hot);
+}
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
 if (TargetDecl->hasAttr())

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 0bb9c91f2434..dec0cba84343 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1744,6 +1744,13 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
 }
+if (D->hasAttr()) {
+  if (!ShouldAddOptNone)
+B.addAttribute(llvm::Attribute::OptimizeForSize);
+  // xur
+  //  B.addAttribute(llvm::Attribute::Hot);
+  fprintf(stderr, "hihi 1\n");
+}
 
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::MinSize);

diff  --git a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp 
b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
index 0228c8a8ef14..eba8d9e9c3c3 100644
--- a/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ b/llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -252,6 +252,30 @@ static cl::opt PGOInstrumentEntry(
 "pgo-instrument-entry", cl::init(false), cl::Hidden,
 cl::desc("Force to instrument function entry basicblock."));
 
+static cl::opt PGOVerifyHotBFI(
+"pgo-verify-hot-bfi", cl::init(false), cl::Hidden,
+cl::desc("Print out the non-match BFI count if a hot raw profile count "
+ "becomes non-hot, or a cold raw profile count becomes hot. "
+ "The print is enabled under -Rpass-analysis=pgo, or "
+ "internal option -pass-remakrs-analysis=pgo."));
+
+static cl::opt PGOVerifyBFI(
+"pgo-verify-bfi", cl::init(false), cl::Hidden,
+cl::desc("Print out mismatched BFI counts after setting profile metadata "
+ "The print is enabled under -Rpass-analysis=pgo, or "
+ "internal option -pass-remakrs-analysis=pgo."));
+
+static cl::opt PGOVerifyBFIRatio(
+"pgo-verify-bfi-ratio", cl::init(5), cl::Hidden,
+cl::desc("Set the threshold for pgo-verify-big -- only print out "
+ "mismatched BFI if the 
diff erence percentage is greater than "
+ "this value (in percentage)."));
+
+static cl::opt PGOVerifyBFICutoff(
+"pgo-verify-bfi-cutoff", cl::init(1), cl::Hidden,
+cl::desc("Set the threshold for pgo-verify-bfi -- skip the counts whose "
+ "profile count value is below."));
+
 // Command line option to turn on CFG dot dump after profile annotation.
 // Defined in Analysis/BlockFrequencyInfo.cpp:  -pgo-view-counts
 extern cl::opt PGOViewCounts;
@@ -1616,6 +1640,82 @@ PreservedAnalyses PGOInstrumentationGen::run(Module &M,
   return PreservedAnalyses::none();
 }
 
+// Compare the profile count values with BFI count values, and print out
+// the non-matching ones.
+static void verifyFuncBFI(PGOUseFunc &Func, LoopInfo &LI,
+  BranchProbabilityInfo &NBPI,
+  uint64_t HotCountThreshold,
+  uint64_t ColdCountThreshold) {
+  Function &F = Func.getFunc();
+  BlockFrequencyInfo NBFI(F, NBPI, LI);
+  //  bool PrintFunc = false;
+  bool HotBBOnly = PGOVerifyHotBFI;
+  std::string Msg;
+  OptimizationRemarkEmitter ORE(&F);
+
+  unsigned BBNum = 0, BBMisMatchNum = 0, NonZeroBBNum = 0;
+  for (auto &BBI : F) {
+uint64_t CountValue = 

[clang] c36f31c - [PGO] remove unintentional code in early commit

2020-12-14 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-12-14T18:41:49-08:00
New Revision: c36f31c4db065e987160a776749f5da81efc24c5

URL: 
https://github.com/llvm/llvm-project/commit/c36f31c4db065e987160a776749f5da81efc24c5
DIFF: 
https://github.com/llvm/llvm-project/commit/c36f31c4db065e987160a776749f5da81efc24c5.diff

LOG: [PGO] remove unintentional code in early commit

Remove unintentional code in
commit 54e03d [PGO] Verify BFI counts after loading profile data.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index ced287643c28..73194be922dd 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1943,11 +1943,6 @@ void CodeGenModule::ConstructAttributeList(
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::Cold);
-if (TargetDecl->hasAttr()) {
-  // xur
-  fprintf(stderr, "hihi 2\n");
-  //  FuncAttrs.addAttribute(llvm::Attribute::Hot);
-}
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
 if (TargetDecl->hasAttr())

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index dec0cba84343..0bb9c91f2434 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1744,13 +1744,6 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
 }
-if (D->hasAttr()) {
-  if (!ShouldAddOptNone)
-B.addAttribute(llvm::Attribute::OptimizeForSize);
-  // xur
-  //  B.addAttribute(llvm::Attribute::Hot);
-  fprintf(stderr, "hihi 1\n");
-}
 
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::MinSize);



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


Re: [PATCH] D91813: [PGO] verify BFI counts after loading profile data

2020-12-14 Thread Rong Xu via cfe-commits
Thanks for catching that.
I messed up the commit from another patch.
Fixed in commit c36f31c.

-Rong

On Mon, Dec 14, 2020 at 4:50 PM dmajor via Phabricator <
revi...@reviews.llvm.org> wrote:

> dmajor added inline comments.
>
>
> 
> Comment at: clang/lib/CodeGen/CGCall.cpp:1948
> +  // xur
> +  fprintf(stderr, "hihi 2\n");
> +  //  FuncAttrs.addAttribute(llvm::Attribute::Hot);
> 
> This looks like something for temporary local debugging, was it
> intentional to commit it?
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D91813/new/
>
> https://reviews.llvm.org/D91813
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D90275: [clang][IR] Add support for leaf attribute

2020-12-16 Thread Rong Xu via cfe-commits
yes. Also #43 should be #42
I fixed it in
https://reviews.llvm.org/D92493
But that was just to make my test pass.

On Wed, Dec 16, 2020 at 11:35 AM Gulfem Savrun Yeniceri via Phabricator <
revi...@reviews.llvm.org> wrote:

> gulfem added a comment.
>
> > The problem in `llvm/test/Bitcode/attributes.ll` is clear?
>
> Instead of `define void @f70() nocallback`, it should be `define void
> @f69() nocallback`, right?
>
>
> Repository:
>   rG LLVM Github Monorepo
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D90275/new/
>
> https://reviews.llvm.org/D90275
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 3733463 - [IR][PGO] Add hot func attribute and use hot/cold attribute in func section

2020-12-17 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-12-17T18:41:12-08:00
New Revision: 3733463dbb58a29892be3872bd32f93cb9af492c

URL: 
https://github.com/llvm/llvm-project/commit/3733463dbb58a29892be3872bd32f93cb9af492c
DIFF: 
https://github.com/llvm/llvm-project/commit/3733463dbb58a29892be3872bd32f93cb9af492c.diff

LOG: [IR][PGO] Add hot func attribute and use hot/cold attribute in func section

Clang FE currently has hot/cold function attribute. But we only have
cold function attribute in LLVM IR.

This patch adds support of hot function attribute to LLVM IR.  This
attribute will be used in setting function section prefix/suffix.
Currently .hot and .unlikely suffix only are added in PGO (Sample PGO)
compilation (through isFunctionHotInCallGraph and
isFunctionColdInCallGraph).

This patch changes the behavior. The new behavior is:
(1) If the user annotates a function as hot or isFunctionHotInCallGraph
is true, this function will be marked as hot. Otherwise,
(2) If the user annotates a function as cold or
isFunctionColdInCallGraph is true, this function will be marked as
cold.

The changes are:
(1) user annotated function attribute will used in setting function
section prefix/suffix.
(2) hot attribute overwrites profile count based hotness.
(3) profile count based hotness overwrite user annotated cold attribute.

The intention for these changes is to provide the user a way to mark
certain function as hot in cases where training input is hard to cover
all the hot functions.

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

Added: 
llvm/test/CodeGen/X86/hot-unlikely-section-prefix.ll
llvm/test/MC/AsmParser/function_hot_attr.ll

Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/test/CodeGen/attributes.c
llvm/docs/LangRef.rst
llvm/include/llvm/Bitcode/LLVMBitCodes.h
llvm/include/llvm/IR/Attributes.td
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/lib/Bitcode/Writer/BitcodeWriter.cpp
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Verifier.cpp
llvm/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
llvm/test/Bitcode/attributes.ll

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index bfc7b8e74d8f..e28736bd3d2f 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -1944,6 +1944,8 @@ void CodeGenModule::ConstructAttributeList(
   FuncAttrs.addAttribute(llvm::Attribute::NoReturn);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::Cold);
+if (TargetDecl->hasAttr())
+  FuncAttrs.addAttribute(llvm::Attribute::Hot);
 if (TargetDecl->hasAttr())
   FuncAttrs.addAttribute(llvm::Attribute::NoDuplicate);
 if (TargetDecl->hasAttr())

diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index 7dd343dbcc16..93916e85a461 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -1744,7 +1744,8 @@ void 
CodeGenModule::SetLLVMFunctionAttributesForDefinition(const Decl *D,
 B.addAttribute(llvm::Attribute::OptimizeForSize);
   B.addAttribute(llvm::Attribute::Cold);
 }
-
+if (D->hasAttr())
+  B.addAttribute(llvm::Attribute::Hot);
 if (D->hasAttr())
   B.addAttribute(llvm::Attribute::MinSize);
   }

diff  --git a/clang/test/CodeGen/attributes.c b/clang/test/CodeGen/attributes.c
index 0c1455d3c612..5ef176c138af 100644
--- a/clang/test/CodeGen/attributes.c
+++ b/clang/test/CodeGen/attributes.c
@@ -63,6 +63,13 @@ void t72() { t71(); }
 // CHECK: call void @t71() [[COLDSITE:#[0-9]+]]
 // CHECK: declare void @t71() [[COLDDECL:#[0-9]+]]
 
+// CHECK: define void @t82() [[HOTDEF:#[0-9]+]] {
+void t81(void) __attribute__((hot));
+void t82() __attribute__((hot));
+void t82() { t81(); }
+// CHECK: call void @t81() [[HOTSITE:#[0-9]+]]
+// CHECK: declare void @t81() [[HOTDECL:#[0-9]+]]
+
 // CHECK: define void @t10() [[NUW]] section "xSECT" {
 void t10(void) __attribute__((section("xSECT")));
 void t10(void) {}
@@ -72,6 +79,9 @@ void __attribute__((section("xSECT"))) t11(void) {}
 // CHECK: define i32 @t19() [[NUW]] {
 extern int t19(void) __attribute__((weak_import));
 int t19(void) {
+// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
+// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
+// RUN: %clang_cc1 -emit-llvm -fcf-protection=branch -triple i386-linux-gnu -o 
%t %s
   return 10;
 }
 
@@ -111,6 +121,9 @@ void t24(f_t f1) {
 // CHECK: attributes [[NR]] = { noinline noreturn nounwind{{.*}} }
 // CHECK: attributes [[COLDDEF]] = { cold {{.*}}}
 // CHECK: attributes [[COLDDECL]] = { cold {{.*}}}
+// CHECK: attributes [[HOTDEF]] = { hot {{.*}}}
+// CHECK: attributes [[HOTDECL]] = { hot {{.*}}}
 // CHECK: attributes [[NOC

[clang] b7425e9 - [NFC] Fix typos

2021-08-16 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2021-08-16T10:15:30-07:00
New Revision: b7425e956be60a73004d7ae5bb37da85872c29fb

URL: 
https://github.com/llvm/llvm-project/commit/b7425e956be60a73004d7ae5bb37da85872c29fb
DIFF: 
https://github.com/llvm/llvm-project/commit/b7425e956be60a73004d7ae5bb37da85872c29fb.diff

LOG: [NFC] Fix typos

s/senstive/senstive/g

Added: 


Modified: 
clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
compiler-rt/test/profile/Linux/instrprof-cs.c
llvm/include/llvm/Transforms/Instrumentation.h
llvm/lib/ProfileData/SampleProfReader.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
index 175dfcef0df45..a13de306eac84 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCInstMethSignature.cpp
@@ -6,7 +6,7 @@
 //
 
//===--===//
 //
-//  This file defines a CheckObjCInstMethSignature, a flow-insenstive check
+//  This file defines a CheckObjCInstMethSignature, a flow-insensitive check
 //  that determines if an Objective-C class interface incorrectly redefines
 //  the method signature in a subclass.
 //

diff  --git a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
index 90c5583d89691..dcca8be55e337 100644
--- a/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/NSErrorChecker.cpp
@@ -6,7 +6,7 @@
 //
 
//===--===//
 //
-//  This file defines a CheckNSError, a flow-insenstive check
+//  This file defines a CheckNSError, a flow-insensitive check
 //  that determines if an Objective-C class interface correctly returns
 //  a non-void return type.
 //

diff  --git a/compiler-rt/test/profile/Linux/instrprof-cs.c 
b/compiler-rt/test/profile/Linux/instrprof-cs.c
index d825525a532db..0ad6f0350c560 100644
--- a/compiler-rt/test/profile/Linux/instrprof-cs.c
+++ b/compiler-rt/test/profile/Linux/instrprof-cs.c
@@ -8,7 +8,7 @@
 // RUN: %clang_profgen=%t.profraw -o %t.gen.cis -O2 %s
 // RUN: %run %t.gen.cis
 // RUN: llvm-profdata merge -o %t.cis.profdata %t.profraw
-// Check context insenstive profile
+// Check context insensitive profile
 // RUN: %clang_profuse=%t.cis.profdata  -O2 -emit-llvm -S %s -o - | FileCheck 
%s --check-prefix=CIS
 int g1 = 1;
 int volatile g2 = 2;

diff  --git a/llvm/include/llvm/Transforms/Instrumentation.h 
b/llvm/include/llvm/Transforms/Instrumentation.h
index 03108bacb0da5..0c822999aecf3 100644
--- a/llvm/include/llvm/Transforms/Instrumentation.h
+++ b/llvm/include/llvm/Transforms/Instrumentation.h
@@ -78,7 +78,7 @@ struct GCOVOptions {
 ModulePass *createGCOVProfilerPass(const GCOVOptions &Options =
GCOVOptions::getDefault());
 
-// PGO Instrumention. Parameter IsCS indicates if this is the context senstive
+// PGO Instrumention. Parameter IsCS indicates if this is the context sensitive
 // instrumentation.
 ModulePass *createPGOInstrumentationGenLegacyPass(bool IsCS = false);
 ModulePass *
@@ -138,7 +138,7 @@ struct InstrProfOptions {
 };
 
 /// Insert frontend instrumentation based profiling. Parameter IsCS indicates 
if
-// this is the context senstive instrumentation.
+// this is the context sensitive instrumentation.
 ModulePass *createInstrProfilingLegacyPass(
 const InstrProfOptions &Options = InstrProfOptions(), bool IsCS = false);
 

diff  --git a/llvm/lib/ProfileData/SampleProfReader.cpp 
b/llvm/lib/ProfileData/SampleProfReader.cpp
index 6058eddb13dc7..a801ca1ef36d7 100644
--- a/llvm/lib/ProfileData/SampleProfReader.cpp
+++ b/llvm/lib/ProfileData/SampleProfReader.cpp
@@ -53,7 +53,7 @@ using namespace sampleprof;
 // For ext-binary format profiles, the flag is set in the summary.
 static cl::opt ProfileIsFSDisciminator(
 "profile-isfs", cl::Hidden, cl::init(false),
-cl::desc("Profile uses flow senstive discriminators"));
+cl::desc("Profile uses flow sensitive discriminators"));
 
 /// Dump the function profile for \p FName.
 ///



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


[clang] 5fdaaf7 - [SampleFDO] Flow Sensitive Sample FDO (FSAFDO) profile loader

2021-08-18 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2021-08-18T18:37:35-07:00
New Revision: 5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4

URL: 
https://github.com/llvm/llvm-project/commit/5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4
DIFF: 
https://github.com/llvm/llvm-project/commit/5fdaaf7fd8f35ac9c9de50a45b09e29c7b0d48c4.diff

LOG: [SampleFDO] Flow Sensitive Sample FDO (FSAFDO) profile loader

This patch implements Flow Sensitive Sample FDO (FSAFDO) profile
loader. We have two profile loaders for FS profile,
one before RegAlloc and one before BlockPlacement.

To enable it, when -fprofile-sample-use= is specified,
add "-enable-fs-discriminator=true \
 -disable-ra-fsprofile-loader=false \
 -disable-layout-fsprofile-loader=false"
to turn on the FS profile loaders.

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

Added: 
llvm/include/llvm/CodeGen/MIRSampleProfile.h
llvm/include/llvm/Support/PGOOptions.h
llvm/lib/CodeGen/MIRSampleProfile.cpp
llvm/test/CodeGen/X86/Inputs/fsloader.afdo

Modified: 
clang/lib/CodeGen/BackendUtil.cpp
llvm/include/llvm/CodeGen/MachineDominators.h
llvm/include/llvm/CodeGen/MachineOptimizationRemarkEmitter.h
llvm/include/llvm/CodeGen/Passes.h
llvm/include/llvm/IR/DebugInfoMetadata.h
llvm/include/llvm/InitializePasses.h
llvm/include/llvm/Passes/PassBuilder.h
llvm/include/llvm/Target/TargetMachine.h
llvm/include/llvm/Transforms/Utils/SampleProfileLoaderBaseImpl.h
llvm/lib/CodeGen/CMakeLists.txt
llvm/lib/CodeGen/TargetPassConfig.cpp
llvm/lib/LTO/LTOBackend.cpp
llvm/lib/Transforms/IPO/SampleProfile.cpp
llvm/test/CodeGen/X86/fsafdo_test2.ll
llvm/tools/opt/NewPMDriver.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index 9e4e40a36e056..404d2680fac35 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -1261,6 +1261,8 @@ void EmitAssemblyHelper::EmitAssemblyWithNewPassManager(
   "", PGOOptions::NoAction, PGOOptions::CSIRInstr,
   CodeGenOpts.DebugInfoForProfiling);
   }
+  if (TM)
+TM->setPGOOption(PGOOpt);
 
   PipelineTuningOptions PTO;
   PTO.LoopUnrolling = CodeGenOpts.UnrollLoops;

diff  --git a/llvm/include/llvm/CodeGen/MIRSampleProfile.h 
b/llvm/include/llvm/CodeGen/MIRSampleProfile.h
new file mode 100644
index 0..7872daf3a54c6
--- /dev/null
+++ b/llvm/include/llvm/CodeGen/MIRSampleProfile.h
@@ -0,0 +1,81 @@
+//===- MIRSampleProfile.h: SampleFDO Support in MIR ---*- c++ 
-*---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file contains the supoorting functions for machine level Sample FDO
+// loader. This is used in Flow Sensitive SampelFDO.
+//
+//===--===//
+
+#ifndef LLVM_CODEGEN_MIRSAMPLEPROFILE_H
+#define LLVM_CODEGEN_MIRSAMPLEPROFILE_H
+
+#include "llvm/Analysis/ProfileSummaryInfo.h"
+#include "llvm/CodeGen/MachineBasicBlock.h"
+#include "llvm/CodeGen/MachineBlockFrequencyInfo.h"
+#include "llvm/CodeGen/MachineBranchProbabilityInfo.h"
+#include "llvm/CodeGen/MachineDominators.h"
+#include "llvm/CodeGen/MachineFunction.h"
+#include "llvm/CodeGen/MachineFunctionPass.h"
+#include "llvm/CodeGen/MachineInstr.h"
+#include "llvm/CodeGen/MachineLoopInfo.h"
+#include "llvm/CodeGen/MachineOptimizationRemarkEmitter.h"
+#include "llvm/CodeGen/MachinePostDominators.h"
+#include "llvm/CodeGen/Passes.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/InitializePasses.h"
+#include "llvm/ProfileData/InstrProf.h"
+#include "llvm/ProfileData/SampleProf.h"
+#include "llvm/ProfileData/SampleProfReader.h"
+
+#include 
+
+namespace llvm {
+
+using namespace sampleprof;
+
+class MIRProfileLoader;
+class MIRProfileLoaderPass : public MachineFunctionPass {
+  MachineFunction *MF;
+  std::string ProfileFileName;
+  FSDiscriminatorPass P;
+  unsigned LowBit;
+  unsigned HighBit;
+
+public:
+  static char ID;
+  /// FS bits will only use the '1' bits in the Mask.
+  MIRProfileLoaderPass(std::string FileName = "",
+   std::string RemappingFileName = "",
+   FSDiscriminatorPass P = FSDiscriminatorPass::Pass1)
+  : MachineFunctionPass(ID), ProfileFileName(FileName), P(P),
+MIRSampleLoader(
+std::make_unique(FileName, RemappingFileName)) {
+LowBit = getFSPassBitBegin(P);
+HighBit = getFSPassBitEnd(P);
+assert(LowBit < HighBit && "HighBit needs to be greater than Lowbit");
+  }
+
+  /// getMachineFunction - Return the last machine function c

[clang] 6cee539 - [Clang] Change AnonStructIds in MangleContext to per-function based

2022-10-23 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2022-10-23T22:33:52-07:00
New Revision: 6cee5393371fdde798605c88bad0ebceb3626257

URL: 
https://github.com/llvm/llvm-project/commit/6cee5393371fdde798605c88bad0ebceb3626257
DIFF: 
https://github.com/llvm/llvm-project/commit/6cee5393371fdde798605c88bad0ebceb3626257.diff

LOG: [Clang] Change AnonStructIds in MangleContext to per-function based

Clang is generating different mangled names for the same lambda
function in slightly changed builds (like with non-related
source/Macro change). This is due to the fact that clang uses a
cross-translation-unit sequential string "$_" in lambda's
mangled name. Here, "n" is the AnonStructIds field in MangleContext.

Different mangled names for a unchanged function is undesirable:
it makes perf comparison harder, and can cause some unnecessary
profile mismatch in SampleFDO.

This patch makes mangled name for lambda functions more stable
by changing AnonStructIds to a per-function based seq number if the
DeclContext is a function.

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

Added: 


Modified: 
clang/include/clang/AST/Mangle.h
clang/lib/AST/ItaniumMangle.cpp
clang/test/CodeGen/attr-function-return.cpp
clang/test/CodeGenCXX/catch-undef-behavior.cpp
clang/test/CodeGenCXX/cxx1y-init-captures-eh.cpp
clang/test/CodeGenCXX/cxx1y-init-captures.cpp
clang/test/CodeGenCXX/lambda-expressions-nested-linkage.cpp
clang/test/CodeGenCXX/lambda-expressions.cpp
clang/test/CodeGenCXX/mangle-lambdas.cpp
clang/test/CodeGenCXX/nrvo.cpp
clang/test/CodeGenObjCXX/arc-forwarded-lambda-call.mm
clang/test/CodeGenObjCXX/block-nested-in-lambda.mm
clang/test/CodeGenObjCXX/lambda-expressions.mm
clang/test/CodeGenObjCXX/property-lvalue-lambda.mm

Removed: 




diff  --git a/clang/include/clang/AST/Mangle.h 
b/clang/include/clang/AST/Mangle.h
index 96cc8c90a8e83..a22ed5ab72405 100644
--- a/clang/include/clang/AST/Mangle.h
+++ b/clang/include/clang/AST/Mangle.h
@@ -61,6 +61,7 @@ class MangleContext {
   llvm::DenseMap GlobalBlockIds;
   llvm::DenseMap LocalBlockIds;
   llvm::DenseMap AnonStructIds;
+  llvm::DenseMap FuncAnonStructSize;
 
 public:
   ManglerKind getKind() const { return Kind; }
@@ -87,9 +88,17 @@ class MangleContext {
 return Result.first->second;
   }
 
-  uint64_t getAnonymousStructId(const NamedDecl *D) {
+  uint64_t getAnonymousStructId(const NamedDecl *D,
+const FunctionDecl *FD = nullptr) {
+auto FindResult = AnonStructIds.find(D);
+if (FindResult != AnonStructIds.end())
+  return FindResult->second;
+
+// If FunctionDecl is passed in, the anonymous structID will be 
per-function
+// based.
+unsigned Id = FD ? FuncAnonStructSize[FD]++ : AnonStructIds.size();
 std::pair::iterator, bool>
-Result = AnonStructIds.insert(std::make_pair(D, AnonStructIds.size()));
+Result = AnonStructIds.insert(std::make_pair(D, Id));
 return Result.first->second;
   }
 

diff  --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 46229a0843ef1..dbd9bb518d8b9 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -1588,7 +1588,9 @@ void CXXNameMangler::mangleUnqualifiedName(
 
 // Get a unique id for the anonymous struct. If it is not a real output
 // ID doesn't matter so use fake one.
-unsigned AnonStructId = NullOut ? 0 : Context.getAnonymousStructId(TD);
+unsigned AnonStructId =
+NullOut ? 0
+: Context.getAnonymousStructId(TD, dyn_cast(DC));
 
 // Mangle it as a source name in the form
 // [n] $_

diff  --git a/clang/test/CodeGen/attr-function-return.cpp 
b/clang/test/CodeGen/attr-function-return.cpp
index 47ef1a74cbb69..75cecc99ad490 100644
--- a/clang/test/CodeGen/attr-function-return.cpp
+++ b/clang/test/CodeGen/attr-function-return.cpp
@@ -15,14 +15,14 @@ int foo(void) {
   }();
 }
 int bar(void) {
-  // CHECK: @"_ZZ3barvENK3$_1clEv"({{.*}}) [[EXTERN:#[0-9]+]]
+  // CHECK: @"_ZZ3barvENK3$_0clEv"({{.*}}) [[EXTERN:#[0-9]+]]
   return []() __attribute__((function_return("thunk-extern"))) {
 return 42;
   }
   ();
 }
 int baz(void) {
-  // CHECK: @"_ZZ3bazvENK3$_2clEv"({{.*}}) [[KEEP:#[0-9]+]]
+  // CHECK: @"_ZZ3bazvENK3$_0clEv"({{.*}}) [[KEEP:#[0-9]+]]
   return []() __attribute__((function_return("keep"))) {
 return 42;
   }

diff  --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp 
b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
index 9869b1a862526..44ad39c7c8118 100644
--- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp
+++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -735,7 +735,7 @@ namespace CopyValueRepresentation {
 }
 
 void ThisAlign::this_align_lambda_2() {
-  // CHECK-LABEL: define internal void 
@"_ZZN9ThisAlign19this_align_lambda_2EvENK3$_1clEv"
+  // CHECK-LABEL: define internal void 
@"_ZZN9ThisAlign19thi

Re: [PATCH] D74878: [remark][diagnostics] [codegen] Fix PR44896

2020-02-21 Thread Rong Xu via cfe-commits
OK. I will add  a warning but not turn it off at the CodeGenOpt (but it
will not pass to LLVMContext). I will update the patch shortly.

On Fri, Feb 21, 2020 at 1:53 AM serge via Phabricator <
revi...@reviews.llvm.org> wrote:

> serge-sans-paille added a comment.
>
> Let's go that way then. @xur I leave it to you to add the appropriate
> warning at least on the clang side? Feel free to just use the code from
> https://reviews.llvm.org/D74871?id=245594.
>
>
> CHANGES SINCE LAST ACTION
>   https://reviews.llvm.org/D74878/new/
>
> https://reviews.llvm.org/D74878
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 11857d4 - [remark][diagnostics] [codegen] Fix PR44896

2020-02-25 Thread Rong Xu via cfe-commits

Author: Rong Xu
Date: 2020-02-25T08:15:17-08:00
New Revision: 11857d49948b845dcfd7c7f78595095e3add012d

URL: 
https://github.com/llvm/llvm-project/commit/11857d49948b845dcfd7c7f78595095e3add012d
DIFF: 
https://github.com/llvm/llvm-project/commit/11857d49948b845dcfd7c7f78595095e3add012d.diff

LOG: [remark][diagnostics] [codegen] Fix PR44896

This patch fixes PR44896. For IR input files, option fdiscard-value-names
should be ignored as we need named values in loadModule().
Commit 60d3947922 sets this option after loadModule() where valued names
already created. This creates an inconsistent state in setNameImpl()
that leads to a seg fault.
This patch forces fdiscard-value-names to be false for IR input files.

This patch also emits a warning of "ignoring -fdiscard-value-names" if
option fdiscard-value-names is explictly enabled in the commandline for
IR input files.

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

Added: 
clang/test/CodeGen/PR44896.ll

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/Driver/ToolChains/Clang.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index ecd871e36ee8..48ece91d3c45 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -271,6 +271,9 @@ def warn_drv_unsupported_debug_info_opt_for_target : 
Warning<
   InGroup;
 def warn_c_kext : Warning<
   "ignoring -fapple-kext which is valid for C++ and Objective-C++ only">;
+def warn_ignoring_fdiscard_for_bitcode : Warning<
+  "ignoring -fdiscard-value-names for LLVM Bitcode">,
+  InGroup;
 def warn_drv_input_file_unused : Warning<
   "%0: '%1' input unused%select{ when '%3' is present|}2">,
   InGroup;

diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 5ebc34cd2700..81946b194495 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1146,6 +1146,9 @@ void CodeGenAction::ExecuteAction() {
CI.getTargetOpts(), CI.getLangOpts(),
CI.getFrontendOpts().ShowTimers,
std::move(LinkModules), *VMContext, nullptr);
+// PR44896: Force DiscardValueNames as false. DiscardValueNames cannot be
+// true here because the valued names are needed for reading textual IR.
+Ctx.setDiscardValueNames(false);
 Ctx.setDiagnosticHandler(
 std::make_unique(CodeGenOpts, &Result));
 

diff  --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 19a23c9de5b3..d387a1dc2079 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -4332,8 +4332,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
-   options::OPT_fno_discard_value_names, !IsAssertBuild))
+   options::OPT_fno_discard_value_names, !IsAssertBuild)) {
+if (Args.hasArg(options::OPT_fdiscard_value_names) &&
+(std::any_of(Inputs.begin(), Inputs.end(),
+ [](const clang::driver::InputInfo &II) {
+   return types::isLLVMIR(II.getType());
+ }))) {
+  D.Diag(diag::warn_ignoring_fdiscard_for_bitcode);
+}
 CmdArgs.push_back("-discard-value-names");
+  }
 
   // Set the main file name, so that debug info works even with
   // -save-temps.

diff  --git a/clang/test/CodeGen/PR44896.ll b/clang/test/CodeGen/PR44896.ll
new file mode 100644
index ..a4d344579870
--- /dev/null
+++ b/clang/test/CodeGen/PR44896.ll
@@ -0,0 +1,15 @@
+; RUN: %clang -fdiscard-value-names -S %s -o /dev/null 2>&1 | FileCheck 
--check-prefix=WARNING %s
+; RUN: %clang -S %s -o /dev/null 2>&1 | FileCheck --check-prefix=NOWARNING %s
+; RUN: %clang_cc1 -S -emit-llvm %s -discard-value-names -o /dev/null
+; PR 44896
+
+; WARNING: ignoring -fdiscard-value-names for LLVM Bitcode
+; NOWARNING-NOT: ignoring -fdiscard-value-names for LLVM Bitcode
+
+target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64--linux-gnu"
+
+define linkonce i8* @b(i8* %a) {
+  ret i8* %a
+}
+



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


r259811 - [PGO] cc1 option name change for profile instrumentation

2016-02-04 Thread Rong Xu via cfe-commits
Author: xur
Date: Thu Feb  4 12:39:09 2016
New Revision: 259811

URL: http://llvm.org/viewvc/llvm-project?rev=259811&view=rev
Log:
[PGO] cc1 option name change for profile instrumentation

This patch changes cc1 option -fprofile-instr-generate to an enum option
-fprofile-instrument={clang|none}. It also changes cc1 options
-fprofile-instr-generate= to -fprofile-instrument-path=.
The driver level option -fprofile-instr-generate and -fprofile-instr-generate=
remain intact. This change will pave the way to integrate new PGO
instrumentation in IR level.

Review: http://reviews.llvm.org/D16730

Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CGStmt.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.cpp
cfe/trunk/lib/CodeGen/CodeGenFunction.h
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CoverageMapping/block-storage-starts-region.m
cfe/trunk/test/CoverageMapping/break.c
cfe/trunk/test/CoverageMapping/builtinmacro.c
cfe/trunk/test/CoverageMapping/casts.c
cfe/trunk/test/CoverageMapping/classtemplate.cpp
cfe/trunk/test/CoverageMapping/comment-in-macro.c
cfe/trunk/test/CoverageMapping/continue.c
cfe/trunk/test/CoverageMapping/control-flow-macro.c
cfe/trunk/test/CoverageMapping/decl.c
cfe/trunk/test/CoverageMapping/header.cpp
cfe/trunk/test/CoverageMapping/if.c
cfe/trunk/test/CoverageMapping/implicit-def-in-macro.m
cfe/trunk/test/CoverageMapping/includehell.cpp
cfe/trunk/test/CoverageMapping/ir.c
cfe/trunk/test/CoverageMapping/label.cpp
cfe/trunk/test/CoverageMapping/lambda.cpp
cfe/trunk/test/CoverageMapping/logical.cpp
cfe/trunk/test/CoverageMapping/loopmacro.c
cfe/trunk/test/CoverageMapping/loops.cpp
cfe/trunk/test/CoverageMapping/macro-expansion.c
cfe/trunk/test/CoverageMapping/macro-expressions.cpp
cfe/trunk/test/CoverageMapping/macroception.c
cfe/trunk/test/CoverageMapping/macroparams.c
cfe/trunk/test/CoverageMapping/macroparams2.c
cfe/trunk/test/CoverageMapping/macros.c
cfe/trunk/test/CoverageMapping/macroscopes.cpp
cfe/trunk/test/CoverageMapping/md.cpp
cfe/trunk/test/CoverageMapping/moremacros.c
cfe/trunk/test/CoverageMapping/nestedclass.cpp
cfe/trunk/test/CoverageMapping/objc.m
cfe/trunk/test/CoverageMapping/preprocessor.c
cfe/trunk/test/CoverageMapping/return.c
cfe/trunk/test/CoverageMapping/switch.c
cfe/trunk/test/CoverageMapping/switchmacro.c
cfe/trunk/test/CoverageMapping/system_macro.c
cfe/trunk/test/CoverageMapping/templates.cpp
cfe/trunk/test/CoverageMapping/test.c
cfe/trunk/test/CoverageMapping/trycatch.cpp
cfe/trunk/test/CoverageMapping/trymacro.cpp
cfe/trunk/test/CoverageMapping/unreachable-macro.c
cfe/trunk/test/CoverageMapping/unused_names.c
cfe/trunk/test/CoverageMapping/while.c
cfe/trunk/test/Driver/clang_f_opts.c
cfe/trunk/test/Profile/c-captured.c
cfe/trunk/test/Profile/c-general.c
cfe/trunk/test/Profile/c-generate.c
cfe/trunk/test/Profile/c-indirect-call.c
cfe/trunk/test/Profile/c-linkage-available_externally.c
cfe/trunk/test/Profile/c-linkage.c
cfe/trunk/test/Profile/c-unreachable-after-switch.c
cfe/trunk/test/Profile/cxx-implicit.cpp
cfe/trunk/test/Profile/cxx-lambda.cpp
cfe/trunk/test/Profile/cxx-linkage.cpp
cfe/trunk/test/Profile/cxx-rangefor.cpp
cfe/trunk/test/Profile/cxx-structors.cpp
cfe/trunk/test/Profile/cxx-templates.cpp
cfe/trunk/test/Profile/cxx-virtual-destructor-calls.cpp
cfe/trunk/test/Profile/objc-general.m

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=259811&r1=259810&r2=259811&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Thu Feb  4 12:39:09 
2016
@@ -27,6 +27,8 @@ def err_drv_invalid_thread_model_for_tar
   "invalid thread model '%0' in '%1' for this target">;
 def err_drv_invalid_linker_name : Error<
   "invalid linker name in argument '%0'">;
+def err_drv_invalid_pgo_instrumentor: Error<
+  "invalid PGO instrumentor in argument '%0'">;
 def err_drv_invalid_rtlib_name : Error<
   "invalid runtime library name in argument '%0'">;
 def err_drv_unsupported_rtlib_for_platform : Error<

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=259811&r1=259810&r2=259811&view=diff
===

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-04 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 46960.
xur added a comment.

Now http://reviews.llvm.org/D16730 has been committed (as r259811)

Here is the patch that adds cc1 option -fprofile-instrument=llvm to enable IR 
level PGO generate and use.

The pgo use part of the patch depends http://reviews.llvm.org/D15540 which 
differentiates the IR level and clang profiles. To detect the profile 
automatically, we need to first the profile. It can either done in driver or in 
Clang codegen (lib/CodeGen/CodeGenModule.cpp). If we do this in Clang codegen, 
we would have to change the Codegen option which does not seem to be a good 
approach. As a result, we do this in the driver in this patch.

Again like in http://reviews.llvm.org/D16730, this patch won't change any 
driver (user level) options. Only cc1 options are touched.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- test/CodeGen/pgo-instrumentation.c
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,28 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-GEN
+// CHECK-PGOGENPASS-INVOKED-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=clang -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-instr-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
+// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is not invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestclang.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=clang -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
+// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
Index: test/CodeGen/Inputs/pgotestir.profraw
===
--- test/CodeGen/Inputs/pgotestir.profraw
+++ test/CodeGen/Inputs/pgotestir.profraw
@@ -0,0 +1 @@
+:ir
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -478,14 +478,18 @@
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
 
-  enum PGOInstrumentor { Unknown, None, Clang };
+  enum PGOInstrumentor { Unknown, None, Clang, LLVM };
   if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
 StringRef Value = A->getValue();
 PGOInstrumentor Method = llvm::StringSwitch(Value)
- .Case("clang", Clang)
  .Case("none", None)
+ .Case("clang", Clang)
+ .Case("llvm", LLVM)
  .Default(Unknown);
 switch (Method) {
+case LLVM:
+  Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+  break;
 case Clang:
   Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
   break;
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Dr

r260116 - Fix missing space (NFC)

2016-02-08 Thread Rong Xu via cfe-commits
Author: xur
Date: Mon Feb  8 12:12:41 2016
New Revision: 260116

URL: http://llvm.org/viewvc/llvm-project?rev=260116&view=rev
Log:
Fix missing space (NFC)

Fixed the inconsistently placed : (missing space) introduced in in r259811.




Modified:
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Driver/CC1Options.td

Modified: cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td?rev=260116&r1=260115&r2=260116&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td Mon Feb  8 12:12:41 
2016
@@ -27,7 +27,7 @@ def err_drv_invalid_thread_model_for_tar
   "invalid thread model '%0' in '%1' for this target">;
 def err_drv_invalid_linker_name : Error<
   "invalid linker name in argument '%0'">;
-def err_drv_invalid_pgo_instrumentor: Error<
+def err_drv_invalid_pgo_instrumentor : Error<
   "invalid PGO instrumentor in argument '%0'">;
 def err_drv_invalid_rtlib_name : Error<
   "invalid runtime library name in argument '%0'">;

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=260116&r1=260115&r2=260116&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Feb  8 12:12:41 2016
@@ -270,10 +270,10 @@ def fsanitize_coverage_trace_cmp
 def fsanitize_coverage_8bit_counters
 : Flag<["-"], "fsanitize-coverage-8bit-counters">,
   HelpText<"Enable frequency counters in sanitizer coverage">;
-def fprofile_instrument_EQ: Joined<["-"], "fprofile-instrument=">,
+def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
 HelpText<"Enable PGO instrumentation. The accepted values is clang or "
  "none">;
-def fprofile_instrument_path_EQ: Joined<["-"], "fprofile-instrument-path=">,
+def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
 


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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-08 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 47251.
xur marked an inline comment as done.
xur added a comment.

fixed the typo in comments


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -478,14 +478,18 @@
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
 
-  enum PGOInstrumentor { Unknown, None, Clang };
+  enum PGOInstrumentor { Unknown, None, Clang, LLVM };
   if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
 StringRef Value = A->getValue();
 PGOInstrumentor Method = llvm::StringSwitch(Value)
- .Case("clang", Clang)
  .Case("none", None)
+ .Case("clang", Clang)
+ .Case("llvm", LLVM)
  .Default(Unknown);
 switch (Method) {
+case LLVM:
+  Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+  break;
 case Clang:
   Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
   break;
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -3196,6 +3197,18 @@
   return VersionTuple();
 }
 
+// Set the profile kind if it's not the default clang kind.
+static void setProfileKindFlag(ArgStringList &CmdArgs,
+   std::string ProfileName) {
+  auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
+  if (ReaderOrErr.getError())
+return;
+  std::unique_ptr PGOReader =
+std::move(ReaderOrErr.get());
+  if (PGOReader->isIRLevelProfile())
+CmdArgs.push_back("-fprofile-instrument=llvm");
+}
+
 static void addPGOAndCoverageFlags(Compilation &C, const Driver &D,
const InputInfo &Output, const ArgList &Args,
ArgStringList &CmdArgs) {
@@ -3238,8 +3251,10 @@
   }
 
   if (ProfileUseArg) {
-if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ))
+if (ProfileUseArg->getOption().matches(options::OPT_fprofile_instr_use_EQ)) {
   ProfileUseArg->render(Args, CmdArgs);
+  setProfileKindFlag(CmdArgs, ProfileUseArg->getValue());
+}
 else if ((ProfileUseArg->getOption().matches(
   options::OPT_fprofile_use_EQ) ||
   ProfileUseArg->getOption().matches(
@@ -3250,6 +3265,7 @@
 llvm::sys::path::append(Path, "default.profdata");
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-fprofile-instr-use=") + Path));
+  setProfileKindFlag(CmdArgs, Path.str().str());
 }
   }
 
Index: lib/Driver/CMakeLists.txt
===
--- lib/Driver/CMakeLists.txt
+++ lib/Driver/CMakeLists.txt
@@ -1,6 +1,7 @@
 set(LLVM_LINK_COMPONENTS
   Option
   Support
+  ProfileData
   )
 
 add_clang_library(clangDriver
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -147,7 +147,8 @@
   if (C.getLangOpts().ObjC1)
 ObjCData = new ObjCEntrypoints();
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.hasProfileIRInstr() &&
+  !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =
 llvm::IndexedInstrProfReader::create(CodeGenOpts.InstrProfileInput);
 if (std::error_code EC = ReaderOrErr.getError()) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -434,6 +434,13 @@
 Options.NoRedZone = CodeGenOpts.DisableRedZone;
 Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
 MPM->add(createInstrProfilingPass(Options));
+  } else if (CodeGenOpts.hasProfileIRInstr()) {
+if (!CodeGenOpts.InstrProfileInput.empty())
+  PMBuilder.PGOInstrUse = CodeGenOpts.InstrProfileInput;
+else if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
   }
 
   if (!CodeGenOpts.SampleProfileFile.empty())
Index: include/clang/Frontend/CodeGenOption

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-09 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 47331.
xur added a comment.

Ping

(also added the test that missed from last upload).

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/CMakeLists.txt
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- test/CodeGen/pgo-instrumentation.c
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,28 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-GEN
+// CHECK-PGOGENPASS-INVOKED-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=clang -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-instr-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
+// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestir.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is not invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotestclang.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=clang -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
+// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
Index: test/CodeGen/Inputs/pgotestir.profraw
===
--- test/CodeGen/Inputs/pgotestir.profraw
+++ test/CodeGen/Inputs/pgotestir.profraw
@@ -0,0 +1 @@
+:ir
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -478,14 +478,18 @@
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
 
-  enum PGOInstrumentor { Unknown, None, Clang };
+  enum PGOInstrumentor { Unknown, None, Clang, LLVM };
   if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
 StringRef Value = A->getValue();
 PGOInstrumentor Method = llvm::StringSwitch(Value)
- .Case("clang", Clang)
  .Case("none", None)
+ .Case("clang", Clang)
+ .Case("llvm", LLVM)
  .Default(Unknown);
 switch (Method) {
+case LLVM:
+  Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+  break;
 case Clang:
   Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
   break;
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -32,6 +32,7 @@
 #include "llvm/Option/Arg.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/Option.h"
+#include "llvm/ProfileData/InstrProfReader.h"
 #include "llvm/Support/CodeGen.h"
 #include "llvm/Support/Compression.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -3196,6 +3197,18 @@
   return VersionTuple();
 }
 
+// Set the profile kind if it's not the default clang kind.
+static void setProfileKindFlag(ArgStringList &CmdArgs,
+   std::string ProfileName) {
+  auto ReaderOrErr = llvm::IndexedInstrProfReader::create(ProfileName);
+  if (ReaderOrErr.getError())
+return;
+  std::unique_ptr PGOReader =
+std::move(ReaderOrErr.get(

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-22 Thread Rong Xu via cfe-commits
xur marked an inline comment as done.
xur added a comment.

I'll send a revised patch soon.



Comment at: lib/CodeGen/CodeGenModule.cpp:150
@@ -149,2 +149,3 @@
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.hasProfileIRInstr() &&
+  !CodeGenOpts.InstrProfileInput.empty()) {

davidxl wrote:
> Better to use if (CodeGenOpts.hasProfileClangInstr() && ..)
OK. That would require to insert an extra cc1 option of 
-profile-instrument=clang for profile-use. And possibly some test case option 
changes too.


Comment at: lib/Driver/Tools.cpp:3201
@@ +3200,3 @@
+// Set the profile kind if it's not the default clang kind.
+static void setProfileKindFlag(ArgStringList &CmdArgs,
+   std::string ProfileName) {

davidxl wrote:
> I don't quite like this change in the driver. I think the right thing to do 
> is:
> 
> 1) for profile use case, there is no need to pass -fprofile-instrument=<...> 
> FE option from the driver
> 2) The profileInstrKind determination needs to happen in FE (not driver) by 
> peeking into the passed in profile data.
I'll split off the profile kind detection to a separated patch suggested by 
Sean.


Comment at: test/CodeGen/pgo-instrumentation.c:4
@@ +3,3 @@
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=llvm 
-fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass

silvas wrote:
> Use `%clang_cc1` here and elsewhere.
Will do.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-23 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 48846.
xur marked an inline comment as done.
xur added a comment.

Here is the new patch that removes the auto detection of profile kind.

In this patch, I replace the CC1 option of -fprofile-instr-use=<> with 
-fprofile-instrument={llvm-use|clang-use}. For the use compilation, the profile 
reuses the -fprofile-instrument-path= option.

Again, all changes are of CC1 options. Driver options are intact.

Some test are modified due to the -fprofile-instr-use= option change.

A new test is added to test IR profile compilation. 
test/CodeGen/pgo-instrumentation.c


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-path=%t.nonexistent.profdata -fprofile-instrument=clang-use 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-23 Thread Rong Xu via cfe-commits
xur marked 4 inline comments as done.


Comment at: lib/CodeGen/CodeGenModule.cpp:151
@@ -151,1 +150,3 @@
+  if (CodeGenOpts.hasProfileClangUse() &&
+  !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =

davidxl wrote:
> Is the second condition still needed? Should it be asserted ?
The second condition is not needed. I'll change the code in the coming patch.


Comment at: test/CodeGen/pgo-instrumentation.c:4
@@ +3,3 @@
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang-cc1 -O2 -fprofile-instrument=llvm %s -mllvm 
-debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s 
-check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass

davidxl wrote:
> should be %clang_cc1
I think both %clang_cc1 and %clang-cc1 are accepted. But all the other tests 
are using %clang_cc1. I'll change.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-23 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 48859.
xur marked 2 inline comments as done.
xur added a comment.

Integrated with David's comments.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-path=%t.nonexistent.profdata -fprofile-instrument=clang-use 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=PGOUSE %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=LMBUSE %s
 
Index: test/Profile/c-unprofiled.c
==

[PATCH] D17622: [PGO] clang cc1 option change to enable IR level instrumenation

2016-02-25 Thread Rong Xu via cfe-commits
xur created this revision.
xur added reviewers: davidxl, silvas, justinruggles.
xur added subscribers: cfe-commits, xur, mcrosier, davidxl, slingn.

This patch expands cc1 option -fprofile-instrument= with three new values:
(1) -fprofile-instrument=llvm
This enables IR PGO instrumentation.
(2) -fprofile-instrument=llvm-use
This enables PGO use compilation using IR level profiles. The profile is 
specified by -fprofile-instrument-path= (cc1) option.
(3) -fprofile-instrument=clang-use
This enables PGO use compilation using clang profiles. This replaces current 
cc1 option -fprofile-instr-use=. The profile is specified by 
-fprofile-instrument-path= (cc1) option.

Some tests are modified due to the -fprofile-instr-use= option change.
A new test is added to test IR profile compilation.
test/CodeGen/pgo-instrumentation.c

Original discussion is in http://reviews.llvm.org/D15829.

http://reviews.llvm.org/D17622

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-path=%t.nonexistent.profdata -fprofile-instrument=clang-use 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-path=%t.profdata -fprofile-instrument=clang-use > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profil

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-25 Thread Rong Xu via cfe-commits
Create a new review here:
http://reviews.llvm.org/D17622

Thanks,

-Rong

On Wed, Feb 24, 2016 at 9:22 PM, Sean Silva  wrote:
> silvas added a comment.
>
> In http://reviews.llvm.org/D15829#360006, @xur wrote:
>
>> Here is the new patch that removes the auto detection of profile kind.
>>
>> In this patch, I replace the CC1 option of -fprofile-instr-use=<> with 
>> -fprofile-instrument={llvm-use|clang-use}. For the use compilation, the 
>> profile reuses the -fprofile-instrument-path= option.
>>
>> Again, all changes are of CC1 options. Driver options are intact.
>>
>> Some test are modified due to the -fprofile-instr-use= option change.
>>
>> A new test is added to test IR profile compilation.
>>  test/CodeGen/pgo-instrumentation.c
>
>
> I meant in a new phabricator review. This one is has gone on for too long and 
> is convoluted and hard to follow. (lots of stray inline comments etc.)
>
>
> http://reviews.llvm.org/D15829
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-02-25 Thread Rong Xu via cfe-commits
xur added a comment.

Create a new review here:
http://reviews.llvm.org/D17622

Thanks,

-Rong


http://reviews.llvm.org/D15829



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


[PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-03-30 Thread Rong Xu via cfe-commits
xur created this revision.
xur added reviewers: davidxl, bogner, joker.eph.
xur added subscribers: cfe-commits, vsk, xur.

Write out the PGOFuncName meta data if PGOFuncName is different from function's 
raw name. This should only apply to internal linkage functions. This is to be 
consumed by indirect-call promotion when called in LTO optimization passes 
(D17864 under review).

This patch depends on http://reviews.llvm.org/D18623.


http://reviews.llvm.org/D18624

Files:
  lib/CodeGen/CodeGenPGO.cpp

Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -787,6 +787,11 @@
 (llvm::InstrProfValueKind)ValueKind,
 NumValueSites[ValueKind]);
 
+// Write out PGOFuncName meta data.
+llvm::Function *F = ValueSite->getFunction();
+if (!llvm::getPGOFuncNameMetaData(*F))
+  llvm::createPGOFuncNameMetaData(*F);
+
 NumValueSites[ValueKind]++;
   }
 }


Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -787,6 +787,11 @@
 (llvm::InstrProfValueKind)ValueKind,
 NumValueSites[ValueKind]);
 
+// Write out PGOFuncName meta data.
+llvm::Function *F = ValueSite->getFunction();
+if (!llvm::getPGOFuncNameMetaData(*F))
+  llvm::createPGOFuncNameMetaData(*F);
+
 NumValueSites[ValueKind]++;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-03-30 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 52134.
xur added a comment.

sync the change in http://reviews.llvm.org/D18623.


http://reviews.llvm.org/D18624

Files:
  lib/CodeGen/CodeGenPGO.cpp

Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -787,6 +787,11 @@
 (llvm::InstrProfValueKind)ValueKind,
 NumValueSites[ValueKind]);
 
+// Create PGOFuncName meta data.
+llvm::Function *F = ValueSite->getFunction();
+if (!llvm::getPGOFuncNameMetadata(*F))
+  llvm::createPGOFuncNameMetadata(*F);
+
 NumValueSites[ValueKind]++;
   }
 }


Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -787,6 +787,11 @@
 (llvm::InstrProfValueKind)ValueKind,
 NumValueSites[ValueKind]);
 
+// Create PGOFuncName meta data.
+llvm::Function *F = ValueSite->getFunction();
+if (!llvm::getPGOFuncNameMetadata(*F))
+  llvm::createPGOFuncNameMetadata(*F);
+
 NumValueSites[ValueKind]++;
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-19 Thread Rong Xu via cfe-commits
xur added a comment.

I did not test Clang based instrumentation with SPEC. I will try it with
povray today.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-19 Thread Rong Xu via cfe-commits
I did not test Clang based instrumentation with SPEC. I will try it with
povray today.

On Tue, Apr 19, 2016 at 9:40 AM, Adam Nemet  wrote:

> anemet added a comment.
>
> As discussed under http://reviews.llvm.org/D17864, I did a run with this
> and I don't get the indirect call promoted that calls static functions in
> povray.   I will dig more but do I need to pass some extra flag?
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-19 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 54275.
xur added a comment.

Previous patch was bad (as David noticed) -- we might not annotate all the 
functions that we interested.

This updated patch should work.

BTW, I got the following promotions for 453.provay:

LLVM gold plugin: csg.cpp:157:15: Promote indirect call to 
_ZN3povL23All_Plane_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 1654869 out of 1695169
LLVM gold plugin: csg.cpp:157:15: Promote indirect call to 
_ZN3povL31All_CSG_Intersect_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 40300 out of 40300
LLVM gold plugin: csg.cpp:252:11: Promote indirect call to 
_ZN3povL24All_Sphere_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 72389427 out of 132687016
LLVM gold plugin: csg.cpp:252:11: Promote indirect call to 
_ZN3povL23All_Plane_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 44987633 out of 60297589
LLVM gold plugin: lighting.cpp:828:11: Promote indirect call to 
_ZN3povL31All_CSG_Intersect_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 271222 out of 581624
LLVM gold plugin: lighting.cpp:828:11: Promote indirect call to 
_ZN3povL27All_Ellipsoid_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 220561 out of 310402
LLVM gold plugin: objects.cpp:111:7: Promote indirect call to 
_ZN3povL31All_CSG_Intersect_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 14382553 out of 16537858
LLVM gold plugin: objects.cpp:111:7: Promote indirect call to 
_ZN3povL23All_Plane_IntersectionsEPNS_13Object_StructEPNS_10Ray_StructEPNS_13istack_structE
 with count 1489615 out of 2155305
LLVM gold plugin: objects.cpp:175:11: Promote indirect call to 
_ZN3povL12Inside_PlaneEPdPNS_13Object_StructE with count 50136636 out of 
70129039
LLVM gold plugin: objects.cpp:175:11: Promote indirect call to 
_ZN3povL14Inside_QuadricEPdPNS_13Object_StructE with count 16280600 out of 
19992403
LLVM gold plugin: render.cpp:3579:9: Promote indirect call to 
_ZN3povL23Inside_CSG_IntersectionEPdPNS_13Object_StructE with count 4065174 out 
of 4516860
LLVM gold plugin: render.cpp:3579:9: Promote indirect call to 
_ZN3povL12Inside_PlaneEPdPNS_13Object_StructE with count 451686 out of 451686
LLVM gold plugin: spec_qsort.cpp:38:14: Promote indirect call to 
_ZN3povL9compboxesEPvS0_ with count 9339 out of 9339
LLVM gold plugin: textstreambuffer.cpp:278:4: Promote indirect call to 
_ZN12pov_frontend21DefaultRenderFrontend19DefaultStreamBuffer12directoutputEPKcj
 with count 9922 out of 9924
LLVM gold plugin: textstreambuffer.cpp:237:4: Promote indirect call to 
_ZN12pov_frontend21DefaultRenderFrontend19DefaultStreamBuffer10lineoutputEPKcj 
with count 9922 out of 9924

Adam: Could you try again?

Thanks,

-Rong


http://reviews.llvm.org/D18624

Files:
  lib/CodeGen/CodeGenPGO.cpp

Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -43,6 +43,9 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  if (!llvm::getPGOFuncNameMetadata(*Fn))
+llvm::createPGOFuncNameMetadata(*Fn);
 }
 
 namespace {


Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -43,6 +43,9 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  if (!llvm::getPGOFuncNameMetadata(*Fn))
+llvm::createPGOFuncNameMetadata(*Fn);
 }
 
 namespace {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
the reason for splitting the check is we don't need this check at all in
llvm instrument,-- as it's done per function. but I guess it does not
matter much to move it in to create -- it's only called once per function.





On Wed, Apr 20, 2016 at 3:04 PM, David Li  wrote:

> davidxl added inline comments.
>
> 
> Comment at: lib/CodeGen/CodeGenPGO.cpp:47
> @@ +46,3 @@
> +  // Create PGOFuncName meta data.
> +  if (!llvm::getPGOFuncNameMetadata(*Fn))
> +llvm::createPGOFuncNameMetadata(*Fn);
> 
> This check be folded into the creator. The creator interface name also
> needs to be changed properly (created when needed)
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
xur added a comment.

the reason for splitting the check is we don't need this check at all in
llvm instrument,-- as it's done per function. but I guess it does not
matter much to move it in to create -- it's only called once per function.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
these two patches work fine in my build. My llvm was on top ov r265491. The
opt remarks in the last email were emitted by the compiler.

I'll try to reproduce with r266465.


On Apr 20, 2016 4:00 PM, "Adam Nemet"  wrote:

> anemet added a comment.
>
> Still does not to work.  The metadata has the full path for the file while
> the prof data only has the filename.
>
> FTR, I applied this and the ICP patch on top of r266465.
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-20 Thread Rong Xu via cfe-commits
xur added a comment.

these two patches work fine in my build. My llvm was on top ov r265491. The
opt remarks in the last email were emitted by the compiler.

I'll try to reproduce with r266465.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-21 Thread Rong Xu via cfe-commits
I tried D17864 and D18624 with the latest trunk of r267006 on a clean
client.
The built compiler works fine with povray.

the meta data only has the files name.

How did you build povray?
can you show me your command line in building (for example, csg.cpp) for
both--fprofile-instr-use and -fprofile-instr-generate?


On Wed, Apr 20, 2016 at 4:41 PM, Adam Nemet  wrote:

> anemet added a comment.
>
> Rong, do you have full paths or just the filename?
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-21 Thread Rong Xu via cfe-commits
xur added a comment.

I tried http://reviews.llvm.org/D17864 and http://reviews.llvm.org/D18624 with 
the latest trunk of r267006 on a clean
client.
The built compiler works fine with povray.

the meta data only has the files name.

How did you build povray?
can you show me your command line in building (for example, csg.cpp) for
both--fprofile-instr-use and -fprofile-instr-generate?


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-21 Thread Rong Xu via cfe-commits
I was using spec-run where the command line has the pathless filename.

The source in Atam's command-line has the absolute path.
In meta-data creation, we used Module's getSourceFileName() which has the
source name appeared in the command line (in this case, a full patch name).

While in Clang's setFuncName, it uses CGM.getCodeGenOpts().MainFileName.
This string strips the path from the source.

I can expand function createPGOFuncNameMetadata() to handle this (I mean
using the stripped name).

But I need to point out that stripping the patch may not a good idea as it
greatly increases the change name conflicts:
If we have
static bar() in dir1/foo.c
and
static bar() in dir2/foo.c

if the user compiler with:
> clang ... dir1/foo.c
> clang ... dir2/foo.c
With Clang's scheme, both functions would have PGOFuncName of foo.c:bar().
In IR instrumentation, we will have different name in this case:
dir1/foo.c:bar(), and dir2/foo.c:bar()

Of course, if the user compiles the code the following way:
> cd dir1; clang foo.c
>cd ../dir2; clang foo.c
we will have conflict for both instrumentation.
In this case, we can suggestion the user to have the relative path in the
build line.



On Thu, Apr 21, 2016 at 11:23 AM, Adam Nemet  wrote:

> anemet added a comment.
>
> > How did you build povray?
>
> >  can you show me your command line in building (for example, csg.cpp) for
>
> >  both--fprofile-instr-use and -fprofile-instr-generate?
>
>
> Sent it in an email.
>
>
> http://reviews.llvm.org/D18624
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-21 Thread Rong Xu via cfe-commits
xur added a comment.

I was using spec-run where the command line has the pathless filename.

The source in Atam's command-line has the absolute path.
In meta-data creation, we used Module's getSourceFileName() which has the
source name appeared in the command line (in this case, a full patch name).

While in Clang's setFuncName, it uses CGM.getCodeGenOpts().MainFileName.
This string strips the path from the source.

I can expand function createPGOFuncNameMetadata() to handle this (I mean
using the stripped name).

But I need to point out that stripping the patch may not a good idea as it
greatly increases the change name conflicts:
If we have
static bar() in dir1/foo.c
and
static bar() in dir2/foo.c

if the user compiler with:

> clang ... dir1/foo.c

>  clang ... dir2/foo.c


With Clang's scheme, both functions would have PGOFuncName of foo.c:bar().
In IR instrumentation, we will have different name in this case:
dir1/foo.c:bar(), and dir2/foo.c:bar()

Of course, if the user compiles the code the following way:

> cd dir1; clang foo.c

> cd ../dir2; clang foo.c


we will have conflict for both instrumentation.
In this case, we can suggestion the user to have the relative path in the
build line.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-22 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 54717.
xur added a comment.

Handling the path-stripped prefix in PGOFuncName.

This new patch depends on http://reviews.llvm.org/D19433


http://reviews.llvm.org/D18624

Files:
  CodeGenPGO.cpp

Index: CodeGenPGO.cpp
===
--- CodeGenPGO.cpp
+++ CodeGenPGO.cpp
@@ -43,6 +43,8 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  llvm::createPGOFuncNameMetadata(*Fn, FuncName);
 }
 
 namespace {


Index: CodeGenPGO.cpp
===
--- CodeGenPGO.cpp
+++ CodeGenPGO.cpp
@@ -43,6 +43,8 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  llvm::createPGOFuncNameMetadata(*Fn, FuncName);
 }
 
 namespace {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-22 Thread Rong Xu via cfe-commits
xur added a comment.

tested with povray with full path names  in the command line and it works fine.


http://reviews.llvm.org/D18624



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


Re: [PATCH] D18624: [PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name.

2016-04-22 Thread Rong Xu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL267224: PGO] PGOFuncName meta data if PGOFuncName is 
different from function's raw name (authored by xur).

Changed prior to commit:
  http://reviews.llvm.org/D18624?vs=54717&id=54725#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D18624

Files:
  cfe/trunk/lib/CodeGen/CodeGenPGO.cpp

Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -43,6 +43,8 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  llvm::createPGOFuncNameMetadata(*Fn, FuncName);
 }
 
 namespace {


Index: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
===
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
@@ -43,6 +43,8 @@
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  llvm::createPGOFuncNameMetadata(*Fn, FuncName);
 }
 
 namespace {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r267224 - PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name

2016-04-22 Thread Rong Xu via cfe-commits
Author: xur
Date: Fri Apr 22 16:19:05 2016
New Revision: 267224

URL: http://llvm.org/viewvc/llvm-project?rev=267224&view=rev
Log:
PGO] PGOFuncName meta data if PGOFuncName is different from function's raw name

Write out the PGOFuncName meta data if PGOFuncName is different from function's
raw name. This should only apply to internal linkage functions. This is to be
consumed by indirect-call promotion when called in LTO optimization pass.

Differential Revision: http://reviews.llvm.org/D18624

Modified:
cfe/trunk/lib/CodeGen/CodeGenPGO.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=267224&r1=267223&r2=267224&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Apr 22 16:19:05 2016
@@ -43,6 +43,8 @@ void CodeGenPGO::setFuncName(StringRef N
 
 void CodeGenPGO::setFuncName(llvm::Function *Fn) {
   setFuncName(Fn->getName(), Fn->getLinkage());
+  // Create PGOFuncName meta data.
+  llvm::createPGOFuncNameMetadata(*Fn, FuncName);
 }
 
 namespace {


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


Re: [PATCH] D21823: [Driver] Add flags for enabling both types of PGO Instrumentation

2016-06-29 Thread Rong Xu via cfe-commits
xur added a comment.

Thanks for doing this. I like the patch in general.  Hers are my minor 
feedbacks:
(1) It seems the original options of -fprofile-instr-generate and 
-fprofile-instr-use will be kept. Is so, what is the guideline to use these two 
sets of options. Also, we need some documentations for the new user-visible
options.
(2) One difference b/w -fprofile-instr-generate/-fprofile-instr-use and the new 
options is -fpgo-train={source-cfg | optimizer-cfg} can coexist with 
-fpgo-apply=. I don't think they work as intended in current 
implementation. I would suggest to not allow it.
(3) I would request a driver option to specify the profile name. While  
LLVM_PROFILE_FILE environment variable can do that, a command line option is 
gonna be useful (at least in our setup).

-Rong


Repository:
  rL LLVM

http://reviews.llvm.org/D21823



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


Re: [PATCH] D17622: [PGO] clang cc1 option change to enable IR level instrumenation

2016-02-26 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 49243.
xur added a comment.

Sean, Thanks for the review and suggestions.

Here is the patch that only adds -fprofile-instrument=llvm.

I'll have another patch using your suggestion on cc1 options for profile use 
compilation.


http://reviews.llvm.org/D17622

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- test/CodeGen/pgo-instrumentation.c
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,9 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -481,18 +481,23 @@
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
 
-  enum PGOInstrumentor { Unknown, None, Clang };
+  enum PGOInstrumentor { Unknown, None, Clang, LLVM };
   if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
 StringRef Value = A->getValue();
 PGOInstrumentor Method = llvm::StringSwitch(Value)
- .Case("clang", Clang)
  .Case("none", None)
+ .Case("clang", Clang)
+ .Case("llvm", LLVM)
  .Default(Unknown);
 switch (Method) {
+case LLVM:
+  Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+  break;
 case Clang:
   Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
   break;
 case None:
+  // Null operation -- The default is ProfileNone.
   break;
 case Unknown:
   Diags.Report(diag::err_drv_invalid_pgo_instrumentor)
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -437,6 +437,12 @@
 Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
 MPM->add(createInstrProfilingPass(Options));
   }
+  if (CodeGenOpts.hasProfileIRInstr()) {
+if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
+  }
 
   if (!CodeGenOpts.SampleProfileFile.empty())
 MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
Index: include/clang/Frontend/CodeGenOptions.h
===
--- include/clang/Frontend/CodeGenOptions.h
+++ include/clang/Frontend/CodeGenOptions.h
@@ -80,9 +80,10 @@
   };
 
   enum ProfileInstrKind {
-ProfileNoInstr,// No instrumentation.
-ProfileClangInstr  // Clang instrumentation to generate execution counts
+ProfileNone,   // Profile instrumentation is turned off.
+ProfileClangInstr, // Clang instrumentation to generate execution counts
// to use with PGO.
+ProfileIRInstr,// IR level PGO instrumentation in LLVM.
   };
 
   /// The code model to use (-mcmodel).
@@ -226,6 +227,11 @@
   bool hasProfileClangInstr() const {
 return getProfileInstr() == ProfileClangInstr;
   }
+
+  /// \brief Check if IR level profile instrumentation is on.
+  bool hasProfileIRInstr() const {
+return getProfileInstr() == ProfileIRInstr;
+  }
 };
 
 }  // end namespace clang
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -104,7 +104,7 @@
 VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
 
 /// \brief Choose profile instrumenation kind or no instrumentation.
-ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNoInstr)
+ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0

Re: [PATCH] D17622: [PGO] clang cc1 option change to enable IR level instrumenation

2016-02-29 Thread Rong Xu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262239: [PGO] clang cc1 option change to enable IR level 
instrumentation (authored by xur).

Changed prior to commit:
  http://reviews.llvm.org/D17622?vs=49243&id=49394#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17622

Files:
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/include/clang/Frontend/CodeGenOptions.h
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/pgo-instrumentation.c

Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def
@@ -104,7 +104,7 @@
 VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is specified.
 
 /// \brief Choose profile instrumenation kind or no instrumentation.
-ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNoInstr)
+ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h
@@ -80,9 +80,10 @@
   };
 
   enum ProfileInstrKind {
-ProfileNoInstr,// No instrumentation.
-ProfileClangInstr  // Clang instrumentation to generate execution counts
+ProfileNone,   // Profile instrumentation is turned off.
+ProfileClangInstr, // Clang instrumentation to generate execution counts
// to use with PGO.
+ProfileIRInstr,// IR level PGO instrumentation in LLVM.
   };
 
   /// The code model to use (-mcmodel).
@@ -226,6 +227,11 @@
   bool hasProfileClangInstr() const {
 return getProfileInstr() == ProfileClangInstr;
   }
+
+  /// \brief Check if IR level profile instrumentation is on.
+  bool hasProfileIRInstr() const {
+return getProfileInstr() == ProfileIRInstr;
+  }
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -274,8 +274,8 @@
 : Flag<["-"], "fsanitize-coverage-trace-pc">,
   HelpText<"Enable PC tracing in sanitizer coverage">;
 def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
-HelpText<"Enable PGO instrumentation. The accepted values is clang or "
- "none">;
+HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, "
+ "or none">;
 def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
Index: cfe/trunk/test/CodeGen/pgo-instrumentation.c
===
--- cfe/trunk/test/CodeGen/pgo-instrumentation.c
+++ cfe/trunk/test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,9 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=llvm %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang_cc1 -O2 -fprofile-instrument=clang %s -mllvm -debug-pass=Structure -emit-llvm -o - 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
Index: cfe/trunk/lib/CodeGen/BackendUtil.cpp
===
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp
@@ -437,6 +437,12 @@
 Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
 MPM->add(createInstrProfilingPass(Options));
   }
+  if (CodeGenOpts.hasProfileIRInstr()) {
+if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
+  }
 
   if (!CodeGenOpts.SampleProfileFile.empty())
 MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
Index: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
===
--- cfe/trunk/lib/Frontend/CompilerInvoca

r262239 - [PGO] clang cc1 option change to enable IR level instrumentation

2016-02-29 Thread Rong Xu via cfe-commits
Author: xur
Date: Mon Feb 29 12:54:59 2016
New Revision: 262239

URL: http://llvm.org/viewvc/llvm-project?rev=262239&view=rev
Log:
[PGO] clang cc1 option change to enable IR level instrumentation

This patch expands cc1 option -fprofile-instrument= with a new value: 
-fprofile-instrument=llvm
which enables IR level PGO instrumentation.

Reviewers: davidxl, silvas

Differential Revision: http://reviews.llvm.org/D17622

Added:
cfe/trunk/test/CodeGen/pgo-instrumentation.c
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=262239&r1=262238&r2=262239&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Mon Feb 29 12:54:59 2016
@@ -274,8 +274,8 @@ def fsanitize_coverage_trace_pc
 : Flag<["-"], "fsanitize-coverage-trace-pc">,
   HelpText<"Enable PC tracing in sanitizer coverage">;
 def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
-HelpText<"Enable PGO instrumentation. The accepted values is clang or "
- "none">;
+HelpText<"Enable PGO instrumentation. The accepted value is clang, llvm, "
+ "or none">;
 def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=262239&r1=262238&r2=262239&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Mon Feb 29 12:54:59 2016
@@ -104,7 +104,7 @@ VALUE_CODEGENOPT(OptimizationLevel, 2, 0
 VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///< If -Os (==1) or -Oz (==2) is 
specified.
 
 /// \brief Choose profile instrumenation kind or no instrumentation.
-ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNoInstr)
+ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=262239&r1=262238&r2=262239&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h Mon Feb 29 12:54:59 2016
@@ -80,9 +80,10 @@ public:
   };
 
   enum ProfileInstrKind {
-ProfileNoInstr,// No instrumentation.
-ProfileClangInstr  // Clang instrumentation to generate execution counts
+ProfileNone,   // Profile instrumentation is turned off.
+ProfileClangInstr, // Clang instrumentation to generate execution counts
// to use with PGO.
+ProfileIRInstr,// IR level PGO instrumentation in LLVM.
   };
 
   /// The code model to use (-mcmodel).
@@ -226,6 +227,11 @@ public:
   bool hasProfileClangInstr() const {
 return getProfileInstr() == ProfileClangInstr;
   }
+
+  /// \brief Check if IR level profile instrumentation is on.
+  bool hasProfileIRInstr() const {
+return getProfileInstr() == ProfileIRInstr;
+  }
 };
 
 }  // end namespace clang

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=262239&r1=262238&r2=262239&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Feb 29 12:54:59 2016
@@ -437,6 +437,12 @@ void EmitAssemblyHelper::CreatePasses(Fu
 Options.InstrProfileOutput = CodeGenOpts.InstrProfileOutput;
 MPM->add(createInstrProfilingPass(Options));
   }
+  if (CodeGenOpts.hasProfileIRInstr()) {
+if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
+  }
 
   if (!CodeGenOpts.SampleProfileFile.empty())
 MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));

Modified: cfe/trunk/lib/Frontend/CompilerInvocation.cpp
URL: 
http://llvm.org/viewvc

[PATCH] D17737: [PGO] change profile use cc1 option

2016-02-29 Thread Rong Xu via cfe-commits
xur created this revision.
xur added reviewers: davidxl, silvas, bogner.
xur added subscribers: davidxl, xur, cfe-commits.

This patch takes the suggestion by Sean Silva in 
https://reviews.llvm.org/D17622 to decouple cc1 option from driver level option.

-fprofile-instr-use={} is now a driver only option. The cc1 part is replaced by 
-fprofile-instrument-use={llvm,clang}.
It sets a CodeGenOpt `ProfileUse` which is either {None, Clang, LLVM}, a common 
enum for -fprofile-instrument={} (for the profile instrument).

The profile path cc1 option now becomes -fprofile-instrument-usepath={}.

http://reviews.llvm.org/D17737

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-usepath=%t.nonexistent.profdata -fprofile-instrument-use=clang 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-usepath=%t.profdata -fprofile-instrument-use=clang | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-usepath=%t.profdata -fprofile-instrument-use=clang > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-usepath=%t.profdata -fprofile-instrument-use=clang > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-

Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-02-29 Thread Rong Xu via cfe-commits
xur marked 4 inline comments as done.


Comment at: lib/Frontend/CompilerInvocation.cpp:378
@@ -377,1 +377,3 @@
 
+enum PGOInstrumentor { ProfileUnknown, ProfileNone, ProfileClang, ProfileLLVM 
};
+static PGOInstrumentor getPGOInstrumentor(StringRef S) {

silvas wrote:
> Can we reuse the enum used for CodeGenOpts? Please add a comment if not.
this is a very good suggestion. I'll change the code as you suggested.


Comment at: lib/Frontend/CompilerInvocation.cpp:533
@@ +532,3 @@
+  Args.getLastArgValue(OPT_fprofile_instrument_path_EQ);
+  Opts.InstrProfileInput =
+  Args.getLastArgValue(OPT_fprofile_instrument_usepath_EQ);

silvas wrote:
> Maybe consider renaming these variables in a separate patch. The current 
> naming is pretty confusing since it makes it seems like InstrProfileOutput 
> mirrors InstrProfileInput, but they are totally unrelated. Maybe 
> `InstrProfileDefaultProfrawPath` and `InstrProfileUsePath`, respectively.
> 
> Maybe in this patch rename `InstrProfileInput` to `ProfileInstrumentUsePath` 
> to match the option name?
Will change the name InstrProfileInput to ProfileInstrumentUsePath in this path.

I will change Opts.InstrProfileOutput to InstrProfileDefaultProfrawPath in a 
separated patch.


http://reviews.llvm.org/D17737



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


Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-02-29 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 49444.
xur marked 2 inline comments as done.
xur added a comment.

Integrated Sean's review suggestions.

-Rong


http://reviews.llvm.org/D17737

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata -fprofile-instrument-use=clang 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use-path=%t.profdata -fprofile-instrument-use=clang | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -fprofile-instrument-use=clang > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -fprofile-instrument-use=clang > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata -fprofile-instrument-use=clang > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=PGOUSE %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=LMBUSE %s
 
Index: test/Profile/c-unprofiled.c
===

Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-03-01 Thread Rong Xu via cfe-commits
xur marked an inline comment as done.


Comment at: lib/CodeGen/CodeGenModule.cpp:154
@@ +153,3 @@
+assert(!CodeGenOpts.ProfileInstrumentUsePath.empty() &&
+   "Need to explicitly specify the profile name.");
+auto ReaderOrErr = llvm::IndexedInstrProfReader::create(

silvas wrote:
> Are we ensuring consistency in the driver? If not, we definitely want to do 
> that.
I think in driver level, the change change is consistent with the old behavior: 
driver will always set option -fprofile-instrument-use-path= for the pgo use 
compilation,
i.e. when -fprofile-instru-use{=} or -fprofile-use{=} is in the 
command line, we will always have -fprofile-instrument-use-path=,
It will be translated to CodeGenOpts.ProfileInstrumentUsePath in 
ParseCodeGenArgs(). 

In the cc1 level, the behavior changed: old behavior is:
-fprofile-instru-use= will trigger the use compilation.
Now requires two cc1 opitons:
-fprofile-instrument=clang -fprofile-instrument-use-path=.
Having -fprofile-instrument=clang only will trigger the assertion and
having -fprofile-instrument-use-path= is vold op.
I did this because the old pgo use cc1 option requires the profile path.

This is contrast in the IR level instrument, where 
-fprofile-instrument-use-path= is optional: we will use default.profdata 
in the absence.




Comment at: lib/Frontend/CompilerInvocation.cpp:381
@@ +380,3 @@
+   OptSpecifier Id, DiagnosticsEngine &Diags) {
+  if (Id != OPT_fprofile_instrument_EQ && Id != OPT_fprofile_instrument_use_EQ)
+return;

silvas wrote:
> I think it would be better to assert that it is one of the two options rather 
> than silently doing nothing.
Yes. Assertion is better. Will do in the commit.


http://reviews.llvm.org/D17737



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


Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-03-02 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 49647.
xur marked an inline comment as done.
xur added a comment.

I think David's suggestion to use one cc1 option -fprofile-instrument-use-path 
is a very good idea.
I update the patch to get rid of -fprofille-instrument-use.

The profile kind is now set by checking the profile header. I use a separated 
function (instead of using the overloaded name of setPGOInstrumentor()).

The assertion in lib/CodeGen/CodeGenModule.cpp:153 might not be needed. As 
Profilekind CodeGenOpts is getting from CodeGenOpts.ProfileInstrumentUsePath, 
so it should not be empty. But I keep it just in case.


http://reviews.llvm.org/D17737

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CMakeLists.txt
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use-path=%t.profdata | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use

Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-03-02 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 49655.
xur added a comment.

Integrated with Sean's review comments.

-Rong


http://reviews.llvm.org/D17737

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CMakeLists.txt
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotestclang.profraw
  test/CodeGen/Inputs/pgotestir.profraw
  test/CodeGen/pgo-instrumentation.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-counter-overflows.c
  test/Profile/c-general.c
  test/Profile/c-outdated-data.c
  test/Profile/c-unprofiled-blocks.c
  test/Profile/c-unprofiled.c
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/objc-general.m
  test/Profile/profile-does-not-exist.c

Index: test/Profile/profile-does-not-exist.c
===
--- test/Profile/profile-does-not-exist.c
+++ test/Profile/profile-does-not-exist.c
@@ -1,4 +1,4 @@
-// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instr-use=%t.nonexistent.profdata 2>&1 | FileCheck %s
+// RUN: not %clang_cc1 -emit-llvm %s -o - -fprofile-instrument-use-path=%t.nonexistent.profdata 2>&1 | FileCheck %s
 
 // CHECK: error: Could not read profile {{.*}}.nonexistent.profdata:
 // CHECK-NOT: Assertion failed
Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -3,7 +3,7 @@
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument-use-path=%t.profdata | FileCheck -check-prefix=PGOUSE %s
 
 #ifdef HAVE_FOUNDATION
 
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -6,7 +6,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=T100GEN -check-prefix=ALL %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-templates.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=T0USE -check-prefix=ALL %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=T100USE -check-prefix=ALL %s
 
Index: test/Profile/cxx-rangefor.cpp
===
--- test/Profile/cxx-rangefor.cpp
+++ test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=CHECK -check-prefix=PGOUSE %s
 
 // PGOGEN: @[[RFC:__profc__Z9range_forv]] = private global [5 x i64] zeroinitializer
Index: test/Profile/cxx-lambda.cpp
===
--- test/Profile/cxx-lambda.cpp
+++ test/Profile/cxx-lambda.cpp
@@ -5,7 +5,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=LMBGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-lambda.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-lambda.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument-use-path=%t.profdata > %tuse
 // RUN: FileCheck --input-file=%tuse -check-prefix=PGOUSE %s
 // RUN: FileCheck --input-file=%tuse -check-prefix=LMBUSE %s
 
Index: test/Profile/c-unprofiled.c
===
--- test/Profile/c-unprofiled.c
+++ test/Profile/c-unprofiled.c
@@ -7,7 +7,7 @@
 // doesn't play wel

r262515 - [PGO] Change profile use cc1 option to handle IR level profiles

2016-03-02 Thread Rong Xu via cfe-commits
Author: xur
Date: Wed Mar  2 14:59:36 2016
New Revision: 262515

URL: http://llvm.org/viewvc/llvm-project?rev=262515&view=rev
Log:
[PGO] Change profile use cc1 option to handle IR level profiles

This patch changes cc1 option for PGO profile use from
-fprofile-instr-use= to -fprofile-instrument-use-path=.
-fprofile-instr-use= is now a driver only option.

In addition to decouple the cc1 option from the driver level option, this patch
also enables IR level profile use. cc1 option handling now reads the profile
header and sets CodeGenOpt ProfileUse (valid values are {None, Clang, LLVM}
-- this is a common enum for -fprofile-instrument={}, for the profile
instrumentation), and invoke the pipeline to enable the respective PGO use pass.

Reviewers: silvas, davidxl

Differential Revision: http://reviews.llvm.org/D17737

Added:
cfe/trunk/test/CodeGen/Inputs/pgotestclang.profraw
cfe/trunk/test/CodeGen/Inputs/pgotestir.profraw
Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Frontend/CodeGenOptions.def
cfe/trunk/include/clang/Frontend/CodeGenOptions.h
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/CMakeLists.txt
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/test/CodeGen/pgo-instrumentation.c
cfe/trunk/test/Driver/clang_f_opts.c
cfe/trunk/test/Profile/c-captured.c
cfe/trunk/test/Profile/c-counter-overflows.c
cfe/trunk/test/Profile/c-general.c
cfe/trunk/test/Profile/c-outdated-data.c
cfe/trunk/test/Profile/c-unprofiled-blocks.c
cfe/trunk/test/Profile/c-unprofiled.c
cfe/trunk/test/Profile/cxx-lambda.cpp
cfe/trunk/test/Profile/cxx-rangefor.cpp
cfe/trunk/test/Profile/cxx-templates.cpp
cfe/trunk/test/Profile/objc-general.m
cfe/trunk/test/Profile/profile-does-not-exist.c

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=262515&r1=262514&r2=262515&view=diff
==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Wed Mar  2 14:59:36 2016
@@ -279,6 +279,9 @@ def fprofile_instrument_EQ : Joined<["-"
 def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
+def fprofile_instrument_use_path_EQ :
+Joined<["-"], "fprofile-instrument-use-path=">,
+HelpText<"Specify the profile path in PGO use compilation">;
 
 
//===--===//
 // Dependency Output Options

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=262515&r1=262514&r2=262515&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Wed Mar  2 14:59:36 2016
@@ -462,7 +462,7 @@ def fprofile_instr_generate_EQ : Joined<
 def fprofile_instr_use : Flag<["-"], "fprofile-instr-use">, Group,
 Flags<[DriverOption]>;
 def fprofile_instr_use_EQ : Joined<["-"], "fprofile-instr-use=">,
-Group, Flags<[CC1Option]>,
+Group, Flags<[DriverOption]>,
 HelpText<"Use instrumentation data for profile-guided optimization">;
 def fcoverage_mapping : Flag<["-"], "fcoverage-mapping">,
 Group, Flags<[CC1Option]>,

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.def?rev=262515&r1=262514&r2=262515&view=diff
==
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def (original)
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def Wed Mar  2 14:59:36 2016
@@ -105,6 +105,8 @@ VALUE_CODEGENOPT(OptimizeSize, 2, 0) ///
 
 /// \brief Choose profile instrumenation kind or no instrumentation.
 ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
+/// \brief Choose profile kind for PGO use compilation.
+ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileNone)
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping

Modified: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Frontend/CodeGenOptions.h?rev=262515&r1=262514&r2=262515&view=diff
==
--- cfe/trunk/i

Re: [PATCH] D17737: [PGO] change profile use cc1 option

2016-03-02 Thread Rong Xu via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL262515: [PGO] Change profile use cc1 option to handle IR 
level profiles (authored by xur).

Changed prior to commit:
  http://reviews.llvm.org/D17737?vs=49655&id=49664#toc

Repository:
  rL LLVM

http://reviews.llvm.org/D17737

Files:
  cfe/trunk/include/clang/Driver/CC1Options.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Frontend/CodeGenOptions.def
  cfe/trunk/include/clang/Frontend/CodeGenOptions.h
  cfe/trunk/lib/CodeGen/BackendUtil.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/CMakeLists.txt
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/test/CodeGen/Inputs/pgotestclang.profraw
  cfe/trunk/test/CodeGen/Inputs/pgotestir.profraw
  cfe/trunk/test/CodeGen/pgo-instrumentation.c
  cfe/trunk/test/Driver/clang_f_opts.c
  cfe/trunk/test/Profile/c-captured.c
  cfe/trunk/test/Profile/c-counter-overflows.c
  cfe/trunk/test/Profile/c-general.c
  cfe/trunk/test/Profile/c-outdated-data.c
  cfe/trunk/test/Profile/c-unprofiled-blocks.c
  cfe/trunk/test/Profile/c-unprofiled.c
  cfe/trunk/test/Profile/cxx-lambda.cpp
  cfe/trunk/test/Profile/cxx-rangefor.cpp
  cfe/trunk/test/Profile/cxx-templates.cpp
  cfe/trunk/test/Profile/objc-general.m
  cfe/trunk/test/Profile/profile-does-not-exist.c

Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.def
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.def
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.def
@@ -105,6 +105,8 @@
 
 /// \brief Choose profile instrumenation kind or no instrumentation.
 ENUM_CODEGENOPT(ProfileInstr, ProfileInstrKind, 2, ProfileNone)
+/// \brief Choose profile kind for PGO use compilation.
+ENUM_CODEGENOPT(ProfileUse, ProfileInstrKind, 2, ProfileNone)
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
Index: cfe/trunk/include/clang/Frontend/CodeGenOptions.h
===
--- cfe/trunk/include/clang/Frontend/CodeGenOptions.h
+++ cfe/trunk/include/clang/Frontend/CodeGenOptions.h
@@ -153,7 +153,7 @@
   std::string SampleProfileFile;
 
   /// Name of the profile file to use as input for -fprofile-instr-use
-  std::string InstrProfileInput;
+  std::string ProfileInstrumentUsePath;
 
   /// Name of the function summary index file to use for ThinLTO function
   /// importing.
@@ -232,6 +232,16 @@
   bool hasProfileIRInstr() const {
 return getProfileInstr() == ProfileIRInstr;
   }
+
+  /// \brief Check if Clang profile use is on.
+  bool hasProfileClangUse() const {
+return getProfileUse() == ProfileClangInstr;
+  }
+
+  /// \brief Check if IR level profile use is on.
+  bool hasProfileIRUse() const {
+return getProfileUse() == ProfileIRInstr;
+  }
 };
 
 }  // end namespace clang
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -462,7 +462,7 @@
 def fprofile_instr_use : Flag<["-"], "fprofile-instr-use">, Group,
 Flags<[DriverOption]>;
 def fprofile_instr_use_EQ : Joined<["-"], "fprofile-instr-use=">,
-Group, Flags<[CC1Option]>,
+Group, Flags<[DriverOption]>,
 HelpText<"Use instrumentation data for profile-guided optimization">;
 def fcoverage_mapping : Flag<["-"], "fcoverage-mapping">,
 Group, Flags<[CC1Option]>,
Index: cfe/trunk/include/clang/Driver/CC1Options.td
===
--- cfe/trunk/include/clang/Driver/CC1Options.td
+++ cfe/trunk/include/clang/Driver/CC1Options.td
@@ -279,6 +279,9 @@
 def fprofile_instrument_path_EQ : Joined<["-"], "fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
+def fprofile_instrument_use_path_EQ :
+Joined<["-"], "fprofile-instrument-use-path=">,
+HelpText<"Specify the profile path in PGO use compilation">;
 
 //===--===//
 // Dependency Output Options
Index: cfe/trunk/test/Profile/cxx-rangefor.cpp
===
--- cfe/trunk/test/Profile/cxx-rangefor.cpp
+++ cfe/trunk/test/Profile/cxx-rangefor.cpp
@@ -4,7 +4,7 @@
 // RUN: FileCheck --input-file=%tgen -check-prefix=CHECK -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/cxx-rangefor.proftext -o %t.profdata
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-rangefor.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-use=%t.profdata > %tuse
+// RUN: %clang_cc1 -

[PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2015-12-30 Thread Rong Xu via cfe-commits
xur created this revision.
xur added reviewers: davidxl, silvas, bogner.
xur added a subscriber: cfe-commits.

This patch introduce a new toggle option -fprofile-ir-instr that enables IR 
level instrumentation. It needs to be used in combination with current PGO 
options. Without an existing PGO options, this option alone is a null operation.
 
This patch depends on llvm patch http://reviews.llvm.org/D15828 where we 
introduce a pair of passmanagerbuilder options: 
 -profile-generate=
 -profile-use=
Note that the profile specified in driver level options 
(-fprofile-instr-generate, -fprofile-instr-use, -fprofile-generate, and 
-profile-use) overrides the profile in the passmanagerbuilder option.


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp

Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -449,8 +449,10 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+  Opts.ProfileIRInstr = Args.hasArg(OPT_fprofile_ir_instr);
+  if (!Opts.ProfileIRInstr)
+Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
+Args.hasArg(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileOutput = 
Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3223,6 +3223,8 @@
   CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
 }
   }
+
+  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);
 }
 
 static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -147,7 +147,7 @@
   if (C.getLangOpts().ObjC1)
 ObjCData = new ObjCEntrypoints();
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.ProfileIRInstr && !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =
 llvm::IndexedInstrProfReader::create(CodeGenOpts.InstrProfileInput);
 if (std::error_code EC = ReaderOrErr.getError()) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -431,6 +431,14 @@
 MPM->add(createInstrProfilingPass(Options));
   }
 
+  if (CodeGenOpts.ProfileIRInstr) {
+assert (!CodeGenOpts.ProfileInstrGenerate);
+if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+if (!CodeGenOpts.InstrProfileInput.empty())
+  PMBuilder.PGOInstrUse = CodeGenOpts.InstrProfileInput;
+  }
+
   if (!CodeGenOpts.SampleProfileFile.empty())
 MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -105,6 +105,7 @@
 
 CODEGENOPT(ProfileInstrGenerate , 1, 0) ///< Instrument code to generate
 ///< execution counts to use with PGO.
+CODEGENOPT(ProfileIRInstr, 1, 0) ///< IR level code PGO instrumentation and 
use.
 CODEGENOPT(CoverageMapping , 1, 0) ///< Generate coverage mapping regions to
///< enable code coverage analysis.
 CODEGENOPT(DumpCoverageMapping , 1, 0) ///< Dump the generated coverage mapping
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -452,6 +452,9 @@
 def fprofile_instr_use_EQ : Joined<["-"], "fprofile-instr-use=">,
 Group, Flags<[CC1Option]>,
 HelpText<"Use instrumentation data for profile-guided optimization">;
+def fprofile_ir_instr : Flag<["-"], "fprofile-ir-instr">, Group,
+Flags<[CC1Option]>,
+HelpText<"Use IR level instrumentation rather the FE implementation">;
 def fcoverage_mapping : Flag<["-"], "fcoverage-mapping">,
 Group, Flags<[CC1Option]>,
 HelpText<"Generate coverage mapping to enable code coverage analysis">;


Index: lib/Frontend/CompilerInvocation.cpp
===

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-13 Thread Rong Xu via cfe-commits
xur marked an inline comment as done.
xur added a comment.

I'll sent the revised patch based on the comments shortly.



Comment at: lib/CodeGen/BackendUtil.cpp:435
@@ +434,3 @@
+  if (CodeGenOpts.ProfileIRInstr) {
+assert (!CodeGenOpts.ProfileInstrGenerate);
+if (!CodeGenOpts.InstrProfileOutput.empty())

davidxl wrote:
> What is this asserting about?
Option ProfileInstrGenerate is to be used in Clang instrumentation only. If I 
reuse this options, I would need to change all the references in clang. I 
update the comments  in the coming patch.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-13 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 44776.
xur added a comment.

added new tests and comments based on the review comments.


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/instrprof-ld.c

Index: test/Driver/instrprof-ld.c
===
--- test/Driver/instrprof-ld.c
+++ test/Driver/instrprof-ld.c
@@ -105,3 +105,23 @@
 //
 // CHECK-WATCHOS-ARMV7: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
 // CHECK-WATCHOS-ARMV7: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}darwin{{/|}}libclang_rt.profile_watchos.a"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -shared \
+// RUN: -target x86_64-unknown-linux -fprofile-ir-instr -fprofile-instr-generate \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64-SHARED-IR-Level %s
+//
+// CHECK-LINUX-X86-64-SHARED-IR-Level: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-LINUX-X86-64-SHARED-IR-Level: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
+//
+// RUN: %clang -no-canonical-prefixes %s -### -o %t.o 2>&1 \
+// RUN: -shared \
+// RUN: -target x86_64-unknown-linux -fprofile-ir-instr \
+// RUN: -resource-dir=%S/Inputs/resource_dir \
+// RUN: --sysroot=%S/Inputs/basic_linux_tree \
+// RUN:   | FileCheck --check-prefix=CHECK-LINUX-X86-64-SHARED-IR-Level-2 %s
+//
+// CHECK-LINUX-X86-64-SHARED-IR-Level-2: "{{(.*[^-.0-9A-Z_a-z])?}}ld{{(.exe)?}}"
+// CHECK-LINUX-X86-64-SHARED-IR-Level-2-NOT: "{{.*}}/Inputs/resource_dir{{/|}}lib{{/|}}linux{{/|}}libclang_rt.profile-x86_64.a" {{.*}} "-lc"
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -449,8 +449,16 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+  // Only set ProfileIRInstr when there are profile generate or use options.
+  Opts.ProfileIRInstr = Args.hasArg(OPT_fprofile_ir_instr) &&
+(Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ) ||
+ Args.hasArg(OPT_fprofile_instr_use_EQ));
+  // Set Opts.ProfileInstrGenerate when Opts.ProfileIRInstr is false.
+  // Opts.ProfileInstrGenerate will be used for Clang instrumentation only.
+  if (!Opts.ProfileIRInstr)
+Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
+Args.hasArg(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3223,6 +3223,8 @@
   CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
 }
   }
+
+  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);
 }
 
 static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -147,7 +147,7 @@
   if (C.getLangOpts().ObjC1)
 ObjCData = new ObjCEntrypoints();
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.ProfileIRInstr && !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =
 llvm::IndexedInstrProfReader::create(CodeGenOpts.InstrProfileInput);
 if (std::error_code EC = ReaderOrErr.getError()) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -431,6 +431,18 @@
 MPM->add(createInstrProfilingPass(Options));
   }
 
+  if (CodeGenOpts.ProfileIRInstr) {
+// Should not have ProfileInstrGenerate set -- it is for clang
+// instrumentation only.
+assert (!CodeGenOpts.ProfileInstrGenerate);
+if (!CodeGenOpts.InstrProfileInput.empty())
+  PMBuilder.PGOInstrUse = CodeGenOpts.InstrProfileInput;
+else if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
+  }
+

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-21 Thread Rong Xu via cfe-commits
xur added a comment.

Ping.

Passmanagerbuilder change has been committed. Could you take a look at this 
command line option patch?

Thanks,

-Rong


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-22 Thread Rong Xu via cfe-commits
On Thu, Jan 21, 2016 at 7:32 PM, Sean Silva  wrote:
> silvas added a comment.
>
> @slingn and I had a discussion offline about the potential names and came up 
> with some ideas, but none is a clear winner.
>
> Overall, my feeling is that from a user's perspective, the frontend stuff is 
> probably best referred to as "coverage-based". It's not as clear for the 
> IR-level stuff, but referring to it as the "pgo focused" or "optimization 
> focused" instrumentation might be a way to describe it. E.g. perhaps 
> `-fprofile-instr-method={coverage,optimization}`.
>

Agreed. Frontend instrumentation has a less chance of the mismatch
caused by compiler change. IR-level instrumentation is more for the
PGO optimization. Speed and simplicity are the focus -- that is also
the main reason that we don't split the BB for no-return-calls.

> For now, can we make this a CC1-only option? Then we don't have to hold up 
> the patch review on the driver stuff. Once we have fully integrated the 
> IR-level instrumentation, we can revisit exposing the user-visible name. (as 
> compiler developers, we can of course use the flag freely for 
> integration/testing).

I can do this. I just need to move the option define from Opertion.td
to CC1Options.td. The user would need to use '-Xclang
-fprofile-ir-instr' to invoke.

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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-22 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 45708.
xur added a comment.

This new patches integrates Sean review comments:
(1) make -fprofile-ir-instr a cc1 option instead of driver option.
(2) add one cc1 option test, and test the pass is indeed invoked.
(3) remove the driver test (runtime library).
(4) fix a comment.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- /dev/null
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,9 @@
+// Test PGO instrumentation.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PASS
+// CHECK-PASS: PGOInstrumentationGenPass
+//
+// Ensure cc1 option -fprofile-ir-instr is null operation without existing pgo options.
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PASS2
+// CHECK-PASS2-NOT: PGOInstrumentationGenPass
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -477,8 +477,16 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+  // Only set ProfileIRInstr when there are profile generate or use options.
+  Opts.ProfileIRInstr = Args.hasArg(OPT_fprofile_ir_instr) &&
+(Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ) ||
+ Args.hasArg(OPT_fprofile_instr_use_EQ));
+  // Set Opts.ProfileInstrGenerate when Opts.ProfileIRInstr is false.
+  // Opts.ProfileInstrGenerate will be used for Clang instrumentation only.
+  if (!Opts.ProfileIRInstr)
+Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
+Args.hasArg(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3275,6 +3275,8 @@
   CmdArgs.push_back(Args.MakeArgString(CoverageFilename));
 }
   }
+
+  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);
 }
 
 static void addPS4ProfileRTArgs(const ToolChain &TC, const ArgList &Args,
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -147,7 +147,7 @@
   if (C.getLangOpts().ObjC1)
 ObjCData = new ObjCEntrypoints();
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.ProfileIRInstr && !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =
 llvm::IndexedInstrProfReader::create(CodeGenOpts.InstrProfileInput);
 if (std::error_code EC = ReaderOrErr.getError()) {
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -436,6 +436,18 @@
 MPM->add(createInstrProfilingPass(Options));
   }
 
+  if (CodeGenOpts.ProfileIRInstr) {
+// Should not have ProfileInstrGenerate set -- it is for clang
+// instrumentation only.
+assert (!CodeGenOpts.ProfileInstrGenerate);
+if (!CodeGenOpts.InstrProfileInput.empty())
+  PMBuilder.PGOInstrUse = CodeGenOpts.InstrProfileInput;
+else if (!CodeGenOpts.InstrProfileOutput.empty())
+  PMBuilder.PGOInstrGen = CodeGenOpts.InstrProfileOutput;
+else
+  PMBuilder.PGOInstrGen = "default.profraw";
+  }
+
   if (!CodeGenOpts.SampleProfileFile.empty())
 MPM->add(createSampleProfileLoaderPass(CodeGenOpts.SampleProfileFile));
 
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -105,6 +105,7 @@
 
 CODEGENOPT(ProfileInstrGenerate , 1, 0) ///< Instrument code to generate
 ///< execution counts to use with PGO.
+CODEGENOPT(ProfileIRInstr, 1, 0) ///< IR level PGO instrumentation and use.
 CODEGENOPT(

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-22 Thread Rong Xu via cfe-commits
xur added inline comments.


Comment at: lib/Driver/Tools.cpp:3279
@@ -3278,1 +3278,3 @@
+
+  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);
 }

mcrosier wrote:
> I don't think AddAllArgs is what you really want.  What if the user specifies 
> the option twice?  Do we really want to pass the flag from the driver to the 
> front-end twice?  Also, should we warn if the option is passed twice?
> 
> I also think some of the logic in CompilerInvocation should land here...  see 
> comments below.
Thanks for pointing thi out. What about add a guard, like:
-  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);
+  if (Args.hasArg(options::OPT_fprofile_ir_instr))
+Args.AddAllArgs(CmdArgs, options::OPT_fprofile_ir_instr);

But looking at it again, I think i need to remove this stmt in the most 
recently patch as OPT_profile_ir_instr is now a CC1 option. it will not be seen 
here, right?




Comment at: lib/Frontend/CompilerInvocation.cpp:482
@@ +481,3 @@
+  Opts.ProfileIRInstr = Args.hasArg(OPT_fprofile_ir_instr) &&
+(Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ) ||

mcrosier wrote:
> IIRC, the general practice is to put this type of logic in the driver.  
> Specifically, in Driver.cpp include something like
> 
> if (Args.hasArg(OPT_fprofile_ir_instr) &&
> (Args.hasArg(OPT_fprofile_instr_generate) ||
>  Args.hasArg(OPT_fprofile_instr_generate_EQ) ||
>  Args.hasArg(OPT_fprofile_instr_use_EQ)))
>   // Add -fprofile_ir_instr flag
> 
> 
In the most recent patch (Suggested by Sean as a temporary measure to speed up 
the code review)  where -fprofiel-ir-instr becomes a CC1 only option, I have to 
do it here. Driver won't see the OPT_fprofile_ir_instr. 

But I'll remember you point when this becomes a Driver option in the next step. 
Also note that the driver could convert "-fprofile-genearte" to 
"-fprofiel-instr-generate" and also for "-fprofile-use".  So the condition will 
be longer if we move to driver.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-22 Thread Rong Xu via cfe-commits
xur added inline comments.


Comment at: lib/CodeGen/BackendUtil.cpp:440
@@ +439,3 @@
+  if (CodeGenOpts.ProfileIRInstr) {
+// Should not have ProfileInstrGenerate set -- it is for clang
+// instrumentation only.

silvas wrote:
> Then change the existing references in clang. Please try to cleanly integrate 
> the new functionality, not "sneak it in" with the smallest number of lines 
> changed (and creating technical debt for future maintainers).
The integration is actually clean to me: For CodeGenOpt: ProfileInstrGenerate 
is for Clang instrumentation and ProfileIRInstr is for IR instrumentation. They 
need to mutually exclusive. 

Maybe I need to modify the name and description for  ProfileInstrGenerate to 
reflect the change.


Comment at: lib/Frontend/CompilerInvocation.cpp:482
@@ +481,3 @@
+  Opts.ProfileIRInstr = Args.hasArg(OPT_fprofile_ir_instr) &&
+(Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ) ||

silvas wrote:
> xur wrote:
> > mcrosier wrote:
> > > IIRC, the general practice is to put this type of logic in the driver.  
> > > Specifically, in Driver.cpp include something like
> > > 
> > > if (Args.hasArg(OPT_fprofile_ir_instr) &&
> > > (Args.hasArg(OPT_fprofile_instr_generate) ||
> > >  Args.hasArg(OPT_fprofile_instr_generate_EQ) ||
> > >  Args.hasArg(OPT_fprofile_instr_use_EQ)))
> > >   // Add -fprofile_ir_instr flag
> > > 
> > > 
> > In the most recent patch (Suggested by Sean as a temporary measure to speed 
> > up the code review)  where -fprofiel-ir-instr becomes a CC1 only option, I 
> > have to do it here. Driver won't see the OPT_fprofile_ir_instr. 
> > 
> > But I'll remember you point when this becomes a Driver option in the next 
> > step. Also note that the driver could convert "-fprofile-genearte" to 
> > "-fprofiel-instr-generate" and also for "-fprofile-use".  So the condition 
> > will be longer if we move to driver.
> Chad makes a good point though. This should be just `Opts.ProfileIRInstr = 
> Args.hasArg(OPT_fprofile_ir_instr);` because we can assume that for cc11 this 
> option is not used except in conjunction with `-fprofile-instr-{generate,use}`
If we can have the assumption. Yes I can simplify the stmt. If the user breaks 
the assumption. Current patch will not invoke the IR PGO pass, while the 
proposed way will cause error. Of course, you can say this is a usage error.

I have no problem to simplify this.


Comment at: lib/Frontend/CompilerInvocation.cpp:487
@@ +486,3 @@
+  // Opts.ProfileInstrGenerate will be used for Clang instrumentation only.
+  if (!Opts.ProfileIRInstr)
+Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||

silvas wrote:
> I don't like this. It breaks the 1:1 mapping of flags to codegen options. 
> Like Chad said, this sort of complexity should be kept in the driver.
> 
> Some refactoring may be needed to cleanly integrate the new IR 
> instrumentation.
hmm. I don't think there is 1:1 mapping b/w flags and codegen options, because 
-fprofile-instr-generate is shared by IR and FE instrumentation.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-25 Thread Rong Xu via cfe-commits
OK. Now I understand what you meant. I was trying to avoid driver changes.
It seems you are saying I can change the driver to support cc1 options more
cleanly. This can be done.

Thanks,

Rong
On Jan 25, 2016 12:43, "Sean Silva"  wrote:

> silvas added inline comments.
>
> 
> Comment at: lib/Frontend/CompilerInvocation.cpp:487
> @@ +486,3 @@
> +  // Opts.ProfileInstrGenerate will be used for Clang instrumentation
> only.
> +  if (!Opts.ProfileIRInstr)
> +Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate)
> ||
> 
> davidxl wrote:
> > xur wrote:
> > > silvas wrote:
> > > > I don't like this. It breaks the 1:1 mapping of flags to codegen
> options. Like Chad said, this sort of complexity should be kept in the
> driver.
> > > >
> > > > Some refactoring may be needed to cleanly integrate the new IR
> instrumentation.
> > > hmm. I don't think there is 1:1 mapping b/w flags and codegen options,
> because -fprofile-instr-generate is shared by IR and FE instrumentation.
> > If you rename the FE PGO CodeGen opt name as proposed, it will be
> clearer and less confusing.
> > hmm. I don't think there is 1:1 mapping b/w flags and codegen options,
> because -fprofile-instr-generate is shared by IR and FE instrumentation.
>
> Maybe at the driver level (that discussion has yet to conclude), but at
> cc1 level options should be factored to be clean and orthogonal. Like Chad
> said, the complexity of verifying options that are mutually exclusive or
> that must be present with other options should be done in the driver. cc1
> is a private interface
>
>
>
> http://reviews.llvm.org/D15829
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-25 Thread Rong Xu via cfe-commits
xur added a subscriber: xur.
xur added a comment.

OK. Now I understand what you meant. I was trying to avoid driver changes.
It seems you are saying I can change the driver to support cc1 options more
cleanly. This can be done.

Thanks,

Rong


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-25 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 45929.
xur marked an inline comment as done.
xur added a comment.

Here is the new patch. Changes from previous patch are:
(1) rename codegen option ProfileInstrGenerate to ClangProfInstrGen to avoid 
the name confusion (Davidxl). This option is for clang instrumentation only.
(2) improve the test suggested by Sean.
(3) move the logic of checking if argument ProfileIRInstr needs to be added to 
Tools.C (suggested by Chad and Sean). This still does not look very clean -- I 
need to manually expand the -Xclang option for this. The difficulty here is 
that we have shared driver level arguments (-fprofile-generate and 
-fprofile-use etc) and there is no cc1 option for clang instrumentation. Once 
we have driver level option for IR level instrumentation, the code can be 
improved.


http://reviews.llvm.org/D15829

Files:
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotest.profraw
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- /dev/null
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,23 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-V1
+// CHECK-PGOGENPASS-INVOKED-V1: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-V2
+// CHECK-PGOGENPASS-INVOKED-V2: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-instr-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-V1
+// CHECK-PGOUSEPASS-INVOKED-V1: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-V2
+// CHECK-PGOUSEPASS-INVOKED-V2: PGOInstrumentationUsePass
+//
+// Ensure cc1 option -fprofile-ir-instr is null operation without existing pgo options.
+// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOPASS-INVOKED
+// CHECK-PGOPASS-INVOKED-NOT: PGOInstrumentation{Gen|USE}Pass
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -477,8 +477,13 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+  if (Args.hasArg(OPT_fprofile_ir_instr))
+// Set ProfileIRInstr when there are profile generate or use options.
+Opts.ProfileIRInstr = true;
+  else
+// Opts.ClangProfInstrGen will be used for Clang instrumentation only.
+Opts.ClangProfInstrGen = Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5514,7 +5514,20 @@
 
   // Forward -Xclang arguments to -cc1, and -mllvm arguments to the LLVM option
   // parser.
-  Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  //Args.AddAllArgValues(CmdArgs, options::OPT_Xclang);
+  for (const Arg *A : Args.filtered(options::OPT_Xclang)) {
+A->claim();
+if ((StringRef(A->getValue(0)) == "-fprofile-ir-instr") &&
+(Args.hasArg(options::OPT_fprofile_instr_generate) ||
+ Args.hasArg(options::OPT_fprofile_instr_generate_EQ) ||
+ Args.hasArg(options::OPT_fprofile_generate) ||
+ Args.hasArg(options::OPT_fprofile_generate_EQ) ||
+ Args.hasArg(options::OPT_fprofile_instr

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-27 Thread Rong Xu via cfe-commits
Sean: Adding a new CC1 option ProfileClangInstr will make things
cleaner. But this won't solve the problem. The root of all the mess is
there is no driver level option for IR instrumentation. I need to
either "hijack" the -Xclang option, or move the logic to
CompilerInvocation.cpp, which both you don't like.

The reason is I have to reply on the Driver option
-fprofile-instr-generate to have the right link line for the profile
library. -fprofile-instr-generate will set the Instrumentation to
Clang (regardless use of current cc1 option of
-fprofile-instr-generate, or the new proposed -fprofile-clang-instr).
For IR instrumentation where the user specifies "-Xclang
-fprofile-ir-instr", I need to overwrite the driver level option. To
get that, I either parse the -Xclang value (this is "hijack), or I
handle it in CC1 (in CompilerInvocation.cpp). I don't see a way to
avoid it.

Can we use a hidden driver option here for IR instrumentation?

On Tue, Jan 26, 2016 at 5:01 PM, Sean Silva  wrote:
> silvas added inline comments.
>
> 
> Comment at: lib/Driver/Tools.cpp:5520
> @@ +5519,3 @@
> +A->claim();
> +if ((StringRef(A->getValue(0)) == "-fprofile-ir-instr") &&
> +(Args.hasArg(options::OPT_fprofile_instr_generate) ||
> 
> This is definitely not the right thing to do. Don't hijack -Xclang (which is 
> a completely generic thing).
>
> 
> Comment at: lib/Frontend/CompilerInvocation.cpp:483
> @@ +482,3 @@
> +Opts.ProfileIRInstr = true;
> +  else
> +// Opts.ClangProfInstrGen will be used for Clang instrumentation only.
> 
> This still isn't factored right. I think at this point the meaning of the 
> driver-level options is not really useful at CC1 level (too convoluted) for 
> it to be useful to pass them through.
>
> The right thing to do here is probably more like:
> - refactor so that we have 4 individual CC1 options for InstrProfileOutput, 
> InstrProfileInput, ProfileIRInstr, ClangProfInstrGen (although probably 
> rename ClangProfInstrGen and ProfileIRInstr to be consistent with each other, 
> e.g. "ProfileIRInstr" and "ProfileClangInstr").
> - add logic in Driver to convert from the driver-level options to the CC1 
> options.
>
> 
> Comment at: test/CodeGen/pgo-instrumentation.c:5
> @@ +4,3 @@
> +// RUN: %clang -O2 -c -Xclang -fprofile-ir-instr -fprofile-instr-generate %s 
> -mllvm -debug-pass=Structure 2>&1 | FileCheck %s 
> -check-prefix=CHECK-PGOGENPASS-INVOKED-V1
> +// CHECK-PGOGENPASS-INVOKED-V1: PGOInstrumentationGenPass
> +//
> 
> It isn't clear what V1/V2 mean.
>
>
> http://reviews.llvm.org/D15829
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-27 Thread Rong Xu via cfe-commits
xur added a comment.

Sean: Adding a new CC1 option ProfileClangInstr will make things
cleaner. But this won't solve the problem. The root of all the mess is
there is no driver level option for IR instrumentation. I need to
either "hijack" the -Xclang option, or move the logic to
CompilerInvocation.cpp, which both you don't like.

The reason is I have to reply on the Driver option
-fprofile-instr-generate to have the right link line for the profile
library. -fprofile-instr-generate will set the Instrumentation to
Clang (regardless use of current cc1 option of
-fprofile-instr-generate, or the new proposed -fprofile-clang-instr).
For IR instrumentation where the user specifies "-Xclang
-fprofile-ir-instr", I need to overwrite the driver level option. To
get that, I either parse the -Xclang value (this is "hijack), or I
handle it in CC1 (in CompilerInvocation.cpp). I don't see a way to
avoid it.

Can we use a hidden driver option here for IR instrumentation?


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-27 Thread Rong Xu via cfe-commits
On Wed, Jan 27, 2016 at 11:31 AM, David Li  wrote:
> davidxl added inline comments.
>
> 
> Comment at: lib/Driver/Tools.cpp:5520
> @@ +5519,3 @@
> +A->claim();
> +if ((StringRef(A->getValue(0)) == "-fprofile-ir-instr") &&
> +(Args.hasArg(options::OPT_fprofile_instr_generate) ||
> 
> silvas wrote:
>> This is definitely not the right thing to do. Don't hijack -Xclang (which is 
>> a completely generic thing).
> Why do we need special handling here ? will the existing behavior (simple 
> forwarding) work?

The original patch does the simple forwarding. In that case, we handle
the cc1 options (choosing b/w IR or clang instrumentation) in
CompilerInvocation.cpp. Sean and Chad think this logic should be
driver.

>
> Note that intention of the cc1 option is to hide it from the user but make it 
> used by the developers -- so we can make assumption that this option is used 
> only when -fprofile-instr-generate[=...] is specified. You can add 
> diagnostics later during cc1 option processing if it is not the case.
>
> Also think about making it easier to flip the default behavior in the future, 
> it might be better to make the cc1 option look like this:
>
> -fprofile-instrumentor=[clang|LLVM]
>
> if the option is missing, the current default will be 'clang'. In the future 
> just switch it to 'llvm'.
>
> 
> Comment at: lib/Frontend/CompilerInvocation.cpp:483
> @@ +482,3 @@
> +Opts.ProfileIRInstr = true;
> +  else
> +// Opts.ClangProfInstrGen will be used for Clang instrumentation only.
> 
> silvas wrote:
>> This still isn't factored right. I think at this point the meaning of the 
>> driver-level options is not really useful at CC1 level (too convoluted) for 
>> it to be useful to pass them through.
>>
>> The right thing to do here is probably more like:
>> - refactor so that we have 4 individual CC1 options for InstrProfileOutput, 
>> InstrProfileInput, ProfileIRInstr, ClangProfInstrGen (although probably 
>> rename ClangProfInstrGen and ProfileIRInstr to be consistent with each 
>> other, e.g. "ProfileIRInstr" and "ProfileClangInstr").
>> - add logic in Driver to convert from the driver-level options to the CC1 
>> options.
> It is already pretty close to your proposal -- the only missing thing is cc1 
> option for ClangProfInstrGen. However given that IR and Clang InstrGen are 
> mutually exclusive, is an additional CC1 option needed?
>
>
> http://reviews.llvm.org/D15829
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-27 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 46199.
xur added a comment.

This new version implemented the usage model David proposed. We now have a cc1 
option -fprofile-instrumentor={llvm | clang} to choose which instrumentation to 
use. The slight difference from David's proposal is that we can use this option 
with -fprofile-instr-use.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotest.profraw
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- /dev/null
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,28 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=llvm -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=llvm -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-GEN
+// CHECK-PGOGENPASS-INVOKED-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=clang -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=llvm -fprofile-instr-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
+// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=llvm -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is not invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrumentor=clang -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
+// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -477,8 +477,28 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+
+  enum PGOInstrumentor { Unknown, Clang, LLVM };
+  if (Arg *A = Args.getLastArg(OPT_fprofile_instrumentor_EQ)) {
+StringRef Value = A->getValue();
+PGOInstrumentor Method = llvm::StringSwitch(Value)
+  .Case("clang", Clang)
+  .Case("llvm", LLVM)
+  .Default(Unknown);
+if (Method == Unknown)
+  Diags.Report(diag::err_drv_invalid_pgo_instrumentor) 
+ << A->getAsString(Args) << Value;
+else {
+  Opts.ProfileIRInstr = (Method == LLVM);
+  Opts.ProfileClangInstr = (Method == Clang);
+}
+  } else {
+// Default PGO instrumentor is Clang instrumentation.
+Opts.ProfileClangInstr = Args.hasArg(OPT_fprofile_instr_generate) ||
+ Args.hasArg(OPT_fprofile_instr_generate_EQ);
+Opts.ProfileIRInstr = false;
+  }
+
   Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -37,7 +37,7 @@
   PGOReader ? PGOReader->getVersion() : llvm::IndexedInstrProf::Version);
 
   // If we're generating a profile, create a variable for the name.
-  if (C

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-28 Thread Rong Xu via cfe-commits
xur added a comment.

I'll send an updated patch shortly.



Comment at: include/clang/Frontend/CodeGenOptions.def:106
@@ -105,3 +105,3 @@
 
-CODEGENOPT(ProfileInstrGenerate , 1, 0) ///< Instrument code to generate
-///< execution counts to use with PGO.
+CODEGENOPT(ProfileClangInstr, 1, 0) ///< Clang Instrumentation to generate
+///< execution counts to use with PGO.

silvas wrote:
> davidxl wrote:
> > For the sake of being consistent with the new cc1 option, making this an 
> > enum option is better:
> > 
> > ENUM_CODEGENOPT(ProfileInstr,... ) which takes two legal values 
> > ProfInstrClang, ProfInstrLLVM
> > 
> > I'd like to hear Sean's opinion on this.
> SGTM. I was going to suggest something similar. This is more consistent with 
> e.g. OPT_debug_info_kind_EQ and the other multi-value options.
OK. I'll use ENUM as you two suggested.


Comment at: lib/CodeGen/CodeGenModule.cpp:150
@@ -149,3 +149,3 @@
 
-  if (!CodeGenOpts.InstrProfileInput.empty()) {
+  if (!CodeGenOpts.ProfileIRInstr && !CodeGenOpts.InstrProfileInput.empty()) {
 auto ReaderOrErr =

silvas wrote:
> This seems like a latent bug: `!CodeGenOpts.ProfileIRInstr` is true when we 
> are doing no instrumentation. Using an ENUM_CODEGENOPT will fix this and 
> related issues.
I don't think this is a bug. As I mentioned in the update comments. I still use 
this option (-fprofile-instrumentor=) in profile-use compilation. Once we have 
the llvm-profdata patch in, we can detect the profile kind and remove this.


Comment at: lib/Frontend/CompilerInvocation.cpp:495
@@ +494,3 @@
+}
+  } else {
+// Default PGO instrumentor is Clang instrumentation.

silvas wrote:
> The work being done in this `else` is redundant. 
> `-fprofile-instrumentor={clang,llvm,none}` (with "none" being the default if 
> the argument isn't passed) covers this case as 
> `-fprofile-instrumentor=clang`. The driver can be changed to translate 
> `-fprofile-instr-generate` into `-fprofile-instrumentor=clang`. (and 
> `-fprofile-instrument=` might be a better name)
Only if we changed the driver and pushed in -fprofile-instrumentor to the cc1 
argument list, the else part is indeed redundant.

But since I did not change the driver options handling, we still need this else 
branch -- we only set ProfileClangInstr when there is 
OPT_fprofile_instr_generate.

I'll change the -fprofile-instrumentor to -fprofile-instrument and change the 
driver to push in this argument. I will probably remove 
OPT_fprfoile_instr_generate as a CC1 option.




http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-28 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 46303.
xur added a comment.

Integrated most recently comments/suggestions from David and Sean.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotest.profraw
  test/CodeGen/pgo-instrumentation.c

Index: test/CodeGen/pgo-instrumentation.c
===
--- /dev/null
+++ test/CodeGen/pgo-instrumentation.c
@@ -0,0 +1,28 @@
+// Test if PGO instrumentation and use pass are invoked.
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=LLVM -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=LLVM -fprofile-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-GEN
+// CHECK-PGOGENPASS-INVOKED-GEN: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationGenPass is not invoked.
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=Clang -fprofile-instr-generate %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG
+// CHECK-PGOGENPASS-INVOKED-INSTR-GEN-CLANG-NOT: PGOInstrumentationGenPass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=LLVM -fprofile-instr-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-INSTR-USE
+// CHECK-PGOUSEPASS-INVOKED-INSTR-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=LLVM -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE
+// CHECK-PGOUSEPASS-INVOKED-USE: PGOInstrumentationUsePass
+//
+// Ensure Pass PGOInstrumentationUsePass is not invoked.
+// RUN: llvm-profdata merge -o %t.profdata %S/Inputs/pgotest.profraw
+// RUN: %clang -O2 -c -Xclang -fprofile-instrument=Clang -fprofile-use=%t.profdata %s -mllvm -debug-pass=Structure 2>&1 | FileCheck %s -check-prefix=CHECK-PGOUSEPASS-INVOKED-USE-CLANG
+// CHECK-PGOUSEPASS-INVOKED-USE-CLANG-NOT: PGOInstrumentationUsePass
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -477,8 +477,29 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
-  Opts.ProfileInstrGenerate = Args.hasArg(OPT_fprofile_instr_generate) ||
-  Args.hasArg(OPT_fprofile_instr_generate_EQ);
+
+  enum PGOInstrumentor { Unknown, Clang, LLVM };
+  if (Arg *A = Args.getLastArg(OPT_fprofile_instrument_EQ)) {
+StringRef Value = A->getValue();
+PGOInstrumentor Method = llvm::StringSwitch(Value)
+ .Case("Clang", Clang)
+ .Case("LLVM", LLVM)
+ .Default(Unknown);
+switch (Method) {
+case LLVM:
+  Opts.setProfileInstr(CodeGenOptions::ProfileIRInstr);
+  break;
+case Clang:
+  Opts.setProfileInstr(CodeGenOptions::ProfileClangInstr);
+  break;
+case Unknown:
+default:
+  Diags.Report(diag::err_drv_invalid_pgo_instrumentor)
+  << A->getAsString(Args) << Value;
+  break;
+}
+  }
+
   Opts.InstrProfileOutput = Args.getLastArgValue(OPT_fprofile_instr_generate_EQ);
   Opts.InstrProfileInput = Args.getLastArgValue(OPT_fprofile_instr_use_EQ);
   Opts.CoverageMapping =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -3230,8 +3230,9 @@
   llvm::sys::path::append(Path, "default.profraw");
   CmdArgs.push_back(
   Args.MakeArgString(Twine("-fprofile-instr-generate=") + Path));
-} else
-  Args.AddAllArgs(CmdArgs, options::OPT_fprofile_instr_generate);
+}
+// The default is to use Clang Instrumentation.
+CmdArgs.push_back("-fprofile-instrument=Clang");

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-28 Thread Rong Xu via cfe-commits
The previous patch was not good as it failed 58 tests that use
-fprofile-instr-generate as a cc1 option.

I can see two methods to solve this:
(1) we change all the 58 tests to use -fprofile-instrument=Clang option.
(2) Fall back to my previous patch: keep -fprofile-instr-generate as
the CC1 options and check it in Frontend/CompilerInvocation.cpp. (i.e.
The redundant else branch Sean was referring to).  We have to do it
here because we cannot assume driver will append
-fprofile-instrument=Clang in the case the user uses
-fprofile-instr-generate as the cc1 option.



On Thu, Jan 28, 2016 at 12:04 PM, Rong Xu  wrote:
> xur updated this revision to Diff 46303.
> xur added a comment.
>
> Integrated most recently comments/suggestions from David and Sean.
>
> Thanks,
>
> -Rong
>
>
> http://reviews.llvm.org/D15829
>
> Files:
>   include/clang/Basic/DiagnosticDriverKinds.td
>   include/clang/Driver/CC1Options.td
>   include/clang/Driver/Options.td
>   include/clang/Frontend/CodeGenOptions.def
>   include/clang/Frontend/CodeGenOptions.h
>   lib/CodeGen/BackendUtil.cpp
>   lib/CodeGen/CGStmt.cpp
>   lib/CodeGen/CodeGenFunction.cpp
>   lib/CodeGen/CodeGenFunction.h
>   lib/CodeGen/CodeGenModule.cpp
>   lib/CodeGen/CodeGenPGO.cpp
>   lib/Driver/Tools.cpp
>   lib/Frontend/CompilerInvocation.cpp
>   test/CodeGen/Inputs/pgotest.profraw
>   test/CodeGen/pgo-instrumentation.c
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-28 Thread Rong Xu via cfe-commits
xur added a comment.

The previous patch was not good as it failed 58 tests that use
-fprofile-instr-generate as a cc1 option.

I can see two methods to solve this:
(1) we change all the 58 tests to use -fprofile-instrument=Clang option.
(2) Fall back to my previous patch: keep -fprofile-instr-generate as
the CC1 options and check it in Frontend/CompilerInvocation.cpp. (i.e.
The redundant else branch Sean was referring to).  We have to do it
here because we cannot assume driver will append
-fprofile-instrument=Clang in the case the user uses
-fprofile-instr-generate as the cc1 option.


http://reviews.llvm.org/D15829



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


Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-29 Thread Rong Xu via cfe-commits
xur updated this revision to Diff 46389.
xur added a comment.

This new patch adds the change the clang test cases (cc1 option 
-fprofile-instr-generate to -fprofile-instrument=Clang).

It also replaces cc1 option -fprofile-instr-generate= to 
-fprofile-instrument-path=, as suggested by David.

Thanks,

-Rong


http://reviews.llvm.org/D15829

Files:
  include/clang/Basic/DiagnosticDriverKinds.td
  include/clang/Driver/CC1Options.td
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  include/clang/Frontend/CodeGenOptions.h
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGStmt.cpp
  lib/CodeGen/CodeGenFunction.cpp
  lib/CodeGen/CodeGenFunction.h
  lib/CodeGen/CodeGenModule.cpp
  lib/CodeGen/CodeGenPGO.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGen/Inputs/pgotest.profraw
  test/CodeGen/pgo-instrumentation.c
  test/CoverageMapping/block-storage-starts-region.m
  test/CoverageMapping/break.c
  test/CoverageMapping/builtinmacro.c
  test/CoverageMapping/casts.c
  test/CoverageMapping/classtemplate.cpp
  test/CoverageMapping/comment-in-macro.c
  test/CoverageMapping/continue.c
  test/CoverageMapping/control-flow-macro.c
  test/CoverageMapping/decl.c
  test/CoverageMapping/header.cpp
  test/CoverageMapping/if.c
  test/CoverageMapping/implicit-def-in-macro.m
  test/CoverageMapping/includehell.cpp
  test/CoverageMapping/ir.c
  test/CoverageMapping/label.cpp
  test/CoverageMapping/lambda.cpp
  test/CoverageMapping/logical.cpp
  test/CoverageMapping/loopmacro.c
  test/CoverageMapping/loops.cpp
  test/CoverageMapping/macro-expansion.c
  test/CoverageMapping/macro-expressions.cpp
  test/CoverageMapping/macroception.c
  test/CoverageMapping/macroparams.c
  test/CoverageMapping/macroparams2.c
  test/CoverageMapping/macros.c
  test/CoverageMapping/macroscopes.cpp
  test/CoverageMapping/md.cpp
  test/CoverageMapping/moremacros.c
  test/CoverageMapping/nestedclass.cpp
  test/CoverageMapping/objc.m
  test/CoverageMapping/preprocessor.c
  test/CoverageMapping/return.c
  test/CoverageMapping/switch.c
  test/CoverageMapping/switchmacro.c
  test/CoverageMapping/system_macro.c
  test/CoverageMapping/templates.cpp
  test/CoverageMapping/test.c
  test/CoverageMapping/trycatch.cpp
  test/CoverageMapping/trymacro.cpp
  test/CoverageMapping/unreachable-macro.c
  test/CoverageMapping/unused_names.c
  test/CoverageMapping/while.c
  test/Driver/clang_f_opts.c
  test/Profile/c-captured.c
  test/Profile/c-general.c
  test/Profile/c-generate.c
  test/Profile/c-indirect-call.c
  test/Profile/c-linkage-available_externally.c
  test/Profile/c-linkage.c
  test/Profile/c-unreachable-after-switch.c
  test/Profile/cxx-implicit.cpp
  test/Profile/cxx-lambda.cpp
  test/Profile/cxx-linkage.cpp
  test/Profile/cxx-rangefor.cpp
  test/Profile/cxx-structors.cpp
  test/Profile/cxx-templates.cpp
  test/Profile/cxx-virtual-destructor-calls.cpp
  test/Profile/objc-general.m

Index: test/Profile/objc-general.m
===
--- test/Profile/objc-general.m
+++ test/Profile/objc-general.m
@@ -1,6 +1,6 @@
 // Test instrumentation of general constructs in objective C.
 
-// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-generate | FileCheck -check-prefix=PGOGEN %s
+// RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instrument=Clang | FileCheck -check-prefix=PGOGEN %s
 
 // RUN: llvm-profdata merge %S/Inputs/objc-general.proftext -o %t.profdata
 // RUN: %clang_cc1 -triple x86_64-apple-macosx10.9 -main-file-name objc-general.m %s -o - -emit-llvm -fblocks -fprofile-instr-use=%t.profdata | FileCheck -check-prefix=PGOUSE %s
Index: test/Profile/cxx-virtual-destructor-calls.cpp
===
--- test/Profile/cxx-virtual-destructor-calls.cpp
+++ test/Profile/cxx-virtual-destructor-calls.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -main-file-name cxx-virtual-destructor-calls.cpp %s -o - -fprofile-instr-generate | FileCheck %s
+// RUN: %clang_cc1 -triple %itanium_abi_triple -emit-llvm -main-file-name cxx-virtual-destructor-calls.cpp %s -o - -fprofile-instrument=Clang | FileCheck %s
 
 struct Member {
   ~Member();
Index: test/Profile/cxx-templates.cpp
===
--- test/Profile/cxx-templates.cpp
+++ test/Profile/cxx-templates.cpp
@@ -1,7 +1,7 @@
 // Tests for instrumentation of templated code. Each instantiation of a template
 // should be instrumented separately.
 
-// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instr-generate > %tgen
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-templates.cpp -std=c++11 -o - -emit-llvm -fprofile-instrument=Clang > %tgen
 // RUN: Fil

Re: [PATCH] D15829: [PGO] Clang Option that enables IR level PGO instrumentation

2016-01-29 Thread Rong Xu via cfe-commits
xur added a comment.

To make the review easier, I split the cc1 names change part into a new NFC 
patch here.
http://reviews.llvm.org/D16730


http://reviews.llvm.org/D15829



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