[llvm-commits] [llvm] r53304 - in /llvm/trunk: include/llvm/Target/TargetAsmInfo.h lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.cpp
Anton Korobeynikov
asl at math.spbu.ru
Wed Jul 9 06:22:46 PDT 2008
Author: asl
Date: Wed Jul 9 08:22:46 2008
New Revision: 53304
URL: http://llvm.org/viewvc/llvm-project?rev=53304&view=rev
Log:
Provide general hook for section name calculation
Modified:
llvm/trunk/include/llvm/Target/TargetAsmInfo.h
llvm/trunk/lib/Target/TargetAsmInfo.cpp
llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=53304&r1=53303&r2=53304&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Wed Jul 9 08:22:46 2008
@@ -481,11 +481,14 @@
/// global with all necessary flags and marks.
virtual std::string SectionForGlobal(const GlobalValue *GV) const;
+ // Helper methods for SectionForGlobal
virtual std::string UniqueSectionForGlobal(const GlobalValue* GV,
SectionKind::Kind kind) const;
virtual std::string PrintSectionFlags(unsigned flags) const { return ""; }
+ virtual std::string SelectSectionForGlobal(const GlobalValue *GV) const;
+
// Accessors.
//
const char *getTextSection() const {
Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=53304&r1=53303&r2=53304&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Wed Jul 9 08:22:46 2008
@@ -257,12 +257,43 @@
std::string
TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
+ unsigned flags = SectionFlagsForGlobal(GV, GV->getSection().c_str());
+
+ std::string Name;
+
+ // Select section name
+ if (GV->hasSection()) {
+ // Honour section already set, if any
+ Name = GV->getSection();
+ } else {
+ // Use default section depending on the 'type' of global
+ Name = SelectSectionForGlobal(GV);
+ }
+
+ Name += PrintSectionFlags(flags);
+ return Name;
+}
+
+// Lame default implementation. Calculate the section name for global.
+std::string
+TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV) const {
SectionKind::Kind kind = SectionKindForGlobal(GV);
- if (kind == SectionKind::Text)
- return getTextSection();
- else if (kind == SectionKind::BSS && getBSSSection())
- return getBSSSection();
+ if (GV->hasLinkOnceLinkage() ||
+ GV->hasWeakLinkage() ||
+ GV->hasCommonLinkage())
+ return UniqueSectionForGlobal(GV, kind);
+ else {
+ if (kind == SectionKind::Text)
+ return getTextSection();
+ else if (kind == SectionKind::BSS && getBSSSection())
+ return getBSSSection();
+ else if (getReadOnlySection() &&
+ (kind == SectionKind::ROData ||
+ kind == SectionKind::RODataMergeConst ||
+ kind == SectionKind::RODataMergeStr))
+ return getReadOnlySection();
+ }
return getDataSection();
}
Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=53304&r1=53303&r2=53304&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Wed Jul 9 08:22:46 2008
@@ -494,7 +494,7 @@
case Function::InternalLinkage:
case Function::DLLExportLinkage:
case Function::ExternalLinkage:
- Name = TextSection;
+ Name = getTextSection();
break;
case Function::WeakLinkage:
case Function::LinkOnceLinkage:
@@ -509,22 +509,22 @@
else {
switch (kind) {
case SectionKind::Data:
- Name = DataSection;
+ Name = getDataSection();
break;
case SectionKind::BSS:
- Name = (BSSSection ? BSSSection : DataSection);
+ Name = (getBSSSection() ? getBSSSection() : getDataSection());
break;
case SectionKind::ROData:
case SectionKind::RODataMergeStr:
case SectionKind::RODataMergeConst:
// FIXME: Temporary
- Name = DataSection;
+ Name = getDataSection();
break;
case SectionKind::ThreadData:
- Name = (TLSDataSection ? TLSDataSection : DataSection);
+ Name = (getTLSDataSection() ? getTLSDataSection() : getDataSection());
break;
case SectionKind::ThreadBSS:
- Name = (TLSBSSSection ? TLSBSSSection : DataSection);
+ Name = (getTLSBSSSection() ? getTLSBSSSection() : getDataSection());
default:
assert(0 && "Unsuported section kind for global");
}
More information about the llvm-commits
mailing list