[llvm] r333356 - Cleanups for getKindForGlobal:
Eric Christopher via llvm-commits
llvm-commits at lists.llvm.org
Sun May 27 04:23:20 PDT 2018
Author: echristo
Date: Sun May 27 04:23:20 2018
New Revision: 333356
URL: http://llvm.org/viewvc/llvm-project?rev=333356&view=rev
Log:
Cleanups for getKindForGlobal:
- Clarify block comment
- Make Function/GlobalVariable split more explicit.
- Move locals closer to uses.
Modified:
llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
Modified: llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp?rev=333356&r1=333355&r2=333356&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp (original)
+++ llvm/trunk/lib/Target/TargetLoweringObjectFile.cpp Sun May 27 04:23:20 2018
@@ -138,22 +138,21 @@ void TargetLoweringObjectFile::emitPerso
/// 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::ge
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::ge
// 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();
More information about the llvm-commits
mailing list