1 //===- ReduceIRReferences.cpp - Specialized Delta Pass --------------------===//
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
7 //===----------------------------------------------------------------------===//
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.
13 //===----------------------------------------------------------------------===//
15 #include "ReduceIRReferences.h"
17 #include "llvm/CodeGen/MachineFrameInfo.h"
18 #include "llvm/CodeGen/MachineFunction.h"
19 #include "llvm/CodeGen/MachineModuleInfo.h"
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 (isa
<const Value
*>(MMO
->getPointerInfo().V
))
31 MMO
->setValue(static_cast<const Value
*>(nullptr));
34 // TODO: Try to remove GlobalValue references and metadata
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
);
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
) {
52 MBB
.clearBasicBlock();
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();
65 MFI
.clearObjectAllocation(I
);
71 void llvm::reduceIRInstructionReferencesDeltaPass(TestRunner
&Test
) {
72 runDeltaPass(Test
, stripIRFromInstructions
,
73 "Reducing IR references from instructions");
76 void llvm::reduceIRBlockReferencesDeltaPass(TestRunner
&Test
) {
77 runDeltaPass(Test
, stripIRFromBlocks
, "Reducing IR references from blocks");
80 void llvm::reduceIRFunctionReferencesDeltaPass(TestRunner
&Test
) {
81 runDeltaPass(Test
, stripIRFromFunctions
,
82 "Reducing IR references from functions");