1326938Sdim//===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===// 2326938Sdim// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6326938Sdim// 7326938Sdim//===----------------------------------------------------------------------===// 8326938Sdim/// 9326938Sdim/// \file 10341825Sdim/// Cost tables and simple lookup functions 11326938Sdim/// 12326938Sdim//===----------------------------------------------------------------------===// 13326938Sdim 14326938Sdim#ifndef LLVM_CODEGEN_COSTTABLE_H_ 15326938Sdim#define LLVM_CODEGEN_COSTTABLE_H_ 16326938Sdim 17326938Sdim#include "llvm/ADT/ArrayRef.h" 18326938Sdim#include "llvm/ADT/STLExtras.h" 19341825Sdim#include "llvm/Support/MachineValueType.h" 20326938Sdim 21326938Sdimnamespace llvm { 22326938Sdim 23326938Sdim/// Cost Table Entry 24326938Sdimstruct CostTblEntry { 25326938Sdim int ISD; 26326938Sdim MVT::SimpleValueType Type; 27326938Sdim unsigned Cost; 28326938Sdim}; 29326938Sdim 30326938Sdim/// Find in cost table, TypeTy must be comparable to CompareTy by == 31326938Sdiminline const CostTblEntry *CostTableLookup(ArrayRef<CostTblEntry> Tbl, 32326938Sdim int ISD, MVT Ty) { 33326938Sdim auto I = find_if(Tbl, [=](const CostTblEntry &Entry) { 34326938Sdim return ISD == Entry.ISD && Ty == Entry.Type; 35326938Sdim }); 36326938Sdim if (I != Tbl.end()) 37326938Sdim return I; 38326938Sdim 39326938Sdim // Could not find an entry. 40326938Sdim return nullptr; 41326938Sdim} 42326938Sdim 43326938Sdim/// Type Conversion Cost Table 44326938Sdimstruct TypeConversionCostTblEntry { 45326938Sdim int ISD; 46326938Sdim MVT::SimpleValueType Dst; 47326938Sdim MVT::SimpleValueType Src; 48326938Sdim unsigned Cost; 49326938Sdim}; 50326938Sdim 51326938Sdim/// Find in type conversion cost table, TypeTy must be comparable to CompareTy 52326938Sdim/// by == 53326938Sdiminline const TypeConversionCostTblEntry * 54326938SdimConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntry> Tbl, 55326938Sdim int ISD, MVT Dst, MVT Src) { 56326938Sdim auto I = find_if(Tbl, [=](const TypeConversionCostTblEntry &Entry) { 57326938Sdim return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst; 58326938Sdim }); 59326938Sdim if (I != Tbl.end()) 60326938Sdim return I; 61326938Sdim 62326938Sdim // Could not find an entry. 63326938Sdim return nullptr; 64326938Sdim} 65326938Sdim 66326938Sdim} // namespace llvm 67326938Sdim 68326938Sdim#endif /* LLVM_CODEGEN_COSTTABLE_H_ */ 69