Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / llvm / tools / llvm-reduce / ReducerWorkItem.h
blobdc11322917af887351189502005d8308b7c090be
1 //===- ReducerWorkItem.h - Wrapper for Module -------------------*- 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_REDUCERWORKITEM_H
10 #define LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H
12 #include "llvm/IR/Module.h"
13 #include <memory>
15 namespace llvm {
16 class LLVMContext;
17 class MachineModuleInfo;
18 class MemoryBufferRef;
19 class raw_ostream;
20 class TargetMachine;
21 class TestRunner;
22 struct BitcodeLTOInfo;
24 class ReducerWorkItem {
25 public:
26 std::shared_ptr<Module> M;
27 std::unique_ptr<BitcodeLTOInfo> LTOInfo;
28 std::unique_ptr<MachineModuleInfo> MMI;
30 ReducerWorkItem();
31 ~ReducerWorkItem();
32 ReducerWorkItem(ReducerWorkItem &) = delete;
33 ReducerWorkItem(ReducerWorkItem &&) = default;
35 bool isMIR() const { return MMI != nullptr; }
37 LLVMContext &getContext() {
38 return M->getContext();
41 Module &getModule() { return *M; }
42 const Module &getModule() const { return *M; }
43 operator Module &() const { return *M; }
45 void print(raw_ostream &ROS, void *p = nullptr) const;
46 bool verify(raw_fd_ostream *OS) const;
47 std::unique_ptr<ReducerWorkItem> clone(const TargetMachine *TM) const;
49 /// Return a number to indicate whether there was any reduction progress.
50 uint64_t getComplexityScore() const {
51 return isMIR() ? computeMIRComplexityScore() : computeIRComplexityScore();
54 void writeOutput(raw_ostream &OS, bool EmitBitcode) const;
55 void readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, StringRef ToolName);
56 void writeBitcode(raw_ostream &OutStream) const;
58 bool isReduced(const TestRunner &Test) const;
60 private:
61 uint64_t computeIRComplexityScore() const;
62 uint64_t computeMIRComplexityScore() const;
65 std::pair<std::unique_ptr<ReducerWorkItem>, bool>
66 parseReducerWorkItem(StringRef ToolName, StringRef Filename, LLVMContext &Ctxt,
67 std::unique_ptr<TargetMachine> &TM, bool IsMIR);
68 } // namespace llvm
70 #endif