CostTable.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //===-- CostTable.h - Instruction Cost Table handling -----------*- C++ -*-===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is distributed under the University of Illinois Open Source
  6. // License. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. ///
  10. /// \file
  11. /// \brief Cost tables and simple lookup functions
  12. ///
  13. //===----------------------------------------------------------------------===//
  14. #ifndef LLVM_TARGET_COSTTABLE_H_
  15. #define LLVM_TARGET_COSTTABLE_H_
  16. namespace llvm {
  17. /// Cost Table Entry
  18. template <class TypeTy>
  19. struct CostTblEntry {
  20. int ISD;
  21. TypeTy Type;
  22. unsigned Cost;
  23. };
  24. /// Find in cost table, TypeTy must be comparable to CompareTy by ==
  25. template <class TypeTy, class CompareTy>
  26. int CostTableLookup(const CostTblEntry<TypeTy> *Tbl, unsigned len, int ISD,
  27. CompareTy Ty) {
  28. for (unsigned int i = 0; i < len; ++i)
  29. if (ISD == Tbl[i].ISD && Ty == Tbl[i].Type)
  30. return i;
  31. // Could not find an entry.
  32. return -1;
  33. }
  34. /// Find in cost table, TypeTy must be comparable to CompareTy by ==
  35. template <class TypeTy, class CompareTy, unsigned N>
  36. int CostTableLookup(const CostTblEntry<TypeTy>(&Tbl)[N], int ISD,
  37. CompareTy Ty) {
  38. return CostTableLookup(Tbl, N, ISD, Ty);
  39. }
  40. /// Type Conversion Cost Table
  41. template <class TypeTy>
  42. struct TypeConversionCostTblEntry {
  43. int ISD;
  44. TypeTy Dst;
  45. TypeTy Src;
  46. unsigned Cost;
  47. };
  48. /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
  49. /// by ==
  50. template <class TypeTy, class CompareTy>
  51. int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl,
  52. unsigned len, int ISD, CompareTy Dst,
  53. CompareTy Src) {
  54. for (unsigned int i = 0; i < len; ++i)
  55. if (ISD == Tbl[i].ISD && Src == Tbl[i].Src && Dst == Tbl[i].Dst)
  56. return i;
  57. // Could not find an entry.
  58. return -1;
  59. }
  60. /// Find in type conversion cost table, TypeTy must be comparable to CompareTy
  61. /// by ==
  62. template <class TypeTy, class CompareTy, unsigned N>
  63. int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy>(&Tbl)[N],
  64. int ISD, CompareTy Dst, CompareTy Src) {
  65. return ConvertCostTableLookup(Tbl, N, ISD, Dst, Src);
  66. }
  67. } // namespace llvm
  68. #endif /* LLVM_TARGET_COSTTABLE_H_ */