forked from OSchip/llvm-project
[NFC] Restructure linkage name printing in AsmWriter
This restructuring was suggested in the review for D46699, which prepares the linkage type printer for use in printing the ThinLTO summary index (where we want to print "external" and also don't want a space after the linkage type as it is printed by the caller). llvm-svn: 333281
This commit is contained in:
parent
d6e9f1477f
commit
c80c873837
|
@ -2478,6 +2478,43 @@ void AssemblyWriter::printModule(const Module *M) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static std::string getLinkageName(GlobalValue::LinkageTypes LT) {
|
||||||
|
switch (LT) {
|
||||||
|
case GlobalValue::ExternalLinkage:
|
||||||
|
return "external";
|
||||||
|
case GlobalValue::PrivateLinkage:
|
||||||
|
return "private";
|
||||||
|
case GlobalValue::InternalLinkage:
|
||||||
|
return "internal";
|
||||||
|
case GlobalValue::LinkOnceAnyLinkage:
|
||||||
|
return "linkonce";
|
||||||
|
case GlobalValue::LinkOnceODRLinkage:
|
||||||
|
return "linkonce_odr";
|
||||||
|
case GlobalValue::WeakAnyLinkage:
|
||||||
|
return "weak";
|
||||||
|
case GlobalValue::WeakODRLinkage:
|
||||||
|
return "weak_odr";
|
||||||
|
case GlobalValue::CommonLinkage:
|
||||||
|
return "common";
|
||||||
|
case GlobalValue::AppendingLinkage:
|
||||||
|
return "appending";
|
||||||
|
case GlobalValue::ExternalWeakLinkage:
|
||||||
|
return "extern_weak";
|
||||||
|
case GlobalValue::AvailableExternallyLinkage:
|
||||||
|
return "available_externally";
|
||||||
|
}
|
||||||
|
llvm_unreachable("invalid linkage");
|
||||||
|
}
|
||||||
|
|
||||||
|
// When printing the linkage types in IR where the ExternalLinkage is
|
||||||
|
// not printed, and other linkage types are expected to be printed with
|
||||||
|
// a space after the name.
|
||||||
|
static std::string getLinkageNameWithSpace(GlobalValue::LinkageTypes LT) {
|
||||||
|
if (LT == GlobalValue::ExternalLinkage)
|
||||||
|
return "";
|
||||||
|
return getLinkageName(LT) + " ";
|
||||||
|
}
|
||||||
|
|
||||||
static void printMetadataIdentifier(StringRef Name,
|
static void printMetadataIdentifier(StringRef Name,
|
||||||
formatted_raw_ostream &Out) {
|
formatted_raw_ostream &Out) {
|
||||||
if (Name.empty()) {
|
if (Name.empty()) {
|
||||||
|
@ -2524,34 +2561,6 @@ void AssemblyWriter::printNamedMDNode(const NamedMDNode *NMD) {
|
||||||
Out << "}\n";
|
Out << "}\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *getLinkagePrintName(GlobalValue::LinkageTypes LT) {
|
|
||||||
switch (LT) {
|
|
||||||
case GlobalValue::ExternalLinkage:
|
|
||||||
return "";
|
|
||||||
case GlobalValue::PrivateLinkage:
|
|
||||||
return "private ";
|
|
||||||
case GlobalValue::InternalLinkage:
|
|
||||||
return "internal ";
|
|
||||||
case GlobalValue::LinkOnceAnyLinkage:
|
|
||||||
return "linkonce ";
|
|
||||||
case GlobalValue::LinkOnceODRLinkage:
|
|
||||||
return "linkonce_odr ";
|
|
||||||
case GlobalValue::WeakAnyLinkage:
|
|
||||||
return "weak ";
|
|
||||||
case GlobalValue::WeakODRLinkage:
|
|
||||||
return "weak_odr ";
|
|
||||||
case GlobalValue::CommonLinkage:
|
|
||||||
return "common ";
|
|
||||||
case GlobalValue::AppendingLinkage:
|
|
||||||
return "appending ";
|
|
||||||
case GlobalValue::ExternalWeakLinkage:
|
|
||||||
return "extern_weak ";
|
|
||||||
case GlobalValue::AvailableExternallyLinkage:
|
|
||||||
return "available_externally ";
|
|
||||||
}
|
|
||||||
llvm_unreachable("invalid linkage");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
|
static void PrintVisibility(GlobalValue::VisibilityTypes Vis,
|
||||||
formatted_raw_ostream &Out) {
|
formatted_raw_ostream &Out) {
|
||||||
switch (Vis) {
|
switch (Vis) {
|
||||||
|
@ -2640,7 +2649,7 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) {
|
||||||
if (!GV->hasInitializer() && GV->hasExternalLinkage())
|
if (!GV->hasInitializer() && GV->hasExternalLinkage())
|
||||||
Out << "external ";
|
Out << "external ";
|
||||||
|
|
||||||
Out << getLinkagePrintName(GV->getLinkage());
|
Out << getLinkageNameWithSpace(GV->getLinkage());
|
||||||
PrintDSOLocation(*GV, Out);
|
PrintDSOLocation(*GV, Out);
|
||||||
PrintVisibility(GV->getVisibility(), Out);
|
PrintVisibility(GV->getVisibility(), Out);
|
||||||
PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
|
PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
|
||||||
|
@ -2687,7 +2696,7 @@ void AssemblyWriter::printIndirectSymbol(const GlobalIndirectSymbol *GIS) {
|
||||||
WriteAsOperandInternal(Out, GIS, &TypePrinter, &Machine, GIS->getParent());
|
WriteAsOperandInternal(Out, GIS, &TypePrinter, &Machine, GIS->getParent());
|
||||||
Out << " = ";
|
Out << " = ";
|
||||||
|
|
||||||
Out << getLinkagePrintName(GIS->getLinkage());
|
Out << getLinkageNameWithSpace(GIS->getLinkage());
|
||||||
PrintDSOLocation(*GIS, Out);
|
PrintDSOLocation(*GIS, Out);
|
||||||
PrintVisibility(GIS->getVisibility(), Out);
|
PrintVisibility(GIS->getVisibility(), Out);
|
||||||
PrintDLLStorageClass(GIS->getDLLStorageClass(), Out);
|
PrintDLLStorageClass(GIS->getDLLStorageClass(), Out);
|
||||||
|
@ -2790,7 +2799,7 @@ void AssemblyWriter::printFunction(const Function *F) {
|
||||||
} else
|
} else
|
||||||
Out << "define ";
|
Out << "define ";
|
||||||
|
|
||||||
Out << getLinkagePrintName(F->getLinkage());
|
Out << getLinkageNameWithSpace(F->getLinkage());
|
||||||
PrintDSOLocation(*F, Out);
|
PrintDSOLocation(*F, Out);
|
||||||
PrintVisibility(F->getVisibility(), Out);
|
PrintVisibility(F->getVisibility(), Out);
|
||||||
PrintDLLStorageClass(F->getDLLStorageClass(), Out);
|
PrintDLLStorageClass(F->getDLLStorageClass(), Out);
|
||||||
|
|
Loading…
Reference in New Issue