This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Power ISA features for Semachecking
ClosedPublic

Authored by quinnp on Jul 6 2021, 10:22 AM.

Details

Summary

[NFC] This patch adds features for pwr7, pwr8, and pwr9 that can be
used for semachecking builtin functions that are only valid for certain
versions of ppc.

Diff Detail

Event Timeline

quinnp created this revision.Jul 6 2021, 10:22 AM
quinnp requested review of this revision.Jul 6 2021, 10:23 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 6 2021, 10:23 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
quinnp updated this revision to Diff 356774.Jul 6 2021, 10:27 AM

Updating pwr10 features to include previous features.

quinnp added reviewers: Restricted Project, nemanjai, stefanp.Jul 6 2021, 10:29 AM

Can you please add a test for this similar to clang/test/Driver/ppc-pcrel.cpp and other similar tests?
Also, I imagine this will produce some warnings from the back end since the back end doesn't know what these target features mean. Can you please see what happens when you try to compile something after this patch?

qiucf added a subscriber: qiucf.Jul 6 2021, 10:10 PM
qiucf added inline comments.
clang/lib/Basic/Targets/PPC.cpp
452

Will it be better if name to isa2_07, isa3_0 to make it less confusing?

Besides, in backend we have subtarget features isa-v30-instructions and isa-v31-instructions but they're not present at frontend, we should pass these feature flags to backend correctly.

quinnp updated this revision to Diff 357297.Jul 8 2021, 11:26 AM

Work in progress addressing review comments.

Herald added a project: Restricted Project. · View Herald TranscriptJul 8 2021, 11:26 AM
quinnp updated this revision to Diff 357604.Jul 9 2021, 12:48 PM

Feature is now working correctly.

quinnp updated this revision to Diff 357644.Jul 9 2021, 2:40 PM

Parameterizing the ppc builtin arch sema error.

This change is made assuming that the SemaFeatureCheck will be used by other builtins in the future. SemaFeatureCheck is commented to avoid an unused function error when building the compiler. SemaArchFeatureCheck can be used to semacheck builtins which require a minimum version of PPC and require a feature to be enabled.

nemanjai added inline comments.Jul 10 2021, 9:20 AM
clang/lib/Sema/SemaChecking.cpp
3277–3278

I don't think we need another function here. Simply passing a StringRef parameter to the other one that will have a default value of empty should suffice. Then if the parameter is non-empty, we push it into the diagnostic.
Something like:

if (!S.Context.getTargetInfo().hasFeature(FeatureToCheck)) {
  S.Diag(TheCall->getBeginLoc(), DiagID);
  if (!DiagArg.empty())
    Diag << DiagArg;
  Diag << TheCall->getSourceRange();
  return true;
}

(keep in mind that I don't know if I've adequately captured how DiagnosticBuilder works, but something along these lines should be possible). Then of course, the calls to this would be with "7" rather than 7.

quinnp updated this revision to Diff 357942.Jul 12 2021, 7:40 AM

Addressing some review comments.

quinnp marked an inline comment as done.Jul 12 2021, 7:42 AM
quinnp updated this revision to Diff 358004.Jul 12 2021, 11:21 AM

Adding tests for each of the features

quinnp edited the summary of this revision. (Show Details)Jul 12 2021, 11:23 AM
quinnp marked an inline comment as done.
lei added a subscriber: lei.Jul 12 2021, 11:37 AM
lei added inline comments.
clang/lib/Sema/SemaChecking.cpp
3279

may I suggest early exit instead?

if (S.Context.getTargetInfo().hasFeature(FeatureToCheck))
  return false;

if (DiagArg.empty()) 
  S.Diag(TheCall->getBeginLoc(), DiagID) << TheCall->getSourceRange();
else
  S.Diag(TheCall->getBeginLoc(), DiagID) << DiagArg << TheCall->getSourceRange();

return true;

The testing is a bit overkill. A single test case with run lines for -mcpu=pwr7-10 and a single prefix for each should suffice. For each prefix, just check for +/- for all the features you expect. The triples can be randomly distributed across the 4 run lines.
And yes, please use early exit as Lei pointed out.

quinnp updated this revision to Diff 358049.Jul 12 2021, 1:21 PM

Addressing review comments.

Using an early exit for SemaFeatureCheck and combining the 3 test cases into 1.

quinnp marked an inline comment as done.Jul 12 2021, 1:24 PM
nemanjai accepted this revision.Jul 12 2021, 2:31 PM

LGTM. Thanks.

This revision is now accepted and ready to land.Jul 12 2021, 2:31 PM
This revision was landed with ongoing or failed builds.Jul 13 2021, 8:54 AM
This revision was automatically updated to reflect the committed changes.