This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Add all predecessor archs in target info
ClosedPublic

Authored by danielkiss on Sep 21 2022, 5:30 AM.

Details

Summary

A given function is compatible with all previous arch versions.
To avoid compering values of the attribute this logic adds all predecessor
architecture values.

Diff Detail

Build Status
Buildable 188423

Event Timeline

danielkiss created this revision.Sep 21 2022, 5:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 5:30 AM
danielkiss requested review of this revision.Sep 21 2022, 5:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 21 2022, 5:30 AM

I think the idea makes sense. I was expecting some tests to change, where they were previously checking for "..,+v8.2a" and would now see v8.1a and v8a, etc.

clang/lib/Basic/Targets/AArch64.cpp
534

Why getCPUArchKind?

clang/lib/Driver/ToolChains/Arch/AArch64.cpp
420 ↗(On Diff #461862)

This looks like it is expecting to add new features just after the arch feature, which may not be the correct one. I'm not sure how much that matters but I guess the idea is that those features can later be disabled.

Can't approve because I don't know the motivation, but in general this is a good thing to add. I wish the target parser had a better way to model it so we didn't have to rely on the ordering of enum values but that's out of scope for now.

clang/lib/Basic/Targets/AArch64.cpp
536

I'd prefer that this sort of logic went in the target parser somewhere. Ok it's yet another one off function but I'd like to keep all these target query functions all in one place.

NormaliseV8V9? Horrible name but you get the idea.

635–636

Can you add a comment here explaining the intent of this?

I think it is something like, if the current architecture kind is not equal to what the feature would give you, make the current arch kind equal to the feature's architecture. So if ArchKind was v8.2 and I put in v8.4, we set ArchKind to 8.4. If it was 8.5 to start with, don't change it.

It's not so obvious on first read though.

llvm/include/llvm/Support/AArch64TargetParser.h
116

We need to at least add comments to the ArchKind definition in target parser to say that order matters now. They are in order but only because it made sense to list them that way.

Perhaps test the order in the target parser tests but that feels like repeating the same stuff and just another test we need to update. So compromise with a comment.

Cant accept the revision rather, I'll leave that to the others.

danielkiss marked 5 inline comments as done.

Refactored and added tests.

dmgreen accepted this revision.Sep 26 2022, 12:55 AM

I think this looks OK. It is a good sign that I had something similar, even if the code came out quite differently.

There are a number of nitpicks below, the general idea LGTM. Thanks for the patch.

clang/lib/Basic/Targets/AArch64.cpp
533

Add a comment explaining that we add 8.x architectures based on 9.x, and another that we add all previous architectures.

535

Capitalize i. Here and below.

635

predeccor -> predecessor?

clang/test/CodeGen/aarch64-subarch-compatbility.c
4

shall able -> should be able?

llvm/unittests/Support/TargetParserTest.cpp
1579

Use EXPECT_EQ for these?

1585

Should <= be <?

1587–1588

It may be better to list the possibilities for current v9 architectures.

This revision is now accepted and ready to land.Sep 26 2022, 12:55 AM
DavidSpickett added inline comments.Sep 26 2022, 1:24 AM
clang/lib/Basic/Targets/AArch64.cpp
541

It's not clear to me that you need 2 loops or the conditional here. What prevents you from just having:

llvm::AArch64::ArchKind AK = llvm::AArch64::getSubArchArchKind(Name);
for (llvm::AArch64::ArchKind i = llvm::AArch64::convertV9toV8(AK);
  i != llvm::AArch64::ArchKind::INVALID; --i)
    Features[llvm::AArch64::getSubArch(i)] = Enabled;

Given that converting anything that isn't v9 returns itself, then you walk backwards to all the previous architectures. Seems like you only need to do that once but tell me what I'm missing.

danielkiss marked 7 inline comments as done.

address comments.

clang/lib/Basic/Targets/AArch64.cpp
541

The iterator only works inside the architecture family 9/8.
so the first loop will set only the v8 counterparts while the second the v9.

DavidSpickett accepted this revision.Sep 26 2022, 3:34 AM

My questions were answered, LGTM.

clang/lib/Basic/Targets/AArch64.cpp
541

Got it, I missed that your operator-- when applied to v9.0 will return invalid. I thought it would go to whatever last v8 there was.

dmgreen accepted this revision.Sep 27 2022, 1:01 AM

Thanks. LGTM

clang/lib/Basic/Targets/AArch64.cpp
534

architechture -> architecture

This revision was landed with ongoing or failed builds.Sep 27 2022, 1:23 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 27 2022, 1:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript