This is an archive of the discontinued LLVM Phabricator instance.

[RISCV] Refactor RVV Policy by structure
ClosedPublic

Authored by BeMg on Dec 13 2022, 9:49 PM.

Details

Summary

RVV intrinsic function has several policy variants.

Include TU, TA, TAMU, TAMA, TUMU, TUMA, MU, MA, TUM, TAM

Currently, the clang side enumerates these policies, but it's hard to add a new policy.

This patch use structure to replace the origin policy enumeration, and enhance some policy transform logic.

This is a clean-up job that will not affect the RVV intrinsic functionality and make sure riscv_vector_builtin_cg.inc is the same as the original one.

Diff Detail

Event Timeline

BeMg created this revision.Dec 13 2022, 9:49 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 13 2022, 9:49 PM
BeMg requested review of this revision.Dec 13 2022, 9:49 PM
BeMg edited the summary of this revision. (Show Details)Dec 13 2022, 9:50 PM
craig.topper added inline comments.Dec 14 2022, 10:30 AM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
105

You can unify the two constructors by adding = false after _IntrinsicWithoutMU

133

This is missing IntrinsicWithoutMU

140

Does this need to include PolicyNone and IntrinsicWithoutMU?

clang/lib/Sema/SemaRISCVVectorLookup.cpp
211

Use emplace_back

clang/utils/TableGen/RISCVVEmitter.cpp
531

emplace_back

BeMg updated this revision to Diff 483068.Dec 14 2022, 7:01 PM
  1. Update policy constructor
  2. use emplace_back
  3. Fix miss WithoutIntrinsicMU in policy equal check
BeMg added inline comments.Dec 14 2022, 7:05 PM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
140

In updateNamesAndPolicy, Policy will be reduce as follow

PolicyNone -> TUMU or TA or TU according to function argument
TUM -> TUMA
TAM -> TAMA
MU -> TAMU
MA -> TAMA

For comparing the order of Policy, (PolicyNone TUM TAM MU MA) doesn't matter.

BeMg added inline comments.Dec 14 2022, 7:06 PM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
105

Done

133

Done.

clang/lib/Sema/SemaRISCVVectorLookup.cpp
211

Done

clang/utils/TableGen/RISCVVEmitter.cpp
531

Done

craig.topper added inline comments.Dec 14 2022, 9:35 PM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
141

You can remove this->

clang/lib/Sema/SemaRISCVVectorLookup.cpp
211

I suggested emplace_back because it allows you to remove Policy(

craig.topper added inline comments.Dec 14 2022, 9:41 PM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
131

You can drop this->

397

= Policy() is unnecessary.

BeMg updated this revision to Diff 483414.Dec 15 2022, 7:25 PM
  1. Remove this->
  2. Remove Policy() in struct declarationx
kito-cheng added inline comments.Dec 16 2022, 12:07 AM
clang/include/clang/Support/RISCVVIntrinsicUtils.h
100

Maybe use enum value for tail/mask policy? *U and *A are mutually exclusive, so
I feel they should just using same variables:

bool PolicyNone = false;
enum PolicyType {
  Undisturbed,
  Agnostic,
  Omit, // No policy required.
};

PolicyType TailPolicy = Omit;
PolicyType MastPolicy = Omit;
bool IntrinsicWithoutMU = false;
462

llvm_unreachable

clang/utils/TableGen/RISCVVEmitter.cpp
167–168

Use !RVVI->isTUPolicy() && !RVVI->isTUMUPolicy() instead of RVVI->getDefaultPolicyBits() != 0, that's kind of too magical predication.

BeMg updated this revision to Diff 483707.Dec 16 2022, 6:54 PM
  1. Use Undisturbed, Agnostic and Omit to represent Tail and Mask
  2. Replace getDefaultPolicyBits != 0 with !RVVI->isTUPolicy() && !RVVI->isTUMUPolicy()
  3. Use llvm_unreachable
This revision is now accepted and ready to land.Dec 18 2022, 10:39 PM
This revision was landed with ongoing or failed builds.Dec 20 2022, 1:20 AM
This revision was automatically updated to reflect the committed changes.