This is an archive of the discontinued LLVM Phabricator instance.

[XCOFF][AIX] Fix getSymbol to return the correct qualname when necessary
ClosedPublic

Authored by jasonliu on Apr 13 2020, 12:06 PM.

Details

Summary

AIX symbol have qualname and unqualified name. The stock getSymbol could only return unqualified name, which leads us to patch many caller side(lowerConstant, getMCSymbolForTOCPseudoMO). So we should try to address this problem in the callee side(getSymbol) and clean up the caller side instead.

Note: this is a "mostly" NFC patch, with a fix for the original lowerConstant behavior.

Diff Detail

Event Timeline

jasonliu created this revision.Apr 13 2020, 12:06 PM
jasonliu retitled this revision from [XCOFF][AIX] Fix getSymbol to return the correct qualname to [XCOFF][AIX] Fix getSymbol to return the correct qualname when necessary.Apr 13 2020, 12:07 PM
This comment was removed by jasonliu.
jasonliu marked an inline comment as done.Apr 13 2020, 12:11 PM
jasonliu added inline comments.
llvm/lib/Target/TargetMachine.cpp
263

To reviewers,
I'm not sure if this is a preferred way to inject target specific behavior. Or we want to override TargetMachine::getSymbol directly instead.
Please let me know if you find the other way is more appealing, or you could think of a better way to inject this target specific behavior.
Thanks.

jasonliu edited the summary of this revision. (Show Details)Apr 13 2020, 12:12 PM
jasonliu marked an inline comment as done.Apr 13 2020, 12:18 PM
jasonliu added inline comments.
llvm/include/llvm/Target/TargetLoweringObjectFile.h
241

specialied -> specialized.

llvm/include/llvm/Target/TargetLoweringObjectFile.h
240

Add "a" before "special".

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1975

Add "a" before "qualname". Replace "the" with "a" before "GV".

1993

Add "a" before "GV".

Let's indicate the specific reason why we expect that this would change when -fdata-sections is specified (namely that we could avoid having label symbols if the linkage name is applied to the csect symbol). User-specified section names can either cause such cases or get in the way of them.

llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
6

The object-file testing is not enough to check against the existence of additional symbols whose unqualified name is common. It is probably sufficient if we just verify that the relocation names the defined common[RW].

53

This should use a FileCheck variable.

jasonliu updated this revision to Diff 257331.Apr 14 2020, 7:44 AM

Address comments.

jasonliu marked 4 inline comments as done.Apr 14 2020, 7:44 AM
jasonliu marked an inline comment as done.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1994

No comma before "since".

llvm/lib/Target/TargetMachine.cpp
261

Suggestion:
XCOFF symbols have a special naming convention.

263

Can getTargetSymbol return nullptr to indicate that "falling through" to the generic path is okay? This means that the three lines below don't need to be duplicated.

llvm/test/CodeGen/PowerPC/aix-xcoff-lower-comm.ll
3

The two lines above have trailing whitespace.

27

I think {{[0-9]+}} or similar should be used here. The file does not need to have a .text section.

86

If it is important that there is no entry between pointer and common, then we can base everything off INDX. I don't think we are actually checking for that here, so we should use COM_INDX+1 in place of INDX+5.

daltenty marked an inline comment as done.Apr 14 2020, 9:04 AM
daltenty added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1748

Does it matter we're losing this early error check? Will we end up creating symbols for unanticipated GV kinds before we hit the corresponding check in emitGlobalVariable (and do we care)?

llvm/lib/Target/TargetMachine.cpp
263

This seems the right way to go to me. Going through the TLOF seems appropriate since this is really an object format property, doing a override in the TargetMachine hierarchy doesn't really seem to capture that.

DiggerLin added inline comments.Apr 14 2020, 10:12 AM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1997

to be consistent with getSectionForExternalReference and getSectionForFunctionDescriptor , I am prefer to use getNameWithPrefix(NameStr, GV, TM); here

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1970

I understand the current caller does not have the necessary context, but target symbols for XCOFF are not limited to the csect versus label that this currently handles. It extends to function descriptor versus entry point.

Can we use an expanded version of this function to common up the entry point referencing between AsmPrinter::SetupMachineFunction and the transformCallee that is used by PPCTargetLowering::FinishCall?

jasonliu marked an inline comment as done.Apr 14 2020, 2:13 PM
jasonliu added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1748

I think it's possible for us to create symbols for unanticpated GV kinds, but it will get caught in emitGlobalVariable if we don't do it in getTargetSymbol. I think it should be Okay if we could eventually catch it.

