llvm.org GIT mirror llvm / 5dc47ff
implement support for uniquing MachO sections. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@78866 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 49 addition(s) and 17 deletion(s). Raw diff Collapse all Expand all
1919 namespace llvm {
2020 class Mangler;
2121 class MCSection;
22 class MCSectionMachO;
2223 class MCContext;
2324 class GlobalValue;
2425 class StringRef;
2728
2829 class TargetLoweringObjectFile {
2930 MCContext *Ctx;
31
32 TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
33 void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
3034 protected:
3135
3236 TargetLoweringObjectFile();
224228
225229
226230 class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
231 mutable void *UniquingMap;
232
227233 const MCSection *CStringSection;
228234 const MCSection *UStringSection;
229235 const MCSection *TextCoalSection;
235241 const MCSection *EightByteConstantSection;
236242 const MCSection *SixteenByteConstantSection;
237243 public:
244 TargetLoweringObjectFileMachO() : UniquingMap(0) {}
245 ~TargetLoweringObjectFileMachO();
238246
239247 virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
240248
256264
257265 /// getMachOSection - Return the MCSection for the specified mach-o section.
258266 /// This requires the operands to be valid.
259 const MCSection *getMachOSection(const StringRef &Segment,
260 const StringRef &Section,
261 unsigned TypeAndAttributes,
262 SectionKind K) const {
267 const MCSectionMachO *getMachOSection(const StringRef &Segment,
268 const StringRef &Section,
269 unsigned TypeAndAttributes,
270 SectionKind K) const {
263271 return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
264272 }
265 const MCSection *getMachOSection(const StringRef &Segment,
266 const StringRef &Section,
267 unsigned TypeAndAttributes,
268 unsigned Reserved2, SectionKind K) const;
273 const MCSectionMachO *getMachOSection(const StringRef &Segment,
274 const StringRef &Section,
275 unsigned TypeAndAttributes,
276 unsigned Reserved2,
277 SectionKind K) const;
269278
270279 /// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
271280 /// symbols into.
2323 #include "llvm/Target/TargetMachine.h"
2424 #include "llvm/Target/TargetOptions.h"
2525 #include "llvm/Support/Mangler.h"
26 #include "llvm/ADT/SmallString.h"
2627 #include "llvm/ADT/StringExtras.h"
2728 using namespace llvm;
2829
127128 const GlobalVariable *GVar = dyn_cast(GV);
128129 if (GVar == 0)
129130 return SectionKind::getText();
130
131131
132132 // Handle thread-local data first.
133133 if (GVar->isThreadLocal()) {
508508 // MachO
509509 //===----------------------------------------------------------------------===//
510510
511
512 const MCSection *TargetLoweringObjectFileMachO::
511 typedef StringMap MachOUniqueMapTy;
512
513 TargetLoweringObjectFileMachO::~TargetLoweringObjectFileMachO() {
514 // If we have the MachO uniquing map, free it.
515 delete (MachOUniqueMapTy*)UniquingMap;
516 }
517
518
519 const MCSectionMachO *TargetLoweringObjectFileMachO::
513520 getMachOSection(const StringRef &Segment, const StringRef &Section,
514521 unsigned TypeAndAttributes,
515522 unsigned Reserved2, SectionKind Kind) const {
516 // FIXME: UNIQUE HERE.
517 //if (MCSection *S = getContext().GetSection(Name))
518 // return S;
519
520 return MCSectionMachO::Create(Segment, Section, TypeAndAttributes, Reserved2,
521 Kind, getContext());
523 // We unique sections by their segment/section pair. The returned section
524 // may not have the same flags as the requested section, if so this should be
525 // diagnosed by the client as an error.
526
527 // Create the map if it doesn't already exist.
528 if (UniquingMap == 0)
529 UniquingMap = new MachOUniqueMapTy();
530 MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)UniquingMap;
531
532 // Form the name to look up.
533 SmallString<64> Name;
534 Name.append(Segment.begin(), Segment.end());
535 Name.push_back(',');
536 Name.append(Section.begin(), Section.end());
537
538 // Do the lookup, if we have a hit, return it.
539 const MCSectionMachO *&Entry = Map[StringRef(Name.data(), Name.size())];
540 if (Entry) return Entry;
541
542 // Otherwise, return a new section.
543 return Entry = MCSectionMachO::Create(Segment, Section, TypeAndAttributes,
544 Reserved2, Kind, getContext());
522545 }
523546
524547