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
|
// SPDX-License-Identifier: GPL-3.0-or-later
#ifndef RCC_CODEGEN_LIVEREGUNITS_H
#define RCC_CODEGEN_LIVEREGUNITS_H
#include "rcc/CodeGen/MachineIRTypes.h"
#include "rcc/CodeGen/Register.h"
#include "rcc/Support/Error.h"
#include <cstddef>
#include <cstdint>
#include <optional>
#include <span>
#include <unordered_map>
#include <vector>
namespace rcc {
class MachineFunction;
class MachineInstr;
class MachineOperand;
class RegisterMask;
class TargetDescription;
struct PhysicalRegisterDesc;
class LiveRegUnits final {
public:
[[nodiscard]] LaneMask lanes(RegisterUnitID Unit) const noexcept;
[[nodiscard]] bool contains(RegisterUnitID Unit, LaneMask Lanes = LaneMask::all()) const noexcept;
[[nodiscard]] bool intersects(RegisterUnitID Unit,
LaneMask Lanes = LaneMask::all()) const noexcept;
[[nodiscard]] bool empty() const noexcept {
return Values.empty();
}
void add(RegisterUnitID Unit, LaneMask Lanes);
void remove(RegisterUnitID Unit, LaneMask Lanes);
void unite(const LiveRegUnits &Other);
void subtract(const LiveRegUnits &Other);
[[nodiscard]] Expected<bool> available(PhysicalRegister Reg,
const TargetDescription &Target) const;
[[nodiscard]] static Expected<void> accumulateUsedDefed(const MachineInstr &Instruction,
LiveRegUnits &Modified,
LiveRegUnits &Used,
const TargetDescription &Target);
[[nodiscard]] const std::unordered_map<RegisterUnitID, LaneMask> &entries() const noexcept {
return Values;
}
friend bool operator==(const LiveRegUnits &, const LiveRegUnits &) = default;
private:
std::unordered_map<RegisterUnitID, LaneMask> Values;
};
struct PhysicalUnitAccess final {
RegisterUnitID Unit;
LaneMask Lanes;
};
[[nodiscard]] LaneMask normalizeUnitLanes(LaneMask UnitViewLanes,
LaneMask RegisterLanes = LaneMask::all()) noexcept;
[[nodiscard]] LaneMask denormalizeUnitLanes(LaneMask UnitLanes, LaneMask UnitViewLanes) noexcept;
[[nodiscard]] LaneMask physicalRegisterLanes(const PhysicalRegisterDesc &Description) noexcept;
[[nodiscard]] LiveRegUnits physicalRegisterCoverage(const PhysicalRegisterDesc &Description,
LaneMask Requested = LaneMask::all());
[[nodiscard]] bool isSubset(const LiveRegUnits &Subset, const LiveRegUnits &Superset) noexcept;
[[nodiscard]] std::size_t laneCount(const LiveRegUnits &Set) noexcept;
[[nodiscard]] Expected<LaneMask> virtualRegisterLanes(Register Reg, const MachineFunction &Function,
const TargetDescription &Target);
[[nodiscard]] Expected<LaneMask> virtualOperandLanes(const MachineOperand &Operand,
const MachineFunction &Function,
const TargetDescription &Target);
[[nodiscard]] Expected<std::vector<PhysicalUnitAccess>>
physicalOperandUnits(const MachineOperand &Operand, const TargetDescription &Target);
void addPhysicalRegister(LiveRegUnits &Set, const PhysicalRegisterDesc &Description,
LaneMask Requested = LaneMask::all());
[[nodiscard]] bool isReservedPhysicalRegister(Register Reg, const MachineFunction &Function,
const TargetDescription &Target) noexcept;
[[nodiscard]] Expected<void> addRegisterMaskDefs(LiveRegUnits &Set, const RegisterMask &Mask,
const TargetDescription &Target);
[[nodiscard]] Expected<void> addRegisterMaskUses(LiveRegUnits &Set, const RegisterMask &Mask,
const TargetDescription &Target);
} // namespace rcc
#endif // RCC_CODEGEN_LIVEREGUNITS_H
|