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(Oracle
&O
, Module
&Program
) {
21 std::vector
<Instruction
*> InitInstToKeep
;
23 for (auto &F
: Program
)
25 // Removing the terminator would make the block invalid. Only iterate over
26 // instructions before the terminator.
27 InitInstToKeep
.push_back(BB
.getTerminator());
28 for (auto &Inst
: make_range(BB
.begin(), std::prev(BB
.end())))
30 InitInstToKeep
.push_back(&Inst
);
33 // We create a vector first, then convert it to a set, so that we don't have
34 // to pay the cost of rebalancing the set frequently if the order we insert
35 // the elements doesn't match the order they should appear inside the set.
36 std::set
<Instruction
*> InstToKeep(InitInstToKeep
.begin(),
37 InitInstToKeep
.end());
39 std::vector
<Instruction
*> InstToDelete
;
40 for (auto &F
: Program
)
43 if (!InstToKeep
.count(&Inst
)) {
44 Inst
.replaceAllUsesWith(UndefValue::get(Inst
.getType()));
45 InstToDelete
.push_back(&Inst
);
48 for (auto &I
: InstToDelete
)
52 void llvm::reduceInstructionsDeltaPass(TestRunner
&Test
) {
53 outs() << "*** Reducing Instructions...\n";
54 runDeltaPass(Test
, extractInstrFromModule
);