summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnton Korobeynikov <asl@math.spbu.ru>2008-09-24 22:14:23 +0000
committerAnton Korobeynikov <asl@math.spbu.ru>2008-09-24 22:14:23 +0000
commit076e905b9480a75a33f5bbf56f26ecd2d8e88dc2 (patch)
tree991f647055f68842b64d4a63b5d0ba97242e7e57
parent69ff51baa0e051aee3a2a554b31aad8f15be3d74 (diff)
downloadbcm5719-llvm-076e905b9480a75a33f5bbf56f26ecd2d8e88dc2.tar.gz
bcm5719-llvm-076e905b9480a75a33f5bbf56f26ecd2d8e88dc2.zip
Move actual section printing stuff to AsmPrinter from TAI reducing heap traffic.
llvm-svn: 56573
-rw-r--r--llvm/include/llvm/Target/TargetAsmInfo.h3
-rw-r--r--llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp16
-rw-r--r--llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp3
-rw-r--r--llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp5
-rw-r--r--llvm/lib/Target/CellSPU/SPUAsmPrinter.cpp2
-rw-r--r--llvm/lib/Target/IA64/IA64AsmPrinter.cpp5
-rw-r--r--llvm/lib/Target/Mips/MipsAsmPrinter.cpp5
-rw-r--r--llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp10
-rw-r--r--llvm/lib/Target/Sparc/SparcAsmPrinter.cpp5
-rw-r--r--llvm/lib/Target/TargetAsmInfo.cpp10
-rw-r--r--llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp6
11 files changed, 33 insertions, 37 deletions
diff --git a/llvm/include/llvm/Target/TargetAsmInfo.h b/llvm/include/llvm/Target/TargetAsmInfo.h
index 8305e54f9e8..49a99c509e6 100644
--- a/llvm/include/llvm/Target/TargetAsmInfo.h
+++ b/llvm/include/llvm/Target/TargetAsmInfo.h
@@ -113,6 +113,7 @@ namespace llvm {
public:
bool isNamed() const { return Flags & SectionFlags::Named; }
unsigned getEntitySize() const { return (Flags >> 24) & 0xFF; }
+
const std::string& getName() const { return Name; }
unsigned getFlags() const { return Flags; }
};
@@ -573,7 +574,7 @@ namespace llvm {
/// SectionForGlobal - This hooks returns proper section name for given
/// global with all necessary flags and marks.
- virtual std::string SectionForGlobal(const GlobalValue *GV) const;
+ virtual const Section* SectionForGlobal(const GlobalValue *GV) const;
// Helper methods for SectionForGlobal
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
diff --git a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
index 93ebf218188..9fc57a9545c 100644
--- a/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
+++ b/llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
@@ -115,8 +115,18 @@ void AsmPrinter::SwitchToSection(const Section* NS) {
// FIXME: Make CurrentSection a Section* in the future
CurrentSection = NewSection;
- if (!CurrentSection.empty())
- O << CurrentSection << TAI->getDataSectionStartSuffix() << '\n';
+ if (!CurrentSection.empty()) {
+ // If section is named we need to switch into it via special '.section'
+ // directive and also append funky flags. Otherwise - section name is just
+ // some magic assembler directive.
+ if (NS->isNamed())
+ O << TAI->getSwitchToSectionDirective()
+ << CurrentSection
+ << TAI->getSectionFlags(NS->getFlags());
+ else
+ O << CurrentSection;
+ O << TAI->getDataSectionStartSuffix() << '\n';
+ }
IsInTextSection = (NS->getFlags() & SectionFlags::Code);
}
@@ -326,7 +336,7 @@ void AsmPrinter::EmitJumpTableInfo(MachineJumpTableInfo *MJTI,
// function body itself, otherwise the label differences won't make sense.
// We should also do if the section name is NULL or function is declared in
// discardable section.
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
} else {
SwitchToDataSection(JumpTableDataSection);
}
diff --git a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
index 4db430f9e22..08f05978b6a 100644
--- a/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
+++ b/llvm/lib/Target/ARM/AsmPrinter/ARMAsmPrinter.cpp
@@ -846,7 +846,6 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
}
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
const Type *Type = C->getType();
@@ -858,7 +857,7 @@ void ARMAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (Subtarget->isTargetELF())
O << "\t.type " << name << ",%object\n";
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && !GVar->hasSection() && !GVar->isThreadLocal()) {
// FIXME: This seems to be pretty darwin-specific
diff --git a/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp b/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp
index b1265afe1ab..9a4102c1a46 100644
--- a/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp
+++ b/llvm/lib/Target/Alpha/AlphaAsmPrinter.cpp
@@ -149,7 +149,7 @@ bool AlphaAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(4, F);
switch (F->getLinkage()) {
@@ -214,14 +214,13 @@ void AlphaAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (EmitSpecialLLVMGlobal(GVar))
return;
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
unsigned Size = TD->getABITypeSize(C->getType());
unsigned Align = TD->getPreferredAlignmentLog(GVar);
// 0: Switch to section
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
// 1: Check visibility
printVisibility(name, GVar->getVisibility());
diff --git a/llvm/lib/Target/CellSPU/SPUAsmPrinter.cpp b/llvm/lib/Target/CellSPU/SPUAsmPrinter.cpp
index ef33968c28f..5b0bacfc89f 100644
--- a/llvm/lib/Target/CellSPU/SPUAsmPrinter.cpp
+++ b/llvm/lib/Target/CellSPU/SPUAsmPrinter.cpp
@@ -418,7 +418,7 @@ LinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF)
// Print out labels for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(3, F);
switch (F->getLinkage()) {
diff --git a/llvm/lib/Target/IA64/IA64AsmPrinter.cpp b/llvm/lib/Target/IA64/IA64AsmPrinter.cpp
index ff33125913c..0d04bf54b4f 100644
--- a/llvm/lib/Target/IA64/IA64AsmPrinter.cpp
+++ b/llvm/lib/Target/IA64/IA64AsmPrinter.cpp
@@ -130,7 +130,7 @@ bool IA64AsmPrinter::runOnMachineFunction(MachineFunction &MF) {
EmitConstantPool(MF.getConstantPool());
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
// Print out labels for the function.
EmitAlignment(5);
@@ -264,7 +264,6 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
O << "\n\n";
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
unsigned Size = TD->getABITypeSize(C->getType());
@@ -272,7 +271,7 @@ void IA64AsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
printVisibility(name, GVar->getVisibility());
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
diff --git a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
index fbe3faa3393..9525f46bcbb 100644
--- a/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
+++ b/llvm/lib/Target/Mips/MipsAsmPrinter.cpp
@@ -224,7 +224,7 @@ emitFunctionStart(MachineFunction &MF)
{
// Print out the label for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str());
+ SwitchToSection(TAI->SectionForGlobal(F));
// 2 bits aligned
EmitAlignment(2, F);
@@ -479,7 +479,6 @@ printModuleLevelGV(const GlobalVariable* GVar) {
return;
O << "\n\n";
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
const Type *CTy = C->getType();
@@ -501,7 +500,7 @@ printModuleLevelGV(const GlobalVariable* GVar) {
printVisibility(name, GVar->getVisibility());
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
diff --git a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
index a8127f6f63c..2d9ecbd71e3 100644
--- a/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
+++ b/llvm/lib/Target/PowerPC/AsmPrinter/PPCAsmPrinter.cpp
@@ -571,7 +571,7 @@ bool PPCLinuxAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
@@ -662,7 +662,6 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
std::string name = Mang->getValueName(GVar);
- std::string SectionName = TAI->SectionForGlobal(GVar);
printVisibility(name, GVar->getVisibility());
@@ -671,7 +670,7 @@ void PPCLinuxAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
unsigned Size = TD->getABITypeSize(Type);
unsigned Align = TD->getPreferredAlignmentLog(GVar);
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
@@ -759,7 +758,7 @@ bool PPCDarwinAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out labels for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
switch (F->getLinkage()) {
default: assert(0 && "Unknown linkage type!");
@@ -888,7 +887,6 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
}
std::string name = Mang->getValueName(GVar);
- std::string SectionName = TAI->SectionForGlobal(GVar);
printVisibility(name, GVar->getVisibility());
@@ -897,7 +895,7 @@ void PPCDarwinAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
unsigned Size = TD->getABITypeSize(Type);
unsigned Align = TD->getPreferredAlignmentLog(GVar);
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && /* FIXME: Verify correct */
!GVar->hasSection() &&
diff --git a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp
index bb4d6aeea7b..424adaa7c3f 100644
--- a/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp
+++ b/llvm/lib/Target/Sparc/SparcAsmPrinter.cpp
@@ -99,7 +99,7 @@ bool SparcAsmPrinter::runOnMachineFunction(MachineFunction &MF) {
// Print out the label for the function.
const Function *F = MF.getFunction();
- SwitchToTextSection(TAI->SectionForGlobal(F).c_str(), F);
+ SwitchToSection(TAI->SectionForGlobal(F));
EmitAlignment(4, F);
O << "\t.globl\t" << CurrentFnName << '\n';
@@ -242,7 +242,6 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
O << "\n\n";
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
unsigned Size = TD->getABITypeSize(C->getType());
@@ -250,7 +249,7 @@ void SparcAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
printVisibility(name, GVar->getVisibility());
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && !GVar->hasSection()) {
if (!GVar->isThreadLocal() &&
diff --git a/llvm/lib/Target/TargetAsmInfo.cpp b/llvm/lib/Target/TargetAsmInfo.cpp
index 06b77dd26aa..536f16d6578 100644
--- a/llvm/lib/Target/TargetAsmInfo.cpp
+++ b/llvm/lib/Target/TargetAsmInfo.cpp
@@ -272,7 +272,7 @@ TargetAsmInfo::SectionFlagsForGlobal(const GlobalValue *GV,
return Flags;
}
-std::string
+const Section*
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
const Section* S;
// Select section name
@@ -286,13 +286,7 @@ TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
S = SelectSectionForGlobal(GV);
}
- if (!S->isNamed())
- return S->Name;
-
- // If section is named we need to switch into it via special '.section'
- // directive and also append funky flags. Otherwise - section name is just
- // some magic assembler directive.
- return getSwitchToSectionDirective() + S->Name + getSectionFlags(S->Flags);
+ return S;
}
// Lame default implementation. Calculate the section name for global.
diff --git a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
index 61c8f12eec3..01fda9f1f08 100644
--- a/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
+++ b/llvm/lib/Target/X86/AsmPrinter/X86ATTAsmPrinter.cpp
@@ -148,11 +148,10 @@ void X86ATTAsmPrinter::decorateName(std::string &Name,
void X86ATTAsmPrinter::emitFunctionHeader(const MachineFunction &MF) {
const Function *F = MF.getFunction();
- std::string SectionName = TAI->SectionForGlobal(F);
decorateName(CurrentFnName, F);
- SwitchToTextSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(F));
unsigned FnAlign = OptimizeForSize ? 1 : 4;
if (!F->isDeclaration() && F->hasNote(FnAttr::OptimizeForSize))
@@ -766,7 +765,6 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
return;
}
- std::string SectionName = TAI->SectionForGlobal(GVar);
std::string name = Mang->getValueName(GVar);
Constant *C = GVar->getInitializer();
const Type *Type = C->getType();
@@ -778,7 +776,7 @@ void X86ATTAsmPrinter::printModuleLevelGV(const GlobalVariable* GVar) {
if (Subtarget->isTargetELF())
O << "\t.type\t" << name << ",@object\n";
- SwitchToDataSection(SectionName.c_str());
+ SwitchToSection(TAI->SectionForGlobal(GVar));
if (C->isNullValue() && !GVar->hasSection()) {
// FIXME: This seems to be pretty darwin-specific
OpenPOWER on IntegriCloud