1 //===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Cost tables and simple lookup functions
13 //===----------------------------------------------------------------------===//
15 #ifndef LLVM_TARGET_COSTTABLE_H_
16 #define LLVM_TARGET_COSTTABLE_H_
18 #include "llvm/ADT/ArrayRef.h"
23 template <class TypeTy>
30 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
31 template <class TypeTy, class CompareTy>
32 const CostTblEntry<TypeTy> *CostTableLookup(ArrayRef<CostTblEntry<TypeTy>> Tbl,
33 int ISD, CompareTy Ty) {
34 auto I = std::find_if(Tbl.begin(), Tbl.end(),
35 [=](const CostTblEntry<TypeTy> &Entry) {
36 return ISD == Entry.ISD && Ty == Entry.Type; });
40 // Could not find an entry.
44 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
45 template <class TypeTy, class CompareTy, unsigned N>
46 const CostTblEntry<TypeTy> *CostTableLookup(const CostTblEntry<TypeTy>(&Tbl)[N],
47 int ISD, CompareTy Ty) {
48 return CostTableLookup(makeArrayRef(Tbl), ISD, Ty);
51 /// Type Conversion Cost Table
52 template <class TypeTy>
53 struct TypeConversionCostTblEntry {
60 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
62 template <class TypeTy, class CompareTy>
63 const TypeConversionCostTblEntry<TypeTy> *
64 ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntry<TypeTy>> Tbl,
65 int ISD, CompareTy Dst, CompareTy Src) {
66 auto I = std::find_if(Tbl.begin(), Tbl.end(),
67 [=](const TypeConversionCostTblEntry<TypeTy> &Entry) {
68 return ISD == Entry.ISD && Src == Entry.Src &&
74 // Could not find an entry.
78 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
80 template <class TypeTy, class CompareTy, unsigned N>
81 const TypeConversionCostTblEntry<TypeTy> *
82 ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy>(&Tbl)[N],
83 int ISD, CompareTy Dst, CompareTy Src) {
84 return ConvertCostTableLookup(makeArrayRef(Tbl), ISD, Dst, Src);
90 #endif /* LLVM_TARGET_COSTTABLE_H_ */