14 #define DEBUG_TYPE "hexagon-sdata"
39 cl::desc(
"The maximum size of an object in the sdata section"));
46 cl::desc(
"Allow static variables in .sdata"));
50 cl::desc(
"Trace global value placement"));
55 #define TRACE_TO(s, X) s << X
59 if (TraceGVPlacement) { \
60 TRACE_TO(errs(), X); \
66 if (TraceGVPlacement) { \
67 TRACE_TO(errs(), X); \
69 DEBUG(TRACE_TO(dbgs(), X)); \
122 TRACE(
"[SelectSectionForGlobal] GO(" << GO->
getName() <<
") ");
131 << (Kind.
isCommon() ?
"kind_common " :
"" )
132 << (Kind.
isBSS() ?
"kind_bss " :
"" )
133 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
136 return selectSmallSectionForGlobal(GO, Kind, TM);
146 TRACE(
"default_ELF_section\n");
153 TRACE(
"[getExplicitSectionGlobal] GO(" << GO->
getName() <<
") from("
161 << (Kind.
isCommon() ?
"kind_common " :
"" )
162 << (Kind.
isBSS() ?
"kind_bss " :
"" )
163 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
176 return selectSmallSectionForGlobal(GO, Kind, TM);
179 TRACE(
"default_ELF_section\n");
188 DEBUG(
dbgs() <<
"Checking if value is in small-data, -G"
192 DEBUG(
dbgs() <<
"no, not a global variable\n");
199 if (GVar->hasSection()) {
201 DEBUG(
dbgs() << (IsSmall ?
"yes" :
"no") <<
", has section: "
202 << GVar->getSection() <<
'\n');
206 if (GVar->isConstant()) {
211 bool IsLocal = GVar->hasLocalLinkage();
217 Type *GType = GVar->getType();
218 if (
PointerType *PT = dyn_cast<PointerType>(GType))
219 GType = PT->getElementType();
221 if (isa<ArrayType>(GType)) {
231 if (
ST->isOpaque()) {
232 DEBUG(
dbgs() <<
"no, has opaque type\n");
237 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType);
243 DEBUG(
dbgs() <<
"no, size exceeds sdata threshold: " << Size <<
'\n');
262 unsigned HexagonTargetObjectFile::getSmallestAddressableSize(
const Type *Ty,
266 unsigned SmallestElement = 8;
272 const StructType *STy = cast<const StructType>(Ty);
274 unsigned AtomicSize = getSmallestAddressableSize(
E, GV, TM);
275 if (AtomicSize < SmallestElement)
276 SmallestElement = AtomicSize;
281 const ArrayType *ATy = cast<const ArrayType>(Ty);
285 const VectorType *PTy = cast<const VectorType>(Ty);
312 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
315 unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
321 TRACE(
"Small data. Size(" << Size <<
")");
331 TRACE(
" default sbss\n");
332 return SmallBSSSection;
339 if (EmitUniquedSection) {
357 TRACE(
" small COMMON (" << Name <<
")\n");
367 TRACE(
" const_object_as_data ");
375 TRACE(
" default sdata\n");
376 return SmallDataSection;
383 if (EmitUniquedSection) {
387 TRACE(
" unique sdata(" << Name <<
")\n");
392 TRACE(
"default ELF section\n");
Instances of this class represent a uniqued identifier for a section in the current translation unit...
A parsed version of the target data layout string in and methods for querying it. ...
static SectionKind getData()
bool isMergeableConst() const
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
2: 32-bit floating point type
static const char * getSectionSuffixForSize(unsigned Size)
4: 80-bit floating point type (X87)
1: 16-bit floating point type
Type * getElementType() const
StringRef getName() const
Return a constant reference to the value's name.
std::string str() const
Return the twine contents as a std::string.
bool hasCommonLinkage() const
static cl::opt< bool > NoSmallDataSorting("mno-sort-sda", cl::init(false), cl::Hidden, cl::desc("Disable small data sections sorting"))
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Class to represent struct types.
virtual void Initialize(MCContext &ctx, const TargetMachine &TM)
This method must be called before any actual lowering is done.
bool hasInternalLinkage() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
bool hasPrivateLinkage() const
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Context object for machine code objects.
ArrayRef< Type * > const elements() const
Class to represent array types.
StringRef getSection() const
Get the custom section of this global if it has one.
TypeID getTypeID() const
Return the type id for the type.
MCContext & getContext() const
Type * getElementType() const
Class to represent pointers.
static GCRegistry::Add< CoreCLRGC > E("coreclr","CoreCLR-compatible GC")
11: Arbitrary bit width integers
bool hasSection() const
Check if this global has a custom object file section.
unsigned getSmallDataSize() const
initializer< Ty > init(const Ty &Val)
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE size_t find(char C, size_t From=0) const
Search for the first character C in the string.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
The instances of the Type class are immutable: once they are created, they are never changed...
static bool isSmallDataSection(StringRef Sec)
void InitializeELF(bool UseInitArray_)
SectionKind - This is a simple POD value that classifies the properties of a section.
6: 128-bit floating point type (two 64-bits, PowerPC)
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections...
bool hasExternalLinkage() const
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
16: SIMD 'packed' format, or other vector type
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static cl::opt< unsigned > SmallDataThreshold("hexagon-small-data-threshold", cl::init(8), cl::Hidden, cl::desc("The maximum size of an object in the sdata section"))
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
static cl::opt< bool > TraceGVPlacement("trace-gv-placement", cl::Hidden, cl::init(false), cl::desc("Trace global value placement"))
static cl::opt< bool > StaticsInSData("hexagon-statics-in-small-data", cl::init(false), cl::Hidden, cl::ZeroOrMore, cl::desc("Allow static variables in .sdata"))
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
Class to represent vector types.
PointerType * getType() const
Global values are always pointers.
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
bool isSmallDataEnabled() const
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool hasLocalLinkage() const
3: 64-bit floating point type
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
Module * getParent()
Get the module that this global value is contained inside of...
Primary interface to the complete machine description for the target machine.
MCSection * getExplicitSectionGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
Targets should implement this method to assign a section to globals with an explicit section specfied...
MCSection * BSSSection
Section that is default initialized to zero.
StringRef - Represent a constant reference to a string, i.e.
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const
Return true if this global value should be placed into small data/bss section.
9: MMX vectors (64 bits, X86 specific)
unsigned getNumElements() const
Random access to the elements.
5: 128-bit floating point type (112-bit mantissa)