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