LLVM  13.0.0git
MIRFormatter.h
Go to the documentation of this file.
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"
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 &)>
34 
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
59  const PseudoSourceValue &PSV) const {
60  PSV.printCustom(OS);
61  }
62 
63  /// Implement target specific parsing of target custom pseudo source value.
66  const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
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
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:897
MI
IRTranslator LLVM IR MI
Definition: IRTranslator.cpp:100
llvm
Definition: AllocatorList.h:23
Optional.h
llvm::MIRFormatter::MIRFormatter
MIRFormatter()
Definition: MIRFormatter.h:35
llvm::Optional< unsigned >
llvm::ModuleSlotTracker
Manage lifetime of a slot tracker for printing IR.
Definition: ModuleSlotTracker.h:29
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:64
llvm::MIRFormatter::ErrorCallbackType
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
Definition: MIRFormatter.h:33
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:3261
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:48
llvm::StringRef::iterator
const char * iterator
Definition: StringRef.h:61
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:50
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: STLExtras.h:168
llvm::MachineInstr
Representation of each machine instruction.
Definition: MachineInstr.h:64
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:41
llvm::MachineFunction
Definition: MachineFunction.h:230
llvm::StringRef
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:57
llvm_unreachable
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Definition: ErrorHandling.h:136
llvm::PerFunctionMIParsingState
Definition: MIParser.h:160
llvm::Twine
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:80
llvm::MIRFormatter::~MIRFormatter
virtual ~MIRFormatter()=default
llvm::MIRFormatter
MIRFormater - Interface to format MIR operand based on target.
Definition: MIRFormatter.h:30
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:58
llvm::Value
LLVM Value Representation.
Definition: Value.h:75