[clang] c4206f1 - [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (#101472)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 14 02:30:58 PDT 2024
Author: Piyou Chen
Date: 2024-08-14T17:30:53+08:00
New Revision: c4206f1ff1d946c495b74738eba9303dafb17e18
URL: https://github.com/llvm/llvm-project/commit/c4206f1ff1d946c495b74738eba9303dafb17e18
DIFF: https://github.com/llvm/llvm-project/commit/c4206f1ff1d946c495b74738eba9303dafb17e18.diff
LOG: [RISCV][compiler-rt] Update __init_riscv_feature_bits prototype (#101472)
This patch add `void* PlatformArgs` parameter to
`__init_riscv_feature_bits`. `PlatformArgs` allows the platform to
provide pre-computed data and access it without extra effort. For
example, Linux could pass the vDSO object to avoid an extra system call.
```
__init_riscv_feature_bits()
->
__init_riscv_feature_bits(void *PlatformArgs)
```
Added:
Modified:
clang/lib/CodeGen/CGBuiltin.cpp
clang/test/CodeGen/builtin-cpu-supports.c
compiler-rt/lib/builtins/cpu_model/riscv.c
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index bfae7f8abdb50a..b5e5240e55be3f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -14370,13 +14370,13 @@ Value *CodeGenFunction::EmitAArch64CpuInit() {
}
Value *CodeGenFunction::EmitRISCVCpuInit() {
- llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
+ llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, {VoidPtrTy}, false);
llvm::FunctionCallee Func =
CGM.CreateRuntimeFunction(FTy, "__init_riscv_feature_bits");
auto *CalleeGV = cast<llvm::GlobalValue>(Func.getCallee());
CalleeGV->setDSOLocal(true);
CalleeGV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
- return Builder.CreateCall(Func);
+ return Builder.CreateCall(Func, {llvm::ConstantPointerNull::get(VoidPtrTy)});
}
Value *CodeGenFunction::EmitX86CpuInit() {
diff --git a/clang/test/CodeGen/builtin-cpu-supports.c b/clang/test/CodeGen/builtin-cpu-supports.c
index 071d627b7181b5..b252484fc3df95 100644
--- a/clang/test/CodeGen/builtin-cpu-supports.c
+++ b/clang/test/CodeGen/builtin-cpu-supports.c
@@ -250,7 +250,7 @@ int test_ppc(int a) {
// CHECK-RV32-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
// CHECK-RV32-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4
// CHECK-RV32-NEXT: store i32 [[A]], ptr [[A_ADDR]], align 4
-// CHECK-RV32-NEXT: call void @__init_riscv_feature_bits()
+// CHECK-RV32-NEXT: call void @__init_riscv_feature_bits(ptr null)
// CHECK-RV32-NEXT: [[TMP0:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8
// CHECK-RV32-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 1
// CHECK-RV32-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1
@@ -301,7 +301,7 @@ int test_ppc(int a) {
// CHECK-RV64-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
// CHECK-RV64-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4
// CHECK-RV64-NEXT: store i32 [[A]], ptr [[A_ADDR]], align 4
-// CHECK-RV64-NEXT: call void @__init_riscv_feature_bits()
+// CHECK-RV64-NEXT: call void @__init_riscv_feature_bits(ptr null)
// CHECK-RV64-NEXT: [[TMP0:%.*]] = load i64, ptr getelementptr inbounds ({ i32, [1 x i64] }, ptr @__riscv_feature_bits, i32 0, i32 1, i32 0), align 8
// CHECK-RV64-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 1
// CHECK-RV64-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1
diff --git a/compiler-rt/lib/builtins/cpu_model/riscv.c b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 0c443025b74c63..05c36b3d9e39ea 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -328,14 +328,18 @@ static void initRISCVFeature(struct riscv_hwprobe Hwprobes[]) {
static int FeaturesBitCached = 0;
-void __init_riscv_feature_bits() CONSTRUCTOR_ATTRIBUTE;
+void __init_riscv_feature_bits(void *) CONSTRUCTOR_ATTRIBUTE;
// A constructor function that sets __riscv_feature_bits, and
// __riscv_vendor_feature_bits to the right values. This needs to run
// only once. This constructor is given the highest priority and it should
// run before constructors without the priority set. However, it still runs
// after ifunc initializers and needs to be called explicitly there.
-void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits() {
+
+// PlatformArgs allows the platform to provide pre-computed data and access it
+// without extra effort. For example, Linux could pass the vDSO object to avoid
+// an extra system call.
+void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits(void *PlatformArgs) {
if (FeaturesBitCached)
return;
More information about the cfe-commits
mailing list