LLVM API Documentation

CostTable.h
Go to the documentation of this file.
00001 //===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 ///
00010 /// \file
00011 /// \brief Cost tables and simple lookup functions
00012 ///
00013 //===----------------------------------------------------------------------===//
00014 
00015 #ifndef LLVM_TARGET_COSTTABLE_H_
00016 #define LLVM_TARGET_COSTTABLE_H_
00017 
00018 namespace llvm {
00019 
00020 /// Cost Table Entry
00021 template <class TypeTy>
00022 struct CostTblEntry {
00023   int ISD;
00024   TypeTy Type;
00025   unsigned Cost;
00026 };
00027 
00028 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
00029 template <class TypeTy, class CompareTy>
00030 int CostTableLookup(const CostTblEntry<TypeTy> *Tbl, unsigned len, int ISD,
00031                     CompareTy Ty) {
00032   for (unsigned int i = 0; i < len; ++i)
00033     if (ISD == Tbl[i].ISD && Ty == Tbl[i].Type)
00034       return i;
00035 
00036   // Could not find an entry.
00037   return -1;
00038 }
00039 
00040 /// Find in cost table, TypeTy must be comparable to CompareTy by ==
00041 template <class TypeTy, class CompareTy, unsigned N>
00042 int CostTableLookup(const CostTblEntry<TypeTy>(&Tbl)[N], int ISD,
00043                     CompareTy Ty) {
00044   return CostTableLookup(Tbl, N, ISD, Ty);
00045 }
00046 
00047 /// Type Conversion Cost Table
00048 template <class TypeTy>
00049 struct TypeConversionCostTblEntry {
00050   int ISD;
00051   TypeTy Dst;
00052   TypeTy Src;
00053   unsigned Cost;
00054 };
00055 
00056 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
00057 /// by ==
00058 template <class TypeTy, class CompareTy>
00059 int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl,
00060                            unsigned len, int ISD, CompareTy Dst,
00061                            CompareTy Src) {
00062   for (unsigned int i = 0; i < len; ++i)
00063     if (ISD == Tbl[i].ISD && Src == Tbl[i].Src && Dst == Tbl[i].Dst)
00064       return i;
00065 
00066   // Could not find an entry.
00067   return -1;
00068 }
00069 
00070 /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
00071 /// by ==
00072 template <class TypeTy, class CompareTy, unsigned N>
00073 int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy>(&Tbl)[N],
00074                            int ISD, CompareTy Dst, CompareTy Src) {
00075   return ConvertCostTableLookup(Tbl, N, ISD, Dst, Src);
00076 }
00077 
00078 } // namespace llvm
00079 
00080 
00081 #endif /* LLVM_TARGET_COSTTABLE_H_ */