1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-10-19 02:52:53 +02:00

[ThinLTO] Serialize the Module SourceFileName to/from LLVM assembly

Summary:
This change serializes out and in the SourceFileName to LLVM assembly
so that it is preserved through "llvm-dis | llvm-as". This is
necessary to ensure that the global identifiers created for local values
in the module summary index are the same even if the bitcode is
streamed out and read back from LLVM assembly.

Serializing the summary itself to LLVM assembly is in progress.

Reviewers: joker.eph

Subscribers: llvm-commits, joker.eph

Differential Revision: http://reviews.llvm.org/D18588

llvm-svn: 264869
This commit is contained in:
Teresa Johnson 2016-03-30 14:00:02 +00:00
parent a48ee9f67e
commit a54f488a6d
6 changed files with 31 additions and 0 deletions

View File

@ -533,6 +533,7 @@ lltok::Kind LLLexer::LexIdentifier() {
KEYWORD(notail);
KEYWORD(target);
KEYWORD(triple);
KEYWORD(source_filename);
KEYWORD(unwind);
KEYWORD(deplibs); // FIXME: Remove in 4.0.
KEYWORD(datalayout);

View File

@ -239,6 +239,10 @@ bool LLParser::ParseTopLevelEntities() {
case lltok::kw_define: if (ParseDefine()) return true; break;
case lltok::kw_module: if (ParseModuleAsm()) return true; break;
case lltok::kw_target: if (ParseTargetDefinition()) return true; break;
case lltok::kw_source_filename:
if (ParseSourceFileName())
return true;
break;
case lltok::kw_deplibs: if (ParseDepLibs()) return true; break;
case lltok::LocalVarID: if (ParseUnnamedType()) return true; break;
case lltok::LocalVar: if (ParseNamedType()) return true; break;
@ -335,6 +339,19 @@ bool LLParser::ParseTargetDefinition() {
}
}
/// toplevelentity
/// ::= 'source_filename' '=' STRINGCONSTANT
bool LLParser::ParseSourceFileName() {
assert(Lex.getKind() == lltok::kw_source_filename);
std::string Str;
Lex.Lex();
if (ParseToken(lltok::equal, "expected '=' after source_filename") ||
ParseStringConstant(Str))
return true;
M->setSourceFileName(Str);
return false;
}
/// toplevelentity
/// ::= 'deplibs' '=' '[' ']'
/// ::= 'deplibs' '=' '[' STRINGCONSTANT (',' STRINGCONSTANT)* ']'

View File

@ -261,6 +261,7 @@ namespace llvm {
bool ValidateEndOfModule();
bool ParseTargetDefinition();
bool ParseModuleAsm();
bool ParseSourceFileName();
bool ParseDepLibs(); // FIXME: Remove in 4.0.
bool ParseUnnamedType();
bool ParseNamedType();

View File

@ -59,6 +59,7 @@ namespace lltok {
kw_notail,
kw_target,
kw_triple,
kw_source_filename,
kw_unwind,
kw_deplibs, // FIXME: Remove in 4.0
kw_datalayout,

View File

@ -2215,6 +2215,9 @@ void AssemblyWriter::printModule(const Module *M) {
M->getModuleIdentifier().find('\n') == std::string::npos)
Out << "; ModuleID = '" << M->getModuleIdentifier() << "'\n";
if (!M->getSourceFileName().empty())
Out << "source_filename = \"" << M->getSourceFileName() << "\"\n";
const std::string &DL = M->getDataLayoutStr();
if (!DL.empty())
Out << "target datalayout = \"" << DL << "\"\n";

View File

@ -0,0 +1,8 @@
; Make sure that llvm-as/llvm-dis properly assemble/disassemble the
; source_filename.
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
; CHECK: source_filename = "test.cc"
source_filename = "test.cc"