jasonliu marked an inline comment as done.Apr 14 2020, 2:18 PM
jasonliu added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1970

Relay some of the discussion from offline:
I feel adding a boolean to the parameter to determine if we need a function descriptor or entry point would make this function very XCOFF centric and complicate the interface.
I would try to add comments to make sure user of this function is clear that this function will only produce function descriptor. And in a separate patch, I will add a new function called getFunctionEntryPointSymbol to return the function entry point for every caller.

jasonliu updated this revision to Diff 257705.Apr 15 2020, 6:52 AM
jasonliu marked 6 inline comments as done.

Address various comments.

jasonliu updated this revision to Diff 257706.Apr 15 2020, 6:54 AM

I think this is pretty much there. It is important enough that I'd want explicit approval from another one of the reviewers as well though.

llvm/include/llvm/CodeGen/TargetLoweringObjectFileImpl.h
262

Comments about function descriptor versus entry point would go here?

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1976

Comment goes here to clarify that a GV representing the address of a function is inherently ambiguous between representing a function descriptor and a function entry point.

jasonliu updated this revision to Diff 258051.Apr 16 2020, 7:32 AM

Updated comments to clarify function descriptor vs function entry point.

jasonliu marked 2 inline comments as done.Apr 16 2020, 7:33 AM
DiggerLin added inline comments.Apr 16 2020, 7:55 AM
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1987

add some thing like to test isBSSLocal by the way ?

@comm_bs = internal global i32 0, align 4
@ps = global i32* @comm_bs, align 4

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

since we get the qualname symbol, I do not think we need to set
GVSym->setStorageClass (....) here.

1639

since we have created the MCSectionXCOFF *Csect in the getSymbol.
do we still need this ?

can we change to
if (GVSym->hasRepresentedCsectSet())

Csect = GVSym->getRepresentedCsect()

else {

Csect = getObjFileLowering().SectionForGlobal(
        : getObjFileLowering().SectionForGlobal(
              GV, GVKind = getObjFileLowering().getKindForGlobal(GV, TM),

}
?

DiggerLin added inline comments.Apr 16 2020, 8:04 AM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1643–1644

since we have a qualname symbol, I do not think we need to create and unnecessary UnqualifiedName symbol.
maybe we change change the interface of emitXCOFFLocalCommonSymbol. I do not think we need to pass two Symbols(MCSymbol *LabelSym, and MCSymbol *CsectSym) in the emitXCOFFLocalCommonSymbol.

DiggerLin added inline comments.Apr 16 2020, 8:17 AM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1632

sorry, please discard the comment, maybe label here, it still need to set the StorageClass() here

llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1978

s/represents/represent/;

llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1643–1644

The label does not have to be given linkage, but it is not optional in the assembly syntax.

jasonliu updated this revision to Diff 258077.Apr 16 2020, 9:37 AM
jasonliu marked 3 inline comments as done.
jasonliu added inline comments.
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
1987

I don't feel a strong need about this, as this code path is going to get exercise by emitGlobalVariable and getMCSymbolForTOCPseudoMO, and so we know we will get a qualname for it and is covered by the old test cases already.

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

Thanks. I don't think we need to get csect for external symbol. For the other symbol, even if it's qualname, we could still get it with SectionForGlobal query.
I would like to avoid the usage of hasRepresentedCsectSet() if possible. Whenever we use that interface means we have a potential timing issue (some are indeed by design) for csect setting.
So I adjust the code accordingly.

1643–1644

.lcomm a[BS],4,a[BS],2 does not work. First expression must be a label.

jasonliu updated this revision to Diff 258078.Apr 16 2020, 9:43 AM
jasonliu marked an inline comment as done.

Thanks. I believe all of the comments have been addressed appropriately.

DiggerLin added inline comments.Apr 16 2020, 10:29 AM
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1643–1644

we can change

LabelSym->print(OS, MAI);

to

OS << CsectSym->getUnqualifiedName();

in the function void MCAsmStreamer::emitXCOFFLocalCommonSymbol

jasonliu marked an inline comment as done.Apr 16 2020, 11:34 AM
jasonliu added inline comments.
llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
1643–1644

I'd prefer to leave the interface as it is. The label and the csect does not necessarily have to be .lcomm a, 4, a[BS],2. It could be `.lcomm a, 4, b[BS],2'.
In the future, if we need to do an assembly paser, we could receive the case like above, and need to have label and csect represented separately.

This revision is now accepted and ready to land.Apr 16 2020, 12:24 PM
This revision was automatically updated to reflect the committed changes.