[PATCH] D82822: [OpenMP][FIX] Consistently use OpenMPIRBuilder if requested

2020-08-02 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

In D82822#2187576 , @jdoerfert wrote:

> @davezarzycki The bots reported this as well, didn't build MLIR locally, this 
> should have been fixed by 4d83aa4771d84940626d86c883193af390812281 
> 

I was seeing the same issue with what @davezarzycki has encountered. Not sure 
why this is related to MLIR. The failure is cause by this line:

  74: // CHECK-DEBUG-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 
@__kmpc_global_thread_num(%struct.ident_t* **@12**), !dbg !{{[0-9]*}}

where `@12` is supposed to be defined as

  @11 = private unnamed_addr constant [90 x i8] 
c";llvm-project/clang/test/OpenMP/irbuilder_nested_parallel_for.c;parallel_for_1;85;1;;\00",
 align 1
  @12 = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, i32 
0, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @11, i32 0, i32 0) }, 
align 8

The exact match of `@12` seems a bit fragile to me since global data names 
could be changed from time to time. Can you please make it bit more robust? 
Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82822/new/

https://reviews.llvm.org/D82822

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


[PATCH] D82822: [OpenMP][FIX] Consistently use OpenMPIRBuilder if requested

2020-08-02 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

In D82822#2189692 , @jdoerfert wrote:

> In D82822#2189366 , @hoyFB wrote:
>
>> In D82822#2187576 , @jdoerfert 
>> wrote:
>>
>>> @davezarzycki The bots reported this as well, didn't build MLIR locally, 
>>> this should have been fixed by 4d83aa4771d84940626d86c883193af390812281 
>>> 
>>
>> I was seeing the same issue with what @davezarzycki has encountered. Not 
>> sure why this is related to MLIR. The failure is cause by this line:
>>
>>   74: // CHECK-DEBUG-NEXT:[[OMP_GLOBAL_THREAD_NUM:%.*]] = call i32 
>> @__kmpc_global_thread_num(%struct.ident_t* **@12**), !dbg !{{[0-9]*}}
>>
>> where `@12` is supposed to be defined as
>>
>>   @11 = private unnamed_addr constant [90 x i8] 
>> c";llvm-project/clang/test/OpenMP/irbuilder_nested_parallel_for.c;parallel_for_1;85;1;;\00",
>>  align 1
>>   @12 = private unnamed_addr global %struct.ident_t { i32 0, i32 2, i32 0, 
>> i32 0, i8* getelementptr inbounds ([90 x i8], [90 x i8]* @11, i32 0, i32 0) 
>> }, align 8
>>
>> The exact match of `@12` seems a bit fragile to me since global data names 
>> could be changed from time to time. Can you please make it bit more robust? 
>> Thank
>
> I just created D85099  to eliminate the 
> problem permanently. Feel free to take a look.

Thanks for the quick turnaround!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D82822/new/

https://reviews.llvm.org/D82822

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


[PATCH] D83176: [OpenMPIRBuilder][Fix] Move llvm::omp::types to OpenMPIRBuilder.

2020-07-05 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

Thanks for the quick turnaround! I confirm the change fixes our build break.




Comment at: llvm/lib/Transforms/IPO/OpenMPOpt.cpp:313
   {
\
 SmallVector ArgsTypes({__VA_ARGS__});   
\
 Function *F = M.getFunction(_Name);
\

sstefan1 wrote:
> I wasn't sure how to handle `__VA_ARGS__` here, since we would need 
> `OMPBuilder` in front of every type. 
> That is why helper macros above exist. The problem with this is that this 
> creates some unused variables in `OpenMPOpt`.
> 
> Not sure if `-Wno-unused-variable` would be a good thing to do temporarily? 
> Is there another way to handle `__VA_ARGS__` here?
Could it be possible to use `OMPBuilder. _Name`, `OMPBuilder. _ReturnType` 
everywhere?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D83176/new/

https://reviews.llvm.org/D83176



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


[PATCH] D77952: [TLI] Reduce copies for TLI and TLA

2020-04-11 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

Thanks for the nice cleanup!




Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:456
+  TargetLibraryAnalysis(const Triple &T)
+  : BaselineInfoImpl(TargetLibraryInfoImpl(T)) {}
+  TargetLibraryAnalysis(const TargetLibraryInfoImpl &BaselineInfoImpl)

Can `T` just be used here? `TargetLibraryInfoImpl` comes with a such 
constructor: `TargetLibraryInfoImpl(const Triple &T)`


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77952/new/

https://reviews.llvm.org/D77952



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


[PATCH] D77952: [TLI] Reduce copies for TLI and TLA

2020-04-11 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB accepted this revision.
hoyFB added inline comments.
This revision is now accepted and ready to land.



Comment at: llvm/include/llvm/Analysis/TargetLibraryInfo.h:456
+  TargetLibraryAnalysis(const Triple &T)
+  : BaselineInfoImpl(TargetLibraryInfoImpl(T)) {}
+  TargetLibraryAnalysis(const TargetLibraryInfoImpl &BaselineInfoImpl)

hoyFB wrote:
> Can `T` just be used here? `TargetLibraryInfoImpl` comes with a such 
> constructor: `TargetLibraryInfoImpl(const Triple &T)`
Unlikely not. That is an explicit constructor and `BaselineInfoImpl` is an 
`Optional` object.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77952/new/

https://reviews.llvm.org/D77952



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


[PATCH] D69732: [WIP][LTO] Apply SamplePGO pipeline tunes for ThinLTO pre-link to full LTO

2020-07-14 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

In D69732#1771950 , @ormris wrote:

> I've done testing with the following global parameters.
>
> - The base for the branch is llvmorg-10-init-8655-g94a4a2c97f8
> - Used llvm, clang, lld, and llvm-ar from this branch.
> - The sqlite kvtest program was the test payload.
>
>   This test compared an unmodified compiler from the base of the branch with 
> a modified compiler with this patch applied and the loop optimisation passes 
> mentioned above moved to the backend. The results were as follows. All 
> numbers in seconds.
>
>   |Run|Modified LTO|Modified SPGO+LTO|Unmodified SPGO+LTO| 
> |---||-|---| 
> |1|42.00|41.73|42.08| |2|42.30|39.49|42.45| |3|41.21|42.46|42.49| 
> |AVG:|41.84|41.23|42.34|
>
>   TL;DR the average run using a compiler built with the modified SPGO 
> pipeline is about a second faster. Definitely a positive initial result.
>
> In D69732#1730732 , @tejohnson wrote:
>
> > This probably needs to be taken over by someone who cares about full LTO 
> > performance (@wristow or @ormris ?). This patch was some cleanup of the 
> > full LTO sample PGO pipeline, but has a number of issues I enumerate in the 
> > summary.
>
>
> Given the performance improvements here, I'd like to develop this patch 
> further.


@ormris I'd like to follow up on this. We had a similar change internally which 
led up to some gains when combined with SPGO, and we'd like to help move 
forward with this patch here. Would you mind sharing the plan or progress on 
your side? Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D69732/new/

https://reviews.llvm.org/D69732



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


[PATCH] D77484: [Vector] Pass VectLib to LTO backend so TLI build correct vector function list

2020-04-05 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

In D77484#1962445 , @tejohnson wrote:

> We're trying to move towards encoding all of this in the IR. And in fact, I 
> recently implemented a series of patches to make the TLI to be built 
> per-function, and along with some patches from @gchatelet to encode 
> -fno-builtin* as function attributes, we now handle that part of the TLII 
> with IR. See D67923  which is the last patch 
> in the series. We should encode the vectlib as function attributes similarly, 
> and just thread that through to the TLI.


That's an interesting idea. How does the linkage work if two functions have 
different vectlib attributes? Linking against two vectlibs may cause name 
conflicts or other issues.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D77484/new/

https://reviews.llvm.org/D77484



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


[PATCH] D75162: [X86][F16C] Remove cvtph2ps intrinsics and use generic half2float conversion (PR37554)

2020-03-03 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added inline comments.



Comment at: llvm/include/llvm/IR/IntrinsicsX86.td:2551
-  Intrinsic<[llvm_v4f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;
-  def int_x86_vcvtph2ps_256 : GCCBuiltin<"__builtin_ia32_vcvtph2ps256">,
-  Intrinsic<[llvm_v8f32_ty], [llvm_v8i16_ty], [IntrNoMem]>;

Hello, we have some tools generating these intrinsics being removed here. Can 
you suggest what we should generate on LLVM IR with this change?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75162/new/

https://reviews.llvm.org/D75162



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


[PATCH] D76291: [Support] Fix formatted_raw_ostream for UTF-8

2020-03-17 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added inline comments.



Comment at: clang/test/Analysis/checker-plugins.c:120
+// CHECK-CHECKER-OPTION-HELP-SAME: example checker opt. (default:
+// CHECK-CHECKER-OPTION-HELP-NEXT: false)

LGTM, thanks for fixing this!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D76291/new/

https://reviews.llvm.org/D76291



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


[PATCH] D74814: IR printing for single function with the new pass manager.

2020-02-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB created this revision.
Herald added subscribers: llvm-commits, cfe-commits, hiraditya.
Herald added projects: clang, LLVM.
hoyFB added a reviewer: wenlei.
hoyFB added a subscriber: wenlei.

The IR printing always prints out all functions in a module with the new pass 
manager, even with -filter-print-funcs specified. This is being fixed in this 
change. However, there are two exceptions, i.e, with user-specified wildcast 
switch -filter-print-funcs=* or -print-module-scope, under which IR of all 
functions should be printed.

Test Plan:
make check-clang
make check-llvm


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74814

Files:
  clang/test/Misc/print-single-function.c
  llvm/lib/Passes/StandardInstrumentations.cpp


Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@
   llvm_unreachable("Unknown IR unit");
 }
 
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
-  dbgs() << Banner << Extra << "\n";
-  M->print(dbgs(), nullptr, false);
-}
 void printIR(const Function *F, StringRef Banner,
  StringRef Extra = StringRef()) {
   if (!llvm::isFunctionInPrintList(F->getName()))
 return;
   dbgs() << Banner << Extra << "\n" << static_cast(*F);
 }
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
+  if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+dbgs() << Banner << Extra << "\n";
+M->print(dbgs(), nullptr, false);
+  } else {
+for (const auto &F : M->functions()) {
+  printIR(&F, Banner, Extra);
+}
+  }
+}
+
 void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
  StringRef Extra = StringRef()) {
   bool BannerPrinted = false;
Index: clang/test/Misc/print-single-function.c
===
--- /dev/null
+++ clang/test/Misc/print-single-function.c
@@ -0,0 +1,21 @@
+// Testing single function IR printing with the new pass manager.  there are 
two exceptions, i.e, with user-specified wildcast switch -filter-print-funcs=* 
or -print-module-scope, under which IR of all functions should be printed.
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm 
-print-after-all -mllvm -filter-print-funcs=foo %s -o %t 2>&1 | FileCheck %s 
--check-prefix=FOO
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm 
-print-after-all -mllvm -filter-print-funcs=foo %s -mllvm -print-module-scope 
-o %t 2>&1 | FileCheck %s --check-prefix=ALL
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm 
-print-after-all -mllvm -filter-print-funcs=* %s -o %t 2>&1 | FileCheck %s 
--check-prefix=ALL
+
+// FOO: *** IR Dump After AlwaysInlinerPass ***
+// FOO: define void @foo()
+// FOO-NOT: define void @bar()
+
+// ALL: *** IR Dump After AlwaysInlinerPass ***
+// ALL-NEXT: ; ModuleID =
+// ALL: define void @foo()
+// ALL: define void @bar()
+
+void bar() {
+  return;
+}
+
+void foo() {
+  bar();
+}


Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@
   llvm_unreachable("Unknown IR unit");
 }
 
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
-  dbgs() << Banner << Extra << "\n";
-  M->print(dbgs(), nullptr, false);
-}
 void printIR(const Function *F, StringRef Banner,
  StringRef Extra = StringRef()) {
   if (!llvm::isFunctionInPrintList(F->getName()))
 return;
   dbgs() << Banner << Extra << "\n" << static_cast(*F);
 }
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) {
+  if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+dbgs() << Banner << Extra << "\n";
+M->print(dbgs(), nullptr, false);
+  } else {
+for (const auto &F : M->functions()) {
+  printIR(&F, Banner, Extra);
+}
+  }
+}
+
 void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
  StringRef Extra = StringRef()) {
   bool BannerPrinted = false;
Index: clang/test/Misc/print-single-function.c
===
--- /dev/null
+++ clang/test/Misc/print-single-function.c
@@ -0,0 +1,21 @@
+// Testing single function IR printing with the new pass manager.  there are two exceptions, i.e, with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope, under which IR of all functions should be printed.
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm -print-after-all -mllvm -filter-print-funcs=foo %s -o %t 2>&1 | FileCheck %s --check-prefix=FOO
+// RUN: %clang_cc1 -emit-llvm -fexperimental-new-pass-manager -mllvm -print-after-all -mllvm -filte

[PATCH] D74814: IR printing for single function with the new pass manager.

2020-02-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB added a comment.

In D74814#1882064 , @wenlei wrote:

> Thanks for fixing this. Could you use `.ll` IR file as test case and place it 
> alongside with `test/Other/module-pass-printer.ll` or just reuse that one? We 
> can also use `opt` to invoke new pass manager, so it doesn't need to be a 
> clang test.


Sounds good. I was trying to figure out how to invoke the new pass manager with 
OPT. Is there a command line switch to do that?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74814/new/

https://reviews.llvm.org/D74814



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


[PATCH] D74814: IR printing for single function with the new pass manager.

2020-02-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB updated this revision to Diff 245474.
hoyFB added a comment.

Updating D74814 : IR printing for single 
function with the new pass manager.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74814/new/

https://reviews.llvm.org/D74814

Files:
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/module-pass-printer.ll


Index: llvm/test/Other/module-pass-printer.ll
===
--- llvm/test/Other/module-pass-printer.ll
+++ llvm/test/Other/module-pass-printer.ll
@@ -1,14 +1,28 @@
 ; Check pass name is only printed once.
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck 
%s
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo,bar | FileCheck %s
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo | FileCheck %s  -check-prefix=FOO
 
 ; Check pass name is not printed if a module doesn't include any function 
specified in -filter-print-funcs.
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
 
+; Check whole module is printed with user-specified wildcast switch 
-filter-print-funcs=* or -print-module-scope
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all | 
FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+
 ; CHECK: *** IR Dump After Force set function attributes ***
 ; CHECK-NOT: *** IR Dump After Force set function attributes ***
 ; EMPTY-NOT: *** IR Dump After Force set function attributes ***
 
+; FOO:  IR Dump After ForceFunctionAttrsPass
+; FOO:  define void @foo
+; FOO-NOT:  define void @bar
+
+; ALL:  IR Dump After ForceFunctionAttrsPass
+; ALL:  define void @foo
+; ALL:  define void @bar
+
 define void @foo() {
   ret void
 }
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@
   llvm_unreachable("Unknown IR unit");
 }
 
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
-  dbgs() << Banner << Extra << "\n";
-  M->print(dbgs(), nullptr, false);
-}
 void printIR(const Function *F, StringRef Banner,
  StringRef Extra = StringRef()) {
   if (!llvm::isFunctionInPrintList(F->getName()))
 return;
   dbgs() << Banner << Extra << "\n" << static_cast(*F);
 }
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
+  if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+dbgs() << Banner << Extra << "\n";
+M->print(dbgs(), nullptr, false);
+  } else {
+for (const auto &F : M->functions()) {
+  printIR(&F, Banner, Extra);
+}
+  }
+}
+
 void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
  StringRef Extra = StringRef()) {
   bool BannerPrinted = false;


Index: llvm/test/Other/module-pass-printer.ll
===
--- llvm/test/Other/module-pass-printer.ll
+++ llvm/test/Other/module-pass-printer.ll
@@ -1,14 +1,28 @@
 ; Check pass name is only printed once.
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck %s
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=foo,bar | FileCheck %s
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=foo | FileCheck %s  -check-prefix=FOO
 
 ; Check pass name is not printed if a module doesn't include any function specified in -filter-print-funcs.
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all -filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
 
+; Check whole module is printed with user-specified wildcast switch -filter-print-funcs=* or -print-module-scope
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all -filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+
 ; CHECK: *** IR Dump After Force set function attributes ***
 ; CHECK-NOT: *** IR Dump After Force set function attributes ***
 ; EMPTY-NOT: *** IR Dump After Force set function attributes ***
 
+; FOO:  IR Dump After ForceFunctionAttrsPass
+; FOO:  define void @foo
+; FOO-NOT:  define void 

[PATCH] D74814: IR printing for single function with the new pass manager.

2020-02-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoyFB updated this revision to Diff 245484.
hoyFB added a comment.

Updating D74814 : IR printing for single 
function with the new pass manager.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74814/new/

https://reviews.llvm.org/D74814

Files:
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/test/Other/module-pass-printer.ll


Index: llvm/test/Other/module-pass-printer.ll
===
--- llvm/test/Other/module-pass-printer.ll
+++ llvm/test/Other/module-pass-printer.ll
@@ -1,13 +1,43 @@
 ; Check pass name is only printed once.
-; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck 
%s
-; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo,bar | FileCheck %s
+; Check only one function is printed
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo | FileCheck %s  -check-prefix=FOO
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo | FileCheck %s  -check-prefix=FOO
+
+; Check pass name is only printed once.
+; Check both functions are printed
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo,bar | FileCheck %s -check-prefix=BOTH
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo,bar | FileCheck %s -check-prefix=BOTH
 
 ; Check pass name is not printed if a module doesn't include any function 
specified in -filter-print-funcs.
 ; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=baz | FileCheck %s -allow-empty -check-prefix=EMPTY
+
+; Check whole module is printed with user-specified wildcast switch 
-filter-print-funcs=* or -print-module-scope
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all | FileCheck 
%s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -forceattrs -disable-output  -print-after-all 
-filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all | 
FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=* | FileCheck %s -check-prefix=ALL
+; RUN: opt < %s 2>&1 -passes=forceattrs -disable-output -print-after-all 
-filter-print-funcs=foo -print-module-scope | FileCheck %s -check-prefix=ALL
+
+; FOO:  IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
+; FOO:  define void @foo
+; FOO-NOT:  define void @bar
+; FOO-NOT:  IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
+
+; BOTH: IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
+; BOTH: define void @foo
+; BOTH: define void @bar
+; BOTH-NOT: IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
+; BOTH-NOT: ModuleID =
+
+; EMPTY-NOT: IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
 
-; CHECK: *** IR Dump After Force set function attributes ***
-; CHECK-NOT: *** IR Dump After Force set function attributes ***
-; EMPTY-NOT: *** IR Dump After Force set function attributes ***
+; ALL:  IR Dump After {{Force set function attributes|ForceFunctionAttrsPass}}
+; ALL:  ModuleID =
+; ALL:  define void @foo
+; ALL:  define void @bar
+; ALL-NOT: IR Dump After {{Force set function 
attributes|ForceFunctionAttrsPass}}
 
 define void @foo() {
   ret void
Index: llvm/lib/Passes/StandardInstrumentations.cpp
===
--- llvm/lib/Passes/StandardInstrumentations.cpp
+++ llvm/lib/Passes/StandardInstrumentations.cpp
@@ -70,16 +70,24 @@
   llvm_unreachable("Unknown IR unit");
 }
 
-void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
-  dbgs() << Banner << Extra << "\n";
-  M->print(dbgs(), nullptr, false);
-}
 void printIR(const Function *F, StringRef Banner,
  StringRef Extra = StringRef()) {
   if (!llvm::isFunctionInPrintList(F->getName()))
 return;
   dbgs() << Banner << Extra << "\n" << static_cast(*F);
 }
+
+void printIR(const Module *M, StringRef Banner, StringRef Extra = StringRef()) 
{
+  if (llvm::isFunctionInPrintList("*") || llvm::forcePrintModuleIR()) {
+dbgs() << Banner << Extra << "\n";
+M->print(dbgs(), nullptr, false);
+  } else {
+for (const auto &F : M->functions()) {
+  printIR(&F, Banner, Extra);
+}
+  }
+}
+
 void printIR(const LazyCallGraph::SCC *C, StringRef Banner,
  StringRef Extra = StringRef()) {
   bool BannerPrinted = false;


Index: llvm/tes

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320680.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,9 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,9 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegF

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:609-610
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");

wmi wrote:
> The third arg of Args.hasFlag defaults to true, which means 
> -plugin-opt=pseudo-probe-for-profiling will be inserted even if no 
> -fpseudo-probe-for-profiling or -fno-pseudo-probe-for-profiling is provided. 
> Is it expected?
Good catch, it's not expected. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320686.
hoy added a comment.

Addressing Wei's comment.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/inclu

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy marked an inline comment as done.
hoy added inline comments.



Comment at: clang/test/Driver/pseudo-probe-lto.c:6
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+

wmi wrote:
> Better add another check of NOPROBE when neither -fpseudo-probe-for-profiling 
> or -fno-pseudo-probe-for-profiling is provided. 
Good point, test case added.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-02-02 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320822.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{!"clang version 3.9.0"}
+!12 = !DILocation(line: 2, column: 20, scope: !4)
+!13 = distinct !{!13, !14}
+!14 = !{!"llvm.loop.unroll.full"}
Index: llvm/test/Transforms/Samp

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-02-02 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
hoy marked an inline comment as done.
Closed by commit rGd3e2e3740d07: [CSSPGO] Passing the clang driver switch 
-fpseudo-probe-for-profiling to theā€¦ (authored by hoy).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1155,7 +1155,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultFalse,
   PosFlag, NegFlag,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling, false))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> S

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-02-02 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 320844.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{!"clang version 3.9.0"}
+!12 = !DILocation(line: 2, column: 20, scope: !4)
+!13 = distinct !{!13, !14}
+!14 = !{!"llvm.loop.unroll.full"}
Index: llvm/test/Transforms/Samp

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-02-02 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3d89b3cbec23: [CSSPGO] Introducing distribution factor for 
pseudo probe. (authored by hoy).

