1//===- ReduceVirtualRegisters.cpp - Specialized Delta Pass ----------------===//
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// This file implements a function which calls the Generic Delta pass in order
10// to simplify virtual registers in MIR.
11//
12//===----------------------------------------------------------------------===//
13
14#include "ReduceVirtualRegisters.h"
15#include "llvm/CodeGen/MachineModuleInfo.h"
16#include "llvm/CodeGen/MachineRegisterInfo.h"
17
18using namespace llvm;
19
20static void dropRegisterHintsFromFunction(Oracle &O, MachineFunction &MF) {
21 MachineRegisterInfo &MRI = MF.getRegInfo();
22 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
23 Register Reg = Register::index2VirtReg(Index: I);
24
25 const std::pair<unsigned, SmallVector<Register, 4>> *Hints =
26 MRI.getRegAllocationHints(VReg: Reg);
27 if (!Hints || Hints->second.empty())
28 continue;
29
30 if (!O.shouldKeep())
31 MRI.clearSimpleHint(VReg: Reg);
32 }
33}
34
35void llvm::reduceVirtualRegisterHintsDeltaPass(Oracle &O,
36 ReducerWorkItem &WorkItem) {
37 for (const Function &F : WorkItem.getModule()) {
38 if (auto *MF = WorkItem.MMI->getMachineFunction(F))
39 dropRegisterHintsFromFunction(O, MF&: *MF);
40 }
41}
42