diff options
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.cpp | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MILexer.h | 1 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRParser/MIParser.cpp | 265 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MIRPrinter.cpp | 27 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineInstr.cpp | 19 | ||||
-rw-r--r-- | llvm/lib/CodeGen/MachineOperand.cpp | 57 | ||||
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp | 2 | ||||
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 5 |
8 files changed, 117 insertions, 260 deletions
diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 0c35a91f828..21511586ff1 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -242,7 +242,6 @@ static MIToken::TokenKind getIdentifierKind(StringRef Identifier) { .Case("jump-table", MIToken::kw_jump_table) .Case("constant-pool", MIToken::kw_constant_pool) .Case("call-entry", MIToken::kw_call_entry) - .Case("custom", MIToken::kw_custom) .Case("liveout", MIToken::kw_liveout) .Case("address-taken", MIToken::kw_address_taken) .Case("landing-pad", MIToken::kw_landing_pad) diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index af5327cacfe..1e2eba91ceb 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -110,7 +110,6 @@ struct MIToken { kw_jump_table, kw_constant_pool, kw_call_entry, - kw_custom, kw_liveout, kw_address_taken, kw_landing_pad, diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index 0f2648e2bfa..525c70016a0 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -28,7 +28,6 @@ #include "llvm/AsmParser/SlotMapping.h" #include "llvm/CodeGen/GlobalISel/RegisterBank.h" #include "llvm/CodeGen/GlobalISel/RegisterBankInfo.h" -#include "llvm/CodeGen/MIRFormatter.h" #include "llvm/CodeGen/MIRPrinter.h" #include "llvm/CodeGen/MachineBasicBlock.h" #include "llvm/CodeGen/MachineFrameInfo.h" @@ -344,37 +343,6 @@ VRegInfo &PerFunctionMIParsingState::getVRegInfoNamed(StringRef RegName) { return *I.first->second; } -static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST, - DenseMap<unsigned, const Value *> &Slots2Values) { - int Slot = MST.getLocalSlot(V); - if (Slot == -1) - return; - Slots2Values.insert(std::make_pair(unsigned(Slot), V)); -} - -/// Creates the mapping from slot numbers to function's unnamed IR values. -static void initSlots2Values(const Function &F, - DenseMap<unsigned, const Value *> &Slots2Values) { - ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false); - MST.incorporateFunction(F); - for (const auto &Arg : F.args()) - mapValueToSlot(&Arg, MST, Slots2Values); - for (const auto &BB : F) { - mapValueToSlot(&BB, MST, Slots2Values); - for (const auto &I : BB) - mapValueToSlot(&I, MST, Slots2Values); - } -} - -const Value* PerFunctionMIParsingState::getIRValue(unsigned Slot) { - if (Slots2Values.empty()) - initSlots2Values(MF.getFunction(), Slots2Values); - auto ValueInfo = Slots2Values.find(Slot); - if (ValueInfo == Slots2Values.end()) - return nullptr; - return ValueInfo->second; -} - namespace { /// A wrapper struct around the 'MachineOperand' struct that includes a source @@ -402,6 +370,8 @@ class MIParser { PerFunctionMIParsingState &PFS; /// Maps from slot numbers to function's unnamed basic blocks. DenseMap<unsigned, const BasicBlock *> Slots2BasicBlocks; + /// Maps from slot numbers to function's unnamed values. + DenseMap<unsigned, const Value *> Slots2Values; public: MIParser(PerFunctionMIParsingState &PFS, SMDiagnostic &Error, @@ -485,12 +455,9 @@ public: bool parseTargetIndexOperand(MachineOperand &Dest); bool parseCustomRegisterMaskOperand(MachineOperand &Dest); bool parseLiveoutRegisterMaskOperand(MachineOperand &Dest); - bool parseMachineOperand(const unsigned OpCode, const unsigned OpIdx, - MachineOperand &Dest, + bool parseMachineOperand(MachineOperand &Dest, Optional<unsigned> &TiedDefIdx); - bool parseMachineOperandAndTargetFlags(const unsigned OpCode, - const unsigned OpIdx, - MachineOperand &Dest, + bool parseMachineOperandAndTargetFlags(MachineOperand &Dest, Optional<unsigned> &TiedDefIdx); bool parseOffset(int64_t &Offset); bool parseAlignment(unsigned &Alignment); @@ -506,9 +473,6 @@ public: bool parsePreOrPostInstrSymbol(MCSymbol *&Symbol); bool parseHeapAllocMarker(MDNode *&Node); - bool parseTargetImmMnemonic(const unsigned OpCode, const unsigned OpIdx, - MachineOperand &Dest, const MIRFormatter &MF); - private: /// Convert the integer literal in the current token into an unsigned integer. /// @@ -587,9 +551,6 @@ bool MIParser::error(StringRef::iterator Loc, const Twine &Msg) { return true; } -typedef function_ref<bool(StringRef::iterator Loc, const Twine &)> - ErrorCallbackType; - static const char *toString(MIToken::TokenKind TokenKind) { switch (TokenKind) { case MIToken::comma: @@ -951,7 +912,7 @@ bool MIParser::parse(MachineInstr *&MI) { Token.isNot(MIToken::coloncolon) && Token.isNot(MIToken::lbrace)) { auto Loc = Token.location(); Optional<unsigned> TiedDefIdx; - if (parseMachineOperandAndTargetFlags(OpCode, Operands.size(), MO, TiedDefIdx)) + if (parseMachineOperandAndTargetFlags(MO, TiedDefIdx)) return true; if (OpCode == TargetOpcode::DBG_VALUE && MO.isReg()) MO.setIsDebug(); @@ -1532,61 +1493,17 @@ bool MIParser::parseImmediateOperand(MachineOperand &Dest) { return false; } -bool MIParser::parseTargetImmMnemonic(const unsigned OpCode, - const unsigned OpIdx, - MachineOperand &Dest, - const MIRFormatter &MF) { - assert(Token.is(MIToken::dot)); - auto Loc = Token.location(); // record start position - size_t Len = 1; // for "." - lex(); - - // Handle the case that mnemonic starts with number. - if (Token.is(MIToken::IntegerLiteral)) { - Len += Token.range().size(); - lex(); - } - - StringRef Src; - if (Token.is(MIToken::comma)) - Src = StringRef(Loc, Len); - else { - assert(Token.is(MIToken::Identifier)); - Src = StringRef(Loc, Len + Token.stringValue().size()); - } - int64_t Val; - if (MF.parseImmMnemonic(OpCode, OpIdx, Src, Val, - [this](StringRef::iterator Loc, const Twine &Msg) - -> bool { return error(Loc, Msg); })) - return true; - - Dest = MachineOperand::CreateImm(Val); - if (!Token.is(MIToken::comma)) - lex(); - return false; -} - -static bool parseIRConstant(StringRef::iterator Loc, StringRef StringValue, - PerFunctionMIParsingState &PFS, const Constant *&C, - ErrorCallbackType ErrCB) { +bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue, + const Constant *&C) { auto Source = StringValue.str(); // The source has to be null terminated. SMDiagnostic Err; - C = parseConstantValue(Source, Err, *PFS.MF.getFunction().getParent(), + C = parseConstantValue(Source, Err, *MF.getFunction().getParent(), &PFS.IRSlots); if (!C) - return ErrCB(Loc + Err.getColumnNo(), Err.getMessage()); + return error(Loc + Err.getColumnNo(), Err.getMessage()); return false; } -bool MIParser::parseIRConstant(StringRef::iterator Loc, StringRef StringValue, - const Constant *&C) { - return ::parseIRConstant( - Loc, StringValue, PFS, C, - [this](StringRef::iterator Loc, const Twine &Msg) -> bool { - return error(Loc, Msg); - }); -} - bool MIParser::parseIRConstant(StringRef::iterator Loc, const Constant *&C) { if (parseIRConstant(Loc, StringRef(Loc, Token.range().end() - Loc), C)) return true; @@ -1719,52 +1636,27 @@ bool MIParser::parseFPImmediateOperand(MachineOperand &Dest) { return false; } -static bool getHexUint(const MIToken &Token, APInt &Result) { - assert(Token.is(MIToken::HexLiteral)); - StringRef S = Token.range(); - assert(S[0] == '0' && tolower(S[1]) == 'x'); - // This could be a floating point literal with a special prefix. - if (!isxdigit(S[2])) - return true; - StringRef V = S.substr(2); - APInt A(V.size()*4, V, 16); - - // If A is 0, then A.getActiveBits() is 0. This isn't a valid bitwidth. Make - // sure it isn't the case before constructing result. - unsigned NumBits = (A == 0) ? 32 : A.getActiveBits(); - Result = APInt(NumBits, ArrayRef<uint64_t>(A.getRawData(), A.getNumWords())); - return false; -} - -bool getUnsigned(const MIToken &Token, unsigned &Result, - ErrorCallbackType ErrCB) { +bool MIParser::getUnsigned(unsigned &Result) { if (Token.hasIntegerValue()) { const uint64_t Limit = uint64_t(std::numeric_limits<unsigned>::max()) + 1; uint64_t Val64 = Token.integerValue().getLimitedValue(Limit); if (Val64 == Limit) - return ErrCB(Token.location(), "expected 32-bit integer (too large)"); + return error("expected 32-bit integer (too large)"); Result = Val64; return false; } if (Token.is(MIToken::HexLiteral)) { APInt A; - if (getHexUint(Token, A)) + if (getHexUint(A)) return true; if (A.getBitWidth() > 32) - return ErrCB(Token.location(), "expected 32-bit integer (too large)"); + return error("expected 32-bit integer (too large)"); Result = A.getZExtValue(); return false; } return true; } -bool MIParser::getUnsigned(unsigned &Result) { - return ::getUnsigned( - Token, Result, [this](StringRef::iterator Loc, const Twine &Msg) -> bool { - return error(Loc, Msg); - }); -} - bool MIParser::parseMBBReference(MachineBasicBlock *&MBB) { assert(Token.is(MIToken::MachineBasicBlock) || Token.is(MIToken::MachineBasicBlockLabel)); @@ -1844,25 +1736,23 @@ bool MIParser::parseFixedStackObjectOperand(MachineOperand &Dest) { return false; } -static bool parseGlobalValue(const MIToken &Token, - PerFunctionMIParsingState &PFS, GlobalValue *&GV, - ErrorCallbackType ErrCB) { +bool MIParser::parseGlobalValue(GlobalValue *&GV) { switch (Token.kind()) { case MIToken::NamedGlobalValue: { - const Module *M = PFS.MF.getFunction().getParent(); + const Module *M = MF.getFunction().getParent(); GV = M->getNamedValue(Token.stringValue()); if (!GV) - return ErrCB(Token.location(), Twine("use of undefined global value '") + - Token.range() + "'"); + return error(Twine("use of undefined global value '") + Token.range() + + "'"); break; } case MIToken::GlobalValue: { unsigned GVIdx; - if (getUnsigned(Token, GVIdx, ErrCB)) + if (getUnsigned(GVIdx)) return true; if (GVIdx >= PFS.IRSlots.GlobalValues.size()) - return ErrCB(Token.location(), Twine("use of undefined global value '@") + - Twine(GVIdx) + "'"); + return error(Twine("use of undefined global value '@") + Twine(GVIdx) + + "'"); GV = PFS.IRSlots.GlobalValues[GVIdx]; break; } @@ -1872,14 +1762,6 @@ static bool parseGlobalValue(const MIToken &Token, return false; } -bool MIParser::parseGlobalValue(GlobalValue *&GV) { - return ::parseGlobalValue( - Token, PFS, GV, - [this](StringRef::iterator Loc, const Twine &Msg) -> bool { - return error(Loc, Msg); - }); -} - bool MIParser::parseGlobalAddressOperand(MachineOperand &Dest) { GlobalValue *GV = nullptr; if (parseGlobalValue(GV)) @@ -2528,8 +2410,7 @@ bool MIParser::parseLiveoutRegisterMaskOperand(MachineOperand &Dest) { return false; } -bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx, - MachineOperand &Dest, +bool MIParser::parseMachineOperand(MachineOperand &Dest, Optional<unsigned> &TiedDefIdx) { switch (Token.kind()) { case MIToken::kw_implicit: @@ -2618,12 +2499,6 @@ bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx, return parseCustomRegisterMaskOperand(Dest); } else return parseTypedImmediateOperand(Dest); - case MIToken::dot: { - if (const auto *Formatter = MF.getTarget().getMIRFormatter()) { - return parseTargetImmMnemonic(OpCode, OpIdx, Dest, *Formatter); - } - LLVM_FALLTHROUGH; - } default: // FIXME: Parse the MCSymbol machine operand. return error("expected a machine operand"); @@ -2632,8 +2507,7 @@ bool MIParser::parseMachineOperand(const unsigned OpCode, const unsigned OpIdx, } bool MIParser::parseMachineOperandAndTargetFlags( - const unsigned OpCode, const unsigned OpIdx, MachineOperand &Dest, - Optional<unsigned> &TiedDefIdx) { + MachineOperand &Dest, Optional<unsigned> &TiedDefIdx) { unsigned TF = 0; bool HasTargetFlags = false; if (Token.is(MIToken::kw_target_flags)) { @@ -2665,7 +2539,7 @@ bool MIParser::parseMachineOperandAndTargetFlags( return true; } auto Loc = Token.location(); - if (parseMachineOperand(OpCode, OpIdx, Dest, TiedDefIdx)) + if (parseMachineOperand(Dest, TiedDefIdx)) return true; if (!HasTargetFlags) return false; @@ -2726,31 +2600,30 @@ bool MIParser::parseOperandsOffset(MachineOperand &Op) { return false; } -static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS, - const Value *&V, ErrorCallbackType ErrCB) { +bool MIParser::parseIRValue(const Value *&V) { switch (Token.kind()) { case MIToken::NamedIRValue: { - V = PFS.MF.getFunction().getValueSymbolTable()->lookup(Token.stringValue()); + V = MF.getFunction().getValueSymbolTable()->lookup(Token.stringValue()); break; } case MIToken::IRValue: { unsigned SlotNumber = 0; - if (getUnsigned(Token, SlotNumber, ErrCB)) + if (getUnsigned(SlotNumber)) return true; - V = PFS.getIRValue(SlotNumber); + V = getIRValue(SlotNumber); break; } case MIToken::NamedGlobalValue: case MIToken::GlobalValue: { GlobalValue *GV = nullptr; - if (parseGlobalValue(Token, PFS, GV, ErrCB)) + if (parseGlobalValue(GV)) return true; V = GV; break; } case MIToken::QuotedIRValue: { const Constant *C = nullptr; - if (parseIRConstant(Token.location(), Token.stringValue(), PFS, C, ErrCB)) + if (parseIRConstant(Token.location(), Token.stringValue(), C)) return true; V = C; break; @@ -2759,17 +2632,10 @@ static bool parseIRValue(const MIToken &Token, PerFunctionMIParsingState &PFS, llvm_unreachable("The current token should be an IR block reference"); } if (!V) - return ErrCB(Token.location(), Twine("use of undefined IR value '") + Token.range() + "'"); + return error(Twine("use of undefined IR value '") + Token.range() + "'"); return false; } -bool MIParser::parseIRValue(const Value *&V) { - return ::parseIRValue( - Token, PFS, V, [this](StringRef::iterator Loc, const Twine &Msg) -> bool { - return error(Loc, Msg); - }); -} - bool MIParser::getUint64(uint64_t &Result) { if (Token.hasIntegerValue()) { if (Token.integerValue().getActiveBits() > 64) @@ -2790,7 +2656,20 @@ bool MIParser::getUint64(uint64_t &Result) { } bool MIParser::getHexUint(APInt &Result) { - return ::getHexUint(Token, Result); + assert(Token.is(MIToken::HexLiteral)); + StringRef S = Token.range(); + assert(S[0] == '0' && tolower(S[1]) == 'x'); + // This could be a floating point literal with a special prefix. + if (!isxdigit(S[2])) + return true; + StringRef V = S.substr(2); + APInt A(V.size()*4, V, 16); + + // If A is 0, then A.getActiveBits() is 0. This isn't a valid bitwidth. Make + // sure it isn't the case before constructing result. + unsigned NumBits = (A == 0) ? 32 : A.getActiveBits(); + Result = APInt(NumBits, ArrayRef<uint64_t>(A.getRawData(), A.getNumWords())); + return false; } bool MIParser::parseMemoryOperandFlag(MachineMemOperand::Flags &Flags) { @@ -2877,19 +2756,6 @@ bool MIParser::parseMemoryPseudoSourceValue(const PseudoSourceValue *&PSV) { "expected a global value or an external symbol after 'call-entry'"); } break; - case MIToken::kw_custom: { - lex(); - if (const auto *Formatter = MF.getTarget().getMIRFormatter()) { - if (Formatter->parseCustomPseudoSourceValue( - Token.stringValue(), MF, PFS, PSV, - [this](StringRef::iterator Loc, const Twine &Msg) -> bool { - return error(Loc, Msg); - })) - return true; - } else - return error("unable to parse target custom pseudo source value"); - break; - } default: llvm_unreachable("The current token should be pseudo source value"); } @@ -2901,7 +2767,7 @@ bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) { if (Token.is(MIToken::kw_constant_pool) || Token.is(MIToken::kw_stack) || Token.is(MIToken::kw_got) || Token.is(MIToken::kw_jump_table) || Token.is(MIToken::FixedStackObject) || Token.is(MIToken::StackObject) || - Token.is(MIToken::kw_call_entry) || Token.is(MIToken::kw_custom)) { + Token.is(MIToken::kw_call_entry)) { const PseudoSourceValue *PSV = nullptr; if (parseMemoryPseudoSourceValue(PSV)) return true; @@ -3152,8 +3018,35 @@ const BasicBlock *MIParser::getIRBlock(unsigned Slot, const Function &F) { return getIRBlockFromSlot(Slot, CustomSlots2BasicBlocks); } +static void mapValueToSlot(const Value *V, ModuleSlotTracker &MST, + DenseMap<unsigned, const Value *> &Slots2Values) { + int Slot = MST.getLocalSlot(V); + if (Slot == -1) + return; + Slots2Values.insert(std::make_pair(unsigned(Slot), V)); +} + +/// Creates the mapping from slot numbers to function's unnamed IR values. +static void initSlots2Values(const Function &F, + DenseMap<unsigned, const Value *> &Slots2Values) { + ModuleSlotTracker MST(F.getParent(), /*ShouldInitializeAllMetadata=*/false); + MST.incorporateFunction(F); + for (const auto &Arg : F.args()) + mapValueToSlot(&Arg, MST, Slots2Values); + for (const auto &BB : F) { + mapValueToSlot(&BB, MST, Slots2Values); + for (const auto &I : BB) + mapValueToSlot(&I, MST, Slots2Values); + } +} + const Value *MIParser::getIRValue(unsigned Slot) { - return PFS.getIRValue(Slot); + if (Slots2Values.empty()) + initSlots2Values(MF.getFunction(), Slots2Values); + auto ValueInfo = Slots2Values.find(Slot); + if (ValueInfo == Slots2Values.end()) + return nullptr; + return ValueInfo->second; } MCSymbol *MIParser::getOrCreateMCSymbol(StringRef Name) { @@ -3218,15 +3111,3 @@ bool llvm::parseMDNode(PerFunctionMIParsingState &PFS, MDNode *&Node, StringRef Src, SMDiagnostic &Error) { return MIParser(PFS, Error, Src).parseStandaloneMDNode(Node); } - -bool MIRFormatter::parseIRValue(StringRef Src, MachineFunction &MF, - PerFunctionMIParsingState &PFS, const Value *&V, - ErrorCallbackType ErrorCallback) { - MIToken Token; - Src = lexMIToken(Src, Token, [&](StringRef::iterator Loc, const Twine &Msg) { - ErrorCallback(Loc, Msg); - }); - V = nullptr; - - return ::parseIRValue(Token, PFS, V, ErrorCallback); -} diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index 9d9c12a9591..b06e34a809f 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -709,7 +709,6 @@ void MIPrinter::print(const MachineInstr &MI) { 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 @@ void MIPrinter::print(const MachineInstr &MI) { 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; } } @@ -857,7 +856,7 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx, if (ShouldPrintRegisterTies && Op.isReg() && Op.isTied() && !Op.isDef()) TiedOperandIdx = Op.getParent()->findTiedOperandIdx(OpIdx); const TargetIntrinsicInfo *TII = MI.getMF()->getTarget().getIntrinsicInfo(); - Op.print(OS, MST, TypeToPrint, OpIdx, PrintDef, /*IsStandalone=*/false, + Op.print(OS, MST, TypeToPrint, PrintDef, /*IsStandalone=*/false, ShouldPrintRegisterTies, TiedOperandIdx, TRI, TII); break; } @@ -875,28 +874,6 @@ void MIPrinter::print(const MachineInstr &MI, unsigned OpIdx, } } -void MIRFormatter::printIRValue(raw_ostream &OS, const Value &V, - ModuleSlotTracker &MST) { - if (isa<GlobalValue>(V)) { - V.printAsOperand(OS, /*PrintType=*/false, MST); - return; - } - if (isa<Constant>(V)) { - // Machine memory operands can load/store to/from constant value pointers. - OS << '`'; - V.printAsOperand(OS, /*PrintType=*/true, MST); - OS << '`'; - return; - } - OS << "%ir."; - if (V.hasName()) { - printLLVMNameWithoutPrefix(OS, V.getName()); - return; - } - int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1; - MachineOperand::printIRSlotNumber(OS, Slot); -} - void llvm::printMIR(raw_ostream &OS, const Module &M) { yaml::Output Out(OS); Out << const_cast<Module &>(M); diff --git a/llvm/lib/CodeGen/MachineInstr.cpp b/llvm/lib/CodeGen/MachineInstr.cpp index 177fef80e2e..16ae732169a 100644 --- a/llvm/lib/CodeGen/MachineInstr.cpp +++ b/llvm/lib/CodeGen/MachineInstr.cpp @@ -89,15 +89,13 @@ static void tryToGetTargetInfo(const MachineInstr &MI, 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 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, 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"); @@ -1509,7 +1506,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, LLT TypeToPrint = MRI ? getTypeToPrint(StartOp, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(StartOp); - MO.print(OS, MST, TypeToPrint, StartOp, /*PrintDef=*/false, IsStandalone, + MO.print(OS, MST, TypeToPrint, /*PrintDef=*/false, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); ++StartOp; } @@ -1564,7 +1561,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, const unsigned OpIdx = InlineAsm::MIOp_AsmString; LLT TypeToPrint = MRI ? getTypeToPrint(OpIdx, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(OpIdx); - getOperand(OpIdx).print(OS, MST, TypeToPrint, OpIdx, /*PrintDef=*/true, IsStandalone, + getOperand(OpIdx).print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); @@ -1603,7 +1600,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, else { LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(i); - MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } else if (isDebugLabel() && MO.isMetadata()) { @@ -1614,7 +1611,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, else { LLT TypeToPrint = MRI ? getTypeToPrint(i, PrintedTypes, *MRI) : LLT{}; unsigned TiedOperandIdx = getTiedOperandIdx(i); - MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } else if (i == AsmDescOp && MO.isImm()) { @@ -1681,7 +1678,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, if (MO.isImm() && isOperandSubregIdx(i)) MachineOperand::printSubRegIdx(OS, MO.getImm(), TRI); else - MO.print(OS, MST, TypeToPrint, i, /*PrintDef=*/true, IsStandalone, + MO.print(OS, MST, TypeToPrint, /*PrintDef=*/true, IsStandalone, ShouldPrintRegisterTies, TiedOperandIdx, TRI, IntrinsicInfo); } } @@ -1740,7 +1737,7 @@ void MachineInstr::print(raw_ostream &OS, ModuleSlotTracker &MST, 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 index 5dd98467ba6..8b19501ec3c 100644 --- a/llvm/lib/CodeGen/MachineOperand.cpp +++ b/llvm/lib/CodeGen/MachineOperand.cpp @@ -14,7 +14,6 @@ #include "llvm/ADT/StringExtras.h" #include "llvm/Analysis/Loads.h" #include "llvm/Analysis/MemoryLocation.h" -#include "llvm/CodeGen/MIRFormatter.h" #include "llvm/CodeGen/MIRPrinter.h" #include "llvm/CodeGen/MachineFrameInfo.h" #include "llvm/CodeGen/MachineJumpTableInfo.h" @@ -459,6 +458,28 @@ static void printIRBlockReference(raw_ostream &OS, const BasicBlock &BB, OS << "<unknown>"; } +static void printIRValueReference(raw_ostream &OS, const Value &V, + ModuleSlotTracker &MST) { + if (isa<GlobalValue>(V)) { + V.printAsOperand(OS, /*PrintType=*/false, MST); + return; + } + if (isa<Constant>(V)) { + // Machine memory operands can load/store to/from constant value pointers. + OS << '`'; + V.printAsOperand(OS, /*PrintType=*/true, MST); + OS << '`'; + return; + } + OS << "%ir."; + if (V.hasName()) { + printLLVMNameWithoutPrefix(OS, V.getName()); + return; + } + int Slot = MST.getCurrentFunction() ? MST.getLocalSlot(&V) : -1; + MachineOperand::printIRSlotNumber(OS, Slot); +} + static void printSyncScope(raw_ostream &OS, const LLVMContext &Context, SyncScope::ID SSID, SmallVectorImpl<StringRef> &SSNs) { @@ -713,15 +734,14 @@ void MachineOperand::print(raw_ostream &OS, LLT TypeToPrint, const TargetIntrinsicInfo *IntrinsicInfo) const { tryToGetTargetInfo(*this, TRI, IntrinsicInfo); ModuleSlotTracker DummyMST(nullptr); - print(OS, DummyMST, TypeToPrint, None, /*PrintDef=*/false, - /*IsStandalone=*/true, + print(OS, DummyMST, TypeToPrint, /*PrintDef=*/false, /*IsStandalone=*/true, /*ShouldPrintRegisterTies=*/true, /*TiedOperandIdx=*/0, TRI, IntrinsicInfo); } void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, - LLT TypeToPrint, Optional<unsigned> OpIdx, bool PrintDef, - bool IsStandalone, bool ShouldPrintRegisterTies, + LLT TypeToPrint, bool PrintDef, bool IsStandalone, + bool ShouldPrintRegisterTies, unsigned TiedOperandIdx, const TargetRegisterInfo *TRI, const TargetIntrinsicInfo *IntrinsicInfo) const { @@ -782,16 +802,9 @@ void MachineOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, OS << '(' << TypeToPrint << ')'; break; } - case MachineOperand::MO_Immediate: { - const MIRFormatter *Formatter = nullptr; - if (const MachineFunction *MF = getMFIfAvailable(*this)) - Formatter = MF->getTarget().getMIRFormatter(); - if (Formatter) - Formatter->printImm(OS, *getParent(), OpIdx, getImm()); - else - OS << getImm(); + case MachineOperand::MO_Immediate: + OS << getImm(); break; - } case MachineOperand::MO_CImmediate: getCImm()->printAsOperand(OS, /*PrintType=*/true, MST); break; @@ -1057,8 +1070,7 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, SmallVectorImpl<StringRef> &SSNs, const LLVMContext &Context, const MachineFrameInfo *MFI, - const TargetInstrInfo *TII, - const MIRFormatter* MIRF) const { + const TargetInstrInfo *TII) const { OS << '('; if (isVolatile()) OS << "volatile "; @@ -1099,7 +1111,7 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, if (const Value *Val = getValue()) { OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into "); - MIRFormatter::printIRValue(OS, *Val, MST); + printIRValueReference(OS, *Val, MST); } else if (const PseudoSourceValue *PVal = getPseudoValue()) { OS << ((isLoad() && isStore()) ? " on " : isLoad() ? " from " : " into "); assert(PVal && "Expected a pseudo source value"); @@ -1132,20 +1144,15 @@ void MachineMemOperand::print(raw_ostream &OS, ModuleSlotTracker &MST, printLLVMNameWithoutPrefix( OS, cast<ExternalSymbolPseudoSourceValue>(PVal)->getSymbol()); break; - default: { + default: // 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); - OS << '\"'; + OS << "custom "; + PVal->printCustom(OS); break; } - } } MachineOperand::printOperandOffset(OS, getOffset()); if (getBaseAlignment() != getSize()) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp index a12d708c2dd..6fd71393bf3 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGDumper.cpp @@ -480,7 +480,7 @@ static void printMemOperand(raw_ostream &OS, const MachineMemOperand &MMO, if (MF) MST.incorporateFunction(MF->getFunction()); SmallVector<StringRef, 0> SSNs; - MMO.print(OS, MST, SSNs, Ctx, MFI, TII, MF->getTarget().getMIRFormatter()); + 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 index f070b143d5b..97a1eb2f190 100644 --- 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 @@ TargetMachine::TargetMachine(const Target &T, StringRef DataLayoutString, : 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<MIRFormatter>(); -} + DefaultOptions(Options), Options(Options) {} TargetMachine::~TargetMachine() = default; |