Skip to content

Commit c4206f1

Browse files
authored
[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) ```
1 parent 31f593e commit c4206f1

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14370,13 +14370,13 @@ Value *CodeGenFunction::EmitAArch64CpuInit() {
1437014370
}
1437114371

1437214372
Value *CodeGenFunction::EmitRISCVCpuInit() {
14373-
llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, false);
14373+
llvm::FunctionType *FTy = llvm::FunctionType::get(VoidTy, {VoidPtrTy}, false);
1437414374
llvm::FunctionCallee Func =
1437514375
CGM.CreateRuntimeFunction(FTy, "__init_riscv_feature_bits");
1437614376
auto *CalleeGV = cast<llvm::GlobalValue>(Func.getCallee());
1437714377
CalleeGV->setDSOLocal(true);
1437814378
CalleeGV->setDLLStorageClass(llvm::GlobalValue::DefaultStorageClass);
14379-
return Builder.CreateCall(Func);
14379+
return Builder.CreateCall(Func, {llvm::ConstantPointerNull::get(VoidPtrTy)});
1438014380
}
1438114381

1438214382
Value *CodeGenFunction::EmitX86CpuInit() {

clang/test/CodeGen/builtin-cpu-supports.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ int test_ppc(int a) {
250250
// CHECK-RV32-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
251251
// CHECK-RV32-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4
252252
// CHECK-RV32-NEXT: store i32 [[A]], ptr [[A_ADDR]], align 4
253-
// CHECK-RV32-NEXT: call void @__init_riscv_feature_bits()
253+
// CHECK-RV32-NEXT: call void @__init_riscv_feature_bits(ptr null)
254254
// 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
255255
// CHECK-RV32-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 1
256256
// CHECK-RV32-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1
@@ -301,7 +301,7 @@ int test_ppc(int a) {
301301
// CHECK-RV64-NEXT: [[RETVAL:%.*]] = alloca i32, align 4
302302
// CHECK-RV64-NEXT: [[A_ADDR:%.*]] = alloca i32, align 4
303303
// CHECK-RV64-NEXT: store i32 [[A]], ptr [[A_ADDR]], align 4
304-
// CHECK-RV64-NEXT: call void @__init_riscv_feature_bits()
304+
// CHECK-RV64-NEXT: call void @__init_riscv_feature_bits(ptr null)
305305
// 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
306306
// CHECK-RV64-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 1
307307
// CHECK-RV64-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1

compiler-rt/lib/builtins/cpu_model/riscv.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,14 +328,18 @@ static void initRISCVFeature(struct riscv_hwprobe Hwprobes[]) {
328328

329329
static int FeaturesBitCached = 0;
330330

331-
void __init_riscv_feature_bits() CONSTRUCTOR_ATTRIBUTE;
331+
void __init_riscv_feature_bits(void *) CONSTRUCTOR_ATTRIBUTE;
332332

333333
// A constructor function that sets __riscv_feature_bits, and
334334
// __riscv_vendor_feature_bits to the right values. This needs to run
335335
// only once. This constructor is given the highest priority and it should
336336
// run before constructors without the priority set. However, it still runs
337337
// after ifunc initializers and needs to be called explicitly there.
338-
void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits() {
338+
339+
// PlatformArgs allows the platform to provide pre-computed data and access it
340+
// without extra effort. For example, Linux could pass the vDSO object to avoid
341+
// an extra system call.
342+
void CONSTRUCTOR_ATTRIBUTE __init_riscv_feature_bits(void *PlatformArgs) {
339343

340344
if (FeaturesBitCached)
341345
return;

0 commit comments

Comments
 (0)