llvm.org GIT mirror llvm / 38cff38
sink uniquing of sections out of MCContext into the ELF and PECOFF TLOF implementations. MCContext no longer maintains a string -> section map. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78874 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 10 years ago
6 changed file(s) with 49 addition(s) and 42 deletion(s). Raw diff Collapse all Expand all
4545 public:
4646 MCContext();
4747 ~MCContext();
48
49 /// GetSection - Look up a section with the given @param Name, returning
50 /// null if it doesn't exist.
51 MCSection *GetSection(const StringRef &Name) const;
52
53 void SetSection(const StringRef &Name, MCSection *S) {
54 MCSection *&Entry = Sections[Name];
55 assert(Entry == 0 && "Multiple sections with the same name created");
56 Entry = S;
57 }
5848
5949 /// CreateSymbol - Create a new symbol with the specified @param Name.
6050 ///
5151 /// of a syntactic one.
5252 bool IsDirective;
5353
54 MCSectionELF(const StringRef &Name, bool IsDirective, SectionKind K,
55 MCContext &Ctx);
54 MCSectionELF(const StringRef &name, bool isDirective, SectionKind K)
55 : MCSection(K), Name(name), IsDirective(isDirective) {
56 }
5657 public:
5758
5859 static MCSectionELF *Create(const StringRef &Name, bool IsDirective,
7677 /// of a syntactic one.
7778 bool IsDirective;
7879
79 MCSectionCOFF(const StringRef &Name, bool IsDirective, SectionKind K,
80 MCContext &Ctx);
80 MCSectionCOFF(const StringRef &name, bool isDirective, SectionKind K)
81 : MCSection(K), Name(name), IsDirective(isDirective) {
82 }
8183 public:
8284
8385 static MCSectionCOFF *Create(const StringRef &Name, bool IsDirective,
182182
183183 class TargetLoweringObjectFileELF : public TargetLoweringObjectFile {
184184 bool HasCrazyBSS;
185 mutable void *UniquingMap;
185186 protected:
186187 /// TLSDataSection - Section directive for Thread Local data.
187188 ///
207208 public:
208209 TargetLoweringObjectFileELF(// FIXME: REMOVE AFTER UNIQUING IS FIXED.
209210 bool hasCrazyBSS = false)
210 : HasCrazyBSS(hasCrazyBSS) {}
211 : HasCrazyBSS(hasCrazyBSS), UniquingMap(0) {}
212
213 ~TargetLoweringObjectFileELF();
214
211215
212216 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
213217
301305
302306
303307 class TargetLoweringObjectFileCOFF : public TargetLoweringObjectFile {
308 mutable void *UniquingMap;
304309 public:
310 TargetLoweringObjectFileCOFF() : UniquingMap(0) {}
311 ~TargetLoweringObjectFileCOFF();
312
305313 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
306314
307315 virtual const MCSection *
1919 MCContext::~MCContext() {
2020 // NOTE: The sections are all allocated out of a bump pointer allocator,
2121 // we don't need to free them here.
22 }
23
24 MCSection *MCContext::GetSection(const StringRef &Name) const {
25 StringMap::const_iterator I = Sections.find(Name);
26 return I != Sections.end() ? I->second : 0;
2722 }
2823
2924 MCSymbol *MCContext::CreateSymbol(const StringRef &Name) {
2626
2727 MCSectionELF *MCSectionELF::
2828 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
29 return new (Ctx) MCSectionELF(Name, IsDirective, K, Ctx);
29 return new (Ctx) MCSectionELF(Name, IsDirective, K);
3030 }
31
32 MCSectionELF::MCSectionELF(const StringRef &name, bool isDirective,
33 SectionKind K, MCContext &Ctx)
34 : MCSection(K), Name(name), IsDirective(isDirective) {
35 Ctx.SetSection(Name, this);
36 }
37
3831
3932 void MCSectionELF::PrintSwitchToSection(const TargetAsmInfo &TAI,
4033 raw_ostream &OS) const {
117110
118111 MCSectionCOFF *MCSectionCOFF::
119112 Create(const StringRef &Name, bool IsDirective, SectionKind K, MCContext &Ctx) {
120 return new (Ctx) MCSectionCOFF(Name, IsDirective, K, Ctx);
113 return new (Ctx) MCSectionCOFF(Name, IsDirective, K);
121114 }
122
123 MCSectionCOFF::MCSectionCOFF(const StringRef &name, bool isDirective,
124 SectionKind K, MCContext &Ctx)
125 : MCSection(K), Name(name), IsDirective(isDirective) {
126 Ctx.SetSection(Name, this);
127 }
128
129115
130116 void MCSectionCOFF::PrintSwitchToSection(const TargetAsmInfo &TAI,
131117 raw_ostream &OS) const {
279279 //===----------------------------------------------------------------------===//
280280 // ELF
281281 //===----------------------------------------------------------------------===//
282 typedef StringMap ELFUniqueMapTy;
283
284 TargetLoweringObjectFileELF::~TargetLoweringObjectFileELF() {
285 // If we have the section uniquing map, free it.
286 delete (ELFUniqueMapTy*)UniquingMap;
287 }
282288
283289 const MCSection *TargetLoweringObjectFileELF::
284290 getELFSection(const char *Name, bool isDirective, SectionKind Kind) const {
285 if (MCSection *S = getContext().GetSection(Name))
286 return S;
287 return MCSectionELF::Create(Name, isDirective, Kind, getContext());
291 // Create the map if it doesn't already exist.
292 if (UniquingMap == 0)
293 UniquingMap = new ELFUniqueMapTy();
294 ELFUniqueMapTy &Map = *(ELFUniqueMapTy*)UniquingMap;
295
296 // Do the lookup, if we have a hit, return it.
297 const MCSectionELF *&Entry = Map[Name];
298 if (Entry) return Entry;
299
300 return Entry = MCSectionELF::Create(Name, isDirective, Kind, getContext());
288301 }
289302
290303 void TargetLoweringObjectFileELF::Initialize(MCContext &Ctx,
804817 // COFF
805818 //===----------------------------------------------------------------------===//
806819
820 typedef StringMap COFFUniqueMapTy;
821
822 TargetLoweringObjectFileCOFF::~TargetLoweringObjectFileCOFF() {
823 delete (COFFUniqueMapTy*)UniquingMap;
824 }
825
807826
808827 const MCSection *TargetLoweringObjectFileCOFF::
809828 getCOFFSection(const char *Name, bool isDirective, SectionKind Kind) const {
810 if (MCSection *S = getContext().GetSection(Name))
811 return S;
812 return MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
829 // Create the map if it doesn't already exist.
830 if (UniquingMap == 0)
831 UniquingMap = new MachOUniqueMapTy();
832 COFFUniqueMapTy &Map = *(COFFUniqueMapTy*)UniquingMap;
833
834 // Do the lookup, if we have a hit, return it.
835 const MCSectionCOFF *&Entry = Map[Name];
836 if (Entry) return Entry;
837
838 return Entry = MCSectionCOFF::Create(Name, isDirective, Kind, getContext());
813839 }
814840
815841 void TargetLoweringObjectFileCOFF::Initialize(MCContext &Ctx,