[llvm-commits] [llvm] r77096 - in /llvm/trunk: include/llvm/Target/DarwinTargetAsmInfo.h include/llvm/Target/ELFTargetAsmInfo.h include/llvm/Target/TargetAsmInfo.h lib/Target/DarwinTargetAsmInfo.cpp lib/Target/ELFTargetAsmInfo.cpp lib/Target/PIC16/PIC16TargetAsmInfo.cpp lib/Target/PIC16/PIC16TargetAsmInfo.h lib/Target/TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.cpp lib/Target/X86/X86TargetAsmInfo.h
Chris Lattner
sabre at nondot.org
Sat Jul 25 16:21:55 PDT 2009
Author: lattner
Date: Sat Jul 25 18:21:55 2009
New Revision: 77096
URL: http://llvm.org/viewvc/llvm-project?rev=77096&view=rev
Log:
make SectionKind be a first-class pod struct instead of just
an enum.
Modified:
llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
llvm/trunk/include/llvm/Target/TargetAsmInfo.h
llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h
llvm/trunk/lib/Target/TargetAsmInfo.cpp
llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
Modified: llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/DarwinTargetAsmInfo.h Sat Jul 25 18:21:55 2009
@@ -35,7 +35,7 @@
explicit DarwinTargetAsmInfo(const TargetMachine &TM);
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
virtual bool emitUsedDirectiveFor(const GlobalValue *GV,
Mangler *Mang) const;
Modified: llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/ELFTargetAsmInfo.h Sat Jul 25 18:21:55 2009
@@ -37,10 +37,10 @@
/// ".tbss" gets the TLS bit set etc.
virtual unsigned getFlagsForNamedSection(const char *Section) const;
- const char *getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const;
+ const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) const;
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
virtual std::string printSectionFlags(unsigned flags) const;
const Section* DataRelSection;
Modified: llvm/trunk/include/llvm/Target/TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetAsmInfo.h?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetAsmInfo.h (original)
+++ llvm/trunk/include/llvm/Target/TargetAsmInfo.h Sat Jul 25 18:21:55 2009
@@ -31,7 +31,9 @@
};
}
- namespace SectionKind {
+ /// SectionKind - This is a simple POD value that classifies the properties of
+ /// a section.
+ struct SectionKind {
enum Kind {
Unknown = 0, ///< Custom section.
Text, ///< Text section.
@@ -53,9 +55,12 @@
/// Thread local data.
ThreadData, ///< Initialized TLS data objects
ThreadBSS ///< Uninitialized TLS data objects
- };
+ } K; // This is private.
+
+ // FIXME: Eliminate.
+ Kind getKind() const { return K; }
- static inline bool isReadOnly(Kind K) {
+ bool isReadOnly() const {
return (K == SectionKind::ROData ||
K == SectionKind::DataRelRO ||
K == SectionKind::DataRelROLocal ||
@@ -63,20 +68,20 @@
K == SectionKind::RODataMergeStr);
}
- static inline bool isBSS(Kind K) {
+ bool isBSS() const {
return K == BSS || K == ThreadBSS;
}
- static inline bool isTLS(Kind K) {
+ bool isTLS() const {
return K == ThreadData || K == ThreadBSS;
}
- static inline bool isCode(Kind K) {
+ bool isCode() const {
return K == Text;
}
- static inline bool isWritable(Kind K) {
- return isTLS(K) ||
+ bool isWritable() const {
+ return isTLS() ||
K == SectionKind::Data ||
K == SectionKind::DataRel ||
K == SectionKind::DataRelLocal ||
@@ -84,7 +89,24 @@
K == SectionKind::DataRelROLocal ||
K == SectionKind::BSS;
}
- }
+
+ static SectionKind get(Kind K) {
+ SectionKind Res = { K };
+ return Res;
+ }
+ static SectionKind getText() { return get(Text); }
+ static SectionKind getBSS() { return get(BSS); }
+ static SectionKind getData() { return get(Data); }
+ static SectionKind getDataRel() { return get(DataRel); }
+ static SectionKind getDataRelLocal() { return get(DataRelLocal); }
+ static SectionKind getROData() { return get(ROData); }
+ static SectionKind getDataRelRO() { return get(DataRelRO); }
+ static SectionKind getDataRelROLocal() { return get(DataRelROLocal); }
+ static SectionKind getRODataMergeStr() { return get(RODataMergeStr); }
+ static SectionKind getRODataMergeConst() { return get(RODataMergeConst); }
+ static SectionKind getThreadData() { return get(ThreadData); }
+ static SectionKind getThreadBSS() { return get(ThreadBSS); }
+};
namespace SectionFlags {
const unsigned Invalid = -1U;
@@ -109,8 +131,9 @@
return (Flags >> 24) & 0xFF;
}
+ // FIXME: Why does this return a value?
static inline unsigned setEntitySize(unsigned Flags, unsigned Size) {
- return ((Flags & ~EntitySize) | ((Size & 0xFF) << 24));
+ return (Flags & ~EntitySize) | ((Size & 0xFF) << 24);
}
struct KeyInfo {
@@ -604,7 +627,7 @@
/// global. This is important for globals that need to be merged across
/// translation units.
virtual const char *
- getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const {
+ getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
return 0;
}
@@ -628,7 +651,7 @@
/// getFlagsForNamedSection.
virtual const Section *
getSpecialCasedSectionGlobals(const GlobalValue *GV,
- SectionKind::Kind Kind) const{
+ SectionKind Kind) const {
return 0;
}
@@ -637,7 +660,7 @@
// FIXME: Eliminate this.
virtual const Section* SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
/// getSLEB128Size - Compute the number of bytes required for a signed
/// leb128 value.
Modified: llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/DarwinTargetAsmInfo.cpp Sat Jul 25 18:21:55 2009
@@ -126,12 +126,12 @@
const Section*
DarwinTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const {
+ SectionKind Kind) const {
// FIXME: Use sectionflags:linkonce instead of isWeakForLinker() here.
bool isWeak = GV->isWeakForLinker();
bool isNonStatic = TM.getRelocationModel() != Reloc::Static;
- switch (Kind) {
+ switch (Kind.getKind()) {
case SectionKind::ThreadData:
case SectionKind::ThreadBSS:
llvm_unreachable("Darwin doesn't support TLS");
Modified: llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/ELFTargetAsmInfo.cpp Sat Jul 25 18:21:55 2009
@@ -48,7 +48,7 @@
const Section*
ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const {
+ SectionKind Kind) const {
if (const Function *F = dyn_cast<Function>(GV)) {
switch (F->getLinkage()) {
default: llvm_unreachable("Unknown linkage type!");
@@ -62,7 +62,7 @@
}
const GlobalVariable *GVar = cast<GlobalVariable>(GV);
- switch (Kind) {
+ switch (Kind.getKind()) {
default: llvm_unreachable("Unsuported section kind for global");
case SectionKind::BSS:
return getBSSSection_();
@@ -147,8 +147,8 @@
const char *
-ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const{
- switch (Kind) {
+ELFTargetAsmInfo::getSectionPrefixForUniqueGlobal(SectionKind Kind) const{
+ switch (Kind.getKind()) {
default: llvm_unreachable("Unknown section kind");
case SectionKind::Text: return ".gnu.linkonce.t.";
case SectionKind::Data: return ".gnu.linkonce.d.";
Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.cpp Sat Jul 25 18:21:55 2009
@@ -187,7 +187,7 @@
// multiple data sections if required.
const Section*
PIC16TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV1,
- SectionKind::Kind Kind) const {
+ SectionKind Kind) const {
// We select the section based on the initializer here, so it really
// has to be a GlobalVariable.
const GlobalVariable *GV = dyn_cast<GlobalVariable>(GV1);
@@ -247,7 +247,7 @@
/// section assignment of a global.
const Section *
PIC16TargetAsmInfo::getSpecialCasedSectionGlobals(const GlobalValue *GV,
- SectionKind::Kind Kind) const{
+ SectionKind Kind) const {
// If GV has a sectin name or section address create that section now.
if (GV->hasSection()) {
if (const GlobalVariable *GVar = cast<GlobalVariable>(GV)) {
Modified: llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/PIC16/PIC16TargetAsmInfo.h Sat Jul 25 18:21:55 2009
@@ -75,7 +75,7 @@
const Section *CreateROSectionForGlobal(const GlobalVariable *GV,
std::string Addr = "") const;
virtual const Section *SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
const Section *CreateSectionForGlobal(const GlobalVariable *GV,
const std::string &Addr = "") const;
public:
@@ -97,7 +97,7 @@
/// section assignment of a global.
virtual const Section *
getSpecialCasedSectionGlobals(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
};
Modified: llvm/trunk/lib/Target/TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetAsmInfo.cpp?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/TargetAsmInfo.cpp Sat Jul 25 18:21:55 2009
@@ -174,8 +174,12 @@
if (!GV->getSection().empty())
return false;
- // Otherwise, put it in BSS unless the target really doesn't want us to.
- return !NoZerosInBSS;
+ // If -nozero-initialized-in-bss is specified, don't ever use BSS.
+ if (NoZerosInBSS)
+ return false;
+
+ // Otherwise, put it in BSS!
+ return true;
}
static bool isConstantString(const Constant *C) {
@@ -195,39 +199,39 @@
}
static unsigned SectionFlagsForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) {
+ SectionKind Kind) {
// Decode flags from global and section kind.
unsigned Flags = SectionFlags::None;
if (GV->isWeakForLinker())
Flags |= SectionFlags::Linkonce;
- if (SectionKind::isBSS(Kind))
+ if (Kind.isBSS())
Flags |= SectionFlags::BSS;
- if (SectionKind::isTLS(Kind))
+ if (Kind.isTLS())
Flags |= SectionFlags::TLS;
- if (SectionKind::isCode(Kind))
+ if (Kind.isCode())
Flags |= SectionFlags::Code;
- if (SectionKind::isWritable(Kind))
+ if (Kind.isWritable())
Flags |= SectionFlags::Writable;
return Flags;
}
-static SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV,
- Reloc::Model ReloModel) {
+static SectionKind SectionKindForGlobal(const GlobalValue *GV,
+ Reloc::Model ReloModel) {
// Early exit - functions should be always in text sections.
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
if (GVar == 0)
- return SectionKind::Text;
+ return SectionKind::getText();
bool isThreadLocal = GVar->isThreadLocal();
// Variable can be easily put to BSS section.
if (isSuitableForBSS(GVar))
- return isThreadLocal ? SectionKind::ThreadBSS : SectionKind::BSS;
+ return isThreadLocal ? SectionKind::getThreadBSS() : SectionKind::getBSS();
// If this is thread-local, put it in the general "thread_data" section.
if (isThreadLocal)
- return SectionKind::ThreadData;
+ return SectionKind::getThreadData();
Constant *C = GVar->getInitializer();
@@ -243,32 +247,32 @@
// If initializer is a null-terminated string, put it in a "cstring"
// section if the target has it.
if (isConstantString(C))
- return SectionKind::RODataMergeStr;
+ return SectionKind::getRODataMergeStr();
// Otherwise, just drop it into a mergable constant section.
- return SectionKind::RODataMergeConst;
+ return SectionKind::getRODataMergeConst();
case Constant::LocalRelocation:
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up.
if (ReloModel == Reloc::Static)
- return SectionKind::ROData;
+ return SectionKind::getROData();
// Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel.local section.
- return SectionKind::DataRelROLocal;
+ return SectionKind::getDataRelROLocal();
case Constant::GlobalRelocations:
// In static relocation model, the linker will resolve all addresses, so
// the relocation entries will actually be constants by the time the app
// starts up.
if (ReloModel == Reloc::Static)
- return SectionKind::ROData;
+ return SectionKind::getROData();
// Otherwise, the dynamic linker needs to fix it up, put it in the
// writable data.rel section.
- return SectionKind::DataRelRO;
+ return SectionKind::getDataRelRO();
}
}
@@ -278,13 +282,13 @@
// globals together onto fewer pages, improving the locality of the dynamic
// linker.
if (ReloModel == Reloc::Static)
- return SectionKind::Data;
+ return SectionKind::getData();
switch (C->getRelocationInfo()) {
default: llvm_unreachable("unknown relocation info kind");
- case Constant::NoRelocation: return SectionKind::Data;
- case Constant::LocalRelocation: return SectionKind::DataRelLocal;
- case Constant::GlobalRelocations: return SectionKind::DataRel;
+ case Constant::NoRelocation: return SectionKind::getData();
+ case Constant::LocalRelocation: return SectionKind::getDataRelLocal();
+ case Constant::GlobalRelocations: return SectionKind::getDataRel();
}
}
@@ -295,7 +299,7 @@
assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
"Can only be used for global definitions");
- SectionKind::Kind Kind = SectionKindForGlobal(GV, TM.getRelocationModel());
+ SectionKind Kind = SectionKindForGlobal(GV, TM.getRelocationModel());
// Select section name.
if (GV->hasSection()) {
@@ -337,15 +341,15 @@
// Lame default implementation. Calculate the section name for global.
const Section*
TargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
- SectionKind::Kind Kind) const {
- if (SectionKind::isCode(Kind))
+ SectionKind Kind) const {
+ if (Kind.isCode())
return getTextSection();
- if (SectionKind::isBSS(SectionKind::BSS))
+ if (Kind.isBSS())
if (const Section *S = getBSSSection_())
return S;
- if (SectionKind::isReadOnly(Kind))
+ if (Kind.isReadOnly())
if (const Section *S = getReadOnlySection())
return S;
Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.cpp Sat Jul 25 18:21:55 2009
@@ -266,22 +266,12 @@
}
const char *X86COFFTargetAsmInfo::
-getSectionPrefixForUniqueGlobal(SectionKind::Kind Kind) const {
- switch (Kind) {
- default: llvm_unreachable("Unknown section kind");
- case SectionKind::Text: return ".text$linkonce";
- case SectionKind::Data:
- case SectionKind::DataRelLocal:
- case SectionKind::DataRel:
- case SectionKind::BSS:
- case SectionKind::ThreadData:
- case SectionKind::ThreadBSS: return ".data$linkonce";
- case SectionKind::ROData:
- case SectionKind::DataRelRO:
- case SectionKind::DataRelROLocal:
- case SectionKind::RODataMergeConst:
- case SectionKind::RODataMergeStr: return ".rdata$linkonce";
- }
+getSectionPrefixForUniqueGlobal(SectionKind Kind) const {
+ if (Kind.isCode())
+ return ".text$linkonce";
+ if (Kind.isWritable())
+ return ".data$linkonce";
+ return ".rdata$linkonce";
}
std::string X86COFFTargetAsmInfo::printSectionFlags(unsigned flags) const {
Modified: llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h?rev=77096&r1=77095&r2=77096&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h (original)
+++ llvm/trunk/lib/Target/X86/X86TargetAsmInfo.h Sat Jul 25 18:21:55 2009
@@ -54,7 +54,7 @@
virtual unsigned PreferredEHDataFormat(DwarfEncoding::Target Reason,
bool Global) const;
virtual const char *
- getSectionPrefixForUniqueGlobal(SectionKind::Kind kind) const;
+ getSectionPrefixForUniqueGlobal(SectionKind kind) const;
virtual std::string printSectionFlags(unsigned flags) const;
};
More information about the llvm-commits
mailing list