1 //===- ReducerWorkItem.h - Wrapper for Module -------------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H
10 #define LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H
12 #include "llvm/IR/Module.h"
17 class MachineModuleInfo
;
18 class MemoryBufferRef
;
22 struct BitcodeLTOInfo
;
24 class ReducerWorkItem
{
26 std::shared_ptr
<Module
> M
;
27 std::unique_ptr
<BitcodeLTOInfo
> LTOInfo
;
28 std::unique_ptr
<MachineModuleInfo
> MMI
;
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;
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
);