forked from OSchip/llvm-project
Target: Change various section classifiers in TargetLoweringObjectFile to take a GlobalObject.
These functions are about classifying a global which will actually be emitted, so it does not make sense for them to take a GlobalValue which may for example be an alias. Change the Mach-O object writer and the Hexagon, Lanai and MIPS backends to look through aliases before using TargetLoweringObjectFile interfaces. These are functional changes but all appear to be bug fixes. Differential Revision: https://reviews.llvm.org/D25917 llvm-svn: 285006
This commit is contained in:
parent
87eea10711
commit
6733564e5a
|
@ -53,10 +53,10 @@ public:
|
|||
const Constant *C,
|
||||
unsigned &Align) const override;
|
||||
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *getSectionForJumpTable(const Function &F,
|
||||
|
@ -103,10 +103,10 @@ public:
|
|||
ArrayRef<Module::ModuleFlagEntry> ModuleFlags,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
|
||||
|
@ -144,10 +144,10 @@ public:
|
|||
~TargetLoweringObjectFileCOFF() override {}
|
||||
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
void getNameWithPrefix(SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
namespace llvm {
|
||||
|
||||
class Comdat;
|
||||
class GlobalObject;
|
||||
class PointerType;
|
||||
class Module;
|
||||
|
||||
|
@ -492,6 +493,11 @@ public:
|
|||
// increased.
|
||||
bool canIncreaseAlignment() const;
|
||||
|
||||
const GlobalObject *getBaseObject() const {
|
||||
return const_cast<GlobalValue *>(this)->getBaseObject();
|
||||
}
|
||||
GlobalObject *getBaseObject();
|
||||
|
||||
/// This method unlinks 'this' from the containing module, but does not delete
|
||||
/// it.
|
||||
virtual void removeFromParent() = 0;
|
||||
|
|
|
@ -86,21 +86,21 @@ public:
|
|||
|
||||
/// Classify the specified global variable into a set of target independent
|
||||
/// categories embodied in SectionKind.
|
||||
static SectionKind getKindForGlobal(const GlobalValue *GV,
|
||||
static SectionKind getKindForGlobal(const GlobalObject *GO,
|
||||
const TargetMachine &TM);
|
||||
|
||||
/// This method computes the appropriate section to emit the specified global
|
||||
/// variable or function definition. This should not be passed external (or
|
||||
/// available externally) globals.
|
||||
MCSection *SectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
/// This method computes the appropriate section to emit the specified global
|
||||
/// variable or function definition. This should not be passed external (or
|
||||
/// available externally) globals.
|
||||
MCSection *SectionForGlobal(const GlobalValue *GV,
|
||||
MCSection *SectionForGlobal(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const {
|
||||
return SectionForGlobal(GV, getKindForGlobal(GV, TM), TM);
|
||||
return SectionForGlobal(GO, getKindForGlobal(GO, TM), TM);
|
||||
}
|
||||
|
||||
virtual void getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
||||
|
@ -115,9 +115,9 @@ public:
|
|||
|
||||
/// Targets should implement this method to assign a section to globals with
|
||||
/// an explicit section specfied. The implementation of this method can
|
||||
/// assume that GV->hasSection() is true.
|
||||
/// assume that GO->hasSection() is true.
|
||||
virtual MCSection *
|
||||
getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const = 0;
|
||||
|
||||
/// Return an MCExpr to use for a reference to the specified global variable
|
||||
|
@ -187,7 +187,7 @@ public:
|
|||
const GlobalValue *GV) const {}
|
||||
|
||||
protected:
|
||||
virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
|
||||
virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
|
||||
SectionKind Kind,
|
||||
const TargetMachine &TM) const = 0;
|
||||
};
|
||||
|
|
|
@ -209,15 +209,15 @@ static const Comdat *getELFComdat(const GlobalValue *GV) {
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileELF::getExplicitSectionGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
StringRef SectionName = GV->getSection();
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
StringRef SectionName = GO->getSection();
|
||||
|
||||
// Infer section flags from the section name if we can.
|
||||
Kind = getELFKindForNamedSection(SectionName, Kind);
|
||||
|
||||
StringRef Group = "";
|
||||
unsigned Flags = getELFSectionFlags(Kind);
|
||||
if (const Comdat *C = getELFComdat(GV)) {
|
||||
if (const Comdat *C = getELFComdat(GO)) {
|
||||
Group = C->getName();
|
||||
Flags |= ELF::SHF_GROUP;
|
||||
}
|
||||
|
@ -246,7 +246,7 @@ static StringRef getSectionPrefixForGlobal(SectionKind Kind) {
|
|||
}
|
||||
|
||||
static MCSectionELF *
|
||||
selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
||||
selectELFSectionForGlobal(MCContext &Ctx, const GlobalObject *GO,
|
||||
SectionKind Kind, Mangler &Mang,
|
||||
const TargetMachine &TM, bool EmitUniqueSection,
|
||||
unsigned Flags, unsigned *NextUniqueID) {
|
||||
|
@ -274,7 +274,7 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
|||
}
|
||||
|
||||
StringRef Group = "";
|
||||
if (const Comdat *C = getELFComdat(GV)) {
|
||||
if (const Comdat *C = getELFComdat(GO)) {
|
||||
Flags |= ELF::SHF_GROUP;
|
||||
Group = C->getName();
|
||||
}
|
||||
|
@ -285,8 +285,8 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
|||
// We also need alignment here.
|
||||
// FIXME: this is getting the alignment of the character, not the
|
||||
// alignment of the global!
|
||||
unsigned Align = GV->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GV));
|
||||
unsigned Align = GO->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GO));
|
||||
|
||||
std::string SizeSpec = ".rodata.str" + utostr(EntrySize) + ".";
|
||||
Name = SizeSpec + utostr(Align);
|
||||
|
@ -297,7 +297,7 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
|||
Name = getSectionPrefixForGlobal(Kind);
|
||||
}
|
||||
|
||||
if (const Function *F = dyn_cast<Function>(GV)) {
|
||||
if (const auto *F = dyn_cast<Function>(GO)) {
|
||||
const auto &OptionalPrefix = F->getSectionPrefix();
|
||||
if (OptionalPrefix)
|
||||
Name += *OptionalPrefix;
|
||||
|
@ -305,7 +305,7 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
|||
|
||||
if (EmitUniqueSection && UniqueSectionNames) {
|
||||
Name.push_back('.');
|
||||
TM.getNameWithPrefix(Name, GV, Mang, true);
|
||||
TM.getNameWithPrefix(Name, GO, Mang, true);
|
||||
}
|
||||
unsigned UniqueID = MCContext::GenericSectionID;
|
||||
if (EmitUniqueSection && !UniqueSectionNames) {
|
||||
|
@ -317,7 +317,7 @@ selectELFSectionForGlobal(MCContext &Ctx, const GlobalValue *GV,
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
unsigned Flags = getELFSectionFlags(Kind);
|
||||
|
||||
// If we have -ffunction-section or -fdata-section then we should emit the
|
||||
|
@ -329,9 +329,9 @@ MCSection *TargetLoweringObjectFileELF::SelectSectionForGlobal(
|
|||
else
|
||||
EmitUniqueSection = TM.getDataSections();
|
||||
}
|
||||
EmitUniqueSection |= GV->hasComdat();
|
||||
EmitUniqueSection |= GO->hasComdat();
|
||||
|
||||
return selectELFSectionForGlobal(getContext(), GV, Kind, getMangler(), TM,
|
||||
return selectELFSectionForGlobal(getContext(), GO, Kind, getMangler(), TM,
|
||||
EmitUniqueSection, Flags, &NextUniqueID);
|
||||
}
|
||||
|
||||
|
@ -572,22 +572,22 @@ static void checkMachOComdat(const GlobalValue *GV) {
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// Parse the section specifier and create it if valid.
|
||||
StringRef Segment, Section;
|
||||
unsigned TAA = 0, StubSize = 0;
|
||||
bool TAAParsed;
|
||||
|
||||
checkMachOComdat(GV);
|
||||
checkMachOComdat(GO);
|
||||
|
||||
std::string ErrorCode =
|
||||
MCSectionMachO::ParseSectionSpecifier(GV->getSection(), Segment, Section,
|
||||
MCSectionMachO::ParseSectionSpecifier(GO->getSection(), Segment, Section,
|
||||
TAA, TAAParsed, StubSize);
|
||||
if (!ErrorCode.empty()) {
|
||||
// If invalid, report the error with report_fatal_error.
|
||||
report_fatal_error("Global variable '" + GV->getName() +
|
||||
report_fatal_error("Global variable '" + GO->getName() +
|
||||
"' has an invalid section specifier '" +
|
||||
GV->getSection() + "': " + ErrorCode + ".");
|
||||
GO->getSection() + "': " + ErrorCode + ".");
|
||||
}
|
||||
|
||||
// Get the section.
|
||||
|
@ -604,7 +604,7 @@ MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
|
|||
// to reject it here.
|
||||
if (S->getTypeAndAttributes() != TAA || S->getStubSize() != StubSize) {
|
||||
// If invalid, report the error with report_fatal_error.
|
||||
report_fatal_error("Global variable '" + GV->getName() +
|
||||
report_fatal_error("Global variable '" + GO->getName() +
|
||||
"' section type or attributes does not match previous"
|
||||
" section specifier");
|
||||
}
|
||||
|
@ -613,19 +613,19 @@ MCSection *TargetLoweringObjectFileMachO::getExplicitSectionGlobal(
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
checkMachOComdat(GV);
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
checkMachOComdat(GO);
|
||||
|
||||
// Handle thread local data.
|
||||
if (Kind.isThreadBSS()) return TLSBSSSection;
|
||||
if (Kind.isThreadData()) return TLSDataSection;
|
||||
|
||||
if (Kind.isText())
|
||||
return GV->isWeakForLinker() ? TextCoalSection : TextSection;
|
||||
return GO->isWeakForLinker() ? TextCoalSection : TextSection;
|
||||
|
||||
// If this is weak/linkonce, put this in a coalescable section, either in text
|
||||
// or data depending on if it is writable.
|
||||
if (GV->isWeakForLinker()) {
|
||||
if (GO->isWeakForLinker()) {
|
||||
if (Kind.isReadOnly())
|
||||
return ConstTextCoalSection;
|
||||
return DataCoalSection;
|
||||
|
@ -633,21 +633,21 @@ MCSection *TargetLoweringObjectFileMachO::SelectSectionForGlobal(
|
|||
|
||||
// FIXME: Alignment check should be handled by section classifier.
|
||||
if (Kind.isMergeable1ByteCString() &&
|
||||
GV->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GV)) < 32)
|
||||
GO->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GO)) < 32)
|
||||
return CStringSection;
|
||||
|
||||
// Do not put 16-bit arrays in the UString section if they have an
|
||||
// externally visible label, this runs into issues with certain linker
|
||||
// versions.
|
||||
if (Kind.isMergeable2ByteCString() && !GV->hasExternalLinkage() &&
|
||||
GV->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GV)) < 32)
|
||||
if (Kind.isMergeable2ByteCString() && !GO->hasExternalLinkage() &&
|
||||
GO->getParent()->getDataLayout().getPreferredAlignment(
|
||||
cast<GlobalVariable>(GO)) < 32)
|
||||
return UStringSection;
|
||||
|
||||
// With MachO only variables whose corresponding symbol starts with 'l' or
|
||||
// 'L' can be merged, so we only try merging GVs with private linkage.
|
||||
if (GV->hasPrivateLinkage() && Kind.isMergeableConst()) {
|
||||
if (GO->hasPrivateLinkage() && Kind.isMergeableConst()) {
|
||||
if (Kind.isMergeableConst4())
|
||||
return FourByteConstantSection;
|
||||
if (Kind.isMergeableConst8())
|
||||
|
@ -821,10 +821,13 @@ static bool canUsePrivateLabel(const MCAsmInfo &AsmInfo,
|
|||
void TargetLoweringObjectFileMachO::getNameWithPrefix(
|
||||
SmallVectorImpl<char> &OutName, const GlobalValue *GV,
|
||||
const TargetMachine &TM) const {
|
||||
SectionKind GVKind = TargetLoweringObjectFile::getKindForGlobal(GV, TM);
|
||||
const MCSection *TheSection = SectionForGlobal(GV, GVKind, TM);
|
||||
bool CannotUsePrivateLabel =
|
||||
!canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
|
||||
bool CannotUsePrivateLabel = true;
|
||||
if (auto *GO = GV->getBaseObject()) {
|
||||
SectionKind GOKind = TargetLoweringObjectFile::getKindForGlobal(GO, TM);
|
||||
const MCSection *TheSection = SectionForGlobal(GO, GOKind, TM);
|
||||
CannotUsePrivateLabel =
|
||||
!canUsePrivateLabel(*TM.getMCAsmInfo(), *TheSection);
|
||||
}
|
||||
getMangler().getNameWithPrefix(OutName, GV, CannotUsePrivateLabel);
|
||||
}
|
||||
|
||||
|
@ -912,18 +915,18 @@ static int getSelectionForCOFF(const GlobalValue *GV) {
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileCOFF::getExplicitSectionGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
int Selection = 0;
|
||||
unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
|
||||
StringRef Name = GV->getSection();
|
||||
StringRef Name = GO->getSection();
|
||||
StringRef COMDATSymName = "";
|
||||
if (GV->hasComdat()) {
|
||||
Selection = getSelectionForCOFF(GV);
|
||||
if (GO->hasComdat()) {
|
||||
Selection = getSelectionForCOFF(GO);
|
||||
const GlobalValue *ComdatGV;
|
||||
if (Selection == COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE)
|
||||
ComdatGV = getComdatGVForCOFF(GV);
|
||||
ComdatGV = getComdatGVForCOFF(GO);
|
||||
else
|
||||
ComdatGV = GV;
|
||||
ComdatGV = GO;
|
||||
|
||||
if (!ComdatGV->hasPrivateLinkage()) {
|
||||
MCSymbol *Sym = TM.getSymbol(ComdatGV, getMangler());
|
||||
|
@ -951,7 +954,7 @@ static const char *getCOFFSectionNameForUniqueGlobal(SectionKind Kind) {
|
|||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// If we have -ffunction-sections then we should emit the global value to a
|
||||
// uniqued section specifically for it.
|
||||
bool EmitUniquedSection;
|
||||
|
@ -960,19 +963,19 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
|
|||
else
|
||||
EmitUniquedSection = TM.getDataSections();
|
||||
|
||||
if ((EmitUniquedSection && !Kind.isCommon()) || GV->hasComdat()) {
|
||||
if ((EmitUniquedSection && !Kind.isCommon()) || GO->hasComdat()) {
|
||||
const char *Name = getCOFFSectionNameForUniqueGlobal(Kind);
|
||||
unsigned Characteristics = getCOFFSectionFlags(Kind, TM);
|
||||
|
||||
Characteristics |= COFF::IMAGE_SCN_LNK_COMDAT;
|
||||
int Selection = getSelectionForCOFF(GV);
|
||||
int Selection = getSelectionForCOFF(GO);
|
||||
if (!Selection)
|
||||
Selection = COFF::IMAGE_COMDAT_SELECT_NODUPLICATES;
|
||||
const GlobalValue *ComdatGV;
|
||||
if (GV->hasComdat())
|
||||
ComdatGV = getComdatGVForCOFF(GV);
|
||||
if (GO->hasComdat())
|
||||
ComdatGV = getComdatGVForCOFF(GO);
|
||||
else
|
||||
ComdatGV = GV;
|
||||
ComdatGV = GO;
|
||||
|
||||
unsigned UniqueID = MCContext::GenericSectionID;
|
||||
if (EmitUniquedSection)
|
||||
|
@ -985,7 +988,7 @@ MCSection *TargetLoweringObjectFileCOFF::SelectSectionForGlobal(
|
|||
COMDATSymName, Selection, UniqueID);
|
||||
} else {
|
||||
SmallString<256> TmpData;
|
||||
getMangler().getNameWithPrefix(TmpData, GV, /*CannotUsePrivateLabel=*/true);
|
||||
getMangler().getNameWithPrefix(TmpData, GO, /*CannotUsePrivateLabel=*/true);
|
||||
return getContext().getCOFFSection(Name, Characteristics, Kind, TmpData,
|
||||
Selection, UniqueID);
|
||||
}
|
||||
|
|
|
@ -213,6 +213,14 @@ bool GlobalValue::canIncreaseAlignment() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
GlobalObject *GlobalValue::getBaseObject() {
|
||||
if (auto *GO = dyn_cast<GlobalObject>(this))
|
||||
return GO;
|
||||
if (auto *GA = dyn_cast<GlobalAlias>(this))
|
||||
return GA->getBaseObject();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
//===----------------------------------------------------------------------===//
|
||||
// GlobalVariable Implementation
|
||||
//===----------------------------------------------------------------------===//
|
||||
|
|
|
@ -21,10 +21,10 @@ using namespace llvm;
|
|||
//===----------------------------------------------------------------------===//
|
||||
|
||||
MCSection *AMDGPUTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GV) &&
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
if (Kind.isReadOnly() && AMDGPU::isReadOnlySegment(GO) &&
|
||||
AMDGPU::shouldEmitConstantsToTextSection(TM.getTargetTriple()))
|
||||
return TextSection;
|
||||
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace llvm {
|
|||
|
||||
class AMDGPUTargetObjectFile : public TargetLoweringObjectFileELF {
|
||||
public:
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
};
|
||||
|
||||
|
|
|
@ -26,16 +26,16 @@ void AVRTargetObjectFile::Initialize(MCContext &Ctx, const TargetMachine &TM) {
|
|||
}
|
||||
|
||||
MCSection *
|
||||
AVRTargetObjectFile::SelectSectionForGlobal(const GlobalValue *GV,
|
||||
AVRTargetObjectFile::SelectSectionForGlobal(const GlobalObject *GO,
|
||||
SectionKind Kind,
|
||||
const TargetMachine &TM) const {
|
||||
// Global values in flash memory are placed in the progmem.data section
|
||||
// unless they already have a user assigned section.
|
||||
if (AVR::isProgramMemoryAddress(GV) && !GV->hasSection())
|
||||
if (AVR::isProgramMemoryAddress(GO) && !GO->hasSection())
|
||||
return ProgmemDataSection;
|
||||
|
||||
// Otherwise, we work the same way as ELF.
|
||||
return Base::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return Base::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
} // end of namespace llvm
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ class AVRTargetObjectFile : public TargetLoweringObjectFileELF {
|
|||
public:
|
||||
void Initialize(MCContext &ctx, const TargetMachine &TM) override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
private:
|
||||
|
|
|
@ -1507,7 +1507,8 @@ HexagonTargetLowering::LowerGLOBALADDRESS(SDValue Op, SelectionDAG &DAG) const {
|
|||
|
||||
if (RM == Reloc::Static) {
|
||||
SDValue GA = DAG.getTargetGlobalAddress(GV, dl, PtrVT, Offset);
|
||||
if (HLOF.isGlobalInSmallSection(GV, HTM))
|
||||
const GlobalObject *GO = GV->getBaseObject();
|
||||
if (GO && HLOF.isGlobalInSmallSection(GO, HTM))
|
||||
return DAG.getNode(HexagonISD::CONST32_GP, dl, PtrVT, GA);
|
||||
return DAG.getNode(HexagonISD::CONST32, dl, PtrVT, GA);
|
||||
}
|
||||
|
|
|
@ -101,22 +101,22 @@ void HexagonTargetObjectFile::Initialize(MCContext &Ctx,
|
|||
}
|
||||
|
||||
MCSection *HexagonTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
TRACE("[SelectSectionForGlobal] GV(" << GV->getName() << ") ");
|
||||
TRACE("input section(" << GV->getSection() << ") ");
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
TRACE("[SelectSectionForGlobal] GO(" << GO->getName() << ") ");
|
||||
TRACE("input section(" << GO->getSection() << ") ");
|
||||
|
||||
TRACE((GV->hasPrivateLinkage() ? "private_linkage " : "")
|
||||
<< (GV->hasLocalLinkage() ? "local_linkage " : "")
|
||||
<< (GV->hasInternalLinkage() ? "internal " : "")
|
||||
<< (GV->hasExternalLinkage() ? "external " : "")
|
||||
<< (GV->hasCommonLinkage() ? "common_linkage " : "")
|
||||
<< (GV->hasCommonLinkage() ? "common " : "" )
|
||||
TRACE((GO->hasPrivateLinkage() ? "private_linkage " : "")
|
||||
<< (GO->hasLocalLinkage() ? "local_linkage " : "")
|
||||
<< (GO->hasInternalLinkage() ? "internal " : "")
|
||||
<< (GO->hasExternalLinkage() ? "external " : "")
|
||||
<< (GO->hasCommonLinkage() ? "common_linkage " : "")
|
||||
<< (GO->hasCommonLinkage() ? "common " : "" )
|
||||
<< (Kind.isCommon() ? "kind_common " : "" )
|
||||
<< (Kind.isBSS() ? "kind_bss " : "" )
|
||||
<< (Kind.isBSSLocal() ? "kind_bss_local " : "" ));
|
||||
|
||||
if (isGlobalInSmallSection(GV, TM))
|
||||
return selectSmallSectionForGlobal(GV, Kind, TM);
|
||||
if (isGlobalInSmallSection(GO, TM))
|
||||
return selectSmallSectionForGlobal(GO, Kind, TM);
|
||||
|
||||
if (Kind.isCommon()) {
|
||||
// This is purely for LTO+Linker Script because commons don't really have a
|
||||
|
@ -128,50 +128,50 @@ MCSection *HexagonTargetObjectFile::SelectSectionForGlobal(
|
|||
|
||||
TRACE("default_ELF_section\n");
|
||||
// Otherwise, we work the same as ELF.
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
TRACE("[getExplicitSectionGlobal] GV(" << GV->getName() << ") from("
|
||||
<< GV->getSection() << ") ");
|
||||
TRACE((GV->hasPrivateLinkage() ? "private_linkage " : "")
|
||||
<< (GV->hasLocalLinkage() ? "local_linkage " : "")
|
||||
<< (GV->hasInternalLinkage() ? "internal " : "")
|
||||
<< (GV->hasExternalLinkage() ? "external " : "")
|
||||
<< (GV->hasCommonLinkage() ? "common_linkage " : "")
|
||||
<< (GV->hasCommonLinkage() ? "common " : "" )
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
TRACE("[getExplicitSectionGlobal] GO(" << GO->getName() << ") from("
|
||||
<< GO->getSection() << ") ");
|
||||
TRACE((GO->hasPrivateLinkage() ? "private_linkage " : "")
|
||||
<< (GO->hasLocalLinkage() ? "local_linkage " : "")
|
||||
<< (GO->hasInternalLinkage() ? "internal " : "")
|
||||
<< (GO->hasExternalLinkage() ? "external " : "")
|
||||
<< (GO->hasCommonLinkage() ? "common_linkage " : "")
|
||||
<< (GO->hasCommonLinkage() ? "common " : "" )
|
||||
<< (Kind.isCommon() ? "kind_common " : "" )
|
||||
<< (Kind.isBSS() ? "kind_bss " : "" )
|
||||
<< (Kind.isBSSLocal() ? "kind_bss_local " : "" ));
|
||||
|
||||
if (GV->hasSection()) {
|
||||
StringRef Section = GV->getSection();
|
||||
if (GO->hasSection()) {
|
||||
StringRef Section = GO->getSection();
|
||||
if (Section.find(".access.text.group") != StringRef::npos)
|
||||
return getContext().getELFSection(GV->getSection(), ELF::SHT_PROGBITS,
|
||||
return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS,
|
||||
ELF::SHF_ALLOC | ELF::SHF_EXECINSTR);
|
||||
if (Section.find(".access.data.group") != StringRef::npos)
|
||||
return getContext().getELFSection(GV->getSection(), ELF::SHT_PROGBITS,
|
||||
return getContext().getELFSection(GO->getSection(), ELF::SHT_PROGBITS,
|
||||
ELF::SHF_WRITE | ELF::SHF_ALLOC);
|
||||
}
|
||||
|
||||
if (isGlobalInSmallSection(GV, TM))
|
||||
return selectSmallSectionForGlobal(GV, Kind, TM);
|
||||
if (isGlobalInSmallSection(GO, TM))
|
||||
return selectSmallSectionForGlobal(GO, Kind, TM);
|
||||
|
||||
// Otherwise, we work the same as ELF.
|
||||
TRACE("default_ELF_section\n");
|
||||
return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::getExplicitSectionGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
|
||||
/// Return true if this global value should be placed into small data/bss
|
||||
/// section.
|
||||
bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV,
|
||||
bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const {
|
||||
// Only global variables, not functions.
|
||||
DEBUG(dbgs() << "Checking if value is in small-data, -G"
|
||||
<< SmallDataThreshold << ": \"" << GV->getName() << "\": ");
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
||||
<< SmallDataThreshold << ": \"" << GO->getName() << "\": ");
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO);
|
||||
if (!GVar) {
|
||||
DEBUG(dbgs() << "no, not a global variable\n");
|
||||
return false;
|
||||
|
@ -297,9 +297,9 @@ unsigned HexagonTargetObjectFile::getSmallestAddressableSize(const Type *Ty,
|
|||
}
|
||||
|
||||
MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const Type *GTy = GV->getType()->getElementType();
|
||||
unsigned Size = getSmallestAddressableSize(GTy, GV, TM);
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const Type *GTy = GO->getType()->getElementType();
|
||||
unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
|
||||
|
||||
// If we have -ffunction-section or -fdata-section then we should emit the
|
||||
// global value to a unique section specifically for it... even for sdata.
|
||||
|
@ -325,7 +325,7 @@ MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
|
|||
|
||||
if (EmitUniquedSection) {
|
||||
Name.append(".");
|
||||
Name.append(GV->getName());
|
||||
Name.append(GO->getName());
|
||||
}
|
||||
TRACE(" unique sbss(" << Name << ")\n");
|
||||
return getContext().getELFSection(Name.str(), ELF::SHT_NOBITS,
|
||||
|
@ -352,7 +352,7 @@ MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
|
|||
// case the Kind could be wrong for it.
|
||||
if (Kind.isMergeableConst()) {
|
||||
TRACE(" const_object_as_data ");
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GO);
|
||||
if (GVar->hasSection() && isSmallDataSection(GVar->getSection()))
|
||||
Kind = SectionKind::getData();
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
|
|||
|
||||
if (EmitUniquedSection) {
|
||||
Name.append(".");
|
||||
Name.append(GV->getName());
|
||||
Name.append(GO->getName());
|
||||
}
|
||||
TRACE(" unique sdata(" << Name << ")\n");
|
||||
return getContext().getELFSection(Name.str(), ELF::SHT_PROGBITS,
|
||||
|
@ -378,5 +378,5 @@ MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
|
|||
|
||||
TRACE("default ELF section\n");
|
||||
// Otherwise, we work the same as ELF.
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
|
|
@ -19,14 +19,15 @@ namespace llvm {
|
|||
public:
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO,
|
||||
SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
bool isGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM)
|
||||
const;
|
||||
bool isGlobalInSmallSection(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
bool isSmallDataEnabled() const;
|
||||
|
||||
|
@ -39,7 +40,7 @@ namespace llvm {
|
|||
unsigned getSmallestAddressableSize(const Type *Ty, const GlobalValue *GV,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
MCSection *selectSmallSectionForGlobal(const GlobalValue *GV,
|
||||
MCSection *selectSmallSectionForGlobal(const GlobalObject *GO,
|
||||
SectionKind Kind,
|
||||
const TargetMachine &TM) const;
|
||||
};
|
||||
|
|
|
@ -1167,8 +1167,9 @@ SDValue LanaiTargetLowering::LowerGlobalAddress(SDValue Op,
|
|||
|
||||
// If the code model is small or global variable will be placed in the small
|
||||
// section, then assume address will fit in 21-bits.
|
||||
const GlobalObject *GO = GV->getBaseObject();
|
||||
if (getTargetMachine().getCodeModel() == CodeModel::Small ||
|
||||
TLOF->isGlobalInSmallSection(GV, getTargetMachine())) {
|
||||
(GO && TLOF->isGlobalInSmallSection(GO, getTargetMachine()))) {
|
||||
SDValue Small = DAG.getTargetGlobalAddress(
|
||||
GV, DL, getPointerTy(DAG.getDataLayout()), Offset, LanaiII::MO_NO_FLAG);
|
||||
return DAG.getNode(ISD::OR, DL, MVT::i32,
|
||||
|
|
|
@ -49,22 +49,22 @@ static bool isInSmallSection(uint64_t Size) {
|
|||
// Return true if this global address should be placed into small data/bss
|
||||
// section.
|
||||
bool LanaiTargetObjectFile::isGlobalInSmallSection(
|
||||
const GlobalValue *GV, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, const TargetMachine &TM) const {
|
||||
// We first check the case where global is a declaration, because finding
|
||||
// section kind using getKindForGlobal() is only allowed for global
|
||||
// definitions.
|
||||
if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
|
||||
return isGlobalInSmallSectionImpl(GV, TM);
|
||||
if (GO->isDeclaration() || GO->hasAvailableExternallyLinkage())
|
||||
return isGlobalInSmallSectionImpl(GO, TM);
|
||||
|
||||
return isGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM));
|
||||
return isGlobalInSmallSection(GO, TM, getKindForGlobal(GO, TM));
|
||||
}
|
||||
|
||||
// Return true if this global address should be placed into small data/bss
|
||||
// section.
|
||||
bool LanaiTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV,
|
||||
bool LanaiTargetObjectFile::isGlobalInSmallSection(const GlobalObject *GO,
|
||||
const TargetMachine &TM,
|
||||
SectionKind Kind) const {
|
||||
return (isGlobalInSmallSectionImpl(GV, TM) &&
|
||||
return (isGlobalInSmallSectionImpl(GO, TM) &&
|
||||
(Kind.isData() || Kind.isBSS() || Kind.isCommon()));
|
||||
}
|
||||
|
||||
|
@ -72,34 +72,34 @@ bool LanaiTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV,
|
|||
// section. This method does all the work, except for checking the section
|
||||
// kind.
|
||||
bool LanaiTargetObjectFile::isGlobalInSmallSectionImpl(
|
||||
const GlobalValue *GV, const TargetMachine & /*TM*/) const {
|
||||
const GlobalObject *GO, const TargetMachine & /*TM*/) const {
|
||||
// Only global variables, not functions.
|
||||
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
|
||||
const auto *GVA = dyn_cast<GlobalVariable>(GO);
|
||||
if (!GVA)
|
||||
return false;
|
||||
|
||||
if (GV->hasLocalLinkage())
|
||||
if (GVA->hasLocalLinkage())
|
||||
return false;
|
||||
|
||||
if (((GV->hasExternalLinkage() && GV->isDeclaration()) ||
|
||||
GV->hasCommonLinkage()))
|
||||
if (((GVA->hasExternalLinkage() && GVA->isDeclaration()) ||
|
||||
GVA->hasCommonLinkage()))
|
||||
return false;
|
||||
|
||||
Type *Ty = GV->getType()->getElementType();
|
||||
Type *Ty = GVA->getValueType();
|
||||
return isInSmallSection(
|
||||
GV->getParent()->getDataLayout().getTypeAllocSize(Ty));
|
||||
GVA->getParent()->getDataLayout().getTypeAllocSize(Ty));
|
||||
}
|
||||
|
||||
MCSection *LanaiTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// Handle Small Section classification here.
|
||||
if (Kind.isBSS() && isGlobalInSmallSection(GV, TM, Kind))
|
||||
if (Kind.isBSS() && isGlobalInSmallSection(GO, TM, Kind))
|
||||
return SmallBSSSection;
|
||||
if (Kind.isData() && isGlobalInSmallSection(GV, TM, Kind))
|
||||
if (Kind.isData() && isGlobalInSmallSection(GO, TM, Kind))
|
||||
return SmallDataSection;
|
||||
|
||||
// Otherwise, we work the same as ELF.
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
/// Return true if this constant should be placed into small data section.
|
||||
|
|
|
@ -18,19 +18,20 @@ class LanaiTargetObjectFile : public TargetLoweringObjectFileELF {
|
|||
MCSection *SmallDataSection;
|
||||
MCSection *SmallBSSSection;
|
||||
|
||||
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM,
|
||||
SectionKind Kind) const;
|
||||
bool isGlobalInSmallSectionImpl(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
public:
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
|
||||
/// Return true if this global address should be placed into small data/bss
|
||||
/// section.
|
||||
bool isGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
|
||||
SectionKind Kind) const;
|
||||
bool isGlobalInSmallSection(const GlobalValue *GV,
|
||||
bool isGlobalInSmallSection(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const;
|
||||
bool isGlobalInSmallSectionImpl(const GlobalValue *GV,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
/// Return true if this constant should be placed into small data section.
|
||||
|
|
|
@ -1772,7 +1772,8 @@ SDValue MipsTargetLowering::lowerGlobalAddress(SDValue Op,
|
|||
const MipsTargetObjectFile *TLOF =
|
||||
static_cast<const MipsTargetObjectFile *>(
|
||||
getTargetMachine().getObjFileLowering());
|
||||
if (TLOF->IsGlobalInSmallSection(GV, getTargetMachine()))
|
||||
const GlobalObject *GO = GV->getBaseObject();
|
||||
if (GO && TLOF->IsGlobalInSmallSection(GO, getTargetMachine()))
|
||||
// %gp_rel relocation
|
||||
return getAddrGPRel(N, SDLoc(N), Ty, DAG);
|
||||
|
||||
|
|
|
@ -61,23 +61,23 @@ static bool IsInSmallSection(uint64_t Size) {
|
|||
|
||||
/// Return true if this global address should be placed into small data/bss
|
||||
/// section.
|
||||
bool MipsTargetObjectFile::
|
||||
IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM) const {
|
||||
bool MipsTargetObjectFile::IsGlobalInSmallSection(
|
||||
const GlobalObject *GO, const TargetMachine &TM) const {
|
||||
// We first check the case where global is a declaration, because finding
|
||||
// section kind using getKindForGlobal() is only allowed for global
|
||||
// definitions.
|
||||
if (GV->isDeclaration() || GV->hasAvailableExternallyLinkage())
|
||||
return IsGlobalInSmallSectionImpl(GV, TM);
|
||||
if (GO->isDeclaration() || GO->hasAvailableExternallyLinkage())
|
||||
return IsGlobalInSmallSectionImpl(GO, TM);
|
||||
|
||||
return IsGlobalInSmallSection(GV, TM, getKindForGlobal(GV, TM));
|
||||
return IsGlobalInSmallSection(GO, TM, getKindForGlobal(GO, TM));
|
||||
}
|
||||
|
||||
/// Return true if this global address should be placed into small data/bss
|
||||
/// section.
|
||||
bool MipsTargetObjectFile::
|
||||
IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
|
||||
IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM,
|
||||
SectionKind Kind) const {
|
||||
return (IsGlobalInSmallSectionImpl(GV, TM) &&
|
||||
return (IsGlobalInSmallSectionImpl(GO, TM) &&
|
||||
(Kind.isData() || Kind.isBSS() || Kind.isCommon()));
|
||||
}
|
||||
|
||||
|
@ -85,7 +85,7 @@ IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
|
|||
/// section. This method does all the work, except for checking the section
|
||||
/// kind.
|
||||
bool MipsTargetObjectFile::
|
||||
IsGlobalInSmallSectionImpl(const GlobalValue *GV,
|
||||
IsGlobalInSmallSectionImpl(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const {
|
||||
const MipsSubtarget &Subtarget =
|
||||
*static_cast<const MipsTargetMachine &>(TM).getSubtargetImpl();
|
||||
|
@ -95,37 +95,37 @@ IsGlobalInSmallSectionImpl(const GlobalValue *GV,
|
|||
return false;
|
||||
|
||||
// Only global variables, not functions.
|
||||
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GV);
|
||||
const GlobalVariable *GVA = dyn_cast<GlobalVariable>(GO);
|
||||
if (!GVA)
|
||||
return false;
|
||||
|
||||
// Enforce -mlocal-sdata.
|
||||
if (!LocalSData && GV->hasLocalLinkage())
|
||||
if (!LocalSData && GVA->hasLocalLinkage())
|
||||
return false;
|
||||
|
||||
// Enforce -mextern-sdata.
|
||||
if (!ExternSData && ((GV->hasExternalLinkage() && GV->isDeclaration()) ||
|
||||
GV->hasCommonLinkage()))
|
||||
if (!ExternSData && ((GVA->hasExternalLinkage() && GVA->isDeclaration()) ||
|
||||
GVA->hasCommonLinkage()))
|
||||
return false;
|
||||
|
||||
Type *Ty = GV->getValueType();
|
||||
Type *Ty = GVA->getValueType();
|
||||
return IsInSmallSection(
|
||||
GV->getParent()->getDataLayout().getTypeAllocSize(Ty));
|
||||
GVA->getParent()->getDataLayout().getTypeAllocSize(Ty));
|
||||
}
|
||||
|
||||
MCSection *MipsTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// TODO: Could also support "weak" symbols as well with ".gnu.linkonce.s.*"
|
||||
// sections?
|
||||
|
||||
// Handle Small Section classification here.
|
||||
if (Kind.isBSS() && IsGlobalInSmallSection(GV, TM, Kind))
|
||||
if (Kind.isBSS() && IsGlobalInSmallSection(GO, TM, Kind))
|
||||
return SmallBSSSection;
|
||||
if (Kind.isData() && IsGlobalInSmallSection(GV, TM, Kind))
|
||||
if (Kind.isData() && IsGlobalInSmallSection(GO, TM, Kind))
|
||||
return SmallDataSection;
|
||||
|
||||
// Otherwise, we work the same as ELF.
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
/// Return true if this constant should be placed into small data section.
|
||||
|
|
|
@ -18,20 +18,21 @@ class MipsTargetMachine;
|
|||
MCSection *SmallDataSection;
|
||||
MCSection *SmallBSSSection;
|
||||
const MipsTargetMachine *TM;
|
||||
|
||||
bool IsGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM,
|
||||
SectionKind Kind) const;
|
||||
bool IsGlobalInSmallSectionImpl(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const;
|
||||
public:
|
||||
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
|
||||
/// Return true if this global address should be placed into small data/bss
|
||||
/// section.
|
||||
bool IsGlobalInSmallSection(const GlobalValue *GV, const TargetMachine &TM,
|
||||
SectionKind Kind) const;
|
||||
bool IsGlobalInSmallSection(const GlobalValue *GV,
|
||||
bool IsGlobalInSmallSection(const GlobalObject *GO,
|
||||
const TargetMachine &TM) const;
|
||||
bool IsGlobalInSmallSectionImpl(const GlobalValue *GV,
|
||||
const TargetMachine &TM) const;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
/// Return true if this constant should be placed into small data section.
|
||||
|
|
|
@ -4598,6 +4598,6 @@ NVPTXTargetObjectFile::~NVPTXTargetObjectFile() {
|
|||
}
|
||||
|
||||
MCSection *NVPTXTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
return getDataSection();
|
||||
}
|
||||
|
|
|
@ -91,12 +91,12 @@ public:
|
|||
return ReadOnlySection;
|
||||
}
|
||||
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override {
|
||||
return DataSection;
|
||||
}
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
};
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ Initialize(MCContext &Ctx, const TargetMachine &TM) {
|
|||
}
|
||||
|
||||
MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// Here override ReadOnlySection to DataRelROSection for PPC64 SVR4 ABI
|
||||
// when we have a constant that contains global relocations. This is
|
||||
// necessary because of this ABI's handling of pointers to functions in
|
||||
|
@ -39,13 +39,13 @@ MCSection *PPC64LinuxTargetObjectFile::SelectSectionForGlobal(
|
|||
// For more information, see the description of ELIMINATE_COPY_RELOCS in
|
||||
// GNU ld.
|
||||
if (Kind.isReadOnly()) {
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
||||
const auto *GVar = dyn_cast<GlobalVariable>(GO);
|
||||
|
||||
if (GVar && GVar->isConstant() && GVar->getInitializer()->needsRelocation())
|
||||
Kind = SectionKind::getReadOnlyWithRel();
|
||||
}
|
||||
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
|
||||
return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
const MCExpr *PPC64LinuxTargetObjectFile::
|
||||
|
|
|
@ -22,7 +22,7 @@ namespace llvm {
|
|||
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
/// \brief Describe a TLS variable address within debug info.
|
||||
|
|
|
@ -132,15 +132,15 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
|
|||
/// classifies the global in a variety of ways that make various target
|
||||
/// implementations simpler. The target implementation is free to ignore this
|
||||
/// extra info of course.
|
||||
SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
|
||||
SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
|
||||
const TargetMachine &TM){
|
||||
assert(!GV->isDeclaration() && !GV->hasAvailableExternallyLinkage() &&
|
||||
assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
|
||||
"Can only be used for global definitions");
|
||||
|
||||
Reloc::Model ReloModel = TM.getRelocationModel();
|
||||
|
||||
// Early exit - functions should be always in text sections.
|
||||
const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
|
||||
const auto *GVar = dyn_cast<GlobalVariable>(GO);
|
||||
if (!GVar)
|
||||
return SectionKind::getText();
|
||||
|
||||
|
@ -201,7 +201,8 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
|
|||
// Otherwise, just drop it into a mergable constant section. If we have
|
||||
// a section for this size, use it, otherwise use the arbitrary sized
|
||||
// mergable section.
|
||||
switch (GV->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
|
||||
switch (
|
||||
GVar->getParent()->getDataLayout().getTypeAllocSize(C->getType())) {
|
||||
case 4: return SectionKind::getMergeableConst4();
|
||||
case 8: return SectionKind::getMergeableConst8();
|
||||
case 16: return SectionKind::getMergeableConst16();
|
||||
|
@ -234,13 +235,13 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalValue *GV,
|
|||
/// variable or function definition. This should not be passed external (or
|
||||
/// available externally) globals.
|
||||
MCSection *TargetLoweringObjectFile::SectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
// Select section name.
|
||||
if (GV->hasSection())
|
||||
return getExplicitSectionGlobal(GV, Kind, TM);
|
||||
if (GO->hasSection())
|
||||
return getExplicitSectionGlobal(GO, Kind, TM);
|
||||
|
||||
// Use default section depending on the 'type' of global
|
||||
return SelectSectionForGlobal(GV, Kind, TM);
|
||||
return SelectSectionForGlobal(GO, Kind, TM);
|
||||
}
|
||||
|
||||
MCSection *TargetLoweringObjectFile::getSectionForJumpTable(
|
||||
|
|
|
@ -96,8 +96,8 @@ static unsigned getXCoreSectionFlags(SectionKind K, bool IsCPRel) {
|
|||
}
|
||||
|
||||
MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
StringRef SectionName = GV->getSection();
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
StringRef SectionName = GO->getSection();
|
||||
// Infer section flags from the section name if we can.
|
||||
bool IsCPRel = SectionName.startswith(".cp.");
|
||||
if (IsCPRel && !Kind.isReadOnly())
|
||||
|
@ -107,9 +107,9 @@ MCSection *XCoreTargetObjectFile::getExplicitSectionGlobal(
|
|||
}
|
||||
|
||||
MCSection *XCoreTargetObjectFile::SelectSectionForGlobal(
|
||||
const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
|
||||
const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
|
||||
|
||||
bool UseCPRel = GV->isLocalLinkage(GV->getLinkage());
|
||||
bool UseCPRel = GO->hasLocalLinkage();
|
||||
|
||||
if (Kind.isText()) return TextSection;
|
||||
if (UseCPRel) {
|
||||
|
@ -118,8 +118,8 @@ MCSection *XCoreTargetObjectFile::SelectSectionForGlobal(
|
|||
if (Kind.isMergeableConst8()) return MergeableConst8Section;
|
||||
if (Kind.isMergeableConst16()) return MergeableConst16Section;
|
||||
}
|
||||
Type *ObjType = GV->getValueType();
|
||||
auto &DL = GV->getParent()->getDataLayout();
|
||||
Type *ObjType = GO->getValueType();
|
||||
auto &DL = GO->getParent()->getDataLayout();
|
||||
if (TM.getCodeModel() == CodeModel::Small || !ObjType->isSized() ||
|
||||
DL.getTypeAllocSize(ObjType) < CodeModelLargeSize) {
|
||||
if (Kind.isReadOnly()) return UseCPRel? ReadOnlySection
|
||||
|
|
|
@ -25,10 +25,10 @@ static const unsigned CodeModelLargeSize = 256;
|
|||
public:
|
||||
void Initialize(MCContext &Ctx, const TargetMachine &TM) override;
|
||||
|
||||
MCSection *getExplicitSectionGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
|
||||
MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
|
||||
const TargetMachine &TM) const override;
|
||||
|
||||
MCSection *getSectionForConstant(const DataLayout &DL, SectionKind Kind,
|
||||
|
|
Loading…
Reference in New Issue