[clang] 6f0d0be - [5/15][Clang][RISCV][NFC] Remove extra attribute Policy::IntrinsicWithoutMU by reusing HasTailPolicy and HasMaskPolicy
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 24 00:10:53 PST 2023
Author: eopXD
Date: 2023-01-24T00:10:48-08:00
New Revision: 6f0d0be567e85747bf7525ea4ebf100968b7ec9d
URL: https://github.com/llvm/llvm-project/commit/6f0d0be567e85747bf7525ea4ebf100968b7ec9d
DIFF: https://github.com/llvm/llvm-project/commit/6f0d0be567e85747bf7525ea4ebf100968b7ec9d.diff
LOG: [5/15][Clang][RISCV][NFC] Remove extra attribute Policy::IntrinsicWithoutMU by reusing HasTailPolicy and HasMaskPolicy
Righteously there shouldn't be any special cases here because
`HasTailPolicy` and `HasMaskPolicy` is able to express necessary cases.
This commit is a part of the step-by-step effort to remove
`Policy::Scheme::Omit`, which completely does not make sense in RVV 1.0
because an RVV instruction always executes with `vta` and `vma` set
to a certain value.
This is the 5th 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.
Reviewed By: craig.topper, kito-cheng
Differential Revision: https://reviews.llvm.org/D141754
Added:
Modified:
clang/include/clang/Support/RISCVVIntrinsicUtils.h
clang/lib/Sema/SemaRISCVVectorLookup.cpp
clang/lib/Support/RISCVVIntrinsicUtils.cpp
clang/utils/TableGen/RISCVVEmitter.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Support/RISCVVIntrinsicUtils.h b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
index 425784b4b6fd3..dc5323062ed43 100644
--- a/clang/include/clang/Support/RISCVVIntrinsicUtils.h
+++ b/clang/include/clang/Support/RISCVVIntrinsicUtils.h
@@ -101,12 +101,14 @@ struct Policy {
};
PolicyType TailPolicy = Omit;
PolicyType MaskPolicy = Omit;
- bool IntrinsicWithoutMU = false;
- Policy() : IsUnspecified(true) {}
- Policy(PolicyType _TailPolicy, PolicyType _MaskPolicy,
- bool _IntrinsicWithoutMU = false)
- : TailPolicy(_TailPolicy), MaskPolicy(_MaskPolicy),
- IntrinsicWithoutMU(_IntrinsicWithoutMU) {}
+ bool HasTailPolicy, HasMaskPolicy;
+ Policy(bool HasTailPolicy, bool HasMaskPolicy)
+ : IsUnspecified(true), HasTailPolicy(HasTailPolicy),
+ HasMaskPolicy(HasMaskPolicy) {}
+ Policy(PolicyType TailPolicy, PolicyType MaskPolicy, bool HasTailPolicy,
+ bool HasMaskPolicy)
+ : TailPolicy(TailPolicy), MaskPolicy(MaskPolicy),
+ HasTailPolicy(HasTailPolicy), HasMaskPolicy(HasMaskPolicy) {}
bool isTAMAPolicy() const {
return TailPolicy == Agnostic && MaskPolicy == Agnostic;
@@ -124,16 +126,6 @@ struct Policy {
return TailPolicy == Undisturbed && MaskPolicy == Undisturbed;
}
- bool isTUMPolicy() const {
- return TailPolicy == Undisturbed && MaskPolicy == Agnostic &&
- IntrinsicWithoutMU;
- }
-
- bool isTAMPolicy() const {
- return TailPolicy == Agnostic && MaskPolicy == Agnostic &&
- IntrinsicWithoutMU;
- }
-
bool isTAPolicy() const {
return TailPolicy == Agnostic && MaskPolicy == Omit;
}
@@ -150,12 +142,17 @@ struct Policy {
return MaskPolicy == Undisturbed && TailPolicy == Omit;
}
+ bool hasTailPolicy() const { return HasTailPolicy; }
+
+ bool hasMaskPolicy() const { return HasMaskPolicy; }
+
bool isUnspecified() const { return IsUnspecified; }
bool operator==(const Policy &Other) const {
return IsUnspecified == Other.IsUnspecified &&
TailPolicy == Other.TailPolicy && MaskPolicy == Other.MaskPolicy &&
- IntrinsicWithoutMU == Other.IntrinsicWithoutMU;
+ HasTailPolicy == Other.HasTailPolicy &&
+ HasMaskPolicy == Other.HasMaskPolicy;
}
bool operator!=(const Policy &Other) const { return !(*this == Other); }
@@ -473,7 +470,8 @@ class RVVIntrinsic {
unsigned NF, PolicyScheme DefaultScheme,
Policy PolicyAttrs);
- static llvm::SmallVector<Policy> getSupportedUnMaskedPolicies();
+ static llvm::SmallVector<Policy>
+ getSupportedUnMaskedPolicies(bool HasTailPolicy, bool HasMaskPolicy);
static llvm::SmallVector<Policy>
getSupportedMaskedPolicies(bool HasTailPolicy, bool HasMaskPolicy);
diff --git a/clang/lib/Sema/SemaRISCVVectorLookup.cpp b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
index 8dab3991db4da..7716dfb15458a 100644
--- a/clang/lib/Sema/SemaRISCVVectorLookup.cpp
+++ b/clang/lib/Sema/SemaRISCVVectorLookup.cpp
@@ -192,21 +192,24 @@ void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
PolicyScheme MaskedPolicyScheme =
static_cast<PolicyScheme>(Record.MaskedPolicyScheme);
+ const Policy DefaultPolicy(Record.HasTailPolicy, Record.HasMaskPolicy);
+
llvm::SmallVector<PrototypeDescriptor> ProtoSeq =
RVVIntrinsic::computeBuiltinTypes(BasicProtoSeq, /*IsMasked=*/false,
/*HasMaskedOffOperand=*/false,
Record.HasVL, Record.NF,
- UnMaskedPolicyScheme, Policy());
+ UnMaskedPolicyScheme, DefaultPolicy);
llvm::SmallVector<PrototypeDescriptor> ProtoMaskSeq =
RVVIntrinsic::computeBuiltinTypes(
BasicProtoSeq, /*IsMasked=*/true, Record.HasMaskedOffOperand,
- Record.HasVL, Record.NF, MaskedPolicyScheme, Policy());
+ Record.HasVL, Record.NF, MaskedPolicyScheme, DefaultPolicy);
bool UnMaskedHasPolicy = UnMaskedPolicyScheme != PolicyScheme::SchemeNone;
bool MaskedHasPolicy = MaskedPolicyScheme != PolicyScheme::SchemeNone;
SmallVector<Policy> SupportedUnMaskedPolicies =
- RVVIntrinsic::getSupportedUnMaskedPolicies();
+ RVVIntrinsic::getSupportedUnMaskedPolicies(Record.HasTailPolicy,
+ Record.HasMaskPolicy);
SmallVector<Policy> SupportedMaskedPolicies =
RVVIntrinsic::getSupportedMaskedPolicies(Record.HasTailPolicy,
Record.HasMaskPolicy);
@@ -259,7 +262,7 @@ void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
// Create non-masked intrinsic.
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr, false, *Types,
- UnMaskedHasPolicy, Policy());
+ UnMaskedHasPolicy, DefaultPolicy);
// Create non-masked policy intrinsic.
if (Record.UnMaskedPolicyScheme != PolicyScheme::SchemeNone) {
@@ -282,7 +285,7 @@ void RISCVIntrinsicManagerImpl::InitIntrinsicList() {
std::optional<RVVTypes> MaskTypes =
TypeCache.computeTypes(BaseType, Log2LMUL, Record.NF, ProtoMaskSeq);
InitRVVIntrinsic(Record, SuffixStr, OverloadedSuffixStr, true,
- *MaskTypes, MaskedHasPolicy, Policy());
+ *MaskTypes, MaskedHasPolicy, DefaultPolicy);
if (Record.MaskedPolicyScheme == PolicyScheme::SchemeNone)
continue;
// Create masked policy intrinsic.
diff --git a/clang/lib/Support/RISCVVIntrinsicUtils.cpp b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
index d67221ee942c8..280fd3f8669a2 100644
--- a/clang/lib/Support/RISCVVIntrinsicUtils.cpp
+++ b/clang/lib/Support/RISCVVIntrinsicUtils.cpp
@@ -969,34 +969,39 @@ llvm::SmallVector<PrototypeDescriptor> RVVIntrinsic::computeBuiltinTypes(
return NewPrototype;
}
-llvm::SmallVector<Policy> RVVIntrinsic::getSupportedUnMaskedPolicies() {
- return {
- Policy(Policy::PolicyType::Undisturbed, Policy::PolicyType::Omit), // TU
- Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Omit)}; // TA
+llvm::SmallVector<Policy>
+RVVIntrinsic::getSupportedUnMaskedPolicies(bool HasTailPolicy,
+ bool HasMaskPolicy) {
+ return {Policy(Policy::PolicyType::Undisturbed, Policy::PolicyType::Omit,
+ HasTailPolicy, HasMaskPolicy), // TU
+ Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Omit,
+ HasTailPolicy, HasMaskPolicy)}; // TA
}
llvm::SmallVector<Policy>
RVVIntrinsic::getSupportedMaskedPolicies(bool HasTailPolicy,
bool HasMaskPolicy) {
if (HasTailPolicy && HasMaskPolicy)
- return {Policy(Policy::PolicyType::Undisturbed,
- Policy::PolicyType::Agnostic), // TUMA
- Policy(Policy::PolicyType::Agnostic,
- Policy::PolicyType::Agnostic), // TAMA
- Policy(Policy::PolicyType::Undisturbed,
- Policy::PolicyType::Undisturbed), // TUMU
- Policy(Policy::PolicyType::Agnostic,
- Policy::PolicyType::Undisturbed)}; // TAMU
+ return {
+ Policy(Policy::PolicyType::Undisturbed, Policy::PolicyType::Agnostic,
+ HasTailPolicy, HasMaskPolicy), // TUMA
+ Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Agnostic,
+ HasTailPolicy, HasMaskPolicy), // TAMA
+ Policy(Policy::PolicyType::Undisturbed, Policy::PolicyType::Undisturbed,
+ HasTailPolicy, HasMaskPolicy), // TUMU
+ Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Undisturbed,
+ HasTailPolicy, HasMaskPolicy)}; // TAMU
if (HasTailPolicy && !HasMaskPolicy)
return {Policy(Policy::PolicyType::Undisturbed,
- Policy::PolicyType::Agnostic, true), // TUM
+ Policy::PolicyType::Agnostic, HasTailPolicy,
+ HasMaskPolicy), // TUM
Policy(Policy::PolicyType::Agnostic, Policy::PolicyType::Agnostic,
- true)}; // TAM
+ HasTailPolicy, HasMaskPolicy)}; // TAM
if (!HasTailPolicy && HasMaskPolicy)
- return {
- Policy(Policy::PolicyType::Omit, Policy::PolicyType::Agnostic), // MA
- Policy(Policy::PolicyType::Omit,
- Policy::PolicyType::Undisturbed)}; // MU
+ return {Policy(Policy::PolicyType::Omit, Policy::PolicyType::Agnostic,
+ HasTailPolicy, HasMaskPolicy), // MA
+ Policy(Policy::PolicyType::Omit, Policy::PolicyType::Undisturbed,
+ HasTailPolicy, HasMaskPolicy)}; // MU
llvm_unreachable("An RVV instruction should not be without both tail policy "
"and mask policy");
}
@@ -1031,9 +1036,9 @@ void RVVIntrinsic::updateNamesAndPolicy(bool IsMasked, bool HasPolicy,
BuiltinName += "_ta";
}
} else {
- if (PolicyAttrs.isTUMPolicy())
+ if (PolicyAttrs.isTUMAPolicy() && !PolicyAttrs.hasMaskPolicy())
appendPolicySuffix("_tum");
- else if (PolicyAttrs.isTAMPolicy())
+ else if (PolicyAttrs.isTAMAPolicy() && !PolicyAttrs.hasMaskPolicy())
appendPolicySuffix("_tam");
else if (PolicyAttrs.isTUMUPolicy())
appendPolicySuffix("_tumu");
@@ -1043,17 +1048,18 @@ void RVVIntrinsic::updateNamesAndPolicy(bool IsMasked, bool HasPolicy,
appendPolicySuffix("_tuma");
else if (PolicyAttrs.isTAMAPolicy())
appendPolicySuffix("_tama");
- else if (PolicyAttrs.isTUPolicy())
+ else if (PolicyAttrs.isTUPolicy() && !IsMasked)
appendPolicySuffix("_tu");
- else if (PolicyAttrs.isTAPolicy())
+ else if (PolicyAttrs.isTAPolicy() && !IsMasked)
appendPolicySuffix("_ta");
- else if (PolicyAttrs.isMUPolicy()) {
+ else if (PolicyAttrs.isMUPolicy() && !PolicyAttrs.hasTailPolicy()) {
appendPolicySuffix("_mu");
PolicyAttrs.TailPolicy = Policy::PolicyType::Agnostic;
- } else if (PolicyAttrs.isMAPolicy()) {
+ } else if (PolicyAttrs.isMAPolicy() && !PolicyAttrs.hasTailPolicy()) {
appendPolicySuffix("_ma");
PolicyAttrs.TailPolicy = Policy::PolicyType::Agnostic;
- }
+ } else
+ llvm_unreachable("Unhandled policy condition");
}
}
diff --git a/clang/utils/TableGen/RISCVVEmitter.cpp b/clang/utils/TableGen/RISCVVEmitter.cpp
index eb9ec3e5bc0f7..59a250aa29c95 100644
--- a/clang/utils/TableGen/RISCVVEmitter.cpp
+++ b/clang/utils/TableGen/RISCVVEmitter.cpp
@@ -528,8 +528,10 @@ void RVVEmitter::createRVVIntrinsics(
StringRef MaskedIRName = R->getValueAsString("MaskedIRName");
unsigned NF = R->getValueAsInt("NF");
+ const Policy DefaultPolicy(HasTailPolicy, HasMaskPolicy);
SmallVector<Policy> SupportedUnMaskedPolicies =
- RVVIntrinsic::getSupportedUnMaskedPolicies();
+ RVVIntrinsic::getSupportedUnMaskedPolicies(HasTailPolicy,
+ HasMaskPolicy);
SmallVector<Policy> SupportedMaskedPolicies =
RVVIntrinsic::getSupportedMaskedPolicies(HasTailPolicy, HasMaskPolicy);
@@ -543,13 +545,13 @@ void RVVEmitter::createRVVIntrinsics(
parsePrototypes(OverloadedSuffixProto);
// Compute Builtin types
- auto Prototype =
- RVVIntrinsic::computeBuiltinTypes(BasicPrototype, /*IsMasked=*/false,
- /*HasMaskedOffOperand=*/false, HasVL,
- NF, UnMaskedPolicyScheme, Policy());
+ auto Prototype = RVVIntrinsic::computeBuiltinTypes(
+ BasicPrototype, /*IsMasked=*/false,
+ /*HasMaskedOffOperand=*/false, HasVL, NF, UnMaskedPolicyScheme,
+ DefaultPolicy);
auto MaskedPrototype = RVVIntrinsic::computeBuiltinTypes(
BasicPrototype, /*IsMasked=*/true, HasMaskedOffOperand, HasVL, NF,
- MaskedPolicyScheme, Policy());
+ MaskedPolicyScheme, DefaultPolicy);
// Create Intrinsics for each type and LMUL.
for (char I : TypeRange) {
@@ -571,7 +573,7 @@ void RVVEmitter::createRVVIntrinsics(
/*IsMasked=*/false, /*HasMaskedOffOperand=*/false, HasVL,
UnMaskedPolicyScheme, SupportOverloading, HasBuiltinAlias,
ManualCodegen, *Types, IntrinsicTypes, RequiredFeatures, NF,
- Policy()));
+ DefaultPolicy));
if (UnMaskedPolicyScheme != PolicyScheme::SchemeNone)
for (auto P : SupportedUnMaskedPolicies) {
SmallVector<PrototypeDescriptor> PolicyPrototype =
@@ -597,7 +599,7 @@ void RVVEmitter::createRVVIntrinsics(
Name, SuffixStr, OverloadedName, OverloadedSuffixStr, MaskedIRName,
/*IsMasked=*/true, HasMaskedOffOperand, HasVL, MaskedPolicyScheme,
SupportOverloading, HasBuiltinAlias, ManualCodegen, *MaskTypes,
- IntrinsicTypes, RequiredFeatures, NF, Policy()));
+ IntrinsicTypes, RequiredFeatures, NF, DefaultPolicy));
if (MaskedPolicyScheme == PolicyScheme::SchemeNone)
continue;
for (auto P : SupportedMaskedPolicies) {
More information about the cfe-commits
mailing list