LLVM 24.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 and target specific virtual
41/// registers. Should be passed by value.
43 friend hash_code hash_value(const MCRegister &);
44 unsigned Reg;
45
46public:
47 constexpr MCRegister(unsigned Val = 0) : Reg(Val) {}
48
49 // Register numbers can represent physical registers and virtual registers
50 // used after codegen by some targets (SPIRV and WebAssembly).
51 // The unsigned values are divided into these ranges:
52 //
53 // 0 Not a register, can be used as a sentinel.
54 // [1;2^30) Physical registers assigned by TableGen.
55 // [2^30;2^31) Hole for stack slots in CodeGen's Register type.
56 // [2^31;2^32) Target specific virtual registers after codegen.
57 //
58 // Further sentinels can be allocated from the small negative integers.
59 // DenseMapInfo<unsigned> uses -1u and -2u.
60 static_assert(std::numeric_limits<decltype(Reg)>::max() >= 0xFFFFFFFF,
61 "Reg isn't large enough to hold full range.");
62 static constexpr unsigned NoRegister = 0u;
63 static constexpr unsigned FirstPhysicalReg = 1u;
64 static constexpr unsigned LastPhysicalReg = (1u << 30) - 1;
65 static constexpr unsigned TargetVirtualRegFlag = 1u << 31;
66
67 /// Return true if the specified register number is in
68 /// the physical register namespace.
69 static constexpr bool isPhysicalRegister(unsigned Reg) {
70 return FirstPhysicalReg <= Reg && Reg <= LastPhysicalReg;
71 }
72
73 /// Return true if the specified register number is in the physical register
74 /// namespace.
75 constexpr bool isPhysical() const { return isPhysicalRegister(Reg); }
76
77 constexpr operator unsigned() const { return Reg; }
78
79 /// Check-convert the provided unsigned value to an MCRegister.
80 static constexpr MCRegister from(unsigned Val) {
81 assert(Val == NoRegister || isPhysicalRegister(Val));
82 return MCRegister(Val);
83 }
84
85 constexpr unsigned id() const { return Reg; }
86
87 constexpr bool isValid() const { return Reg != NoRegister; }
88
89 /// Comparisons between register objects
90 constexpr bool operator==(const MCRegister &Other) const {
91 return Reg == Other.Reg;
92 }
93 constexpr bool operator!=(const MCRegister &Other) const {
94 return Reg != Other.Reg;
95 }
96
97 /// Comparisons against register constants. E.g.
98 /// * R == AArch64::WZR
99 /// * R == 0
100 constexpr bool operator==(unsigned Other) const { return Reg == Other; }
101 constexpr bool operator!=(unsigned Other) const { return Reg != Other; }
102 constexpr bool operator==(int Other) const { return Reg == unsigned(Other); }
103 constexpr bool operator!=(int Other) const { return Reg != unsigned(Other); }
104 // MSVC requires that we explicitly declare these two as well.
105 constexpr bool operator==(MCPhysReg Other) const {
106 return Reg == unsigned(Other);
107 }
108 constexpr bool operator!=(MCPhysReg Other) const {
109 return Reg != unsigned(Other);
110 }
111};
112
113// Provide DenseMapInfo for MCRegister
114template <> struct DenseMapInfo<MCRegister> {
115 static unsigned getHashValue(const MCRegister &Val) {
117 }
118 static bool isEqual(const MCRegister &LHS, const MCRegister &RHS) {
119 return LHS == RHS;
120 }
121};
122
123inline hash_code hash_value(const MCRegister &Reg) {
124 return hash_value(Reg.id());
125}
126} // namespace llvm
127
128#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 and target specific virtual registers.
Definition MCRegister.h:42
constexpr bool isValid() const
Definition MCRegister.h:87
static constexpr unsigned LastPhysicalReg
Definition MCRegister.h:64
static constexpr unsigned FirstPhysicalReg
Definition MCRegister.h:63
constexpr bool operator==(const MCRegister &Other) const
Comparisons between register objects.
Definition MCRegister.h:90
constexpr bool operator!=(MCPhysReg Other) const
Definition MCRegister.h:108
static constexpr unsigned NoRegister
Definition MCRegister.h:62
constexpr bool operator!=(int Other) const
Definition MCRegister.h:103
static constexpr bool isPhysicalRegister(unsigned Reg)
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:69
constexpr MCRegister(unsigned Val=0)
Definition MCRegister.h:47
static constexpr MCRegister from(unsigned Val)
Check-convert the provided unsigned value to an MCRegister.
Definition MCRegister.h:80
constexpr bool operator==(unsigned Other) const
Comparisons against register constants.
Definition MCRegister.h:100
constexpr bool operator==(int Other) const
Definition MCRegister.h:102
friend hash_code hash_value(const MCRegister &)
Definition MCRegister.h:123
constexpr bool operator!=(const MCRegister &Other) const
Definition MCRegister.h:93
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition MCRegister.h:75
constexpr bool operator==(MCPhysReg Other) const
Definition MCRegister.h:105
constexpr bool operator!=(unsigned Other) const
Definition MCRegister.h:101
static constexpr unsigned TargetVirtualRegFlag
Definition MCRegister.h:65
constexpr unsigned id() const
Definition MCRegister.h:85
An opaque object representing a hash code.
Definition Hashing.h:77
This is an optimization pass for GlobalISel generic memory operations.
hash_code hash_value(const FixedPointSemantics &Val)
@ Other
Any other memory.
Definition ModRef.h:68
constexpr NextUseDistance max(NextUseDistance A, NextUseDistance B)
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:118
static unsigned getHashValue(const MCRegister &Val)
Definition MCRegister.h:115
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