diff --git a/include/llvm/CodeGen/CostTable.h b/include/llvm/CodeGen/CostTable.h index 52f3bfaea18..fc4648c2522 100644 --- a/include/llvm/CodeGen/CostTable.h +++ b/include/llvm/CodeGen/CostTable.h @@ -21,16 +21,19 @@ namespace llvm { /// Cost Table Entry -struct CostTblEntry { +template +struct CostTblEntryT { int ISD; MVT::SimpleValueType Type; - unsigned Cost; + CostType Cost; }; +using CostTblEntry = CostTblEntryT; -/// Find in cost table, TypeTy must be comparable to CompareTy by == -inline const CostTblEntry *CostTableLookup(ArrayRef Tbl, - int ISD, MVT Ty) { - auto I = find_if(Tbl, [=](const CostTblEntry &Entry) { +/// Find in cost table. +template +inline const CostTblEntryT * +CostTableLookup(ArrayRef> Tbl, int ISD, MVT Ty) { + auto I = find_if(Tbl, [=](const CostTblEntryT &Entry) { return ISD == Entry.ISD && Ty == Entry.Type; }); if (I != Tbl.end()) @@ -40,22 +43,32 @@ inline const CostTblEntry *CostTableLookup(ArrayRef Tbl, return nullptr; } +template +inline const CostTblEntryT * +CostTableLookup(const CostTblEntryT (&Table)[N], int ISD, MVT Ty) { + // Wrapper to fix template argument deduction failures. + return CostTableLookup(makeArrayRef(Table), ISD, Ty); +} + /// Type Conversion Cost Table -struct TypeConversionCostTblEntry { +template +struct TypeConversionCostTblEntryT { int ISD; MVT::SimpleValueType Dst; MVT::SimpleValueType Src; - unsigned Cost; + CostType Cost; }; +using TypeConversionCostTblEntry = TypeConversionCostTblEntryT; -/// Find in type conversion cost table, TypeTy must be comparable to CompareTy -/// by == -inline const TypeConversionCostTblEntry * -ConvertCostTableLookup(ArrayRef Tbl, +/// Find in type conversion cost table. +template +inline const TypeConversionCostTblEntryT * +ConvertCostTableLookup(ArrayRef> Tbl, int ISD, MVT Dst, MVT Src) { - auto I = find_if(Tbl, [=](const TypeConversionCostTblEntry &Entry) { - return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst; - }); + auto I = + find_if(Tbl, [=](const TypeConversionCostTblEntryT &Entry) { + return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst; + }); if (I != Tbl.end()) return I; @@ -63,6 +76,14 @@ ConvertCostTableLookup(ArrayRef Tbl, return nullptr; } +template +inline const TypeConversionCostTblEntryT * +ConvertCostTableLookup(const TypeConversionCostTblEntryT (&Table)[N], + int ISD, MVT Dst, MVT Src) { + // Wrapper to fix template argument deduction failures. + return ConvertCostTableLookup(makeArrayRef(Table), ISD, Dst, Src); +} + } // namespace llvm #endif /* LLVM_CODEGEN_COSTTABLE_H_ */