aboutsummaryrefslogtreecommitdiff
path: root/backend/include/rcc/CodeGen/RegisterMask.h
blob: d5a5b71f62e85afac2decfe7b80122b6ec1c9e4d (plain)
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
// SPDX-License-Identifier: GPL-3.0-or-later

#ifndef RCC_CODEGEN_REGISTERMASK_H
#define RCC_CODEGEN_REGISTERMASK_H

#include "rcc/CodeGen/Register.h"

#include <cstddef>
#include <cstdint>
#include <span>
#include <utility>
#include <vector>

namespace rcc {

class RegisterMask final {
public:
  explicit RegisterMask(std::vector<std::uint64_t> PreservedWords)
      : PreservedWords(std::move(PreservedWords)) {}

  [[nodiscard]] bool preserves(PhysicalRegister PhysReg) const noexcept;

  [[nodiscard]] bool clobbers(PhysicalRegister PhysReg) const noexcept {
    return !preserves(PhysReg);
  }

  [[nodiscard]] std::span<const std::uint64_t> words() const noexcept {
    return PreservedWords;
  }

  friend bool operator==(const RegisterMask &Left, const RegisterMask &Right) = default;

private:
  std::vector<std::uint64_t> PreservedWords;
};

} // namespace rcc

#endif // RCC_CODEGEN_REGISTERMASK_H