diff options
author | Chris Lattner <sabre@nondot.org> | 2009-08-12 23:55:02 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-08-12 23:55:02 +0000 |
commit | 2d5bdc2bce68585c6f91249e66adf3b71d15aa4d (patch) | |
tree | eaf8e8973ac7f8ad063bcc8f65d6c15241219500 /llvm/lib/Target/TargetLoweringObjectFile.cpp | |
parent | 69273e64747ccf17ce1ac68bc7114cb4f6301d2e (diff) | |
download | bcm5719-llvm-2d5bdc2bce68585c6f91249e66adf3b71d15aa4d.tar.gz bcm5719-llvm-2d5bdc2bce68585c6f91249e66adf3b71d15aa4d.zip |
implement support for uniquing MachO sections.
llvm-svn: 78866
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r-- | llvm/lib/Target/TargetLoweringObjectFile.cpp | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp index 321af98a74b..904f01ae354 100644 --- a/llvm/lib/Target/TargetLoweringObjectFile.cpp +++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp @@ -24,6 +24,7 @@ #include "llvm/Target/TargetMachine.h" #include "llvm/Target/TargetOptions.h" #include "llvm/Support/Mangler.h" +#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringExtras.h" using namespace llvm; @@ -128,7 +129,6 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV, const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV); if (GVar == 0) return SectionKind::getText(); - // Handle thread-local data first. if (GVar->isThreadLocal()) { @@ -509,17 +509,40 @@ getSectionForConstant(SectionKind Kind) const { // MachO //===----------------------------------------------------------------------===// +typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; -const MCSection *TargetLoweringObjectFileMachO:: +TargetLoweringObjectFileMachO::~TargetLoweringObjectFileMachO() { + // If we have the MachO uniquing map, free it. + delete (MachOUniqueMapTy*)UniquingMap; +} + + +const MCSectionMachO *TargetLoweringObjectFileMachO:: getMachOSection(const StringRef &Segment, const StringRef &Section, unsigned TypeAndAttributes, unsigned Reserved2, SectionKind Kind) const { - // FIXME: UNIQUE HERE. - //if (MCSection *S = getContext().GetSection(Name)) - // return S; - - return MCSectionMachO::Create(Segment, Section, TypeAndAttributes, Reserved2, - Kind, getContext()); + // We unique sections by their segment/section pair. The returned section + // may not have the same flags as the requested section, if so this should be + // diagnosed by the client as an error. + + // Create the map if it doesn't already exist. + if (UniquingMap == 0) + UniquingMap = new MachOUniqueMapTy(); + MachOUniqueMapTy &Map = *(MachOUniqueMapTy*)UniquingMap; + + // Form the name to look up. + SmallString<64> Name; + Name.append(Segment.begin(), Segment.end()); + Name.push_back(','); + Name.append(Section.begin(), Section.end()); + + // Do the lookup, if we have a hit, return it. + const MCSectionMachO *&Entry = Map[StringRef(Name.data(), Name.size())]; + if (Entry) return Entry; + + // Otherwise, return a new section. + return Entry = MCSectionMachO::Create(Segment, Section, TypeAndAttributes, + Reserved2, Kind, getContext()); } |