File: RegCategory.h

package info (click to toggle)
intel-graphics-compiler 1.0.12504.6-1%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 83,912 kB
  • sloc: cpp: 910,147; lisp: 202,655; ansic: 15,197; python: 4,025; yacc: 2,241; lex: 1,570; pascal: 244; sh: 104; makefile: 25
file content (120 lines) | stat: -rw-r--r-- 3,217 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*========================== begin_copyright_notice ============================

Copyright (C) 2019-2021 Intel Corporation

SPDX-License-Identifier: MIT

============================= end_copyright_notice ===========================*/

#ifndef VC_UTILS_GENX_REGCATEGORY_H
#define VC_UTILS_GENX_REGCATEGORY_H

#include "vc/Utils/General/EnumUtils.h"
#include <llvm/ADT/StringRef.h>

#include <type_traits>
#include <utility>

namespace vc {

// The encoding for register category, used in GenXCategory,
// GenXLiveness and GenXVisaRegAlloc.  It is an anonymous enum inside a class
// rather than a named enum so you don't need to cast to/from int.
//
// Please update the following functions when changing this enum:
// isRealCategory
// isMaskCategory
// getRegCategoryName
// getRegCategoryShortName
enum class RegCategory : uint8_t {
  None,
  General,
  Address,
  Predicate,
  Sampler,
  Surface,
  EM,
  RM,
  LastCategory = RM
};

constexpr size_t numRegCategories() {
  return static_cast<size_t>(RegCategory::LastCategory) + 1;
}

constexpr bool checkRegCategory(RegCategory Category) {
  auto IntCat = static_cast<std::underlying_type_t<RegCategory>>(Category);
  if (IntCat >= vc::numRegCategories())
    return false;
  return true;
}

constexpr bool isRealCategory(RegCategory Category) {
  switch (Category) {
  case vc::RegCategory::General:
  case vc::RegCategory::Address:
  case vc::RegCategory::Predicate:
  case vc::RegCategory::Sampler:
  case vc::RegCategory::Surface:
    return true;
  case vc::RegCategory::None:
  case vc::RegCategory::EM:
  case vc::RegCategory::RM:
    return false;
  }
  IGC_ASSERT_MESSAGE(
      false,
      "New RegCategory was added, but isRealCategory func was not updated");
  return false;
}

constexpr bool isRealOrNoneCategory(RegCategory Category) {
  return isRealCategory(Category) || Category == RegCategory::None;
}

constexpr bool isMaskCategory(RegCategory Category) {
  switch (Category) {
  case vc::RegCategory::None:
  case vc::RegCategory::General:
  case vc::RegCategory::Address:
  case vc::RegCategory::Predicate:
  case vc::RegCategory::Sampler:
  case vc::RegCategory::Surface:
    return false;
  case vc::RegCategory::EM:
  case vc::RegCategory::RM:
    return true;
  }
  IGC_ASSERT_MESSAGE(
      false,
      "New RegCategory was added, but isMaskCategory func was not updated");
  return false;
}

template <typename SequenceContainer>
constexpr auto &&accessContainer(SequenceContainer &&SC, RegCategory Category) {
  return SC[static_cast<size_t>(Category)];
}

using RegCategoryIterator =
    EnumIterator<RegCategory, RegCategory::LastCategory>;

class RegCategoryView final {};

constexpr RegCategoryIterator begin(RegCategoryView) {
  return RegCategory::None;
}

constexpr RegCategoryIterator end(RegCategoryView) { return {}; }

// Get name of register category for debugging purposes.
// For anything unknown "???" is returned.
llvm::StringRef getRegCategoryName(RegCategory Category);

// Get short code of register category for debugging purposes.
// For None "-" is returned, for anything unknown -- "?".
llvm::StringRef getRegCategoryShortName(RegCategory Category);

} // namespace vc

#endif // VC_UTILS_GENX_REGCATEGORY_H