[compiler-rt] [compiler-rt][RISCV] Initialize length only when __init_riscv_feature… (PR #115449)

Kito Cheng via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 8 01:43:18 PST 2024


https://github.com/kito-cheng created https://github.com/llvm/llvm-project/pull/115449

…_bits success

That could give us a simple way to detect `__init_riscv_feature_bits` got fail.

See also https://github.com/riscv-non-isa/riscv-c-api-doc/pull/95

>From 8f877184967c6ab04692283bb3c7a52121f68e22 Mon Sep 17 00:00:00 2001
From: Kito Cheng <kito.cheng at sifive.com>
Date: Fri, 8 Nov 2024 00:18:30 +0800
Subject: [PATCH] [compiler-rt][RISCV] Initialize length only when
 __init_riscv_feature_bits success

That could give us a simple way to detect `__init_riscv_feature_bits`
got fail.

See also https://github.com/riscv-non-isa/riscv-c-api-doc/pull/95
---
 compiler-rt/lib/builtins/cpu_model/riscv.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/builtins/cpu_model/riscv.c b/compiler-rt/lib/builtins/cpu_model/riscv.c
index 74534896057ef5..c9aab19e9c7884 100644
--- a/compiler-rt/lib/builtins/cpu_model/riscv.c
+++ b/compiler-rt/lib/builtins/cpu_model/riscv.c
@@ -356,9 +356,6 @@ void __init_riscv_feature_bits(void *PlatformArgs) {
   if (FeaturesBitCached)
     return;
 
-  __riscv_feature_bits.length = RISCV_FEATURE_BITS_LENGTH;
-  __riscv_vendor_feature_bits.length = RISCV_VENDOR_FEATURE_BITS_LENGTH;
-
 #if defined(__linux__)
   struct riscv_hwprobe Hwprobes[] = {
       {RISCV_HWPROBE_KEY_BASE_BEHAVIOR, 0}, {RISCV_HWPROBE_KEY_IMA_EXT_0, 0},
@@ -369,6 +366,9 @@ void __init_riscv_feature_bits(void *PlatformArgs) {
     return;
 
   initRISCVFeature(Hwprobes);
+
+  __riscv_feature_bits.length = RISCV_FEATURE_BITS_LENGTH;
+  __riscv_vendor_feature_bits.length = RISCV_VENDOR_FEATURE_BITS_LENGTH;
 #endif // defined(__linux__)
 
   FeaturesBitCached = 1;



More information about the llvm-commits mailing list