[llvm-commits] [llvm] r78866 - in /llvm/trunk: include/llvm/Target/TargetLoweringObjectFile.h lib/Target/TargetLoweringObjectFile.cpp
Chris Lattner
sabre at nondot.org
Wed Aug 12 16:55:02 PDT 2009
Author: lattner
Date: Wed Aug 12 18:55:02 2009
New Revision: 78866
URL: http://llvm.org/viewvc/llvm-project?rev=78866&view=rev
Log:
implement support for uniquing MachO sections.
Modified:
llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
Modified: llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h?rev=78866&r1=78865&r2=78866&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h (original)
+++ llvm/trunk/include/llvm/Target/TargetLoweringObjectFile.h Wed Aug 12 18:55:02 2009
@@ -20,6 +20,7 @@
namespace llvm {
class Mangler;
class MCSection;
+ class MCSectionMachO;
class MCContext;
class GlobalValue;
class StringRef;
@@ -28,6 +29,9 @@
class TargetLoweringObjectFile {
MCContext *Ctx;
+
+ TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
+ void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
protected:
TargetLoweringObjectFile();
@@ -225,6 +229,8 @@
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
+ mutable void *UniquingMap;
+
const MCSection *CStringSection;
const MCSection *UStringSection;
const MCSection *TextCoalSection;
@@ -236,6 +242,8 @@
const MCSection *EightByteConstantSection;
const MCSection *SixteenByteConstantSection;
public:
+ TargetLoweringObjectFileMachO() : UniquingMap(0) {}
+ ~TargetLoweringObjectFileMachO();
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
@@ -257,16 +265,17 @@
/// getMachOSection - Return the MCSection for the specified mach-o section.
/// This requires the operands to be valid.
- const MCSection *getMachOSection(const StringRef &Segment,
- const StringRef &Section,
- unsigned TypeAndAttributes,
- SectionKind K) const {
+ const MCSectionMachO *getMachOSection(const StringRef &Segment,
+ const StringRef &Section,
+ unsigned TypeAndAttributes,
+ SectionKind K) const {
return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
}
- const MCSection *getMachOSection(const StringRef &Segment,
- const StringRef &Section,
- unsigned TypeAndAttributes,
- unsigned Reserved2, SectionKind K) const;
+ const MCSectionMachO *getMachOSection(const StringRef &Segment,
+ const StringRef &Section,
+ unsigned TypeAndAttributes,
+ unsigned Reserved2,
+ SectionKind K) const;
/// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
/// symbols into.
Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=78866&r1=78865&r2=78866&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Wed Aug 12 18:55:02 2009
@@ -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 @@
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 @@
// 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());
}
More information about the llvm-commits
mailing list