33#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)); \
89 if (Sec ==
".sdata" || Sec ==
".sbss" || Sec ==
".scommon")
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);
152 if (Kind.isCommon()) {
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 " :
"" ));
181 if (Section.contains(
".access.text.group"))
184 if (Section.contains(
".access.data.group"))
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");
220 <<
", has section: " << GVar->
getSection() <<
'\n');
252 if (ST->isOpaque()) {
282 bool UsesLabelDifference,
const Function &
F)
const {
289unsigned HexagonTargetObjectFile::getSmallestAddressableSize(
const Type *Ty,
293 unsigned SmallestElement = 8;
297 switch (Ty->getTypeID()) {
301 unsigned AtomicSize = getSmallestAddressableSize(E, GV,
TM);
302 if (AtomicSize < SmallestElement)
303 SmallestElement = AtomicSize;
309 return getSmallestAddressableSize(ATy->getElementType(), GV,
TM);
314 return getSmallestAddressableSize(PTy->getElementType(), GV,
TM);
324 return DL.getTypeAllocSize(
const_cast<Type*
>(Ty));
344MCSection *HexagonTargetObjectFile::selectSmallSectionForGlobal(
347 unsigned Size = getSmallestAddressableSize(GTy, GO,
TM);
351 bool EmitUniquedSection =
TM.getDataSections();
353 TRACE(
"Small data. Size(" <<
Size <<
")");
355 if (
Kind.isBSS() ||
Kind.isBSSLocal()) {
363 TRACE(
" default sbss\n");
364 return SmallBSSSection;
367 StringRef
Prefix(
".sbss");
368 SmallString<128>
Name(Prefix);
371 if (EmitUniquedSection) {
375 TRACE(
" unique sbss(" << Name <<
")\n");
380 if (
Kind.isCommon()) {
389 TRACE(
" small COMMON (" << Name <<
")\n");
398 if (
Kind.isMergeableConst()) {
399 TRACE(
" const_object_as_data ");
407 TRACE(
" default sdata\n");
408 return SmallDataSection;
411 StringRef
Prefix(
".sdata");
412 SmallString<128>
Name(Prefix);
415 if (EmitUniquedSection) {
419 TRACE(
" unique sdata(" << Name <<
")\n");
424 TRACE(
"default ELF section\n");
435 for (
const auto *U : GO->
users()) {
440 auto *Bb =
I->getParent();
443 auto *UserFn = Bb->getParent();
446 else if (ReturnFn != UserFn)
452MCSection *HexagonTargetObjectFile::selectSectionForLookupTable(
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static cl::opt< bool > TraceGVPlacement("trace-gv-placement", cl::Hidden, cl::init(false), cl::desc("Trace global value placement"))
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< unsigned > SmallDataThreshold("hexagon-small-data-threshold", cl::init(8), cl::Hidden, cl::desc("The maximum size of an object in the sdata section"))
static cl::opt< bool > StaticsInSData("hexagon-statics-in-small-data", cl::Hidden, cl::desc("Allow static variables in .sdata"))
static const char * getSectionSuffixForSize(unsigned Size)
static cl::opt< bool > EmitLutInText("hexagon-emit-lut-text", cl::Hidden, cl::init(false), cl::desc("Emit hexagon lookup tables in function section"))
static cl::opt< bool > NoSmallDataSorting("mno-sort-sda", cl::init(false), cl::Hidden, cl::desc("Disable small data sections sorting"))
static bool isSmallDataSection(StringRef Sec)
Module.h This file contains the declarations for the Module class.
This file defines the SmallString class.
LLVM_ABI TypeSize getTypeAllocSize(Type *Ty) const
Returns the offset in bytes between successive objects of the specified type, including alignment pad...
StringRef getSection() const
Get the custom section of this global if it has one.
bool hasSection() const
Check if this global has a custom object file section.
bool hasExternalLinkage() const
bool hasLocalLinkage() const
bool hasPrivateLinkage() const
bool hasInternalLinkage() const
LLVM_ABI const DataLayout & getDataLayout() const
Get the data layout of the module this global belongs to.
bool hasCommonLinkage() const
Type * getValueType() const
bool isConstant() const
If the value is a global constant, its value is immutable throughout the runtime execution of the pro...
bool shouldPutJumpTableInFunctionSection(bool UsesLabelDifference, const Function &F) const override
bool isSmallDataEnabled(const TargetMachine &TM) const
void initialize(MCContext &Ctx, const TargetMachine &TM, const Module &M) override
This method must be called before any actual lowering is done.
bool isGlobalInSmallSection(const GlobalObject *GO, const TargetMachine &TM) const
Return true if this global value should be placed into small data/bss section.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
unsigned getSmallDataSize() 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...
const Function * getLutUsedFunction(const GlobalObject *GO) const
Context object for machine code objects.
MCSectionELF * getELFSection(const Twine &Section, unsigned Type, unsigned Flags)
MCSection * BSSSection
Section that is default initialized to zero.
MCContext & getContext() const
Instances of this class represent a uniqued identifier for a section in the current translation unit.
A Module instance is used to store all the information related to an LLVM module.
SectionKind - This is a simple POD value that classifies the properties of a section.
static SectionKind getText()
static SectionKind getData()
Represent a constant reference to a string, i.e.
bool starts_with(StringRef Prefix) const
Check if this string starts with the given Prefix.
bool contains(StringRef Other) const
Return true if the given string is a substring of *this, and false otherwise.
Class to represent struct types.
ArrayRef< Type * > elements() const
unsigned getNumElements() const
Random access to the elements.
MCSection * SelectSectionForGlobal(const GlobalObject *GO, SectionKind Kind, const TargetMachine &TM) const override
void initialize(MCContext &Ctx, const TargetMachine &TM, const Module &M) override
This method must be called before any actual lowering is done.
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...
Primary interface to the complete machine description for the target machine.
The instances of the Type class are immutable: once they are created, they are never changed.
@ X86_AMXTyID
AMX vectors (8192 bits, X86 specific)
@ TypedPointerTyID
Typed pointer used by some GPU targets.
@ HalfTyID
16-bit floating point type
@ TargetExtTyID
Target extension type.
@ VoidTyID
type with no size
@ ScalableVectorTyID
Scalable SIMD vector type.
@ FloatTyID
32-bit floating point type
@ IntegerTyID
Arbitrary bit width integers.
@ FixedVectorTyID
Fixed width SIMD vector type.
@ BFloatTyID
16-bit floating point type (7-bit significand)
@ DoubleTyID
64-bit floating point type
@ X86_FP80TyID
80-bit floating point type (X87)
@ PPC_FP128TyID
128-bit floating point type (two 64-bits, PowerPC)
@ ByteTyID
Arbitrary bit width bytes.
@ FP128TyID
128-bit floating point type (112-bit significand)
iterator_range< user_iterator > users()
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
initializer< Ty > init(const Ty &Val)
This is an optimization pass for GlobalISel generic memory operations.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.