Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / TestRunner.h
blob136cd80ea1c6201ade366d83b6a1d5961d8dcc9e
1 //===-- tools/llvm-reduce/TestRunner.h ---------------------------*- C++ -*-===/
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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
10 #define LLVM_TOOLS_LLVM_REDUCE_TESTRUNNER_H
12 #include "ReducerWorkItem.h"
13 #include "llvm/ADT/SmallString.h"
14 #include "llvm/IR/Module.h"
15 #include "llvm/Support/Error.h"
16 #include "llvm/Support/FileSystem.h"
17 #include "llvm/Support/Path.h"
18 #include "llvm/Support/Program.h"
19 #include "llvm/Target/TargetMachine.h"
20 #include <vector>
22 namespace llvm {
24 // This class contains all the info necessary for running the provided
25 // interesting-ness test, as well as the most reduced module and its
26 // respective filename.
27 class TestRunner {
28 public:
29 TestRunner(StringRef TestName, const std::vector<std::string> &TestArgs,
30 std::unique_ptr<ReducerWorkItem> Program,
31 std::unique_ptr<TargetMachine> TM, StringRef ToolName,
32 StringRef OutputFilename, bool InputIsBitcode, bool OutputBitcode);
34 /// Runs the interesting-ness test for the specified file
35 /// @returns 0 if test was successful, 1 if otherwise
36 int run(StringRef Filename) const;
38 /// Returns the most reduced version of the original testcase
39 ReducerWorkItem &getProgram() const { return *Program; }
41 void setProgram(std::unique_ptr<ReducerWorkItem> &&P) {
42 assert(P && "Setting null program?");
43 Program = std::move(P);
46 const TargetMachine *getTargetMachine() const { return TM.get(); }
48 StringRef getToolName() const { return ToolName; }
50 void writeOutput(StringRef Message);
52 bool inputIsBitcode() const {
53 return InputIsBitcode;
56 private:
57 StringRef TestName;
58 StringRef ToolName;
59 const std::vector<std::string> &TestArgs;
60 std::unique_ptr<ReducerWorkItem> Program;
61 std::unique_ptr<TargetMachine> TM;
62 StringRef OutputFilename;
63 const bool InputIsBitcode;
64 bool EmitBitcode;
67 } // namespace llvm
69 #endif