summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Target/TargetLoweringObjectFile.cpp
diff options
context:
space:
mode:
authorEric Christopher <echristo@gmail.com>2018-05-27 11:23:20 +0000
committerEric Christopher <echristo@gmail.com>2018-05-27 11:23:20 +0000
commited169ec42460d8388ad6d10aae49a82154b1f6ea (patch)
tree6e1176047bafbcda68b40d2bf4fbf02453f8e4c8 /llvm/lib/Target/TargetLoweringObjectFile.cpp
parent66c5bbc53e0b215143ed65e20561e3c5bab80e93 (diff)
downloadbcm5719-llvm-ed169ec42460d8388ad6d10aae49a82154b1f6ea.tar.gz
bcm5719-llvm-ed169ec42460d8388ad6d10aae49a82154b1f6ea.zip
Cleanups for getKindForGlobal:
- Clarify block comment - Make Function/GlobalVariable split more explicit. - Move locals closer to uses. llvm-svn: 333356
Diffstat (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp')
-rw-r--r--llvm/lib/Target/TargetLoweringObjectFile.cpp21
1 files changed, 10 insertions, 11 deletions
diff --git a/llvm/lib/Target/TargetLoweringObjectFile.cpp b/llvm/lib/Target/TargetLoweringObjectFile.cpp
index c05ea70d1e6..ee4cca6ae49 100644
--- a/llvm/lib/Target/TargetLoweringObjectFile.cpp
+++ b/llvm/lib/Target/TargetLoweringObjectFile.cpp
@@ -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();
OpenPOWER on IntegriCloud