mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-25 00:24:26 +00:00
IR: Add COMDATs to the IR
This new IR facility allows us to represent the object-file semantic of a COMDAT group. COMDATs allow us to tie together sections and make the inclusion of one dependent on another. This is required to implement features like MS ABI VFTables and optimizing away certain kinds of initialization in C++. This functionality is only representable in COFF and ELF, Mach-O has no similar mechanism. Differential Revision: http://reviews.llvm.org/D4178 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211920 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -106,6 +106,7 @@ static void PrintEscapedString(StringRef Name, raw_ostream &Out) {
|
||||
|
||||
enum PrefixType {
|
||||
GlobalPrefix,
|
||||
ComdatPrefix,
|
||||
LabelPrefix,
|
||||
LocalPrefix,
|
||||
NoPrefix
|
||||
@ -119,6 +120,7 @@ static void PrintLLVMName(raw_ostream &OS, StringRef Name, PrefixType Prefix) {
|
||||
switch (Prefix) {
|
||||
case NoPrefix: break;
|
||||
case GlobalPrefix: OS << '@'; break;
|
||||
case ComdatPrefix: OS << '$'; break;
|
||||
case LabelPrefix: break;
|
||||
case LocalPrefix: OS << '%'; break;
|
||||
}
|
||||
@ -1165,8 +1167,15 @@ static void WriteAsOperandInternal(raw_ostream &Out, const Value *V,
|
||||
}
|
||||
|
||||
void AssemblyWriter::init() {
|
||||
if (TheModule)
|
||||
TypePrinter.incorporateTypes(*TheModule);
|
||||
if (!TheModule)
|
||||
return;
|
||||
TypePrinter.incorporateTypes(*TheModule);
|
||||
for (const Function &F : *TheModule)
|
||||
if (const Comdat *C = F.getComdat())
|
||||
Comdats.insert(C);
|
||||
for (const GlobalVariable &GV : TheModule->globals())
|
||||
if (const Comdat *C = GV.getComdat())
|
||||
Comdats.insert(C);
|
||||
}
|
||||
|
||||
|
||||
@ -1308,6 +1317,15 @@ void AssemblyWriter::printModule(const Module *M) {
|
||||
|
||||
printTypeIdentities();
|
||||
|
||||
// Output all comdats.
|
||||
if (!Comdats.empty())
|
||||
Out << '\n';
|
||||
for (const Comdat *C : Comdats) {
|
||||
printComdat(C);
|
||||
if (C != Comdats.back())
|
||||
Out << '\n';
|
||||
}
|
||||
|
||||
// Output all globals.
|
||||
if (!M->global_empty()) Out << '\n';
|
||||
for (Module::const_global_iterator I = M->global_begin(), E = M->global_end();
|
||||
@ -1470,6 +1488,10 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
|
||||
PrintEscapedString(GV->getSection(), Out);
|
||||
Out << '"';
|
||||
}
|
||||
if (GV->hasComdat()) {
|
||||
Out << ", comdat ";
|
||||
PrintLLVMName(Out, GV->getComdat()->getName(), ComdatPrefix);
|
||||
}
|
||||
if (GV->getAlignment())
|
||||
Out << ", align " << GV->getAlignment();
|
||||
|
||||
@ -1506,10 +1528,19 @@ void AssemblyWriter::printAlias(const GlobalAlias *GA) {
|
||||
writeOperand(Aliasee, !isa<ConstantExpr>(Aliasee));
|
||||
}
|
||||
|
||||
if (GA->hasComdat()) {
|
||||
Out << ", comdat ";
|
||||
PrintLLVMName(Out, GA->getComdat()->getName(), ComdatPrefix);
|
||||
}
|
||||
|
||||
printInfoComment(*GA);
|
||||
Out << '\n';
|
||||
}
|
||||
|
||||
void AssemblyWriter::printComdat(const Comdat *C) {
|
||||
C->print(Out);
|
||||
}
|
||||
|
||||
void AssemblyWriter::printTypeIdentities() {
|
||||
if (TypePrinter.NumberedTypes.empty() &&
|
||||
TypePrinter.NamedTypes.empty())
|
||||
@ -1647,6 +1678,10 @@ void AssemblyWriter::printFunction(const Function *F) {
|
||||
PrintEscapedString(F->getSection(), Out);
|
||||
Out << '"';
|
||||
}
|
||||
if (F->hasComdat()) {
|
||||
Out << " comdat ";
|
||||
PrintLLVMName(Out, F->getComdat()->getName(), ComdatPrefix);
|
||||
}
|
||||
if (F->getAlignment())
|
||||
Out << " align " << F->getAlignment();
|
||||
if (F->hasGC())
|
||||
@ -2158,6 +2193,31 @@ void NamedMDNode::print(raw_ostream &ROS) const {
|
||||
W.printNamedMDNode(this);
|
||||
}
|
||||
|
||||
void Comdat::print(raw_ostream &ROS) const {
|
||||
PrintLLVMName(ROS, getName(), ComdatPrefix);
|
||||
ROS << " = comdat ";
|
||||
|
||||
switch (getSelectionKind()) {
|
||||
case Comdat::Any:
|
||||
ROS << "any";
|
||||
break;
|
||||
case Comdat::ExactMatch:
|
||||
ROS << "exactmatch";
|
||||
break;
|
||||
case Comdat::Largest:
|
||||
ROS << "largest";
|
||||
break;
|
||||
case Comdat::NoDuplicates:
|
||||
ROS << "noduplicates";
|
||||
break;
|
||||
case Comdat::SameSize:
|
||||
ROS << "samesize";
|
||||
break;
|
||||
}
|
||||
|
||||
ROS << '\n';
|
||||
}
|
||||
|
||||
void Type::print(raw_ostream &OS) const {
|
||||
TypePrinting TP;
|
||||
TP.print(const_cast<Type*>(this), OS);
|
||||
@ -2241,5 +2301,8 @@ void Type::dump() const { print(dbgs()); }
|
||||
// Module::dump() - Allow printing of Modules from the debugger.
|
||||
void Module::dump() const { print(dbgs(), nullptr); }
|
||||
|
||||
// \brief Allow printing of Comdats from the debugger.
|
||||
void Comdat::dump() const { print(dbgs()); }
|
||||
|
||||
// NamedMDNode::dump() - Allow printing of NamedMDNodes from the debugger.
|
||||
void NamedMDNode::dump() const { print(dbgs()); }
|
||||
|
Reference in New Issue
Block a user