Skip to content

Commit 04b4700

Browse files
committed
sink uniquing of sections out of MCContext into the ELF and PECOFF TLOF implementations.
MCContext no longer maintains a string -> section map. llvm-svn: 78874
1 parent 6bb66bb commit 04b4700

File tree

6 files changed

+49
-42
lines changed

6 files changed

+49
-42
lines changed

llvm/include/llvm/MC/MCContext.h

-10
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,6 @@ namespace llvm {
4646
public:
4747
MCContext();
4848
~MCContext();
49-
50-
/// GetSection - Look up a section with the given @param Name, returning
51-
/// null if it doesn't exist.
52-
MCSection *GetSection(const StringRef &Name) const;
53-
54-
void SetSection(const StringRef &Name, MCSection *S) {
55-
MCSection *&Entry = Sections[Name];
56-
assert(Entry == 0 && "Multiple sections with the same name created");
57-
Entry = S;
58-
}
5949

6050
/// CreateSymbol - Create a new symbol with the specified @param Name.
6151
///

llvm/include/llvm/MC/MCSection.h

+6-4
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ namespace llvm {
5252
/// of a syntactic one.
5353
bool IsDirective;
5454

55-
MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K,
56-
MCContext &Ctx);
55+
MCSectionELF(const StringRef &name, bool isDirective, SectionKind K)
56+
: MCSection(K), Name(name), IsDirective(isDirective) {
57+
}
5758
public:
5859

5960
static MCSectionELF *Create(const StringRef &Name, bool IsDirective,
@@ -77,8 +78,9 @@ namespace llvm {
7778
/// of a syntactic one.
7879
bool IsDirective;
7980

80-
MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K,
81-
MCContext &Ctx);
81+
MCSectionCOFF(const StringRef &name, bool isDirective, SectionKind K)
82+
: MCSection(K), Name(name), IsDirective(isDirective) {
83+
}
8284
public:
8385

8486
static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective,

llvm/include/llvm/Target/TargetLoweringObjectFile.h

+9-1
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ class TargetLoweringObjectFile {
183183

184184
class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
185185
bool HasCrazyBSS;
186+
mutable void *UniquingMap;
186187
protected:
187188
/// TLSDataSection - Section directive for Thread Local data.
188189
///
@@ -208,7 +209,10 @@ class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
208209
public:
209210
TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
210211
bool hasCrazyBSS = false)
211-
: HasCrazyBSS(hasCrazyBSS) {}
212+
: HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
213+
214+
~TargetLoweringObjectFileELF();
215+
212216

213217
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
214218

@@ -302,7 +306,11 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
302306

303307

304308
class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
309+
mutable void *UniquingMap;
305310
public:
311+
TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
312+
~TargetLoweringObjectFileCOFF();
313+
306314
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
307315

308316
virtual const MCSection *

llvm/lib/MC/MCContext.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@ MCContext::~MCContext() {
2222
// we don't need to free them here.
2323
}
2424

25-
MCSection *MCContext::GetSection(const StringRef &Name) const {
26-
StringMap<MCSection*>::const_iterator I = Sections.find(Name);
27-
return I != Sections.end() ? I->second : 0;
28-
}
29-
3025
MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
3126
assert(Name[0] != '\0' && "Normal symbols cannot be unnamed!");
3227

llvm/lib/MC/MCSection.cpp

+2-16
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,9 @@ MCSection::~MCSection() {
2727

2828
MCSectionELF *MCSectionELF::
2929
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
30-
return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
30+
return new (Ctx) MCSectionELF(Name, IsDirective, K);
3131
}
3232

33-
MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
34-
SectionKind K, MCContext &Ctx)
35-
: MCSection(K), Name(name), IsDirective(isDirective) {
36-
Ctx.SetSection(Name, this);
37-
}
38-
39-
4033
void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
4134
raw_ostream &OS) const {
4235
if (isDirective()) {
@@ -118,16 +111,9 @@ void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
118111

119112
MCSectionCOFF *MCSectionCOFF::
120113
Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
121-
return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
114+
return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
122115
}
123116

124-
MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
125-
SectionKind K, MCContext &Ctx)
126-
: MCSection(K), Name(name), IsDirective(isDirective) {
127-
Ctx.SetSection(Name, this);
128-
}
129-
130-
131117
void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
132118
raw_ostream &OS) const {
133119

llvm/lib/Target/TargetLoweringObjectFile.cpp

+32-6
Original file line numberDiff line numberDiff line change
@@ -280,12 +280,25 @@ TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
280280
//===----------------------------------------------------------------------===//
281281
// ELF
282282
//===----------------------------------------------------------------------===//
283+
typedef StringMap<const MCSectionELF*> ELFUniqueMapTy;
284+
285+
TargetLoweringObjectFileELF::~TargetLoweringObjectFileELF() {
286+
// If we have the section uniquing map, free it.
287+
delete (ELFUniqueMapTy*)UniquingMap;
288+
}
283289

284290
const MCSection *TargetLoweringObjectFileELF::
285291
getELFSection(const char *Name, bool isDirective, SectionKind Kind) const {
286-
if (MCSection *S = getContext().GetSection(Name))
287-
return S;
288-
return MCSectionELF::Create(Name, isDirective, Kind, getContext());
292+
// Create the map if it doesn't already exist.
293+
if (UniquingMap == 0)
294+
UniquingMap = new ELFUniqueMapTy();
295+
ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
296+
297+
// Do the lookup, if we have a hit, return it.
298+
const MCSectionELF *&Entry = Map[Name];
299+
if (Entry) return Entry;
300+
301+
return Entry = MCSectionELF::Create(Name, isDirective, Kind, getContext());
289302
}
290303

291304
void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
@@ -805,12 +818,25 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const {
805818
// COFF
806819
//===----------------------------------------------------------------------===//
807820

821+
typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
822+
823+
TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF() {
824+
delete (COFFUniqueMapTy*)UniquingMap;
825+
}
826+
808827

809828
const MCSection *TargetLoweringObjectFileCOFF::
810829
getCOFFSection(const char *Name, bool isDirective, SectionKind Kind) const {
811-
if (MCSection *S = getContext().GetSection(Name))
812-
return S;
813-
return MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
830+
// Create the map if it doesn't already exist.
831+
if (UniquingMap == 0)
832+
UniquingMap = new MachOUniqueMapTy();
833+
COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)UniquingMap;
834+
835+
// Do the lookup, if we have a hit, return it.
836+
const MCSectionCOFF *&Entry = Map[Name];
837+
if (Entry) return Entry;
838+
839+
return Entry = MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
814840
}
815841

816842
void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,

0 commit comments

Comments
 (0)