1 //===- ReduceIRReferences.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 remove backreferences to the IR from MIR. In particular, this will remove 11 // the Value references in MachineMemOperands. 12 // 13 //===----------------------------------------------------------------------===// 14 15 #include "ReduceIRReferences.h" 16 #include "Delta.h" 17 #include "llvm/CodeGen/MachineFrameInfo.h" 18 19 using namespace llvm; 20 21 static void dropIRReferencesFromInstructions(Oracle &O, MachineFunction &MF) { 22 for (MachineBasicBlock &MBB : MF) { 23 for (MachineInstr &MI : MBB) { 24 if (!O.shouldKeep()) { 25 for (MachineMemOperand *MMO : MI.memoperands()) { 26 // Leave behind pseudo source values. 27 // TODO: Removing all MemOperand values is a further reduction step. 28 if (MMO->getPointerInfo().V.is<const Value *>()) 29 MMO->setValue(static_cast<const Value *>(nullptr)); 30 } 31 32 // TODO: Try to remove GlobalValue references and metadata 33 } 34 } 35 } 36 } 37 38 static void stripIRFromInstructions(Oracle &O, ReducerWorkItem &WorkItem) { 39 for (const Function &F : WorkItem.getModule()) { 40 if (auto *MF = WorkItem.MMI->getMachineFunction(F)) 41 dropIRReferencesFromInstructions(O, *MF); 42 } 43 } 44 45 static void stripIRFromBlocks(Oracle &O, ReducerWorkItem &WorkItem) { 46 for (const Function &F : WorkItem.getModule()) { 47 if (auto *MF = WorkItem.MMI->getMachineFunction(F)) { 48 for (MachineBasicBlock &MBB : *MF) { 49 if (!O.shouldKeep()) 50 MBB.clearBasicBlock(); 51 } 52 } 53 } 54 } 55 56 static void stripIRFromFunctions(Oracle &O, ReducerWorkItem &WorkItem) { 57 for (const Function &F : WorkItem.getModule()) { 58 if (!O.shouldKeep()) { 59 if (auto *MF = WorkItem.MMI->getMachineFunction(F)) { 60 MachineFrameInfo &MFI = MF->getFrameInfo(); 61 for (int I = MFI.getObjectIndexBegin(), E = MFI.getObjectIndexEnd(); 62 I != E; ++I) 63 MFI.clearObjectAllocation(I); 64 } 65 } 66 } 67 } 68 69 void llvm::reduceIRInstructionReferencesDeltaPass(TestRunner &Test) { 70 outs() << "*** Reducing IR references from instructions...\n"; 71 runDeltaPass(Test, stripIRFromInstructions); 72 } 73 74 void llvm::reduceIRBlockReferencesDeltaPass(TestRunner &Test) { 75 outs() << "*** Reducing IR references from blocks...\n"; 76 runDeltaPass(Test, stripIRFromBlocks); 77 } 78 79 void llvm::reduceIRFunctionReferencesDeltaPass(TestRunner &Test) { 80 outs() << "*** Reducing IR references from functions...\n"; 81 runDeltaPass(Test, stripIRFromFunctions); 82 } 83