This is an archive of the discontinued LLVM Phabricator instance.

[ARM][AArch64] generate subtarget feature flags [NFC]
ClosedPublic

Authored by tmatheson on Mar 3 2022, 6:55 AM.

Details

Summary

This patch aims to reduce a lot of the boilerplate around adding new subtarget
features. From the SubtargetFeatures tablegen definitions, a series of calls to
the macro GET_SUBTARGETINFO_MACRO are generated in
ARM/AArch64GenSubtargetInfo.inc. ARMSubtarget/AArch64Subtarget can then use
this macro to define bool members and the corresponding getter methods.

Some naming inconsistencies have been fixed to allow this, and one unused
member removed.

This implementation only applies to boolean members; in future both BitVector
and enum members could also be generated.

Diff Detail

Event Timeline

tmatheson created this revision.Mar 3 2022, 6:55 AM
tmatheson requested review of this revision.Mar 3 2022, 6:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 6:55 AM
tmatheson retitled this revision from [ARM][AArch64] generate subtarget feature flags to [ARM][AArch64] generate subtarget feature flags [NFC].Mar 3 2022, 6:56 AM

Ping. Anyone have thoughts on this approach?

tmatheson edited reviewers, added: dmgreen; removed: greened.Mar 11 2022, 5:23 AM
MaskRay accepted this revision.Mar 11 2022, 6:32 PM

Looks great!

llvm/lib/Target/AArch64/AArch64Subtarget.h
158

Is NAME used? Or do you expect it may be used in the future?

llvm/lib/Target/ARM/ARM.td
53

It seems that you just copy comments from *Subtarget.h to the TableGen file. Seems useful to push the comment in a separate commit to make it clear this patch changes TableGen very little.

177

Previous comments use True if while this one uses If true,. Try improving consistency.

Also, end comments with a period.

llvm/utils/TableGen/SubtargetEmitter.cpp
1811

delete blank line after for

This revision is now accepted and ready to land.Mar 11 2022, 6:32 PM
MaskRay added inline comments.Mar 11 2022, 6:33 PM
llvm/utils/TableGen/SubtargetEmitter.cpp
1812

https://llvm.org/docs/CodingStandards.html#use-auto-type-deduction-to-make-code-more-readable

String can be std::string, StringRef, or SmallString<0>. It is clearer to spell it.

1823
MaskRay added inline comments.Mar 11 2022, 6:36 PM
llvm/lib/Target/ARM/ARM.td
205

https://llvm.org/docs/CodingStandards.html#doxygen-use-in-documentation-comments
"Don’t duplicate function or class name at the beginning of the comment."

232

The two sentences now have no punctuation as a separator.

MaskRay added inline comments.Mar 11 2022, 6:38 PM
llvm/lib/Target/ARM/ARM.td
191

supports AES does not convey more information than FeatureAES. Drop the comment.

(The previous comment // If true, processor supports SHA1 and SHA256 conveys more information.)

tmatheson updated this revision to Diff 416126.Mar 17 2022, 3:40 AM

Address review comments

tmatheson marked 8 inline comments as done.Mar 17 2022, 3:42 AM
tmatheson added inline comments.
llvm/lib/Target/AArch64/AArch64Subtarget.h
158

Unused so removed for now.

skan added a subscriber: skan.Mar 17 2022, 4:18 AM
skan added inline comments.Mar 17 2022, 5:04 AM
llvm/utils/TableGen/SubtargetEmitter.cpp
1816

A question: Why we need to check [ here?

1817

Just checking IsBool could not handle some X86 features ...

bool hasCMov() const { return HasCMov || X86SSELevel >= SSE1 || is64Bit(); }
bool useAA() const override { return UseAA; }
bool hasLAHFSAHF() const { return HasLAHFSAHF64 || !is64Bit(); }
1821

I'm afraid this assumption is not correct. The default value is orthogonal to the value set by a feature.

1826

The comments is missing is the generated header file.

tmatheson added inline comments.Mar 17 2022, 6:13 AM
llvm/utils/TableGen/SubtargetEmitter.cpp
1816

This is to exclude BitVector fields which have attributes like ReserveRegister[i]

1817

IMO these functions should be renamed to make it clear they do more than just check a feature field.

1821

It is correct for ARM/AArch64, which I would argue is sensible.

1826

The comments have been moved to the SubtargetFeature declarations in the tablegen files. It would be better if they were available on the getter/fields but that can't be accomplished using a macro.

skan added inline comments.Mar 17 2022, 5:24 PM
llvm/utils/TableGen/SubtargetEmitter.cpp
1817

IMO these functions should be renamed to make it clear they do more than just check a feature field.

It loses the flexibility.

skan added a comment.Mar 17 2022, 7:44 PM

In summary, this solution is good for ARM, but is not generic enough. We have to deprecate some customized interfaces and find other workarounds for X86 and AMDGPU w/ this method.
D121768 provides a more flexible approach to allow developer customize the fields and interfaces, and handle the descriptions of features in a better way. Could we consider applying D121768 first and then reducing hand-written ARM codes in this patch?

I'm going to submit this, since it has been approved for a while and covers a decent subset of the features without invasive changes. We can keep discussing any future alterations in D121768.

This revision was landed with ongoing or failed builds.Mar 18 2022, 4:48 AM
This revision was automatically updated to reflect the committed changes.