brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · e5851a2 Raw
65 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8///9/// \file10/// This file contains helper functions to find and list registers that are11/// tracked by the unwinding information checker.12///13//===----------------------------------------------------------------------===//14 15#ifndef LLVM_DWARFCFICHECKER_REGISTERS_H16#define LLVM_DWARFCFICHECKER_REGISTERS_H17 18#include "llvm/MC/MCRegister.h"19#include "llvm/MC/MCRegisterInfo.h"20 21namespace llvm {22 23/// 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, MCRegister Reg) {27  return MCRI->superregs(Reg).empty();28}29 30inline SmallVector<MCPhysReg> getSuperRegs(const MCRegisterInfo *MCRI) {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 44inline SmallVector<MCPhysReg> getTrackingRegs(const MCRegisterInfo *MCRI) {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 52inline MCRegister getSuperReg(const MCRegisterInfo *MCRI, MCRegister Reg) {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 llvm63 64#endif65