X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=blobdiff_plain;f=include%2Fllvm%2FTarget%2FCostTable.h;fp=include%2Fllvm%2FTarget%2FCostTable.h;h=489435fb1c04c2f415dc77aa45c186273402330c;hp=34f6041137c12635a870f64b66bb93a1201e1ad2;hb=156f73362ef164405dceb74f7b1b04ad203bb43a;hpb=59991f96f9c522f456d9cb6d2eda4a226806d7ff diff --git a/include/llvm/Target/CostTable.h b/include/llvm/Target/CostTable.h index 34f6041137c..489435fb1c0 100644 --- a/include/llvm/Target/CostTable.h +++ b/include/llvm/Target/CostTable.h @@ -15,6 +15,8 @@ #ifndef LLVM_TARGET_COSTTABLE_H_ #define LLVM_TARGET_COSTTABLE_H_ +#include "llvm/ADT/ArrayRef.h" + namespace llvm { /// Cost Table Entry @@ -27,21 +29,23 @@ struct CostTblEntry { /// Find in cost table, TypeTy must be comparable to CompareTy by == template -int CostTableLookup(const CostTblEntry *Tbl, unsigned len, int ISD, - CompareTy Ty) { - for (unsigned int i = 0; i < len; ++i) - if (ISD == Tbl[i].ISD && Ty == Tbl[i].Type) - return i; +const CostTblEntry *CostTableLookup(ArrayRef> Tbl, + int ISD, CompareTy Ty) { + auto I = std::find_if(Tbl.begin(), Tbl.end(), + [=](const CostTblEntry &Entry) { + return ISD == Entry.ISD && Ty == Entry.Type; }); + if (I != Tbl.end()) + return I; // Could not find an entry. - return -1; + return nullptr; } /// Find in cost table, TypeTy must be comparable to CompareTy by == template -int CostTableLookup(const CostTblEntry(&Tbl)[N], int ISD, - CompareTy Ty) { - return CostTableLookup(Tbl, N, ISD, Ty); +const CostTblEntry *CostTableLookup(const CostTblEntry(&Tbl)[N], + int ISD, CompareTy Ty) { + return CostTableLookup(makeArrayRef(Tbl), ISD, Ty); } /// Type Conversion Cost Table @@ -56,23 +60,28 @@ struct TypeConversionCostTblEntry { /// Find in type conversion cost table, TypeTy must be comparable to CompareTy /// by == template -int ConvertCostTableLookup(const TypeConversionCostTblEntry *Tbl, - unsigned len, int ISD, CompareTy Dst, - CompareTy Src) { - for (unsigned int i = 0; i < len; ++i) - if (ISD == Tbl[i].ISD && Src == Tbl[i].Src && Dst == Tbl[i].Dst) - return i; +const TypeConversionCostTblEntry * +ConvertCostTableLookup(ArrayRef> Tbl, + int ISD, CompareTy Dst, CompareTy Src) { + auto I = std::find_if(Tbl.begin(), Tbl.end(), + [=](const TypeConversionCostTblEntry &Entry) { + return ISD == Entry.ISD && Src == Entry.Src && + Dst == Entry.Dst; + }); + if (I != Tbl.end()) + return I; // Could not find an entry. - return -1; + return nullptr; } /// Find in type conversion cost table, TypeTy must be comparable to CompareTy /// by == template -int ConvertCostTableLookup(const TypeConversionCostTblEntry(&Tbl)[N], - int ISD, CompareTy Dst, CompareTy Src) { - return ConvertCostTableLookup(Tbl, N, ISD, Dst, Src); +const TypeConversionCostTblEntry * +ConvertCostTableLookup(const TypeConversionCostTblEntry(&Tbl)[N], + int ISD, CompareTy Dst, CompareTy Src) { + return ConvertCostTableLookup(makeArrayRef(Tbl), ISD, Dst, Src); } } // namespace llvm