LLVM 22.0.0git
Registers.h
Go to the documentation of this file.
1//===----------------------------------------------------------------------===//
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/// \file
10/// This file contains helper functions to find and list registers that are
11/// tracked by the unwinding information checker.
12///
13//===----------------------------------------------------------------------===//
14
15#ifndef LLVM_DWARFCFICHECKER_REGISTERS_H
16#define LLVM_DWARFCFICHECKER_REGISTERS_H
17
18#include "llvm/MC/MCRegister.h"
20
21namespace llvm {
22
23/// This analysis only keeps track and cares about super registers, not the
24/// subregisters. All reads from/writes to subregisters are considered the
25/// same operation to super registers.
26inline bool isSuperReg(const MCRegisterInfo *MCRI, MCRegister Reg) {
27 return MCRI->superregs(Reg).empty();
28}
29
31 SmallVector<MCPhysReg> SuperRegs;
32 for (auto &&RegClass : MCRI->regclasses())
33 for (unsigned I = 0; I < RegClass.getNumRegs(); I++) {
34 MCRegister Reg = RegClass.getRegister(I);
35 if (isSuperReg(MCRI, Reg))
36 SuperRegs.push_back(Reg.id());
37 }
38
39 sort(SuperRegs.begin(), SuperRegs.end());
40 SuperRegs.erase(llvm::unique(SuperRegs), SuperRegs.end());
41 return SuperRegs;
42}
43
45 SmallVector<MCPhysReg> TrackingRegs;
46 for (auto Reg : getSuperRegs(MCRI))
47 if (!MCRI->isArtificial(Reg) && !MCRI->isConstant(Reg))
48 TrackingRegs.push_back(Reg);
49 return TrackingRegs;
50}
51
53 if (isSuperReg(MCRI, Reg))
54 return Reg;
55 for (auto SuperReg : MCRI->superregs(Reg))
56 if (isSuperReg(MCRI, SuperReg))
57 return SuperReg;
58
59 llvm_unreachable("Should either be a super reg, or have a super reg");
60}
61
62} // namespace llvm
63
64#endif
#define I(x, y, z)
Definition MD5.cpp:57
Register Reg
MCRegisterInfo base class - We assume that the target defines a static array of MCRegisterDesc object...
iterator_range< regclass_iterator > regclasses() const
iterator_range< MCSuperRegIterator > superregs(MCRegister Reg) const
Return an iterator range over all super-registers of Reg, excluding Reg.
bool isConstant(MCRegister RegNo) const
Returns true if the given register is constant.
bool isArtificial(MCRegister RegNo) const
Returns true if the given register is artificial, which means it represents a regunit that is not sep...
Wrapper class representing physical registers. Should be passed by value.
Definition MCRegister.h:33
iterator erase(const_iterator CI)
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
SmallVector< MCPhysReg > getTrackingRegs(const MCRegisterInfo *MCRI)
Definition Registers.h:44
auto unique(Range &&R, Predicate P)
Definition STLExtras.h:2076
void sort(IteratorTy Start, IteratorTy End)
Definition STLExtras.h:1622
SmallVector< MCPhysReg > getSuperRegs(const MCRegisterInfo *MCRI)
Definition Registers.h:30
MCRegister getSuperReg(const MCRegisterInfo *MCRI, MCRegister Reg)
Definition Registers.h:52
bool isSuperReg(const MCRegisterInfo *MCRI, MCRegister Reg)
This analysis only keeps track and cares about super registers, not the subregisters.
Definition Registers.h:26