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