LLVM 19.0.0git
MIRFormatter.h
Go to the documentation of this file.
1//===-- llvm/CodeGen/MIRFormatter.h -----------------------------*- 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//
9// This file contains the declaration of the MIRFormatter class.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_CODEGEN_MIRFORMATTER_H
14#define LLVM_CODEGEN_MIRFORMATTER_H
15
19#include <cstdint>
20#include <optional>
21
22namespace llvm {
23
24class MachineFunction;
25class MachineInstr;
26class ModuleSlotTracker;
27struct PerFunctionMIParsingState;
28class Twine;
29class Value;
30
31/// MIRFormater - Interface to format MIR operand based on target
33public:
34 typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
36
37 MIRFormatter() = default;
38 virtual ~MIRFormatter() = default;
39
40 /// Implement target specific printing for machine operand immediate value, so
41 /// that we can have more meaningful mnemonic than a 64-bit integer. Passing
42 /// std::nullopt to OpIdx means the index is unknown.
43 virtual void printImm(raw_ostream &OS, const MachineInstr &MI,
44 std::optional<unsigned> OpIdx, int64_t Imm) const {
45 OS << Imm;
46 }
47
48 /// Implement target specific parsing of immediate mnemonics. The mnemonic is
49 /// dot seperated strings.
50 virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
51 StringRef Src, int64_t &Imm,
52 ErrorCallbackType ErrorCallback) const {
53 llvm_unreachable("target did not implement parsing MIR immediate mnemonic");
54 }
55
56 /// Implement target specific printing of target custom pseudo source value.
57 /// Default implementation is not necessarily the correct MIR serialization
58 /// format.
59 virtual void
61 const PseudoSourceValue &PSV) const {
62 PSV.printCustom(OS);
63 }
64
65 /// Implement target specific parsing of target custom pseudo source value.
68 const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
70 "target did not implement parsing MIR custom pseudo source value");
71 }
72
73 /// Helper functions to print IR value as MIR serialization format which will
74 /// be useful for target specific printer, e.g. for printing IR value in
75 /// custom pseudo source value.
76 static void printIRValue(raw_ostream &OS, const Value &V,
78
79 /// Helper functions to parse IR value from MIR serialization format which
80 /// will be useful for target specific parser, e.g. for parsing IR value for
81 /// custom pseudo source value.
82 static bool parseIRValue(StringRef Src, MachineFunction &MF,
83 PerFunctionMIParsingState &PFS, const Value *&V,
84 ErrorCallbackType ErrorCallback);
85};
86
87} // end namespace llvm
88
89#endif
IRTranslator LLVM IR MI
raw_pwrite_stream & OS
MIRFormater - Interface to format MIR operand based on target.
Definition: MIRFormatter.h:32
virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx, StringRef Src, int64_t &Imm, ErrorCallbackType ErrorCallback) const
Implement target specific parsing of immediate mnemonics.
Definition: MIRFormatter.h:50
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
Definition: MIRFormatter.h:35
static bool parseIRValue(StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS, const Value *&V, ErrorCallbackType ErrorCallback)
Helper functions to parse IR value from MIR serialization format which will be useful for target spec...
Definition: MIParser.cpp:3659
virtual ~MIRFormatter()=default
MIRFormatter()=default
virtual void printImm(raw_ostream &OS, const MachineInstr &MI, std::optional< unsigned > OpIdx, int64_t Imm) const
Implement target specific printing for machine operand immediate value, so that we can have more mean...
Definition: MIRFormatter.h:43
virtual void printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST, const PseudoSourceValue &PSV) const
Implement target specific printing of target custom pseudo source value.
Definition: MIRFormatter.h:60
virtual bool parseCustomPseudoSourceValue(StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS, const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const
Implement target specific parsing of target custom pseudo source value.
Definition: MIRFormatter.h:66
static void printIRValue(raw_ostream &OS, const Value &V, ModuleSlotTracker &MST)
Helper functions to print IR value as MIR serialization format which will be useful for target specif...
Definition: MIRPrinter.cpp:966
Representation of each machine instruction.
Definition: MachineInstr.h:69
Manage lifetime of a slot tracker for printing IR.
Special value supplied for machine level alias analysis.
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
LLVM Value Representation.
Definition: Value.h:74
An efficient, type-erasing, non-owning reference to a callable.
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:52
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18