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 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");
203 DEBUG(
dbgs() <<
"Checking if value is in small-data, -G"
207 DEBUG(
dbgs() <<
"no, not a global variable\n");
214 if (GVar->hasSection()) {
216 DEBUG(
dbgs() << (IsSmall ?
"yes" :
"no") <<
", has section: "
217 << GVar->getSection() <<
'\n');
221 if (GVar->isConstant()) {
226 bool IsLocal = GVar->hasLocalLinkage();
232 Type *GType = GVar->getType();
233 if (
PointerType *PT = dyn_cast<PointerType>(GType))
234 GType = PT->getElementType();
236 if (isa<ArrayType>(GType)) {
246 if (
ST->isOpaque()) {
247 DEBUG(
dbgs() <<
"no, has opaque type\n");
252 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType);
258 DEBUG(
dbgs() <<
"no, size exceeds sdata threshold: " << Size <<
'\n');
275 bool UsesLabelDifference,
const Function &
F)
const {
282 unsigned HexagonTargetObjectFile::getSmallestAddressableSize(
const Type *Ty,
286 unsigned SmallestElement = 8;
292 const StructType *STy = cast<const StructType>(Ty);
294 unsigned AtomicSize = getSmallestAddressableSize(
E, GV, TM);
295 if (AtomicSize < SmallestElement)
296 SmallestElement = AtomicSize;
301 const ArrayType *ATy = cast<const ArrayType>(Ty);
305 const VectorType *PTy = cast<const VectorType>(Ty);
332 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
335 unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
341 TRACE(
"Small data. Size(" << Size <<
")");
351 TRACE(
" default sbss\n");
352 return SmallBSSSection;
359 if (EmitUniquedSection) {
377 TRACE(
" small COMMON (" << Name <<
")\n");
387 TRACE(
" const_object_as_data ");
395 TRACE(
" default sdata\n");
396 return SmallDataSection;
403 if (EmitUniquedSection) {
407 TRACE(
" unique sdata(" << Name <<
")\n");
412 TRACE(
"default ELF section\n");
423 for (
auto U : GO->
users()) {
428 auto *Bb =
I->getParent();
431 auto *UserFn = Bb->getParent();
434 else if (ReturnFn != UserFn)
440 MCSection *HexagonTargetObjectFile::selectSectionForLookupTable(
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.
static cl::opt< bool > EmitJtInText("hexagon-emit-jt-text", cl::Hidden, cl::init(false), cl::desc("Emit hexagon jump tables in function section"))
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.
LLVM_NODISCARD LLVM_ATTRIBUTE_ALWAYS_INLINE bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
MCContext & getContext() const
Type * getElementType() const
Class to represent pointers.
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.
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"))
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
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.
const Function * getLutUsedFunction(const GlobalObject *GO) const
5: 128-bit floating point type (112-bit mantissa)
static SectionKind getText()