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 "Delta.h"
16#include "Utils.h"
17#include "llvm/IR/Constants.h"
18#include "llvm/IR/GlobalValue.h"
19#include "llvm/Transforms/Utils/ModuleUtils.h"
20
21using namespace llvm;
22
23/// Removes all aliases aren't inside any of the
24/// desired Chunks.
25static void extractAliasesFromModule(Oracle &O, ReducerWorkItem &Program) {
26 for (auto &GA : make_early_inc_range(Range: Program.getModule().aliases())) {
27 if (!O.shouldKeep()) {
28 GA.replaceAllUsesWith(V: GA.getAliasee());
29 GA.eraseFromParent();
30 }
31 }
32}
33
34static void extractIFuncsFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
35 Module &Mod = WorkItem.getModule();
36
37 std::vector<GlobalIFunc *> IFuncs;
38 for (GlobalIFunc &GI : Mod.ifuncs()) {
39 if (!O.shouldKeep())
40 IFuncs.push_back(x: &GI);
41 }
42
43 if (!IFuncs.empty())
44 lowerGlobalIFuncUsersAsGlobalCtor(M&: Mod, IFuncsToLower: IFuncs);
45}
46
47void llvm::reduceAliasesDeltaPass(TestRunner &Test) {
48 runDeltaPass(Test, ExtractChunksFromModule: extractAliasesFromModule, Message: "Reducing Aliases");
49}
50
51void llvm::reduceIFuncsDeltaPass(TestRunner &Test) {
52 runDeltaPass(Test, ExtractChunksFromModule: extractIFuncsFromModule, Message: "Reducing Ifuncs");
53}
54