it turns out that isWeak() was basically dead anyway. Kill off SectionInfo :-/

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@77812 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner 2009-08-01 21:46:23 +00:00
parent 27602b82c2
commit f9650c061e
5 changed files with 57 additions and 86 deletions

View File

@ -43,12 +43,12 @@ namespace llvm {
public:
virtual ~MCSection();
bool isDirective() const { return IsDirective; }
static MCSection *Create(const StringRef &Name, bool IsDirective,
SectionKind K, MCContext &Ctx);
const std::string &getName() const { return Name; }
bool isDirective() const { return IsDirective; }
SectionKind getKind() const { return Kind; }
};

View File

@ -26,35 +26,7 @@ namespace llvm {
class Mangler;
class TargetMachine;
/// SectionInfo - This class is a target-independent classification of a global
/// which is used to simplify target-specific code by exposing common
/// predicates.
class SectionInfo : public SectionKind {
/// Weak - This is true if the referenced symbol is weak (i.e. linkonce,
/// weak, weak_odr, etc). This is orthogonal from the categorization.
bool Weak : 1;
public:
/// Weak - This is true if the referenced symbol is weak (i.e. linkonce,
/// weak, weak_odr, etc). This is orthogonal from the categorization.
bool isWeak() const { return Weak; }
static SectionInfo get(Kind K, bool isWeak = false) {
SectionInfo Res;
Res.K = K;
Res.Weak = isWeak;
return Res;
}
static SectionInfo get(SectionKind K, bool isWeak = false) {
SectionInfo Res;
*(SectionKind*)&Res = K;
Res.Weak = isWeak;
return Res;
}
};
class TargetLoweringObjectFile {
MCContext *Ctx;
protected:
@ -146,7 +118,7 @@ public:
/// getFlagsForNamedSection.
virtual const MCSection *
getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
SectionInfo Kind) const {
SectionKind Kind) const {
return 0;
}
@ -159,7 +131,7 @@ public:
protected:
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
};
@ -192,7 +164,7 @@ public:
SmallVectorImpl<char> &Str) const;
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
protected:
const MCSection *DataRelSection;
@ -221,7 +193,7 @@ public:
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
virtual const MCSection *
@ -244,7 +216,7 @@ public:
SmallVectorImpl<char> &Str) const;
virtual const MCSection *
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const;
};

View File

