Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

64 lines
1.6 KiB

  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 by ==
  25. template <class TypeTy>
  26. int CostTableLookup(const CostTblEntry<TypeTy> *Tbl,
  27. unsigned len, int ISD, TypeTy Ty) {
  28. for (unsigned int i = 0; i < len; ++i)
  29. if (Tbl[i].ISD == ISD && Tbl[i].Type == Ty)
  30. return i;
  31. // Could not find an entry.
  32. return -1;
  33. }
  34. /// Type Conversion Cost Table
  35. template <class TypeTy>
  36. struct TypeConversionCostTblEntry {
  37. int ISD;
  38. TypeTy Dst;
  39. TypeTy Src;
  40. unsigned Cost;
  41. };
  42. /// Find in type conversion cost table, TypeTy must be comparable by ==
  43. template <class TypeTy>
  44. int ConvertCostTableLookup(const TypeConversionCostTblEntry<TypeTy> *Tbl,
  45. unsigned len, int ISD, TypeTy Dst, TypeTy Src) {
  46. for (unsigned int i = 0; i < len; ++i)
  47. if (Tbl[i].ISD == ISD && Tbl[i].Src == Src && Tbl[i].Dst == Dst)
  48. return i;
  49. // Could not find an entry.
  50. return -1;
  51. }
  52. } // namespace llvm
  53. #endif /* LLVM_TARGET_COSTTABLE_H_ */