Debian Codegraph @

llvm-project/llvm/tools/llvm-reduce/deltas/ReduceVirtualRegisters.cpp

raw
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
19 using namespace llvm;
20
21 static 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(I);
25
26 const std::pair<Register, SmallVector<Register, 4>> &Hints =
27 MRI.getRegAllocationHints(Reg);
28 if (Hints.second.empty())
29 continue;
30
31 if (!O.shouldKeep())
32 MRI.clearSimpleHint(Reg);
33 }
34 }
35
36 static 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);
41 }
42 }
43
44 void llvm::reduceVirtualRegisterHintsDeltaPass(TestRunner &Test) {
45 runDeltaPass(Test, dropRegisterHintsFromFunctions,
46 "Reducing virtual register hints from functions");
47 }