Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / ReduceVirtualRegisters.cpp
blob2b97e65bbf0938df62d6dd2aa53d4b81ddc74b6c
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.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceVirtualRegisters.h"
15 #include "Delta.h"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
19 using namespace llvm;
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);
26 const std::pair<unsigned, SmallVector<Register, 4>> &Hints =
27 MRI.getRegAllocationHints(Reg);
28 if (Hints.second.empty())
29 continue;
31 if (!O.shouldKeep())
32 MRI.clearSimpleHint(Reg);
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);
44 void llvm::reduceVirtualRegisterHintsDeltaPass(TestRunner &Test) {
45 runDeltaPass(Test, dropRegisterHintsFromFunctions,
46 "Reducing virtual register hints from functions");