[PATCH] D141032: [Clang][RISCV] Expose vlenb to user
Yueh-Ting (eop) Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Jan 8 22:46:32 PST 2023
eopXD updated this revision to Diff 487293.
eopXD marked 5 inline comments as done.
eopXD added a comment.
Address comments from Craig.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D141032/new/
https://reviews.llvm.org/D141032
Files:
clang/include/clang/Basic/riscv_vector.td
clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
Index: clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/RISCV/rvv-intrinsics/vlenb.c
@@ -0,0 +1,41 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals
+// REQUIRES: riscv-registered-target
+// RUN: %clang_cc1 -triple riscv32 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV32 %s
+// RUN: %clang_cc1 -triple riscv64 -target-feature +v -disable-O0-optnone -emit-llvm %s -o - \
+// RUN: | opt -S -O2 | FileCheck --check-prefix=RV64 %s
+
+#include <riscv_vector.h>
+
+// RV32-LABEL: @test_vlenb(
+// RV32-NEXT: entry:
+// RV32-NEXT: [[TMP0:%.*]] = tail call i32 @llvm.read_register.i32(metadata [[META4:![0-9]+]])
+// RV32-NEXT: ret i32 [[TMP0]]
+//
+// RV64-LABEL: @test_vlenb(
+// RV64-NEXT: entry:
+// RV64-NEXT: [[TMP0:%.*]] = tail call i64 @llvm.read_register.i64(metadata [[META4:![0-9]+]])
+// RV64-NEXT: ret i64 [[TMP0]]
+//
+unsigned long test_vlenb(void) {
+ return vlenb();
+}
+//.
+// RV32: attributes #0 = { mustprogress nofree noinline nosync nounwind willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+32bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" }
+// RV32: attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(read) }
+//.
+// RV64: attributes #0 = { mustprogress nofree noinline nosync nounwind willreturn memory(read) vscale_range(2,1024) "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+64bit,+d,+f,+v,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b" }
+// RV64: attributes #1 = { mustprogress nocallback nofree nosync nounwind willreturn memory(read) }
+//.
+// RV32: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV32: !1 = !{i32 1, !"target-abi", !"ilp32d"}
+// RV32: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV32: !3 = !{!"clang version 16.0.0 (git at github.com:llvm/llvm-project.git e80f0cc0a318fe8473ba460d6a16166d81b303b1)"}
+// RV32: !4 = !{!"vlenb"}
+//.
+// RV64: !0 = !{i32 1, !"wchar_size", i32 4}
+// RV64: !1 = !{i32 1, !"target-abi", !"lp64d"}
+// RV64: !2 = !{i32 1, !"SmallDataLimit", i32 0}
+// RV64: !3 = !{!"clang version 16.0.0 (git at github.com:llvm/llvm-project.git e80f0cc0a318fe8473ba460d6a16166d81b303b1)"}
+// RV64: !4 = !{!"vlenb"}
+//.
Index: clang/include/clang/Basic/riscv_vector.td
===================================================================
--- clang/include/clang/Basic/riscv_vector.td
+++ clang/include/clang/Basic/riscv_vector.td
@@ -1558,6 +1558,32 @@
}] in
def vread_vwrite_csr: RVVHeader;
+let HeaderCode =
+[{
+#define vlenb() __builtin_rvv_vlenb()
+}] in
+def vlenb_macro: RVVHeader;
+
+let HasBuiltinAlias = false, HasVL = false, HasMasked = false,
+ UnMaskedPolicyScheme = NonePolicy, MaskedPolicyScheme = NonePolicy,
+ Log2LMUL = [0], IRName = "",
+ ManualCodegen = [{
+ {
+ LLVMContext &Context = CGM.getLLVMContext();
+ llvm::MDBuilder MDHelper(Context);
+
+ llvm::Metadata *Ops[] = {llvm::MDString::get(Context, "vlenb")};
+ llvm::MDNode *RegName = llvm::MDNode::get(Context, Ops);
+ llvm::Value *Metadata = llvm::MetadataAsValue::get(Context, RegName);
+ llvm::Function *F =
+ CGM.getIntrinsic(llvm::Intrinsic::read_register, {SizeTy});
+ return Builder.CreateCall(F, Metadata);
+ }
+ }] in
+{
+ def vlenb : RVVBuiltin<"", "u", "i">;
+}
+
// 6. Configuration-Setting Instructions
// 6.1. vsetvli/vsetvl instructions
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D141032.487293.patch
Type: text/x-patch
Size: 3684 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230109/5a4ff40e/attachment-0001.bin>
More information about the cfe-commits
mailing list