Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:43:32

0001 //===-- llvm/CodeGen/MIRFormatter.h -----------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 //
0009 // This file contains the declaration of the MIRFormatter class.
0010 //
0011 //===----------------------------------------------------------------------===//
0012 
0013 #ifndef LLVM_CODEGEN_MIRFORMATTER_H
0014 #define LLVM_CODEGEN_MIRFORMATTER_H
0015 
0016 #include "llvm/CodeGen/PseudoSourceValue.h"
0017 #include "llvm/Support/ErrorHandling.h"
0018 #include "llvm/Support/raw_ostream.h"
0019 #include <cstdint>
0020 #include <optional>
0021 
0022 namespace llvm {
0023 
0024 class MachineFunction;
0025 class MachineInstr;
0026 class ModuleSlotTracker;
0027 struct PerFunctionMIParsingState;
0028 class Twine;
0029 class Value;
0030 
0031 /// MIRFormater - Interface to format MIR operand based on target
0032 class MIRFormatter {
0033 public:
0034   typedef function_ref<bool(StringRef::iterator Loc, const Twine &)>
0035       ErrorCallbackType;
0036 
0037   MIRFormatter() = default;
0038   virtual ~MIRFormatter() = default;
0039 
0040   /// Implement target specific printing for machine operand immediate value, so
0041   /// that we can have more meaningful mnemonic than a 64-bit integer. Passing
0042   /// std::nullopt to OpIdx means the index is unknown.
0043   virtual void printImm(raw_ostream &OS, const MachineInstr &MI,
0044                         std::optional<unsigned> OpIdx, int64_t Imm) const {
0045     OS << Imm;
0046   }
0047 
0048   /// Implement target specific parsing of immediate mnemonics. The mnemonic is
0049   /// dot separated strings.
0050   virtual bool parseImmMnemonic(const unsigned OpCode, const unsigned OpIdx,
0051                                 StringRef Src, int64_t &Imm,
0052                                 ErrorCallbackType ErrorCallback) const {
0053     llvm_unreachable("target did not implement parsing MIR immediate mnemonic");
0054   }
0055 
0056   /// Implement target specific printing of target custom pseudo source value.
0057   /// Default implementation is not necessarily the correct MIR serialization
0058   /// format.
0059   virtual void
0060   printCustomPseudoSourceValue(raw_ostream &OS, ModuleSlotTracker &MST,
0061                                const PseudoSourceValue &PSV) const {
0062     PSV.printCustom(OS);
0063   }
0064 
0065   /// Implement target specific parsing of target custom pseudo source value.
0066   virtual bool parseCustomPseudoSourceValue(
0067       StringRef Src, MachineFunction &MF, PerFunctionMIParsingState &PFS,
0068       const PseudoSourceValue *&PSV, ErrorCallbackType ErrorCallback) const {
0069     llvm_unreachable(
0070         "target did not implement parsing MIR custom pseudo source value");
0071   }
0072 
0073   /// Helper functions to print IR value as MIR serialization format which will
0074   /// be useful for target specific printer, e.g. for printing IR value in
0075   /// custom pseudo source value.
0076   static void printIRValue(raw_ostream &OS, const Value &V,
0077                            ModuleSlotTracker &MST);
0078 
0079   /// Helper functions to parse IR value from MIR serialization format which
0080   /// will be useful for target specific parser, e.g. for parsing IR value for
0081   /// custom pseudo source value.
0082   static bool parseIRValue(StringRef Src, MachineFunction &MF,
0083                            PerFunctionMIParsingState &PFS, const Value *&V,
0084                            ErrorCallbackType ErrorCallback);
0085 };
0086 
0087 } // end namespace llvm
0088 
0089 #endif