[clang] Propagate -ftime-report to offload lto (#122143)
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / ReduceRegisterUses.cpp
bloba608935736d1a42f20936a7dd5108de6582fe619
1 //===- ReduceRegisterUses.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 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"
19 using namespace llvm;
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()))
28 continue;
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())
38 continue;
40 Register Reg = MO.getReg();
41 if (Reg.isPhysical() && MRI.isReserved(Reg))
42 continue;
44 if (O.shouldKeep())
45 continue;
47 // Remove implicit operands. If the register is part of the fixed
48 // operand list, set to undef.
49 if (I >= NumRequiredOps)
50 MI.removeOperand(I);
51 else
52 MO.setIsUndef();
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");