MIRFormatter.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===-- llvm/CodeGen/MIRFormatter.h -----------------------------*- 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 file contains the declaration of the MIRFormatter class.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_CODEGEN_MIRFORMATTER_H
  18. #define LLVM_CODEGEN_MIRFORMATTER_H
  19. #include "llvm/ADT/Optional.h"
  20. #include "llvm/CodeGen/PseudoSourceValue.h"
  21. #include "llvm/Support/raw_ostream.h"
  22. #include <cstdint>
  23. namespace llvm {
  24. class MachineFunction;
  25. class MachineInstr;
  26. struct PerFunctionMIParsingState;
  27. /// MIRFormater - Interface to format MIR operand based on target
  28. class MIRFormatter {
  29. public:
  30. typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
  31. ErrorCallbackType;
  32. MIRFormatter() = default;
  33. virtual ~MIRFormatter() = default;
  34. /// Implement target specific printing for machine operand immediate value, so
  35. /// that we can have more meaningful mnemonic than a 64-bit integer. Passing
  36. /// None to OpIdx means the index is unknown.
  37. virtual void printImm(raw_ostream &OS, const MachineInstr &MI,
  38. Optional<unsigned> OpIdx, int64_t Imm) const {
  39. OS << Imm;
  40. }
  41. /// Implement target specific parsing of immediate mnemonics. The mnemonic is
  42. /// dot seperated strings.
  43. virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
  44. StringRef Src, int64_t &Imm,
  45. ErrorCallbackType ErrorCallback) const {
  46. llvm_unreachable("target did not implement parsing MIR immediate mnemonic");
  47. }
  48. /// Implement target specific printing of target custom pseudo source value.
  49. /// Default implementation is not necessarily the correct MIR serialization
  50. /// format.
  51. virtual void
  52. printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST,
  53. const PseudoSourceValue &PSV) const {
  54. PSV.printCustom(OS);
  55. }
  56. /// Implement target specific parsing of target custom pseudo source value.
  57. virtual bool parseCustomPseudoSourceValue(
  58. StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS,
  59. const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
  60. llvm_unreachable(
  61. "target did not implement parsing MIR custom pseudo source value");
  62. }
  63. /// Helper functions to print IR value as MIR serialization format which will
  64. /// be useful for target specific printer, e.g. for printing IR value in
  65. /// custom pseudo source value.
  66. static void printIRValue(raw_ostream &OS, const Value &V,
  67. ModuleSlotTracker &MST);
  68. /// Helper functions to parse IR value from MIR serialization format which
  69. /// will be useful for target specific parser, e.g. for parsing IR value for
  70. /// custom pseudo source value.
  71. static bool parseIRValue(StringRef Src, MachineFunction &MF,
  72. PerFunctionMIParsingState &PFS, const Value *&V,
  73. ErrorCallbackType ErrorCallback);
  74. };
  75. } // end namespace llvm
  76. #endif
  77. #ifdef __GNUC__
  78. #pragma GCC diagnostic pop
  79. #endif