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 "Delta.h"
16#include "llvm/CodeGen/MachineModuleInfo.h"
17#include "llvm/CodeGen/MachineRegisterInfo.h"
18
19using namespace llvm;
20
21static void dropRegisterHintsFromFunction(Oracle &O, MachineFunction &MF) {
22 MachineRegisterInfo &MRI = MF.getRegInfo();
23 for (unsigned I = 0, E = MRI.getNumVirtRegs(); I != E; ++I) {
24 Register Reg = Register::index2VirtReg(Index: I);
25
26 const std::pair<unsigned, SmallVector<Register, 4>> &Hints =
27 MRI.getRegAllocationHints(VReg: Reg);
28 if (Hints.second.empty())
29 continue;
30
31 if (!O.shouldKeep())
32 MRI.clearSimpleHint(VReg: Reg);
33 }
34}
35
36static void dropRegisterHintsFromFunctions(Oracle &O,
37 ReducerWorkItem &WorkItem) {
38 for (const Function &F : WorkItem.getModule()) {
39 if (auto *MF = WorkItem.MMI->getMachineFunction(F))
40 dropRegisterHintsFromFunction(O, MF&: *MF);
41 }
42}
43
44void llvm::reduceVirtualRegisterHintsDeltaPass(TestRunner &Test) {
45 runDeltaPass(Test, ExtractChunksFromModule: dropRegisterHintsFromFunctions,
46 Message: "Reducing virtual register hints from functions");
47}
48

source code of llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp