forked from OSchip/llvm-project
Cleanups for getKindForGlobal:
- Clarify block comment - Make Function/GlobalVariable split more explicit. - Move locals closer to uses. llvm-svn: 333356
This commit is contained in:
parent
66c5bbc53e
commit
ed169ec424
|
@ -138,22 +138,21 @@ void TargetLoweringObjectFile::emitPersonalityValue(MCStreamer &Streamer,
|
|||
|
||||
|
||||
/// getKindForGlobal - This is a top-level target-independent classifier for
|
||||
/// a global variable. Given an global variable and information from TM, it
|
||||
/// classifies the global in a variety of ways that make various target
|
||||
/// implementations simpler. The target implementation is free to ignore this
|
||||
/// extra info of course.
|
||||
/// a global object. Given a global variable and information from the TM, this
|
||||
/// function classifies the global in a target independent manner. This function
|
||||
/// may be overridden by the target implementation.
|
||||
SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
|
||||
const TargetMachine &TM){
|
||||
assert(!GO->isDeclaration() && !GO->hasAvailableExternallyLinkage() &&
|
||||
"Can only be used for global definitions");
|
||||
|
||||
Reloc::Model ReloModel = TM.getRelocationModel();
|
||||
|
||||
// Early exit - functions should be always in text sections.
|
||||
const auto *GVar = dyn_cast<GlobalVariable>(GO);
|
||||
if (!GVar)
|
||||
// Functions are classified as text sections.
|
||||
if (isa<Function>(GO))
|
||||
return SectionKind::getText();
|
||||
|
||||
// Global variables require more detailed analysis.
|
||||
const auto *GVar = cast<GlobalVariable>(GO);
|
||||
|
||||
// Handle thread-local data first.
|
||||
if (GVar->isThreadLocal()) {
|
||||
if (isSuitableForBSS(GVar, TM.Options.NoZerosInBSS))
|
||||
|
@ -174,14 +173,13 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
|
|||
return SectionKind::getBSS();
|
||||
}
|
||||
|
||||
const Constant *C = GVar->getInitializer();
|
||||
|
||||
// If the global is marked constant, we can put it into a mergable section,
|
||||
// a mergable string section, or general .data if it contains relocations.
|
||||
if (GVar->isConstant()) {
|
||||
// If the initializer for the global contains something that requires a
|
||||
// relocation, then we may have to drop this into a writable data section
|
||||
// even though it is marked const.
|
||||
const Constant *C = GVar->getInitializer();
|
||||
if (!C->needsRelocation()) {
|
||||
// If the global is required to have a unique address, it can't be put
|
||||
// into a mergable section: just drop it into the general read-only
|
||||
|
@ -227,6 +225,7 @@ SectionKind TargetLoweringObjectFile::getKindForGlobal(const GlobalObject *GO,
|
|||
// the time the app starts up. However, we can't put this into a
|
||||
// mergable section, because the linker doesn't take relocations into
|
||||
// consideration when it tries to merge entries in the section.
|
||||
Reloc::Model ReloModel = TM.getRelocationModel();
|
||||
if (ReloModel == Reloc::Static || ReloModel == Reloc::ROPI ||
|
||||
ReloModel == Reloc::RWPI || ReloModel == Reloc::ROPI_RWPI)
|
||||
return SectionKind::getReadOnly();
|
||||
|
|
Loading…
Reference in New Issue