Changed prior to commit:
  https://reviews.llvm.org/D93264?vs=320844&id=320873#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY-DAG: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY-DAG: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = 

[PATCH] D96354: Avoid conflicts between debug-info and pseudo-probe profiling

2021-02-09 Thread Hongtao Yu via Phabricator via cfe-commits
hoy accepted this revision.
hoy added a comment.
This revision is now accepted and ready to land.

Thanks for fixing these issues! LGTM.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96354/new/

https://reviews.llvm.org/D96354

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


[PATCH] D96354: Avoid conflicts between debug-info and pseudo-probe profiling

2021-02-16 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D96354#2554129 , @probinson wrote:

>> the driver had a redundant pass-through of the option
>
> I could've sworn it worked to remove that, but it didn't when I rebased, so 
> that's gone from the final patch (i.e, the explicit pass-through in the 
> driver is still there).  It's a functionally separate topic anyway.

Soung

In D96354#2566273 , @dblaikie wrote:

> @hoy Could you explain a bit further why these two features are 
> incompatible/what the crash looks like? At first glance I wouldn't expect any 
> debug info mode to be incompatible with any non-debug-info mode (maybe less 
> useful, but not crashy levels of incompatible).

Both debug-info mode and the pseudo-probe mode use the Dwarf discriminators but 
for different purposes. Therefore the passes that populate the Dwarf 
discriminators should not be scheduled at the same time. The crash was like 
compiler fatal error before this change. It


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96354/new/

https://reviews.llvm.org/D96354

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


[PATCH] D96354: Avoid conflicts between debug-info and pseudo-probe profiling

2021-02-16 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D96354#2566511 , @dblaikie wrote:

> In D96354#2566502 , @hoy wrote:
>
>> In D96354#2554129 , @probinson 
>> wrote:
>>
 the driver had a redundant pass-through of the option
>>>
>>> I could've sworn it worked to remove that, but it didn't when I rebased, so 
>>> that's gone from the final patch (i.e, the explicit pass-through in the 
>>> driver is still there).  It's a functionally separate topic anyway.
>>
>> Soung
>>
>> In D96354#2566273 , @dblaikie wrote:
>>
>>> @hoy Could you explain a bit further why these two features are 
>>> incompatible/what the crash looks like? At first glance I wouldn't expect 
>>> any debug info mode to be incompatible with any non-debug-info mode (maybe 
>>> less useful, but not crashy levels of incompatible).
>>
>> Both debug-info mode and the pseudo-probe mode use the Dwarf discriminators 
>> but for different purposes. Therefore the passes that populate the Dwarf 
>> discriminators should not be scheduled at the same time. The crash was like 
>> compiler fatal error before this change. It
>
> Oh, that's subtle and seems somewhat unfortunate. Is that documented 
> somewhere I could read more about?

The summary of this diff has some information https://reviews.llvm.org/D91756 . 
Unfortunately we haven't rolled out a formal document yet.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D96354/new/

https://reviews.llvm.org/D96354

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


[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks

2020-08-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: llvm-commits, cfe-commits, dang, laytonio, asbirlea, 
hiraditya, mgorny.
Herald added projects: clang, LLVM.
hoy requested review of this revision.
Herald added a subscriber: jdoerfert.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86193

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/emit-pseudo-probe.c
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/CodeGen/MachineInstr.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/CodeGen/SelectionDAGNodes.h
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Support/TargetOpcodes.def
  llvm/include/llvm/Target/Target.td
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/lib/IR/BasicBlock.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/CMakeLists.txt
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/Evaluator.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll

Index: llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
+; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
+; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+;
+;; Check the generation of pseudoprobe intrinsic call.
+
+define void @foo(i32 %x) {
+bb0:
+  %cmp = icmp eq i32 %x, 0
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID:]], 1, 0
+  br i1 %cmp, label %bb1, label %bb2
+
+bb1:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 3, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb2:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 2, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb3:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4)
+  ret void
+}
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5122,7 +5122,9 @@
 
 if (I->mayReadOrWriteMemory() &&
 (!isa(I) ||
- cast(I)->getIntrinsicID() != Intrinsic::sideeffect)) {
+ (cast(I)->getIntrinsicID() != Intrinsic::sideeffect &&
+  cast(I)->getIntrinsicID() !=
+  Intrinsic::pseudoprobe))) {
   // Update the linked list of memory accessing instructions.
   if (CurrentLoadStore) {
 CurrentLoadStore->NextLoadStore = SD;
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7167,7 +7167,8 @@
 
   Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
   if (ID && (ID == Intrinsic::assume || ID == Intrinsic::lifetime_end ||
- ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect))
+ ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect ||
+ ID == Intrinsic::pseudoprobe))
 return nullptr;
 
   auto willWiden = [&](unsigned VF) -> bool {
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ 

[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks

2020-08-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 286476.
hoy added a comment.

Updating D86193 : [CSSPGO] Pseudo probe 
instrumentation for basic blocks


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/emit-pseudo-probe.c
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/CodeGen/MachineInstr.h
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/CodeGen/SelectionDAGNodes.h
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Support/TargetOpcodes.def
  llvm/include/llvm/Target/Target.td
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/lib/IR/BasicBlock.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/CMakeLists.txt
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/Evaluator.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll

Index: llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
+; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
+; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+;
+;; Check the generation of pseudoprobe intrinsic call.
+
+define void @foo(i32 %x) {
+bb0:
+  %cmp = icmp eq i32 %x, 0
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID:]], 1, 0
+  br i1 %cmp, label %bb1, label %bb2
+
+bb1:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 3, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb2:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 2, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb3:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4)
+  ret void
+}
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5122,7 +5122,9 @@
 
 if (I->mayReadOrWriteMemory() &&
 (!isa(I) ||
- cast(I)->getIntrinsicID() != Intrinsic::sideeffect)) {
+ (cast(I)->getIntrinsicID() != Intrinsic::sideeffect &&
+  cast(I)->getIntrinsicID() !=
+  Intrinsic::pseudoprobe))) {
   // Update the linked list of memory accessing instructions.
   if (CurrentLoadStore) {
 CurrentLoadStore->NextLoadStore = SD;
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7167,7 +7167,8 @@
 
   Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
   if (ID && (ID == Intrinsic::assume || ID == Intrinsic::lifetime_end ||
- ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect))
+ ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect ||
+ ID == Intrinsic::pseudoprobe))
 return nullptr;
 
   auto willWiden = [&](unsigned VF) -> bool {
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
@@ -666,6 +666,10 @@
cast

[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-08-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 286664.
hoy edited the summary of this revision.
hoy added a comment.

Updating D86193 : [CSSPGO] Pseudo probe 
instrumentation for basic blocks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/emit-pseudo-probe.c
  llvm/include/llvm/Analysis/TargetTransformInfoImpl.h
  llvm/include/llvm/CodeGen/BasicTTIImpl.h
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/ISDOpcodes.h
  llvm/include/llvm/CodeGen/MachineInstr.h
  llvm/include/llvm/CodeGen/SelectionDAG.h
  llvm/include/llvm/CodeGen/SelectionDAGNodes.h
  llvm/include/llvm/IR/BasicBlock.h
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Support/TargetOpcodes.def
  llvm/include/llvm/Target/Target.td
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/Analysis/AliasSetTracker.cpp
  llvm/lib/Analysis/ValueTracking.cpp
  llvm/lib/Analysis/VectorUtils.cpp
  llvm/lib/CodeGen/Analysis.cpp
  llvm/lib/CodeGen/CodeGenPrepare.cpp
  llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp
  llvm/lib/CodeGen/SelectionDAG/SelectionDAGISel.cpp
  llvm/lib/IR/BasicBlock.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Transforms/IPO/CMakeLists.txt
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/lib/Transforms/Scalar/TailRecursionElimination.cpp
  llvm/lib/Transforms/Utils/Evaluator.cpp
  llvm/lib/Transforms/Utils/SimplifyCFG.cpp
  llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
  llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
  llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
  llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll

Index: llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
@@ -0,0 +1,29 @@
+; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
+; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
+; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+;
+;; Check the generation of pseudoprobe intrinsic call.
+
+define void @foo(i32 %x) {
+bb0:
+  %cmp = icmp eq i32 %x, 0
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID:]], 1, 0
+  br i1 %cmp, label %bb1, label %bb2
+
+bb1:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 3, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb2:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 2, 0
+; CHECK-MIR: PSEUDO_PROBE [[#GUID]], 4, 0
+  br label %bb3
+
+bb3:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4)
+  ret void
+}
Index: llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5122,7 +5122,9 @@
 
 if (I->mayReadOrWriteMemory() &&
 (!isa(I) ||
- cast(I)->getIntrinsicID() != Intrinsic::sideeffect)) {
+ (cast(I)->getIntrinsicID() != Intrinsic::sideeffect &&
+  cast(I)->getIntrinsicID() !=
+  Intrinsic::pseudoprobe))) {
   // Update the linked list of memory accessing instructions.
   if (CurrentLoadStore) {
 CurrentLoadStore->NextLoadStore = SD;
Index: llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
===
--- llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
+++ llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
@@ -7167,7 +7167,8 @@
 
   Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
   if (ID && (ID == Intrinsic::assume || ID == Intrinsic::lifetime_end ||
- ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect))
+ ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect ||
+ ID == Intrinsic::pseudoprobe))
 return nullptr;
 
   auto willWiden = [&](unsigned VF) -> bool {
Index: llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
===
--- llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp
+++ llvm/lib/Transforms/Vectorize/LoadStoreVectorizer.cpp

[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-08-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D86193#2227129 , @davidxl wrote:

> A heads up -- I won't be able to review patch until mid Sept. Hope this is 
> fine.

Thanks for the heads-up. That's fine. We can wait for your input.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-08-24 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D86193#2232609 , @wmi wrote:

> Thanks for the patch! A few questions:
>
>> probe blocks some CFG transformations that can mess up profile correlation.
>
> Can you enumerate some CFG transformations which be blocked? Is it possible 
> that some CFG transformations being blocked are actually beneficial for later 
> optimizations?

There are some optimizations such as if-convert, tail call elimination, that 
were initially blocked by the pseudo probe intrinsic but is now unblocked by 
fixes included in this change. With the current change we do not see perf 
degradation out of SPEC and one of our internal large services.

The main optimizations left blocked intentionally are those that merge blocks 
for smaller code size, such as tail merge which is the opposite of jump 
threading. We believe that those optimizations are not very beneficial for 
performance and AutoFDO. But if things are changed we can always unblock them.

> Are the intrinsic probes counted when computing bb size and function size?

That's a good question. On the IR level, pseudo probe intrinsics are treated in 
a similar way of the debug intrinsics and the side-effect intrinsics. On the 
MIR level, pseudo probe intrinsics are implemented as a 
`StandardPseudoInstruction`. So they should not be counted towards real code 
size.

> And could you split the patches into small parts for easier review. For 
> example,  Add the intrinsic support in IR and MIR. SampleProfileProbe pass. 
> -fpseudo-probe-for-profiling support. changes in various passes.

Thanks for the suggestion. Agreed the current patch is too big to review. Will 
come up with a list of breakdowns.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D86502: [CSSPGO] Pseudo probe instrumentation for basic blocks

2020-08-24 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: llvm-commits, cfe-commits, wenlei, dang, dexonsmith, 
hiraditya.
Herald added projects: clang, LLVM.
hoy requested review of this revision.

This change introduces a new clang switch `-fpseudo-probe-for-profiling` to 
enable AutoFDO with pseudo instrumentation. Please refer to 
https://reviews.llvm.org/D86193 for the whole story.

One implication from pseudo-probe instrumentation is that the profile is now 
sensitive to CFG changes. We perform the pseudo instrumentation very early in 
the pre-LTO pipeline, before any CFG transformation. This ensures that the CFG 
instrumented and annotated is stable and optimization-resilient.

The early instrumentation also allows the inliner to duplicate probes for 
inlined instances. When a probe along with the other instructions of a callee 
function are inlined into its caller function, the GUID of the callee function 
goes with the probe. This allows samples collected on inlined probes to be 
reported for the original callee function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D86502

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/emit-pseudo-probe.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -901,6 +901,12 @@
 OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
   ModulePassManager MPM(DebugLogging);
 
+  // Place pseudo probe instrumentation as the first pass of the pipeline to
+  // minimize the impact of optimization changes.
+  if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
+  Phase != ThinLTOPhase::PostLink)
+MPM.addPass(SampleProfileProbePass(TM));
+
   bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
 
   // In ThinLTO mode, when flattened profile is used, all the available
@@ -1254,7 +1260,7 @@
   for (auto &C : PipelineStartEPCallbacks)
 C(MPM);
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Add the core simplification pipeline.
@@ -1278,7 +1284,7 @@
   // Force any function attributes we want the rest of the pipeline to observe.
   MPM.addPass(ForceFunctionAttrsPass());
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Apply module pipeline start EP callback.
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -36,11 +36,15 @@
   enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
   PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
  std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
- CSPGOAction CSAction = NoCSAction, bool SamplePGOSupport = false)
+ CSPGOAction CSAction = NoCSAction,
+ bool DebugInfoForProfiling = false,
+ bool PseudoProbeForProfiling = false)
   : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
 ProfileRemappingFile(ProfileRemappingFile), Action(Action),
-CSAction(CSAction),
-SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
+CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
+  (Action == SampleUse &&
+   !PseudoProbeForProfiling)),
+PseudoProbeForProfiling(PseudoProbeForProfiling) {
 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
 // callback with IRUse action without ProfileFile.
 
@@ -55,16 +59,22 @@
 // a profile.
 assert(this->CSAction != CSIRUse || this->Action == IRUse);
 
-// If neither Action nor CSAction, SamplePGOSupport needs to be true.
+// If neither Action nor CSAction, DebugInfoForProfiling or
+// PseudoProbeForProfiling needs to be true.
 assert(this->Action != NoAction || this->CSAction != NoCSAction ||
-   this->SamplePGOSupport);
+   this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
+
+// Pseudo probe instrumentation should only work with autoFDO or no FDO.
+assert(!this->PseudoProbeForProfiling || this->Action == NoAction ||
+   this->Action == SampleUse);
   }
   std::string ProfileFile;
   std::string CSProfileGenFile;
   std::string ProfileRemappingFile;
   PGOAction Action;
   CSPGOAction CSAction;
-  bo

[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-08-26 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D86193#2240353 , @wmi wrote:

>> There are some optimizations such as if-convert, tail call elimination, that 
>> were initially blocked by the pseudo probe intrinsic but is now unblocked by 
>> fixes included in this change. With the current change we do not see perf 
>> degradation out of SPEC and one of our internal large services.
>> The main optimizations left blocked intentionally are those that merge 
>> blocks for smaller code size, such as tail merge which is the opposite of 
>> jump threading. We believe that those optimizations are not very beneficial 
>> for performance and AutoFDO.
>
> If the optimizations are not very beneficial for performance and AutoFDO and 
> should be blocked, it may be better to block them in a more general way and 
> not depend on pseudo probe, because blocking them may also be beneficial for 
> debug info based AutoFDO.

In theory, yes, we should have a black list of transforms (mainly related to 
block merge) that are not needed by AutoFDO and block them. In reality it might 
take quite some efforts to figure them out. Pseudo probe, on the other hand, 
starts with blocking those transforms in the first place and relax the ones 
that might actually help AutoFDO.

> Another reason is that pseudo probe looks pretty much like debug information 
> to me. They are used to annotate the IR but shouldn't affect the 
> transformation. Binaries built w/wo debug information are required to be 
> identical in LLVM. I think that requirement could be applied on pseudo probe 
> as well. It is even better to have some test to enforce it so that no change 
> in the future could break the requirement.

Good point! Yes, pseudo probe is implemented in a similar way with the debug 
intrinsics. However they are not guaranteed to not affect the codegen since its 
main purpose is to achieve an accurate profile correlation with low cost. 
Regarding the cost, it sits somewhere between the debug intrinsics and the PGO 
instrumentation and close to a zero cost in practice. Agreed that it would be 
better to have tests protect the pseudo probe cost from going too high, but not 
sure which optimizations we should start with. Maybe to start with some 
critical optimizations like inlining, vectorization?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-08-26 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D86193#2240596 , @wmi wrote:

> In D86193#2240502 , @hoy wrote:
>
>> In D86193#2240353 , @wmi wrote:
>>
 There are some optimizations such as if-convert, tail call elimination, 
 that were initially blocked by the pseudo probe intrinsic but is now 
 unblocked by fixes included in this change. With the current change we do 
 not see perf degradation out of SPEC and one of our internal large 
 services.
 The main optimizations left blocked intentionally are those that merge 
 blocks for smaller code size, such as tail merge which is the opposite of 
 jump threading. We believe that those optimizations are not very 
 beneficial for performance and AutoFDO.
>>>
>>> If the optimizations are not very beneficial for performance and AutoFDO 
>>> and should be blocked, it may be better to block them in a more general way 
>>> and not depend on pseudo probe, because blocking them may also be 
>>> beneficial for debug info based AutoFDO.
>>
>> In theory, yes, we should have a black list of transforms (mainly related to 
>> block merge) that are not needed by AutoFDO and block them. In reality it 
>> might take quite some efforts to figure them out. Pseudo probe, on the other 
>> hand, starts with blocking those transforms in the first place and relax the 
>> ones that might actually help AutoFDO.
>>
>>> Another reason is that pseudo probe looks pretty much like debug 
>>> information to me. They are used to annotate the IR but shouldn't affect 
>>> the transformation. Binaries built w/wo debug information are required to 
>>> be identical in LLVM. I think that requirement could be applied on pseudo 
>>> probe as well. It is even better to have some test to enforce it so that no 
>>> change in the future could break the requirement.
>>
>> Good point! Yes, pseudo probe is implemented in a similar way with the debug 
>> intrinsics. However they are not guaranteed to not affect the codegen since 
>> its main purpose is to achieve an accurate profile correlation with low 
>> cost. Regarding the cost, it sits somewhere between the debug intrinsics and 
>> the PGO instrumentation and close to a zero cost in practice.
>
> I see. It makes sense to fix up some important transformations to achieve the 
> goal of low cost. To achieve the goal of not affecting codegen needs a lot 
> more effort to test and fix up all over the pipeline. I don't mean to have it 
> ready in the patch, but I think it maybe something worthy to strive for later 
> on.

Sounds good, we will be accumulating a list of AutoFDO-unfriendly transforms 
over time.

>> Agreed that it would be better to have tests protect the pseudo probe cost 
>> from going too high, but not sure which optimizations we should start with. 
>> Maybe to start with some critical optimizations like inlining, vectorization?
>
> The test I have in my mind comes from debug info. It is to bootstrap llvm 
> with and without debug information. The test is to check whether the binaries 
> built after stripping the debug information are identical. I am thinking 
> pseudo probe can have such test setup somewhere sometime in the future. Same 
> as above, it doesn't have to be ready currently.

I like the idea. It would catch a regression on pseudo probe with new 
optimization changes. Let me think about it. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-08-28 Thread Hongtao Yu via Phabricator via cfe-commits
hoy marked an inline comment as done.
hoy added a comment.

In D86502#2245460 , @wmi wrote:

>> The early instrumentation also allows the inliner to duplicate probes for 
>> inlined instances. When a probe along with the other instructions of a 
>> callee function are inlined into its caller function, the GUID of the callee 
>> function goes with the probe. This allows samples collected on inlined 
>> probes to be reported for the original callee function.
>
> Just get a question from reading the above. Suppose `A` only has one BB and 
> the BB has one PseudoProbe in it. If function `A` is inlined into `B1` and 
> `B2` and both `B1` and `B2` inlined into `C`, the PseudoProbe from `A` will 
> have two copies in `C` both carrying GUID of `A`. How the samples collected 
> from `A` inlined into `B1` inlined into `C` are categorized differently from 
> `A` inlined into `B2` inlined into `C`, especially when debug information is 
> not enabled (so no inline stack information in the binary)?

This is a very good question. Inlined functions are differentiated by their 
original callsites. A pseudo probe is allocated for each callsite in the 
`SampleProfileProbe` pass. Nested inlining will produce a stack of pseudo 
probes, similar with the Dwarf inline stack. The work is not included in the 
first set of patches.




Comment at: llvm/include/llvm/Passes/PassBuilder.h:67-69
+// Pseudo probe instrumentation should only work with autoFDO or no FDO.
+assert(!this->PseudoProbeForProfiling || this->Action == NoAction ||
+   this->Action == SampleUse);

wmi wrote:
> Need it to work with more types of action for example instrumentation FDO or 
> cs instrumentation FDO. For instrumentation FDO optimized binary, we may want 
> to collect AutoFDO profile for it for performance comparison, enhance the 
> intrumentation profile with AutoFDO profile to make the profile more 
> production representative, ...
> 
> Currently debug information based AutoFDO supports it.
I see. I just removed this assert and the let assert above handle both 
`DebugInfoForProfiling` and `PseudoProbeForProfiling`.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

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


[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-08-28 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 288716.
hoy marked an inline comment as done.
hoy added a comment.

Updating D86502 : [CSSPGO] A Clang switch 
-fpseudo-probe-for-profiling for pseudo-probe instrumentation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/emit-pseudo-probe.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -901,6 +901,12 @@
 OptimizationLevel Level, ThinLTOPhase Phase, bool DebugLogging) {
   ModulePassManager MPM(DebugLogging);
 
+  // Place pseudo probe instrumentation as the first pass of the pipeline to
+  // minimize the impact of optimization changes.
+  if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
+  Phase != ThinLTOPhase::PostLink)
+MPM.addPass(SampleProfileProbePass(TM));
+
   bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
 
   // In ThinLTO mode, when flattened profile is used, all the available
@@ -1254,7 +1260,7 @@
   for (auto &C : PipelineStartEPCallbacks)
 C(MPM);
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Add the core simplification pipeline.
@@ -1278,7 +1284,7 @@
   // Force any function attributes we want the rest of the pipeline to observe.
   MPM.addPass(ForceFunctionAttrsPass());
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Apply module pipeline start EP callback.
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -36,11 +36,15 @@
   enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
   PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
  std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
- CSPGOAction CSAction = NoCSAction, bool SamplePGOSupport = false)
+ CSPGOAction CSAction = NoCSAction,
+ bool DebugInfoForProfiling = false,
+ bool PseudoProbeForProfiling = false)
   : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
 ProfileRemappingFile(ProfileRemappingFile), Action(Action),
