This is an archive of the discontinued LLVM Phabricator instance.

Small Data SectionKind and PPC-EABI SDA Relocation
Needs RevisionPublic

Authored by jackoalan on Nov 6 2016, 10:55 PM.

Details

Summary

This patch refactors GlobalVariable section classification on targets by adding the target-independent notion of small-data sections in SectionKind. This is done by logically extending those sections that may be small, with existing predicates masking the "small bit" out:

/// SmallDataSections - Data sections where individual entries are capped
/// for size, typically for global-register-relative relocation.
/// These test as logical equivalents with respect to their unspecified
/// counterparts, but not vice-versa.

   /// SmallKindMask - Used to access the underlying Kind
   SmallKindMask = 0x7f,

   /// SmallData - This is writeable data that has a non-zero initializer.
   SmallData = (Data | 0x80),

   /// SmallReadOnly - This is non-writeable data that has a non-zero
   /// initializer.
   SmallReadOnly = (ReadOnly | 0x80),

   /// SmallBSS - This is writeable data that has a zero initializer.
   SmallBSS = (BSS | 0x80),

   /// SmallCommon - These represent tentative definitions, which always
   /// have a zero initializer and are never marked 'constant'.
   SmallCommon = (Common | 0x80)

Small data support calls were seemingly duplicated from the Mips TargetLoweringObjectFile into Hexagon and Lanai targets. This has been folded into a virtual TargetLoweringObjectFile::isGlobalInSmallSectionKind method; targets may implement this to share the core SectionKind classification mechanism invoked by TargetLoweringObjectFile::getKindForGlobal. TargetLoweringObjectFile::isGlobalInSmallSection is a new target-independent way to perform this test on any GlobalObject, definition or declaration. Additionally, this aids SelectionDAG implementations by having a consistent and clear predicate when producing small data access code.

Additionally, a new PPC-EABI Subtarget is defined with memri relocation triggering to take advantage of the R_PPC_EMB_SDA21 relocation type.

Diff Detail

Event Timeline

jackoalan updated this revision to Diff 77010.Nov 6 2016, 10:55 PM
jackoalan retitled this revision from to Small Data SectionKind and PPC-EABI SDA Relocation.
jackoalan updated this object.
jackoalan set the repository for this revision to rL LLVM.
jackoalan updated this object.Nov 6 2016, 11:01 PM
jackoalan edited edge metadata.
sdardis added inline comments.Nov 9 2016, 5:13 AM
include/llvm/MC/SectionKind.h
121

You should define SmallKind = 0x80, and use that throughout instead of the magic number 0x80.

135

Bikeshedding, but I think this should be BaseKind() or UnderlyingKind().

jackoalan updated this revision to Diff 77382.Nov 9 2016, 11:12 AM

Create SmallKind = 0x80 enum entry, rename smallUnderlyingKind() to UnderlyingKind()

jackoalan updated this revision to Diff 77428.EditedNov 9 2016, 5:35 PM
jackoalan edited edge metadata.

Little-endian addressing fix. Uses addressing described in "3.1.4.4 PowerPC Instruction Addressing in Little-Endian Mode" section of programming manual. (needed to think of it from the offset operand end)

IsLittleEndian? 0 : 1

echristo requested changes to this revision.Nov 9 2016, 10:05 PM
echristo added a reviewer: echristo.
echristo added a subscriber: echristo.

I'd very much like to avoid this use of the subtarget here. You're basing object file level code generation based on something that changes on a per function basis and not on a global basis. I don't think the mips port is a good foundation to build this work on top of here.

My suggestion would be to base it upon either a) the target triple, or b) the information in the top level TargetMachine without the lower level subtarget info.

Thanks.

-eric

This revision now requires changes to proceed.Nov 9 2016, 10:05 PM
jackoalan updated this revision to Diff 77568.Nov 10 2016, 4:16 PM
jackoalan edited edge metadata.

Remove PPCSubtarget:: useEABISmallDataSections() flag, opting for direct TargetTriple::isEABI().

Also remove intrinsically redundant EABI conditionals within PPCEmbeddedTargetObjectFile imps.

jackoalan updated this revision to Diff 77582.Nov 10 2016, 6:01 PM
jackoalan edited edge metadata.

Remove stray blank line, Rebase against upstream master.

jackoalan updated this revision to Diff 78313.Nov 16 2016, 7:20 PM
jackoalan edited edge metadata.

Rebase against latest master. check-all test results match those experienced on base master.

kparzysz edited edge metadata.Nov 17 2016, 5:50 AM

Looks ok from Hexagon's perspective.

jackoalan updated this revision to Diff 78414.EditedNov 17 2016, 1:36 PM
jackoalan edited edge metadata.
jackoalan marked 2 inline comments as done.

Object file ABI tag is now set with the following for PPC:

uint8_t OSABI = TT.isEABI() ? ELF::ELFOSABI_STANDALONE :
                MCELFObjectTargetWriter::getOSABI(TT.getOS());

Linker can now deterministically synthesize _SDA_BASE_ symbols for EABI targets.

Also add tests for ADDR14 and REL14 relocations.

jackoalan updated this revision to Diff 78451.Nov 17 2016, 6:34 PM
jackoalan edited edge metadata.

To better follow GCC convention, use sda21 rather than sdarx as the symbol variant.

Also remove stray getSubtargetImpl and register-strip-prevention unrelated to patch.

jackoalan updated this revision to Diff 78830.Nov 21 2016, 9:26 PM
jackoalan edited edge metadata.

Add target-independent small data classification for constants via MachineConstantPoolEntry::getSectionKind().

jackoalan updated this revision to Diff 79808.Nov 30 2016, 1:49 PM
jackoalan edited edge metadata.
jackoalan removed rL LLVM as the repository for this revision.

Rebase against upstream master

echristo added inline comments.Jul 27 2020, 10:05 PM
lib/Target/PowerPC/PPCTargetObjectFile.cpp
15

I don't think you need this anymore FWIW.

This revision now requires changes to proceed.Jul 27 2020, 10:05 PM