forked from OSchip/llvm-project
Handle visibility printing with all generality. Remove bunch of duplicate code.
llvm-svn: 54540
This commit is contained in:
parent
f1f8aa3e50
commit
ed47329174
|
@ -355,6 +355,10 @@ namespace llvm {
|
|||
const char *Prefix = 0);
|
||||
void printSuffixedName(const std::string &Name, const char* Suffix);
|
||||
|
||||
/// printVisibility - This prints visibility information about symbol, if
|
||||
/// this is suported by the target.
|
||||
void printVisibility(const std::string& Name, unsigned Visibility) const;
|
||||
|
||||
private:
|
||||
void EmitLLVMUsedList(Constant *List);
|
||||
void EmitXXStructorList(Constant *List);
|
||||
|
|
|
@ -1469,3 +1469,14 @@ void AsmPrinter::printSuffixedName(const char *Name, const char *Suffix,
|
|||
void AsmPrinter::printSuffixedName(const std::string &Name, const char* Suffix) {
|
||||
printSuffixedName(Name.c_str(), Suffix);
|
||||
}
|
||||
|
||||
void AsmPrinter::printVisibility(const std::string& Name,
|
||||
unsigned Visibility) const {
|
||||
if (Visibility == GlobalValue::HiddenVisibility) {
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << Name << '\n';
|
||||
} else if (Visibility == GlobalValue::ProtectedVisibility) {
|
||||
if (const char *Directive = TAI->getProtectedDirective())
|
||||
O << Directive << Name << '\n';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -226,14 +226,7 @@ bool ARMAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
break;
|
||||
}
|
||||
|
||||
const char *VisibilityDirective = NULL;
|
||||
if (F->hasHiddenVisibility())
|
||||
VisibilityDirective = TAI->getHiddenDirective();
|
||||
else if (F->hasProtectedVisibility())
|
||||
VisibilityDirective = TAI->getProtectedDirective();
|
||||
|
||||
if (VisibilityDirective)
|
||||
O << VisibilityDirective << CurrentFnName << "\n";
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
if (AFI->isThumbFunction()) {
|
||||
EmitAlignment(1, F, AFI->getAlign());
|
||||
|
@ -870,14 +863,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
unsigned Size = TD->getABITypeSize(Type);
|
||||
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
||||
|
||||
const char *VisibilityDirective = NULL;
|
||||
if (GVar->hasHiddenVisibility())
|
||||
VisibilityDirective = TAI->getHiddenDirective();
|
||||
else if (GVar->hasProtectedVisibility())
|
||||
VisibilityDirective = TAI->getProtectedDirective();
|
||||
|
||||
if (VisibilityDirective)
|
||||
O << VisibilityDirective << name << "\n";
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
if (Subtarget->isTargetELF())
|
||||
O << "\t.type " << name << ",%object\n";
|
||||
|
|
|
@ -164,6 +164,8 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
break;
|
||||
}
|
||||
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
O << "\t.ent " << CurrentFnName << "\n";
|
||||
|
||||
O << CurrentFnName << ":\n";
|
||||
|
@ -221,8 +223,7 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
SwitchToDataSection(SectionName.c_str());
|
||||
|
||||
// 1: Check visibility
|
||||
if (GVar->hasHiddenVisibility())
|
||||
O << TAI->getHiddenDirective() << name << "\n";
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
// 2: Kind
|
||||
switch (GVar->getLinkage()) {
|
||||
|
|
|
@ -142,6 +142,9 @@ bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
// Print out labels for the function.
|
||||
EmitAlignment(5);
|
||||
O << "\t.global\t" << CurrentFnName << '\n';
|
||||
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
O << "\t.type\t" << CurrentFnName << ", @function\n";
|
||||
O << CurrentFnName << ":\n";
|
||||
|
||||
|
@ -274,7 +277,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
unsigned Size = TD->getABITypeSize(C->getType());
|
||||
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
||||
|
||||
// FIXME: ELF supports visibility
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
|
||||
|
|
|
@ -237,6 +237,8 @@ emitFunctionStart(MachineFunction &MF)
|
|||
O << "\t.globl\t" << CurrentFnName << '\n';
|
||||
O << "\t.ent\t" << CurrentFnName << '\n';
|
||||
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
if ((TAI->hasDotTypeDotSizeDirective()) && Subtarget->isLinux())
|
||||
O << "\t.type\t" << CurrentFnName << ", @function\n";
|
||||
|
||||
|
@ -497,7 +499,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
} else
|
||||
Align = TD->getPreferredTypeAlignmentShift(CTy);
|
||||
|
||||
// FIXME: ELF supports visibility
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
|
||||
|
@ -508,7 +510,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
|
||||
if (GVar->hasInternalLinkage())
|
||||
O << "\t.local\t" << name << '\n';
|
||||
|
||||
|
||||
O << TAI->getCOMMDirective() << name << ',' << Size;
|
||||
if (TAI->getCOMMDirectiveTakesAlignment())
|
||||
O << ',' << (1 << Align);
|
||||
|
|
|
@ -593,9 +593,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (F->hasHiddenVisibility())
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << CurrentFnName << '\n';
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
EmitAlignment(2, F);
|
||||
O << CurrentFnName << ":\n";
|
||||
|
@ -671,9 +669,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
std::string name = Mang->getValueName(GVar);
|
||||
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||
|
||||
if (GVar->hasHiddenVisibility())
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << name << '\n';
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
Constant *C = GVar->getInitializer();
|
||||
const Type *Type = C->getType();
|
||||
|
@ -792,9 +788,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (F->hasHiddenVisibility())
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << CurrentFnName << '\n';
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
EmitAlignment(OptimizeForSize ? 2 : 4, F);
|
||||
O << CurrentFnName << ":\n";
|
||||
|
@ -909,9 +903,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
std::string name = Mang->getValueName(GVar);
|
||||
std::string SectionName = TAI->SectionForGlobal(GVar);
|
||||
|
||||
if (GVar->hasHiddenVisibility())
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << name << '\n';
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
Constant *C = GVar->getInitializer();
|
||||
const Type *Type = C->getType();
|
||||
|
|
|
@ -107,6 +107,9 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
|
|||
SwitchToTextSection(getSectionForFunction(*F).c_str(), F);
|
||||
EmitAlignment(4, F);
|
||||
O << "\t.globl\t" << CurrentFnName << '\n';
|
||||
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
O << "\t.type\t" << CurrentFnName << ", #function\n";
|
||||
O << CurrentFnName << ":\n";
|
||||
|
||||
|
@ -250,7 +253,8 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
unsigned Size = TD->getABITypeSize(C->getType());
|
||||
unsigned Align = TD->getPreferredAlignment(GVar);
|
||||
|
||||
// FIXME: ELF supports visibility
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
SwitchToDataSection(SectionName.c_str());
|
||||
|
||||
if (C->isNullValue() && !GVar->hasSection()) {
|
||||
|
|
|
@ -183,13 +183,8 @@ void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
|
|||
}
|
||||
break;
|
||||
}
|
||||
if (F->hasHiddenVisibility()) {
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << CurrentFnName << '\n';
|
||||
} else if (F->hasProtectedVisibility()) {
|
||||
if (const char *Directive = TAI->getProtectedDirective())
|
||||
O << Directive << CurrentFnName << '\n';
|
||||
}
|
||||
|
||||
printVisibility(CurrentFnName, F->getVisibility());
|
||||
|
||||
if (Subtarget->isTargetELF())
|
||||
O << "\t.type\t" << CurrentFnName << ",@function\n";
|
||||
|
@ -773,13 +768,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
|
|||
unsigned Size = TD->getABITypeSize(Type);
|
||||
unsigned Align = TD->getPreferredAlignmentLog(GVar);
|
||||
|
||||
if (GVar->hasHiddenVisibility()) {
|
||||
if (const char *Directive = TAI->getHiddenDirective())
|
||||
O << Directive << name << '\n';
|
||||
} else if (GVar->hasProtectedVisibility()) {
|
||||
if (const char *Directive = TAI->getProtectedDirective())
|
||||
O << Directive << name << '\n';
|
||||
}
|
||||
printVisibility(name, GVar->getVisibility());
|
||||
|
||||
if (Subtarget->isTargetELF())
|
||||
O << "\t.type\t" << name << ",@object\n";
|
||||
|
|
Loading…
Reference in New Issue