MIRParser.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- MIRParser.h - MIR serialization format parser ------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This MIR serialization library is currently a work in progress. It can't
  15. // serialize machine functions at this time.
  16. //
  17. // This file declares the functions that parse the MIR serialization format
  18. // files.
  19. //
  20. //===----------------------------------------------------------------------===//
  21. #ifndef LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
  22. #define LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
  23. #include "llvm/IR/Module.h"
  24. #include "llvm/Support/MemoryBuffer.h"
  25. #include <memory>
  26. namespace llvm {
  27. class Function;
  28. class MIRParserImpl;
  29. class MachineModuleInfo;
  30. class SMDiagnostic;
  31. class StringRef;
  32. typedef llvm::function_ref<Optional<std::string>(StringRef)>
  33. DataLayoutCallbackTy;
  34. /// This class initializes machine functions by applying the state loaded from
  35. /// a MIR file.
  36. class MIRParser {
  37. std::unique_ptr<MIRParserImpl> Impl;
  38. public:
  39. MIRParser(std::unique_ptr<MIRParserImpl> Impl);
  40. MIRParser(const MIRParser &) = delete;
  41. ~MIRParser();
  42. /// Parses the optional LLVM IR module in the MIR file.
  43. ///
  44. /// A new, empty module is created if the LLVM IR isn't present.
  45. /// \returns nullptr if a parsing error occurred.
  46. std::unique_ptr<Module> parseIRModule(
  47. DataLayoutCallbackTy DataLayoutCallback = [](StringRef) { return None; });
  48. /// Parses MachineFunctions in the MIR file and add them to the given
  49. /// MachineModuleInfo \p MMI.
  50. ///
  51. /// \returns true if an error occurred.
  52. bool parseMachineFunctions(Module &M, MachineModuleInfo &MMI);
  53. };
  54. /// This function is the main interface to the MIR serialization format parser.
  55. ///
  56. /// It reads in a MIR file and returns a MIR parser that can parse the embedded
  57. /// LLVM IR module and initialize the machine functions by parsing the machine
  58. /// function's state.
  59. ///
  60. /// \param Filename - The name of the file to parse.
  61. /// \param Error - Error result info.
  62. /// \param Context - Context which will be used for the parsed LLVM IR module.
  63. /// \param ProcessIRFunction - function to run on every IR function or stub
  64. /// loaded from the MIR file.
  65. std::unique_ptr<MIRParser> createMIRParserFromFile(
  66. StringRef Filename, SMDiagnostic &Error, LLVMContext &Context,
  67. std::function<void(Function &)> ProcessIRFunction = nullptr);
  68. /// This function is another interface to the MIR serialization format parser.
  69. ///
  70. /// It returns a MIR parser that works with the given memory buffer and that can
  71. /// parse the embedded LLVM IR module and initialize the machine functions by
  72. /// parsing the machine function's state.
  73. ///
  74. /// \param Contents - The MemoryBuffer containing the machine level IR.
  75. /// \param Context - Context which will be used for the parsed LLVM IR module.
  76. std::unique_ptr<MIRParser>
  77. createMIRParser(std::unique_ptr<MemoryBuffer> Contents, LLVMContext &Context,
  78. std::function<void(Function &)> ProcessIRFunction = nullptr);
  79. } // end namespace llvm
  80. #endif // LLVM_CODEGEN_MIRPARSER_MIRPARSER_H
  81. #ifdef __GNUC__
  82. #pragma GCC diagnostic pop
  83. #endif