aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-07-25 23:21:55 +0000
committerChris Lattner <sabre@nondot.org>2009-07-25 23:21:55 +0000
commit460d51e0c029814cd901a2642bcaa7d776ff5929 (patch)
tree58e9d81acef6ea84bc90dcdc50ea4f6835c566f6 /lib
parent7d509134dcec17f6094032196b21af5c67943f0f (diff)
downloadexternal_llvm-460d51e0c029814cd901a2642bcaa7d776ff5929.zip
external_llvm-460d51e0c029814cd901a2642bcaa7d776ff5929.tar.gz
external_llvm-460d51e0c029814cd901a2642bcaa7d776ff5929.tar.bz2
make SectionKind be a first-class pod struct instead of just
an enum. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77096 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Target/DarwinTargetAsmInfo.cpp4
-rw-r--r--lib/Target/ELFTargetAsmInfo.cpp8
-rw-r--r--lib/Target/PIC16/PIC16TargetAsmInfo.cpp4
-rw-r--r--lib/Target/PIC16/PIC16TargetAsmInfo.h4
-rw-r--r--lib/Target/TargetAsmInfo.cpp58
-rw-r--r--lib/Target/X86/X86TargetAsmInfo.cpp22
-rw-r--r--lib/Target/X86/X86TargetAsmInfo.h2
7 files changed, 48 insertions, 54 deletions
diff --git a/lib/Target/DarwinTargetAsmInfo.cpp b/lib/Target/DarwinTargetAsmInfo.cpp
index 2d750a5..38cdc2e 100644
--- a/lib/Target/DarwinTargetAsmInfo.cpp
+++ b/lib/Target/DarwinTargetAsmInfo.cpp
@@ -126,12 +126,12 @@ bool DarwinTargetAsmInfo::emitUsedDirectiveFor(const GlobalValue* GV,
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");
diff --git a/lib/Target/ELFTargetAsmInfo.cpp b/lib/Target/ELFTargetAsmInfo.cpp
index ea07836..510816f 100644
--- a/lib/Target/ELFTargetAsmInfo.cpp
+++ b/lib/Target/ELFTargetAsmInfo.cpp
@@ -48,7 +48,7 @@ ELFTargetAsmInfo::ELFTargetAsmInfo(const TargetMachine &TM)
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 @@ ELFTargetAsmInfo::SelectSectionForGlobal(const GlobalValue *GV,
}
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 @@ unsigned ELFTargetAsmInfo::getFlagsForNamedSection(const char *Name) const {
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.";
diff --git a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
index dce1b78..aba1564 100644
--- a/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
+++ b/lib/Target/PIC16/PIC16TargetAsmInfo.cpp
@@ -187,7 +187,7 @@ PIC16TargetAsmInfo::getSectionForAuto(const GlobalVariable *GV) const {
// 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 @@ PIC16TargetAsmInfo::~PIC16TargetAsmInfo() {
/// 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)) {
diff --git a/lib/Target/PIC16/PIC16TargetAsmInfo.h b/lib/Target/PIC16/PIC16TargetAsmInfo.h
index d9259aa..1ced3bf 100644
--- a/lib/Target/PIC16/PIC16TargetAsmInfo.h
+++ b/lib/Target/PIC16/PIC16TargetAsmInfo.h
@@ -75,7 +75,7 @@ namespace llvm {
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 @@ namespace llvm {
/// section assignment of a global.
virtual const Section *
getSpecialCasedSectionGlobals(const GlobalValue *GV,
- SectionKind::Kind Kind) const;
+ SectionKind Kind) const;
};
diff --git a/lib/Target/TargetAsmInfo.cpp b/lib/Target/TargetAsmInfo.cpp
index 0a4c1b4..c3fb942 100644
--- a/lib/Target/TargetAsmInfo.cpp
+++ b/lib/Target/TargetAsmInfo.cpp
@@ -174,8 +174,12 @@ static bool isSuitableForBSS(const GlobalVariable *GV) {
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 bool isConstantString(const Constant *C) {
}
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 @@ static SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV,
// 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 @@ static SectionKind::Kind SectionKindForGlobal(const GlobalValue *GV,
// 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 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
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 @@ const Section *TargetAsmInfo::SectionForGlobal(const GlobalValue *GV) const {
// 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;
diff --git a/lib/Target/X86/X86TargetAsmInfo.cpp b/lib/Target/X86/X86TargetAsmInfo.cpp
index e71cd70..39dfb00 100644
--- a/lib/Target/X86/X86TargetAsmInfo.cpp
+++ b/lib/Target/X86/X86TargetAsmInfo.cpp
@@ -266,22 +266,12 @@ X86COFFTargetAsmInfo::PreferredEHDataFormat(DwarfEncoding::Target Reason,
}
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 {
diff --git a/lib/Target/X86/X86TargetAsmInfo.h b/lib/Target/X86/X86TargetAsmInfo.h
index 94bae7e..af1ee2d 100644
--- a/lib/Target/X86/X86TargetAsmInfo.h
+++ b/lib/Target/X86/X86TargetAsmInfo.h
@@ -54,7 +54,7 @@ namespace llvm {
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;
};