diff options
Diffstat (limited to 'contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp')
-rw-r--r-- | contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp | 126 |
1 files changed, 65 insertions, 61 deletions
diff --git a/contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp b/contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp index 82b437e..c9c4f95 100644 --- a/contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp +++ b/contrib/llvm/lib/Target/Hexagon/HexagonTargetObjectFile.cpp @@ -10,17 +10,27 @@ // This file contains the declarations of the HexagonTargetAsmInfo properties. // //===----------------------------------------------------------------------===// + #define DEBUG_TYPE "hexagon-sdata" -#include "HexagonTargetMachine.h" #include "HexagonTargetObjectFile.h" +#include "llvm/ADT/SmallString.h" +#include "llvm/ADT/StringRef.h" +#include "llvm/ADT/Twine.h" #include "llvm/IR/DataLayout.h" #include "llvm/IR/DerivedTypes.h" -#include "llvm/IR/Function.h" +#include "llvm/IR/GlobalObject.h" +#include "llvm/IR/GlobalValue.h" #include "llvm/IR/GlobalVariable.h" +#include "llvm/IR/Type.h" #include "llvm/MC/MCContext.h" +#include "llvm/MC/SectionKind.h" +#include "llvm/Support/Casting.h" #include "llvm/Support/CommandLine.h" +#include "llvm/Support/Debug.h" #include "llvm/Support/ELF.h" +#include "llvm/Support/raw_ostream.h" +#include "llvm/Target/TargetMachine.h" using namespace llvm; @@ -44,13 +54,21 @@ static cl::opt<bool> TraceGVPlacement("trace-gv-placement", // (e.g. -debug and -debug-only=globallayout) #define TRACE_TO(s, X) s << X #ifdef NDEBUG -#define TRACE(X) do { if (TraceGVPlacement) { TRACE_TO(errs(), X); } } while (0) +#define TRACE(X) \ + do { \ + if (TraceGVPlacement) { \ + TRACE_TO(errs(), X); \ + } \ + } while (false) #else -#define TRACE(X) \ - do { \ - if (TraceGVPlacement) { TRACE_TO(errs(), X); } \ - else { DEBUG( TRACE_TO(dbgs(), X) ); } \ - } while (0) +#define TRACE(X) \ + do { \ + if (TraceGVPlacement) { \ + TRACE_TO(errs(), X); \ + } else { \ + DEBUG(TRACE_TO(dbgs(), X)); \ + } \ + } while (false) #endif // Returns true if the section name is such that the symbol will be put @@ -69,7 +87,6 @@ static bool isSmallDataSection(StringRef Sec) { Sec.find(".scommon.") != StringRef::npos; } - static const char *getSectionSuffixForSize(unsigned Size) { switch (Size) { default: @@ -100,25 +117,23 @@ void HexagonTargetObjectFile::Initialize(MCContext &Ctx, ELF::SHF_HEX_GPREL); } - MCSection *HexagonTargetObjectFile::SelectSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, Mangler &Mang, - 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, Mang, 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 @@ -130,54 +145,49 @@ MCSection *HexagonTargetObjectFile::SelectSectionForGlobal( TRACE("default_ELF_section\n"); // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, - Mang, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } - MCSection *HexagonTargetObjectFile::getExplicitSectionGlobal( - const GlobalValue *GV, SectionKind Kind, Mangler &Mang, - 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, Mang, 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, - Mang, 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; @@ -238,17 +248,14 @@ bool HexagonTargetObjectFile::isGlobalInSmallSection(const GlobalValue *GV, return true; } - bool HexagonTargetObjectFile::isSmallDataEnabled() const { return SmallDataThreshold > 0; } - unsigned HexagonTargetObjectFile::getSmallDataSize() const { return SmallDataThreshold; } - /// Descends any type down to "elementary" components, /// discovering the smallest addressable one. /// If zero is returned, declaration will not be modified. @@ -302,12 +309,10 @@ unsigned HexagonTargetObjectFile::getSmallestAddressableSize(const Type *Ty, return 0; } - MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal( - const GlobalValue *GV, SectionKind Kind, Mangler &Mang, - 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. @@ -333,7 +338,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, @@ -360,7 +365,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(); } @@ -377,7 +382,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, @@ -386,6 +391,5 @@ MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal( TRACE("default ELF section\n"); // Otherwise, we work the same as ELF. - return TargetLoweringObjectFileELF::SelectSectionForGlobal(GV, Kind, - Mang, TM); + return TargetLoweringObjectFileELF::SelectSectionForGlobal(GO, Kind, TM); } |