1 //===- ReducerWorkItem.h - Wrapper for Module and MachineFunction ---------===// 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 //===----------------------------------------------------------------------===// 8 9 #ifndef LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H 10 #define LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H 11 12 #include "llvm/Bitcode/BitcodeReader.h" 13 #include "llvm/CodeGen/MachineFunction.h" 14 #include "llvm/CodeGen/MachineModuleInfo.h" 15 #include "llvm/IR/Module.h" 16 #include "llvm/IR/ModuleSummaryIndex.h" 17 #include "llvm/Target/TargetMachine.h" 18 19 using namespace llvm; 20 21 class ReducerWorkItem { 22 public: 23 std::shared_ptr<Module> M; 24 std::unique_ptr<BitcodeLTOInfo> LTOInfo; 25 std::unique_ptr<MachineModuleInfo> MMI; 26 isMIR()27 bool isMIR() const { return MMI != nullptr; } 28 getModule()29 const Module &getModule() const { return *M; } 30 31 void print(raw_ostream &ROS, void *p = nullptr) const; 32 operator Module &() const { return *M; } 33 34 /// Return a number to indicate whether there was any reduction progress. getComplexityScore()35 uint64_t getComplexityScore() const { 36 return isMIR() ? computeMIRComplexityScore() : getIRSize(); 37 } 38 39 private: 40 uint64_t computeMIRComplexityScore() const; 41 uint64_t getIRSize() const; 42 }; 43 44 std::unique_ptr<ReducerWorkItem> 45 parseReducerWorkItem(const char *ToolName, StringRef Filename, 46 LLVMContext &Ctxt, std::unique_ptr<TargetMachine> &TM, 47 bool IsMIR); 48 49 std::unique_ptr<ReducerWorkItem> 50 cloneReducerWorkItem(const ReducerWorkItem &MMM, const TargetMachine *TM); 51 52 bool verifyReducerWorkItem(const ReducerWorkItem &MMM, raw_fd_ostream *OS); 53 54 #endif 55