This is an archive of the discontinued LLVM Phabricator instance.

[CostModel] Templatize EntryCost::Cost to allow custom cost metrics
ClosedPublic

Authored by RKSimon on Jul 20 2021, 3:15 AM.

Details

Summary

We currently use an unsigned value for our CostTblEntry and TypeConversionCostTblEntry cost tables which is limiting depending on how the target wishes to handle various CostKinds etc.

For instance, targets might wish to store separate instruction count, latency or throughput values etc. On D46276 we have been investigating storing a code snippet to improve latency/throughput cost calculations.

There is a slight problem in that template argument deduction was struggling to match the now templatized Costs[] tables in a ArrayRef constructor - I've added helper wrappers for CostTableLookup/ConvertCostTableLookup which avoids us having to update all existing calls with a template hint.

Diff Detail

Event Timeline

RKSimon requested review of this revision.Jul 20 2021, 3:15 AM
RKSimon created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptJul 20 2021, 3:15 AM
RKSimon added inline comments.Jul 20 2021, 3:19 AM
llvm/include/llvm/CodeGen/CostTable.h
24

oops - I forgot to update all of these to CostType to avoid confusion with TargetCostKind - will fix shortly

RKSimon updated this revision to Diff 360068.Jul 20 2021, 3:25 AM

Consistently using CostType for template param

Sounds useful. My C++ templates are not super strong (for someone who works on compilers) but could it use:

template <typename CostType = unsigned> struct CostTblEntry

It looks like that might be a C++17 thing, to make it clean though.

llvm/include/llvm/CodeGen/CostTable.h
36

CostTblEntry -> CostTblEntryT<CostType>?

47

CostTblEntry -> CostTblEntryT<CostType>?

ABataev added inline comments.Jul 20 2021, 4:49 AM
llvm/include/llvm/CodeGen/CostTable.h
48–53

Drop llvm::?

52

makeArrayRef(Table) instead of llvm::ArrayRef<llvm::CostTblEntryT<CostType>>(Table)?

80–89

Drop llvm::?

86

makeArrayRef(Table)

Matt added a subscriber: Matt.Jul 20 2021, 6:55 AM
RKSimon updated this revision to Diff 360112.Jul 20 2021, 7:02 AM

Thanks for the reviews - tidied up the code as suggested (it'd taken so long to get the template code to work I'd rather over complicated it all.....)

RKSimon marked 6 inline comments as done.Jul 20 2021, 7:03 AM
ABataev accepted this revision.Jul 20 2021, 7:05 AM

LGTM with a nit, unless there are no others comments

llvm/include/llvm/CodeGen/CostTable.h
82

llvm::?

This revision is now accepted and ready to land.Jul 20 2021, 7:05 AM

Yeah, I'm happy with this.

RKSimon added inline comments.Jul 20 2021, 7:18 AM
llvm/include/llvm/CodeGen/CostTable.h
80–89

Sorry - I missed that one!

This revision was landed with ongoing or failed builds.Jul 20 2021, 7:37 AM
This revision was automatically updated to reflect the committed changes.