This is an archive of the discontinued LLVM Phabricator instance.

[NFC][XCOFF] Refactor Csect creation into TargetLoweringObjectFile
ClosedPublic

Authored by daltenty on Jan 7 2020, 10:01 AM.

Details

Summary

We create a number of standard types of control sections in multiple places for
things like the function descriptors, external references and the TOC anchor
among others, so it is possible for their properties to be defined
inconsistently in different places. This refactor moves their creation and
properties into functions in the TargetLoweringObjectFile class hierarchy, where
functions for retrieving various special types of sections typically seem
to reside.

Note: There is one case in PPCISelLowering which is specific to function entry
points which we don't address since we don't have access to the TLOF there.

Diff Detail

Event Timeline

daltenty created this revision.Jan 7 2020, 10:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 7 2020, 10:01 AM
daltenty retitled this revision from [NFC][XCOFF] Refactor CSect creation into TargetLoweringObjectFile to [NFC][XCOFF] Refactor Csect creation into TargetLoweringObjectFile.Jan 7 2020, 10:02 AM
DiggerLin added inline comments.Jan 8 2020, 8:03 AM
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
251

I think we can
getSectionForExternalReference(const MCSymbol *Sym). const override here ?

I search all the place where invoke getSectionForExternalReference , it can use the function define getSectionForExternalReference(const MCSymbol *Sym)

the benefit of using getSectionForExternalReference(const MCSymbol *Sym) , we save one parameter and have some function parameter as getSectionForFunctionDescriptor and getSectionForTOCEntry

DiggerLin added inline comments.Jan 8 2020, 8:27 AM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1619

If I understand correctly, I do not think we need to change the

if (!GV->hasInitializer())  to here .

the reason is if the extern variable is declared in the source code. but never be used, it the declare extern variable do not to show on the xcoff object file even in the symbol table or in the asm file.

if the extern variable is declared and be used as initiator , the MCSection will be created in the PPCAIXAsmPrinter::lowerConstant()

jasonliu added inline comments.Jan 10 2020, 9:51 AM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1985

Other getSection... function do not set the containing csect.
And I think for the design of the function, this extra convenient thing it does, did not reflect on anywhere (function name does not suggest it would do that). When developer see the call site only, they might actually want to find out why we do not set the containing csect (until they find it here).
So I suggest to move it out for both consistency and the design.

daltenty planned changes to this revision.Jan 13 2020, 8:53 AM
daltenty marked 3 inline comments as done.Jan 14 2020, 10:47 AM
daltenty added inline comments.
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
251

I was original inclined to do this as well, but we need to query the GlobalObject to determine whether it is a function, so we can set the correct Storage Mapping Class.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1619

There are other cases than will be handled by lowerConstant(). We may refer to the external global in a function body, in which case we will need to setup the symbols containing CSect here.

daltenty updated this revision to Diff 238038.Jan 14 2020, 10:48 AM
  • Move set containing csect out of getSectionForTOCEntry
daltenty updated this revision to Diff 238239.Jan 15 2020, 6:42 AM
  • Avoid unneeded variable rename
daltenty updated this revision to Diff 238241.Jan 15 2020, 6:44 AM
  • And avoid comment change
Harbormaster completed remote builds in B44041: Diff 238241.
jasonliu added inline comments.Jan 15 2020, 7:15 AM
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
251

Have we thought about passing an extra bool parameter to indicate whether it is a function or not? I don't like bool parameter either, but in this case, it might not be that bad, and we could avoid querying if we need to create a new name.

daltenty marked an inline comment as done.Jan 15 2020, 10:30 AM
daltenty added inline comments.
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
251

Unfortunately functions are not the only special case of externals we will need to handle in the future (e.g. thread locals), so I think this interface creates a better abstraction for the future. The current parameter types are also fairly congruent with what we see for some of the other get*Section() members here.

jasonliu accepted this revision.Jan 16 2020, 6:58 AM

Other than some minor nits. LGTM.

llvm/include/llvm/Target/TargetLoweringObjectFile.h
216

nit: it's -> its

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1984

nit: similar to the function above, we could return this TCEntry directly without creating a local variable.

This revision is now accepted and ready to land.Jan 16 2020, 6:58 AM
llvm/include/llvm/Target/TargetLoweringObjectFile.h
215

This is for targets that use separate function descriptor symbols, not for targets that support function descriptors in general.

221

https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi-1.9.html mentions TOC entries. Did we implement this function for the corresponding LLVM implementation?

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1619

Please add this rationale to the comment about creating the containing csect.

daltenty updated this revision to Diff 238519.Jan 16 2020, 8:59 AM
daltenty marked 5 inline comments as done.
  • Comment updates
  • Just do a direct return in getSectionForTOCEntry
llvm/include/llvm/Target/TargetLoweringObjectFile.h
221

I can add the ELF change if we think it is in scope, though this will make this no longer an XCOFF only patch. Perhaps we better do that as a follow on patch?

llvm/include/llvm/Target/TargetLoweringObjectFile.h
221

The second this lands, having the interface here without a TODO comment suggests that it is already implemented for the existing targets for which it applies. The alternative consideration is whether the scope of the interface is correct. Should it be clearly more XCOFF specific and should it be a virtual function at this level of the class hierarchy at all?

daltenty updated this revision to Diff 238773.Jan 17 2020, 7:22 AM
  • Add todo
daltenty marked an inline comment as done.Jan 17 2020, 7:23 AM
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
247

I am not sure there is anything about this interface that indicates that it is not suitable for retrieving the section for a function descriptor in the case where said section should be an external reference. In lowerConstant, the argument value needed to call this function is available even in the case where the function is undefined.

250

I am not sure there is anything about this interface that indicates that it is not suitable for retrieving the section for an external reference to a function entry point. Where getAIXFuncEntryPointSymbolSDNode is present in the codebase, the function is also handled as a GlobalObject.

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1837

Add "a" before "defined global".

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1622

Assert !GV->isDeclaration() here to be sure that GVKind has been initialized.

daltenty marked 2 inline comments as done.Jan 17 2020, 9:02 AM
daltenty added inline comments.
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
247

I will add a comment indicating this interface is for use only with defined functions.

250

Indeed, that is not a limitation of this interface, this is the case in PPCISelLowering mentioned in the patch description. It was my intention to handle that as a separate patch since it will require some further refactoring as it appears the TLOF is not available there.

daltenty marked an inline comment as done.Jan 17 2020, 9:14 AM
daltenty added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1622

The branch on !GV->hasInitializer() above guarantees this, GV->hasInitializer() is defined as !isDeclaration()

daltenty updated this revision to Diff 238802.Jan 17 2020, 9:16 AM
  • Address comments
daltenty marked an inline comment as done.Jan 17 2020, 9:17 AM
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
250

The interface is ambiguous as it stands on whether the function descriptor or function entry point is meant.

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1973

There should be an assertion that the function is defined.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1622

It is better not to rely on such a relationship between the two queries.

daltenty marked 3 inline comments as done.Jan 20 2020, 2:10 PM
daltenty added inline comments.
llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
250

I've added a comment to clarify this is the behaviour for XCOFF

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1973

That query is not safe to make on the symbol here, as it requires a fragment that we may not have.

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1622

I will replace the branch condition above with 'isDeclaration()' so the relationship is explicit

daltenty updated this revision to Diff 239201.Jan 20 2020, 2:12 PM
  • Address comments

LGTM with minor comment.

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
250

I think this deserves to be a Doxygen comment.

This revision was automatically updated to reflect the committed changes.