-CSAction(CSAction),
-SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
+CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
+  (Action == SampleUse &&
+   !PseudoProbeForProfiling)),
+PseudoProbeForProfiling(PseudoProbeForProfiling) {
 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
 // callback with IRUse action without ProfileFile.
 
@@ -55,16 +59,18 @@
 // a profile.
 assert(this->CSAction != CSIRUse || this->Action == IRUse);
 
-// If neither Action nor CSAction, SamplePGOSupport needs to be true.
+// If neither Action nor CSAction, DebugInfoForProfiling or
+// PseudoProbeForProfiling needs to be true.
 assert(this->Action != NoAction || this->CSAction != NoCSAction ||
-   this->SamplePGOSupport);
+   this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
   }
   std::string ProfileFile;
   std::string CSProfileGenFile;
   std::string ProfileRemappingFile;
   PGOAction Action;
   CSPGOAction CSAction;
-  bool SamplePGOSupport;
+  bool DebugInfoForProfiling;
+  bool PseudoProbeForProfiling;
 };
 
 /// Tunable parameters for passes in the default pipelines.
Index: clang/test/CodeGen/emit-pseudo-probe.c
===
--- /dev/null
+++ clang/test/CodeGen/emit-pseudo-probe.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O2  -fexperimental-new-pass-manager -fpseudo-probe-for-profiling -g -emit-llvm -S -o - %s | FileCheck %s
+
+// Check the generation of pseudoprobe intrinsic call
+
+void bar();
+void go();
+
+void foo(int x) {
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1)
+  if (x == 0)
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2)
+bar();
+  else
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3)
+go();
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4)
+}
Index: clang/lib/Frontend/CompilerInvocation.cpp
===

[PATCH] D87853: [Sema] Update specialization iterator after template argument deduction.

2020-09-17 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: cfe-commits, wenlei.
Herald added a project: clang.
hoy requested review of this revision.

Template argument deduction may update the underlying specialization container 
and invalidate previous iterators of the container. This triggered an assert 
(in DeclTemplate.cpp) and corrupted the heap with writing through invalid 
iterators. This change recomputes invalided iterators in place before they are 
referenced.

Test Plan:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87853

Files:
  clang/lib/Sema/SemaTemplate.cpp


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -4471,7 +4471,16 @@
   // Note that we do not instantiate a definition until we see an odr-use
   // in DoMarkVarDeclReferenced().
   // FIXME: LateAttrs et al.?
-  VarTemplateSpecializationDecl *Decl = BuildVarTemplateInstantiation(
+  // Search for the variable template specialization declaration that
+  // corresponds to these arguments again to get an up-to-date InsertPos.
+  // The template argument deduction in between may update the underlying
+  // specialization container and invalidate previous iterators.
+  VarTemplateSpecializationDecl *Decl =
+  Template->findSpecialization(Converted, InsertPos);
+  // Assert we should not have a variable template specialization, otherwise we
+  // should have returned early.
+  assert(!Decl);
+  Decl = BuildVarTemplateInstantiation(
   Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
   Converted, TemplateNameLoc, InsertPos /*, LateAttrs, StartingScope*/);
   if (!Decl)


Index: clang/lib/Sema/SemaTemplate.cpp
===
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -4471,7 +4471,16 @@
   // Note that we do not instantiate a definition until we see an odr-use
   // in DoMarkVarDeclReferenced().
   // FIXME: LateAttrs et al.?
-  VarTemplateSpecializationDecl *Decl = BuildVarTemplateInstantiation(
+  // Search for the variable template specialization declaration that
+  // corresponds to these arguments again to get an up-to-date InsertPos.
+  // The template argument deduction in between may update the underlying
+  // specialization container and invalidate previous iterators.
+  VarTemplateSpecializationDecl *Decl =
+  Template->findSpecialization(Converted, InsertPos);
+  // Assert we should not have a variable template specialization, otherwise we
+  // should have returned early.
+  assert(!Decl);
+  Decl = BuildVarTemplateInstantiation(
   Template, InstantiationPattern, *InstantiationArgs, TemplateArgs,
   Converted, TemplateNameLoc, InsertPos /*, LateAttrs, StartingScope*/);
   if (!Decl)
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D87853: [Sema] Update specialization iterator after template argument deduction.

2020-09-17 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

The bug is exposed by instantiating a large variadic template. I haven't 
managed to get down to a decent size of regression test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D87853/new/

https://reviews.llvm.org/D87853

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


[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-09-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

@davidxl I'm wondering if it is a good time for you to start reviewing the 
patches. Please let me know if you need more time. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2021-01-11 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 315908.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

Files:
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  
llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ /dev/null
@@ -1,24 +0,0 @@
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-
-define internal i32 @foo() {
-entry:
-  ret i32 0
-}
-
-define dso_local i32 (...)* @bar() {
-entry:
-  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
-}
-
-; O0: Running pass: UniqueInternalLinkageNamesPass
-
-;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass.
-; O2: Running pass: UniqueInternalLinkageNamesPass
-; O2: Running pass: SampleProfileProbePass
-
-; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
-; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes=unique-internal-linkage-names < %s -o - | FileCheck %s --check-prefix=DBG
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0
+}
+
+define dso_local i32 (...)* @bar() {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
+}
+
+define internal i32 @go() !dbg !19 {
+entry:
+  ret i32 0
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!15 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DISubprogram(name: "foo", linkageName: "foo", scope: !1, isDefinition: false, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
+!19 = distinct !DISubprogram(name: "go", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2)
+
+; O0: Running pass: UniqueInternalLinkageNamesPass
+
+;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass.
+; O2: Running pass: UniqueInternalLinkageNamesPass
+; O2: Running p

[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2021-01-11 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG32bcfcda4e28: Rename debug linkage name with 
-funique-internal-linkage-names (authored by hoy).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

Files:
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  
llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ /dev/null
@@ -1,24 +0,0 @@
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
-
-define internal i32 @foo() {
-entry:
-  ret i32 0
-}
-
-define dso_local i32 (...)* @bar() {
-entry:
-  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
-}
-
-; O0: Running pass: UniqueInternalLinkageNamesPass
-
-;; Check UniqueInternalLinkageNamesPass is scheduled before SampleProfileProbePass.
-; O2: Running pass: UniqueInternalLinkageNamesPass
-; O2: Running pass: SampleProfileProbePass
-
-; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
-; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueInternalLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes=unique-internal-linkage-names < %s -o - | FileCheck %s --check-prefix=DBG
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0
+}
+
+define dso_local i32 (...)* @bar() {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
+}
+
+define internal i32 @go() !dbg !19 {
+entry:
+  ret i32 0
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!15 = distinct !DISubprogram(name: "foo", linkageName: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DISubprogram(name: "foo", linkageName: "foo", scope: !1, isDefinition: false, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized)
+!19 = distinct !DISubprogram(name: "go", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, declaration: !18, retainedNodes: !2)
+
+; O0: Running pass: UniqueInternalLinkageNamesPass
+
+;; Check UniqueInternalLinkageNamesPa

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-12 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/PseudoProbe.h:41
   //  [18:3] - probe id
-  //  [25:19] - reserved
+  //  [25:19] - probe distribution factor
   //  [28:26] - probe type, see PseudoProbeType

wmi wrote:
> The bits in discriminator is a scare resource. Have you considered using less 
> bits to represent probe distribution factor? I guess it is possible that 
> using a little more coarse grain distribution factor won't affect performance.
That's a good point. We are using seven bits to represent [0, 100] so that 
integral numbers can be distinguished. Yes, we could use fewer bits to 
represent, say 4 bits to represent only even numbers. We could also not use any 
bits here but instead use the distribution factor of the outer block probes 
when the competition of those bits are high. I can do an experiment to see how 
well that works.



Comment at: llvm/include/llvm/Passes/StandardInstrumentations.h:273
   IRChangedPrinter PrintChangedIR;
+  PseudoProbeVerifier PseudoProbeVerification;
   VerifyInstrumentation Verify;

wmi wrote:
> Before PseudoProbeUpdate pass, there is no need to verify because 
> PseudoProbeUpdate will make distribution factor consistent. PseudoProbeUpdate 
> run in a late stage in the lto/thinlto prelink pipeline, and no many passes 
> need the verification, so what is the major usage of PseudoProbeVerifier?  
Yeah, there's no need to verify intermediate passes. The verifier pass is just 
a handy utility that tracks those passes that do code duplication for 
debugging. Perhaps I should give it a better name like PseudoCloningTracker?



Comment at: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp:133-134
+  float PrevProbeFactor = PrevProbeFactors[I.first];
+  if (std::abs(CurProbeFactor - PrevProbeFactor) >
+  DistributionFactorVariance) {
+if (!BannerPrinted) {

wmi wrote:
> Why not issue warning/error message when verification fails? That will make 
> enabling the verification in release compiler possible.
The verifier is for debugging only. It doesn't really do any verification. It 
just helps to track code duplication. Sorry for the naming confusion.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-13 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/PseudoProbe.h:41
   //  [18:3] - probe id
-  //  [25:19] - reserved
+  //  [25:19] - probe distribution factor
   //  [28:26] - probe type, see PseudoProbeType

hoy wrote:
> wmi wrote:
> > The bits in discriminator is a scare resource. Have you considered using 
> > less bits to represent probe distribution factor? I guess it is possible 
> > that using a little more coarse grain distribution factor won't affect 
> > performance.
> That's a good point. We are using seven bits to represent [0, 100] so that 
> integral numbers can be distinguished. Yes, we could use fewer bits to 
> represent, say 4 bits to represent only even numbers. We could also not use 
> any bits here but instead use the distribution factor of the outer block 
> probes when the competition of those bits are high. I can do an experiment to 
> see how well that works.
On a second thought, using the distribution factor of block probes for call 
probe may not work well since a callsite may be surrounded by more than one 
block probes. 

We could use also fewer bits like 6 bits to encode even numbers in the range 
[0, 100], or 5 bits to encoding multiples of 3 in [0, 100]. I did a profile 
quality measurement with the even number encoding. It's OK overall except for 
two SPEC benchmarks. I guess it's a trade-off we'll have to take when there's a 
competition on those bits. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-13 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 316567.
hoy added a comment.

Adding support in the priority-based inliner.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{!"clang version 3.9.0"}
+!12 = !DILocation(line: 2, column: 20, scope: !4)
+!13 = distinct !{!13, !14}
+!14 = !{!"llvm.loop.unroll.full"}
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-13 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/PseudoProbe.h:41
   //  [18:3] - probe id
-  //  [25:19] - reserved
+  //  [25:19] - probe distribution factor
   //  [28:26] - probe type, see PseudoProbeType

wmi wrote:
> hoy wrote:
> > hoy wrote:
> > > wmi wrote:
> > > > The bits in discriminator is a scare resource. Have you considered 
> > > > using less bits to represent probe distribution factor? I guess it is 
> > > > possible that using a little more coarse grain distribution factor 
> > > > won't affect performance.
> > > That's a good point. We are using seven bits to represent [0, 100] so 
> > > that integral numbers can be distinguished. Yes, we could use fewer bits 
> > > to represent, say 4 bits to represent only even numbers. We could also 
> > > not use any bits here but instead use the distribution factor of the 
> > > outer block probes when the competition of those bits are high. I can do 
> > > an experiment to see how well that works.
> > On a second thought, using the distribution factor of block probes for call 
> > probe may not work well since a callsite may be surrounded by more than one 
> > block probes. 
> > 
> > We could use also fewer bits like 6 bits to encode even numbers in the 
> > range [0, 100], or 5 bits to encoding multiples of 3 in [0, 100]. I did a 
> > profile quality measurement with the even number encoding. It's OK overall 
> > except for two SPEC benchmarks. I guess it's a trade-off we'll have to take 
> > when there's a competition on those bits. 
> Could you elaborate a little bit about the case that a callsite is surrounded 
> by more than one block probe? Is it because bb merge like in cfg 
> simplification?
Yes, block merge in cfg simplification is a good example. Inlining can also end 
up with callee code and caller code in one block. Jump threading or other cfg 
optimizations that convert a conditional jump into an unconditional jump can 
result in block merge too.

So far our way to track block weight for blocks with multiple probes is to take 
the maximum count out of those probes. When it comes to tracking callsite 
count, it is handy and accurate to attach a dedicated distribution factor for 
each individual call. For example, when a call is inlined, the inlinee's probes 
will be cloned into the caller, and they will be prorated based on the 
callsite's dedicated distribution factor.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-14 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/PseudoProbe.h:41
   //  [18:3] - probe id
-  //  [25:19] - reserved
+  //  [25:19] - probe distribution factor
   //  [28:26] - probe type, see PseudoProbeType

wmi wrote:
> hoy wrote:
> > wmi wrote:
> > > hoy wrote:
> > > > hoy wrote:
> > > > > wmi wrote:
> > > > > > The bits in discriminator is a scare resource. Have you considered 
> > > > > > using less bits to represent probe distribution factor? I guess it 
> > > > > > is possible that using a little more coarse grain distribution 
> > > > > > factor won't affect performance.
> > > > > That's a good point. We are using seven bits to represent [0, 100] so 
> > > > > that integral numbers can be distinguished. Yes, we could use fewer 
> > > > > bits to represent, say 4 bits to represent only even numbers. We 
> > > > > could also not use any bits here but instead use the distribution 
> > > > > factor of the outer block probes when the competition of those bits 
> > > > > are high. I can do an experiment to see how well that works.
> > > > On a second thought, using the distribution factor of block probes for 
> > > > call probe may not work well since a callsite may be surrounded by more 
> > > > than one block probes. 
> > > > 
> > > > We could use also fewer bits like 6 bits to encode even numbers in the 
> > > > range [0, 100], or 5 bits to encoding multiples of 3 in [0, 100]. I did 
> > > > a profile quality measurement with the even number encoding. It's OK 
> > > > overall except for two SPEC benchmarks. I guess it's a trade-off we'll 
> > > > have to take when there's a competition on those bits. 
> > > Could you elaborate a little bit about the case that a callsite is 
> > > surrounded by more than one block probe? Is it because bb merge like in 
> > > cfg simplification?
> > Yes, block merge in cfg simplification is a good example. Inlining can also 
> > end up with callee code and caller code in one block. Jump threading or 
> > other cfg optimizations that convert a conditional jump into an 
> > unconditional jump can result in block merge too.
> > 
> > So far our way to track block weight for blocks with multiple probes is to 
> > take the maximum count out of those probes. When it comes to tracking 
> > callsite count, it is handy and accurate to attach a dedicated distribution 
> > factor for each individual call. For example, when a call is inlined, the 
> > inlinee's probes will be cloned into the caller, and they will be prorated 
> > based on the callsite's dedicated distribution factor.
> Actually, I think we may be able to extend Discriminator and 
> PseudoProbeDwarfDiscriminator. To emit Discriminator into Dwarf, we need to 
> follow Dwarf standard about how many bits Discrminator is going to occupy. 
> But inside compiler, Discriminator is represented as MetaData so it hasn't to 
> be 32bits. For example, we can extend Discriminator MetaData to be 64bits or 
> even larger and specify only lower 32bits will be actually emitted into Dwarf 
> section. For intermediate information like distribution factors, we can put 
> it into the higher bits. 
That's a good idea, I like that. Actually we thought about that int the past 
and our concern was about memory cost since the discriminator filed in 
`DILexicalBlockFile` metadata is not optional. It is probably OK for pseudo 
probe since discriminators are only used for callsites. It might be a problem 
with -fdebug-info-for-profiling where discriminators can be used more often. 

It sounds to me extending the size of discriminator is desirable for pseudo 
probes and potentially FS-AFDO. It might be worth evaluating the cost at some 
time. What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-14 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/PseudoProbe.h:41
   //  [18:3] - probe id
-  //  [25:19] - reserved
+  //  [25:19] - probe distribution factor
   //  [28:26] - probe type, see PseudoProbeType

wmi wrote:
> hoy wrote:
> > wmi wrote:
> > > hoy wrote:
> > > > wmi wrote:
> > > > > hoy wrote:
> > > > > > hoy wrote:
> > > > > > > wmi wrote:
> > > > > > > > The bits in discriminator is a scare resource. Have you 
> > > > > > > > considered using less bits to represent probe distribution 
> > > > > > > > factor? I guess it is possible that using a little more coarse 
> > > > > > > > grain distribution factor won't affect performance.
> > > > > > > That's a good point. We are using seven bits to represent [0, 
> > > > > > > 100] so that integral numbers can be distinguished. Yes, we could 
> > > > > > > use fewer bits to represent, say 4 bits to represent only even 
> > > > > > > numbers. We could also not use any bits here but instead use the 
> > > > > > > distribution factor of the outer block probes when the 
> > > > > > > competition of those bits are high. I can do an experiment to see 
> > > > > > > how well that works.
> > > > > > On a second thought, using the distribution factor of block probes 
> > > > > > for call probe may not work well since a callsite may be surrounded 
> > > > > > by more than one block probes. 
> > > > > > 
> > > > > > We could use also fewer bits like 6 bits to encode even numbers in 
> > > > > > the range [0, 100], or 5 bits to encoding multiples of 3 in [0, 
> > > > > > 100]. I did a profile quality measurement with the even number 
> > > > > > encoding. It's OK overall except for two SPEC benchmarks. I guess 
> > > > > > it's a trade-off we'll have to take when there's a competition on 
> > > > > > those bits. 
> > > > > Could you elaborate a little bit about the case that a callsite is 
> > > > > surrounded by more than one block probe? Is it because bb merge like 
> > > > > in cfg simplification?
> > > > Yes, block merge in cfg simplification is a good example. Inlining can 
> > > > also end up with callee code and caller code in one block. Jump 
> > > > threading or other cfg optimizations that convert a conditional jump 
> > > > into an unconditional jump can result in block merge too.
> > > > 
> > > > So far our way to track block weight for blocks with multiple probes is 
> > > > to take the maximum count out of those probes. When it comes to 
> > > > tracking callsite count, it is handy and accurate to attach a dedicated 
> > > > distribution factor for each individual call. For example, when a call 
> > > > is inlined, the inlinee's probes will be cloned into the caller, and 
> > > > they will be prorated based on the callsite's dedicated distribution 
> > > > factor.
> > > Actually, I think we may be able to extend Discriminator and 
> > > PseudoProbeDwarfDiscriminator. To emit Discriminator into Dwarf, we need 
> > > to follow Dwarf standard about how many bits Discrminator is going to 
> > > occupy. But inside compiler, Discriminator is represented as MetaData so 
> > > it hasn't to be 32bits. For example, we can extend Discriminator MetaData 
> > > to be 64bits or even larger and specify only lower 32bits will be 
> > > actually emitted into Dwarf section. For intermediate information like 
> > > distribution factors, we can put it into the higher bits. 
> > That's a good idea, I like that. Actually we thought about that int the 
> > past and our concern was about memory cost since the discriminator filed in 
> > `DILexicalBlockFile` metadata is not optional. It is probably OK for pseudo 
> > probe since discriminators are only used for callsites. It might be a 
> > problem with -fdebug-info-for-profiling where discriminators can be used 
> > more often. 
> > 
> > It sounds to me extending the size of discriminator is desirable for pseudo 
> > probes and potentially FS-AFDO. It might be worth evaluating the cost at 
> > some time. What do you think?
> Yes, it is worth evaluating the cost. It is only about intermediate data in 
> compiler and it won't affect the binary and profile output, therefore it 
> won't introduce backward compatibility issue. I think it is up to you to 
> choose whether to evaluate it now or later.  
Sounds good. Will do a measurement for both -fpseudo-probe-for-profiling and 
-fdebug-info-for-profiling later.



Comment at: llvm/lib/IR/PseudoProbe.cpp:65
+void setProbeDistributionFactor(Instruction &Inst, float Factor) {
+  assert(Factor <= 1);
+  if (auto *II = dyn_cast(&Inst)) {

wmi wrote:
> Add assertion message.
Will do.



Comment at: llvm/lib/Transforms/IPO/SampleProfile.cpp:363
   const FunctionSamples *CalleeSamples;
   uint64_t CallsiteCount;
+  // Call site distribution factor to prorate the profile samples for a

wmi wrote:
> CallsiteCount will be the count before being prorated or after if 
> CallsiteDist

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2021-01-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 317726.
hoy marked an inline comment as done.
hoy added a comment.

Addressing Wei's feedbacks.

Also prorating indirect callsite target count annotation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/ProfileData/SampleProf.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0", isOptimized: false, runtimeVersion: 0, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{!"clang version 3.9.0"}
+!12 = !DILocation(line: 2, column: 20, scope: !4)
+!13 = distinct !{!13, !14}
+!14 = !{!"l

[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: wenlei, dang, steven_wu, hiraditya.
Herald added a reviewer: jansvoboda11.
hoy requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

As titled.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -flto=thin -fpseudo-probe-for-profiling 2>&1 | 
FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 318714.
hoy added a comment.

Fixing test failure on Windows.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,5 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s
+
+// CHECK: -plugin-opt=pseudo-probe-for-profiling
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,10 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env var)">;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-24 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/lib/Driver/ToolChains/CommonArgs.cpp:609
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasArg(options::OPT_fpseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");

wenlei wrote:
> `getLastArg(options::OPT_fpseudo_probe_for_profiling, 
> options::OPT_fno_pseudo_probe_for_profiling` instead?
Good point, changed to 
```
Args.hasFlag(options::OPT_fpseudo_probe_for_profiling, 
options::OPT_fno_pseudo_probe_for_profiling)
```

which matches the last positive flag


```
bool ArgList::hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const {
  if (Arg *A = getLastArg(Pos, Neg))
return A->getOption().matches(Pos);
  return Default;
}
```


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

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


[PATCH] D95271: [CSSPGO] Passing the clang driver switch -fpseudo-probe-for-profiling to the linker.

2021-01-24 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 318878.
hoy added a comment.

Addressing Wenleis' feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D95271/new/

https://reviews.llvm.org/D95271

Files:
  clang/include/clang/Driver/Options.td
  clang/lib/Driver/ToolChains/CommonArgs.cpp
  clang/test/Driver/pseudo-probe-lto.c


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin 
-fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto 
-fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck 
%s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
+
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">, DefaultsToFalse,
   ChangedBy, ResetBy,
-  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample profiler">>;
+  BothFlags<[NoXarchOption, CC1Option], " pseudo probes for sample 
profiling">>;
 def forder_file_instrumentation : Flag<["-"], "forder-file-instrumentation">,
 Group, Flags<[CC1Option, CoreOption]>,
 HelpText<"Generate instrumented code to collect order file into 
default.profraw file (overridden by '=' form of option or LLVM_PROFILE_FILE env 
var)">;


Index: clang/test/Driver/pseudo-probe-lto.c
===
--- /dev/null
+++ clang/test/Driver/pseudo-probe-lto.c
@@ -0,0 +1,10 @@
+// RUN: touch %t.o
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto=thin -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling -fpseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=PROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+// RUN: %clang -### %t.o -target x86_64-unknown-linux -flto -fpseudo-probe-for-profiling -fno-pseudo-probe-for-profiling 2>&1 | FileCheck %s --check-prefix=NOPROBE
+
+// PROBE: -plugin-opt=pseudo-probe-for-profiling
+// NOPROBE-NOT: -plugin-opt=pseudo-probe-for-profiling
+
Index: clang/lib/Driver/ToolChains/CommonArgs.cpp
===
--- clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -605,6 +605,11 @@
   CmdArgs.push_back("-plugin-opt=new-pass-manager");
   }
 
+  // Pass an option to enable pseudo probe emission.
+  if (Args.hasFlag(options::OPT_fpseudo_probe_for_profiling,
+   options::OPT_fno_pseudo_probe_for_profiling))
+CmdArgs.push_back("-plugin-opt=pseudo-probe-for-profiling");
+
   // Setup statistics file output.
   SmallString<128> StatsFile = getStatsFileName(Args, Output, Input, D);
   if (!StatsFile.empty())
Index: clang/include/clang/Driver/Options.td
===
--- clang/include/clang/Driver/Options.td
+++ clang/include/clang/Driver/Options.td
@@ -1221,7 +1221,7 @@
 defm pseudo_probe_for_profiling : BoolFOption<"pseudo-probe-for-profiling",
   CodeGenOpts<"PseudoProbeForProfiling">,

[PATCH] D88338: [clangd] clangd --check: standalone diagnosis of common problems

2020-10-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang-tools-extra/clangd/tool/Check.cpp:243
+  size_t N = 50;
+  auto xxx = std::string(N, 'x');
+)cpp";

Hi, I'm seeing an error with this "tweak: ExpandAutoType ==> FAIL: Could not 
deduce type for 'auto' type". It's probably due to that the std string header 
was not available when running `check.test`, thus the test failed. Is it 
expected that the header is available when test is run? Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88338/new/

https://reviews.llvm.org/D88338

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


[PATCH] D88338: [clangd] clangd --check: standalone diagnosis of common problems

2020-10-02 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D88338#2307976 , @sammccall wrote:

> Sorry @rsmith @hoy, I've replaced the test with one without such dependencies 
> in bc18d8d9b705d31a94c51900c8b18e4feaf9c7fb 
> .

Thanks for the quick turnaround!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D88338/new/

https://reviews.llvm.org/D88338

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


[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-11-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D86502#2245734 , @wmi wrote:

> In D86502#2245578 , @hoy wrote:
>
>> In D86502#2245460 , @wmi wrote:
>>
 The early instrumentation also allows the inliner to duplicate probes for 
 inlined instances. When a probe along with the other instructions of a 
 callee function are inlined into its caller function, the GUID of the 
 callee function goes with the probe. This allows samples collected on 
 inlined probes to be reported for the original callee function.
>>>
>>> Just get a question from reading the above. Suppose `A` only has one BB and 
>>> the BB has one PseudoProbe in it. If function `A` is inlined into `B1` and 
>>> `B2` and both `B1` and `B2` inlined into `C`, the PseudoProbe from `A` will 
>>> have two copies in `C` both carrying GUID of `A`. How the samples collected 
>>> from `A` inlined into `B1` inlined into `C` are categorized differently 
>>> from `A` inlined into `B2` inlined into `C`, especially when debug 
>>> information is not enabled (so no inline stack information in the binary)?
>>
>> This is a very good question. Inlined functions are differentiated by their 
>> original callsites. A pseudo probe is allocated for each callsite in the 
>> `SampleProfileProbe` pass. Nested inlining will produce a stack of pseudo 
>> probes, similar with the Dwarf inline stack. The work is not included in the 
>> first set of patches.
>
> Thanks, then how does the pseudo probe for a callsite after inline to 
> represent the inline scope it covers?

It is represented by the dwarf inline stack for that inlined pseudo probe. I'm 
about to send out a patch for it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

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


[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-11-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: llvm-commits, cfe-commits, dexonsmith, wenlei, 
pengfei, hiraditya, mgorny.
Herald added projects: clang, LLVM.
hoy requested review of this revision.

An indirect call site needs to be probed for its potential call targets. With 
CSSPGO a direct call also needs a probe so that a calling context can be 
represented by a stack of callsite probes. Unlike pseudo probes for basic 
blocks that are in form of standalone intrinsic call instructions, pseudo 
probes for callsites have to be attached to the call instruction, thus a 
separate instruction would not work.

One possible way of attaching a probe to a call instruction is to use a special 
metadata that carries information about the probe. The special metadata will 
have to make its way through the optimization pipeline down to object emission. 
This requires additional efforts to maintain the metadata in various places. 
Given that the !dbg metadata is a first-class metadata and has all essential 
support in place , leveraging the !dbg metadata as a channel to encode pseudo 
probe information is handy.

With the requirement of not inflating !dbg metadata that is allocated for 
almost every instruction, we found that the 32-bit DWARF discriminator field 
which mainly serves AutoFDO can be reused for pseudo probes. DWARF 
discriminators distinguish identical source locations between instructions and 
with pseudo probes such support is not required. In this change we are using 
the discriminator field to encode the ID and type of a callsite probe and the 
encoded value will be unpacked and consumed right before object emission.

To avoid collision with the baseline AutoFDO in various places that handles 
dwarf discriminators where a check against  the `-pseudo-probe-for-profiling` 
switch is not available, a special encoding scheme is used to tell apart a 
pseudo probe discriminator from a regular discriminator. For the regular 
discriminator, if all lowest 3 bits are non-zero, it means the discriminator is 
basically empty and all higher 29 bits can be reversed for pseudo probe use.

Callsite pseudo probes are inserted in `SampleProfileProbePass` and a 
target-independent MIR pass `PseudoProbeInserter` is added to unpack the probe 
ID/type from `!dbg`.

Note that with this work the switch -debug-info-for-profiling will not work 
with -pseudo-probe-for-profiling anymore. They cannot be used at the same time.

Test Plan:


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll

Index: llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
===
--- llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
+++ llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -28,9 +28,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(sc

[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-11-18 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 306280.
hoy edited the summary of this revision.
hoy added a comment.

Updating D91756 : [CSSPGO] Pseudo probes for 
function calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll

Index: llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
===
--- llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
+++ llvm/test/Transforms/SampleProfile/emit-pseudo-probe.ll
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -28,9 +28,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 67108887)
+; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
+;; A discriminator of 134217759 which is 0x81f in hexdecimal, stands for a direct call probe
+;; with an index of 3.
+; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 134217759)
+
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!9, !10}
@@ -39,10 +65,12 @@
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !6)
 !6 = !{!7}
 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, !"Dwarf Version", i32 4}
 !10 = !{i32 2, !"Debug Info Version", i32 3}
 !11 = !{!"clang version 3.9.0"}
-!12 = !DILocation(line: 2, scope: !3)
\ No newline at end of file
+!12 = !DILocation(line: 2, scope: !3)
+!13 = !DILocation(line: 2, column: 20, scope: !4)
Index: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -37,8 +37,10 @@
 
 SampleProfileProber::SampleProfileProber(Function &Func) : F(&Func) {
   BlockProbeIds.clear();
+  CallProbeIds.clear();
   LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
   computeProbeIdForBlocks();
+  computeProbeIdForCallsites();
 }
 
 void SampleProfileProber::computeProbeIdForBlocks() {
@@ -47,11 +49,28 @@
   }
 }
 
+void SampleProfileProber::computeProbeIdForCallsites() {
+  for (auto &BB : *F) {
+for (auto &I : BB) {
+  if (!isa(I))
+continue;
+  if (isa(&I))
+continue;
+  CallProbeIds[&I] = ++LastProbeId;
+}
+  }
+}
+
 uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
   auto I = BlockProbeIds.find(const_cast(BB));
   return I == BlockProbeIds.end() ? 0 : I->second;
 }
 
+uint32_t SampleProfileProber::getCallsiteId(const Instruction *call) const {
+  auto iter

[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-11-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 306488.
hoy added a comment.

Updating D86502 : [CSSPGO] A Clang switch 
-fpseudo-probe-for-profiling for pseudo-probe instrumentation.

Changing test corresponding to intrinsic attributes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -973,6 +973,12 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Place pseudo probe instrumentation as the first pass of the pipeline to
+  // minimize the impact of optimization changes.
+  if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
+  Phase != ThinLTOPhase::PostLink)
+MPM.addPass(SampleProfileProbePass(TM));
+
   bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
 
   // In ThinLTO mode, when flattened profile is used, all the available
@@ -1338,7 +1344,7 @@
   for (auto &C : PipelineStartEPCallbacks)
 C(MPM, Level);
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Add the core simplification pipeline.
@@ -1366,7 +1372,7 @@
   // Force any function attributes we want the rest of the pipeline to observe.
   MPM.addPass(ForceFunctionAttrsPass());
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Apply module pipeline start EP callback.
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -36,11 +36,15 @@
   enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
   PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
  std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
- CSPGOAction CSAction = NoCSAction, bool SamplePGOSupport = false)
+ CSPGOAction CSAction = NoCSAction,
+ bool DebugInfoForProfiling = false,
+ bool PseudoProbeForProfiling = false)
   : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
 ProfileRemappingFile(ProfileRemappingFile), Action(Action),
-CSAction(CSAction),
-SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
+CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
+  (Action == SampleUse &&
+   !PseudoProbeForProfiling)),
+PseudoProbeForProfiling(PseudoProbeForProfiling) {
 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
 // callback with IRUse action without ProfileFile.
 
@@ -55,16 +59,18 @@
 // a profile.
 assert(this->CSAction != CSIRUse || this->Action == IRUse);
 
-// If neither Action nor CSAction, SamplePGOSupport needs to be true.
+// If neither Action nor CSAction, DebugInfoForProfiling or
+// PseudoProbeForProfiling needs to be true.
 assert(this->Action != NoAction || this->CSAction != NoCSAction ||
-   this->SamplePGOSupport);
+   this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
   }
   std::string ProfileFile;
   std::string CSProfileGenFile;
   std::string ProfileRemappingFile;
   PGOAction Action;
   CSPGOAction CSAction;
-  bool SamplePGOSupport;
+  bool DebugInfoForProfiling;
+  bool PseudoProbeForProfiling;
 };
 
 /// Tunable parameters for passes in the default pipelines.
Index: clang/test/CodeGen/pseudo-probe-emit.c
===
--- /dev/null
+++ clang/test/CodeGen/pseudo-probe-emit.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O2  -fexperimental-new-pass-manager -fpseudo-probe-for-profiling -g -emit-llvm -S -o - %s | FileCheck %s
+
+// Check the generation of pseudoprobe intrinsic call
+
+void bar();
+void go();
+
+void foo(int x) {
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0)
+  if (x == 0)
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2, i32 0)
+bar();
+  else
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3, i32 0)
+go();
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0)
+}
Index:

