Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:28

0001 //===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 ///
0009 /// \file
0010 /// Cost tables and simple lookup functions
0011 ///
0012 //===----------------------------------------------------------------------===//
0013 
0014 #ifndef LLVM_CODEGEN_COSTTABLE_H_
0015 #define LLVM_CODEGEN_COSTTABLE_H_
0016 
0017 #include "llvm/ADT/ArrayRef.h"
0018 #include "llvm/ADT/STLExtras.h"
0019 #include "llvm/CodeGenTypes/MachineValueType.h"
0020 
0021 namespace llvm {
0022 
0023 /// Cost Table Entry
0024 template <typename CostType>
0025 struct CostTblEntryT {
0026   int ISD;
0027   MVT::SimpleValueType Type;
0028   CostType Cost;
0029 };
0030 using CostTblEntry = CostTblEntryT<unsigned>;
0031 
0032 /// Find in cost table.
0033 template <class CostType>
0034 inline const CostTblEntryT<CostType> *
0035 CostTableLookup(ArrayRef<CostTblEntryT<CostType>> Tbl, int ISD, MVT Ty) {
0036   auto I = find_if(Tbl, [=](const CostTblEntryT<CostType> &Entry) {
0037     return ISD == Entry.ISD && Ty == Entry.Type;
0038   });
0039   if (I != Tbl.end())
0040     return I;
0041 
0042   // Could not find an entry.
0043   return nullptr;
0044 }
0045 
0046 template <size_t N, class CostType>
0047 inline const CostTblEntryT<CostType> *
0048 CostTableLookup(const CostTblEntryT<CostType> (&Table)[N], int ISD, MVT Ty) {
0049   // Wrapper to fix template argument deduction failures.
0050   return CostTableLookup<CostType>(Table, ISD, Ty);
0051 }
0052 
0053 /// Type Conversion Cost Table
0054 template <typename CostType>
0055 struct TypeConversionCostTblEntryT {
0056   int ISD;
0057   MVT::SimpleValueType Dst;
0058   MVT::SimpleValueType Src;
0059   CostType Cost;
0060 };
0061 using TypeConversionCostTblEntry = TypeConversionCostTblEntryT<unsigned>;
0062 
0063 /// Find in type conversion cost table.
0064 template <class CostType>
0065 inline const TypeConversionCostTblEntryT<CostType> *
0066 ConvertCostTableLookup(ArrayRef<TypeConversionCostTblEntryT<CostType>> Tbl,
0067                        int ISD, MVT Dst, MVT Src) {
0068   auto I =
0069       find_if(Tbl, [=](const TypeConversionCostTblEntryT<CostType> &Entry) {
0070         return ISD == Entry.ISD && Src == Entry.Src && Dst == Entry.Dst;
0071       });
0072   if (I != Tbl.end())
0073     return I;
0074 
0075   // Could not find an entry.
0076   return nullptr;
0077 }
0078 
0079 template <size_t N, class CostType>
0080 inline const TypeConversionCostTblEntryT<CostType> *
0081 ConvertCostTableLookup(const TypeConversionCostTblEntryT<CostType> (&Table)[N],
0082                        int ISD, MVT Dst, MVT Src) {
0083   // Wrapper to fix template argument deduction failures.
0084   return ConvertCostTableLookup<CostType>(Table, ISD, Dst, Src);
0085 }
0086 
0087 } // namespace llvm
0088 
0089 #endif /* LLVM_CODEGEN_COSTTABLE_H_ */