Skip to content

Commit 239127d

Browse files
authoredAug 31, 2024··
[llvm][RISCV] Support RISCV vector tuple type in llvm IR (#97992)
Summary: This patch proposes new llvm types for RISCV vector tuples represented as `TargetExtType` which contains both `LMUL` and `NF`(num_fields) information and keep it all the way down to `selectionDAG` to match the corresponding `MVT`(support in the following patch). Detail: Currently we have built-in C types for RISCV vector tuple type, e.g. `vint32m1x2_t`, however it's is represented as structure of scalable vector types, i.e. `{<vscale x 2 x i32>, <vscale x 2 x i32>}`. It loses the information for num_fields(NF) as struct is flattened during `selectionDAG`, thus it makes it not possible to handle inline assembly of vector tuple type, it also makes the calling convention of vector tuple types handing not strait forward and hard to realize the allocation code, i.e. `RVVArgDispatcher`. The llvm IR for the example above is then represented as `target("riscv.vector.tuple", <vscale x 8 x i8>, 2)` in which the first type parameter is the equivalent size scalable vecotr of i8 element type, the following integer parameter is the `NF` of the tuple. The new RISCV specific vector insert/extract intrinsics are also added as `llvm.riscv.vector.insert` and `llvm.riscv.vector.extract` to handle tuple type subvector insertion/extraction since the generic ones only operates on `VectorType` but not `TargetExtType`. There are total of 32 llvm types added for each `VREGS * NF <= 8`, where `VREGS` is the vector registers needed for each `LMUL` and `NF` is num_fields. The name of types are: ``` target("riscv.vector.tuple", <vscale x 1 x i8>, 2) // LMUL = mf8, NF = 2 target("riscv.vector.tuple", <vscale x 1 x i8>, 3) // LMUL = mf8, NF = 3 target("riscv.vector.tuple", <vscale x 1 x i8>, 4) // LMUL = mf8, NF = 4 target("riscv.vector.tuple", <vscale x 1 x i8>, 5) // LMUL = mf8, NF = 5 target("riscv.vector.tuple", <vscale x 1 x i8>, 6) // LMUL = mf8, NF = 6 target("riscv.vector.tuple", <vscale x 1 x i8>, 7) // LMUL = mf8, NF = 7 target("riscv.vector.tuple", <vscale x 1 x i8>, 8) // LMUL = mf8, NF = 8 target("riscv.vector.tuple", <vscale x 2 x i8>, 2) // LMUL = mf4, NF = 2 target("riscv.vector.tuple", <vscale x 2 x i8>, 3) // LMUL = mf4, NF = 3 target("riscv.vector.tuple", <vscale x 2 x i8>, 4) // LMUL = mf4, NF = 4 target("riscv.vector.tuple", <vscale x 2 x i8>, 5) // LMUL = mf4, NF = 5 target("riscv.vector.tuple", <vscale x 2 x i8>, 6) // LMUL = mf4, NF = 6 target("riscv.vector.tuple", <vscale x 2 x i8>, 7) // LMUL = mf4, NF = 7 target("riscv.vector.tuple", <vscale x 2 x i8>, 8) // LMUL = mf4, NF = 8 target("riscv.vector.tuple", <vscale x 4 x i8>, 2) // LMUL = mf2, NF = 2 target("riscv.vector.tuple", <vscale x 4 x i8>, 3) // LMUL = mf2, NF = 3 target("riscv.vector.tuple", <vscale x 4 x i8>, 4) // LMUL = mf2, NF = 4 target("riscv.vector.tuple", <vscale x 4 x i8>, 5) // LMUL = mf2, NF = 5 target("riscv.vector.tuple", <vscale x 4 x i8>, 6) // LMUL = mf2, NF = 6 target("riscv.vector.tuple", <vscale x 4 x i8>, 7) // LMUL = mf2, NF = 7 target("riscv.vector.tuple", <vscale x 4 x i8>, 8) // LMUL = mf2, NF = 8 target("riscv.vector.tuple", <vscale x 8 x i8>, 2) // LMUL = m1, NF = 2 target("riscv.vector.tuple", <vscale x 8 x i8>, 3) // LMUL = m1, NF = 3 target("riscv.vector.tuple", <vscale x 8 x i8>, 4) // LMUL = m1, NF = 4 target("riscv.vector.tuple", <vscale x 8 x i8>, 5) // LMUL = m1, NF = 5 target("riscv.vector.tuple", <vscale x 8 x i8>, 6) // LMUL = m1, NF = 6 target("riscv.vector.tuple", <vscale x 8 x i8>, 7) // LMUL = m1, NF = 7 target("riscv.vector.tuple", <vscale x 8 x i8>, 8) // LMUL = m1, NF = 8 target("riscv.vector.tuple", <vscale x 16 x i8>, 2) // LMUL = m2, NF = 2 target("riscv.vector.tuple", <vscale x 16 x i8>, 3) // LMUL = m2, NF = 3 target("riscv.vector.tuple", <vscale x 16 x i8>, 4) // LMUL = m2, NF = 4 target("riscv.vector.tuple", <vscale x 32 x i8>, 2) // LMUL = m4, NF = 2 ``` RFC: https://discourse.llvm.org/t/rfc-support-riscv-vector-tuple-type-in-llvm/80005
1 parent d1f3fec commit 239127d

File tree

1,003 files changed

+144750
-304834
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,003 files changed

+144750
-304834
lines changed
 

‎clang/include/clang/Basic/riscv_vector.td

+113-104
Large diffs are not rendered by default.

‎clang/include/clang/Support/RISCVVIntrinsicUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,7 @@ class RVVIntrinsic {
428428
bool hasBuiltinAlias() const { return HasBuiltinAlias; }
429429
bool hasManualCodegen() const { return !ManualCodegen.empty(); }
430430
bool isMasked() const { return IsMasked; }
431+
llvm::StringRef getOverloadedName() const { return OverloadedName; }
431432
llvm::StringRef getIRName() const { return IRName; }
432433
llvm::StringRef getManualCodegen() const { return ManualCodegen; }
433434
PolicyScheme getPolicyScheme() const { return Scheme; }

0 commit comments

Comments
 (0)
Please sign in to comment.