ReducerWorkItem.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H
  9. #define LLVM_TOOLS_LLVM_REDUCE_REDUCERWORKITEM_H
  10. #include "llvm/IR/Module.h"
  11. #include <memory>
  12. namespace llvm {
  13. class LLVMContext;
  14. class MachineModuleInfo;
  15. class MemoryBufferRef;
  16. class raw_ostream;
  17. class TargetMachine;
  18. class TestRunner;
  19. struct BitcodeLTOInfo;
  20. class ReducerWorkItem {
  21. public:
  22. std::shared_ptr<Module> M;
  23. std::unique_ptr<BitcodeLTOInfo> LTOInfo;
  24. std::unique_ptr<MachineModuleInfo> MMI;
  25. ReducerWorkItem();
  26. ~ReducerWorkItem();
  27. ReducerWorkItem(ReducerWorkItem &) = delete;
  28. ReducerWorkItem(ReducerWorkItem &&) = default;
  29. bool isMIR() const { return MMI != nullptr; }
  30. LLVMContext &getContext() {
  31. return M->getContext();
  32. }
  33. Module &getModule() { return *M; }
  34. const Module &getModule() const { return *M; }
  35. operator Module &() const { return *M; }
  36. void print(raw_ostream &ROS, void *p = nullptr) const;
  37. bool verify(raw_fd_ostream *OS) const;
  38. std::unique_ptr<ReducerWorkItem> clone(const TargetMachine *TM) const;
  39. /// Return a number to indicate whether there was any reduction progress.
  40. uint64_t getComplexityScore() const {
  41. return isMIR() ? computeMIRComplexityScore() : computeIRComplexityScore();
  42. }
  43. void writeOutput(raw_ostream &OS, bool EmitBitcode) const;
  44. void readBitcode(MemoryBufferRef Data, LLVMContext &Ctx, StringRef ToolName);
  45. void writeBitcode(raw_ostream &OutStream) const;
  46. bool isReduced(const TestRunner &Test) const;
  47. private:
  48. uint64_t computeIRComplexityScore() const;
  49. uint64_t computeMIRComplexityScore() const;
  50. };
  51. std::pair<std::unique_ptr<ReducerWorkItem>, bool>
  52. parseReducerWorkItem(StringRef ToolName, StringRef Filename, LLVMContext &Ctxt,
  53. std::unique_ptr<TargetMachine> &TM, bool IsMIR);
  54. } // namespace llvm
  55. #endif