From ed169ec42460d8388ad6d10aae49a82154b1f6ea Mon Sep 17 00:00:00 2001 From: Eric Christopher Date: Sun, 27 May 2018 11:23:20 +0000 Subject: Cleanups for getKindForGlobal: - Clarify block comment - Make Function/GlobalVariable split more explicit. - Move locals closer to uses. llvm-svn: 333356 --- llvm/lib/Target/TargetLoweringObjectFile.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'llvm/lib/Target/TargetLoweringObjectFile.cpp') 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(GO); - if (!GVar) + // Functions are classified as text sections. + if (isa(GO)) return SectionKind::getText(); + // Global variables require more detailed analysis. + const auto *GVar = cast(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(); -- cgit v1.2.3