Skip to content

Commit

Permalink
[Clang][XTHeadVector] support vget/vset/vcreate on vector tuple typ…
Browse files Browse the repository at this point in the history
…es (#130)

* [Clang][XTHeadVector] support `vget/vset` on vector tuple types

* [Clang][XTHeadVector] add wrappers

* [Clang][XTHeadVector] add corresponding tests

* [Clang][RISCV] Add vcreate intrinsics for RVV tuple types

Specification PR: riscv-non-isa/rvv-intrinsic-doc#256

Reviewed By: craig.topper

Differential Revision: https://reviews.llvm.org/D158402

* [Clang][XTHeadVector] Implement `vcreate` on tuple types

* [Clang][XTHeadVector] Add vcreate wrappers

* [Clang][XTHeadVector] Add corresponding tests

---------

Co-authored-by: eopXD <[email protected]>
  • Loading branch information
imkiva and eopXD authored Sep 2, 2024
1 parent 1170a48 commit 4ca21d5
Show file tree
Hide file tree
Showing 13 changed files with 16,676 additions and 28 deletions.
47 changes: 26 additions & 21 deletions clang/include/clang/Basic/riscv_vector.td
Original file line number Diff line number Diff line change
Expand Up @@ -761,27 +761,6 @@ The Vector(s) is poison when the policy behavior allows us to not care
about any masked-off elements.
*/

class PVString<int nf, bit signed> {
string S =
!cond(!eq(nf, 2): !if(signed, "PvPv", "PUvPUv"),
!eq(nf, 3): !if(signed, "PvPvPv", "PUvPUvPUv"),
!eq(nf, 4): !if(signed, "PvPvPvPv", "PUvPUvPUvPUv"),
!eq(nf, 5): !if(signed, "PvPvPvPvPv", "PUvPUvPUvPUvPUv"),
!eq(nf, 6): !if(signed, "PvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUv"),
!eq(nf, 7): !if(signed, "PvPvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUvPUv"),
!eq(nf, 8): !if(signed, "PvPvPvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUvPUvPUv"));
}

class VString<int nf, bit signed> {
string S = !cond(!eq(nf, 2): !if(signed, "vv", "UvUv"),
!eq(nf, 3): !if(signed, "vvv", "UvUvUv"),
!eq(nf, 4): !if(signed, "vvvv", "UvUvUvUv"),
!eq(nf, 5): !if(signed, "vvvvv", "UvUvUvUvUv"),
!eq(nf, 6): !if(signed, "vvvvvv", "UvUvUvUvUvUv"),
!eq(nf, 7): !if(signed, "vvvvvvv", "UvUvUvUvUvUvUv"),
!eq(nf, 8): !if(signed, "vvvvvvvv", "UvUvUvUvUvUvUvUv"));
}

multiclass RVVPseudoUnaryBuiltin<string IR, string type_range> {
let Name = NAME,
IRName = IR,
Expand Down Expand Up @@ -2813,4 +2792,30 @@ let HasMasked = false, HasVL = false, IRName = "" in {
def : RVVBuiltin<"Uv" # T # "Uv", T # "Uv" # T # "UvKzUv", "csil">;
}
}

let Name = "vcreate_v",
UnMaskedPolicyScheme = NonePolicy,
MaskedPolicyScheme = NonePolicy,
SupportOverloading = false,
ManualCodegen = [{
{
assert(isa<StructType>(ResultType));
unsigned NF = cast<StructType>(ResultType)->getNumElements();
llvm::Value *ReturnTuple = llvm::PoisonValue::get(ResultType);
for (unsigned I = 0; I < NF; ++I) {
ReturnTuple = Builder.CreateInsertValue(ReturnTuple, Ops[I], {I});
}
return ReturnTuple;
}
}] in {
foreach nf = NFList in {
let NF = nf in {
defvar T = "(Tuple:" # nf # ")";
defvar V = VString<nf, /*signed=*/true>.S;
defvar UV = VString<nf, /*signed=*/false>.S;
def : RVVBuiltin<T # "v", T # "v" # V, "csilxfd">;
def : RVVBuiltin<T # "Uv", T # "Uv" # UV, "csil">;
}
}
}
}
22 changes: 22 additions & 0 deletions clang/include/clang/Basic/riscv_vector_common.td
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,25 @@ class RVVHeader {
class IsFloat<string type> {
bit val = !or(!eq(type, "x"), !eq(type, "f"), !eq(type, "d"));
}


class PVString<int nf, bit signed> {
string S =
!cond(!eq(nf, 2): !if(signed, "PvPv", "PUvPUv"),
!eq(nf, 3): !if(signed, "PvPvPv", "PUvPUvPUv"),
!eq(nf, 4): !if(signed, "PvPvPvPv", "PUvPUvPUvPUv"),
!eq(nf, 5): !if(signed, "PvPvPvPvPv", "PUvPUvPUvPUvPUv"),
!eq(nf, 6): !if(signed, "PvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUv"),
!eq(nf, 7): !if(signed, "PvPvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUvPUv"),
!eq(nf, 8): !if(signed, "PvPvPvPvPvPvPvPv", "PUvPUvPUvPUvPUvPUvPUvPUv"));
}

class VString<int nf, bit signed> {
string S = !cond(!eq(nf, 2): !if(signed, "vv", "UvUv"),
!eq(nf, 3): !if(signed, "vvv", "UvUvUv"),
!eq(nf, 4): !if(signed, "vvvv", "UvUvUvUv"),
!eq(nf, 5): !if(signed, "vvvvv", "UvUvUvUvUv"),
!eq(nf, 6): !if(signed, "vvvvvv", "UvUvUvUvUvUv"),
!eq(nf, 7): !if(signed, "vvvvvvv", "UvUvUvUvUvUvUv"),
!eq(nf, 8): !if(signed, "vvvvvvvv", "UvUvUvUvUvUvUvUv"));
}
34 changes: 34 additions & 0 deletions clang/include/clang/Basic/riscv_vector_xtheadv.td
Original file line number Diff line number Diff line change
Expand Up @@ -2283,6 +2283,11 @@ let HasMasked = false, HasVL = false, IRName = "" in {
def : RVVBuiltin<"v" # dst_lmul # "v", dst_lmul # "vvKz", "csilxfd", dst_lmul # "v">;
def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "UvUvKz", "csil", dst_lmul # "Uv">;
}
foreach nf = NFList in {
defvar T = "(Tuple:" # nf # ")";
def : RVVBuiltin<T # "vv", "v" # T # "vKz", "csilxfd", "v">;
def : RVVBuiltin<T # "UvUv", "Uv" # T # "UvKz", "csil", "Uv">;
}
}

