LLVM  14.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 struct SlotMapping;
27 
28 /// MIRFormater - Interface to format MIR operand based on target
29 class MIRFormatter {
30 public:
31  typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
33 
35  virtual ~MIRFormatter() = default;
36 
37  /// Implement target specific printing for machine operand immediate value, so
38  /// that we can have more meaningful mnemonic than a 64-bit integer. Passing
39  /// None to OpIdx means the index is unknown.
40  virtual void printImm(raw_ostream &OS, const MachineInstr &MI,
41  Optional<unsigned> OpIdx, int64_t Imm) const {
42  OS << Imm;
43  }
44 
45  /// Implement target specific parsing of immediate mnemonics. The mnemonic is
46  /// dot seperated strings.
47  virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
48  StringRef Src, int64_t &Imm,
49  ErrorCallbackType ErrorCallback) const {
50  llvm_unreachable("target did not implement parsing MIR immediate mnemonic");
51  }
52 
53  /// Implement target specific printing of target custom pseudo source value.
54  /// Default implementation is not necessarily the correct MIR serialization
55  /// format.
56  virtual void
58  const PseudoSourceValue &PSV) const {
59  PSV.printCustom(OS);
60  }
61 
62  /// Implement target specific parsing of target custom pseudo source value.
65  const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
67  "target did not implement parsing MIR custom pseudo source value");
68  }
69 
70  /// Helper functions to print IR value as MIR serialization format which will
71  /// be useful for target specific printer, e.g. for printing IR value in
72  /// custom pseudo source value.
73  static void printIRValue(raw_ostream &OS, const Value &V,
74  ModuleSlotTracker &MST);
75 
76  /// Helper functions to parse IR value from MIR serialization format which
77  /// will be useful for target specific parser, e.g. for parsing IR value for
78  /// custom pseudo source value.
79  static bool parseIRValue(StringRef Src, MachineFunction &MF,
80  PerFunctionMIParsingState &PFS, const Value *&V,
81  ErrorCallbackType ErrorCallback);
82 };
83 
84 } // end namespace llvm
85 
86 #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:105
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AllocatorList.h:23
Optional.h
llvm::MIRFormatter::MIRFormatter
MIRFormatter()
Definition: MIRFormatter.h:34
llvm::Optional< unsigned >
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:63
llvm::MIRFormatter::ErrorCallbackType
function_ref< bool(StringRef::iterator Loc, const Twine &)> ErrorCallbackType
Definition: MIRFormatter.h:32
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:3456
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:47
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:53
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:40
llvm::MachineFunction
Definition: MachineFunction.h:234
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:134
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::MIRFormatter
MIRFormater - Interface to format MIR operand based on target.
Definition: MIRFormatter.h:29
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:57
llvm::Value
LLVM Value Representation.
Definition: Value.h:74