File indexing completed on 2026-05-10 08:43:28
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_CODEGEN_COSTTABLE_H_
0015 #define LLVM_CODEGEN_COSTTABLE_H_
0016
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/ADT/STLExtras.h"
0019 #include "llvm/CodeGenTypes/MachineValueType.h"
0020
0021 namespace llvm {
0022
0023
0024 template <typename CostType>
0025 struct CostTblEntryT {
0026 int ISD;
0027 MVT::SimpleValueType Type;
0028 CostType Cost;
0029 };
0030 using CostTblEntry = CostTblEntryT<unsigned>;
0031
0032
0033 template <class CostType>
0034 inline const CostTblEntryT<CostType> *
0035 CostTableLookup(ArrayRef<CostTblEntryT<CostType>> Tbl, int ISD, MVT Ty) {
0036 auto I = find_if(Tbl, [=](const CostTblEntryT<CostType> &Entry) {
0037 return ISD == Entry.ISD && Ty == Entry.Type;
0038 });
0039 if (I != Tbl.end())
0040 return I;
0041
0042
0043 return nullptr;
0044 }
0045
0046 template <size_t N, class CostType>
0047 inline const CostTblEntryT<CostType> *
0048 CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
0049
0050 return CostTableLookup<CostType>(Table, ISD, Ty);
0051 }
0052
0053
0054 template <typename CostType>
0055 struct TypeConversionCostTblEntryT {
0056 int ISD;
0057 MVT::SimpleValueType Dst;
0058 MVT::SimpleValueType Src;
0059 CostType Cost;
0060 };
0061 using TypeConversionCostTblEntry = TypeConversionCostTblEntryT<unsigned>;
0062
0063
0064 template <class CostType>
0065 inline const TypeConversionCostTblEntryT<CostType> *
0066 ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntryT<CostType>> Tbl,
0067 int ISD, MVT Dst, MVT Src) {
0068 auto I =
0069 find_if(Tbl, [=](const TypeConversionCostTblEntryT<CostType> &Entry) {
0070 return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst;
0071 });
0072 if (I != Tbl.end())
0073 return I;
0074
0075
0076 return nullptr;
0077 }
0078
0079 template <size_t N, class CostType>
0080 inline const TypeConversionCostTblEntryT<CostType> *
0081 ConvertCostTableLookup(const TypeConversionCostTblEntryT<CostType> (&Table)[N],
0082 int ISD, MVT Dst, MVT Src) {
0083
0084 return ConvertCostTableLookup<CostType>(Table, ISD, Dst, Src);
0085 }
0086
0087 }
0088
0089 #endif