Path: blob/main/contrib/llvm-project/llvm/lib/DWARFCFIChecker/Registers.h
213766 views
//===----------------------------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7///8/// \file9/// This file contains helper functions to find and list registers that are10/// tracked by the unwinding information checker.11///12//===----------------------------------------------------------------------===//1314#ifndef LLVM_DWARFCFICHECKER_REGISTERS_H15#define LLVM_DWARFCFICHECKER_REGISTERS_H1617#include "llvm/MC/MCRegister.h"18#include "llvm/MC/MCRegisterInfo.h"19#include <iterator>2021namespace llvm {2223/// This analysis only keeps track and cares about super registers, not the24/// subregisters. All reads from/writes to subregisters are considered the25/// same operation to super registers.26inline bool isSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg) {27return MCRI->superregs(Reg).empty();28}2930inline SmallVector<MCPhysReg> getSuperRegs(const MCRegisterInfo *MCRI) {31SmallVector<MCPhysReg> SuperRegs;32for (auto &&RegClass : MCRI->regclasses())33for (unsigned I = 0; I < RegClass.getNumRegs(); I++) {34MCPhysReg Reg = RegClass.getRegister(I);35if (isSuperReg(MCRI, Reg))36SuperRegs.push_back(Reg);37}3839sort(SuperRegs.begin(), SuperRegs.end());40SuperRegs.erase(llvm::unique(SuperRegs), SuperRegs.end());41return SuperRegs;42}4344inline SmallVector<MCPhysReg> getTrackingRegs(const MCRegisterInfo *MCRI) {45SmallVector<MCPhysReg> TrackingRegs;46for (auto Reg : getSuperRegs(MCRI))47if (!MCRI->isArtificial(Reg) && !MCRI->isConstant(Reg))48TrackingRegs.push_back(Reg);49return TrackingRegs;50}5152inline MCPhysReg getSuperReg(const MCRegisterInfo *MCRI, MCPhysReg Reg) {53if (isSuperReg(MCRI, Reg))54return Reg;55for (auto SuperReg : MCRI->superregs(Reg))56if (isSuperReg(MCRI, SuperReg))57return SuperReg;5859llvm_unreachable("Should either be a super reg, or have a super reg");60}6162} // namespace llvm6364#endif656667