1249259Sdim//===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
2249259Sdim//
3249259Sdim//                     The LLVM Compiler Infrastructure
4249259Sdim//
5249259Sdim// This file is distributed under the University of Illinois Open Source
6249259Sdim// License. See LICENSE.TXT for details.
7249259Sdim//
8249259Sdim//===----------------------------------------------------------------------===//
9249259Sdim///
10249259Sdim/// \file
11249259Sdim/// \brief Cost tables and simple lookup functions
12249259Sdim///
13249259Sdim//===----------------------------------------------------------------------===//
14249259Sdim
15249259Sdim#ifndef LLVM_TARGET_COSTTABLE_H_
16249259Sdim#define LLVM_TARGET_COSTTABLE_H_
17249259Sdim
18249259Sdimnamespace llvm {
19249259Sdim
20249259Sdim/// Cost Table Entry
21249259Sdimtemplate <class TypeTy>
22249259Sdimstruct CostTblEntry {
23249259Sdim  int ISD;
24249259Sdim  TypeTy Type;
25249259Sdim  unsigned Cost;
26249259Sdim};
27249259Sdim
28249259Sdim/// Find in cost table, TypeTy must be comparable by ==
29249259Sdimtemplate <class TypeTy>
30249259Sdimint CostTableLookup(const CostTblEntry<TypeTy> *Tbl,
31249259Sdim                    unsigned len, int ISD, TypeTy Ty) {
32249259Sdim  for (unsigned int i = 0; i < len; ++i)
33249259Sdim    if (Tbl[i].ISD == ISD && Tbl[i].Type == Ty)
34249259Sdim      return i;
35249259Sdim
36249259Sdim  // Could not find an entry.
37249259Sdim  return -1;
38249259Sdim}
39249259Sdim
40249259Sdim/// Type Conversion Cost Table
41249259Sdimtemplate <class TypeTy>
42249259Sdimstruct TypeConversionCostTblEntry {
43249259Sdim  int ISD;
44249259Sdim  TypeTy Dst;
45249259Sdim  TypeTy Src;
46249259Sdim  unsigned Cost;
47249259Sdim};
48249259Sdim
49249259Sdim/// Find in type conversion cost table, TypeTy must be comparable by ==
50249259Sdimtemplate <class TypeTy>
51249259Sdimint ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl,
52249259Sdim                           unsigned len, int ISD, TypeTy Dst, TypeTy Src) {
53249259Sdim  for (unsigned int i = 0; i < len; ++i)
54249259Sdim    if (Tbl[i].ISD == ISD && Tbl[i].Src == Src && Tbl[i].Dst == Dst)
55249259Sdim      return i;
56249259Sdim
57249259Sdim  // Could not find an entry.
58249259Sdim  return -1;
59249259Sdim}
60249259Sdim
61249259Sdim} // namespace llvm
62249259Sdim
63249259Sdim
64249259Sdim#endif /* LLVM_TARGET_COSTTABLE_H_ */
65