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"));
54 cl::desc(
"Emit hexagon jump tables in function section"));
58 cl::desc(
"Emit hexagon lookup tables in function section"));
63 #define TRACE_TO(s, X) s << X 67 if (TraceGVPlacement) { \ 68 TRACE_TO(errs(), X); \ 74 if (TraceGVPlacement) { \ 75 TRACE_TO(errs(), X); \ 77 LLVM_DEBUG(TRACE_TO(dbgs(), X)); \ 130 TRACE(
"[SelectSectionForGlobal] GO(" << GO->
getName() <<
") ");
139 << (Kind.
isCommon() ?
"kind_common " :
"" )
140 << (Kind.
isBSS() ?
"kind_bss " :
"" )
141 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
147 return selectSectionForLookupTable(GO, TM, Fn);
151 return selectSmallSectionForGlobal(GO, Kind, TM);
161 TRACE(
"default_ELF_section\n");
168 TRACE(
"[getExplicitSectionGlobal] GO(" << GO->
getName() <<
") from(" 176 << (Kind.
isCommon() ?
"kind_common " :
"" )
177 << (Kind.
isBSS() ?
"kind_bss " :
"" )
178 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
191 return selectSmallSectionForGlobal(GO, Kind, TM);
194 TRACE(
"default_ELF_section\n");
204 LLVM_DEBUG(
dbgs() <<
"Small-data allocation is disabled, but symbols " 205 "may have explicit section assignments...\n");
218 if (GVar->hasSection()) {
221 <<
", has section: " << GVar->getSection() <<
'\n');
231 if (GVar->isConstant()) {
236 bool IsLocal = GVar->hasLocalLinkage();
242 Type *GType = GVar->getType();
243 if (
PointerType *PT = dyn_cast<PointerType>(GType))
244 GType = PT->getElementType();
246 if (isa<ArrayType>(GType)) {
256 if (
ST->isOpaque()) {
262 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType);
268 LLVM_DEBUG(
dbgs() <<
"no, size exceeds sdata threshold: " << Size <<
'\n');
286 bool UsesLabelDifference,
const Function &
F)
const {
293 unsigned HexagonTargetObjectFile::getSmallestAddressableSize(
const Type *Ty,
297 unsigned SmallestElement = 8;
303 const StructType *STy = cast<const StructType>(Ty);
305 unsigned AtomicSize = getSmallestAddressableSize(
E, GV, TM);
306 if (AtomicSize < SmallestElement)
307 SmallestElement = AtomicSize;
312 const ArrayType *ATy = cast<const ArrayType>(Ty);
316 const VectorType *PTy = cast<const VectorType>(Ty);
343 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
346 unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
352 TRACE(
"Small data. Size(" << Size <<
")");
362 TRACE(
" default sbss\n");
363 return SmallBSSSection;
370 if (EmitUniquedSection) {
374 TRACE(
" unique sbss(" << Name <<
")\n");
388 TRACE(
" small COMMON (" << Name <<
")\n");
398 TRACE(
" const_object_as_data ");
406 TRACE(
" default sdata\n");
407 return SmallDataSection;
414 if (EmitUniquedSection) {
418 TRACE(
" unique sdata(" << Name <<
")\n");
423 TRACE(
"default ELF section\n");
434 for (
auto U : GO->
users()) {
439 auto *Bb =
I->getParent();
442 auto *UserFn = Bb->getParent();
445 else if (ReturnFn != UserFn)
451 MCSection *HexagonTargetObjectFile::selectSectionForLookupTable(
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const
Return true if this global value should be placed into small data/bss section.
StringRef getSection() const
Get the custom section of this global if it has one.
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 hasLocalLinkage() 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...
bool hasPrivateLinkage() const
This class represents lattice values for constants.
2: 32-bit floating point type
ArrayRef< Type * > const elements() const
unsigned getNumElements() const
Random access to the elements.
static const char * getSectionSuffixForSize(unsigned Size)
4: 80-bit floating point type (X87)
1: 16-bit floating point type
static cl::opt< bool > EmitJtInText("hexagon-emit-jt-text", cl::Hidden, cl::init(false), cl::desc("Emit hexagon jump tables in function section"))
amdgpu Simplify well known AMD library false Value Value const Twine & Name
static cl::opt< bool > NoSmallDataSorting("mno-sort-sda", cl::init(false), cl::Hidden, cl::desc("Disable small data sections sorting"))
const DataLayout & getDataLayout() const
Get the data layout for the module's target platform.
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
TypeID getTypeID() const
Return the type id for the type.
unsigned getSmallDataSize() const
Class to represent struct types.
bool hasCommonLinkage() const
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
StringRef str() const
Explicit conversion to StringRef.
Context object for machine code objects.
bool hasExternalLinkage() const
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
Class to represent array types.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
Class to represent pointers.
bool getDataSections() const
Return true if data objects should be emitted into their own section, corresponds to -fdata-sections...
void append(in_iter S, in_iter E)
Append from an iterator pair.
11: Arbitrary bit width integers
initializer< Ty > init(const Ty &Val)
const Function * getLutUsedFunction(const GlobalObject *GO) const
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 GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static bool isSmallDataSection(StringRef Sec)
void InitializeELF(bool UseInitArray_)
bool hasInternalLinkage() const
SectionKind - This is a simple POD value that classifies the properties of a section.
6: 128-bit floating point type (two 64-bits, PowerPC)
MCContext & getContext() const
unsigned UseInitArray
UseInitArray - Use .init_array instead of .ctors for static constructors.
16: SIMD 'packed' format, or other vector type
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.
bool hasSection() const
Check if this global has a custom object file section.
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.
iterator_range< user_iterator > users()
static cl::opt< bool > EmitLutInText("hexagon-emit-lut-text", cl::Hidden, cl::init(false), cl::desc("Emit hexagon lookup tables in function section"))
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 ...
uint64_t getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
bool isMergeableConst() const
bool isPositionIndependent() const
StringRef getName() const
Return a constant reference to the value's name.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
std::string str() const
Return the twine contents as a std::string.
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...
Type * getElementType() const
MCSection * BSSSection
Section that is default initialized to zero.
StringRef - Represent a constant reference to a string, i.e.
9: MMX vectors (64 bits, X86 specific)
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.
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
Type * getElementType() const
PointerType * getType() const
Global values are always pointers.
5: 128-bit floating point type (112-bit mantissa)
static SectionKind getText()
bool isSmallDataEnabled(const TargetMachine &TM) const