This is an archive of the discontinued LLVM Phabricator instance.

Half-done attempt to move tail padding callback from TargetCXXABI to TargetInfo
AbandonedPublic

Authored by dblaikie on Oct 5 2022, 3:16 PM.

Details

Reviewers
rnk
Summary

Spinoff from D119051 to experiment with moving properties from TargetCXXABI to TargetInfo.

This is incomplete as it fails a couple of clang tests at the moment:

Clang :: CodeGenCXX/armv7k.cpp
Clang :: Layout/watchos-standard-layout.cpp

Haven't looked into why those are failing, but posting the code to see if this is even in the right ballpark of what was being suggested

Diff Detail

Event Timeline

dblaikie created this revision.Oct 5 2022, 3:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 3:16 PM
dblaikie requested review of this revision.Oct 5 2022, 3:16 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 5 2022, 3:16 PM
rnk added inline comments.Oct 5 2022, 3:44 PM
clang/include/clang/Basic/TargetInfo.h
953

The virtual method works, but it does seem to have caused a behavior change. I would be fine with switches and conditionals on the LLVM triple, or a TargetInfo field set in the constructor. That's how a lot of these flag-like behaviors are controlled. Whatever makes things easy.

My concern was more that we should put the target's rules for tail padding next to the target's rules for what constitutes POD-ness.

clang/lib/Basic/Targets/OSTargets.h
169

I think it would be equivalent to check T.getArch() == llvm::Triple::AArch64, that's probably what set the TargetCXXABI.

860

WindowsTargetInfo seems shared with mingw which uses GCC rules, so this isn't quite right. You can check getTriple().isWindowsMSVCEnvironment() here to get equivalent behavior.

dblaikie updated this revision to Diff 465957.Oct 6 2022, 7:18 PM

Fix to use CXXABI

dblaikie added inline comments.Oct 6 2022, 7:19 PM
clang/lib/Basic/Targets/OSTargets.h
169

Hmm, seems one of the tests failed because apparently CXXABI can be chosen separately from target. clang/test/CodeGenCXX/armv7k.cpp for instance runs with -triple=arm64_32-apple-ios -emit-llvm -target-abi darwinpcs

Which seems to have an UnknownOS on the triple, but a WatchOS on the TargetCXXABI... (I don't really understand/haven't looked into how all these things relate to the command line arguments there - none of it mentions WatchOS, but maybe darwinpcs is the name of watchOS?

Updating this function to inspect the CXXABI for WatchOS, AppleARM64, and iOS (which I'd missed from here previously) here makes the tests pass...

Maybe that suggests we should move all this (& the D119051) to TargetCXXABI?

dblaikie added inline comments.Oct 7 2022, 1:35 PM
clang/lib/Basic/Targets/OSTargets.h
169

I guess if this version is going to defer entirely to the CXXABI then presumably the other implementations of getTailPaddingUseRules should do that too - or all of this is to say maybe this property should stay in the ABI? & we should add the DefaultedSMFArePOD property to TargetCXXABI, instead of TargetInfo?

(all that said, I am somewhat confused by what an "OS" is, if it's not an ABI? What does it mean to use one OS but a different ABI? What features of the OS persist in that case? I can't think of any, but don't know much about these things)

rnk added a comment.Oct 10 2022, 3:45 PM

I think in the end, perhaps it is not worth disturbing this code.

clang/lib/Basic/Targets/OSTargets.h
169

I can't speak to any of that, it doesn't make any sense to me to separate the ABI from the OS.

dblaikie abandoned this revision.Oct 11 2022, 10:36 PM

(abandoned this, but still kind of curious)

@rjmccall - any background/history of having the CXXABI distinct from the OS? I guess the point might've been that the C ABI is part of/the definition of the OS, but maybe the CXX ABI is more "floating"/flexible on top of that? Though it means these CXX ABIs don't get the benefit of being grouped with the rest of the targetOS - instead they're a bunch of switches, which seems a bit unfortunate, but I guess there's not lots of properties here, so maybe that's OK.

(abandoned this, but still kind of curious)

@rjmccall - any background/history of having the CXXABI distinct from the OS? I guess the point might've been that the C ABI is part of/the definition of the OS, but maybe the CXX ABI is more "floating"/flexible on top of that? Though it means these CXX ABIs don't get the benefit of being grouped with the rest of the targetOS - instead they're a bunch of switches, which seems a bit unfortunate, but I guess there's not lots of properties here, so maybe that's OK.

I guess the other question: Is this flexibility valuable/worthwhile, or could we fold the CXXABI back into the TargetOS?

(abandoned this, but still kind of curious)

@rjmccall - any background/history of having the CXXABI distinct from the OS? I guess the point might've been that the C ABI is part of/the definition of the OS, but maybe the CXX ABI is more "floating"/flexible on top of that? Though it means these CXX ABIs don't get the benefit of being grouped with the rest of the targetOS - instead they're a bunch of switches, which seems a bit unfortunate, but I guess there's not lots of properties here, so maybe that's OK.

I guess the other question: Is this flexibility valuable/worthwhile, or could we fold the CXXABI back into the TargetOS?

I don't think we really want to support targeting an OS while independently changing the target C++ ABI, no. But I think "OS implies C++ ABI implies ABI properties" is generally the way people define platforms, and I wouldn't want to create a situation where targets have to manually implement all of the right C++ ABI properties just to get default behavior for a specific C++ ABI or else end up weirdly divergent. If you have a different way to achieve that goal besides composition, that's worth considering.

(abandoned this, but still kind of curious)

@rjmccall - any background/history of having the CXXABI distinct from the OS? I guess the point might've been that the C ABI is part of/the definition of the OS, but maybe the CXX ABI is more "floating"/flexible on top of that? Though it means these CXX ABIs don't get the benefit of being grouped with the rest of the targetOS - instead they're a bunch of switches, which seems a bit unfortunate, but I guess there's not lots of properties here, so maybe that's OK.

I guess the other question: Is this flexibility valuable/worthwhile, or could we fold the CXXABI back into the TargetOS?

I don't think we really want to support targeting an OS while independently changing the target C++ ABI, no. But I think "OS implies C++ ABI implies ABI properties" is generally the way people define platforms, and I wouldn't want to create a situation where targets have to manually implement all of the right C++ ABI properties just to get default behavior for a specific C++ ABI or else end up weirdly divergent. If you have a different way to achieve that goal besides composition, that's worth considering.

Thanks for the reply!

Ah, I think I see what you mean.

So we could remove the -fc++-abi flag? (well, it's a driver flag... - deprecate it? make it a no-op or an error if you ask for an abi that isn't the one the OS already implies?)

& then maybe ABI could be a mixin the same way TargetOS works? (TargetOS could mixin the C++ ABI, then TargetInfo mixes in TargetOS)

rjmccall added a comment.EditedOct 12 2022, 4:06 PM

I don't remember the history of the -fc++-abi flag at all, so if that's a driver flag, you'll probably need to investigate it more to remove it. Maybe it was added for testing purposes and only made a driver flag accidentally.

I don't remember the history of the -fc++-abi flag at all, so if that's a driver flag, you'll probably need to investigate it more to remove it. Maybe it was added for testing purposes and only made a driver flag accidentally.

Ah, fair enough. Looks like this got added relatively recently (I mean, still a couple of years ago in 2020) in https://reviews.llvm.org/D85802
Guess we had one ABI flag for this added in rG95a546ee4dbdc997e9898c9839f3851f46a78b5c, removed in rGc9bd88e6811fb622cde644a82eac41c0b02c00ee and then the new one added in the above review.
Ah well, all very confusing.

Thanks!