| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
#ifndef LLVM_CODEGEN_COSTTABLE_H_ |
| 15 |
#define LLVM_CODEGEN_COSTTABLE_H_ |
| 16 |
|
| 17 |
#include "llvm/ADT/ArrayRef.h" |
| 18 |
#include "llvm/ADT/STLExtras.h" |
| 19 |
#include "llvm/Support/MachineValueType.h" |
| 20 |
|
| 21 |
namespace llvm { |
| 22 |
|
| 23 |
|
| 24 |
template <typename CostType> |
| 25 |
struct CostTblEntryT { |
| 26 |
int ISD; |
| 27 |
MVT::SimpleValueType Type; |
| 28 |
CostType Cost; |
| 29 |
}; |
| 30 |
using CostTblEntry = CostTblEntryT<unsigned>; |
| 31 |
|
| 32 |
|
| 33 |
template <class CostType> |
| 34 |
inline const CostTblEntryT<CostType> * |
| 35 |
CostTableLookup(ArrayRef<CostTblEntryT<CostType>> Tbl, int ISD, MVT Ty) { |
| 36 |
auto I = find_if(Tbl, [=](const CostTblEntryT<CostType> &Entry) { |
| 37 |
return ISD == Entry.ISD && Ty == Entry.Type; |
| 38 |
}); |
| 39 |
if (I != Tbl.end()) |
| 40 |
return I; |
| 41 |
|
| 42 |
|
| 43 |
return nullptr; |
| 44 |
} |
| 45 |
|
| 46 |
template <size_t N, class CostType> |
| 47 |
inline const CostTblEntryT<CostType> * |
| 48 |
CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) { |
| 49 |
|
| 50 |
return CostTableLookup<CostType>(makeArrayRef(Table), ISD, Ty); |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
template <typename CostType> |
| 55 |
struct TypeConversionCostTblEntryT { |
| 56 |
int ISD; |
| 57 |
MVT::SimpleValueType Dst; |
| 58 |
MVT::SimpleValueType Src; |
| 59 |
CostType Cost; |
| 60 |
}; |
| 61 |
using TypeConversionCostTblEntry = TypeConversionCostTblEntryT<unsigned>; |
| 62 |
|
| 63 |
|
| 64 |
template <class CostType> |
| 65 |
inline const TypeConversionCostTblEntryT<CostType> * |
| 66 |
ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntryT<CostType>> Tbl, |
| 67 |
int ISD, MVT Dst, MVT Src) { |
| 68 |
auto I = |
| 69 |
find_if(Tbl, [=](const TypeConversionCostTblEntryT<CostType> &Entry) { |
| 70 |
return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst; |
| 71 |
}); |
| 72 |
if (I != Tbl.end()) |
| 73 |
return I; |
| 74 |
|
| 75 |
|
| 76 |
return nullptr; |
| 77 |
} |
| 78 |
|
| 79 |
template <size_t N, class CostType> |
| 80 |
inline const TypeConversionCostTblEntryT<CostType> * |
| 81 |
ConvertCostTableLookup(const TypeConversionCostTblEntryT<CostType> (&Table)[N], |
| 82 |
int ISD, MVT Dst, MVT Src) { |
| 83 |
|
| 84 |
return ConvertCostTableLookup<CostType>(makeArrayRef(Table), ISD, Dst, Src); |
| 85 |
} |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
#endif |