From c1136ef3b843a6b0ced314f29e85aa88ca0cf7fd Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Fri, 21 Aug 2015 21:54:12 +0000 Subject: MIR Serialization: Serialize the pointer IR expression values in the machine memory operands. llvm-svn: 245745 --- llvm/lib/CodeGen/MIRParser/MILexer.cpp | 26 ++++++++++++++++++++++++++ llvm/lib/CodeGen/MIRParser/MILexer.h | 3 ++- llvm/lib/CodeGen/MIRParser/MIParser.cpp | 13 +++++++++++-- llvm/lib/CodeGen/MIRPrinter.cpp | 13 +++++++------ 4 files changed, 46 insertions(+), 9 deletions(-) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.cpp b/llvm/lib/CodeGen/MIRParser/MILexer.cpp index 8346ff294e4..28f9d4e298f 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.cpp +++ b/llvm/lib/CodeGen/MIRParser/MILexer.cpp @@ -527,6 +527,30 @@ static Cursor maybeLexNewline(Cursor C, MIToken &Token) { return C; } +static Cursor maybeLexEscapedIRValue( + Cursor C, MIToken &Token, + function_ref ErrorCallback) { + if (C.peek() != '`') + return None; + auto Range = C; + C.advance(); + auto StrRange = C; + while (C.peek() != '`') { + if (C.isEOF() || isNewlineChar(C.peek())) { + ErrorCallback( + C.location(), + "end of machine instruction reached before the closing '`'"); + Token.reset(MIToken::Error, Range.remaining()); + return C; + } + C.advance(); + } + StringRef Value = StrRange.upto(C); + C.advance(); + Token.reset(MIToken::QuotedIRValue, Range.upto(C)).setStringValue(Value); + return C; +} + StringRef llvm::lexMIToken( StringRef Source, MIToken &Token, function_ref ErrorCallback) { @@ -570,6 +594,8 @@ StringRef llvm::lexMIToken( return R.remaining(); if (Cursor R = maybeLexNewline(C, Token)) return R.remaining(); + if (Cursor R = maybeLexEscapedIRValue(C, Token, ErrorCallback)) + return R.remaining(); Token.reset(MIToken::Error, C.remaining()); ErrorCallback(C.location(), diff --git a/llvm/lib/CodeGen/MIRParser/MILexer.h b/llvm/lib/CodeGen/MIRParser/MILexer.h index 35c526be812..ff54aa3554d 100644 --- a/llvm/lib/CodeGen/MIRParser/MILexer.h +++ b/llvm/lib/CodeGen/MIRParser/MILexer.h @@ -115,7 +115,8 @@ struct MIToken { NamedIRBlock, IRBlock, NamedIRValue, - IRValue + IRValue, + QuotedIRValue // `` }; private: diff --git a/llvm/lib/CodeGen/MIRParser/MIParser.cpp b/llvm/lib/CodeGen/MIRParser/MIParser.cpp index e7fb4378121..83ba5a2c90b 100644 --- a/llvm/lib/CodeGen/MIRParser/MIParser.cpp +++ b/llvm/lib/CodeGen/MIRParser/MIParser.cpp @@ -982,7 +982,8 @@ 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.c_str(), Err, *MF.getFunction()->getParent()); + C = parseConstantValue(Source.c_str(), Err, *MF.getFunction()->getParent(), + &IRSlots); if (!C) return error(Loc + Err.getColumnNo(), Err.getMessage()); return false; @@ -1557,6 +1558,13 @@ bool MIParser::parseIRValue(const Value *&V) { V = GV; break; } + case MIToken::QuotedIRValue: { + const Constant *C = nullptr; + if (parseIRConstant(Token.location(), Token.stringValue(), C)) + return true; + V = C; + break; + } default: llvm_unreachable("The current token should be an IR block reference"); } @@ -1662,7 +1670,8 @@ bool MIParser::parseMachinePointerInfo(MachinePointerInfo &Dest) { } if (Token.isNot(MIToken::NamedIRValue) && Token.isNot(MIToken::IRValue) && Token.isNot(MIToken::GlobalValue) && - Token.isNot(MIToken::NamedGlobalValue)) + Token.isNot(MIToken::NamedGlobalValue) && + Token.isNot(MIToken::QuotedIRValue)) return error("expected an IR value reference"); const Value *V = nullptr; if (parseIRValue(V)) diff --git a/llvm/lib/CodeGen/MIRPrinter.cpp b/llvm/lib/CodeGen/MIRPrinter.cpp index aa3d193695a..05bb320d8e6 100644 --- a/llvm/lib/CodeGen/MIRPrinter.cpp +++ b/llvm/lib/CodeGen/MIRPrinter.cpp @@ -613,17 +613,18 @@ void MIPrinter::printIRValueReference(const Value &V) { V.printAsOperand(OS, /*PrintType=*/false, MST); return; } + if (isa(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; } - if (isa(V)) { - // Machine memory operands can load/store to/from constant value pointers. - // TODO: Serialize the constant values. - OS << ""; - return; - } printIRSlotNumber(OS, MST.getLocalSlot(&V)); } -- cgit v1.2.3