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#include <iterator>
21
22namespace llvm {
23
24/// This analysis only keeps track and cares about super registers, not the
25/// subregisters. All reads from/writes to subregisters are considered the
26/// same operation to super registers.
27inline bool isSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg) {
28 return MCRI->superregs(Reg).empty();
29}
30
32 SmallVector<MCPhysReg> SuperRegs;
33 for (auto &&RegClass : MCRI->regclasses())
34 for (unsigned I = 0; I < RegClass.getNumRegs(); I++) {
35 MCPhysReg Reg = RegClass.getRegister(I);
36 if (isSuperReg(MCRI, Reg))
37 SuperRegs.push_back(Reg);
38 }
39
40 sort(SuperRegs.begin(), SuperRegs.end());
41 SuperRegs.erase(llvm::unique(SuperRegs), SuperRegs.end());
42 return SuperRegs;
43}
44
46 SmallVector<MCPhysReg> TrackingRegs;
47 for (auto Reg : getSuperRegs(MCRI))
48 if (!MCRI->isArtificial(Reg) && !MCRI->isConstant(Reg))
49 TrackingRegs.push_back(Reg);
50 return TrackingRegs;
51}
52
54 if (isSuperReg(MCRI, Reg))
55 return Reg;
56 for (auto SuperReg : MCRI->superregs(Reg))
57 if (isSuperReg(MCRI, SuperReg))
58 return SuperReg;
59
60 llvm_unreachable("Should either be a super reg, or have a super reg");
61}
62
63} // namespace llvm
64
65#endif
#define I(x, y, z)
Definition: MD5.cpp:58
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...
iterator erase(const_iterator CI)
Definition: SmallVector.h:738
void push_back(const T &Elt)
Definition: SmallVector.h:414
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1197
#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.
Definition: AddressRanges.h:18
SmallVector< MCPhysReg > getTrackingRegs(const MCRegisterInfo *MCRI)
Definition: Registers.h:45
auto unique(Range &&R, Predicate P)
Definition: STLExtras.h:2095
MCPhysReg getSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg)
Definition: Registers.h:53
void sort(IteratorTy Start, IteratorTy End)
Definition: STLExtras.h:1669
SmallVector< MCPhysReg > getSuperRegs(const MCRegisterInfo *MCRI)
Definition: Registers.h:31
bool isSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg)
This analysis only keeps track and cares about super registers, not the subregisters.
Definition: Registers.h:27