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