let Name = "th_vset_v", MaskedPolicyScheme = NonePolicy,
Expand Down Expand Up @@ -2312,6 +2317,35 @@ let HasMasked = false, HasVL = false, IRName = "" in {
def : RVVBuiltin<"Uv" # dst_lmul # "Uv", dst_lmul # "Uv" # dst_lmul #"UvKzUv", "csil">;
}
}
foreach nf = NFList in {
defvar T = "(Tuple:" # nf # ")";
def : RVVBuiltin<"v" # T # "v", T # "v" # T # "vKzv", "csilxfd">;
def : RVVBuiltin<"Uv" # T # "Uv", T # "Uv" # T # "UvKzUv", "csil">;
}
}

let Name = "th_vcreate_v", UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
SupportOverloading = false,
ManualCodegen = [{
{
assert(isa<StructType>(ResultType));
unsigned NF = cast<StructType>(ResultType)->getNumElements();
llvm::Value *ReturnTuple = llvm::PoisonValue::get(ResultType);
for (unsigned I = 0; I < NF; ++I) {
ReturnTuple = Builder.CreateInsertValue(ReturnTuple, Ops[I], {I});
}
return ReturnTuple;
}
}] in {
foreach nf = NFList in {
let NF = nf in {
defvar T = "(Tuple:" # nf # ")";
defvar V = VString<nf, /*signed=*/true>.S;
defvar UV = VString<nf, /*signed=*/false>.S;
def : RVVBuiltin<T # "v", T # "v" # V, "csilxfd">;
def : RVVBuiltin<T # "Uv", T # "Uv" # UV, "csil">;
}
}
}
}

Expand Down
Loading

0 comments on commit 4ca21d5

Please sign in to comment.