Page MenuHomePhabricator

[CSSPGO] Pseudo probe instrumentation pass
Needs ReviewPublic

Authored by hoy on Aug 24 2020, 5:38 PM.

Details

Reviewers
davidxl
wmi
wenlei
Summary

This change introduces a pseudo probe instrumentation pass for block instrumentation. Please refer to https://reviews.llvm.org/D86193 for the whole story.

Given the following LLVM IR:

define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
  %cmp = icmp eq i32 %x, 0
   br i1 %cmp, label %bb1, label %bb2
bb1:
   br label %bb3
bb2:
   br label %bb3
bb3:
   ret void
}

The instrumented IR will look like below. Note that each llvm.pseudoprobe intrinsic call represents a pseudo probe at a block, of which the first parameter is the GUID of the probe’s owner function and the second parameter is the probe’s ID.

define internal void @foo2(i32 %x, void (i32)* %f) !dbg !4 {
bb0:
   %cmp = icmp eq i32 %x, 0
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 1)
   br i1 %cmp, label %bb1, label %bb2
bb1:                                             
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 2)
   br label %bb3
bb2:                                              
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 3)
   br label %bb3
bb3:                                              
   call void @llvm.pseudoprobe(i64 837061429793323041, i64 4)
   ret void
}

Diff Detail

Event Timeline

hoy created this revision.Aug 24 2020, 5:38 PM
hoy requested review of this revision.Aug 24 2020, 5:38 PM
hoy retitled this revision from [CSSPGO] Pseudo probe instrumenation pass to [CSSPGO] Pseudo probe instrumentation pass.Aug 24 2020, 5:52 PM
hoy edited the summary of this revision. (Show Details)
hoy updated this revision to Diff 287539.Aug 24 2020, 5:54 PM

Updating D86499: [CSSPGO] Pseudo probe instrumentation pass

wmi added inline comments.Sep 9 2020, 9:02 PM
llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
37

Will the class be used in files other than SampleProfileProbe.cpp? If not, it is better to be placed in SampleProfileProbe.cpp.

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
74–77

Can we add a stat support here to see how frequent the probe cannot find an instruction with valid dbgline? Even if no instruction with valid dbgline can be found, is it possible to create a dbgline for it and set the line number to 0 or to the function start (I assume line number is of no use. Only the inline context matters here)?

hoy marked an inline comment as done.Sep 10 2020, 3:41 PM
hoy added inline comments.
llvm/include/llvm/Transforms/IPO/SampleProfileProbe.h
37

Yes, it will be used outside SampleProfileProbe.cpp. It'll later on introduce a field storing the name of IL metadata that'll be used by later probe emission pass.

llvm/lib/Transforms/IPO/SampleProfileProbe.cpp
74–77

This is a very good suggestion, thanks!

The prober pass had not been placed in the very beginning of the pipeline initially and we saw quite some instructions without a real debug line number. It is now placed in the beginning but with some statistics I was still seeing that happened to a few instructions. Giving an artificial line number to such probes will help.

hoy updated this revision to Diff 291096.Sep 10 2020, 3:42 PM
hoy marked an inline comment as done.

Updating D86499: [CSSPGO] Pseudo probe instrumentation pass

modimo added a subscriber: modimo.Sep 11 2020, 3:39 PM