Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / deltas / ReduceAliases.cpp
blob2f2df549b67287140e778dd08be306740cd8094f
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.
12 //===----------------------------------------------------------------------===//
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"
21 using namespace llvm;
23 /// Removes all aliases aren't inside any of the
24 /// desired Chunks.
25 static void extractAliasesFromModule(Oracle &O, ReducerWorkItem &Program) {
26 for (auto &GA : make_early_inc_range(Program.getModule().aliases())) {
27 if (!O.shouldKeep()) {
28 GA.replaceAllUsesWith(GA.getAliasee());
29 GA.eraseFromParent();
34 static void extractIFuncsFromModule(Oracle &O, ReducerWorkItem &WorkItem) {
35 Module &Mod = WorkItem.getModule();
37 std::vector<GlobalIFunc *> IFuncs;
38 for (GlobalIFunc &GI : Mod.ifuncs()) {
39 if (!O.shouldKeep())
40 IFuncs.push_back(&GI);
43 if (!IFuncs.empty())
44 lowerGlobalIFuncUsersAsGlobalCtor(Mod, IFuncs);
47 void llvm::reduceAliasesDeltaPass(TestRunner &Test) {
48 runDeltaPass(Test, extractAliasesFromModule, "Reducing Aliases");
51 void llvm::reduceIFuncsDeltaPass(TestRunner &Test) {
52 runDeltaPass(Test, extractIFuncsFromModule, "Reducing Ifuncs");