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