21 changes: 21 additions & 0 deletions llvm/tools/llvm-reduce/deltas/ReduceGlobalVarInitializers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//===- reduceGlobalsInitializersDeltaPass.h - Specialized Delta Pass
//-------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements a function which calls the Generic Delta pass in order
// to reduce initializers of Global Variables in the provided Module.
//
//===----------------------------------------------------------------------===//

#include "Delta.h"
#include "llvm/IR/Value.h"
#include "llvm/Transforms/Utils/Cloning.h"

namespace llvm {
void reduceGlobalsInitializersDeltaPass(TestRunner &Test);
} // namespace llvm
13 changes: 6 additions & 7 deletions llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
//
// This file implements a function which calls the Generic Delta pass in order
// to reduce initialized Global Variables in the provided Module.
// to reduce Global Variables in the provided Module.
//
//===----------------------------------------------------------------------===//

Expand All @@ -17,22 +17,22 @@

using namespace llvm;

/// Removes all the Initialized GVs that aren't inside the desired Chunks.
/// Removes all the GVs that aren't inside the desired Chunks.
static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
Module *Program) {
Oracle O(ChunksToKeep);

// Get GVs inside desired chunks
std::set<GlobalVariable *> GVsToKeep;
for (auto &GV : Program->globals())
if (GV.hasInitializer() && O.shouldKeep())
if (O.shouldKeep())
GVsToKeep.insert(&GV);

// Delete out-of-chunk GVs and their uses
std::vector<GlobalVariable *> ToRemove;
std::vector<WeakVH> InstToRemove;
for (auto &GV : Program->globals())
if (GV.hasInitializer() && !GVsToKeep.count(&GV)) {
if (!GVsToKeep.count(&GV)) {
for (auto U : GV.users())
if (auto *Inst = dyn_cast<Instruction>(U))
InstToRemove.push_back(Inst);
Expand All @@ -54,16 +54,15 @@ static void extractGVsFromModule(std::vector<Chunk> ChunksToKeep,
GV->eraseFromParent();
}

/// Counts the amount of initialized GVs and displays their
/// Counts the amount of GVs and displays their
/// respective name & index
static int countGVs(Module *Program) {
// TODO: Silence index with --quiet flag
outs() << "----------------------------\n";
outs() << "GlobalVariable Index Reference:\n";
int GVCount = 0;
for (auto &GV : Program->globals())
if (GV.hasInitializer())
outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
outs() << "\t" << ++GVCount << ": " << GV.getName() << "\n";
outs() << "----------------------------\n";
return GVCount;
}
Expand Down
2 changes: 1 addition & 1 deletion llvm/tools/llvm-reduce/deltas/ReduceGlobalVars.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//===----------------------------------------------------------------------===//
//
// This file implements a function which calls the Generic Delta pass in order
// to reduce initialized Global Variables in the provided Module.
// to reduce Global Variables in the provided Module.
//
//===----------------------------------------------------------------------===//

Expand Down