diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2015-01-06 22:55:16 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2015-01-06 22:55:16 +0000 |
commit | 83a362cde8dda902ae516dbb1a721735a338abbb (patch) | |
tree | 6e0316b50f28fe0ba8628ada534b2cf4017799db /llvm/lib/AsmParser/LLParser.cpp | |
parent | ed844c4ad1e403aff4eae0799eeccd21a3a36c90 (diff) | |
download | bcm5719-llvm-83a362cde8dda902ae516dbb1a721735a338abbb.tar.gz bcm5719-llvm-83a362cde8dda902ae516dbb1a721735a338abbb.zip |
Change the .ll syntax for comdats and add a syntactic sugar.
In order to make comdats always explicit in the IR, we decided to make
the syntax a bit more compact for the case of a GlobalObject in a
comdat with the same name.
Just dropping the $name causes problems for
@foo = globabl i32 0, comdat
$bar = comdat ...
and
declare void @foo() comdat
$bar = comdat ...
So the syntax is changed to
@g1 = globabl i32 0, comdat($c1)
@g2 = globabl i32 0, comdat
and
declare void @foo() comdat($c1)
declare void @foo() comdat
llvm-svn: 225302
Diffstat (limited to 'llvm/lib/AsmParser/LLParser.cpp')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index 0ac07cc89ca..232c580b88f 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -850,7 +850,7 @@ bool LLParser::ParseGlobal(const std::string &Name, LocTy NameLoc, GV->setAlignment(Alignment); } else { Comdat *C; - if (parseOptionalComdat(C)) + if (parseOptionalComdat(Name, C)) return true; if (C) GV->setComdat(C); @@ -2899,16 +2899,26 @@ bool LLParser::ParseGlobalTypeAndValue(Constant *&V) { ParseGlobalValue(Ty, V); } -bool LLParser::parseOptionalComdat(Comdat *&C) { +bool LLParser::parseOptionalComdat(StringRef GlobalName, Comdat *&C) { C = nullptr; + + LocTy KwLoc = Lex.getLoc(); if (!EatIfPresent(lltok::kw_comdat)) return false; - if (Lex.getKind() != lltok::ComdatVar) - return TokError("expected comdat variable"); - LocTy Loc = Lex.getLoc(); - StringRef Name = Lex.getStrVal(); - C = getComdat(Name, Loc); - Lex.Lex(); + + if (EatIfPresent(lltok::lparen)) { + if (Lex.getKind() != lltok::ComdatVar) + return TokError("expected comdat variable"); + C = getComdat(Lex.getStrVal(), Lex.getLoc()); + Lex.Lex(); + if (ParseToken(lltok::rparen, "expected ')' after comdat var")) + return true; + } else { + if (GlobalName.empty()) + return TokError("comdat cannot be unnamed"); + C = getComdat(GlobalName, KwLoc); + } + return false; } @@ -3262,7 +3272,7 @@ bool LLParser::ParseFunctionHeader(Function *&Fn, bool isDefine) { BuiltinLoc) || (EatIfPresent(lltok::kw_section) && ParseStringConstant(Section)) || - parseOptionalComdat(C) || + parseOptionalComdat(FunctionName, C) || ParseOptionalAlignment(Alignment) || (EatIfPresent(lltok::kw_gc) && ParseStringConstant(GC)) || |