This is an archive of the discontinued LLVM Phabricator instance.

[AIX][llvm][support] Implement getHostCPUName
ClosedPublic

Authored by daltenty on Feb 3 2021, 12:06 PM.

Details

Summary

We implement getHostCPUName() for AIX via systemcfg interfaces since access to the processor version register is a privileged operation. We return a value based on the current processor implementation mode.

This fixes the cpu detection used by clang for -mcpu=native.

Diff Detail

Event Timeline

daltenty created this revision.Feb 3 2021, 12:06 PM
daltenty requested review of this revision.Feb 3 2021, 12:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 3 2021, 12:06 PM
daltenty edited the summary of this revision. (Show Details)Feb 3 2021, 12:50 PM
llvm/lib/Support/Host.cpp
1235

I think the interfaces from sys/systemcfg.h can be used?

daltenty planned changes to this revision.Feb 3 2021, 1:43 PM
daltenty added inline comments.
llvm/lib/Support/Host.cpp
1235

Thanks, I'll check those out! I was having some trouble finding a documented system interface to get the same functionality, would definitely be preferable if possible.

daltenty updated this revision to Diff 321433.Feb 4 2021, 8:01 AM
  • Use systemcfg interfaces instead. Move the getsysttype call to the test.
daltenty edited the summary of this revision. (Show Details)Feb 4 2021, 8:02 AM
daltenty updated this revision to Diff 321436.Feb 4 2021, 8:08 AM
  • Remove stray program.h
stevewan added inline comments.Feb 4 2021, 12:00 PM
llvm/lib/Support/Host.cpp
1232

I suspect we're going to update this once POWER_10 is defined by the system header, do we need a TO-DO before that happens?

1237

Might be a dumb question, but why do we need the enum and can't do

switch (_system_configuration.implementation) {
case POWER_4:
...
daltenty added inline comments.Feb 4 2021, 1:30 PM
llvm/lib/Support/Host.cpp
1237

The original thinking was to benefit from -Wswitch-enum if someone missed something, but to be honest it just likely we'd miss it there, so I think we can just simply this as suggested.

daltenty marked an inline comment as done.Feb 4 2021, 1:30 PM
daltenty updated this revision to Diff 321558.Feb 4 2021, 1:31 PM
  • Simplify
  • Comment
llvm/lib/Support/Host.cpp
1227–1232

I'm not entirely sure that "something is better than nothing" is necessarily true here for these. All three have variant implementations/modes (e.g., ppc970, pwr5x, pwr6e) that we aren't handling here.

daltenty added inline comments.Feb 5 2021, 7:13 AM
llvm/lib/Support/Host.cpp
1227–1232

For pwr5x and pwr6e (IIUC don't think we can actually encounter ppc970), looking at the interfaces it seems that AIX won't distinguish the implementation mode, so I'm not sure if we can easily refine this in those case. Presumably this will still be better than returning 'generic' in those cases though though.

daltenty added inline comments.Feb 5 2021, 8:13 AM
llvm/lib/Support/Host.cpp
1227–1232

(Or rather ppc970 would presumable appear as POWER 4)

llvm/lib/Support/Host.cpp
1227–1232

What I was able to find internally seems to be that the _system_configuration.version field is PV_4_3 for ppc970, PV_5 exactly for pwr5 (and otherwise indicates pwr5x), and PV_6_Compat exactly for pwr6 (i.e., architected mode; and, if not exactly that value, indicates pwr6e).

Note that this does make sense with the historical background that POWER 6 went out with new instructions that were not going to be enshrined into the ISA going forward.

daltenty updated this revision to Diff 322171.Feb 8 2021, 11:00 AM
  • Handle specialized cases for pwr 4/5/6
daltenty updated this revision to Diff 322182.Feb 8 2021, 11:48 AM
  • Fix formatting

LGTM with minor comments on the test.

llvm/unittests/Support/Host.cpp
436

Minor comment wording/formatting nits.

455

Minor nit: Format as English prose (especially since there's already a period at the end).

458–459

... or rtrim.

459

Use drop_back

This revision is now accepted and ready to land.Feb 9 2021, 7:58 AM
stevewan added inline comments.Feb 9 2021, 9:17 AM
llvm/lib/Support/Host.cpp
1227–1232

PV_6_Compat exactly for pwr6 (i.e., architected mode; and, if not exactly that value, indicates pwr6e).

Noted that the accepted change returns pwr6x instead of pwr6e for versions not matching PV_6_Compat. Do we have a reasoning for that?

daltenty added inline comments.Feb 9 2021, 10:43 AM
llvm/lib/Support/Host.cpp
1227–1232

Good question. This what it appears to be called for LLVM in PPC.td. Why this is the case, I'm not too sure. It's close to what GCC uses (i.e. 'power6x') but our options appear to be incompatible anyway, since we use shortnames and they use long ones, so there's probably a follow on item here if we wanted all the variants of a name to be accepted.

llvm/lib/Support/Host.cpp
1227–1232

pwr6x is a suboption name used by Clang (probably based on GCC's power6x). The latter is documented as mainly being about the mffgpr and mftgpr opcodes. This would therefore map to the pwr6e suboption name used by IBM XL. See https://reviews.llvm.org/D58128 for more information.

daltenty updated this revision to Diff 322478.Feb 9 2021, 12:57 PM
  • Address comments
daltenty marked 4 inline comments as done.Feb 9 2021, 1:09 PM
daltenty retitled this revision from [AIX][support] Implement getHostCPUName to [AIX][llvm][support] Implement getHostCPUName.Feb 9 2021, 1:28 PM
This revision was landed with ongoing or failed builds.Feb 9 2021, 1:30 PM
This revision was automatically updated to reflect the committed changes.
stevewan added inline comments.Feb 9 2021, 2:39 PM
llvm/lib/Support/Host.cpp
1227–1232

Gotcha. So it's just called differently by different compilers, but in the end they are both associated with the "raw mode" of power6.