@@ -280,12 +280,25 @@ TargetLoweringObjectFile::getSectionForConstant(SectionKind Kind) const {
280
280
// ===----------------------------------------------------------------------===//
281
281
// ELF
282
282
// ===----------------------------------------------------------------------===//
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
+ }
283
289
284
290
const MCSection *TargetLoweringObjectFileELF::
285
291
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 ());
289
302
}
290
303
291
304
void TargetLoweringObjectFileELF::Initialize (MCContext &Ctx,
@@ -805,12 +818,25 @@ shouldEmitUsedDirectiveFor(const GlobalValue *GV, Mangler *Mang) const {
805
818
// COFF
806
819
// ===----------------------------------------------------------------------===//
807
820
821
+ typedef StringMap<const MCSectionCOFF*> COFFUniqueMapTy;
822
+
823
+ TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF () {
824
+ delete (COFFUniqueMapTy*)UniquingMap;
825
+ }
826
+
808
827
809
828
const MCSection *TargetLoweringObjectFileCOFF::
810
829
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 ());
814
840
}
815
841
816
842
void TargetLoweringObjectFileCOFF::Initialize (MCContext &Ctx,
0 commit comments