Debian Codegraph @

llvm/tools/llvm-reduce/deltas/ReduceAliases.cpp

raw
1 //===- ReduceAliases.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 reduce aliases in the provided Module.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #include "ReduceAliases.h"
15 #include "llvm/IR/GlobalValue.h"
16 #include "llvm/Transforms/Utils/ModuleUtils.h"
17
18 using namespace llvm;
19
20 /// Removes all aliases aren't inside any of the
21 /// desired Chunks.
22 void llvm::reduceAliasesDeltaPass(Oracle &O, ReducerWorkItem &Program) {
23 for (auto &GA : make_early_inc_range(Program.getModule().aliases())) {
24 if (!O.shouldKeep()) {
25 GA.replaceAllUsesWith(GA.getAliasee());
26 GA.eraseFromParent();
27 }
28 }
29 }
30
31 void llvm::reduceIFuncsDeltaPass(Oracle &O, ReducerWorkItem &WorkItem) {
32 Module &Mod = WorkItem.getModule();
33
34 std::vector<GlobalIFunc *> IFuncs;
35 for (GlobalIFunc &GI : Mod.ifuncs()) {
36 if (!O.shouldKeep())
37 IFuncs.push_back(&GI);
38 }
39
40 if (!IFuncs.empty())
41 lowerGlobalIFuncUsersAsGlobalCtor(Mod, IFuncs);
42 }