This is an archive of the discontinued LLVM Phabricator instance.

[11/15][Clang][RISCV][NFC] Remove Policy::PolicyType::Omit
ClosedPublic

Authored by eopXD on Jan 14 2023, 8:09 AM.

Details

Summary

The attribute can be removed now as preceding patches have removed its
users.

This is the 11th commit of a patch-set that aims to change the default policy
for RVV intrinsics from TAMU to TAMA.

Please refer to the cover letter in the 1st commit (D141573) for an
overview.

Diff Detail

Event Timeline

eopXD created this revision.Jan 14 2023, 8:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 14 2023, 8:09 AM
eopXD requested review of this revision.Jan 14 2023, 8:09 AM
eopXD updated this revision to Diff 489298.Jan 14 2023, 11:19 AM

Rebase to latset main.

eopXD updated this revision to Diff 489306.Jan 14 2023, 11:27 AM

Bump CI.

eopXD retitled this revision from [WIP][11/N][Clang][RISCV][NFC] Remove Policy::PolicyType::Omit to [11/15][Clang][RISCV][NFC] Remove Policy::PolicyType::Omit.Jan 15 2023, 7:54 AM
eopXD edited the summary of this revision. (Show Details)
This revision is now accepted and ready to land.Jan 16 2023, 11:40 PM
craig.topper added inline comments.Jan 17 2023, 4:43 PM
clang/lib/Support/RISCVVIntrinsicUtils.cpp
1038

If you hadn't just removed Omit, it somewhat feels like Omit should be part of Policy and this code to pick the policy suffix string should be inside the Policy class. But I'll defer to your judgement.

eopXD added inline comments.Jan 18 2023, 2:40 AM
clang/lib/Support/RISCVVIntrinsicUtils.cpp
1038

Good idea, I will encapsulate logics into Policy. Considering the next patch-set, to simplify the policy suffixes, IsUnspecified can be further removed. Eventually we can have something like:

void RVVIntrinsic::updateNamesAndPolicy(bool IsMasked, bool HasPolicy,
                                        std::string &Name,
                                        std::string &BuiltinName,
                                        std::string &OverloadedName,
                                        Policy &PolicyAttrs) {
  std::string PolicySuffix =
    PolicyAttrs.getPolicySuffix(IsMasked, HasPolicy);
  Name += PolicySuffix;
  BuiltinName += PolicySuffix;
  OverloadedName += PolicySuffix;
}

I will create a separate revision so we won't be distracted towards the goal of this patch-set.


On the other hand, here is my thought process when considering the removal of Omit as a legit refactoring.

Logics to deal with Omit occurs under here (updateNamesAndPolicy), computeBuiltinTypes, and getPolicyAttrs. The Omit state specified to a Policy implies it has to be corrected to something specific (either Agnostic or Undisturbed) before calling getPolicyAttrs, which will set the values in riscv_vector_cg (called under RISCVVEmitter.cpp. This blocks the possibility of setting TailPolicy, MaskPolicy as constant members.

I picked HasTailPolicy and HasMaskPolicy for the predicates because it was exactly how riscv_vector.td defined the intrinsics. They are necessary as conditions now with the current policy suffix naming rules. With the next patch-set, HasTailPolicy and HasMaskPolicy will only be called by getSupportedUnMaskedPolicies and getSupportedMaskedPolicies. This is because the policy suffix logics here can be simplified to something like: (this does not contradict with the encapsulating topic above)

if (PolicyAttrs.isUnspecified()) {
  if (IsMasked) {
    Name += "_m";
    if (HasPolicy)
      BuiltinName += "_tama";
    else
      BuiltinName += "_m";
  } else {
    if (HasPolicy)
      BuiltinName += "_ta";
  }
} else {
  if (IsMasked) {
    if (PolicyAttrs.isTAMUPolicy())
      appendPolicySuffix("_mu")
    else if (PolicyAttrs.isTUMAPolicy())
      appendPolicySuffix("_tum")
    else if (PolicyAttrs.isTUMUPolicy())
      appendPolicySuffix("_tumu")
    else
      llvm_unreachable("Unhandled policy condition");
  } else {
    if (PolicyAttrs.isTUPolicy())
      appendPolicySuffix("_tu");
    else
      llvm_unreachable("Unhandled policy condition");
  }
}
eopXD updated this revision to Diff 491805.Jan 24 2023, 7:59 AM
eopXD edited the summary of this revision. (Show Details)

Rebase to latest main.

This revision was landed with ongoing or failed builds.Jan 24 2023, 8:13 AM
This revision was automatically updated to reflect the committed changes.