Skip to content

[RISCV][compiler-rt] Small fixes for __riscv_feature_bits #100158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ endif()
set(powerpc64le_SOURCES ${powerpc64_SOURCES})

set(riscv_SOURCES
riscv/feature_bits.c
cpu_model/riscv.c
riscv/fp_mode.c
riscv/save.S
riscv/restore.S
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//=== feature_bits.c - Update RISC-V Feature Bits Structure -*- C -*-=========//
//=== cpu_model/riscv.c - Update RISC-V Feature Bits Structure -*- C -*-======//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "cpu_model.h"

#define RISCV_FEATURE_BITS_LENGTH 1
struct {
unsigned length;
Expand Down Expand Up @@ -204,12 +206,10 @@ static void initRISCVFeature(struct riscv_hwprobe Hwprobes[]) {
// This unsets all extension bitmask bits.

// Init vendor extension
__riscv_vendor_feature_bits.length = 0;
__riscv_vendor_feature_bits.vendorID = Hwprobes[2].value;

// Init standard extension
// TODO: Maybe Extension implied generate from tablegen?
__riscv_feature_bits.length = RISCV_FEATURE_BITS_LENGTH;

unsigned long long features[RISCV_FEATURE_BITS_LENGTH];
int i;
Expand Down Expand Up @@ -277,11 +277,21 @@ static void initRISCVFeature(struct riscv_hwprobe Hwprobes[]) {

static int FeaturesBitCached = 0;

void __init_riscv_feature_bits() {
void __init_riscv_feature_bits() 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() {

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},
Expand Down
Loading