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
18 #include "llvm/ADT/ArrayRef.h"
19 #include "llvm/CodeGen/MachineValueType.h"
20
21 namespace llvm {
22
23 /// Cost Table Entry
24 struct CostTblEntry {
25 int ISD;
26 MVT::SimpleValueType Type;
27 unsigned Cost;
28 };
29
30 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
CostTableLookup(ArrayRef<CostTblEntry> Tbl,int ISD,MVT Ty)31 inline const CostTblEntry *CostTableLookup(ArrayRef<CostTblEntry> Tbl,
32 int ISD, MVT Ty) {
33 auto I = std::find_if(Tbl.begin(), Tbl.end(),
34 [=](const CostTblEntry &Entry) {
35 return ISD == Entry.ISD && Ty == Entry.Type; });
36 if (I != Tbl.end())
37 return I;
38
39 // Could not find an entry.
40 return nullptr;
41 }
42
43 /// Type Conversion Cost Table
44 struct TypeConversionCostTblEntry {
45 int ISD;
46 MVT::SimpleValueType Dst;
47 MVT::SimpleValueType Src;
48 unsigned Cost;
49 };
50
51 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
52 /// by ==
53 inline const TypeConversionCostTblEntry *
ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntry> Tbl,int ISD,MVT Dst,MVT Src)54 ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntry> Tbl,
55 int ISD, MVT Dst, MVT Src) {
56 auto I = std::find_if(Tbl.begin(), Tbl.end(),
57 [=](const TypeConversionCostTblEntry &Entry) {
58 return ISD == Entry.ISD && Src == Entry.Src &&
59 Dst == Entry.Dst;
60 });
61 if (I != Tbl.end())
62 return I;
63
64 // Could not find an entry.
65 return nullptr;
66 }
67
68 } // namespace llvm
69
70
71 #endif /* LLVM_TARGET_COSTTABLE_H_ */
72