1 //===- ReduceArguments.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 reduce uninteresting Arguments from defined functions.
12 //===----------------------------------------------------------------------===//
14 #include "ReduceInstructions.h"
18 /// Removes out-of-chunk arguments from functions, and modifies their calls
19 /// accordingly. It also removes allocations of out-of-chunk arguments.
20 static void extractInstrFromModule(std::vector
<Chunk
> ChunksToKeep
,
22 int I
= 0, InstCount
= 0;
23 std::set
<Instruction
*> InstToKeep
;
25 for (auto &F
: *Program
)
28 if (I
< (int)ChunksToKeep
.size()) {
29 if (ChunksToKeep
[I
].contains(++InstCount
))
30 InstToKeep
.insert(&Inst
);
31 if (ChunksToKeep
[I
].end
== InstCount
)
35 std::vector
<Instruction
*> InstToDelete
;
36 for (auto &F
: *Program
)
39 if (!InstToKeep
.count(&Inst
)) {
40 Inst
.replaceAllUsesWith(UndefValue::get(Inst
.getType()));
41 InstToDelete
.push_back(&Inst
);
44 for (auto &I
: InstToDelete
)
48 /// Counts the amount of basic blocks and prints their name & respective index
49 static unsigned countInstructions(Module
*Program
) {
50 // TODO: Silence index with --quiet flag
51 outs() << "----------------------------\n";
53 for (auto &F
: *Program
)
55 InstCount
+= BB
.getInstList().size();
56 outs() << "Number of instructions: " << InstCount
<< "\n";
61 void llvm::reduceInstructionsDeltaPass(TestRunner
&Test
) {
62 outs() << "*** Reducing Insructions...\n";
63 unsigned InstCount
= countInstructions(Test
.getProgram());
64 runDeltaPass(Test
, InstCount
, extractInstrFromModule
);