LLVM 23.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#include <cstdint>
21
22namespace llvm {
23
24/// Cost Table Entry
25template <typename CostType>
32
33/// Find in cost table.
34template <class CostType>
35inline const CostTblEntryT<CostType> *
37 auto I = find_if(Tbl, [=](const CostTblEntryT<CostType> &Entry) {
38 return ISD == Entry.ISD && Ty == Entry.Type;
39 });
40 if (I != Tbl.end())
41 return I;
42
43 // Could not find an entry.
44 return nullptr;
45}
46
47template <size_t N, class CostType>
48inline const CostTblEntryT<CostType> *
49CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
50 // Wrapper to fix template argument deduction failures.
51 return CostTableLookup<CostType>(Table, ISD, Ty);
52}
53
54/// Type Conversion Cost Table
55template <typename CostType>
63
64/// Find in type conversion cost table.
65template <class CostType>
68 int ISD, MVT Dst, MVT Src) {
69 auto I =
70 find_if(Tbl, [=](const TypeConversionCostTblEntryT<CostType> &Entry) {
71 return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst;
72 });
73 if (I != Tbl.end())
74 return I;
75
76 // Could not find an entry.
77 return nullptr;
78}
79
80template <size_t N, class CostType>
81inline const TypeConversionCostTblEntryT<CostType> *
83 int ISD, MVT Dst, MVT Src) {
84 // Wrapper to fix template argument deduction failures.
85 return ConvertCostTableLookup<CostType>(Table, ISD, Dst, Src);
86}
87
88} // namespace llvm
89
90#endif /* LLVM_CODEGEN_COSTTABLE_H_ */
#define I(x, y, z)
Definition MD5.cpp:57
This file contains some templates that are useful if you are working with the STL at all.
Represent a constant reference to an array (0 or more elements consecutively in memory),...
Definition ArrayRef.h:40
Machine Value Type.
ISD namespace - This namespace contains an enum which represents all of the SelectionDAG node types a...
Definition ISDOpcodes.h:24
This is an optimization pass for GlobalISel generic memory operations.
const CostTblEntryT< CostType > * CostTableLookup(ArrayRef< CostTblEntryT< CostType > > Tbl, int ISD, MVT Ty)
Find in cost table.
Definition CostTable.h:36
TypeConversionCostTblEntryT< uint16_t > TypeConversionCostTblEntry
Definition CostTable.h:62
CostTblEntryT< uint16_t > CostTblEntry
Definition CostTable.h:31
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:1772
const TypeConversionCostTblEntryT< CostType > * ConvertCostTableLookup(ArrayRef< TypeConversionCostTblEntryT< CostType > > Tbl, int ISD, MVT Dst, MVT Src)
Find in type conversion cost table.
Definition CostTable.h:67
#define N
Cost Table Entry.
Definition CostTable.h:26
MVT::SimpleValueType Type
Definition CostTable.h:28
Type Conversion Cost Table.
Definition CostTable.h:56