LLVM 22.0.0git
MCRegister.h
Go to the documentation of this file.
1//===-- llvm/MC/Register.h --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef LLVM_MC_MCREGISTER_H
10#define LLVM_MC_MCREGISTER_H
11
13#include "llvm/ADT/Hashing.h"
14#include <cassert>
15#include <limits>
16
17namespace llvm {
18
19/// An unsigned integer type large enough to represent all physical registers,
20/// but not necessarily virtual registers.
22
23/// Register units are used to compute register aliasing. Every register has at
24/// least one register unit, but it can have more. Two registers overlap if and
25/// only if they have a common register unit.
26///
27/// A target with a complicated sub-register structure will typically have many
28/// fewer register units than actual registers. MCRI::getNumRegUnits() returns
29/// the number of register units in the target.
30enum class MCRegUnit : unsigned;
31
33 using argument_type = MCRegUnit;
34
35 unsigned operator()(MCRegUnit Unit) const {
36 return static_cast<unsigned>(Unit);
37 }
38};
39
40/// Wrapper class representing physical registers. Should be passed by value.
42 friend hash_code hash_value(const MCRegister &);
43 unsigned Reg;
44
45public:
46 constexpr MCRegister(unsigned Val = 0) : Reg(Val) {}
47
48 // Register numbers can represent physical registers, virtual registers, and
49 // sometimes stack slots. The unsigned values are divided into these ranges:
50 //
51 // 0 Not a register, can be used as a sentinel.
52 // [1;2^30) Physical registers assigned by TableGen.
53 // [2^30;2^31) Stack slots. (Rarely used.)
54 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
55 //
56 // Further sentinels can be allocated from the small negative integers.
57 // DenseMapInfo<unsigned> uses -1u and -2u.
58 static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
59 "Reg isn't large enough to hold full range.");
60 static constexpr unsigned NoRegister = 0u;
61 static constexpr unsigned FirstPhysicalReg = 1u;
62 static constexpr unsigned LastPhysicalReg = (1u << 30) - 1;
63
64 /// Return true if the specified register number is in
65 /// the physical register namespace.
66 static constexpr bool isPhysicalRegister(unsigned Reg) {
67 return FirstPhysicalReg <= Reg && Reg <= LastPhysicalReg;
68 }
69
70 /// Return true if the specified register number is in the physical register
71 /// namespace.
72 constexpr bool isPhysical() const { return isPhysicalRegister(Reg); }
73
74 constexpr operator unsigned() const { return Reg; }
75
76 /// Check the provided unsigned value is a valid MCRegister.
77 static MCRegister from(unsigned Val) {
78 assert(Val == NoRegister || isPhysicalRegister(Val));
79 return MCRegister(Val);
80 }
81
82 constexpr unsigned id() const { return Reg; }
83
84 constexpr bool isValid() const { return Reg != NoRegister; }
85
86 /// Comparisons between register objects
87 constexpr bool operator==(const MCRegister &Other) const {
88 return Reg == Other.Reg;
89 }
90 constexpr bool operator!=(const MCRegister &Other) const {
91 return Reg != Other.Reg;
92 }
93
94 /// Comparisons against register constants. E.g.
95 /// * R == AArch64::WZR
96 /// * R == 0
97 constexpr bool operator==(unsigned Other) const { return Reg == Other; }
98 constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
99 constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }
100 constexpr bool operator!=(int Other) const { return Reg != unsigned(Other); }
101 // MSVC requires that we explicitly declare these two as well.
102 constexpr bool operator==(MCPhysReg Other) const {
103 return Reg == unsigned(Other);
104 }
105 constexpr bool operator!=(MCPhysReg Other) const {
106 return Reg != unsigned(Other);
107 }
108};
109
110// Provide DenseMapInfo for MCRegister
111template <> struct DenseMapInfo<MCRegister> {
112 static inline MCRegister getEmptyKey() {
114 }
118 static unsigned getHashValue(const MCRegister &Val) {
120 }
121 static bool isEqual(const MCRegister &LHS, const MCRegister &RHS) {
122 return LHS == RHS;
123 }
124};
125
126inline hash_code hash_value(const MCRegister &Reg) {
127 return hash_value(Reg.id());
128}
129} // namespace llvm
130
131#endif // LLVM_MC_MCREGISTER_H
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
This file defines DenseMapInfo traits for DenseMap.
Register Reg
Value * RHS
Value * LHS
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:41
constexpr bool isValid() const
Definition MCRegister.h:84
static constexpr unsigned LastPhysicalReg
Definition MCRegister.h:62
static constexpr unsigned FirstPhysicalReg
Definition MCRegister.h:61
constexpr bool operator==(const MCRegister &Other) const
Comparisons between register objects.
Definition MCRegister.h:87
constexpr bool operator!=(MCPhysReg Other) const
Definition MCRegister.h:105
static constexpr unsigned NoRegister
Definition MCRegister.h:60
constexpr bool operator!=(int Other) const
Definition MCRegister.h:100
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:66
constexpr MCRegister(unsigned Val=0)
Definition MCRegister.h:46
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition MCRegister.h:77
constexpr bool operator==(unsigned Other) const
Comparisons against register constants.
Definition MCRegister.h:97
constexpr bool operator==(int Other) const
Definition MCRegister.h:99
friend hash_code hash_value(const MCRegister &)
Definition MCRegister.h:126
constexpr bool operator!=(const MCRegister &Other) const
Definition MCRegister.h:90
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:72
constexpr bool operator==(MCPhysReg Other) const
Definition MCRegister.h:102
constexpr bool operator!=(unsigned Other) const
Definition MCRegister.h:98
constexpr unsigned id() const
Definition MCRegister.h:82
An opaque object representing a hash code.
Definition Hashing.h:76
This is an optimization pass for GlobalISel generic memory operations.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
hash_code hash_value(const FixedPointSemantics &Val)
@ Other
Any other memory.
Definition ModRef.h:68
uint16_t MCPhysReg
An unsigned integer type large enough to represent all physical registers, but not necessarily virtua...
Definition MCRegister.h:21
static bool isEqual(const MCRegister &LHS, const MCRegister &RHS)
Definition MCRegister.h:121
static MCRegister getTombstoneKey()
Definition MCRegister.h:115
static unsigned getHashValue(const MCRegister &Val)
Definition MCRegister.h:118
static MCRegister getEmptyKey()
Definition MCRegister.h:112
An information struct used to provide DenseMap with the various necessary components for a given valu...
unsigned operator()(MCRegUnit Unit) const
Definition MCRegister.h:35