LLVM 24.0.0git
PISARegManager.cpp
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 implements management of PISA virtual registers.
11///
12//===----------------------------------------------------------------------===//
13
14#include "PISARegManager.h"
15#include "PISAInstrInfo.h"
16#include "PISASubtarget.h"
19
20using namespace llvm;
21using namespace PISA;
22
23void RegManager::computeMapping() {
24 std::array<unsigned, RegType::NUM_TYPE> Count{};
25 const PISAInstrInfo *TII = MF.getSubtarget<PISASubtarget>().getInstrInfo();
26 for (const MachineBasicBlock &MBB : MF) {
27 for (const MachineInstr &MI : MBB) {
28 for (const MachineOperand &MO : MI.operands()) {
29 if (!MO.isReg() || (!MO.isDef() && !MO.isUndef()))
30 continue;
31
32 Register CurReg = MO.getReg();
33
34 if (CurReg.isPhysical())
35 continue;
36
37 if (Mapping.count(CurReg) != 0)
38 continue;
39
40 unsigned Flags = Usage::None;
41 if (TII->isNoEmissionInstr(MI))
43
44 RegType Type = getRegType(MRI.getRegClass(MO.getReg()));
45 RegInfo Info{Type, Count[Type]++, static_cast<Usage>(Flags)};
46 Mapping[CurReg] = Info;
47 }
48 }
49 }
50}
51
52unsigned RegManager::getRegIdx(Register Reg) const {
53 MappingTy::const_iterator I = Mapping.find(Reg);
54 assert(I != Mapping.end() && "missing?");
55 return I->second.Idx;
56}
57
59 const MachineRegisterInfo &MRI = MF.getRegInfo();
60 unsigned Idx = getRegIdx(Reg);
61 RegType Type = getRegType(MRI.getRegClass(Reg));
64}
65
67 : MF(MF), MRI(MF.getRegInfo()) {
68 computeMapping();
69}
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock & MBB
IRTranslator LLVM IR MI
#define I(x, y, z)
Definition MD5.cpp:57
Promote Memory to Register
Definition Mem2Reg.cpp:110
This file declares instruction information for the PISA target.
This file declares management of PISA virtual registers.
This file declares the PISA subtarget.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
typename SmallVector< std::pair< Register, RegInfo >, 0 >::const_iterator const_iterator
Definition MapVector.h:46
static unsigned encodeVirtualRegisterIndex(unsigned Idx, RegBank Bank, RegType Type)
static RegEncoder::RegType getRegType(uint8_t EncodedBits)
unsigned getRegIdx(Register Reg) const
RegManager(const MachineFunction &MF)
unsigned encodeVirtualRegister(RegBank Bank, Register Reg) const
Wrapper class representing virtual and physical registers.
Definition Register.h:20
static Register index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
Definition Register.h:72
constexpr bool isPhysical() const
Return true if the specified register number is in the physical register namespace.
Definition Register.h:83
The instances of the Type class are immutable: once they are created, they are never changed.
Definition Type.h:46
This is an optimization pass for GlobalISel generic memory operations.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Count
Definition InstrProf.h:145