[llvm] r333281 - [NFC] Restructure linkage name printing in AsmWriter
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Fri May 25 08:15:39 PDT 2018
Author: tejohnson
Date: Fri May 25 08:15:39 2018
New Revision: 333281
URL: http://llvm.org/viewvc/llvm-project?rev=333281&view=rev
Log:
[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).
Modified:
llvm/trunk/lib/IR/AsmWriter.cpp
Modified: llvm/trunk/lib/IR/AsmWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AsmWriter.cpp?rev=333281&r1=333280&r2=333281&view=diff
==============================================================================
--- llvm/trunk/lib/IR/AsmWriter.cpp (original)
+++ llvm/trunk/lib/IR/AsmWriter.cpp Fri May 25 08:15:39 2018
@@ -2478,6 +2478,43 @@ void AssemblyWriter::printModule(const 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,
formatted_raw_ostream &Out) {
if (Name.empty()) {
@@ -2524,34 +2561,6 @@ void AssemblyWriter::printNamedMDNode(co
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,
formatted_raw_ostream &Out) {
switch (Vis) {
@@ -2640,7 +2649,7 @@ void AssemblyWriter::printGlobal(const G
if (!GV->hasInitializer() && GV->hasExternalLinkage())
Out << "external ";
- Out << getLinkagePrintName(GV->getLinkage());
+ Out << getLinkageNameWithSpace(GV->getLinkage());
PrintDSOLocation(*GV, Out);
PrintVisibility(GV->getVisibility(), Out);
PrintDLLStorageClass(GV->getDLLStorageClass(), Out);
@@ -2687,7 +2696,7 @@ void AssemblyWriter::printIndirectSymbol
WriteAsOperandInternal(Out, GIS, &TypePrinter, &Machine, GIS->getParent());
Out << " = ";
- Out << getLinkagePrintName(GIS->getLinkage());
+ Out << getLinkageNameWithSpace(GIS->getLinkage());
PrintDSOLocation(*GIS, Out);
PrintVisibility(GIS->getVisibility(), Out);
PrintDLLStorageClass(GIS->getDLLStorageClass(), Out);
@@ -2790,7 +2799,7 @@ void AssemblyWriter::printFunction(const
} else
Out << "define ";
- Out << getLinkagePrintName(F->getLinkage());
+ Out << getLinkageNameWithSpace(F->getLinkage());
PrintDSOLocation(*F, Out);
PrintVisibility(F->getVisibility(), Out);
PrintDLLStorageClass(F->getDLLStorageClass(), Out);
More information about the llvm-commits
mailing list