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 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 bool isPhysicalRegister(unsigned Reg) {
59 return FirstPhysicalReg <= Reg && Reg < FirstStackSlot;
60 }
61
62 constexpr operator unsigned() const {
63 return Reg;
64 }
65
66 /// Check the provided unsigned value is a valid MCRegister.
67 static MCRegister from(unsigned Val) {
68 assert(Val == NoRegister || isPhysicalRegister(Val));
69 return MCRegister(Val);
70 }
71
72 unsigned id() const {
73 return Reg;
74 }
75
76 bool isValid() const { return Reg != NoRegister; }
77
78 /// Comparisons between register objects
79 bool operator==(const MCRegister &Other) const { return Reg == Other.Reg; }
80 bool operator!=(const MCRegister &Other) const { return Reg != Other.Reg; }
81
82 /// Comparisons against register constants. E.g.
83 /// * R == AArch64::WZR
84 /// * R == 0
85 /// * R == VirtRegMap::NO_PHYS_REG
86 bool operator==(unsigned Other) const { return Reg == Other; }
87 bool operator!=(unsigned Other) const { return Reg != Other; }
88 bool operator==(int Other) const { return Reg == unsigned(Other); }
89 bool operator!=(int Other) const { return Reg != unsigned(Other); }
90 // MSVC requires that we explicitly declare these two as well.
91 bool operator==(MCPhysReg Other) const { return Reg == unsigned(Other); }
92 bool operator!=(MCPhysReg Other) const { return Reg != unsigned(Other); }
93};
94
95// Provide DenseMapInfo for MCRegister
96template<> struct DenseMapInfo<MCRegister> {
97 static inline unsigned getEmptyKey() {
99 }
100 static inline unsigned getTombstoneKey() {
102 }
103 static unsigned getHashValue(const MCRegister &Val) {
105 }
106 static bool isEqual(const MCRegister &LHS, const MCRegister &RHS) {
107 return DenseMapInfo<unsigned>::isEqual(LHS.id(), RHS.id());
108 }
109};
110
112 return hash_value(Reg.id());
113}
114}
115
116#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
bool operator!=(MCPhysReg Other) const
Definition: MCRegister.h:92
static constexpr unsigned FirstPhysicalReg
Definition: MCRegister.h:44
static constexpr unsigned NoRegister
Definition: MCRegister.h:43
bool operator!=(int Other) const
Definition: MCRegister.h:89
bool operator==(MCPhysReg Other) const
Definition: MCRegister.h:91
static bool isStackSlot(unsigned Reg)
This is the portion of the positive number space that is not a physical register.
Definition: MCRegister.h:52
constexpr MCRegister(unsigned Val=0)
Definition: MCRegister.h:29
bool operator!=(const MCRegister &Other) const
Definition: MCRegister.h:80
unsigned id() const
Definition: MCRegister.h:72
static MCRegister from(unsigned Val)
Check the provided unsigned value is a valid MCRegister.
Definition: MCRegister.h:67
static constexpr unsigned FirstStackSlot
Definition: MCRegister.h:45
bool operator!=(unsigned Other) const
Definition: MCRegister.h:87
bool operator==(int Other) const
Definition: MCRegister.h:88
static bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition: MCRegister.h:58
bool isValid() const
Definition: MCRegister.h:76
friend hash_code hash_value(const MCRegister &)
Definition: MCRegister.h:111
bool operator==(const MCRegister &Other) const
Comparisons between register objects.
Definition: MCRegister.h:79
static constexpr unsigned VirtualRegFlag
Definition: MCRegister.h:46
bool operator==(unsigned Other) const
Comparisons against register constants.
Definition: MCRegister.h:86
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:337
static unsigned getEmptyKey()
Definition: MCRegister.h:97
static bool isEqual(const MCRegister &LHS, const MCRegister &RHS)
Definition: MCRegister.h:106
static unsigned getHashValue(const MCRegister &Val)
Definition: MCRegister.h:103
static unsigned getTombstoneKey()
Definition: MCRegister.h:100
An information struct used to provide DenseMap with the various necessary components for a given valu...
Definition: DenseMapInfo.h:51