Olivier Deprez | f4ef2d0 | 2021-04-20 13:36:24 +0200 | [diff] [blame] | 1 | //===-- llvm/CodeGen/MIRFormatter.h -----------------------------*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 10 | // This file contains the declaration of the MIRFormatter class. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
| 14 | #ifndef LLVM_CODEGEN_MIRFORMATTER_H |
| 15 | #define LLVM_CODEGEN_MIRFORMATTER_H |
| 16 | |
| 17 | #include "llvm/ADT/Optional.h" |
| 18 | #include "llvm/CodeGen/PseudoSourceValue.h" |
| 19 | #include "llvm/Support/raw_ostream.h" |
| 20 | #include <cstdint> |
| 21 | |
| 22 | namespace llvm { |
| 23 | |
| 24 | class MachineFunction; |
| 25 | class MachineInstr; |
| 26 | struct PerFunctionMIParsingState; |
| 27 | struct SlotMapping; |
| 28 | |
| 29 | /// MIRFormater - Interface to format MIR operand based on target |
| 30 | class MIRFormatter { |
| 31 | public: |
| 32 | typedef function_ref<bool(StringRef::iterator Loc, const Twine &)> |
| 33 | ErrorCallbackType; |
| 34 | |
| 35 | MIRFormatter() {} |
| 36 | virtual ~MIRFormatter() = default; |
| 37 | |
| 38 | /// Implement target specific printing for machine operand immediate value, so |
| 39 | /// that we can have more meaningful mnemonic than a 64-bit integer. Passing |
| 40 | /// None to OpIdx means the index is unknown. |
| 41 | virtual void printImm(raw_ostream &OS, const MachineInstr &MI, |
| 42 | Optional<unsigned> OpIdx, int64_t Imm) const { |
| 43 | OS << Imm; |
| 44 | } |
| 45 | |
| 46 | /// Implement target specific parsing of immediate mnemonics. The mnemonic is |
| 47 | /// dot seperated strings. |
| 48 | virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx, |
| 49 | StringRef Src, int64_t &Imm, |
| 50 | ErrorCallbackType ErrorCallback) const { |
| 51 | llvm_unreachable("target did not implement parsing MIR immediate mnemonic"); |
| 52 | } |
| 53 | |
| 54 | /// Implement target specific printing of target custom pseudo source value. |
| 55 | /// Default implementation is not necessarily the correct MIR serialization |
| 56 | /// format. |
| 57 | virtual void |
| 58 | printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST, |
| 59 | const PseudoSourceValue &PSV) const { |
| 60 | PSV.printCustom(OS); |
| 61 | } |
| 62 | |
| 63 | /// Implement target specific parsing of target custom pseudo source value. |
| 64 | virtual bool parseCustomPseudoSourceValue( |
| 65 | StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS, |
| 66 | const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const { |
| 67 | llvm_unreachable( |
| 68 | "target did not implement parsing MIR custom pseudo source value"); |
| 69 | } |
| 70 | |
| 71 | /// Helper functions to print IR value as MIR serialization format which will |
| 72 | /// be useful for target specific printer, e.g. for printing IR value in |
| 73 | /// custom pseudo source value. |
| 74 | static void printIRValue(raw_ostream &OS, const Value &V, |
| 75 | ModuleSlotTracker &MST); |
| 76 | |
| 77 | /// Helper functions to parse IR value from MIR serialization format which |
| 78 | /// will be useful for target specific parser, e.g. for parsing IR value for |
| 79 | /// custom pseudo source value. |
| 80 | static bool parseIRValue(StringRef Src, MachineFunction &MF, |
| 81 | PerFunctionMIParsingState &PFS, const Value *&V, |
| 82 | ErrorCallbackType ErrorCallback); |
| 83 | }; |
| 84 | |
| 85 | } // end namespace llvm |
| 86 | |
| 87 | #endif |