mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-24 03:33:20 +01:00
implement support for uniquing MachO sections.
llvm-svn: 78866
This commit is contained in:
parent
9c9c3f30bd
commit
4c9dae455e
@ -20,6 +20,7 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
class Mangler;
|
class Mangler;
|
||||||
class MCSection;
|
class MCSection;
|
||||||
|
class MCSectionMachO;
|
||||||
class MCContext;
|
class MCContext;
|
||||||
class GlobalValue;
|
class GlobalValue;
|
||||||
class StringRef;
|
class StringRef;
|
||||||
@ -28,6 +29,9 @@ namespace llvm {
|
|||||||
|
|
||||||
class TargetLoweringObjectFile {
|
class TargetLoweringObjectFile {
|
||||||
MCContext *Ctx;
|
MCContext *Ctx;
|
||||||
|
|
||||||
|
TargetLoweringObjectFile(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
|
||||||
|
void operator=(const TargetLoweringObjectFile&); // DO NOT IMPLEMENT
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
TargetLoweringObjectFile();
|
TargetLoweringObjectFile();
|
||||||
@ -225,6 +229,8 @@ public:
|
|||||||
|
|
||||||
|
|
||||||
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
|
class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
|
||||||
|
mutable void *UniquingMap;
|
||||||
|
|
||||||
const MCSection *CStringSection;
|
const MCSection *CStringSection;
|
||||||
const MCSection *UStringSection;
|
const MCSection *UStringSection;
|
||||||
const MCSection *TextCoalSection;
|
const MCSection *TextCoalSection;
|
||||||
@ -236,6 +242,8 @@ class TargetLoweringObjectFileMachO : public TargetLoweringObjectFile {
|
|||||||
const MCSection *EightByteConstantSection;
|
const MCSection *EightByteConstantSection;
|
||||||
const MCSection *SixteenByteConstantSection;
|
const MCSection *SixteenByteConstantSection;
|
||||||
public:
|
public:
|
||||||
|
TargetLoweringObjectFileMachO() : UniquingMap(0) {}
|
||||||
|
~TargetLoweringObjectFileMachO();
|
||||||
|
|
||||||
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
|
virtual void Initialize(MCContext &Ctx, const TargetMachine &TM);
|
||||||
|
|
||||||
@ -257,16 +265,17 @@ public:
|
|||||||
|
|
||||||
/// getMachOSection - Return the MCSection for the specified mach-o section.
|
/// getMachOSection - Return the MCSection for the specified mach-o section.
|
||||||
/// This requires the operands to be valid.
|
/// This requires the operands to be valid.
|
||||||
const MCSection *getMachOSection(const StringRef &Segment,
|
const MCSectionMachO *getMachOSection(const StringRef &Segment,
|
||||||
const StringRef &Section,
|
const StringRef &Section,
|
||||||
unsigned TypeAndAttributes,
|
unsigned TypeAndAttributes,
|
||||||
SectionKind K) const {
|
SectionKind K) const {
|
||||||
return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
|
return getMachOSection(Segment, Section, TypeAndAttributes, 0, K);
|
||||||
}
|
}
|
||||||
const MCSection *getMachOSection(const StringRef &Segment,
|
const MCSectionMachO *getMachOSection(const StringRef &Segment,
|
||||||
const StringRef &Section,
|
const StringRef &Section,
|
||||||
unsigned TypeAndAttributes,
|
unsigned TypeAndAttributes,
|
||||||
unsigned Reserved2, SectionKind K) const;
|
unsigned Reserved2,
|
||||||
|
SectionKind K) const;
|
||||||
|
|
||||||
/// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
|
/// getTextCoalSection - Return the "__TEXT,__textcoal_nt" section we put weak
|
||||||
/// symbols into.
|
/// symbols into.
|
||||||
|
@ -24,6 +24,7 @@
|
|||||||
#include "llvm/Target/TargetMachine.h"
|
#include "llvm/Target/TargetMachine.h"
|
||||||
#include "llvm/Target/TargetOptions.h"
|
#include "llvm/Target/TargetOptions.h"
|
||||||
#include "llvm/Support/Mangler.h"
|
#include "llvm/Support/Mangler.h"
|
||||||
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringExtras.h"
|
#include "llvm/ADT/StringExtras.h"
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
|
|
||||||
@ -128,7 +129,6 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
|
|||||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
||||||
if (GVar == 0)
|
if (GVar == 0)
|
||||||
return SectionKind::getText();
|
return SectionKind::getText();
|
||||||
|
|
||||||
|
|
||||||
// Handle thread-local data first.
|
// Handle thread-local data first.
|
||||||
if (GVar->isThreadLocal()) {
|
if (GVar->isThreadLocal()) {
|
||||||
@ -509,17 +509,40 @@ getSectionForConstant(SectionKind Kind) const {
|
|||||||
// MachO
|
// 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,
|
getMachOSection(const StringRef &Segment, const StringRef &Section,
|
||||||
unsigned TypeAndAttributes,
|
unsigned TypeAndAttributes,
|
||||||
unsigned Reserved2, SectionKind Kind) const {
|
unsigned Reserved2, SectionKind Kind) const {
|
||||||
// FIXME: UNIQUE HERE.
|
// We unique sections by their segment/section pair. The returned section
|
||||||
//if (MCSection *S = getContext().GetSection(Name))
|
// may not have the same flags as the requested section, if so this should be
|
||||||
// return S;
|
// diagnosed by the client as an error.
|
||||||
|
|
||||||
return MCSectionMachO::Create(Segment, Section, TypeAndAttributes, Reserved2,
|
// Create the map if it doesn't already exist.
|
||||||
Kind, getContext());
|
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());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user