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_
21 template <class TypeTy
>
28 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
29 template <class TypeTy
, class CompareTy
>
30 int CostTableLookup(const CostTblEntry
<TypeTy
> *Tbl
, unsigned len
, int ISD
,
32 for (unsigned int i
= 0; i
< len
; ++i
)
33 if (ISD
== Tbl
[i
].ISD
&& Ty
== Tbl
[i
].Type
)
36 // Could not find an entry.
40 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
41 template <class TypeTy
, class CompareTy
, unsigned N
>
42 int CostTableLookup(const CostTblEntry
<TypeTy
>(&Tbl
)[N
], int ISD
,
44 return CostTableLookup(Tbl
, N
, ISD
, Ty
);
47 /// Type Conversion Cost Table
48 template <class TypeTy
>
49 struct TypeConversionCostTblEntry
{
56 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
58 template <class TypeTy
, class CompareTy
>
59 int ConvertCostTableLookup(const TypeConversionCostTblEntry
<TypeTy
> *Tbl
,
60 unsigned len
, int ISD
, CompareTy Dst
,
62 for (unsigned int i
= 0; i
< len
; ++i
)
63 if (ISD
== Tbl
[i
].ISD
&& Src
== Tbl
[i
].Src
&& Dst
== Tbl
[i
].Dst
)
66 // Could not find an entry.
70 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
72 template <class TypeTy
, class CompareTy
, unsigned N
>
73 int ConvertCostTableLookup(const TypeConversionCostTblEntry
<TypeTy
>(&Tbl
)[N
],
74 int ISD
, CompareTy Dst
, CompareTy Src
) {
75 return ConvertCostTableLookup(Tbl
, N
, ISD
, Dst
, Src
);
81 #endif /* LLVM_TARGET_COSTTABLE_H_ */