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 | f907a26bc28c1c2e9e7026815a5271bc393d2933 (patch) | |
tree | 331be722fdac69ed3a6d89a5d270e5e8dfc28c24 /lib/IR | |
parent | 8e9ba0e588096d9d8c680999c83350a989bd709d (diff) |
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@225302 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/IR')
-rw-r--r-- | lib/IR/AsmWriter.cpp | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/lib/IR/AsmWriter.cpp b/lib/IR/AsmWriter.cpp index e883cba7f9d..175e20f9794 100644 --- a/lib/IR/AsmWriter.cpp +++ b/lib/IR/AsmWriter.cpp @@ -1683,6 +1683,24 @@ static void PrintThreadLocalModel(GlobalVariable::ThreadLocalMode TLM, } } +static void maybePrintComdat(formatted_raw_ostream &Out, + const GlobalObject &GO) { + const Comdat *C = GO.getComdat(); + if (!C) + return; + + if (isa<GlobalVariable>(GO)) + Out << ','; + Out << " comdat"; + + if (GO.getName() == C->getName()) + return; + + Out << '('; + PrintLLVMName(Out, C->getName(), ComdatPrefix); + Out << ')'; +} + void AssemblyWriter::printGlobal(const GlobalVariable *GV) { if (GV->isMaterializable()) Out << "; Materializable\n"; @@ -1716,10 +1734,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { PrintEscapedString(GV->getSection(), Out); Out << '"'; } - if (GV->hasComdat()) { - Out << ", comdat "; - PrintLLVMName(Out, GV->getComdat()->getName(), ComdatPrefix); - } + maybePrintComdat(Out, *GV); if (GV->getAlignment()) Out << ", align " << GV->getAlignment(); @@ -1900,10 +1915,7 @@ void AssemblyWriter::printFunction(const Function *F) { PrintEscapedString(F->getSection(), Out); Out << '"'; } - if (F->hasComdat()) { - Out << " comdat "; - PrintLLVMName(Out, F->getComdat()->getName(), ComdatPrefix); - } + maybePrintComdat(Out, *F); if (F->getAlignment()) Out << " align " << F->getAlignment(); if (F->hasGC()) |