[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-11-19 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 306497.
hoy added a comment.

Updating D91756 : [CSSPGO] Pseudo probes for 
function calls.

Corresponding changes to support IR/MIR intrinsic attributes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
@@ -1,6 +1,6 @@
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -28,9 +28,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1, 0
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2, 0
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 67108887)
+; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
+;; A discriminator of 134217759 which is 0x81f in hexdecimal, stands for a direct call probe
+;; with an index of 3.
+; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 134217759)
+
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!9, !10}
@@ -39,10 +65,12 @@
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !6)
 !6 = !{!7}
 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, !"Dwarf Version", i32 4}
 !10 = !{i32 2, !"Debug Info Version", i32 3}
 !11 = !{!"clang version 3.9.0"}
-!12 = !DILocation(line: 2, scope: !3)
\ No newline at end of file
+!12 = !DILocation(line: 2, scope: !3)
+!13 = !DILocation(line: 2, column: 20, scope: !4)
Index: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -37,8 +37,10 @@
 
 SampleProfileProber::SampleProfileProber(Function &Func) : F(&Func) {
   BlockProbeIds.clear();
+  CallProbeIds.clear();
   LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
   computeProbeIdForBlocks();
+  computeProbeIdForCallsites();
 }
 
 void SampleProfileProber::computeProbeIdForBlocks() {
@@ -47,11 +49,28 @@
   }
 }
 
+void SampleProfileProber::computeProbeIdForCallsites() {
+  for (auto &BB : *F) {
+for (auto &I : BB) {
+  if (!isa(I))
+continue;
+  if (isa(&I))
+continue;
+  CallProbeIds[&I] = ++LastProbeId;
+}
+  }
+}
+
 uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
   auto I = BlockProbeIds.find(const_cast(BB));
   return I == BlockProbeIds.end() ? 0 : I->second;
 }
 
+ui

[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-11-20 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:978-982
   Opts.DebugInfoForProfiling = Args.hasFlag(
   OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false);
+  Opts.PseudoProbeForProfiling =
+  Args.hasFlag(OPT_fpseudo_probe_for_profiling,
+   OPT_fno_pseudo_probe_for_profiling, false);

wmi wrote:
> Should it emit an error if DebugInfoForProfiling and PseudoProbeForProfiling 
> are enabled at the same time? I see that from the other patch related with 
> pseudoprobe discriminator, these two flags are incompatible.
Yes, we should. It's done in D91756 passbuilder.h : 
https://reviews.llvm.org/D91756#change-Bsibk2p32T1c for both `clang` and `opt`.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

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


[PATCH] D86193: [CSSPGO] Pseudo probe instrumentation for basic blocks.

2020-11-30 Thread Hongtao Yu via Phabricator via cfe-commits
hoy abandoned this revision.
hoy added a comment.

Abandoning this diff which has been broken into four other diffs.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86193/new/

https://reviews.llvm.org/D86193

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


[PATCH] D86502: [CSSPGO] A Clang switch -fpseudo-probe-for-profiling for pseudo-probe instrumentation.

2020-11-30 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGc083fededfa6: [CSSPGO] A Clang switch 
-fpseudo-probe-for-profiling for pseudo-probeā€¦ (authored by hoy).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D86502/new/

https://reviews.llvm.org/D86502

Files:
  clang/include/clang/Basic/CodeGenOptions.def
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp

Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -952,6 +952,12 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Place pseudo probe instrumentation as the first pass of the pipeline to
+  // minimize the impact of optimization changes.
+  if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
+  Phase != ThinLTOPhase::PostLink)
+MPM.addPass(SampleProfileProbePass(TM));
+
   bool HasSampleProfile = PGOOpt && (PGOOpt->Action == PGOOptions::SampleUse);
 
   // In ThinLTO mode, when flattened profile is used, all the available
@@ -1320,7 +1326,7 @@
   for (auto &C : PipelineStartEPCallbacks)
 C(MPM, Level);
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Add the core simplification pipeline.
@@ -1351,7 +1357,7 @@
   // Force any function attributes we want the rest of the pipeline to observe.
   MPM.addPass(ForceFunctionAttrsPass());
 
-  if (PGOOpt && PGOOpt->SamplePGOSupport)
+  if (PGOOpt && PGOOpt->DebugInfoForProfiling)
 MPM.addPass(createModuleToFunctionPassAdaptor(AddDiscriminatorsPass()));
 
   // Apply module pipeline start EP callback.
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -36,11 +36,15 @@
   enum CSPGOAction { NoCSAction, CSIRInstr, CSIRUse };
   PGOOptions(std::string ProfileFile = "", std::string CSProfileGenFile = "",
  std::string ProfileRemappingFile = "", PGOAction Action = NoAction,
- CSPGOAction CSAction = NoCSAction, bool SamplePGOSupport = false)
+ CSPGOAction CSAction = NoCSAction,
+ bool DebugInfoForProfiling = false,
+ bool PseudoProbeForProfiling = false)
   : ProfileFile(ProfileFile), CSProfileGenFile(CSProfileGenFile),
 ProfileRemappingFile(ProfileRemappingFile), Action(Action),
-CSAction(CSAction),
-SamplePGOSupport(SamplePGOSupport || Action == SampleUse) {
+CSAction(CSAction), DebugInfoForProfiling(DebugInfoForProfiling ||
+  (Action == SampleUse &&
+   !PseudoProbeForProfiling)),
+PseudoProbeForProfiling(PseudoProbeForProfiling) {
 // Note, we do allow ProfileFile.empty() for Action=IRUse LTO can
 // callback with IRUse action without ProfileFile.
 
@@ -55,16 +59,18 @@
 // a profile.
 assert(this->CSAction != CSIRUse || this->Action == IRUse);
 
-// If neither Action nor CSAction, SamplePGOSupport needs to be true.
+// If neither Action nor CSAction, DebugInfoForProfiling or
+// PseudoProbeForProfiling needs to be true.
 assert(this->Action != NoAction || this->CSAction != NoCSAction ||
-   this->SamplePGOSupport);
+   this->DebugInfoForProfiling || this->PseudoProbeForProfiling);
   }
   std::string ProfileFile;
   std::string CSProfileGenFile;
   std::string ProfileRemappingFile;
   PGOAction Action;
   CSPGOAction CSAction;
-  bool SamplePGOSupport;
+  bool DebugInfoForProfiling;
+  bool PseudoProbeForProfiling;
 };
 
 /// Tunable parameters for passes in the default pipelines.
Index: clang/test/CodeGen/pseudo-probe-emit.c
===
--- /dev/null
+++ clang/test/CodeGen/pseudo-probe-emit.c
@@ -0,0 +1,17 @@
+// RUN: %clang -O2  -fexperimental-new-pass-manager -fpseudo-probe-for-profiling -g -emit-llvm -S -o - %s | FileCheck %s
+
+// Check the generation of pseudoprobe intrinsic call
+
+void bar();
+void go();
+
+void foo(int x) {
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0)
+  if (x == 0)
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 2, i32 0)
+bar();
+  else
+// CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 3, i32 0)
+go();
+  // CHECK: call void @llvm.pseudoprobe(i64 [[#GUID]], i64 4, i32 0)
+}
Index: cla

[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-12-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/lib/CodeGen/PseudoProbeInserter.cpp:50
+for (MachineBasicBlock &MBB : MF) {
+  MachineInstr *FirstInstr = nullptr;
+  for (MachineInstr &MI : MBB) {

wmi wrote:
> What is the usage of FirstInstr?
Good patch. It's not used in this change. It's used in an upcoming change where 
a probe probing an empty block will be marked specially for better counts 
inference. 



Comment at: llvm/lib/CodeGen/PseudoProbeInserter.cpp:54
+  FirstInstr = &MI;
+if (MI.isCall()) {
+  if (DILocation *DL = MI.getDebugLoc()) {

wmi wrote:
> Will tailcall or other optimizations convert call into something else before 
> PseudoProbeInserter pass?
Good point. A tailcall instruction (a special MIR jump instruction like 
`TAILJMPd`) is considered as  a call and can be identified as  `MI.isCall() && 
MI.isTerminator() && MI.isReturn()`. Tail calls are bad to the 
frame-pointer-based virtual unwinding since they may cause missing frames. An 
upcoming change will mark them specially and a tail call tracker in 
`llvm-profgen` will try to track the missing frames based on some static 
analyses.



Comment at: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp:136-138
+  for (auto &I : CallProbeIds) {
+auto Call = I.first;
+uint32_t Index = I.second;

wmi wrote:
> for (auto &[Call, Index] : CallProbeIds) {
Thanks for the suggestion. This is a C++17 usage and may cause a warning with 
the current build setup which defaults to C++14  (due to -Wc++17)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

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


[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-12-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 308806.
hoy added a comment.

Updating D91756 : [CSSPGO] Pseudo probes for 
function calls.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
@@ -1,7 +1,7 @@
 ; REQUIRES: x86-registered-target
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -29,9 +29,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1, 0
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2, 0
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 67108887)
+; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
+;; A discriminator of 134217759 which is 0x81f in hexdecimal, stands for a direct call probe
+;; with an index of 3.
+; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 134217759)
+
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!9, !10}
@@ -40,10 +66,12 @@
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !6)
 !6 = !{!7}
 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, !"Dwarf Version", i32 4}
 !10 = !{i32 2, !"Debug Info Version", i32 3}
 !11 = !{!"clang version 3.9.0"}
-!12 = !DILocation(line: 2, scope: !3)
\ No newline at end of file
+!12 = !DILocation(line: 2, scope: !3)
+!13 = !DILocation(line: 2, column: 20, scope: !4)
Index: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -37,8 +37,10 @@
 
 SampleProfileProber::SampleProfileProber(Function &Func) : F(&Func) {
   BlockProbeIds.clear();
+  CallProbeIds.clear();
   LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
   computeProbeIdForBlocks();
+  computeProbeIdForCallsites();
 }
 
 void SampleProfileProber::computeProbeIdForBlocks() {
@@ -47,11 +49,28 @@
   }
 }
 
+void SampleProfileProber::computeProbeIdForCallsites() {
+  for (auto &BB : *F) {
+for (auto &I : BB) {
+  if (!isa(I))
+continue;
+  if (isa(&I))
+continue;
+  CallProbeIds[&I] = ++LastProbeId;
+}
+  }
+}
+
 uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
   auto I = BlockProbeIds.find(const_cast(BB));
   return I == BlockProbeIds.end() ? 0 : I->second;
 }
 
+uint32_t SampleProfileProber::

[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-12-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 308874.
hoy added a comment.

Updating D91756 : [CSSPGO] Pseudo probes for 
function calls.

Adding messages for asserts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
@@ -1,7 +1,7 @@
 ; REQUIRES: x86-registered-target
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -29,9 +29,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1, 0
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2, 0
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 67108887)
+; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
+;; A discriminator of 134217759 which is 0x81f in hexdecimal, stands for a direct call probe
+;; with an index of 3.
+; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 134217759)
+
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!9, !10}
@@ -40,10 +66,12 @@
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !6)
 !6 = !{!7}
 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, !"Dwarf Version", i32 4}
 !10 = !{i32 2, !"Debug Info Version", i32 3}
 !11 = !{!"clang version 3.9.0"}
