This is an archive of the discontinued LLVM Phabricator instance.

[CSSPGO] Refactoring findIRAnchors
ClosedPublic

Authored by wlei on Aug 29 2023, 11:12 PM.

Details

Summary

Address feedback in https://reviews.llvm.org/D158817. Since extractProbe can be used for both calliste and BB probe, we can leverage this to unify the callsite handling code.

Diff Detail

Event Timeline

wlei created this revision.Aug 29 2023, 11:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 11:12 PM
wlei requested review of this revision.Aug 29 2023, 11:12 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 29 2023, 11:12 PM
wlei edited the summary of this revision. (Show Details)Aug 29 2023, 11:17 PM
wlei added reviewers: hoy, wenlei.
hoy accepted this revision.Aug 29 2023, 11:48 PM
hoy added inline comments.
llvm/lib/Transforms/IPO/SampleProfile.cpp
2154–2158

nit: may be good to hoist this code into a lamda and share it with the line-number path.

This revision is now accepted and ready to land.Aug 29 2023, 11:48 PM
wlei updated this revision to Diff 554598.Aug 30 2023, 12:15 AM

addressing feedback

llvm/lib/Transforms/IPO/SampleProfile.cpp
2154–2158

Good point, done!

wenlei added inline comments.Aug 30 2023, 10:12 AM
llvm/lib/Transforms/IPO/SampleProfile.cpp
2170–2172

Actually can this be unified with FindTopLevelFrame? For not inlined calls, DIL->getSubprogramLinkageName should be equivalent to FindCalleeName(dyn_cast<CallBase>(&I))?

wlei added inline comments.Aug 30 2023, 11:05 AM
llvm/lib/Transforms/IPO/SampleProfile.cpp
2170–2172

Good point, but to clarify:
DIL->getSubprogramLinkageName is the current/top-level Frame.
FindCalleeName is the current callee name, it's the second top Frame.

Maybe my variable name is misleading in the new patch. Here is actually not FindTopLevelFrame, For example: "main:1 @ foo", the term "top-level" frame is "main:1", but here what it returns is {1, foo} , i,e {the top-level frame's location, the second top's frame's func name}

uh..I need to fix it.

That said, maybe we still can merge FindTopLevelFrame and FindCalleeName , like check if it's inlined code inside of the lambda, let me think.

wlei added inline comments.Aug 30 2023, 1:27 PM
llvm/lib/Transforms/IPO/SampleProfile.cpp
2170–2172

OK.. I'm done one version, please take a look https://reviews.llvm.org/D159221

I ran into some bugs and spent some times debugging, the tricky parts are :

  1. For pseudo-probe mode, a) for inline code, we need to use getCallSiteIdentifier to extract the callsite but b) for non-inlined code, we need to use the probe id.
  1. The pseudo instruction is a CallBase and the getCalledFunction will return a non-empty callee name "llvm.pseudoprobe" which actually should be a empty StringRef.

I then made it work, but as it introduces more complexity, maybe it's still not what we want, any thoughts on this?

wenlei added inline comments.Aug 31 2023, 12:15 PM
llvm/lib/Transforms/IPO/SampleProfile.cpp
2114

Maybe assert that DIL->getInlinedAt() is not null first. For not inlined DIL, this will not get what we want. Assert helps make it clear.

With the assert, the loop can also changed to do-while to make it explicit. I find do-while slightly more readable for this kind of cases.

do {
  PrevDIL = DIL;
  DIL = DIL->getInlinedAt();
} while (DIL->getInlinedAt())
2124

nit: this does not involve search/find, so maybe just GetCanonicalCalleeName.

2170–2172

I guess, FindTopLevelFrame can be called FindTopLevelInlinedCallsite? It would also help to explain in a comment what it does with an example, like the main:1 @ foo one you mentioned above.

For pseudo-probe mode, a) for inline code, we need to use getCallSiteIdentifier to extract the callsite but b) for non-inlined code, we need to use the probe id.

Thanks for clarification - I think that answered my original question, and the answer is no. Getting callsite (loc, callee_name pair) from debug info is only doable for inlined callsite, so for not inlined code, we need to get callee from the call instructions.

I looked at https://reviews.llvm.org/D159221, i think that with better naming, the version in this patch is actually more readable. wdyt?

wlei updated this revision to Diff 555189.Aug 31 2023, 3:59 PM

addressing feedback

wlei added inline comments.Aug 31 2023, 4:01 PM
llvm/lib/Transforms/IPO/SampleProfile.cpp
2114

Sounds good, done.

2170–2172

thanks for the suggestion, renamed and updated the comments.

wenlei accepted this revision.Aug 31 2023, 4:07 PM

lgtm, thanks.

This revision was landed with ongoing or failed builds.Aug 31 2023, 4:26 PM
This revision was automatically updated to reflect the committed changes.