1 //===-- llvm/CodeGen/MIRFormatter.h -----------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file contains the declaration of the MIRFormatter class.
12 //===----------------------------------------------------------------------===//
14 #ifndef LLVM_CODEGEN_MIRFORMATTER_H
15 #define LLVM_CODEGEN_MIRFORMATTER_H
17 #include "llvm/CodeGen/MachineInstr.h"
18 #include "llvm/CodeGen/PseudoSourceValue.h"
22 struct PerFunctionMIParsingState;
25 /// MIRFormater - Interface to format MIR operand based on target
28 typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
32 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 {
42 /// Implement target specific parsing of immediate mnemonics. The mnemonic is
43 /// dot seperated strings.
44 virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
45 StringRef Src, int64_t &Imm,
46 ErrorCallbackType ErrorCallback) const {
47 llvm_unreachable("target did not implement parsing MIR immediate mnemonic");
50 /// Implement target specific printing of target custom pseudo source value.
51 /// Default implementation is not necessarily the correct MIR serialization
54 printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST,
55 const PseudoSourceValue &PSV) const {
59 /// Implement target specific parsing of target custom pseudo source value.
60 virtual bool parseCustomPseudoSourceValue(
61 StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS,
62 const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
64 "target did not implement parsing MIR custom pseudo source value");
67 /// Helper functions to print IR value as MIR serialization format which will
68 /// be useful for target specific printer, e.g. for printing IR value in
69 /// custom pseudo source value.
70 static void printIRValue(raw_ostream &OS, const Value &V,
71 ModuleSlotTracker &MST);
73 /// Helper functions to parse IR value from MIR serialization format which
74 /// will be useful for target specific parser, e.g. for parsing IR value for
75 /// custom pseudo source value.
76 static bool parseIRValue(StringRef Src, MachineFunction &MF,
77 PerFunctionMIParsingState &PFS, const Value *&V,
78 ErrorCallbackType ErrorCallback);
81 } // end namespace llvm