-!12 = !DILocation(line: 2, scope: !3)
\ No newline at end of file
+!12 = !DILocation(line: 2, scope: !3)
+!13 = !DILocation(line: 2, column: 20, scope: !4)
Index: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -37,8 +37,10 @@
 
 SampleProfileProber::SampleProfileProber(Function &Func) : F(&Func) {
   BlockProbeIds.clear();
+  CallProbeIds.clear();
   LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
   computeProbeIdForBlocks();
+  computeProbeIdForCallsites();
 }
 
 void SampleProfileProber::computeProbeIdForBlocks() {
@@ -47,11 +49,28 @@
   }
 }
 
+void SampleProfileProber::computeProbeIdForCallsites() {
+  for (auto &BB : *F) {
+for (auto &I : BB) {
+  if (!isa(I))
+continue;
+  if (isa(&I))
+continue;
+  CallProbeIds[&I] = ++LastProbeId;
+}
+  }
+}
+
 uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
   auto I = BlockProbeIds.find(const_cast(BB));
   return I == BlockProbeIds.end() ? 0 : I->second;
 }
 
+

[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-12-01 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D91756#2427759 , @wmi wrote:

> Another question. Sorry for not bringing it up earlier. When a call with 
> probe metadata attached is inlined, the probe will be gone or it will be kept 
> somehow? I think you want to keep the probe especially for inline instance to 
> reconstruct the context but I didn't figure it out how you did that from the 
> description.

No problem. Sorry for not clarifying it in the description. When a callee is 
inlined, the probe metadata will go with the inlined instructions. The `!dbg` 
metadata of an inlined instruction is in form of a scope stack. The top of the 
stack is the instruction's original `!dbg` metadata and the bottom of the stack 
is the for the original callsite of the top-level inliner. Except for the top 
of the stack, all other elements of the stack actually refer to the nested 
inlined callsites whose discriminator fields (which actually represents a 
calliste probe) can be used to represent the inline context of an inlined 
`PseudoProbeInst` or a `CallInst`. I'll update the description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

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


[PATCH] D91756: [CSSPGO] Pseudo probes for function calls.

2020-12-02 Thread Hongtao Yu via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG24d4291ca704: [CSSPGO] Pseudo probes for function calls. 
(authored by hoy).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91756/new/

https://reviews.llvm.org/D91756

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/CodeGen/CommandFlags.h
  llvm/include/llvm/CodeGen/Passes.h
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/InitializePasses.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Target/TargetOptions.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/CodeGen/CMakeLists.txt
  llvm/lib/CodeGen/CommandFlags.cpp
  llvm/lib/CodeGen/PseudoProbeInserter.cpp
  llvm/lib/CodeGen/SelectionDAG/InstrEmitter.cpp
  llvm/lib/CodeGen/TargetPassConfig.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
===
--- llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
@@ -1,7 +1,7 @@
 ; REQUIRES: x86-registered-target
 ; RUN: opt < %s -passes=pseudo-probe -function-sections -S -o %t
 ; RUN: FileCheck %s < %t --check-prefix=CHECK-IL
-; RUN: llc %t -stop-after=instruction-select -o - | FileCheck %s --check-prefix=CHECK-MIR
+; RUN: llc %t -pseudo-probe-for-profiling -stop-after=pseudo-probe-inserter -o - | FileCheck %s --check-prefix=CHECK-MIR
 ;
 ;; Check the generation of pseudoprobe intrinsic call.
 
@@ -29,9 +29,35 @@
   ret void, !dbg !12
 }
 
