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.
31
32/// Wrapper class representing physical registers. Should be passed by value.
34 friend hash_code hash_value(const MCRegister &);
35 unsigned Reg;
36
37public:
38 constexpr MCRegister(unsigned Val = 0) : Reg(Val) {}
39
40 // Register numbers can represent physical registers, virtual registers, and
41 // sometimes stack slots. The unsigned values are divided into these ranges:
42 //
43 // 0 Not a register, can be used as a sentinel.
44 // [1;2^30) Physical registers assigned by TableGen.
45 // [2^30;2^31) Stack slots. (Rarely used.)
46 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
47 //
48 // Further sentinels can be allocated from the small negative integers.
49 // DenseMapInfo<unsigned> uses -1u and -2u.
50 static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
51 "Reg isn't large enough to hold full range.");
52 static constexpr unsigned NoRegister = 0u;
53 static constexpr unsigned FirstPhysicalReg = 1u;
54 static constexpr unsigned LastPhysicalReg = (1u << 30) - 1;
55
56 /// Return true if the specified register number is in
57 /// the physical register namespace.
58 static constexpr bool isPhysicalRegister(unsigned Reg) {
59 return FirstPhysicalReg <= Reg && Reg <= LastPhysicalReg;
60 }
61
62 /// Return true if the specified register number is in the physical register
63 /// namespace.
64 constexpr bool isPhysical() const { return isPhysicalRegister(Reg); }
65
66 constexpr operator unsigned() const { return Reg; }
67
68 /// Check the provided unsigned value is a valid MCRegister.
69 static MCRegister from(unsigned Val) {
70 assert(Val == NoRegister || isPhysicalRegister(Val));
71 return MCRegister(Val);
72 }
73
74 constexpr unsigned id() const { return Reg; }
75
76 constexpr bool isValid() const { return Reg != NoRegister; }
77
78 /// Comparisons between register objects
79 constexpr bool operator==(const MCRegister &Other) const {
80 return Reg == Other.Reg;
81 }
82 constexpr bool operator!=(const MCRegister &Other) const {
83 return Reg != Other.Reg;
84 }
85
86 /// Comparisons against register constants. E.g.
87 /// * R == AArch64::WZR
88 /// * R == 0
89 constexpr bool operator==(unsigned Other) const { return Reg == Other; }
90 constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
91 constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }
92 constexpr bool operator!=(int Other) const { return Reg != unsigned(Other); }
93 // MSVC requires that we explicitly declare these two as well.
94 constexpr bool operator==(MCPhysReg Other) const {
95 return Reg == unsigned(Other);
96 }
97 constexpr bool operator!=(MCPhysReg Other) const {
98 return Reg != unsigned(Other);
99 }
100};
101
102// Provide DenseMapInfo for MCRegister
103template <> struct DenseMapInfo<MCRegister> {
104 static inline MCRegister getEmptyKey() {
106 }
110 static unsigned getHashValue(const MCRegister &Val) {
112 }
113 static bool isEqual(const MCRegister &LHS, const MCRegister &RHS) {
114 return LHS == RHS;
115 }
116};
117
118inline hash_code hash_value(const MCRegister &Reg) {
119 return hash_value(Reg.id());
120}
121} // namespace llvm
122
123#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:33
constexpr bool isValid() const
Definition MCRegister.h:76
static constexpr unsigned LastPhysicalReg
Definition MCRegister.h:54
static constexpr unsigned FirstPhysicalReg
Definition MCRegister.h:53
constexpr bool operator==(const MCRegister &Other) const
Comparisons between register objects.
Definition MCRegister.h:79
constexpr bool operator!=(MCPhysReg Other) const
Definition MCRegister.h:97
static constexpr unsigned NoRegister
Definition MCRegister.h:52
constexpr bool operator!=(int Other) const
Definition MCRegister.h:92
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:58
constexpr MCRegister(unsigned Val=0)
Definition MCRegister.h:38
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition MCRegister.h:69
constexpr bool operator==(unsigned Other) const
Comparisons against register constants.
Definition MCRegister.h:89
constexpr bool operator==(int Other) const
Definition MCRegister.h:91
friend hash_code hash_value(const MCRegister &)
Definition MCRegister.h:118
constexpr bool operator!=(const MCRegister &Other) const
Definition MCRegister.h:82
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:64
constexpr bool operator==(MCPhysReg Other) const
Definition MCRegister.h:94
constexpr bool operator!=(unsigned Other) const
Definition MCRegister.h:90
constexpr unsigned id() const
Definition MCRegister.h:74
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)
unsigned MCRegUnit
Register units are used to compute register aliasing.
Definition MCRegister.h:30
@ 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:113
static MCRegister getTombstoneKey()
Definition MCRegister.h:107
static unsigned getHashValue(const MCRegister &Val)
Definition MCRegister.h:110
static MCRegister getEmptyKey()
Definition MCRegister.h:104
An information struct used to provide DenseMap with the various necessary components for a given valu...