This is an archive of the discontinued LLVM Phabricator instance.

WholeProgramDevirt: Implement importing for uniform ret val opt.
ClosedPublic

Authored by pcc on Feb 10 2017, 2:51 PM.

Diff Detail

Repository
rL LLVM

Event Timeline

pcc created this revision.Feb 10 2017, 2:51 PM
tejohnson added inline comments.Mar 8 2017, 10:28 AM
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1078 ↗(On Diff #88059)

The function name should be available for each CallSite in each VirtualCallSite on the CSInfo.CallSites. But would the call sites be from more than one function?

pcc added inline comments.Mar 8 2017, 3:30 PM
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1078 ↗(On Diff #88059)

These are not the names of the functions containing the call sites but rather the names of the virtual functions being called.

I think we'll probably want to somehow move these remarks into the exporting phase as well.

tejohnson added inline comments.Mar 8 2017, 4:22 PM
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1078 ↗(On Diff #88059)

Actually, looking at the code I don't understand why we wouldn't be emitting a remark during the exporting phase. DevirtModule::tryUniformRetValOpt will set WasDevirt to true for each Target. That in turn is invoked from tryVirtualConstProp in run() in the part executed on the Export & regular LTO paths, which should cause the function to be added to DevirtTargets for which remarks are emitted.

What's the difference between the remarks emitted for this case in run(), and the ones issued from within applyUniformRetValOpt?

pcc added a subscriber: krasin.Mar 8 2017, 4:48 PM
pcc added inline comments.
llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1078 ↗(On Diff #88059)

I believe that there are two separate kinds of remarks.

  1. http://llvm-cs.pcc.me.uk/lib/Transforms/IPO/WholeProgramDevirt.cpp#280
  2. http://llvm-cs.pcc.me.uk/lib/Transforms/IPO/WholeProgramDevirt.cpp#1221

The first is per call site and mentions the name of one possible target of the virtual call (arbitrarily chosen), and the other is per virtual function and mentions whether any calls to that function have been devirtualized. With this code we will emit the second type of remark during the exporting phase, and the first (with the arbitrary target name missing) during the importing phase.

(@krasin was the original author of the remark code.)

tejohnson accepted this revision.Mar 8 2017, 5:12 PM

LGTM, with comment added on test as suggested below.

llvm/lib/Transforms/IPO/WholeProgramDevirt.cpp
1078 ↗(On Diff #88059)

Yes looks like it. We probably couldn't move the per call site remarks to the exporting side then, but would need more info here to get the name of a targets emitted. Looks like we also emit both remark kinds for applySingleImplDevirt, but there we already have the function name on the importing side.

llvm/test/Transforms/WholeProgramDevirt/import.ll
37 ↗(On Diff #88059)

Comment on why we can't do the optimization here (I see UniformRetVal listed for typeid2 in the yaml file, but I'm probably misunderstanding how that is applied).

This revision is now accepted and ready to land.Mar 8 2017, 5:12 PM
This revision was automatically updated to reflect the committed changes.
pcc marked an inline comment as done.