[PATCH] D66257: [Bugpoint redesign] Modified Functions pass to consider declarations
Diego TreviƱo via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 14 14:54:37 PDT 2019
diegotf created this revision.
diegotf added a reviewer: dblaikie.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
This modification was put in place so the `ReduceMetadata` pass doesn't have to consider debug functions
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D66257
Files:
llvm/test/Reduce/remove-funcs.ll
llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
Index: llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
===================================================================
--- llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
+++ llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp
@@ -23,7 +23,7 @@
std::set<Function *> FuncsToKeep;
unsigned I = 0, FunctionCount = 0;
for (auto &F : *Program)
- if (!F.isDeclaration() && I < ChunksToKeep.size()) {
+ if (I < ChunksToKeep.size()) {
if (ChunksToKeep[I].contains(++FunctionCount))
FuncsToKeep.insert(&F);
if (FunctionCount == ChunksToKeep[I].end)
@@ -32,41 +32,34 @@
// Delete out-of-chunk functions, and replace their calls with undef
std::vector<Function *> FuncsToRemove;
+ std::vector<CallInst *> CallsToRemove;
for (auto &F : *Program)
- if (!F.isDeclaration() && !FuncsToKeep.count(&F)) {
+ if (!FuncsToKeep.count(&F)) {
+ for (auto U : F.users())
+ if (auto *Call = dyn_cast<CallInst>(U)) {
+ Call->replaceAllUsesWith(UndefValue::get(Call->getType()));
+ CallsToRemove.push_back(Call);
+ }
F.replaceAllUsesWith(UndefValue::get(F.getType()));
FuncsToRemove.push_back(&F);
}
+ for (auto *C : CallsToRemove)
+ C->eraseFromParent();
+
for (auto *F : FuncsToRemove)
F->eraseFromParent();
-
- // Delete instructions with undef calls
- std::vector<Instruction *> InstToRemove;
- for (auto &F : *Program)
- for (auto &BB : F)
- for (auto &I : BB)
- if (auto *Call = dyn_cast<CallInst>(&I))
- if (!Call->getCalledFunction()) {
- // Instruction might be stored / used somewhere else
- I.replaceAllUsesWith(UndefValue::get(I.getType()));
- InstToRemove.push_back(&I);
- }
-
- for (auto *I : InstToRemove)
- I->eraseFromParent();
}
/// Counts the amount of non-declaration functions and prints their
/// respective name & index
-static unsigned countDefinedFunctions(Module *Program) {
+static unsigned countFunctions(Module *Program) {
// TODO: Silence index with --quiet flag
outs() << "----------------------------\n";
outs() << "Function Index Reference:\n";
unsigned FunctionCount = 0;
for (auto &F : *Program)
- if (!F.isDeclaration())
- outs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
+ outs() << "\t" << ++FunctionCount << ": " << F.getName() << "\n";
outs() << "----------------------------\n";
return FunctionCount;
@@ -74,7 +67,7 @@
void llvm::reduceFunctionsDeltaPass(TestRunner &Test) {
outs() << "*** Reducing Functions...\n";
- unsigned Functions = countDefinedFunctions(Test.getProgram());
+ unsigned Functions = countFunctions(Test.getProgram());
runDeltaPass(Test, Functions, extractFunctionsFromModule);
outs() << "----------------------------\n";
}
\ No newline at end of file
Index: llvm/test/Reduce/remove-funcs.ll
===================================================================
--- llvm/test/Reduce/remove-funcs.ll
+++ llvm/test/Reduce/remove-funcs.ll
@@ -28,7 +28,4 @@
}
; CHECK-NOT: uninteresting3()
-define i32 @uninteresting3() {
-entry:
- ret i32 10
-}
+declare void @uninteresting3()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66257.215257.patch
Type: text/x-patch
Size: 3187 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190814/b48eaa2c/attachment.bin>
More information about the llvm-commits
mailing list