diff --git a/llvm/include/llvm/CodeGen/CostTable.h b/llvm/include/llvm/CodeGen/CostTable.h --- a/llvm/include/llvm/CodeGen/CostTable.h +++ b/llvm/include/llvm/CodeGen/CostTable.h @@ -21,15 +21,18 @@ namespace llvm { /// Cost Table Entry -struct CostTblEntry { +template +struct CostTblEntryT { int ISD; MVT::SimpleValueType Type; - unsigned Cost; + CostKind 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) { +/// Find in cost table. +template +inline const CostTblEntryT * +CostTableLookup(ArrayRef> Tbl, int ISD, MVT Ty) { auto I = find_if(Tbl, [=](const CostTblEntry &Entry) { return ISD == Entry.ISD && Ty == Entry.Type; }); @@ -40,22 +43,33 @@ return nullptr; } +template +inline const CostTblEntry * +CostTableLookup(const llvm::CostTblEntryT (&Table)[N], int ISD, + MVT Ty) { + // Wrapper to fix template argument deduction failures. + return CostTableLookup( + llvm::ArrayRef>(Table), ISD, Ty); +} + /// Type Conversion Cost Table -struct TypeConversionCostTblEntry { +template struct TypeConversionCostTblEntryT { int ISD; MVT::SimpleValueType Dst; MVT::SimpleValueType Src; - unsigned Cost; + CostKind 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 +77,16 @@ return nullptr; } +template +inline const TypeConversionCostTblEntryT *ConvertCostTableLookup( + const llvm::TypeConversionCostTblEntryT (&Table)[N], int ISD, + MVT Dst, MVT Src) { + // Wrapper to fix template argument deduction failures. + return ConvertCostTableLookup( + llvm::ArrayRef>(Table), ISD, Dst, + Src); +} + } // namespace llvm #endif /* LLVM_CODEGEN_COSTTABLE_H_ */