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,
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,
~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,
namespace llvm {
class Comdat;
+class GlobalObject;
class PointerType;
class Module;
// 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;
/// 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,
/// 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
const GlobalValue *GV) const {}
protected:
- virtual MCSection *SelectSectionForGlobal(const GlobalValue *GV,
+ virtual MCSection *SelectSectionForGlobal(const GlobalObject *GO,
SectionKind Kind,
const TargetMachine &TM) const = 0;
};
}
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;
}
}
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) {
}
StringRef Group = "";
- if (const Comdat *C = getELFComdat(GV)) {
+ if (const Comdat *C = getELFComdat(GO)) {
Flags |= ELF::SHF_GROUP;
Group = C->getName();
}
// 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);
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;
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) {
}
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
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);
}
}
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.
// 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");
}
}
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;
// 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())
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);
}
}
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());
}
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;
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)
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);
}
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
//===----------------------------------------------------------------------===//
//===----------------------------------------------------------------------===//
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);
}
class AMDGPUTargetObjectFile : public TargetLoweringObjectFileELF {
public:
- MCSection *SelectSectionForGlobal(const GlobalValue *GV, SectionKind Kind,
+ MCSection *SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind,
const TargetMachine &TM) const override;
};
}
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
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:
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);
}
}
MCSection *HexagonTargetObjectFile::SelectSectionForGlobal(
- const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
- TRACE("[SelectSectionForGlobal] GV(" << GV->getName() << ") ");
- TRACE("input section(" << 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("[SelectSectionForGlobal] GO(" << GO->getName() << ") ");
+ TRACE("input section(" << 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 (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
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;
}
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.
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,
// 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();
}
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,
TRACE("default ELF section\n");
// Otherwise, we work the same as ELF.
- return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, TM);
+ return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM);
}
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;
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;
};
// 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,
// 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()));
}
// 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.
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.
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);
/// 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()));
}
/// 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();
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.
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.
}
MCSection *NVPTXTargetObjectFile::SelectSectionForGlobal(
- const GlobalValue *GV, SectionKind Kind, const TargetMachine &TM) const {
+ const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const {
return getDataSection();
}
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;
};
}
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
// 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::
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.
/// 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();
// 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();
/// 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(
}
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())
}
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) {
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
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,