From 3755579f93c2b21aabcc47c23c0a5a5676a0d80e Mon Sep 17 00:00:00 2001 From: Diego Trevino Ferrer Date: Wed, 14 Aug 2019 22:22:37 +0000 Subject: [Bugpoint redesign] Modified Functions pass to consider declarations Summary: This modification was put in place so the `ReduceMetadata` pass doesn't have to consider debug functions Reviewers: dblaikie Subscribers: llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D66257 llvm-svn: 368934 --- llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp | 37 +++++++++-------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'llvm/tools/llvm-reduce') diff --git a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp index 5eb57c0b7d4..52777bed640 100644 --- a/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp +++ b/llvm/tools/llvm-reduce/deltas/ReduceFunctions.cpp @@ -22,7 +22,7 @@ static void extractFunctionsFromModule(const std::vector &ChunksToKeep, std::set 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) @@ -31,41 +31,34 @@ static void extractFunctionsFromModule(const std::vector &ChunksToKeep, // Delete out-of-chunk functions, and replace their calls with undef std::vector FuncsToRemove; + std::vector 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(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 InstToRemove; - for (auto &F : *Program) - for (auto &BB : F) - for (auto &I : BB) - if (auto *Call = dyn_cast(&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; @@ -73,7 +66,7 @@ static unsigned countDefinedFunctions(Module *Program) { 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 -- cgit v1.2.3