1 //===- ReduceRegisterUses.cpp - Specialized Delta Pass --------------------===//
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
7 //===----------------------------------------------------------------------===//
9 // This file implements a function which calls the Generic Delta pass in order
10 // to reduce uninteresting register uses from the MachineFunction.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceRegisterUses.h"
15 #include "llvm/CodeGen/MachineFunction.h"
16 #include "llvm/CodeGen/MachineModuleInfo.h"
17 #include "llvm/CodeGen/MachineRegisterInfo.h"
21 static void removeUsesFromFunction(Oracle
&O
, MachineFunction
&MF
) {
22 MachineRegisterInfo
&MRI
= MF
.getRegInfo();
24 for (MachineBasicBlock
&MBB
: MF
) {
25 for (MachineInstr
&MI
: MBB
) {
26 // Generic instructions are not supposed to have undef operands.
27 if (isPreISelGenericOpcode(MI
.getOpcode()))
30 int NumOperands
= MI
.getNumOperands();
31 int NumRequiredOps
= MI
.getNumExplicitOperands() +
32 MI
.getDesc().implicit_defs().size() +
33 MI
.getDesc().implicit_uses().size();
35 for (int I
= NumOperands
- 1; I
>= 0; --I
) {
36 MachineOperand
&MO
= MI
.getOperand(I
);
37 if (!MO
.isReg() || !MO
.readsReg())
40 Register Reg
= MO
.getReg();
41 if (Reg
.isPhysical() && MRI
.isReserved(Reg
))
47 // Remove implicit operands. If the register is part of the fixed
48 // operand list, set to undef.
49 if (I
>= NumRequiredOps
)
58 static void removeUsesFromModule(Oracle
&O
, ReducerWorkItem
&WorkItem
) {
59 for (const Function
&F
: WorkItem
.getModule()) {
60 if (auto *MF
= WorkItem
.MMI
->getMachineFunction(F
))
61 removeUsesFromFunction(O
, *MF
);
65 void llvm::reduceRegisterUsesMIRDeltaPass(TestRunner
&Test
) {
66 runDeltaPass(Test
, removeUsesFromModule
, "Reducing register uses");