+declare void @bar(i32 %x) 
+
+define internal void @foo2(void (i32)* %f) !dbg !4 {
+entry:
+; CHECK-IL: call void @llvm.pseudoprobe(i64 [[#GUID2:]], i64 1, i32 0)
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2:]], 1, 0, 0
+; Check pseudo_probe metadata attached to the indirect call instruction.
+; CHECK-IL: call void %f(i32 1), !dbg ![[#PROBE0:]]
+; CHECK-MIR: PSEUDO_PROBE [[#GUID2]], 2, 1, 0
+  call void %f(i32 1), !dbg !13
+; Check pseudo_probe metadata attached to the direct call instruction.
+; CHECK-IL: call void @bar(i32 1), !dbg ![[#PROBE1:]]
+; CHECK-MIR: PSEUDO_PROBE	[[#GUID2]], 3, 2, 0
+  call void @bar(i32 1)
+  ret void
+}
+
 ; CHECK-IL: ![[#FOO:]] = distinct !DISubprogram(name: "foo"
 ; CHECK-IL: ![[#FAKELINE]] = !DILocation(line: 0, scope: ![[#FOO]])
 ; CHECK-IL: ![[#REALLINE]] = !DILocation(line: 2, scope: ![[#FOO]])
+; CHECK-IL: ![[#PROBE0]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE0:]])
+;; A discriminator of 67108887 which is 0x417 in hexdecimal, stands for a direct call probe
+;; with an index of 2.
+; CHECK-IL: ![[#SCOPE0]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 67108887)
+; CHECK-IL: ![[#PROBE1]] = !DILocation(line: 0, scope: ![[#SCOPE1:]])
+;; A discriminator of 134217759 which is 0x81f in hexdecimal, stands for a direct call probe
+;; with an index of 3.
+; CHECK-IL: ![[#SCOPE1]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 134217759)
+
 
 !llvm.dbg.cu = !{!0}
 !llvm.module.flags = !{!9, !10}
@@ -40,10 +66,12 @@
 !1 = !DIFile(filename: "test.c", directory: "")
 !2 = !{}
 !3 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, unit: !0, retainedNodes: !2)
+!4 = distinct !DISubprogram(name: "foo2", scope: !1, file: !1, line: 2, type: !5, unit: !0, retainedNodes: !2)
 !5 = !DISubroutineType(types: !6)
 !6 = !{!7}
 !7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
 !9 = !{i32 2, !"Dwarf Version", i32 4}
 !10 = !{i32 2, !"Debug Info Version", i32 3}
 !11 = !{!"clang version 3.9.0"}
-!12 = !DILocation(line: 2, scope: !3)
\ No newline at end of file
+!12 = !DILocation(line: 2, scope: !3)
+!13 = !DILocation(line: 2, column: 20, scope: !4)
Index: llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
===
--- llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
+++ llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
@@ -37,8 +37,10 @@
 
 SampleProfileProber::SampleProfileProber(Function &Func) : F(&Func) {
   BlockProbeIds.clear();
+  CallProbeIds.clear();
   LastProbeId = (uint32_t)PseudoProbeReservedId::Last;
   computeProbeIdForBlocks();
+  computeProbeIdForCallsites();
 }
 
 void SampleProfileProber::computeProbeIdForBlocks() {
@@ -47,11 +49,28 @@
   }
 }
 
+void SampleProfileProber::computeProbeIdForCallsites() {
+  for (auto &BB : *F) {
+for (auto &I : BB) {
+  if (!isa(I))
+continue;
+  if (isa(&I))
+continue;
+  CallProbeIds[&I] = ++LastProbeId;
+}
+  }
+}
+
 uint32_t SampleProfileProber::getBlockId(const BasicBlock *BB) const {
   auto I = BlockProbeIds.find(const_cast(BB));
   return I == BlockPr

[PATCH] D92661: [RFC] Fix TLS and Coroutine

2020-12-04 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:1309
+// Intrinsic to obtain the address of a thread_local variable.
+def int_threadlocal : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty]>;
+

With the intrinsic, can TLS variable reference in the same coroutine or regular 
routine be DCE-ed anymore?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92661/new/

https://reviews.llvm.org/D92661

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


[PATCH] D92661: [RFC] Fix TLS and Coroutine

2020-12-04 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:1309
+// Intrinsic to obtain the address of a thread_local variable.
+def int_threadlocal : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty]>;
+

hoy wrote:
> With the intrinsic, can TLS variable reference in the same coroutine or 
> regular routine be DCE-ed anymore?
Sorry, I meant CSE-ed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92661/new/

https://reviews.llvm.org/D92661

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


[PATCH] D92661: [RFC] Fix TLS and Coroutine

2020-12-04 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:1309
+// Intrinsic to obtain the address of a thread_local variable.
+def int_threadlocal : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty]>;
+

lxfind wrote:
> hoy wrote:
> > hoy wrote:
> > > With the intrinsic, can TLS variable reference in the same coroutine or 
> > > regular routine be DCE-ed anymore?
> > Sorry, I meant CSE-ed.
> Since the intrinsics does not have readnone attribute, it won't be CSE-ed 
> before CoroSplit.
> However after CoroSplit, it will be lowered back to the direct reference of 
> the TLS, and will be CSE-ed by latter passes.
> I can add a test function to demonstrate that too.
Sounds good. Can you please point out what optimization passes CSE-ed tls 
reference without this implementation? I'm wondering if those optimizations can 
be postponed to after CoroSplit. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92661/new/

https://reviews.llvm.org/D92661

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


[PATCH] D92661: [RFC] Fix TLS and Coroutine

2020-12-07 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/Intrinsics.td:1309
+// Intrinsic to obtain the address of a thread_local variable.
+def int_threadlocal : Intrinsic<[llvm_ptr_ty], [llvm_ptr_ty]>;
+

lxfind wrote:
> hoy wrote:
> > lxfind wrote:
> > > hoy wrote:
> > > > hoy wrote:
> > > > > With the intrinsic, can TLS variable reference in the same coroutine 
> > > > > or regular routine be DCE-ed anymore?
> > > > Sorry, I meant CSE-ed.
> > > Since the intrinsics does not have readnone attribute, it won't be CSE-ed 
> > > before CoroSplit.
> > > However after CoroSplit, it will be lowered back to the direct reference 
> > > of the TLS, and will be CSE-ed by latter passes.
> > > I can add a test function to demonstrate that too.
> > Sounds good. Can you please point out what optimization passes CSE-ed tls 
> > reference without this implementation? I'm wondering if those optimizations 
> > can be postponed to after CoroSplit. 
> To clarify, it wasn't just CSE that would merge the references of the same 
> TLS.
> For instance, without this patch, a reference to "tls_variable" will just be 
> "@tls_variable". For code like this:
> 
>   @tls_variable = internal thread_local global i32 0, align 4
> 
>   define i32* @foo(){
> ret i32* @tls_variable
>   }
>   
>   define void @bar() {
> %tls1 = call i32* @foo()
> ..coro.suspend..
> %tls2 = call i32* @foo()
> %cond = icmp eq i32* %tls1, %tls2
>   }
> 
> When foo() is inlined into bar(), all uses of %tls1 will be replaced with 
> @tls_variable.
Thanks for the explanation. I have a dumb question. Why isn't corosplit placed 
at the very beginning of the pipeline?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92661/new/

https://reviews.llvm.org/D92661

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


[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe

2020-12-14 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: dexonsmith, wenlei, hiraditya.
hoy requested review of this revision.
Herald added subscribers: llvm-commits, cfe-commits, jdoerfert.
Herald added projects: clang, LLVM.

Sample re-annotation is required in LTO time to achieve a reasonable 
post-inline profile quality. However, we have seen that such LTO-time 
re-annotation degrades profile quality. This is mainly caused by preLTO code 
duplication that is done by passes such as loop unrolling, jump threading, 
indirect call promotion etc, where samples corresponding to a source location 
are aggregated multiple times due to the duplicates. In this change we are 
introducing a concept of distribution factor for pseudo probes so that samples 
can be distributed for duplicated probes scaled by a factor, with the hope that 
optimizations duplicating code well maintains the branch frequency information 
(BFI) based on which probe distribution factors are calculated. Distribution 
factors are updated at the end of preLTO pipeline to reflect an estimated 
portion of the real execution count.

This change also introduces a pseudo probe verifier that can be run after each 
IR passes to detect duplicated pseudo probes.

A saturated distribution factor stands for 1.0. A duplicated probe will carry a 
factor with the value ranged from 0.0 to 1.0. A 64-bit integral distribution 
factor field that represents [0.0, 1.0] is associated to each block probe. 
Unfortunately this cannot be done for callsite probes due to the size 
limitation of a 32-bit Dwarf discriminator. A 7-bit distribution factor is used 
instead.

Changes are also needed to the sample profile inliner to deal with prorated 
callsite counts. The changes have a dependency on the CS inliner and thus not 
included here.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY-DAG: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY-DAG: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+ 

[PATCH] D93264: [CSSPGO] Introducing distribution factor for pseudo probe.

2020-12-16 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 312339.
hoy added a comment.

Rebasing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93264/new/

https://reviews.llvm.org/D93264

Files:
  clang/test/CodeGen/pseudo-probe-emit.c
  llvm/include/llvm/IR/IntrinsicInst.h
  llvm/include/llvm/IR/Intrinsics.td
  llvm/include/llvm/IR/PseudoProbe.h
  llvm/include/llvm/Passes/StandardInstrumentations.h
  llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
  llvm/lib/IR/PseudoProbe.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Passes/PassRegistry.def
  llvm/lib/Passes/StandardInstrumentations.cpp
  llvm/lib/Transforms/IPO/SampleProfile.cpp
  llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
  llvm/test/Transforms/SampleProfile/Inputs/pseudo-probe-update.prof
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit-inline.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-emit.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-profile.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
  llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll

Index: llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-verify.ll
@@ -0,0 +1,77 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='pseudo-probe,loop-unroll-full' -verify-pseudo-probe -S -o %t 2>&1 | FileCheck %s --check-prefix=VERIFY
+; RUN: FileCheck %s < %t
+
+; VERIFY: *** Pseudo Probe Verification After LoopFullUnrollPass ***
+; VERIFY: Function foo:
+; VERIFY-DAG: Probe 6	previous factor 1.00	current factor 5.00
+; VERIFY-DAG: Probe 4	previous factor 1.00	current factor 5.00
+
+declare void @foo2() nounwind
+
+define void @foo(i32 %x) {
+bb:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 1, i32 0, i64 -1)
+  %tmp = alloca [5 x i32*], align 16
+  br label %bb7.preheader
+
+bb3.loopexit:
+  %spec.select.lcssa = phi i32 [ %spec.select, %bb10 ]
+  %tmp5.not = icmp eq i32 %spec.select.lcssa, 0
+  br i1 %tmp5.not, label %bb24, label %bb7.preheader
+
+bb7.preheader:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 3, i32 0, i64 -1)
+  %tmp1.06 = phi i32 [ 5, %bb ], [ %spec.select.lcssa, %bb3.loopexit ]
+  br label %bb10
+
+bb10:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 4, i32 0, i64 -1)
+; CHECK: call void @foo2(), !dbg ![[#PROBE6:]] 
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 2, i32 0, i64 -1)
+  %indvars.iv = phi i64 [ 0, %bb7.preheader ], [ %indvars.iv.next, %bb10 ]
+  %tmp1.14 = phi i32 [ %tmp1.06, %bb7.preheader ], [ %spec.select, %bb10 ]
+  %tmp13 = getelementptr inbounds [5 x i32*], [5 x i32*]* %tmp, i64 0, i64 %indvars.iv
+  %tmp14 = load i32*, i32** %tmp13, align 8
+  %tmp15.not = icmp ne i32* %tmp14, null
+  %tmp18 = sext i1 %tmp15.not to i32
+  %spec.select = add nsw i32 %tmp1.14, %tmp18
+  call void @foo2(), !dbg !12
+  %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
+  %exitcond.not = icmp eq i64 %indvars.iv.next, 5
+  br i1 %exitcond.not, label %bb3.loopexit, label %bb10, !llvm.loop !13
+
+bb24:
+; CHECK: call void @llvm.pseudoprobe(i64 [[#GUID:]], i64 5, i32 0, i64 -1)
+  ret void
+}
+
+;; A discriminator of 186646583 which is 0xb200037 in hexdecimal, stands for a direct call probe
+;; with an index of 6 and a scale of -1%.
+; CHECK: ![[#PROBE6]] = !DILocation(line: 2, column: 20, scope: ![[#SCOPE:]])
+; CHECK: ![[#SCOPE]] = !DILexicalBlockFile(scope: ![[#]], file: ![[#]], discriminator: 186646583)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!9, !10}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, emissionKind: 1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 2, type: !5, isLocal: false, isDefinition: true, scopeLine: 2, isOptimized: false, unit: !0, retainedNodes: !2)
+!5 = !DISubroutineType(types: !6)
+!6 = !{!7}
+!7 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
+!9 = !{i32 2, !"Dwarf Version", i32 4}
+!10 = !{i32 2, !"Debug Info Version", i32 3}
+!11 = !{!"clang version 3.9.0"}
+!12 = !DILocation(line: 2, column: 20, scope: !4)
+!13 = distinct !{!13, !14}
+!14 = !{!"llvm.loop.unroll.full"}
Index: llvm/test/Transforms/SampleProfile/pseudo-probe-update.ll
===
--- /dev/null
+++ llvm/test/Transforms/SampleProfile/pseudo-probe-up

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: dexonsmith, wenlei, hiraditya.
hoy requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

`UniqueInternalLinkageNamesPass` is useful to CSSPGO, especially when pseudo 
probe is used. It solves naming conflict for static functions which otherwise 
will share a merged profile and likely have a profile quality issue with 
mismatched CFG checksums. Since the pseudo probe instrumentation happens very 
early in the pipeline, I'm moving `UniqueInternalLinkageNamesPass` right before 
it. This is being done only to the new pass manager. In addition, funtions that 
are renamed have their debug linkage name and an AutoFDO attribute updated 
optionally.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93656

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/unique-internal-linkage-names.cpp
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/IR/DebugInfoMetadata.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp

Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -13,13 +13,20 @@
 
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
 using namespace llvm;
 
+static cl::opt UniqueDebugAndProfileNames(
+"unqiue-debug-profile-names", cl::init(false), cl::Hidden,
+cl::desc("Uniqueify debug and profile symbol Names"));
+
 static bool uniqueifyInternalLinkageNames(Module &M) {
   llvm::MD5 Md5;
   Md5.update(M.getSourceFileName());
@@ -31,11 +38,19 @@
   // this symbol is of internal linkage type.
   std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
+  MDBuilder MDB(M.getContext());
 
   // Append the module hash to all internal linkage functions.
   for (auto &F : M) {
 if (F.hasInternalLinkage()) {
   F.setName(F.getName() + ModuleNameHash);
+  if (UniqueDebugAndProfileNames) {
+F.addFnAttr("sample-profile-suffix-elision-policy", "selected");
+if (DISubprogram *SP = F.getSubprogram()) {
+  auto Name = MDB.createString(F.getName());
+  SP->replaceRawLinkageName(Name);
+}
+  }
   Changed = true;
 }
   }
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -434,8 +434,10 @@
 
 PassBuilder::PassBuilder(bool DebugLogging, TargetMachine *TM,
  PipelineTuningOptions PTO, Optional PGOOpt,
- PassInstrumentationCallbacks *PIC)
-: DebugLogging(DebugLogging), TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
+ PassInstrumentationCallbacks *PIC,
+ bool UniqueLinkageNames)
+: DebugLogging(DebugLogging), UniqueLinkageNames(UniqueLinkageNames),
+  TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
   if (TM)
 TM->registerPassBuilderCallbacks(*this, DebugLogging);
   if (PIC && shouldPopulateClassToPassNames()) {
@@ -1001,6 +1003,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1771,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/lib/IR/DebugInfoMetadata.cpp
===
--- llvm/lib/IR/DebugInfoMetadata.cpp
+++ llvm/lib/IR/DebugInfoMetadata.cpp
@@ -877,6 +877,10 @@
   return F->getSubprogram() == this;
 }
 
+void DISubprogram::replaceRawLinkageName(MDString *LinkageName) {
+  replaceOperandWith(3, LinkageName);
+}
+
 DILexicalBlock *DILexicalBlock::getImpl(LLVMContext &Context, Metadata *Scope,
 

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp:27
+static cl::opt UniqueDebugAndProfileNames(
+"unqiue-debug-profile-names", cl::init(false), cl::Hidden,
+cl::desc("Uniqueify debug and profile symbol Names"));

tmsriram wrote:
> Can we make it true by default?  Atleast the DW_AT_linkage_name must reflect 
> the new name by default IMO.
Sounds good.



Comment at: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp:51
+  auto Name = MDB.createString(F.getName());
+  SP->replaceRawLinkageName(Name);
+}

tmsriram wrote:
> Do we need to check if it had a rawLinkageName before replacing it?  
Good point. `rawLinkageName` is missing for C programs. I think it might still 
be appropriate to assign a new linkage name in the case so as to differ from 
the original source function name. What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93656#2466689 , @tmsriram wrote:

> https://reviews.llvm.org/D73307#1932131  rnk@ mentioned this :  "At a higher 
> level, should this just be an IR pass that clang adds into the pipeline when 
> the flag is set? It should be safe to rename internal functions and give 
> private functions internal linkage. It would be less invasive to clang and 
> have better separation of concerns. As written, this is based on the source 
> filename on the module, which is accessible from IR. The only reason I can 
> think of against this is that the debug info might refer to the function 
> linkage name, but maybe that is calculated later during codegen."
>
> I just wanted to mention it  here that this was anticipated and was missed in 
> the original patch, my bad as I didnt think about DebugInfo change.  However, 
> I think it is pretty straightforward to change the linkage name so I would 
> still keep the pass approach.

Thanks for the information. Yeah it's pretty straightforward hook it up with 
debug info as an IR pass.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy marked 2 inline comments as done.
hoy added inline comments.



Comment at: llvm/lib/IR/DebugInfoMetadata.cpp:881
+void DISubprogram::replaceRawLinkageName(MDString *LinkageName) {
+  replaceOperandWith(3, LinkageName);
+}

tmsriram wrote:
> Nit, Move the body to DebugInfoMetadata.h itself? 
Done.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313187.
hoy marked an inline comment as done.
hoy added a comment.

Addressing feedbacks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/unique-internal-linkage-names.cpp
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp

Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -13,13 +13,20 @@
 
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/MD5.h"
 #include "llvm/Transforms/Utils/ModuleUtils.h"
 
 using namespace llvm;
 
+static cl::opt UniqueDebugAndProfileNames(
+"unqiue-debug-profile-names", cl::init(true), cl::Hidden,
+cl::desc("Uniqueify debug and profile symbol Names"));
+
 static bool uniqueifyInternalLinkageNames(Module &M) {
   llvm::MD5 Md5;
   Md5.update(M.getSourceFileName());
@@ -31,11 +38,19 @@
   // this symbol is of internal linkage type.
   std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
+  MDBuilder MDB(M.getContext());
 
   // Append the module hash to all internal linkage functions.
   for (auto &F : M) {
 if (F.hasInternalLinkage()) {
   F.setName(F.getName() + ModuleNameHash);
+  if (UniqueDebugAndProfileNames) {
+F.addFnAttr("sample-profile-suffix-elision-policy", "selected");
+if (DISubprogram *SP = F.getSubprogram()) {
+  auto *Name = MDB.createString(F.getName());
+  SP->replaceRawLinkageName(Name);
+}
+  }
   Changed = true;
 }
   }
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -434,8 +434,10 @@
 
 PassBuilder::PassBuilder(bool DebugLogging, TargetMachine *TM,
  PipelineTuningOptions PTO, Optional PGOOpt,
- PassInstrumentationCallbacks *PIC)
-: DebugLogging(DebugLogging), TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
+ PassInstrumentationCallbacks *PIC,
+ bool UniqueLinkageNames)
+: DebugLogging(DebugLogging), UniqueLinkageNames(UniqueLinkageNames),
+  TM(TM), PTO(PTO), PGOOpt(PGOOpt), PIC(PIC) {
   if (TM)
 TM->registerPassBuilderCallbacks(*this, DebugLogging);
   if (PIC && shouldPopulateClassToPassNames()) {
@@ -1001,6 +1003,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1771,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -137,6 +137,7 @@
 /// construction.
 class PassBuilder {
   bool DebugLogging;
+  bool UniqueLinkageNames;
   TargetMachine *TM;
   PipelineTuningOptions PTO;
   Optional PGOOpt;
@@ -281,7 +282,8 @@
   explicit PassBuilder(bool DebugLogging = false, TargetMachine *TM = nullptr,
PipelineTuningOptions PTO = PipelineTuningOptions(),
Optional PGOOpt = None,
-   PassInstrumentationCallbacks *PIC = nullptr);
+   PassInstrumentationCallbacks *PIC = nullptr,
+   bool UniqueLinkageNames = false);
 
   /// Cross register the analysis managers through their proxies.
   ///
Index: llvm/include/llvm/IR/DebugInfoMetadata.h
===
--- llvm/include/llvm/IR/DebugInfoMetadata.h
+++ llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -20

[PATCH] D92806: Single function compilation mode.

2020-12-21 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313221.
hoy added a comment.
Herald added subscribers: cfe-commits, dexonsmith, dang, steven_wu, MaskRay, 
arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a reviewer: MaskRay.
Herald added a project: clang.

Adding LTO, linker and clang supports.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D92806/new/

https://reviews.llvm.org/D92806

Files:
  clang/include/clang/Basic/CodeGenOptions.h
  clang/include/clang/Driver/Options.td
  clang/lib/CodeGen/BackendUtil.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/test/CodeGen/single-func.c
  lld/ELF/Config.h
  lld/ELF/Driver.cpp
  lld/ELF/LTO.cpp
  lld/ELF/Options.td
  lld/test/ELF/lto/lto-single-func.ll
  llvm/include/llvm/LTO/Config.h
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/include/llvm/Transforms/IPO/FuncExtractor.h
  llvm/lib/LTO/LTO.cpp
  llvm/lib/LTO/LTOBackend.cpp
  llvm/lib/Passes/PassBuilder.cpp
  llvm/lib/Transforms/IPO/ExtractGV.cpp
  llvm/test/Other/Inputs/single-func.ll
  llvm/test/Other/single-func.ll
  llvm/tools/llvm-lto2/llvm-lto2.cpp
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -117,6 +117,11 @@
  "the OptimizerLast extension point into default pipelines"),
 cl::Hidden);
 
+static cl::list SingleFuncList(
+"single-func", cl::value_desc("function names"),
+cl::desc("Only compile functions whose names are in the list"),
+cl::CommaSeparated, cl::Hidden);
+
 // Individual pipeline tuning options.
 extern cl::opt DisableLoopUnrolling;
 
@@ -384,6 +389,7 @@
   PB.registerFunctionAnalyses(FAM);
   PB.registerLoopAnalyses(LAM);
   PB.crossRegisterProxies(LAM, FAM, CGAM, MAM);
+  PB.registerFunctionsToCompile(SingleFuncList);
 
   ModulePassManager MPM(DebugPM);
   if (VK > VK_NoVerifier)
Index: llvm/tools/llvm-lto2/llvm-lto2.cpp
===
--- llvm/tools/llvm-lto2/llvm-lto2.cpp
+++ llvm/tools/llvm-lto2/llvm-lto2.cpp
@@ -158,6 +158,11 @@
 PassPlugins("load-pass-plugin",
 cl::desc("Load passes from plugin library"));
 
+static cl::list
+SingleFuncList("single-func", cl::value_desc("function names"),
+   cl::desc("Only compile functions whose name match this"),
+   cl::CommaSeparated, cl::Hidden);
+
 static void check(Error E, std::string Msg) {
   if (!E)
 return;
@@ -297,6 +302,7 @@
   Conf.StatsFile = StatsFile;
   Conf.PTO.LoopVectorization = Conf.OptLevel > 1;
   Conf.PTO.SLPVectorization = Conf.OptLevel > 1;
+  Conf.LTOFunctionsToCompile = SingleFuncList;
 
   ThinBackend Backend;
   if (ThinLTODistributedIndexes)
Index: llvm/test/Other/single-func.ll
===
--- /dev/null
+++ llvm/test/Other/single-func.ll
@@ -0,0 +1,75 @@
+; REQUIRES: x86_64-linux
+; RUN: opt < %s -passes='default' -single-func=foo -S -o %t0 | FileCheck %s --check-prefix=FOO
+; RUN: opt < %s -passes='default' -single-func=foo -S -o %t1 | FileCheck %s --check-prefix=RECUR-FOO
+; RUN: opt < %s -passes='default' -single-func=foo -single-func=bar -S -o %t2 | FileCheck %s --check-prefix=FOO-BAR
+; RUN: opt < %s -passes='default' -single-func=foo -single-func=bar -S -o %t2 | FileCheck %s --check-prefix=FOO-BAR
+
+; RUN: opt -thinlto-bc -o %t3.bc %s
+; RUN: opt -thinlto-bc -o %t4.bc %S/Inputs/single-func.ll
+; RUN: llvm-lto2 run -use-new-pm -single-func=foo %t3.bc %t4.bc -o %t5 -r %t3.bc,main,px -r %t3.bc,foo,px  -r %t3.bc,bar,px -r %t3.bc,go,px -r %t4.bc,other,px  | FileCheck %s --check-prefix=RECUR-FOO
+
+; RUN: opt -o %t3.bc %s
+; RUN: opt -o %t4.bc %S/Inputs/single-func.ll
+; RUN: llvm-lto2 run -use-new-pm -single-func=foo %t3.bc %t4.bc -o %t5 -r %t3.bc,main,px -r %t3.bc,foo,px  -r %t3.bc,bar,px -r %t3.bc,go,px -r %t4.bc,other,px  | FileCheck %s --check-prefix=RECUR-FOO
+
+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-scei-ps4"
+
+define dso_local i32 @main(i32 %x, i32 (i32)* %f) {
+  call i32 @foo(i32 %x, i32 (i32)* %f)
+  ret i32 1
+}
+
+define dso_local i32 @foo(i32 %x, i32 (i32)* %f) {
+entry:
+  %retval = alloca i32, align 4
+  %x.addr = alloca i32, align 4
+  store i32 %x, i32* %x.addr, align 4
+  %0 = load i32, i32* %x.addr, align 4
+  %cmp = icmp eq i32 %0, 0
+  br i1 %cmp, label %if.then, label %if.else
+
+if.then:
+  call i32 @bar()
+  store i32 1, i32* %retval, align 4
+  br label %return
+
+if.else:
+  call i32 %f(i32 1), !prof !0
+  store i32 2, i32* %retval, align 4
+  br label %return
+
+return:
+  %3 = load i32, i32* %retval, align 4
+  ret i32 %3
+}
+
+define dso_local i32 @bar() {
+entry:
+  ret i32 8
+}
+
+define dso_local i32 @go() {
+entry:
+  ret i32 6
+}
+
+!0 = !{!"VP"

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/include/llvm/IR/DebugInfoMetadata.h:2056-2059
+  void replaceRawLinkageName(MDString *LinkageName) {
+replaceOperandWith(3, LinkageName);
+  }
+

tmsriram wrote:
> dblaikie wrote:
> > The need to add this API makes me a bit uncertain that it's the right 
> > direction - any chance you could find other examples of Function 
> > duplication in LLVM passes (maybe the partial inliner? Perhaps when it 
> > partially inlines an external function it has to clone the function so the 
> > external version remains identical?) and how they deal with debug info? 
> > Perhaps there's an existing API/mechanism to update the DISubprogram as you 
> > want without adding this.
> This does not seem like a radical new API to me.  We could use existing 
> setOperand or replaceOperandWith here but need a public wrapper to expose it, 
> just like getRawLinkageName.  For example, DICompositeType is mutated like 
> this with buildODRType.
Yeah, it would be nice to leverage an existing API like this but unfortunately 
I haven't found any.

Regarding passes that duplicate functions, I think the renaming done by 
`UniqueInternalLinkageNamesPass` is transparent to subsequent passes, since it 
is placed very early in the pipeline before any inlining or cloning passes.



Comment at: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp:26-29
+static cl::opt UniqueDebugAndProfileNames(
+"unqiue-debug-profile-names", cl::init(true), cl::Hidden,
+cl::desc("Uniqueify debug and profile symbol Names"));
+

dblaikie wrote:
> Do you have plans to use the flag in testing, etc? If not, I guess you might 
> as well bake in the behavior you want if no one else is using this/there's no 
> current use case for the flexibility?
I'm not quite sure if updating debug names are required in all use cases. 
@tmsriram do you think we can just remove the flag?



Comment at: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp:48
+  if (UniqueDebugAndProfileNames) {
+F.addFnAttr("sample-profile-suffix-elision-policy", "selected");
+if (DISubprogram *SP = F.getSubprogram()) {

dblaikie wrote:
> What's this about/for? Should this be in an independent change?
This is about how the sample profile loader deals with renamed functions. The 
sample loader will use the original function name (i.e, by ignoring all 
suffixes appended) to retrieve a profile by default. With the attribute set 
here. the sample loader will only ignore certain suffixes not including the one 
(.__uniq.) appended here. Please see `getCanonicalFnName` in `SampleProf.h` for 
details. The reason that names are uniquefied here for AutoFDO is to have the 
sample loader differentiate same-named static functions, so the change is sort 
of related here.

I'll put more comments for that.  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93656#2468821 , @aeubanks wrote:

> Also it looks like this is doing 2 different things, the moving of things 
> from Clang to LLVM's PassBuilder, and separately the change to the pass 
> itself. Can these be separated?

I'm not sure about a good way to separate them. There are Clang tests that may 
fail with removing the pass from clang while not adding it correspondingly in 
llvm. Adding the pass in llvm while not removing it from Clang may cause the 
pass to run twice which may also fail the Clang tests. What do you think?




Comment at: llvm/include/llvm/Passes/PassBuilder.h:140
   bool DebugLogging;
+  bool UniqueLinkageNames;
   TargetMachine *TM;

aeubanks wrote:
> This seems better suited to be part of PipelineTuningOptions rather than 
> directly in PassBuilder
Sounds good. Will move it into PipelineTuningOptions.



Comment at: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp:26-29
+static cl::opt UniqueDebugAndProfileNames(
+"unqiue-debug-profile-names", cl::init(true), cl::Hidden,
+cl::desc("Uniqueify debug and profile symbol Names"));
+

tmsriram wrote:
> hoy wrote:
> > dblaikie wrote:
> > > Do you have plans to use the flag in testing, etc? If not, I guess you 
> > > might as well bake in the behavior you want if no one else is using 
> > > this/there's no current use case for the flexibility?
> > I'm not quite sure if updating debug names are required in all use cases. 
> > @tmsriram do you think we can just remove the flag?
> I vote for removing it.
Sounds good, will remove it.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93656#2468841 , @aeubanks wrote:

> In D93656#2468834 , @hoy wrote:
>
>> In D93656#2468821 , @aeubanks wrote:
>>
>>> Also it looks like this is doing 2 different things, the moving of things 
>>> from Clang to LLVM's PassBuilder, and separately the change to the pass 
>>> itself. Can these be separated?
>>
>> I'm not sure about a good way to separate them. There are Clang tests that 
>> may fail with removing the pass from clang while not adding it 
>> correspondingly in llvm. Adding the pass in llvm while not removing it from 
>> Clang may cause the pass to run twice which may also fail the Clang tests. 
>> What do you think?
>
> I mean keep that in one change, but separate out the change to 
> llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp and 
> DebugInfoMetadata.h.

I see, thanks for the clarification.

In D93656#2468698 , @dblaikie wrote:

> This should have a LLVM test coverage for the LLVM changes. (I realize 
> they're also tested by the Clang test, because there's no way to test Clang's 
> pass manager creation short of testing the effect of running the pass manager 
> (hmm - /maybe/ there's a way to dump the pass pipeline? In which case that's 
> how Clang should be tested, just testing that it creates the right pipeline, 
> not that that pipeline does any particular thing))

Added an IR test. There is the llvm switch `-debug-pass=` that can dump the 
pass pipeline. I'm not aware of a clang switch that can do that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313487.
hoy added a comment.

Separated PassBuilder changes.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,36 @@
+; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0, !dbg !18
+}
+
+define dso_local i32 (...)* @bar() !dbg !7 {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), !dbg !14
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13, null}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !DILocation(line: 10, column: 3, scope: !7)
+!15 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DILocation(line: 6, column: 3, scope: !15)
+
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() [[ATTR:#[0-9]+]] !dbg ![[#DBG:]]
+; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1001,6 +1001,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1769,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -127,6 +127,9 @@
   /// Tuning option to enable/disable function merging. Its default value is
   /// false.
   bool MergeFunctions;
+
+  /// Uniquefy function linkage name. Its default value is false.
+  bool UniqueLinkageNames;
 };
 
 /// This class provides access to building LLVM's passes.
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1144,6 +1144,7 @@
   // non-integrated assemblers don't recognize .cgprofile section.
   PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
   PTO.Coroutines = LangOpts.Coroutines;
+  PTO.UniqueLinkageNames = CodeGenOpts.UniqueInternalLinkageNames;
 
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
@@ -1325,11 +1326,6 @@
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
 
-// Add UniqueInternalLinkageNames Pass which renames internal linkage
-// symbols with unique names.
-if (CodeGenOpts.UniqueInternalLinkageNames)
-  MPM.addPass(UniqueInternalLinkageNamesPass());
-
 if (!CodeGenOpts.MemoryProfileOutput.empty()) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313488.
hoy added a comment.

Fixing IR test failure.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,36 @@
+; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0, !dbg !18
+}
+
+define dso_local i32 (...)* @bar() !dbg !7 {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), !dbg !14
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13, null}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !DILocation(line: 10, column: 3, scope: !7)
+!15 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DILocation(line: 6, column: 3, scope: !15)
+
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -1001,6 +1001,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1769,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -127,6 +127,9 @@
   /// Tuning option to enable/disable function merging. Its default value is
   /// false.
   bool MergeFunctions;
+
+  /// Uniquefy function linkage name. Its default value is false.
+  bool UniqueLinkageNames;
 };
 
 /// This class provides access to building LLVM's passes.
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -1144,6 +1144,7 @@
   // non-integrated assemblers don't recognize .cgprofile section.
   PTO.CallGraphProfile = !CodeGenOpts.DisableIntegratedAS;
   PTO.Coroutines = LangOpts.Coroutines;
+  PTO.UniqueLinkageNames = CodeGenOpts.UniqueInternalLinkageNames;
 
   PassInstrumentationCallbacks PIC;
   StandardInstrumentations SI(CodeGenOpts.DebugPassManager);
@@ -1325,11 +1326,6 @@
   MPM = PB.buildPerModuleDefaultPipeline(Level);
 }
 
-// Add UniqueInternalLinkageNames Pass which renames internal linkage
-// symbols with unique names.
-if (CodeGenOpts.UniqueInternalLinkageNames)
-  MPM.addPass(UniqueInternalLinkageNamesPass());
-
 if (!CodeGenOpts.MemoryProfileOutput.empty()) {
   MPM.addPass(createModuleToFunctionPassAdaptor(MemProfilerPass()));
   MPM.addPass(ModuleMemProfilerPass());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy created this revision.
Herald added subscribers: dexonsmith, wenlei, hiraditya.
hoy requested review of this revision.
Herald added projects: clang, LLVM.
Herald added subscribers: llvm-commits, cfe-commits.

Funtions that are renamed under -funique-internal-linkage-names have their 
debug linkage name updated as well.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D93747

Files:
  clang/test/CodeGen/unique-internal-linkage-names.cpp
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll


Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -32,5 +32,6 @@
 !17 = !{!13}
 !18 = !DILocation(line: 6, column: 3, scope: !15)
 
-; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() !dbg ![[#DBG:]]
 ; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
+; CHECK: ![[#DBG]] = distinct !DISubprogram(name: "foo", linkageName: 
"foo.__uniq.{{[0-9a-f]+}}"
Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -13,6 +13,8 @@
 
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/MD5.h"
@@ -31,11 +33,16 @@
   // this symbol is of internal linkage type.
   std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
+  MDBuilder MDB(M.getContext());
 
   // Append the module hash to all internal linkage functions.
   for (auto &F : M) {
 if (F.hasInternalLinkage()) {
   F.setName(F.getName() + ModuleNameHash);
+  if (DISubprogram *SP = F.getSubprogram()) {
+auto *Name = MDB.createString(F.getName());
+SP->replaceRawLinkageName(Name);
+  }
   Changed = true;
 }
   }
Index: llvm/include/llvm/IR/DebugInfoMetadata.h
===
--- llvm/include/llvm/IR/DebugInfoMetadata.h
+++ llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2053,6 +2053,10 @@
 return getNumOperands() > 10 ? getOperandAs(10) : nullptr;
   }
 
+  void replaceRawLinkageName(MDString *LinkageName) {
+replaceOperandWith(3, LinkageName);
+  }
+
   /// Check if this subprogram describes the given function.
   ///
   /// FIXME: Should this be looking through bitcasts?
Index: clang/test/CodeGen/unique-internal-linkage-names.cpp
===
--- clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -5,6 +5,7 @@
 // RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
 // RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUE
 // RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | 
FileCheck %s --check-prefix=UNIQUEO1
+// RUN: %clang_cc1 -triple x86_64 -x c++ -O2 -S -emit-llvm 
-fexperimental-new-pass-manager -funique-internal-linkage-names 
-debug-info-kind=limited -o - < %s | FileCheck %s --check-prefix=UNIQUEDEBUG
 
 static int glob;
 static int foo() {
@@ -65,3 +66,5 @@
 // UNIQUEO1: define weak_odr i32 ()* @_ZL4mverv.resolver()
 // UNIQUEO1: define internal i32 @_ZL4mverv.__uniq.{{[0-9a-f]+}}()
 // UNIQUEO1: define internal i32 @_ZL4mverv.sse4.2.__uniq.{{[0-9a-f]+}}
+// UNIQUEDEBUG: define internal i32 @_ZL3foov.__uniq.{{[0-9a-f]+}}() 
[[ATTR:#[0-9]+]] !dbg ![[#DBG:]]
+// UNIQUEDEBUG: ![[#DBG]] = distinct !DISubprogram(name: "foo", linkageName: 
"_ZL3foov.__uniq.{{[0-9a-f]+}}"


Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -32,5 +32,6 @@
 !17 = !{!13}
 !18 = !DILocation(line: 6, column: 3, scope: !15)
 
-; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() !dbg ![[#DBG:]]
 ; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
+; CHECK: ![[#DBG]] = distinct !DISubprogram(name: "foo", li

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

The changes that rename debug linkage name has been separated as D93747 
. I'm moving the discussion there.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

> In D93656 , @dblaikie wrote:
> Though the C case is interesting - it means you'll end up with C functions 
> with the same DWARF 'name' but different linkage name. I don't know what 
> that'll do to DWARF consumers - I guess they'll probably be OK-ish with it, 
> as much as they are with C++ overloading. I think there are some cases of C 
> name mangling so it's probably supported/OK-ish with DWARF Consumers. 
> Wouldn't hurt for you to take a look/see what happens in that case with a 
> debugger like gdb/check other cases of C name mangling to see what DWARF they 
> end up creating (with both GCC and Clang).

I did a quick experiment with C name managing with GCC and -flto. It turns out 
the `DW_AT_linkage_name` field of `DW_TAG_subprogram` is never set for C 
programs. If set, the gdb debugger will use that field to match the user input 
and set breakpoints. Therefore, giving `DW_AT_linkage_name` a uniquefied name 
prevents the debugger from setting a breakpoint based on source names unless 
the user specifies a decorated name.

Hence, this approach sounds like a workaround for us when the profile quality 
matters more than debugging experience. I'm inclined to have it under a switch. 
What do you think?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-22 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93656#2469504 , @dblaikie wrote:

> In D93656#2469485 , @hoy wrote:
>
>> In D93656#2468841 , @aeubanks wrote:
>>
>>> In D93656#2468834 , @hoy wrote:
>>>
 In D93656#2468821 , @aeubanks 
 wrote:

> Also it looks like this is doing 2 different things, the moving of things 
> from Clang to LLVM's PassBuilder, and separately the change to the pass 
> itself. Can these be separated?

 I'm not sure about a good way to separate them. There are Clang tests that 
 may fail with removing the pass from clang while not adding it 
 correspondingly in llvm. Adding the pass in llvm while not removing it 
 from Clang may cause the pass to run twice which may also fail the Clang 
 tests. What do you think?
>>>
>>> I mean keep that in one change, but separate out the change to 
>>> llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp and 
>>> DebugInfoMetadata.h.
>>
>> I see, thanks for the clarification.
>>
>> In D93656#2468698 , @dblaikie wrote:
>>
>>> This should have a LLVM test coverage for the LLVM changes. (I realize 
>>> they're also tested by the Clang test, because there's no way to test 
>>> Clang's pass manager creation short of testing the effect of running the 
>>> pass manager (hmm - /maybe/ there's a way to dump the pass pipeline? In 
>>> which case that's how Clang should be tested, just testing that it creates 
>>> the right pipeline, not that that pipeline does any particular thing))
>>
>> Added an IR test. There is the llvm switch `-debug-pass=` that can dump the 
>> pass pipeline. I'm not aware of a clang switch that can do that.
>
> Seems some clang tests use something like that, eg:
>
>   clang/test/CodeGen/thinlto-debug-pm.c:// RUN: %clang_cc1 -triple 
> x86_64-unknown-linux-gnu -emit-obj -O0 -o %t2.o -x ir %t.o 
> -fthinlto-index=%t.thinlto.bc -fno-experimental-new-pass-manager -mllvm 
> -debug-pass=Structure 2>&1 | FileCheck %s --check-prefix=O0-OLDPM

Thanks for pointing that out. It seems that only works with the legacy pass 
manager when `-emit-llvm` is specified. With a quick search in the clang 
regression tests it looks like the pipeline dumps are rarely checked there. 
Such checks are done quite a bit in llvm tests though. Does the current clang 
test look okay to you, or do you prefer checking the pipeline dump there? 
Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313566.
hoy edited the summary of this revision.
hoy added a comment.

Checking pipeline in clang test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/unique-internal-linkage-names.cpp
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll

Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,37 @@
+; RUN: opt -S -unique-internal-linkage-names < %s | FileCheck %s
+; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0, !dbg !18
+}
+
+define dso_local i32 (...)* @bar() !dbg !7 {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), !dbg !14
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13, null}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !DILocation(line: 10, column: 3, scope: !7)
+!15 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DILocation(line: 6, column: 3, scope: !15)
+
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -284,6 +284,7 @@
   LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
   CallGraphProfile = true;
   MergeFunctions = false;
+  UniqueLinkageNames = false;
 }
 
 extern cl::opt EnableConstraintElimination;
@@ -1001,6 +1002,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1770,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/PassBuilder.h
+++ llvm/include/llvm/Passes/PassBuilder.h
@@ -127,6 +127,9 @@
   /// Tuning option to enable/disable function merging. Its default value is
   /// false.
   bool MergeFunctions;
+
+  /// Uniquefy function linkage name. Its default value is false.
+  bool UniqueLinkageNames;
 };
 
 /// This class provides access to building LLVM's passes.
Index: clang/test/CodeGen/unique-internal-linkage-names.cpp
===
--- clang/test/CodeGen/unique-internal-linkage-names.cpp
+++ clang/test/CodeGen/unique-internal-linkage-names.cpp
@@ -1,10 +1,10 @@
 // This test checks if internal linkage symbols get unique names with
 // -funique-internal-linkage-names option.
 // RUN: %clang_cc1 -triple x86_64 -x c++ -S -emit-llvm -o - < %s | FileCheck %s --check-prefix=PLAIN
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUE
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O1 -S -emit-llvm -funique-internal-linkage-names -o - < %s | FileCheck %s --check-prefix=UNIQUEO1
-// RUN: %clang_cc1 -triple x86_64 -x c++ -O0 -S -emit-llvm -fexperimental-new-pass-manager -funique-internal-linkage-names -o - < %s | FileCheck %s -

[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93747#2470178 , @tmsriram wrote:

> In D93747#2469556 , @hoy wrote:
>
>>> In D93656 , @dblaikie wrote:
>>> Though the C case is interesting - it means you'll end up with C functions 
>>> with the same DWARF 'name' but different linkage name. I don't know what 
>>> that'll do to DWARF consumers - I guess they'll probably be OK-ish with it, 
>>> as much as they are with C++ overloading. I think there are some cases of C 
>>> name mangling so it's probably supported/OK-ish with DWARF Consumers. 
>>> Wouldn't hurt for you to take a look/see what happens in that case with a 
>>> debugger like gdb/check other cases of C name mangling to see what DWARF 
>>> they end up creating (with both GCC and Clang).
>>
>> I did a quick experiment with C name managing with GCC and -flto. It turns 
>> out the `DW_AT_linkage_name` field of `DW_TAG_subprogram` is never set for C 
>> programs. If set, the gdb debugger will use that field to match the user 
>> input and set breakpoints. Therefore, giving `DW_AT_linkage_name` a 
>> uniquefied name prevents the debugger from setting a breakpoint based on 
>> source names unless the user specifies a decorated name.
>>
>> Hence, this approach sounds like a workaround for us when the profile 
>> quality matters more than debugging experience. I'm inclined to have it 
>> under a switch. What do you think?
>
> Just a thought, we could always check if rawLinkageName is set and only set 
> it when it is not null.  That seems safe without needing the option. Not a 
> strong opinion.

It seems that the demangler of the debugger is not able to handle an uniquefied 
name, even if the debug record originally comes with a linkage name.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names.cpp:48-49
 
+// LPIPELINE: Unique Internal Linkage Names
+// NPIPELINE: Running pass: UniqueInternalLinkageNamesPass
 // PLAIN: @_ZL4glob = internal global

dblaikie wrote:
> Does this test validate the new behavior? (ie: does this test fail without 
> the LLVM changes and pass with it) Not that it necessarily has to - since 
> Clang isn't here to test the LLVM behavior - perhaps this test is sufficient 
> in Clang to test that the code in BackendUtil works to enable this pass.
> 
> This could possibly be staged as independent commits - adding the LLVM 
> functionality in one commit, which would be a no-op for Clang because it 
> wouldn't be setting PTO.UniqueLinkageNames - then committing the Clang change 
> that would remove the custom pass addition and set PTO.UniqueLinkageNames - 
> and then it'd probably be reasonable to have this test be made a bit more 
> explicit (testing the pass manager structure/order) to show that that Clang 
> change had an effect: Moving the pass to the desired location in the pass 
> pipeline.
This is a good question. No, this test does not validate the pipeline change on 
the LLVM side, since Clang shouldn't have knowledge about how the pipelines are 
arranged in LLVM. As you pointed out, the test here is to test if the specific 
pass is run and gives expected results.

Thanks for the suggestion to break the Clang changes and LLVM changes apart 
which would make the testing more specific. The pipeline ordering could be 
tested with a LLVM test but that would require a LLVM switch setup for 
UniqueLinkageNames and I'm not sure there's a need for that switch except for 
testing.



Comment at: 
llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll:1-2
+; RUN: opt -S -unique-internal-linkage-names < %s | FileCheck %s
+; RUN: opt -S -passes=unique-internal-linkage-names < %s | FileCheck %s
+

dblaikie wrote:
> Does this test test any changes that are made in the rest of the patch? Since 
> the test is specifying the pass to test, I would've assumed this test would 
> pass with or without any changes that might move that pass around in the pass 
> order (or indeed add or remove it from the pass manager in general).
> 
> I'd expect this change to be tested in LLVM by a pass manager structure test, 
> similar to the Clang test.
Right, the test here does not test the specific pass order set up by this 
change. It tests that the ordering change does not revert what's already there, 
i.e, the `UniqueInternalLinkageNamesPass` is still run and gives expected 
results.

Ideally the pipeline ordering should also be tested but that would require a 
LLVM switch setup to enable the pass and I'm not sure there's a need for that 
switch except for testing.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added a comment.

In D93747#2470387 , @dblaikie wrote:

> Please remove the clang test change - if this is an LLVM change with LLVM 
> test coverage, that's enough. (we don't generally test every LLVM change from 
> both LLVM and Clang)

Sounds good.

> I'd still be curious if you could look around to see whether there are other 
> cases of function splitting/cloning/etc to see how they deal with updating 
> the DISubprograms, to see if there's some prior art that should be used here.

To the best of my knowledge, existing code does not change the linkage name 
field of a DISubprogram once created. You can create a new DISubprogram record 
with any linkage name you want but bear in mind how the debugger will consume 
the record. Looks like we are the first one to change existing record which 
will confuse the debugger.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

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


[PATCH] D93747: Rename debug linkage name with -funique-internal-linkage-names

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313607.
hoy added a comment.

Undoing changes to the clang test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93747/new/

https://reviews.llvm.org/D93747

Files:
  llvm/include/llvm/IR/DebugInfoMetadata.h
  llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll


Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -32,5 +32,6 @@
 !17 = !{!13}
 !18 = !DILocation(line: 6, column: 3, scope: !15)
 
-; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() !dbg ![[#DBG:]]
 ; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
+; CHECK: ![[#DBG]] = distinct !DISubprogram(name: "foo", linkageName: 
"foo.__uniq.{{[0-9a-f]+}}"
Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -13,6 +13,8 @@
 
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/MD5.h"
@@ -31,11 +33,16 @@
   // this symbol is of internal linkage type.
   std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
+  MDBuilder MDB(M.getContext());
 
   // Append the module hash to all internal linkage functions.
   for (auto &F : M) {
 if (F.hasInternalLinkage()) {
   F.setName(F.getName() + ModuleNameHash);
+  if (DISubprogram *SP = F.getSubprogram()) {
+auto *Name = MDB.createString(F.getName());
+SP->replaceRawLinkageName(Name);
+  }
   Changed = true;
 }
   }
Index: llvm/include/llvm/IR/DebugInfoMetadata.h
===
--- llvm/include/llvm/IR/DebugInfoMetadata.h
+++ llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2053,6 +2053,10 @@
 return getNumOperands() > 10 ? getOperandAs(10) : nullptr;
   }
 
+  void replaceRawLinkageName(MDString *LinkageName) {
+replaceOperandWith(3, LinkageName);
+  }
+
   /// Check if this subprogram describes the given function.
   ///
   /// FIXME: Should this be looking through bitcasts?


Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -32,5 +32,6 @@
 !17 = !{!13}
 !18 = !DILocation(line: 6, column: 3, scope: !15)
 
-; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; CHECK: define internal i32 @foo.__uniq.{{[0-9a-f]+}}() !dbg ![[#DBG:]]
 ; CHECK: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
+; CHECK: ![[#DBG]] = distinct !DISubprogram(name: "foo", linkageName: "foo.__uniq.{{[0-9a-f]+}}"
Index: llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
===
--- llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
+++ llvm/lib/Transforms/Utils/UniqueInternalLinkageNames.cpp
@@ -13,6 +13,8 @@
 
 #include "llvm/Transforms/Utils/UniqueInternalLinkageNames.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/IR/DebugInfoMetadata.h"
+#include "llvm/IR/MDBuilder.h"
 #include "llvm/IR/Module.h"
 #include "llvm/InitializePasses.h"
 #include "llvm/Support/MD5.h"
@@ -31,11 +33,16 @@
   // this symbol is of internal linkage type.
   std::string ModuleNameHash = (Twine(".__uniq.") + Twine(Str)).str();
   bool Changed = false;
+  MDBuilder MDB(M.getContext());
 
   // Append the module hash to all internal linkage functions.
   for (auto &F : M) {
 if (F.hasInternalLinkage()) {
   F.setName(F.getName() + ModuleNameHash);
+  if (DISubprogram *SP = F.getSubprogram()) {
+auto *Name = MDB.createString(F.getName());
+SP->replaceRawLinkageName(Name);
+  }
   Changed = true;
 }
   }
Index: llvm/include/llvm/IR/DebugInfoMetadata.h
===
--- llvm/include/llvm/IR/DebugInfoMetadata.h
+++ llvm/include/llvm/IR/DebugInfoMetadata.h
@@ -2053,6 +2053,10 @@
 return getNumOperands() > 10 ? getOperandAs(10) : nullptr;
   }
 
+  void replaceRawLinkageName(MDString *LinkageName) {
+replaceOperandWith(3, LinkageName);
+  }
+
   /// Check if this subprogram describes the given function.
   ///
   /// FIXME: Should this be l

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names.cpp:48-49
 
+// LPIPELINE: Unique Internal Linkage Names
+// NPIPELINE: Running pass: UniqueInternalLinkageNamesPass
 // PLAIN: @_ZL4glob = internal global

aeubanks wrote:
> dblaikie wrote:
> > hoy wrote:
> > > dblaikie wrote:
> > > > Does this test validate the new behavior? (ie: does this test fail 
> > > > without the LLVM changes and pass with it) Not that it necessarily has 
> > > > to - since Clang isn't here to test the LLVM behavior - perhaps this 
> > > > test is sufficient in Clang to test that the code in BackendUtil works 
> > > > to enable this pass.
> > > > 
> > > > This could possibly be staged as independent commits - adding the LLVM 
> > > > functionality in one commit, which would be a no-op for Clang because 
> > > > it wouldn't be setting PTO.UniqueLinkageNames - then committing the 
> > > > Clang change that would remove the custom pass addition and set 
> > > > PTO.UniqueLinkageNames - and then it'd probably be reasonable to have 
> > > > this test be made a bit more explicit (testing the pass manager 
> > > > structure/order) to show that that Clang change had an effect: Moving 
> > > > the pass to the desired location in the pass pipeline.
> > > This is a good question. No, this test does not validate the pipeline 
> > > change on the LLVM side, since Clang shouldn't have knowledge about how 
> > > the pipelines are arranged in LLVM. As you pointed out, the test here is 
> > > to test if the specific pass is run and gives expected results.
> > > 
> > > Thanks for the suggestion to break the Clang changes and LLVM changes 
> > > apart which would make the testing more specific. The pipeline ordering 
> > > could be tested with a LLVM test but that would require a LLVM switch 
> > > setup for UniqueLinkageNames and I'm not sure there's a need for that 
> > > switch except for testing.
> > > No, this test does not validate the pipeline change on the LLVM side, 
> > > since Clang shouldn't have knowledge about how the pipelines are arranged 
> > > in LLVM. 
> > 
> > "ish" - but Clang should have tests for changes to Clang, ideally. Usually 
> > they can simply be testing LLVM's IR output before it goes to LLVM for 
> > optimization/codegen - but for features that don't have this serialization 
> > boundary that makes testing and isolation clear/simple, it becomes a bit 
> > fuzzier.
> > 
> > In this case, there is a clang change - from adding the pass explicitly in 
> > Clang, to setting a parameter about how LLVM will add the pass, and it has 
> > an observable effect. One way to test this change while isolating the Clang 
> > test from further changes to the pipeline in LLVM, would be to test that 
> > the pass ends up somewhere in the LLVM-created part of the pass pipeline - 
> > the parts that you can't get to from the way the original pass addition was 
> > written in Clang. At least I assume that's the case/what motivated the 
> > change from adding it in Clang to adding it in LLVM?
> > 
> > eg: if LLVM always forms passes {x, y, z} and Clang is able to add passes 
> > before/after, say it always adds 'a' before and 'b' after, to make {a, x, 
> > y, z, b} - and this new pass u was previously added at the start to make 
> > {u, a, x, y, z, b} but now needs to go in {a, x, y, u, z, b} you could test 
> > that 'u' is after 'a' and before 'b', or between 'x' and 'z', etc. If 
> > there's some other more clear/simple/reliable marker of where the 
> > LLVM-created passes start/end in the structured dump, that'd be good to use 
> > as a landmark to make such a test more robust. If there's some meaningful 
> > pass that this pass always needs to go after - testing that might be OK, 
> > even if it's somewhat an implementation detail of LLVM - whatever's likely 
> > to make the test more legible and more reliable/resilient to unrelated 
> > changes would be good.
> > 
> > > As you pointed out, the test here is to test if the specific pass is run 
> > > and gives expected results.
> > 
> > If that's the case, this test could be committed standalone, before any of 
> > these other changes?
> > 
> > > The pipeline ordering could be tested with a LLVM test but that would 
> > > require a LLVM switch setup for UniqueLinkageNames and I'm not sure 
> > > there's a need for that switch except for testing.
> > 
> > That's OK, the entire 'opt' tool and all its switches only exist for 
> > testing. eg: 
> > https://github.com/llvm/llvm-project/blob/master/llvm/tools/opt/NewPMDriver.cpp#L284
> The point of this change is that UniqueInternalLinkageNamesPass should run 
> before SampleProfileProbePass. That must make a difference in the output of 
> something like `clang -emit-llvm -O1`, right? Maybe we can add a new clang 
> test that checks for that new change in IR, no need to check 
> -fdebug-pass-manager. (I'm not familiar with the passes, correct me if I'm 
> wrong)
Maybe we 

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names.cpp:48-49
 
+// LPIPELINE: Unique Internal Linkage Names
+// NPIPELINE: Running pass: UniqueInternalLinkageNamesPass
 // PLAIN: @_ZL4glob = internal global

aeubanks wrote:
> hoy wrote:
> > aeubanks wrote:
> > > dblaikie wrote:
> > > > hoy wrote:
> > > > > dblaikie wrote:
> > > > > > Does this test validate the new behavior? (ie: does this test fail 
> > > > > > without the LLVM changes and pass with it) Not that it necessarily 
> > > > > > has to - since Clang isn't here to test the LLVM behavior - perhaps 
> > > > > > this test is sufficient in Clang to test that the code in 
> > > > > > BackendUtil works to enable this pass.
> > > > > > 
> > > > > > This could possibly be staged as independent commits - adding the 
> > > > > > LLVM functionality in one commit, which would be a no-op for Clang 
> > > > > > because it wouldn't be setting PTO.UniqueLinkageNames - then 
> > > > > > committing the Clang change that would remove the custom pass 
> > > > > > addition and set PTO.UniqueLinkageNames - and then it'd probably be 
> > > > > > reasonable to have this test be made a bit more explicit (testing 
> > > > > > the pass manager structure/order) to show that that Clang change 
> > > > > > had an effect: Moving the pass to the desired location in the pass 
> > > > > > pipeline.
> > > > > This is a good question. No, this test does not validate the pipeline 
> > > > > change on the LLVM side, since Clang shouldn't have knowledge about 
> > > > > how the pipelines are arranged in LLVM. As you pointed out, the test 
> > > > > here is to test if the specific pass is run and gives expected 
> > > > > results.
> > > > > 
> > > > > Thanks for the suggestion to break the Clang changes and LLVM changes 
> > > > > apart which would make the testing more specific. The pipeline 
> > > > > ordering could be tested with a LLVM test but that would require a 
> > > > > LLVM switch setup for UniqueLinkageNames and I'm not sure there's a 
> > > > > need for that switch except for testing.
> > > > > No, this test does not validate the pipeline change on the LLVM side, 
> > > > > since Clang shouldn't have knowledge about how the pipelines are 
> > > > > arranged in LLVM. 
> > > > 
> > > > "ish" - but Clang should have tests for changes to Clang, ideally. 
> > > > Usually they can simply be testing LLVM's IR output before it goes to 
> > > > LLVM for optimization/codegen - but for features that don't have this 
> > > > serialization boundary that makes testing and isolation clear/simple, 
> > > > it becomes a bit fuzzier.
> > > > 
> > > > In this case, there is a clang change - from adding the pass explicitly 
> > > > in Clang, to setting a parameter about how LLVM will add the pass, and 
> > > > it has an observable effect. One way to test this change while 
> > > > isolating the Clang test from further changes to the pipeline in LLVM, 
> > > > would be to test that the pass ends up somewhere in the LLVM-created 
> > > > part of the pass pipeline - the parts that you can't get to from the 
> > > > way the original pass addition was written in Clang. At least I assume 
> > > > that's the case/what motivated the change from adding it in Clang to 
> > > > adding it in LLVM?
> > > > 
> > > > eg: if LLVM always forms passes {x, y, z} and Clang is able to add 
> > > > passes before/after, say it always adds 'a' before and 'b' after, to 
> > > > make {a, x, y, z, b} - and this new pass u was previously added at the 
> > > > start to make {u, a, x, y, z, b} but now needs to go in {a, x, y, u, z, 
> > > > b} you could test that 'u' is after 'a' and before 'b', or between 'x' 
> > > > and 'z', etc. If there's some other more clear/simple/reliable marker 
> > > > of where the LLVM-created passes start/end in the structured dump, 
> > > > that'd be good to use as a landmark to make such a test more robust. If 
> > > > there's some meaningful pass that this pass always needs to go after - 
> > > > testing that might be OK, even if it's somewhat an implementation 
> > > > detail of LLVM - whatever's likely to make the test more legible and 
> > > > more reliable/resilient to unrelated changes would be good.
> > > > 
> > > > > As you pointed out, the test here is to test if the specific pass is 
> > > > > run and gives expected results.
> > > > 
> > > > If that's the case, this test could be committed standalone, before any 
> > > > of these other changes?
> > > > 
> > > > > The pipeline ordering could be tested with a LLVM test but that would 
> > > > > require a LLVM switch setup for UniqueLinkageNames and I'm not sure 
> > > > > there's a need for that switch except for testing.
> > > > 
> > > > That's OK, the entire 'opt' tool and all its switches only exist for 
> > > > testing. eg: 
> > > > https://github.com/llvm/llvm-project/blob/master/llvm/tools/opt/NewPMDriver.cpp#L284
> > > The point of this change is that Un

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names.cpp:48-49
 
+// LPIPELINE: Unique Internal Linkage Names
+// NPIPELINE: Running pass: UniqueInternalLinkageNamesPass
 // PLAIN: @_ZL4glob = internal global

dblaikie wrote:
> aeubanks wrote:
> > dblaikie wrote:
> > > hoy wrote:
> > > > aeubanks wrote:
> > > > > hoy wrote:
> > > > > > aeubanks wrote:
> > > > > > > dblaikie wrote:
> > > > > > > > hoy wrote:
> > > > > > > > > dblaikie wrote:
> > > > > > > > > > Does this test validate the new behavior? (ie: does this 
> > > > > > > > > > test fail without the LLVM changes and pass with it) Not 
> > > > > > > > > > that it necessarily has to - since Clang isn't here to test 
> > > > > > > > > > the LLVM behavior - perhaps this test is sufficient in 
> > > > > > > > > > Clang to test that the code in BackendUtil works to enable 
> > > > > > > > > > this pass.
> > > > > > > > > > 
> > > > > > > > > > This could possibly be staged as independent commits - 
> > > > > > > > > > adding the LLVM functionality in one commit, which would be 
> > > > > > > > > > a no-op for Clang because it wouldn't be setting 
> > > > > > > > > > PTO.UniqueLinkageNames - then committing the Clang change 
> > > > > > > > > > that would remove the custom pass addition and set 
> > > > > > > > > > PTO.UniqueLinkageNames - and then it'd probably be 
> > > > > > > > > > reasonable to have this test be made a bit more explicit 
> > > > > > > > > > (testing the pass manager structure/order) to show that 
> > > > > > > > > > that Clang change had an effect: Moving the pass to the 
> > > > > > > > > > desired location in the pass pipeline.
> > > > > > > > > This is a good question. No, this test does not validate the 
> > > > > > > > > pipeline change on the LLVM side, since Clang shouldn't have 
> > > > > > > > > knowledge about how the pipelines are arranged in LLVM. As 
> > > > > > > > > you pointed out, the test here is to test if the specific 
> > > > > > > > > pass is run and gives expected results.
> > > > > > > > > 
> > > > > > > > > Thanks for the suggestion to break the Clang changes and LLVM 
> > > > > > > > > changes apart which would make the testing more specific. The 
> > > > > > > > > pipeline ordering could be tested with a LLVM test but that 
> > > > > > > > > would require a LLVM switch setup for UniqueLinkageNames and 
> > > > > > > > > I'm not sure there's a need for that switch except for 
> > > > > > > > > testing.
> > > > > > > > > No, this test does not validate the pipeline change on the 
> > > > > > > > > LLVM side, since Clang shouldn't have knowledge about how the 
> > > > > > > > > pipelines are arranged in LLVM. 
> > > > > > > > 
> > > > > > > > "ish" - but Clang should have tests for changes to Clang, 
> > > > > > > > ideally. Usually they can simply be testing LLVM's IR output 
> > > > > > > > before it goes to LLVM for optimization/codegen - but for 
> > > > > > > > features that don't have this serialization boundary that makes 
> > > > > > > > testing and isolation clear/simple, it becomes a bit fuzzier.
> > > > > > > > 
> > > > > > > > In this case, there is a clang change - from adding the pass 
> > > > > > > > explicitly in Clang, to setting a parameter about how LLVM will 
> > > > > > > > add the pass, and it has an observable effect. One way to test 
> > > > > > > > this change while isolating the Clang test from further changes 
> > > > > > > > to the pipeline in LLVM, would be to test that the pass ends up 
> > > > > > > > somewhere in the LLVM-created part of the pass pipeline - the 
> > > > > > > > parts that you can't get to from the way the original pass 
> > > > > > > > addition was written in Clang. At least I assume that's the 
> > > > > > > > case/what motivated the change from adding it in Clang to 
> > > > > > > > adding it in LLVM?
> > > > > > > > 
> > > > > > > > eg: if LLVM always forms passes {x, y, z} and Clang is able to 
> > > > > > > > add passes before/after, say it always adds 'a' before and 'b' 
> > > > > > > > after, to make {a, x, y, z, b} - and this new pass u was 
> > > > > > > > previously added at the start to make {u, a, x, y, z, b} but 
> > > > > > > > now needs to go in {a, x, y, u, z, b} you could test that 'u' 
> > > > > > > > is after 'a' and before 'b', or between 'x' and 'z', etc. If 
> > > > > > > > there's some other more clear/simple/reliable marker of where 
> > > > > > > > the LLVM-created passes start/end in the structured dump, 
> > > > > > > > that'd be good to use as a landmark to make such a test more 
> > > > > > > > robust. If there's some meaningful pass that this pass always 
> > > > > > > > needs to go after - testing that might be OK, even if it's 
> > > > > > > > somewhat an implementation detail of LLVM - whatever's likely 
> > > > > > > > to make the test more legible and more reliable/resilient to 
> > > > > > > > unrelated changes would be good.
> > > > > > > > 
> > > > > > > 

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313630.
hoy added a comment.

Adding PTO checks in LLVM test.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -133,6 +133,13 @@
 static cl::opt DebugInfoForProfiling(
 "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
 cl::desc("Emit special debug info to enable PGO profile generation."));
+static cl::opt PseudoProbeForProfiling(
+"new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
+cl::desc("Emit pseudo probes to enable PGO profile generation."));
+static cl::opt UniqueInternalLinkageNames(
+"new-pm-unique-internal-linkage-names", cl::init(false), cl::Hidden,
+cl::desc("Uniqueify Internal Linkage Symbol Names by appending the MD5 "
+ "hash of the module path."));
 /// @}}
 
 template 
@@ -246,6 +253,9 @@
 if (DebugInfoForProfiling)
   P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
  true);
+else if (PseudoProbeForProfiling)
+  P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+ false, true);
 else
   P = None;
   }
@@ -281,6 +291,7 @@
   // option has been enabled.
   PTO.LoopUnrolling = !DisableLoopUnrolling;
   PTO.Coroutines = Coroutines;
+  PTO.UniqueLinkageNames = UniqueInternalLinkageNames;
   PassBuilder PB(DebugPM, TM, PTO, P, &PIC);
   registerEPCallbacks(PB);
 
Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,50 @@
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+
+define internal i32 @foo() !dbg !15 {
+entry:
+  ret i32 0, !dbg !18
+}
+
+define dso_local i32 (...)* @bar() !dbg !7 {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*), !dbg !14
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4, !5}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 4}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{i32 1, !"wchar_size", i32 4}
+!7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 9, type: !8, scopeLine: 9, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!8 = !DISubroutineType(types: !9)
+!9 = !{!10}
+!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13, null}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !DILocation(line: 10, column: 3, scope: !7)
+!15 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 5, type: !16, scopeLine: 5, spFlags: DISPFlagLocalToUnit | DISPFlagDefinition, unit: !0, retainedNodes: !2)
+!16 = !DISubroutineType(types: !17)
+!17 = !{!13}
+!18 = !DILocation(line: 6, column: 3, scope: !15)
+
+; O0: Running pass: VerifierPass
+; O0: Running analysis: VerifierAnalysis
+; O0: Running pass: UniqueInternalLinkageNamesPass
+; O0: Invalidating analysis: VerifierAnalysis
+
+; O2: Running pass: ForceFunctionAttrsPass
+; O2: Running pass: UniqueInternalLinkageNamesPass
+; O2: Invalidating analysis: VerifierAnalysis
+; O2: Running pass: SampleProfileProbePass
+
+; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cp

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy marked an inline comment as done.
hoy added inline comments.



Comment at: 
llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll:20
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, enums: !2)
+!1 = !DIFile(filename: "test.c", directory: "")

aeubanks wrote:
> is the debug info necessary for the test? it passes without it.
It's not needed. Will remove.



Comment at: 
llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll:39
+
+; O0: Running pass: VerifierPass
+; O0: Running analysis: VerifierAnalysis

aeubanks wrote:
> I don't think we need to check for Verifiers
It shows up as the first pass of the O0 pipeline and I use it as a reference. 
Will remove.



Comment at: 
llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll:44
+
+; O2: Running pass: ForceFunctionAttrsPass
+; O2: Running pass: UniqueInternalLinkageNamesPass

aeubanks wrote:
> why check ForceFunctionAttrsPass?
Like VerifierPass above, I was using it as a reference.



Comment at: 
llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll:47
+; O2: Invalidating analysis: VerifierAnalysis
+; O2: Running pass: SampleProfileProbePass
+

aeubanks wrote:
> should this be run for O0?
There is no need for that as this point and running it under O0 is not tested.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-23 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 313650.
hoy marked an inline comment as done.
hoy added a comment.

Removing unnecessary test code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -133,6 +133,13 @@
 static cl::opt DebugInfoForProfiling(
 "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
 cl::desc("Emit special debug info to enable PGO profile generation."));
+static cl::opt PseudoProbeForProfiling(
+"new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
+cl::desc("Emit pseudo probes to enable PGO profile generation."));
+static cl::opt UniqueInternalLinkageNames(
+"new-pm-unique-internal-linkage-names", cl::init(false), cl::Hidden,
+cl::desc("Uniqueify Internal Linkage Symbol Names by appending the MD5 "
+ "hash of the module path."));
 /// @}}
 
 template 
@@ -246,6 +253,9 @@
 if (DebugInfoForProfiling)
   P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
  true);
+else if (PseudoProbeForProfiling)
+  P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+ false, true);
 else
   P = None;
   }
@@ -281,6 +291,7 @@
   // option has been enabled.
   PTO.LoopUnrolling = !DisableLoopUnrolling;
   PTO.Coroutines = Coroutines;
+  PTO.UniqueLinkageNames = UniqueInternalLinkageNames;
   PassBuilder PB(DebugPM, TM, PTO, P, &PIC);
   registerEPCallbacks(PB);
 
Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,25 @@
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+
+define internal i32 @foo() {
+entry:
+  ret i32 0
+}
+
+define dso_local i32 (...)* @bar() {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
+}
+
+; O0: Running pass: UniqueInternalLinkageNamesPass
+; O0: Invalidating analysis: VerifierAnalysis
+
+; O2: Running pass: UniqueInternalLinkageNamesPass
+; O2: Invalidating analysis: VerifierAnalysis
+; O2: Running pass: SampleProfileProbePass
+
+; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -284,6 +284,7 @@
   LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
   CallGraphProfile = true;
   MergeFunctions = false;
+  UniqueLinkageNames = false;
 }
 
 extern cl::opt EnableConstraintElimination;
@@ -1001,6 +1002,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1770,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/P

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-29 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: clang/test/CodeGen/unique-internal-linkage-names.cpp:48-49
 
+// LPIPELINE: Unique Internal Linkage Names
+// NPIPELINE: Running pass: UniqueInternalLinkageNamesPass
 // PLAIN: @_ZL4glob = internal global

dblaikie wrote:
> hoy wrote:
> > dblaikie wrote:
> > > aeubanks wrote:
> > > > dblaikie wrote:
> > > > > hoy wrote:
> > > > > > aeubanks wrote:
> > > > > > > hoy wrote:
> > > > > > > > aeubanks wrote:
> > > > > > > > > dblaikie wrote:
> > > > > > > > > > hoy wrote:
> > > > > > > > > > > dblaikie wrote:
> > > > > > > > > > > > Does this test validate the new behavior? (ie: does 
> > > > > > > > > > > > this test fail without the LLVM changes and pass with 
> > > > > > > > > > > > it) Not that it necessarily has to - since Clang isn't 
> > > > > > > > > > > > here to test the LLVM behavior - perhaps this test is 
> > > > > > > > > > > > sufficient in Clang to test that the code in 
> > > > > > > > > > > > BackendUtil works to enable this pass.
> > > > > > > > > > > > 
> > > > > > > > > > > > This could possibly be staged as independent commits - 
> > > > > > > > > > > > adding the LLVM functionality in one commit, which 
> > > > > > > > > > > > would be a no-op for Clang because it wouldn't be 
> > > > > > > > > > > > setting PTO.UniqueLinkageNames - then committing the 
> > > > > > > > > > > > Clang change that would remove the custom pass addition 
> > > > > > > > > > > > and set PTO.UniqueLinkageNames - and then it'd probably 
> > > > > > > > > > > > be reasonable to have this test be made a bit more 
> > > > > > > > > > > > explicit (testing the pass manager structure/order) to 
> > > > > > > > > > > > show that that Clang change had an effect: Moving the 
> > > > > > > > > > > > pass to the desired location in the pass pipeline.
> > > > > > > > > > > This is a good question. No, this test does not validate 
> > > > > > > > > > > the pipeline change on the LLVM side, since Clang 
> > > > > > > > > > > shouldn't have knowledge about how the pipelines are 
> > > > > > > > > > > arranged in LLVM. As you pointed out, the test here is to 
> > > > > > > > > > > test if the specific pass is run and gives expected 
> > > > > > > > > > > results.
> > > > > > > > > > > 
> > > > > > > > > > > Thanks for the suggestion to break the Clang changes and 
> > > > > > > > > > > LLVM changes apart which would make the testing more 
> > > > > > > > > > > specific. The pipeline ordering could be tested with a 
> > > > > > > > > > > LLVM test but that would require a LLVM switch setup for 
> > > > > > > > > > > UniqueLinkageNames and I'm not sure there's a need for 
> > > > > > > > > > > that switch except for testing.
> > > > > > > > > > > No, this test does not validate the pipeline change on 
> > > > > > > > > > > the LLVM side, since Clang shouldn't have knowledge about 
> > > > > > > > > > > how the pipelines are arranged in LLVM. 
> > > > > > > > > > 
> > > > > > > > > > "ish" - but Clang should have tests for changes to Clang, 
> > > > > > > > > > ideally. Usually they can simply be testing LLVM's IR 
> > > > > > > > > > output before it goes to LLVM for optimization/codegen - 
> > > > > > > > > > but for features that don't have this serialization 
> > > > > > > > > > boundary that makes testing and isolation clear/simple, it 
> > > > > > > > > > becomes a bit fuzzier.
> > > > > > > > > > 
> > > > > > > > > > In this case, there is a clang change - from adding the 
> > > > > > > > > > pass explicitly in Clang, to setting a parameter about how 
> > > > > > > > > > LLVM will add the pass, and it has an observable effect. 
> > > > > > > > > > One way to test this change while isolating the Clang test 
> > > > > > > > > > from further changes to the pipeline in LLVM, would be to 
> > > > > > > > > > test that the pass ends up somewhere in the LLVM-created 
> > > > > > > > > > part of the pass pipeline - the parts that you can't get to 
> > > > > > > > > > from the way the original pass addition was written in 
> > > > > > > > > > Clang. At least I assume that's the case/what motivated the 
> > > > > > > > > > change from adding it in Clang to adding it in LLVM?
> > > > > > > > > > 
> > > > > > > > > > eg: if LLVM always forms passes {x, y, z} and Clang is able 
> > > > > > > > > > to add passes before/after, say it always adds 'a' before 
> > > > > > > > > > and 'b' after, to make {a, x, y, z, b} - and this new pass 
> > > > > > > > > > u was previously added at the start to make {u, a, x, y, z, 
> > > > > > > > > > b} but now needs to go in {a, x, y, u, z, b} you could test 
> > > > > > > > > > that 'u' is after 'a' and before 'b', or between 'x' and 
> > > > > > > > > > 'z', etc. If there's some other more clear/simple/reliable 
> > > > > > > > > > marker of where the LLVM-created passes start/end in the 
> > > > > > > > > > structured dump, that'd be good to use as a landmark to 
> > > > > > > > > > make such a test more robust. If there's some

[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-29 Thread Hongtao Yu via Phabricator via cfe-commits
hoy added inline comments.



Comment at: llvm/tools/opt/NewPMDriver.cpp:136-138
+static cl::opt PseudoProbeForProfiling(
+"new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
+cl::desc("Emit pseudo probes to enable PGO profile generation."));

dblaikie wrote:
> I guess this should probably have some separate testing, if it's a separate 
> flag/feature? (& flag+tests could be in a separate commit)
I'm not sure there's a separate need for this switch except for being tested in 
`unique-internal-linkage-names.ll`. The point of this whole patch is to place 
the unique name pass before the pseudo probe pass and test it works. Hence it 
sounds appropriate to me to include all changes in one patch. What do you think?



Comment at: llvm/tools/opt/NewPMDriver.cpp:253-258
 if (DebugInfoForProfiling)
   P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
  true);
+else if (PseudoProbeForProfiling)
+  P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+ false, true);

dblaikie wrote:
> Both of these might be more readably written as something like:
> ```
> P.emplace();
> P.PseudoProbeForProfiling = true;
> ```
> & similar. (you can commit the change to DebugInfoForProfiling separately 
> before/after this change to make it consistent with the new one)
> 
> But no big deal either way - while it makes these tidier it makes them a bit 
> less consistent with the other three
That looks cleaner, but there are assertions in the constructor of `PGOOptions` 
which I would not like to bypass by setting the `PseudoProbeForProfiling` field 
separately.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

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


[PATCH] D93656: Moving UniqueInternalLinkageNamesPass to the start of IR pipelines.

2020-12-29 Thread Hongtao Yu via Phabricator via cfe-commits
hoy updated this revision to Diff 314043.
hoy added a comment.

Removing the checks of VerifierAnalysis in test code.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D93656/new/

https://reviews.llvm.org/D93656

Files:
  llvm/include/llvm/Passes/PassBuilder.h
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
  llvm/tools/opt/NewPMDriver.cpp

Index: llvm/tools/opt/NewPMDriver.cpp
===
--- llvm/tools/opt/NewPMDriver.cpp
+++ llvm/tools/opt/NewPMDriver.cpp
@@ -133,6 +133,13 @@
 static cl::opt DebugInfoForProfiling(
 "new-pm-debug-info-for-profiling", cl::init(false), cl::Hidden,
 cl::desc("Emit special debug info to enable PGO profile generation."));
+static cl::opt PseudoProbeForProfiling(
+"new-pm-pseudo-probe-for-profiling", cl::init(false), cl::Hidden,
+cl::desc("Emit pseudo probes to enable PGO profile generation."));
+static cl::opt UniqueInternalLinkageNames(
+"new-pm-unique-internal-linkage-names", cl::init(false), cl::Hidden,
+cl::desc("Uniqueify Internal Linkage Symbol Names by appending the MD5 "
+ "hash of the module path."));
 /// @}}
 
 template 
@@ -246,6 +253,9 @@
 if (DebugInfoForProfiling)
   P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
  true);
+else if (PseudoProbeForProfiling)
+  P = PGOOptions("", "", "", PGOOptions::NoAction, PGOOptions::NoCSAction,
+ false, true);
 else
   P = None;
   }
@@ -281,6 +291,7 @@
   // option has been enabled.
   PTO.LoopUnrolling = !DisableLoopUnrolling;
   PTO.Coroutines = Coroutines;
+  PTO.UniqueLinkageNames = UniqueInternalLinkageNames;
   PassBuilder PB(DebugPM, TM, PTO, P, &PIC);
   registerEPCallbacks(PB);
 
Index: llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
===
--- /dev/null
+++ llvm/test/Transforms/UniqueLinkageNames/unique-internal-linkage-names.ll
@@ -0,0 +1,23 @@
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O0 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='default' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+; RUN: opt -S -passes='thinlto-pre-link' -new-pm-pseudo-probe-for-profiling -new-pm-unique-internal-linkage-names -debug-pass-manager < %s 2>&1 | FileCheck %s --check-prefix=O2 --check-prefix=UNIQUE
+
+define internal i32 @foo() {
+entry:
+  ret i32 0
+}
+
+define dso_local i32 (...)* @bar() {
+entry:
+  ret i32 (...)* bitcast (i32 ()* @foo to i32 (...)*)
+}
+
+; O0: Running pass: UniqueInternalLinkageNamesPass
+
+; O2: Running pass: UniqueInternalLinkageNamesPass
+; O2: Running pass: SampleProfileProbePass
+
+; UNIQUE: define internal i32 @foo.__uniq.{{[0-9a-f]+}}()
+; UNIQUE: ret {{.*}} @foo.__uniq.{{[0-9a-f]+}} {{.*}}
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -284,6 +284,7 @@
   LicmMssaNoAccForPromotionCap = SetLicmMssaNoAccForPromotionCap;
   CallGraphProfile = true;
   MergeFunctions = false;
+  UniqueLinkageNames = false;
 }
 
 extern cl::opt EnableConstraintElimination;
@@ -1001,6 +1002,11 @@
ThinLTOPhase Phase) {
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   // Place pseudo probe instrumentation as the first pass of the pipeline to
   // minimize the impact of optimization changes.
   if (PGOOpt && PGOOpt->PseudoProbeForProfiling &&
@@ -1764,6 +1770,11 @@
 
   ModulePassManager MPM(DebugLogging);
 
+  // Add UniqueInternalLinkageNames Pass which renames internal linkage
+  // symbols with unique names.
+  if (PTO.UniqueLinkageNames)
+MPM.addPass(UniqueInternalLinkageNamesPass());
+
   if (PGOOpt && (PGOOpt->Action == PGOOptions::IRInstr ||
  PGOOpt->Action == PGOOptions::IRUse))
 addPGOInstrPassesForO0(
Index: llvm/include/llvm/Passes/PassBuilder.h
===
--- llvm/include/llvm/Passes/

  1   2   3   >