diff --git a/llvm/include/llvm/CodeGen/MachineMemOperand.h b/llvm/include/llvm/CodeGen/MachineMemOperand.h --- a/llvm/include/llvm/CodeGen/MachineMemOperand.h +++ b/llvm/include/llvm/CodeGen/MachineMemOperand.h @@ -26,7 +26,6 @@ class FoldingSetNodeID; class MDNode; -class MIRFormatter; class raw_ostream; class MachineFunction; class ModuleSlotTracker; @@ -296,8 +295,7 @@ /// @{ void print(raw_ostream &OS, ModuleSlotTracker &MST, SmallVectorImpl &SSNs, const LLVMContext &Context, - const MachineFrameInfo *MFI, const TargetInstrInfo *TII, - const MIRFormatter *MIRF) const; + const MachineFrameInfo *MFI, const TargetInstrInfo *TII) const; /// @} friend bool operator==(const MachineMemOperand &LHS, diff --git a/llvm/include/llvm/CodeGen/TargetInstrInfo.h b/llvm/include/llvm/CodeGen/TargetInstrInfo.h --- a/llvm/include/llvm/CodeGen/TargetInstrInfo.h +++ b/llvm/include/llvm/CodeGen/TargetInstrInfo.h @@ -1807,6 +1807,14 @@ virtual Optional describeLoadedValue(const MachineInstr &MI, Register Reg) const; + /// Return MIR formatter to format/parse MIR operands. Target can override + /// this virtual function and return target specific MIR formatter. + virtual const MIRFormatter *getMIRFormatter() const { + if (!Formatter.get()) + Formatter = std::make_unique(); + return Formatter.get(); + } + private: mutable std::unique_ptr Formatter; unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode; diff --git a/llvm/include/llvm/Target/TargetMachine.h b/llvm/include/llvm/Target/TargetMachine.h --- a/llvm/include/llvm/Target/TargetMachine.h +++ b/llvm/include/llvm/Target/TargetMachine.h @@ -33,7 +33,6 @@ class MCRegisterInfo; class MCSubtargetInfo; class MCSymbol; -class MIRFormatter; class raw_pwrite_stream; class PassManagerBuilder; struct PerFunctionMIParsingState; @@ -95,7 +94,6 @@ std::unique_ptr MRI; std::unique_ptr MII; std::unique_ptr STI; - std::unique_ptr MIRF; unsigned RequireStructuredCFG : 1; unsigned O0WantsFastISel : 1; @@ -199,10 +197,6 @@ return nullptr; } - /// Return MIR formatter to format/parse MIR operands. Target can override - /// this virtual function and return target specific MIR formatter. - virtual const MIRFormatter *getMIRFormatter() const { return MIRF.get(); } - bool requiresStructuredCFG() const { return RequireStructuredCFG; } void setRequiresStructuredCFG(bool Value) { RequireStructuredCFG = Value; } diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -2619,7 +2619,8 @@ } else return parseTypedImmediateOperand(Dest); case MIToken::dot: { - if (const auto *Formatter = MF.getTarget().getMIRFormatter()) { + const auto *TII = MF.getSubtarget().getInstrInfo(); + if (const auto *Formatter = TII->getMIRFormatter()) { return parseTargetImmMnemonic(OpCode, OpIdx, Dest, *Formatter); } LLVM_FALLTHROUGH; @@ -2879,7 +2880,8 @@ break; case MIToken::kw_custom: { lex(); - if (const auto *Formatter = MF.getTarget().getMIRFormatter()) { + const auto *TII = MF.getSubtarget().getInstrInfo(); + if (const auto *Formatter = TII->getMIRFormatter()) { if (Formatter->parseCustomPseudoSourceValue( Token.stringValue(), MF, PFS, PSV, [this](StringRef::iterator Loc, const Twine &Msg) -> bool { diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -709,7 +709,6 @@ const auto *TRI = SubTarget.getRegisterInfo(); assert(TRI && "Expected target register info"); const auto *TII = SubTarget.getInstrInfo(); - const auto *MIRF = MF->getTarget().getMIRFormatter(); assert(TII && "Expected target instruction info"); if (MI.isCFIInstruction()) assert(MI.getNumOperands() == 1 && "Expected 1 operand in CFI instruction"); @@ -808,7 +807,7 @@ for (const auto *Op : MI.memoperands()) { if (NeedComma) OS << ", "; - Op->print(OS, MST, SSNs, Context, &MFI, TII, MIRF); + Op->print(OS, MST, SSNs, Context, &MFI, TII); NeedComma = true; } } diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -89,15 +89,13 @@ const TargetRegisterInfo *&TRI, const MachineRegisterInfo *&MRI, const TargetIntrinsicInfo *&IntrinsicInfo, - const TargetInstrInfo *&TII, - const MIRFormatter *&MIRF) { + const TargetInstrInfo *&TII) { if (const MachineFunction *MF = getMFIfAvailable(MI)) { TRI = MF->getSubtarget().getRegisterInfo(); MRI = &MF->getRegInfo(); IntrinsicInfo = MF->getTarget().getIntrinsicInfo(); TII = MF->getSubtarget().getInstrInfo(); - MIRF = MF->getTarget().getMIRFormatter(); } } @@ -1479,8 +1477,7 @@ const TargetRegisterInfo *TRI = nullptr; const MachineRegisterInfo *MRI = nullptr; const TargetIntrinsicInfo *IntrinsicInfo = nullptr; - const MIRFormatter *MIRF = nullptr; - tryToGetTargetInfo(*this, TRI, MRI, IntrinsicInfo, TII, MIRF); + tryToGetTargetInfo(*this, TRI, MRI, IntrinsicInfo, TII); if (isCFIInstruction()) assert(getNumOperands() == 1 && "Expected 1 operand in CFI instruction"); @@ -1740,7 +1737,7 @@ for (const MachineMemOperand *Op : memoperands()) { if (NeedComma) OS << ", "; - Op->print(OS, MST, SSNs, *Context, MFI, TII, MIRF); + Op->print(OS, MST, SSNs, *Context, MFI, TII); NeedComma = true; } } diff --git a/llvm/lib/CodeGen/MachineOperand.cpp b/llvm/lib/CodeGen/MachineOperand.cpp --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -784,8 +784,11 @@ } case MachineOperand::MO_Immediate: { const MIRFormatter *Formatter = nullptr; - if (const MachineFunction *MF = getMFIfAvailable(*this)) - Formatter = MF->getTarget().getMIRFormatter(); + if (const MachineFunction *MF = getMFIfAvailable(*this)) { + const auto *TII = MF->getSubtarget().getInstrInfo(); + assert(TII && "expected instruction info"); + Formatter = TII->getMIRFormatter(); + } if (Formatter) Formatter->printImm(OS, *getParent(), OpIdx, getImm()); else @@ -1057,8 +1060,7 @@ SmallVectorImpl &SSNs, const LLVMContext &Context, const MachineFrameInfo *MFI, - const TargetInstrInfo *TII, - const MIRFormatter* MIRF) const { + const TargetInstrInfo *TII) const { OS << '('; if (isVolatile()) OS << "volatile "; @@ -1133,15 +1135,13 @@ OS, cast(PVal)->getSymbol()); break; default: { + const MIRFormatter *Formatter = TII->getMIRFormatter(); // FIXME: This is not necessarily the correct MIR serialization format for // a custom pseudo source value, but at least it allows // -print-machineinstrs to work on a target with custom pseudo source // values. OS << "custom \""; - if (MIRF) - MIRF->printCustomPseudoSourceValue(OS, MST, *PVal); - else - PVal->printCustom(OS); + Formatter->printCustomPseudoSourceValue(OS, MST, *PVal); OS << '\"'; break; } diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -480,8 +480,7 @@ if (MF) MST.incorporateFunction(MF->getFunction()); SmallVector SSNs; - MMO.print(OS, MST, SSNs, Ctx, MFI, TII, - MF ? MF->getTarget().getMIRFormatter() : nullptr); + MMO.print(OS, MST, SSNs, Ctx, MFI, TII); } static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -12,7 +12,6 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Analysis/TargetTransformInfo.h" -#include "llvm/CodeGen/MIRFormatter.h" #include "llvm/IR/Function.h" #include "llvm/IR/GlobalAlias.h" #include "llvm/IR/GlobalValue.h" @@ -38,9 +37,7 @@ : TheTarget(T), DL(DataLayoutString), TargetTriple(TT), TargetCPU(CPU), TargetFS(FS), AsmInfo(nullptr), MRI(nullptr), MII(nullptr), STI(nullptr), RequireStructuredCFG(false), O0WantsFastISel(false), - DefaultOptions(Options), Options(Options) { - MIRF = std::make_unique(); -} + DefaultOptions(Options), Options(Options) {} TargetMachine::~TargetMachine() = default;