13 #define DEBUG_TYPE "hexagon-sdata" 38 cl::desc(
"The maximum size of an object in the sdata section"));
45 cl::desc(
"Allow static variables in .sdata"));
49 cl::desc(
"Trace global value placement"));
53 cl::desc(
"Emit hexagon jump tables in function section"));
57 cl::desc(
"Emit hexagon lookup tables in function section"));
62 #define TRACE_TO(s, X) s << X 66 if (TraceGVPlacement) { \ 67 TRACE_TO(errs(), X); \ 73 if (TraceGVPlacement) { \ 74 TRACE_TO(errs(), X); \ 76 LLVM_DEBUG(TRACE_TO(dbgs(), X)); \ 129 TRACE(
"[SelectSectionForGlobal] GO(" << GO->
getName() <<
") ");
138 << (Kind.
isCommon() ?
"kind_common " :
"" )
139 << (Kind.
isBSS() ?
"kind_bss " :
"" )
140 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
146 return selectSectionForLookupTable(GO, TM, Fn);
150 return selectSmallSectionForGlobal(GO, Kind, TM);
160 TRACE(
"default_ELF_section\n");
167 TRACE(
"[getExplicitSectionGlobal] GO(" << GO->
getName() <<
") from(" 175 << (Kind.
isCommon() ?
"kind_common " :
"" )
176 << (Kind.
isBSS() ?
"kind_bss " :
"" )
177 << (Kind.
isBSSLocal() ?
"kind_bss_local " :
"" ));
190 return selectSmallSectionForGlobal(GO, Kind, TM);
193 TRACE(
"default_ELF_section\n");
203 LLVM_DEBUG(
dbgs() <<
"Small-data allocation is disabled, but symbols " 204 "may have explicit section assignments...\n");
217 if (GVar->hasSection()) {
220 <<
", has section: " << GVar->getSection() <<
'\n');
230 if (GVar->isConstant()) {
235 bool IsLocal = GVar->hasLocalLinkage();
241 Type *GType = GVar->getValueType();
242 if (isa<ArrayType>(GType)) {
252 if (
ST->isOpaque()) {
258 unsigned Size = GVar->getParent()->getDataLayout().getTypeAllocSize(GType);
264 LLVM_DEBUG(
dbgs() <<
"no, size exceeds sdata threshold: " << Size <<
'\n');
282 bool UsesLabelDifference,
const Function &
F)
const {
289 unsigned HexagonTargetObjectFile::getSmallestAddressableSize(
const Type *Ty,
293 unsigned SmallestElement = 8;
299 const StructType *STy = cast<const StructType>(Ty);
301 unsigned AtomicSize = getSmallestAddressableSize(
E, GV, TM);
302 if (AtomicSize < SmallestElement)
303 SmallestElement = AtomicSize;
308 const ArrayType *ATy = cast<const ArrayType>(Ty);
312 const VectorType *PTy = cast<const VectorType>(Ty);
339 MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
342 unsigned Size = getSmallestAddressableSize(GTy, GO, TM);
348 TRACE(
"Small data. Size(" << Size <<
")");
358 TRACE(
" default sbss\n");
359 return SmallBSSSection;
366 if (EmitUniquedSection) {
370 TRACE(
" unique sbss(" << Name <<
")\n");
384 TRACE(
" small COMMON (" << Name <<
")\n");
394 TRACE(
" const_object_as_data ");
402 TRACE(
" default sdata\n");
403 return SmallDataSection;
410 if (EmitUniquedSection) {
414 TRACE(
" unique sdata(" << Name <<
")\n");
419 TRACE(
"default ELF section\n");
430 for (
auto U : GO->
users()) {
435 auto *Bb =
I->getParent();
438 auto *UserFn = Bb->getParent();
441 else if (ReturnFn != UserFn)
447 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
amdgpu Simplify well known AMD library false FunctionCallee Value const Twine & Name
ArrayRef< Type * > const elements() const
LLVM_NODISCARD bool startswith(StringRef Prefix) const
Check if this string starts with the given Prefix.
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"))
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
Class to represent array types.
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
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")
TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
static bool isSmallDataSection(StringRef Sec)
void InitializeELF(bool UseInitArray_)
LLVM_NODISCARD size_t find(char C, size_t From=0) const
Search for the first character C in the string.
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 bool equals(StringRef RHS) const
equals - Check for string equality, this is more efficient than compare() when the relative ordering ...
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)
Type * getValueType() const
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)
void Initialize(MCContext &Ctx, const TargetMachine &TM) override
This method must be called before any actual lowering is done.
5: 128-bit floating point type (112-bit mantissa)
static SectionKind getText()
bool isSmallDataEnabled(const TargetMachine &TM) const