CostTable.h revision b3755e7fa2e386e9bd348eda6b1876ae09c1bf99
1//===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9///
10/// \file
11/// \brief Cost tables and simple lookup functions
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_TARGET_COSTTABLE_H_
16#define LLVM_TARGET_COSTTABLE_H_
17
18namespace llvm {
19
20/// Cost Table Entry
21template <class TypeTy>
22struct CostTblEntry {
23  int ISD;
24  TypeTy Type;
25  unsigned Cost;
26};
27
28/// Find in cost table, TypeTy must be comparable by ==
29template <class TypeTy>
30int CostTableLookup(const CostTblEntry<TypeTy> *Tbl,
31                    unsigned len, int ISD, TypeTy Ty) {
32  for (unsigned int i = 0; i < len; ++i)
33    if (Tbl[i].ISD == ISD && Tbl[i].Type == Ty)
34      return i;
35
36  // Could not find an entry.
37  return -1;
38}
39
40/// Type Conversion Cost Table
41template <class TypeTy>
42struct TypeConversionCostTblEntry {
43  int ISD;
44  TypeTy Dst;
45  TypeTy Src;
46  unsigned Cost;
47};
48
49/// Find in type conversion cost table, TypeTy must be comparable by ==
50template <class TypeTy>
51int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl,
52                           unsigned len, int ISD, TypeTy Dst, TypeTy Src) {
53  for (unsigned int i = 0; i < len; ++i)
54    if (Tbl[i].ISD == ISD && Tbl[i].Src == Src && Tbl[i].Dst == Dst)
55      return i;
56
57  // Could not find an entry.
58  return -1;
59}
60
61} // namespace llvm
62
63
64#endif /* LLVM_TARGET_COSTTABLE_H_ */
65