diff --git a/llvm/test/Reduce/Inputs/remove-args.py b/llvm/test/Reduce/Inputs/remove-args.py --- a/llvm/test/Reduce/Inputs/remove-args.py +++ b/llvm/test/Reduce/Inputs/remove-args.py @@ -3,17 +3,10 @@ import sys UsedArgumentPresent = False -# So ReduceFunctions pass doesn't remove anything -FunctionCount = 0 input = open(sys.argv[1], "r") for line in input: if "%used" in line: - UsedArgumentPresent = True - if "define" in line: - FunctionCount += 1 + sys.exit(0) # Interesting! -if UsedArgumentPresent and FunctionCount == 3: - sys.exit(0) # Interesting! -else: - sys.exit(1) +sys.exit(1) diff --git a/llvm/test/Reduce/remove-args.ll b/llvm/test/Reduce/remove-args.ll --- a/llvm/test/Reduce/remove-args.ll +++ b/llvm/test/Reduce/remove-args.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can remove uninteresting function arguments from function definitions as well as their calls. ; Note: This pass also removes InstAllocs of uninteresting args ; -; RUN: llvm-reduce --test %p/Inputs/remove-args.py %s +; RUN: llvm-reduce --test %p/Inputs/remove-args.py %s --run-only args ; RUN: cat reduced.ll | FileCheck %s ; REQUIRES: plugins diff --git a/llvm/test/Reduce/remove-funcs.ll b/llvm/test/Reduce/remove-funcs.ll --- a/llvm/test/Reduce/remove-funcs.ll +++ b/llvm/test/Reduce/remove-funcs.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can remove uninteresting functions as well as ; their InstCalls. ; -; RUN: llvm-reduce --test %p/Inputs/remove-funcs.py %s +; RUN: llvm-reduce --test %p/Inputs/remove-funcs.py %s --run-only funcs ; RUN: cat reduced.ll | FileCheck %s ; REQUIRES: plugins diff --git a/llvm/test/Reduce/remove-global-vars.ll b/llvm/test/Reduce/remove-global-vars.ll --- a/llvm/test/Reduce/remove-global-vars.ll +++ b/llvm/test/Reduce/remove-global-vars.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can remove uninteresting Global Variables as well as ; their direct uses. ; -; RUN: llvm-reduce --test %p/Inputs/remove-global-vars.py %s +; RUN: llvm-reduce --test %p/Inputs/remove-global-vars.py %s --run-only globals ; RUN: cat reduced.ll | FileCheck %s ; REQUIRES: plugins diff --git a/llvm/test/Reduce/remove-metadata.ll b/llvm/test/Reduce/remove-metadata.ll --- a/llvm/test/Reduce/remove-metadata.ll +++ b/llvm/test/Reduce/remove-metadata.ll @@ -1,7 +1,7 @@ ; Test that llvm-reduce can remove uninteresting metadata from an IR file. ; The Metadata pass erases named & unnamed metadata nodes, as well as debug functions. ; -; RUN: llvm-reduce --test %p/Inputs/remove-metadata.py %s +; RUN: llvm-reduce --test %p/Inputs/remove-metadata.py %s --run-only metadata ; RUN: cat reduced.ll | FileCheck %s ; REQUIRES: plugins diff --git a/llvm/tools/llvm-reduce/DeltaManager.h b/llvm/tools/llvm-reduce/DeltaManager.h --- a/llvm/tools/llvm-reduce/DeltaManager.h +++ b/llvm/tools/llvm-reduce/DeltaManager.h @@ -20,7 +20,6 @@ namespace llvm { -// TODO: Add CLI option to run only specified Passes (for unit tests) inline void runDeltaPasses(TestRunner &Tester) { reduceFunctionsDeltaPass(Tester); reduceGlobalsDeltaPass(Tester); @@ -29,4 +28,18 @@ // TODO: Implement the remaining Delta Passes } +inline void runSpecifiedDeltaPasses(TestRunner &Tester, + const std::vector &Passes) { + for (auto &Pass : Passes) { + if (Pass == "funcs") + reduceFunctionsDeltaPass(Tester); + else if (Pass == "globals") + reduceGlobalsDeltaPass(Tester); + else if (Pass == "metadata") + reduceMetadataDeltaPass(Tester); + else if (Pass == "args") + reduceArgumentsDeltaPass(Tester); + } +} + } // namespace llvm diff --git a/llvm/tools/llvm-reduce/llvm-reduce.cpp b/llvm/tools/llvm-reduce/llvm-reduce.cpp --- a/llvm/tools/llvm-reduce/llvm-reduce.cpp +++ b/llvm/tools/llvm-reduce/llvm-reduce.cpp @@ -53,11 +53,24 @@ cl::desc("WARNING: This option will replace your input file" "with the reduced version!")); -static cl::opt - RunOnlySpecifiedPasses("run-only", - cl::desc("option used for testing purposes," - "runs only the specified delta passes"), - cl::Hidden); +static cl::opt + SpecifiedPasses("run-only", + cl::desc("option used for testing purposes," + "runs only the specified delta passes"), + cl::Hidden); + +static std::vector parseDeltaPassNames(std::string PassNames) { + std::vector DeltaPasses; + if (PassNames.empty()) + return DeltaPasses; + + SmallVector Deltas; + StringRef(PassNames).split(Deltas, ',', -1, false); + for (auto &D : Deltas) + DeltaPasses.push_back(D); + + return DeltaPasses; +} // Parses IR into a Module and verifies it static std::unique_ptr parseInputFile(StringRef Filename, @@ -90,8 +103,14 @@ TestRunner Tester(TestFilename, TestArguments, InputFilename); Tester.setProgram(std::move(OriginalProgram)); - // Try to reduce code - runDeltaPasses(Tester); + // No passes specified, run all of them + if (SpecifiedPasses.empty()) + runDeltaPasses(Tester); + else { + std::vector DeltaPasses = parseDeltaPassNames(SpecifiedPasses); + runSpecifiedDeltaPasses(Tester, DeltaPasses); + } + StringRef ReducedFilename = sys::path::filename(Tester.getReducedFilepath()); if (ReducedFilename == sys::path::filename(InputFilename)) {