[clang] [RISCV][NFC] Move some common class/multiclass from riscv_vector.td to riscv_vector_common.td (PR #67587)
Brandon Wu via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 27 11:34:33 PDT 2023
https://github.com/4vtomat created https://github.com/llvm/llvm-project/pull/67587
Since there are more vendor extensions that needs to implement
custom intrinsics, it's useful to move some common usages to
riscv_vector_common.td.
>From 6f3575b70438a0529bd2505ccf55a87cca3eeefd Mon Sep 17 00:00:00 2001
From: Brandon Wu <brandon.wu at sifive.com>
Date: Wed, 27 Sep 2023 11:31:28 -0700
Subject: [PATCH] [RISCV][NFC] Move some common class/multiclass from
riscv_vector.td to riscv_vector_common.td
Since there are more vendor extensions that needs to implement
custom intrinsics, it's useful to move some common usages to
riscv_vector_common.td.
---
clang/include/clang/Basic/riscv_vector.td | 460 ------------------
.../clang/Basic/riscv_vector_common.td | 460 ++++++++++++++++++
2 files changed, 460 insertions(+), 460 deletions(-)
diff --git a/clang/include/clang/Basic/riscv_vector.td b/clang/include/clang/Basic/riscv_vector.td
index 60a1a2b2be6fb40..c685f3ef6087d81 100644
--- a/clang/include/clang/Basic/riscv_vector.td
+++ b/clang/include/clang/Basic/riscv_vector.td
@@ -14,466 +14,6 @@
include "riscv_vector_common.td"
-//===----------------------------------------------------------------------===//
-// Basic classes with automatic codegen.
-//===----------------------------------------------------------------------===//
-
-class RVVOutBuiltin<string suffix, string prototype, string type_range>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IntrinsicTypes = [-1];
-}
-
-class RVVOp0Builtin<string suffix, string prototype, string type_range>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IntrinsicTypes = [0];
-}
-
-class RVVOutOp1Builtin<string suffix, string prototype, string type_range>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IntrinsicTypes = [-1, 1];
-}
-
-class RVVOutOp0Op1Builtin<string suffix, string prototype, string type_range>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IntrinsicTypes = [-1, 0, 1];
-}
-
-multiclass RVVBuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes,
- list<int> intrinsic_types> {
- let IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask",
- IntrinsicTypes = intrinsic_types in {
- foreach s_p = suffixes_prototypes in {
- let Name = NAME # "_" # s_p[0] in {
- defvar suffix = s_p[1];
- defvar prototype = s_p[2];
- def : RVVBuiltin<suffix, prototype, type_range>;
- }
- }
- }
-}
-
-// IntrinsicTypes is output, op0, op1 [-1, 0, 1]
-multiclass RVVOutOp0Op1BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes,
- [-1, 0, 1]>;
-
-multiclass RVVOutBuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1]>;
-
-multiclass RVVOp0BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [0]>;
-
-// IntrinsicTypes is output, op1 [-1, 0]
-multiclass RVVOutOp0BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 0]>;
-
-// IntrinsicTypes is output, op1 [-1, 1]
-multiclass RVVOutOp1BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1]>;
-
-multiclass RVVOp0Op1BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [0, 1]>;
-
-multiclass RVVOutOp1Op2BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1, 2]>;
-
-// IntrinsicTypes is output, op2 [-1, 2]
-multiclass RVVOutOp2BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes>
- : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 2]>;
-
-multiclass RVVSignedBinBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "v", "vvv"],
- ["vx", "v", "vve"]]>;
-
-multiclass RVVSignedBinBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "v", "vvvu"],
- ["vx", "v", "vveu"]]>;
-
-multiclass RVVUnsignedBinBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "Uv", "UvUvUv"],
- ["vx", "Uv", "UvUvUe"]]>;
-
-multiclass RVVUnsignedBinBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "Uv", "UvUvUvu"],
- ["vx", "Uv", "UvUvUeu"]]>;
-
-multiclass RVVIntBinBuiltinSet
- : RVVSignedBinBuiltinSet,
- RVVUnsignedBinBuiltinSet;
-
-multiclass RVVInt64BinBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "l",
- [["vv", "v", "vvv"],
- ["vx", "v", "vve"]]>,
- RVVOutOp1BuiltinSet<NAME, "l",
- [["vv", "Uv", "UvUvUv"],
- ["vx", "Uv", "UvUvUe"]]>;
-
-multiclass RVVSlideOneBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vx", "v", "vve"],
- ["vx", "Uv", "UvUvUe"]]>;
-
-multiclass RVVSignedShiftBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "v", "vvUv"],
- ["vx", "v", "vvz"]]>;
-
-multiclass RVVSignedShiftBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "v", "vvUvu"],
- ["vx", "v", "vvzu"]]>;
-
-multiclass RVVUnsignedShiftBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "Uv", "UvUvUv"],
- ["vx", "Uv", "UvUvz"]]>;
-
-multiclass RVVUnsignedShiftBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "Uv", "UvUvUvu"],
- ["vx", "Uv", "UvUvzu"]]>;
-
-multiclass RVVShiftBuiltinSet
- : RVVSignedShiftBuiltinSet,
- RVVUnsignedShiftBuiltinSet;
-
-let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
- multiclass RVVSignedNShiftBuiltinSet
- : RVVOutOp0Op1BuiltinSet<NAME, "csil",
- [["wv", "v", "vwUv"],
- ["wx", "v", "vwz"]]>;
-
- multiclass RVVSignedNShiftBuiltinSetRoundingMode
- : RVVOutOp0Op1BuiltinSet<NAME, "csil",
- [["wv", "v", "vwUvu"],
- ["wx", "v", "vwzu"]]>;
-
- multiclass RVVUnsignedNShiftBuiltinSet
- : RVVOutOp0Op1BuiltinSet<NAME, "csil",
- [["wv", "Uv", "UvUwUv"],
- ["wx", "Uv", "UvUwz"]]>;
-
- multiclass RVVUnsignedNShiftBuiltinSetRoundingMode
- : RVVOutOp0Op1BuiltinSet<NAME, "csil",
- [["wv", "Uv", "UvUwUvu"],
- ["wx", "Uv", "UvUwzu"]]>;
-
-}
-
-multiclass RVVCarryinBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vvm", "v", "vvvm"],
- ["vxm", "v", "vvem"],
- ["vvm", "Uv", "UvUvUvm"],
- ["vxm", "Uv", "UvUvUem"]]>;
-
-multiclass RVVCarryOutInBuiltinSet<string intrinsic_name>
- : RVVOp0Op1BuiltinSet<intrinsic_name, "csil",
- [["vvm", "vm", "mvvm"],
- ["vxm", "vm", "mvem"],
- ["vvm", "Uvm", "mUvUvm"],
- ["vxm", "Uvm", "mUvUem"]]>;
-
-multiclass RVVSignedMaskOutBuiltinSet
- : RVVOp0Op1BuiltinSet<NAME, "csil",
- [["vv", "vm", "mvv"],
- ["vx", "vm", "mve"]]>;
-
-multiclass RVVUnsignedMaskOutBuiltinSet
- : RVVOp0Op1BuiltinSet<NAME, "csil",
- [["vv", "Uvm", "mUvUv"],
- ["vx", "Uvm", "mUvUe"]]>;
-
-multiclass RVVIntMaskOutBuiltinSet
- : RVVSignedMaskOutBuiltinSet,
- RVVUnsignedMaskOutBuiltinSet;
-
-class RVVIntExt<string intrinsic_name, string suffix, string prototype,
- string type_range>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IRName = intrinsic_name;
- let MaskedIRName = intrinsic_name # "_mask";
- let OverloadedName = NAME;
- let IntrinsicTypes = [-1, 0];
-}
-
-let HasMaskedOffOperand = false in {
- multiclass RVVIntTerBuiltinSet {
- defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
- [["vv", "v", "vvvv"],
- ["vx", "v", "vvev"],
- ["vv", "Uv", "UvUvUvUv"],
- ["vx", "Uv", "UvUvUeUv"]]>;
- }
- multiclass RVVFloatingTerBuiltinSet {
- defm "" : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vv", "v", "vvvv"],
- ["vf", "v", "vvev"]]>;
- }
- multiclass RVVFloatingTerBuiltinSetRoundingMode {
- defm "" : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vv", "v", "vvvvu"],
- ["vf", "v", "vvevu"]]>;
- }
-}
-
-let HasMaskedOffOperand = false, Log2LMUL = [-2, -1, 0, 1, 2] in {
- multiclass RVVFloatingWidenTerBuiltinSet {
- defm "" : RVVOutOp1Op2BuiltinSet<NAME, "xf",
- [["vv", "w", "wwvv"],
- ["vf", "w", "wwev"]]>;
- }
- multiclass RVVFloatingWidenTerBuiltinSetRoundingMode {
- defm "" : RVVOutOp1Op2BuiltinSet<NAME, "xf",
- [["vv", "w", "wwvvu"],
- ["vf", "w", "wwevu"]]>;
- }
-}
-
-multiclass RVVFloatingBinBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vv", "v", "vvv"],
- ["vf", "v", "vve"]]>;
-
-multiclass RVVFloatingBinBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vv", "v", "vvvu"],
- ["vf", "v", "vveu"]]>;
-
-multiclass RVVFloatingBinVFBuiltinSet
- : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vf", "v", "vve"]]>;
-
-multiclass RVVFloatingBinVFBuiltinSetRoundingMode
- : RVVOutOp1BuiltinSet<NAME, "xfd",
- [["vf", "v", "vveu"]]>;
-
-multiclass RVVFloatingMaskOutBuiltinSet
- : RVVOp0Op1BuiltinSet<NAME, "xfd",
- [["vv", "vm", "mvv"],
- ["vf", "vm", "mve"]]>;
-
-multiclass RVVFloatingMaskOutVFBuiltinSet
- : RVVOp0Op1BuiltinSet<NAME, "fd",
- [["vf", "vm", "mve"]]>;
-
-multiclass RVVConvBuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes> {
-let Name = intrinsic_name,
- IRName = intrinsic_name,
- MaskedIRName = intrinsic_name # "_mask",
- IntrinsicTypes = [-1, 0] in {
- foreach s_p = suffixes_prototypes in {
- defvar suffix = s_p[0];
- defvar prototype = s_p[1];
- def : RVVBuiltin<suffix, prototype, type_range>;
- }
- }
-}
-
-
-class RVVMaskBinBuiltin : RVVOutBuiltin<"m", "mmm", "c"> {
- let Name = NAME # "_mm";
- let HasMasked = false;
-}
-
-class RVVMaskUnaryBuiltin : RVVOutBuiltin<"m", "mm", "c"> {
- let Name = NAME # "_m";
-}
-
-class RVVMaskNullaryBuiltin : RVVOutBuiltin<"m", "m", "c"> {
- let Name = NAME # "_m";
- let HasMasked = false;
- let SupportOverloading = false;
-}
-
-class RVVMaskOp0Builtin<string prototype> : RVVOp0Builtin<"m", prototype, "c"> {
- let Name = NAME # "_m";
- let HasMaskedOffOperand = false;
-}
-
-let UnMaskedPolicyScheme = HasPolicyOperand,
- HasMaskedOffOperand = false in {
- multiclass RVVSlideUpBuiltinSet {
- defm "" : RVVOutBuiltinSet<NAME, "csilxfd",
- [["vx","v", "vvvz"]]>;
- defm "" : RVVOutBuiltinSet<NAME, "csil",
- [["vx","Uv", "UvUvUvz"]]>;
- }
-}
-
-let UnMaskedPolicyScheme = HasPassthruOperand,
- ManualCodegen = [{
- if (IsMasked) {
- std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
- if ((PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA))
- Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
- } else {
- if (PolicyAttrs & RVV_VTA)
- Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
- }
-
- Ops.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
- IntrinsicTypes = {ResultType, Ops.back()->getType()};
- }] in {
- multiclass RVVSlideDownBuiltinSet {
- defm "" : RVVOutBuiltinSet<NAME, "csilxfd",
- [["vx","v", "vvz"]]>;
- defm "" : RVVOutBuiltinSet<NAME, "csil",
- [["vx","Uv", "UvUvz"]]>;
- }
-}
-
-class RVVFloatingUnaryBuiltin<string builtin_suffix, string ir_suffix,
- string prototype>
- : RVVOutBuiltin<ir_suffix, prototype, "xfd"> {
- let Name = NAME # "_" # builtin_suffix;
-}
-
-class RVVFloatingUnaryVVBuiltin : RVVFloatingUnaryBuiltin<"v", "v", "vv">;
-
-class RVVConvBuiltin<string suffix, string prototype, string type_range,
- string overloaded_name>
- : RVVBuiltin<suffix, prototype, type_range> {
- let IntrinsicTypes = [-1, 0];
- let OverloadedName = overloaded_name;
-}
-
-class RVVConvToSignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Iv", "Ivv", "xfd", overloaded_name>;
-
-class RVVConvToUnsignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Uv", "Uvv", "xfd", overloaded_name>;
-
-class RVVConvToWidenSignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Iw", "Iwv", "xf", overloaded_name>;
-
-class RVVConvToWidenUnsignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Uw", "Uwv", "xf", overloaded_name>;
-
-class RVVConvToNarrowingSignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Iv", "IvFw", "csi", overloaded_name>;
-
-class RVVConvToNarrowingUnsignedBuiltin<string overloaded_name>
- : RVVConvBuiltin<"Uv", "UvFw", "csi", overloaded_name>;
-
-let HasMaskedOffOperand = true in {
- multiclass RVVSignedReductionBuiltin {
- defm "" : RVVOutOp0BuiltinSet<NAME, "csil",
- [["vs", "vSv", "SvvSv"]]>;
- }
- multiclass RVVUnsignedReductionBuiltin {
- defm "" : RVVOutOp0BuiltinSet<NAME, "csil",
- [["vs", "UvUSv", "USvUvUSv"]]>;
- }
- multiclass RVVFloatingReductionBuiltin {
- defm "" : RVVOutOp0BuiltinSet<NAME, "xfd",
- [["vs", "vSv", "SvvSv"]]>;
- }
- multiclass RVVFloatingReductionBuiltinRoundingMode {
- defm "" : RVVOutOp0BuiltinSet<NAME, "xfd",
- [["vs", "vSv", "SvvSvu"]]>;
- }
- multiclass RVVFloatingWidenReductionBuiltin {
- defm "" : RVVOutOp0BuiltinSet<NAME, "xf",
- [["vs", "vSw", "SwvSw"]]>;
- }
- multiclass RVVFloatingWidenReductionBuiltinRoundingMode {
- defm "" : RVVOutOp0BuiltinSet<NAME, "xf",
- [["vs", "vSw", "SwvSwu"]]>;
- }
-}
-
-multiclass RVVIntReductionBuiltinSet
- : RVVSignedReductionBuiltin,
- RVVUnsignedReductionBuiltin;
-
-// For widen operation which has different mangling name.
-multiclass RVVWidenBuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes> {
- let Log2LMUL = [-3, -2, -1, 0, 1, 2],
- IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask" in {
- foreach s_p = suffixes_prototypes in {
- let Name = NAME # "_" # s_p[0],
- OverloadedName = NAME # "_" # s_p[0] in {
- defvar suffix = s_p[1];
- defvar prototype = s_p[2];
- def : RVVOutOp0Op1Builtin<suffix, prototype, type_range>;
- }
- }
- }
-}
-
-// For widen operation with widen operand which has different mangling name.
-multiclass RVVWidenWOp0BuiltinSet<string intrinsic_name, string type_range,
- list<list<string>> suffixes_prototypes> {
- let Log2LMUL = [-3, -2, -1, 0, 1, 2],
- IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask" in {
- foreach s_p = suffixes_prototypes in {
- let Name = NAME # "_" # s_p[0],
- OverloadedName = NAME # "_" # s_p[0] in {
- defvar suffix = s_p[1];
- defvar prototype = s_p[2];
- def : RVVOutOp1Builtin<suffix, prototype, type_range>;
- }
- }
- }
-}
-
-multiclass RVVSignedWidenBinBuiltinSet
- : RVVWidenBuiltinSet<NAME, "csi",
- [["vv", "w", "wvv"],
- ["vx", "w", "wve"]]>;
-
-multiclass RVVSignedWidenOp0BinBuiltinSet
- : RVVWidenWOp0BuiltinSet<NAME # "_w", "csi",
- [["wv", "w", "wwv"],
- ["wx", "w", "wwe"]]>;
-
-multiclass RVVUnsignedWidenBinBuiltinSet
- : RVVWidenBuiltinSet<NAME, "csi",
- [["vv", "Uw", "UwUvUv"],
- ["vx", "Uw", "UwUvUe"]]>;
-
-multiclass RVVUnsignedWidenOp0BinBuiltinSet
- : RVVWidenWOp0BuiltinSet<NAME # "_w", "csi",
- [["wv", "Uw", "UwUwUv"],
- ["wx", "Uw", "UwUwUe"]]>;
-
-multiclass RVVFloatingWidenBinBuiltinSet
- : RVVWidenBuiltinSet<NAME, "xf",
- [["vv", "w", "wvv"],
- ["vf", "w", "wve"]]>;
-
-multiclass RVVFloatingWidenBinBuiltinSetRoundingMode
- : RVVWidenBuiltinSet<NAME, "xf",
- [["vv", "w", "wvvu"],
- ["vf", "w", "wveu"]]>;
-
-multiclass RVVFloatingWidenOp0BinBuiltinSet
- : RVVWidenWOp0BuiltinSet<NAME # "_w", "xf",
- [["wv", "w", "wwv"],
- ["wf", "w", "wwe"]]>;
-
-multiclass RVVFloatingWidenOp0BinBuiltinSetRoundingMode
- : RVVWidenWOp0BuiltinSet<NAME # "_w", "xf",
- [["wv", "w", "wwvu"],
- ["wf", "w", "wweu"]]>;
-
defvar TypeList = ["c","s","i","l","x","f","d"];
defvar EEWList = [["8", "(Log2EEW:3)"],
["16", "(Log2EEW:4)"],
diff --git a/clang/include/clang/Basic/riscv_vector_common.td b/clang/include/clang/Basic/riscv_vector_common.td
index 74d9ace212e1562..141fac9d68e6d54 100644
--- a/clang/include/clang/Basic/riscv_vector_common.td
+++ b/clang/include/clang/Basic/riscv_vector_common.td
@@ -249,3 +249,463 @@ class RVVBuiltin<string suffix, string prototype, string type_range,
class RVVHeader {
code HeaderCode;
}
+
+//===----------------------------------------------------------------------===//
+// Basic classes with automatic codegen.
+//===----------------------------------------------------------------------===//
+
+class RVVOutBuiltin<string suffix, string prototype, string type_range>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IntrinsicTypes = [-1];
+}
+
+class RVVOp0Builtin<string suffix, string prototype, string type_range>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IntrinsicTypes = [0];
+}
+
+class RVVOutOp1Builtin<string suffix, string prototype, string type_range>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IntrinsicTypes = [-1, 1];
+}
+
+class RVVOutOp0Op1Builtin<string suffix, string prototype, string type_range>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IntrinsicTypes = [-1, 0, 1];
+}
+
+multiclass RVVBuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes,
+ list<int> intrinsic_types> {
+ let IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask",
+ IntrinsicTypes = intrinsic_types in {
+ foreach s_p = suffixes_prototypes in {
+ let Name = NAME # "_" # s_p[0] in {
+ defvar suffix = s_p[1];
+ defvar prototype = s_p[2];
+ def : RVVBuiltin<suffix, prototype, type_range>;
+ }
+ }
+ }
+}
+
+// IntrinsicTypes is output, op0, op1 [-1, 0, 1]
+multiclass RVVOutOp0Op1BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes,
+ [-1, 0, 1]>;
+
+multiclass RVVOutBuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1]>;
+
+multiclass RVVOp0BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [0]>;
+
+// IntrinsicTypes is output, op1 [-1, 0]
+multiclass RVVOutOp0BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 0]>;
+
+// IntrinsicTypes is output, op1 [-1, 1]
+multiclass RVVOutOp1BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1]>;
+
+multiclass RVVOp0Op1BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [0, 1]>;
+
+multiclass RVVOutOp1Op2BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 1, 2]>;
+
+// IntrinsicTypes is output, op2 [-1, 2]
+multiclass RVVOutOp2BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes>
+ : RVVBuiltinSet<intrinsic_name, type_range, suffixes_prototypes, [-1, 2]>;
+
+multiclass RVVSignedBinBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "v", "vvv"],
+ ["vx", "v", "vve"]]>;
+
+multiclass RVVSignedBinBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "v", "vvvu"],
+ ["vx", "v", "vveu"]]>;
+
+multiclass RVVUnsignedBinBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "Uv", "UvUvUv"],
+ ["vx", "Uv", "UvUvUe"]]>;
+
+multiclass RVVUnsignedBinBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "Uv", "UvUvUvu"],
+ ["vx", "Uv", "UvUvUeu"]]>;
+
+multiclass RVVIntBinBuiltinSet
+ : RVVSignedBinBuiltinSet,
+ RVVUnsignedBinBuiltinSet;
+
+multiclass RVVInt64BinBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "l",
+ [["vv", "v", "vvv"],
+ ["vx", "v", "vve"]]>,
+ RVVOutOp1BuiltinSet<NAME, "l",
+ [["vv", "Uv", "UvUvUv"],
+ ["vx", "Uv", "UvUvUe"]]>;
+
+multiclass RVVSlideOneBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vx", "v", "vve"],
+ ["vx", "Uv", "UvUvUe"]]>;
+
+multiclass RVVSignedShiftBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "v", "vvUv"],
+ ["vx", "v", "vvz"]]>;
+
+multiclass RVVSignedShiftBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "v", "vvUvu"],
+ ["vx", "v", "vvzu"]]>;
+
+multiclass RVVUnsignedShiftBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "Uv", "UvUvUv"],
+ ["vx", "Uv", "UvUvz"]]>;
+
+multiclass RVVUnsignedShiftBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "Uv", "UvUvUvu"],
+ ["vx", "Uv", "UvUvzu"]]>;
+
+multiclass RVVShiftBuiltinSet
+ : RVVSignedShiftBuiltinSet,
+ RVVUnsignedShiftBuiltinSet;
+
+let Log2LMUL = [-3, -2, -1, 0, 1, 2] in {
+ multiclass RVVSignedNShiftBuiltinSet
+ : RVVOutOp0Op1BuiltinSet<NAME, "csil",
+ [["wv", "v", "vwUv"],
+ ["wx", "v", "vwz"]]>;
+
+ multiclass RVVSignedNShiftBuiltinSetRoundingMode
+ : RVVOutOp0Op1BuiltinSet<NAME, "csil",
+ [["wv", "v", "vwUvu"],
+ ["wx", "v", "vwzu"]]>;
+
+ multiclass RVVUnsignedNShiftBuiltinSet
+ : RVVOutOp0Op1BuiltinSet<NAME, "csil",
+ [["wv", "Uv", "UvUwUv"],
+ ["wx", "Uv", "UvUwz"]]>;
+
+ multiclass RVVUnsignedNShiftBuiltinSetRoundingMode
+ : RVVOutOp0Op1BuiltinSet<NAME, "csil",
+ [["wv", "Uv", "UvUwUvu"],
+ ["wx", "Uv", "UvUwzu"]]>;
+
+}
+
+multiclass RVVCarryinBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vvm", "v", "vvvm"],
+ ["vxm", "v", "vvem"],
+ ["vvm", "Uv", "UvUvUvm"],
+ ["vxm", "Uv", "UvUvUem"]]>;
+
+multiclass RVVCarryOutInBuiltinSet<string intrinsic_name>
+ : RVVOp0Op1BuiltinSet<intrinsic_name, "csil",
+ [["vvm", "vm", "mvvm"],
+ ["vxm", "vm", "mvem"],
+ ["vvm", "Uvm", "mUvUvm"],
+ ["vxm", "Uvm", "mUvUem"]]>;
+
+multiclass RVVSignedMaskOutBuiltinSet
+ : RVVOp0Op1BuiltinSet<NAME, "csil",
+ [["vv", "vm", "mvv"],
+ ["vx", "vm", "mve"]]>;
+
+multiclass RVVUnsignedMaskOutBuiltinSet
+ : RVVOp0Op1BuiltinSet<NAME, "csil",
+ [["vv", "Uvm", "mUvUv"],
+ ["vx", "Uvm", "mUvUe"]]>;
+
+multiclass RVVIntMaskOutBuiltinSet
+ : RVVSignedMaskOutBuiltinSet,
+ RVVUnsignedMaskOutBuiltinSet;
+
+class RVVIntExt<string intrinsic_name, string suffix, string prototype,
+ string type_range>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IRName = intrinsic_name;
+ let MaskedIRName = intrinsic_name # "_mask";
+ let OverloadedName = NAME;
+ let IntrinsicTypes = [-1, 0];
+}
+
+let HasMaskedOffOperand = false in {
+ multiclass RVVIntTerBuiltinSet {
+ defm "" : RVVOutOp1BuiltinSet<NAME, "csil",
+ [["vv", "v", "vvvv"],
+ ["vx", "v", "vvev"],
+ ["vv", "Uv", "UvUvUvUv"],
+ ["vx", "Uv", "UvUvUeUv"]]>;
+ }
+ multiclass RVVFloatingTerBuiltinSet {
+ defm "" : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vv", "v", "vvvv"],
+ ["vf", "v", "vvev"]]>;
+ }
+ multiclass RVVFloatingTerBuiltinSetRoundingMode {
+ defm "" : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vv", "v", "vvvvu"],
+ ["vf", "v", "vvevu"]]>;
+ }
+}
+
+let HasMaskedOffOperand = false, Log2LMUL = [-2, -1, 0, 1, 2] in {
+ multiclass RVVFloatingWidenTerBuiltinSet {
+ defm "" : RVVOutOp1Op2BuiltinSet<NAME, "xf",
+ [["vv", "w", "wwvv"],
+ ["vf", "w", "wwev"]]>;
+ }
+ multiclass RVVFloatingWidenTerBuiltinSetRoundingMode {
+ defm "" : RVVOutOp1Op2BuiltinSet<NAME, "xf",
+ [["vv", "w", "wwvvu"],
+ ["vf", "w", "wwevu"]]>;
+ }
+}
+
+multiclass RVVFloatingBinBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vv", "v", "vvv"],
+ ["vf", "v", "vve"]]>;
+
+multiclass RVVFloatingBinBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vv", "v", "vvvu"],
+ ["vf", "v", "vveu"]]>;
+
+multiclass RVVFloatingBinVFBuiltinSet
+ : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vf", "v", "vve"]]>;
+
+multiclass RVVFloatingBinVFBuiltinSetRoundingMode
+ : RVVOutOp1BuiltinSet<NAME, "xfd",
+ [["vf", "v", "vveu"]]>;
+
+multiclass RVVFloatingMaskOutBuiltinSet
+ : RVVOp0Op1BuiltinSet<NAME, "xfd",
+ [["vv", "vm", "mvv"],
+ ["vf", "vm", "mve"]]>;
+
+multiclass RVVFloatingMaskOutVFBuiltinSet
+ : RVVOp0Op1BuiltinSet<NAME, "fd",
+ [["vf", "vm", "mve"]]>;
+
+multiclass RVVConvBuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes> {
+let Name = intrinsic_name,
+ IRName = intrinsic_name,
+ MaskedIRName = intrinsic_name # "_mask",
+ IntrinsicTypes = [-1, 0] in {
+ foreach s_p = suffixes_prototypes in {
+ defvar suffix = s_p[0];
+ defvar prototype = s_p[1];
+ def : RVVBuiltin<suffix, prototype, type_range>;
+ }
+ }
+}
+
+
+class RVVMaskBinBuiltin : RVVOutBuiltin<"m", "mmm", "c"> {
+ let Name = NAME # "_mm";
+ let HasMasked = false;
+}
+
+class RVVMaskUnaryBuiltin : RVVOutBuiltin<"m", "mm", "c"> {
+ let Name = NAME # "_m";
+}
+
+class RVVMaskNullaryBuiltin : RVVOutBuiltin<"m", "m", "c"> {
+ let Name = NAME # "_m";
+ let HasMasked = false;
+ let SupportOverloading = false;
+}
+
+class RVVMaskOp0Builtin<string prototype> : RVVOp0Builtin<"m", prototype, "c"> {
+ let Name = NAME # "_m";
+ let HasMaskedOffOperand = false;
+}
+
+let UnMaskedPolicyScheme = HasPolicyOperand,
+ HasMaskedOffOperand = false in {
+ multiclass RVVSlideUpBuiltinSet {
+ defm "" : RVVOutBuiltinSet<NAME, "csilxfd",
+ [["vx","v", "vvvz"]]>;
+ defm "" : RVVOutBuiltinSet<NAME, "csil",
+ [["vx","Uv", "UvUvUvz"]]>;
+ }
+}
+
+let UnMaskedPolicyScheme = HasPassthruOperand,
+ ManualCodegen = [{
+ if (IsMasked) {
+ std::rotate(Ops.begin(), Ops.begin() + 1, Ops.end() - 1);
+ if ((PolicyAttrs & RVV_VTA) && (PolicyAttrs & RVV_VMA))
+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
+ } else {
+ if (PolicyAttrs & RVV_VTA)
+ Ops.insert(Ops.begin(), llvm::PoisonValue::get(ResultType));
+ }
+
+ Ops.push_back(ConstantInt::get(Ops.back()->getType(), PolicyAttrs));
+ IntrinsicTypes = {ResultType, Ops.back()->getType()};
+ }] in {
+ multiclass RVVSlideDownBuiltinSet {
+ defm "" : RVVOutBuiltinSet<NAME, "csilxfd",
+ [["vx","v", "vvz"]]>;
+ defm "" : RVVOutBuiltinSet<NAME, "csil",
+ [["vx","Uv", "UvUvz"]]>;
+ }
+}
+
+class RVVFloatingUnaryBuiltin<string builtin_suffix, string ir_suffix,
+ string prototype>
+ : RVVOutBuiltin<ir_suffix, prototype, "xfd"> {
+ let Name = NAME # "_" # builtin_suffix;
+}
+
+class RVVFloatingUnaryVVBuiltin : RVVFloatingUnaryBuiltin<"v", "v", "vv">;
+
+class RVVConvBuiltin<string suffix, string prototype, string type_range,
+ string overloaded_name>
+ : RVVBuiltin<suffix, prototype, type_range> {
+ let IntrinsicTypes = [-1, 0];
+ let OverloadedName = overloaded_name;
+}
+
+class RVVConvToSignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Iv", "Ivv", "xfd", overloaded_name>;
+
+class RVVConvToUnsignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Uv", "Uvv", "xfd", overloaded_name>;
+
+class RVVConvToWidenSignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Iw", "Iwv", "xf", overloaded_name>;
+
+class RVVConvToWidenUnsignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Uw", "Uwv", "xf", overloaded_name>;
+
+class RVVConvToNarrowingSignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Iv", "IvFw", "csi", overloaded_name>;
+
+class RVVConvToNarrowingUnsignedBuiltin<string overloaded_name>
+ : RVVConvBuiltin<"Uv", "UvFw", "csi", overloaded_name>;
+
+let HasMaskedOffOperand = true in {
+ multiclass RVVSignedReductionBuiltin {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "csil",
+ [["vs", "vSv", "SvvSv"]]>;
+ }
+ multiclass RVVUnsignedReductionBuiltin {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "csil",
+ [["vs", "UvUSv", "USvUvUSv"]]>;
+ }
+ multiclass RVVFloatingReductionBuiltin {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "xfd",
+ [["vs", "vSv", "SvvSv"]]>;
+ }
+ multiclass RVVFloatingReductionBuiltinRoundingMode {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "xfd",
+ [["vs", "vSv", "SvvSvu"]]>;
+ }
+ multiclass RVVFloatingWidenReductionBuiltin {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "xf",
+ [["vs", "vSw", "SwvSw"]]>;
+ }
+ multiclass RVVFloatingWidenReductionBuiltinRoundingMode {
+ defm "" : RVVOutOp0BuiltinSet<NAME, "xf",
+ [["vs", "vSw", "SwvSwu"]]>;
+ }
+}
+
+multiclass RVVIntReductionBuiltinSet
+ : RVVSignedReductionBuiltin,
+ RVVUnsignedReductionBuiltin;
+
+// For widen operation which has different mangling name.
+multiclass RVVWidenBuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes> {
+ let Log2LMUL = [-3, -2, -1, 0, 1, 2],
+ IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask" in {
+ foreach s_p = suffixes_prototypes in {
+ let Name = NAME # "_" # s_p[0],
+ OverloadedName = NAME # "_" # s_p[0] in {
+ defvar suffix = s_p[1];
+ defvar prototype = s_p[2];
+ def : RVVOutOp0Op1Builtin<suffix, prototype, type_range>;
+ }
+ }
+ }
+}
+
+// For widen operation with widen operand which has different mangling name.
+multiclass RVVWidenWOp0BuiltinSet<string intrinsic_name, string type_range,
+ list<list<string>> suffixes_prototypes> {
+ let Log2LMUL = [-3, -2, -1, 0, 1, 2],
+ IRName = intrinsic_name, MaskedIRName = intrinsic_name # "_mask" in {
+ foreach s_p = suffixes_prototypes in {
+ let Name = NAME # "_" # s_p[0],
+ OverloadedName = NAME # "_" # s_p[0] in {
+ defvar suffix = s_p[1];
+ defvar prototype = s_p[2];
+ def : RVVOutOp1Builtin<suffix, prototype, type_range>;
+ }
+ }
+ }
+}
+
+multiclass RVVSignedWidenBinBuiltinSet
+ : RVVWidenBuiltinSet<NAME, "csi",
+ [["vv", "w", "wvv"],
+ ["vx", "w", "wve"]]>;
+
+multiclass RVVSignedWidenOp0BinBuiltinSet
+ : RVVWidenWOp0BuiltinSet<NAME # "_w", "csi",
+ [["wv", "w", "wwv"],
+ ["wx", "w", "wwe"]]>;
+
+multiclass RVVUnsignedWidenBinBuiltinSet
+ : RVVWidenBuiltinSet<NAME, "csi",
+ [["vv", "Uw", "UwUvUv"],
+ ["vx", "Uw", "UwUvUe"]]>;
+
+multiclass RVVUnsignedWidenOp0BinBuiltinSet
+ : RVVWidenWOp0BuiltinSet<NAME # "_w", "csi",
+ [["wv", "Uw", "UwUwUv"],
+ ["wx", "Uw", "UwUwUe"]]>;
+
+multiclass RVVFloatingWidenBinBuiltinSet
+ : RVVWidenBuiltinSet<NAME, "xf",
+ [["vv", "w", "wvv"],
+ ["vf", "w", "wve"]]>;
+
+multiclass RVVFloatingWidenBinBuiltinSetRoundingMode
+ : RVVWidenBuiltinSet<NAME, "xf",
+ [["vv", "w", "wvvu"],
+ ["vf", "w", "wveu"]]>;
+
+multiclass RVVFloatingWidenOp0BinBuiltinSet
+ : RVVWidenWOp0BuiltinSet<NAME # "_w", "xf",
+ [["wv", "w", "wwv"],
+ ["wf", "w", "wwe"]]>;
+
+multiclass RVVFloatingWidenOp0BinBuiltinSetRoundingMode
+ : RVVWidenWOp0BuiltinSet<NAME # "_w", "xf",
+ [["wv", "w", "wwvu"],
+ ["wf", "w", "wweu"]]>;
More information about the cfe-commits
mailing list