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
18using namespace llvm;
19
20/// Removes all aliases aren't inside any of the
21/// desired Chunks.
22void llvm::reduceAliasesDeltaPass(Oracle &O, ReducerWorkItem &Program) {
23 for (auto &GA : make_early_inc_range(Range: Program.getModule().aliases())) {
24 if (!O.shouldKeep()) {
25 GA.replaceAllUsesWith(V: GA.getAliasee());
26 GA.eraseFromParent();
27 }
28 }
29}
30
31void 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(x: &GI);
38 }
39
40 if (!IFuncs.empty())
41 lowerGlobalIFuncUsersAsGlobalCtor(M&: Mod, IFuncsToLower: IFuncs);
42}
43