From 26fb277f92c7c11d518c17b82115f5c161a58857 Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Sat, 1 Aug 2009 21:46:23 +0000 Subject: [PATCH] it turns out that isWeak() was basically dead anyway. Kill off SectionInfo :-/ llvm-svn: 77812 --- llvm/include/llvm/MC/MCSection.h | 4 +- .../include/llvm/Target/TargetLoweringObjectFile.h | 40 ++-------- llvm/lib/Target/PIC16/PIC16TargetObjectFile.cpp | 8 +- llvm/lib/Target/PIC16/PIC16TargetObjectFile.h | 4 +- llvm/lib/Target/TargetLoweringObjectFile.cpp | 87 +++++++++++----------- 5 files changed, 57 insertions(+), 86 deletions(-) diff --git a/llvm/include/llvm/MC/MCSection.h b/llvm/include/llvm/MC/MCSection.h index e9f7666..bdc46be 100644 --- a/llvm/include/llvm/MC/MCSection.h +++ b/llvm/include/llvm/MC/MCSection.h @@ -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; } }; diff --git a/llvm/include/llvm/Target/TargetLoweringObjectFile.h b/llvm/include/llvm/Target/TargetLoweringObjectFile.h index 8727aef..2b2d52f 100644 --- a/llvm/include/llvm/Target/TargetLoweringObjectFile.h +++ b/llvm/include/llvm/Target/TargetLoweringObjectFile.h @@ -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 &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 &Str) const; virtual const MCSection * - SelectSectionForGlobal(const GlobalValue *GV, SectionInfo Kind, + SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind, Mangler *Mang, const TargetMachine &TM) const; }; diff --git a/llvm/lib/Target/PIC16/PIC16TargetObjectFile.cpp b/llvm/lib/Target/PIC16/PIC16TargetObjectFile.cpp index 91e98b2..78e88ca 100644 --- a/llvm/lib/Target/PIC16/PIC16TargetObjectFile.cpp +++ b/llvm/lib/Target/PIC16/PIC16TargetObjectFile.cpp @@ -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(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(GV)) { diff --git a/llvm/lib/Target/PIC16/PIC16TargetObjectFile.h b/llvm/lib/Target/PIC16/PIC16TargetObjectFile.h index 831f924..c296954 100644 --- a/llvm/lib/Target/PIC16/PIC16TargetObjectFile.h +++ b/llvm/lib/Target/PIC16/PIC16TargetObjectFile.h @@ -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: diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp index ae306c4..7e071f4 100644 --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -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(GV)->getInitializer(); const Type *Ty = cast(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(); -- 2.7.4