LLVM 20.0.0git
CostTable.h
Go to the documentation of this file.
1//===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8///
9/// \file
10/// Cost tables and simple lookup functions
11///
12//===----------------------------------------------------------------------===//
13
14#ifndef LLVM_CODEGEN_COSTTABLE_H_
15#define LLVM_CODEGEN_COSTTABLE_H_
16
17#include "llvm/ADT/ArrayRef.h"
18#include "llvm/ADT/STLExtras.h"
20
21namespace llvm {
22
23/// Cost Table Entry
24template <typename CostType>
26 int ISD;
28 CostType Cost;
29};
31
32/// Find in cost table.
33template <class CostType>
34inline const CostTblEntryT<CostType> *
36 auto I = find_if(Tbl, [=](const CostTblEntryT<CostType> &Entry) {
37 return ISD == Entry.ISD && Ty == Entry.Type;
38 });
39 if (I != Tbl.end())
40 return I;
41
42 // Could not find an entry.
43 return nullptr;
44}
45
46template <size_t N, class CostType>
47inline const CostTblEntryT<CostType> *
48CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
49 // Wrapper to fix template argument deduction failures.
50 return CostTableLookup<CostType>(Table, ISD, Ty);
51}
52
53/// Type Conversion Cost Table
54template <typename CostType>
56 int ISD;
59 CostType Cost;
60};
62
63/// Find in type conversion cost table.
64template <class CostType>
67 int ISD, MVT Dst, MVT Src) {
68 auto I =
69 find_if(Tbl, [=](const TypeConversionCostTblEntryT<CostType> &Entry) {
70 return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst;
71 });
72 if (I != Tbl.end())
73 return I;
74
75 // Could not find an entry.
76 return nullptr;
77}
78
79template <size_t N, class CostType>
80inline const TypeConversionCostTblEntryT<CostType> *
82 int ISD, MVT Dst, MVT Src) {
83 // Wrapper to fix template argument deduction failures.
84 return ConvertCostTableLookup<CostType>(Table, ISD, Dst, Src);
85}
86
87} // namespace llvm
88
89#endif /* LLVM_CODEGEN_COSTTABLE_H_ */
#define I(x, y, z)
Definition: MD5.cpp:58
This file contains some templates that are useful if you are working with the STL at all.
ArrayRef - Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition: ArrayRef.h:41
Machine Value Type.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
const CostTblEntryT< CostType > * CostTableLookup(ArrayRef< CostTblEntryT< CostType > > Tbl, int ISD, MVT Ty)
Find in cost table.
Definition: CostTable.h:35
auto find_if(R &&Range, UnaryPredicate P)
Provide wrappers to std::find_if which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1749
const TypeConversionCostTblEntryT< CostType > * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntryT< CostType > > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table.
Definition: CostTable.h:66
#define N
Cost Table Entry.
Definition: CostTable.h:25
MVT::SimpleValueType Type
Definition: CostTable.h:27
Type Conversion Cost Table.
Definition: CostTable.h:55
MVT::SimpleValueType Dst
Definition: CostTable.h:57
MVT::SimpleValueType Src
Definition: CostTable.h:58