[llvm-commits] [llvm] r78874 - in /llvm/trunk: include/llvm/MC/MCContext.h include/llvm/MC/MCSection.h include/llvm/Target/TargetLoweringObjectFile.h lib/MC/MCContext.cpp lib/MC/MCSection.cpp lib/Target/TargetLoweringObjectFile.cpp
Chris Lattner
sabre at nondot.org
Wed Aug 12 17:37:15 PDT 2009
Author: lattner
Date: Wed Aug 12 19:37:15 2009
New Revision: 78874
URL: http://llvm.org/viewvc/llvm-project?rev=78874&view=rev
Log:
sink uniquing of sections out of MCContext into the ELF and PECOFF TLOF implementations.
MCContext no longer maintains a string -> section map.
Modified:
llvm/trunk/include/llvm/MC/MCContext.h
llvm/trunk/include/llvm/MC/MCSection.h
llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
llvm/trunk/lib/MC/MCContext.cpp
llvm/trunk/lib/MC/MCSection.cpp
llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
Modified: llvm/trunk/include/llvm/MC/MCContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCContext.h?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCContext.h (original)
+++ llvm/trunk/include/llvm/MC/MCContext.h Wed Aug 12 19:37:15 2009
@@ -46,16 +46,6 @@
public:
MCContext();
~MCContext();
-
- /// GetSection - Look up a section with the given @param Name, returning
- /// null if it doesn't exist.
- MCSection *GetSection(const StringRef &Name) const;
-
- void SetSection(const StringRef &Name, MCSection *S) {
- MCSection *&Entry = Sections[Name];
- assert(Entry == 0 && "Multiple sections with the same name created");
- Entry = S;
- }
/// CreateSymbol - Create a new symbol with the specified @param Name.
///
Modified: llvm/trunk/include/llvm/MC/MCSection.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/MC/MCSection.h?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/include/llvm/MC/MCSection.h (original)
+++ llvm/trunk/include/llvm/MC/MCSection.h Wed Aug 12 19:37:15 2009
@@ -52,8 +52,9 @@
/// of a syntactic one.
bool IsDirective;
- MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K,
- MCContext &Ctx);
+ MCSectionELF(const StringRef &name, bool isDirective, SectionKind K)
+ : MCSection(K), Name(name), IsDirective(isDirective) {
+ }
public:
static MCSectionELF *Create(const StringRef &Name, bool IsDirective,
@@ -77,8 +78,9 @@
/// of a syntactic one.
bool IsDirective;
- MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K,
- MCContext &Ctx);
+ MCSectionCOFF(const StringRef &name, bool isDirective, SectionKind K)
+ : MCSection(K), Name(name), IsDirective(isDirective) {
+ }
public:
static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective,
Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Wed Aug 12 19:37:15 2009
@@ -183,6 +183,7 @@
class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
bool HasCrazyBSS;
+ mutable void *UniquingMap;
protected:
/// TLSDataSection - Section directive for Thread Local data.
///
@@ -208,7 +209,10 @@
public:
TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
bool hasCrazyBSS = false)
- : HasCrazyBSS(hasCrazyBSS) {}
+ : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
+
+ ~TargetLoweringObjectFileELF();
+
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
@@ -302,7 +306,11 @@
class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
+ mutable void *UniquingMap;
public:
+ TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
+ ~TargetLoweringObjectFileCOFF();
+
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
virtual const MCSection *
Modified: llvm/trunk/lib/MC/MCContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCContext.cpp?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCContext.cpp (original)
+++ llvm/trunk/lib/MC/MCContext.cpp Wed Aug 12 19:37:15 2009
@@ -22,11 +22,6 @@
// we don't need to free them here.
}
-MCSection *MCContext::GetSection(const StringRef &Name) const {
- StringMap<MCSection*>::const_iterator I = Sections.find(Name);
- return I != Sections.end() ? I->second : 0;
-}
-
MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
Modified: llvm/trunk/lib/MC/MCSection.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCSection.cpp?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCSection.cpp (original)
+++ llvm/trunk/lib/MC/MCSection.cpp Wed Aug 12 19:37:15 2009
@@ -27,16 +27,9 @@
MCSectionELF *MCSectionELF::
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
- return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
+ return new (Ctx) MCSectionELF(Name, IsDirective, K);
}
-MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
- SectionKind K, MCContext &Ctx)
- : MCSection(K), Name(name), IsDirective(isDirective) {
- Ctx.SetSection(Name, this);
-}
-
-
void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const {
if (isDirective()) {
@@ -118,16 +111,9 @@
MCSectionCOFF *MCSectionCOFF::
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
- return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
+ return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
}
-MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
- SectionKind K, MCContext &Ctx)
- : MCSection(K), Name(name), IsDirective(isDirective) {
- Ctx.SetSection(Name, this);
-}
-
-
void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
raw_ostream &OS) const {
Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=78874&r1=78873&r2=78874&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Wed Aug 12 19:37:15 2009
@@ -280,12 +280,25 @@
//===----------------------------------------------------------------------===//
// ELF
//===----------------------------------------------------------------------===//
+typedef StringMap<const MCSectionELF*> ELFUniqueMapTy;
+
+TargetLoweringObjectFileELF::~TargetLoweringObjectFileELF() {
+ // If we have the section uniquing map, free it.
+ delete (ELFUniqueMapTy*)UniquingMap;
+}
const MCSection *TargetLoweringObjectFileELF::
getELFSection(const char *Name, bool isDirective, SectionKind Kind) const {
- if (MCSection *S = getContext().GetSection(Name))
- return S;
- return MCSectionELF::Create(Name, isDirective, Kind, getContext());
+ // Create the map if it doesn't already exist.
+ if (UniquingMap == 0)
+ UniquingMap = new ELFUniqueMapTy();
+ ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
+
+ // Do the lookup, if we have a hit, return it.
+ const MCSectionELF *&Entry = Map[Name];
+ if (Entry) return Entry;
+
+ return Entry = MCSectionELF::Create(Name, isDirective, Kind, getContext());
}
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
@@ -805,12 +818,25 @@
// COFF
//===----------------------------------------------------------------------===//
+typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
+
+TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF() {
+ delete (COFFUniqueMapTy*)UniquingMap;
+}
+
const MCSection *TargetLoweringObjectFileCOFF::
getCOFFSection(const char *Name, bool isDirective, SectionKind Kind) const {
- if (MCSection *S = getContext().GetSection(Name))
- return S;
- return MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
+ // Create the map if it doesn't already exist.
+ if (UniquingMap == 0)
+ UniquingMap = new MachOUniqueMapTy();
+ COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)UniquingMap;
+
+ // Do the lookup, if we have a hit, return it.
+ const MCSectionCOFF *&Entry = Map[Name];
+ if (Entry) return Entry;
+
+ return Entry = MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
}
void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,
More information about the llvm-commits
mailing list