Page MenuHomePhabricator

Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline

[NFCI] Move cost estimation from TargetLowering to TargetTransformInfo.

Authored by dfukalov on Jan 19 2022, 2:02 PM.



TragetLowering had two last InstructionCost related getTypeLegalizationCost()
and getScalingFactorCost() members, but all other costs are processed in TTI.

E.g. it is not comfortable to use other TTI members in these two functions
overrided in a target.

Minor refactoring: getTypeLegalizationCost() now doesn't need DataLayout
parameter - it was always passed from TTI.

Diff Detail

Event Timeline

dfukalov created this revision.Jan 19 2022, 2:02 PM
dfukalov added inline comments.Jan 19 2022, 2:10 PM

I'm not sure I should make it virtual (as it was in TLI) and mark it override in targets...


Perhaps TTI::getScalingFactorCost should be unified to TargetLoweringBase::AddrMode AM parameter.

dfukalov published this revision for review.Jan 19 2022, 2:10 PM
Herald added a project: Restricted Project. · View Herald TranscriptJan 19 2022, 2:10 PM

Does anyone else have any comments?


The TTI classes use a CRTP layout - you shouldn't need virtual classes


Not sure about whether that's useful - LoopStrengthReduction seems to be the main user of this, and it has its own data structures. We're going to end up creating the AddrMode structure somewhere, it might as well be here.

@dfukalov reverse ping - what happened with this patch?

Herald added a project: Restricted Project. · View Herald TranscriptAug 2 2022, 5:33 AM
dfukalov updated this revision to Diff 452097.Aug 12 2022, 12:38 AM

I thought we should wait for additional opinions on the patch...

Consolidating all cost-query related functions in TTI makes sense to me.


this could be done independently?

dfukalov added inline comments.Aug 12 2022, 1:13 AM

Actually I added const since the removed TargetLoweringBase::getScalingFactorCost() was const.

dfukalov updated this revision to Diff 452623.Aug 15 2022, 3:56 AM

Addressed comment.

RKSimon added inline comments.Aug 15 2022, 4:17 AM

doxygen comment / description?

dfukalov added inline comments.Aug 15 2022, 7:23 AM

I Just moved the declaration from private to public section to allow access it from BasicTTIImplBase<T>::getTypeLegalizationCost().
There was no description in previous place. The function returns pair of values, which are actually mainly used by getTypeAction() (uses first element of pair) and getTypeToTransformTo() (uses second element). These interfaces have descriptions (related to first and second element of pair respectively.
So, should I copy+combine these descriptions or move them? Or perhaps place references here or there (after move)?

RKSimon added inline comments.Aug 15 2022, 7:37 AM

Yeah, a copy + combine + tweak should be OK - we just need a summary of what is expected. Cheers.

dfukalov updated this revision to Diff 452800.Aug 15 2022, 1:56 PM

Added comment/description for getTypeConversion()

RKSimon accepted this revision.Aug 17 2022, 3:24 AM

LGTM - cheers

This revision is now accepted and ready to land.Aug 17 2022, 3:24 AM
This revision was landed with ongoing or failed builds.Aug 17 2022, 2:39 PM
This revision was automatically updated to reflect the committed changes.
qianzhen added inline comments.

This function used to be a public member in TargetLowering (llvm/lib/Target/AMDGPU/SIISelLowering.h), is there a reason to declare it as a private member when it's moved in TTI? It makes this function inaccessible outside TTI.

dfukalov added inline comments.Aug 22 2022, 3:09 AM

The only user of the function was TTI. Additionally this function was the last in TTL that used InstructionCost entity. So it was moved into TTI and became private. If one needs use the function outside of TTI it can be moved then to public section.

At the moment there are no other users of the function outside of TTI so I didn't see a reason to expose it.