@ -166,14 +166,14 @@ PIC16TargetObjectFile::getSectionForAuto(const GlobalVariable *GV) const {
// multiple data sections if required.
const MCSection *
PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
SectionInfo Info,
SectionKind Kind,
Mangler *Mang,
const TargetMachine &TM) 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);
if (!GV)
return TargetLoweringObjectFile::SelectSectionForGlobal(GV1, Info, Mang,TM);
return TargetLoweringObjectFile::SelectSectionForGlobal(GV1, Kind, Mang,TM);
// Record External Var Decls.
if (GV->isDeclaration()) {
@ -207,7 +207,7 @@ PIC16TargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV1,
return getROSectionForGlobal(GV);
// Else let the default implementation take care of it.
return TargetLoweringObjectFile::SelectSectionForGlobal(GV, Info, Mang,TM);
return TargetLoweringObjectFile::SelectSectionForGlobal(GV, Kind, Mang,TM);
}
PIC16TargetObjectFile::~PIC16TargetObjectFile() {
@ -229,7 +229,7 @@ PIC16TargetObjectFile::~PIC16TargetObjectFile() {
const MCSection *
PIC16TargetObjectFile::getSpecialCasedSectionGlobals(const GlobalValue *GV,
Mangler *Mang,
SectionInfo Info) 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)) {

View File

@ -62,9 +62,9 @@ namespace llvm {
/// section assignment of a global.
virtual const MCSection *
getSpecialCasedSectionGlobals(const GlobalValue *GV, Mangler *Mang,
SectionInfo Info) const;
SectionKind Kind) const;
virtual const MCSection *SelectSectionForGlobal(const GlobalValue *GV,
SectionInfo Info,
SectionKind Kind,
Mangler *Mang,
const TargetMachine&) const;
private:

View File

@ -190,13 +190,12 @@ SectionForGlobal(const GlobalValue *GV, Mangler *Mang,
"Can only be used for global definitions");
SectionKind Kind = SectionKindForGlobal(GV, TM);
SectionInfo Info = SectionInfo::get(Kind, GV->isWeakForLinker());
// Select section name.
if (GV->hasSection()) {
// If the target has special section hacks for specifically named globals,
// return them now.
if (const MCSection *TS = getSpecialCasedSectionGlobals(GV, Mang, Info))
if (const MCSection *TS = getSpecialCasedSectionGlobals(GV, Mang, Kind))
return TS;
// If the target has magic semantics for certain section names, make sure to
@ -209,24 +208,24 @@ SectionForGlobal(const GlobalValue *GV, Mangler *Mang,
// Use default section depending on the 'type' of global
return SelectSectionForGlobal(GV, Info, Mang, TM);
return SelectSectionForGlobal(GV, Kind, Mang, TM);
}
// Lame default implementation. Calculate the section name for global.
const MCSection *
TargetLoweringObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
SectionInfo Info,
SectionKind Kind,
Mangler *Mang,
const TargetMachine &TM) const{
assert(!Info.isThreadLocal() && "Doesn't support TLS");
assert(!Kind.isThreadLocal() && "Doesn't support TLS");
if (Info.isText())
if (Kind.isText())
return getTextSection();
if (Info.isBSS() && BSSSection_ != 0)
if (Kind.isBSS() && BSSSection_ != 0)
return BSSSection_;
if (Info.isReadOnly() && ReadOnlySection != 0)
if (Kind.isReadOnly() && ReadOnlySection != 0)
return ReadOnlySection;
return getDataSection();
@ -410,20 +409,20 @@ static const char *getSectionPrefixForUniqueGlobal(SectionKind Kind) {
}
const MCSection *TargetLoweringObjectFileELF::
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Info,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
// If this global is linkonce/weak and the target handles this by emitting it
// into a 'uniqued' section name, create and return the section now.
if (GV->isWeakForLinker()) {
const char *Prefix = getSectionPrefixForUniqueGlobal(Info);
const char *Prefix = getSectionPrefixForUniqueGlobal(Kind);
std::string Name = Mang->makeNameProper(GV->getNameStr());
return getOrCreateSection((Prefix+Name).c_str(), false, Info);
return getOrCreateSection((Prefix+Name).c_str(), false, Kind);
}
if (Info.isText()) return TextSection;
if (Kind.isText()) return TextSection;
if (Info.isMergeableCString()) {
if (Kind.isMergeableCString()) {
assert(CStringSection_ && "Should have string section prefix");
// We also need alignment here.
@ -437,29 +436,29 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Info,
SectionKind::get(SectionKind::MergeableCString));
}
if (Info.isMergeableConst()) {
if (Info.isMergeableConst4())
if (Kind.isMergeableConst()) {
if (Kind.isMergeableConst4())
return MergeableConst4Section;
if (Info.isMergeableConst8())
if (Kind.isMergeableConst8())
return MergeableConst8Section;
if (Info.isMergeableConst16())
if (Kind.isMergeableConst16())
return MergeableConst16Section;
return ReadOnlySection; // .const
}
if (Info.isReadOnly()) return ReadOnlySection;
if (Kind.isReadOnly()) return ReadOnlySection;
if (Info.isThreadData()) return TLSDataSection;
if (Info.isThreadBSS()) return TLSBSSSection;
if (Kind.isThreadData()) return TLSDataSection;
if (Kind.isThreadBSS()) return TLSBSSSection;
if (Info.isBSS()) return BSSSection_;
if (Kind.isBSS()) return BSSSection_;
if (Info.isDataNoRel()) return DataSection;
if (Info.isDataRelLocal()) return DataRelLocalSection;
if (Info.isDataRel()) return DataRelSection;
if (Info.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
if (Kind.isDataNoRel()) return DataSection;
if (Kind.isDataRelLocal()) return DataRelLocalSection;
if (Kind.isDataRel()) return DataRelSection;
if (Kind.isReadOnlyWithRelLocal()) return DataRelROLocalSection;
assert(Info.isReadOnlyWithRel() && "Unknown section kind");
assert(Kind.isReadOnlyWithRel() && "Unknown section kind");
return DataRelROSection;
}
@ -531,23 +530,23 @@ void TargetLoweringObjectFileMachO::Initialize(MCContext &Ctx,
}
const MCSection *TargetLoweringObjectFileMachO::
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Info,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
assert(!Info.isThreadLocal() && "Darwin doesn't support TLS");
assert(!Kind.isThreadLocal() && "Darwin doesn't support TLS");
if (Info.isText())
if (Kind.isText())
return GV->isWeakForLinker() ? TextCoalSection : TextSection;
// If this is weak/linkonce, put this in a coalescable section, either in text
// or data depending on if it is writable.
if (GV->isWeakForLinker()) {
if (Info.isReadOnly())
if (Kind.isReadOnly())
return ConstTextCoalSection;
return DataCoalSection;
}
// FIXME: Alignment check should be handled by section classifier.
if (Info.isMergeableCString()) {
if (Kind.isMergeableCString()) {
Constant *C = cast<GlobalVariable>(GV)->getInitializer();
const Type *Ty = cast<ArrayType>(C->getType())->getElementType();
const TargetData &TD = *TM.getTargetData();
@ -561,24 +560,24 @@ SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Info,
return ReadOnlySection;
}
if (Info.isMergeableConst()) {
if (Info.isMergeableConst4())
if (Kind.isMergeableConst()) {
if (Kind.isMergeableConst4())
return FourByteConstantSection;
if (Info.isMergeableConst8())
if (Kind.isMergeableConst8())
return EightByteConstantSection;
if (Info.isMergeableConst16() && SixteenByteConstantSection)
if (Kind.isMergeableConst16() && SixteenByteConstantSection)
return SixteenByteConstantSection;
return ReadOnlySection; // .const
}
// FIXME: ROData -> const in -static mode that is relocatable but they happen
// by the static linker. Why not mergeable?
if (Info.isReadOnly())
if (Kind.isReadOnly())
return ReadOnlySection;
// If this is marked const, put it into a const section. But if the dynamic
// linker needs to write to it, put it in the data segment.
if (Info.isReadOnlyWithRel())
if (Kind.isReadOnlyWithRel())
return ConstDataSection;
// Otherwise, just drop the variable in the normal data section.
@ -661,25 +660,25 @@ static const char *getCOFFSectionPrefixForUniqueGlobal(SectionKind Kind) {
const MCSection *TargetLoweringObjectFileCOFF::
SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Info,
SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
Mangler *Mang, const TargetMachine &TM) const {
assert(!Info.isThreadLocal() && "Doesn't support TLS");
assert(!Kind.isThreadLocal() && "Doesn't support TLS");
// If this global is linkonce/weak and the target handles this by emitting it
// into a 'uniqued' section name, create and return the section now.
if (GV->isWeakForLinker()) {
const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Info);
const char *Prefix = getCOFFSectionPrefixForUniqueGlobal(Kind);
std::string Name = Mang->makeNameProper(GV->getNameStr());
return getOrCreateSection((Prefix+Name).c_str(), false, Info);
return getOrCreateSection((Prefix+Name).c_str(), false, Kind);
}
if (Info.isText())
if (Kind.isText())
return getTextSection();
if (Info.isBSS() && BSSSection_ != 0)
if (Kind.isBSS() && BSSSection_ != 0)
return BSSSection_;
if (Info.isReadOnly() && ReadOnlySection != 0)
if (Kind.isReadOnly() && ReadOnlySection != 0)
return ReadOnlySection;
return getDataSection();