LLVM 17.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/// Wrapper class representing physical registers. Should be passed by value.
25 friend hash_code hash_value(const MCRegister &);
26 unsigned Reg;
27
28public:
29 constexpr MCRegister(unsigned Val = 0) : Reg(Val) {}
30
31 // Register numbers can represent physical registers, virtual registers, and
32 // sometimes stack slots. The unsigned values are divided into these ranges:
33 //
34 // 0 Not a register, can be used as a sentinel.
35 // [1;2^30) Physical registers assigned by TableGen.
36 // [2^30;2^31) Stack slots. (Rarely used.)
37 // [2^31;2^32) Virtual registers assigned by MachineRegisterInfo.
38 //
39 // Further sentinels can be allocated from the small negative integers.
40 // DenseMapInfo<unsigned> uses -1u and -2u.
41 static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
42 "Reg isn't large enough to hold full range.");
43 static constexpr unsigned NoRegister = 0u;
44 static constexpr unsigned FirstPhysicalReg = 1u;
45 static constexpr unsigned FirstStackSlot = 1u << 30;
46 static constexpr unsigned VirtualRegFlag = 1u << 31;
47
48 /// This is the portion of the positive number space that is not a physical
49 /// register. StackSlot values do not exist in the MC layer, see
50 /// Register::isStackSlot() for the more information on them.
51 ///
52 static constexpr bool isStackSlot(unsigned Reg) {
53 return FirstStackSlot <= Reg && Reg < VirtualRegFlag;
54 }
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 < FirstStackSlot;
60 }
61
62 constexpr operator unsigned() const { return Reg; }
63
64 /// Check the provided unsigned value is a valid MCRegister.
65 static MCRegister from(unsigned Val) {
66 assert(Val == NoRegister || isPhysicalRegister(Val));
67 return MCRegister(Val);
68 }
69
70 constexpr unsigned id() const { return Reg; }
71
72 constexpr bool isValid() const { return Reg != NoRegister; }
73
74 /// Comparisons between register objects
75 constexpr bool operator==(const MCRegister &Other) const {
76 return Reg == Other.Reg;
77 }
78 constexpr bool operator!=(const MCRegister &Other) const {
79 return Reg != Other.Reg;
80 }
81
82 /// Comparisons against register constants. E.g.
83 /// * R == AArch64::WZR
84 /// * R == 0
85 /// * R == VirtRegMap::NO_PHYS_REG
86 constexpr bool operator==(unsigned Other) const { return Reg == Other; }
87 constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
88 constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }
89 constexpr bool operator!=(int Other) const { return Reg != unsigned(Other); }
90 // MSVC requires that we explicitly declare these two as well.
91 constexpr bool operator==(MCPhysReg Other) const {
92 return Reg == unsigned(Other);
93 }
94 constexpr bool operator!=(MCPhysReg Other) const {
95 return Reg != unsigned(Other);
96 }
97};
98
99// Provide DenseMapInfo for MCRegister
100template <> struct DenseMapInfo<MCRegister> {
101 static inline unsigned getEmptyKey() {
103 }
104 static inline unsigned getTombstoneKey() {
106 }
107 static unsigned getHashValue(const MCRegister &Val) {
109 }
110 static bool isEqual(const MCRegister &LHS, const MCRegister &RHS) {
111 return DenseMapInfo<unsigned>::isEqual(LHS.id(), RHS.id());
112 }
113};
114
116 return hash_value(Reg.id());
117}
118} // namespace llvm
119
120#endif // LLVM_MC_MCREGISTER_H
This file defines DenseMapInfo traits for DenseMap.
unsigned Reg
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Value * RHS
Value * LHS
Wrapper class representing physical registers. Should be passed by value.
Definition: MCRegister.h:24
static constexpr bool isStackSlot(unsigned Reg)
This is the portion of the positive number space that is not a physical register.
Definition: MCRegister.h:52
constexpr bool isValid() const
Definition: MCRegister.h:72
static constexpr unsigned FirstPhysicalReg
Definition: MCRegister.h:44
constexpr bool operator==(const MCRegister &Other) const
Comparisons between register objects.
Definition: MCRegister.h:75
constexpr bool operator!=(MCPhysReg Other) const
Definition: MCRegister.h:94
static constexpr unsigned NoRegister
Definition: MCRegister.h:43
constexpr bool operator!=(int Other) const
Definition: MCRegister.h:89
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:29
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition: MCRegister.h:65
constexpr bool operator==(unsigned Other) const
Comparisons against register constants.
Definition: MCRegister.h:86
static constexpr unsigned FirstStackSlot
Definition: MCRegister.h:45
constexpr bool operator==(int Other) const
Definition: MCRegister.h:88
constexpr bool operator!=(const MCRegister &Other) const
Definition: MCRegister.h:78
friend hash_code hash_value(const MCRegister &)
Definition: MCRegister.h:115
constexpr bool operator==(MCPhysReg Other) const
Definition: MCRegister.h:91
static constexpr unsigned VirtualRegFlag
Definition: MCRegister.h:46
constexpr bool operator!=(unsigned Other) const
Definition: MCRegister.h:87
constexpr unsigned id() const
Definition: MCRegister.h:70
An opaque object representing a hash code.
Definition: Hashing.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
hash_code hash_value(const FixedPointSemantics &Val)
Definition: APFixedPoint.h:128
Expected< ExpressionValue > max(const ExpressionValue &Lhs, const ExpressionValue &Rhs)
Definition: FileCheck.cpp:334
static unsigned getEmptyKey()
Definition: MCRegister.h:101
static bool isEqual(const MCRegister &LHS, const MCRegister &RHS)
Definition: MCRegister.h:110
static unsigned getHashValue(const MCRegister &Val)
Definition: MCRegister.h:107
static unsigned getTombstoneKey()
Definition: MCRegister.h:104
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:51