Skip to content

Commit e3087c4

Browse files
[libc] Start to refactor riscv platform abstraction to support both 32 and 64 bits versions
This patch enables the compilation of libc for rv32 by unifying the current rv64 and rv32 implementation into a single rv implementation. We updated the cmake file to match the new riscv32 arch and force LIBC_TARGET_ARCHITECTURE to be "riscv" whenever we find "riscv32" or "riscv64". This is required as LIBC_TARGET_ARCHITECTURE is used in the path for several platform specific implementations. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148797
1 parent 06f10b8 commit e3087c4

File tree

27 files changed

+45
-223
lines changed

27 files changed

+45
-223
lines changed

libc/cmake/modules/LLVMLibCArchitectures.cmake

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,10 +150,12 @@ elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "aarch64")
150150
set(LIBC_TARGET_ARCHITECTURE_IS_AARCH64 TRUE)
151151
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "x86_64")
152152
set(LIBC_TARGET_ARCHITECTURE_IS_X86 TRUE)
153-
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv32")
154-
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV32 TRUE)
155153
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv64")
156154
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV64 TRUE)
155+
set(LIBC_TARGET_ARCHITECTURE "riscv")
156+
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv32")
157+
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV32 TRUE)
158+
set(LIBC_TARGET_ARCHITECTURE "riscv")
157159
else()
158160
message(FATAL_ERROR
159161
"Unsupported libc target architecture ${LIBC_TARGET_ARCHITECTURE}")

libc/config/linux/app.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ struct TLSImage {
3737

3838
#if defined(LIBC_TARGET_ARCH_IS_X86_64) || \
3939
defined(LIBC_TARGET_ARCH_IS_AARCH64) || \
40-
defined(LIBC_TARGET_ARCH_IS_RISCV64)
40+
defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
4141
// At the language level, argc is an int. But we use uint64_t as the x86_64
4242
// ABI specifies it as an 8 byte value. Likewise, in the ARM64 ABI, arguments
4343
// are usually passed in registers. x0 is a doubleword register, so this is

libc/src/__support/FPUtil/FEnvImpl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,8 @@
3030
#include "x86_64/FEnvImpl.h"
3131
#elif defined(LIBC_TARGET_ARCH_IS_ARM)
3232
#include "arm/FEnvImpl.h"
33-
#elif defined(LIBC_TARGET_ARCH_IS_RISCV32)
34-
#include "riscv32/FEnvImpl.h"
35-
#elif defined(LIBC_TARGET_ARCH_IS_RISCV64)
36-
#include "riscv64/FEnvImpl.h"
33+
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
34+
#include "riscv/FEnvImpl.h"
3735
#else
3836

3937
namespace LIBC_NAMESPACE::fputil {

libc/src/__support/FPUtil/FMA.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
#include "x86_64/FMA.h"
1919
#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
2020
#include "aarch64/FMA.h"
21-
#elif defined(LIBC_TARGET_ARCH_IS_RISCV64)
22-
#include "riscv64/FMA.h"
21+
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
22+
#include "riscv/FMA.h"
2323
#elif defined(LIBC_TARGET_ARCH_IS_GPU)
2424
#include "gpu/FMA.h"
2525
#endif

libc/src/__support/FPUtil/riscv32/FEnvImpl.h renamed to libc/src/__support/FPUtil/riscv/FEnvImpl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===-- riscv32 floating point env manipulation functions -------*- C++ -*-===//
1+
//===-- riscv floating point env manipulation functions ---------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV32_FENVIMPL_H
10-
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV32_FENVIMPL_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H
1111

1212
#include "src/__support/FPUtil/FPBits.h"
1313
#include "src/__support/macros/attributes.h" // For LIBC_INLINE_ASM
@@ -177,4 +177,4 @@ LIBC_INLINE int set_env(const fenv_t *envp) {
177177
} // namespace fputil
178178
} // namespace LIBC_NAMESPACE
179179

180-
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV32_FENVIMPL_H
180+
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FENVIMPL_H

libc/src/__support/FPUtil/riscv64/FMA.h renamed to libc/src/__support/FPUtil/riscv/FMA.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
//===-- RISCV64 implementations of the fma function -------------*- C++ -*-===//
1+
//===-- RISCV implementations of the fma function ---------------*- C++ -*-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_FMA_H
10-
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_FMA_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H
10+
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H
1111

1212
#include "src/__support/macros/attributes.h" // LIBC_INLINE
1313
#include "src/__support/macros/properties/architectures.h"
1414
#include "src/__support/macros/properties/cpu_features.h" // LIBC_TARGET_CPU_HAS_FMA
1515

16-
#if !defined(LIBC_TARGET_ARCH_IS_RISCV64)
16+
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
1717
#error "Invalid include"
1818
#endif
1919

@@ -47,4 +47,4 @@ LIBC_INLINE cpp::enable_if_t<cpp::is_same_v<T, double>, T> fma(T x, T y, T z) {
4747
} // namespace fputil
4848
} // namespace LIBC_NAMESPACE
4949

50-
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_FMA_H
50+
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_FMA_H

libc/src/__support/FPUtil/riscv64/sqrt.h renamed to libc/src/__support/FPUtil/riscv/sqrt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_SQRT_H
10-
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_SQRT_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H
10+
#define LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H
1111

1212
#include "src/__support/common.h"
1313
#include "src/__support/macros/properties/architectures.h"
1414

15-
#if !defined(LIBC_TARGET_ARCH_IS_RISCV64)
15+
#if !defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
1616
#error "Invalid include"
1717
#endif
1818

@@ -36,4 +36,4 @@ template <> LIBC_INLINE double sqrt<double>(double x) {
3636
} // namespace fputil
3737
} // namespace LIBC_NAMESPACE
3838

39-
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV64_SQRT_H
39+
#endif // LLVM_LIBC_SRC___SUPPORT_FPUTIL_RISCV_SQRT_H

libc/src/__support/FPUtil/riscv64/FEnvImpl.h

Lines changed: 0 additions & 180 deletions
This file was deleted.

libc/src/__support/FPUtil/sqrt.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
#include "x86_64/sqrt.h"
1616
#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
1717
#include "aarch64/sqrt.h"
18-
#elif defined(LIBC_TARGET_ARCH_IS_RISCV64)
19-
#include "riscv64/sqrt.h"
18+
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
19+
#include "riscv/sqrt.h"
2020
#else
2121
#include "generic/sqrt.h"
2222

libc/src/__support/OSUtil/linux/riscv64/CMakeLists.txt renamed to libc/src/__support/OSUtil/linux/riscv/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_header_library(
2-
linux_riscv64_util
2+
linux_riscv_util
33
HDRS
44
syscall.h
55
DEPENDS

libc/src/__support/OSUtil/linux/riscv64/syscall.h renamed to libc/src/__support/OSUtil/linux/riscv/syscall.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
//===--------- inline implementation of riscv64 syscalls ----------* C++ *-===//
1+
//===--------- inline implementation of riscv syscalls ------------* C++ *-===//
22
//
33
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66
//
77
//===----------------------------------------------------------------------===//
88

9-
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H
10-
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H
9+
#ifndef LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_SYSCALL_H
10+
#define LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_SYSCALL_H
1111

1212
#include "src/__support/common.h"
1313

@@ -107,4 +107,4 @@ LIBC_INLINE long syscall_impl(long number, long arg1, long arg2, long arg3,
107107
#undef REGISTER_CONSTRAINT_5
108108
#undef REGISTER_CONSTRAINT_6
109109

110-
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV64_SYSCALL_H
110+
#endif // LLVM_LIBC_SRC___SUPPORT_OSUTIL_LINUX_RISCV_SYSCALL_H

libc/src/__support/OSUtil/linux/syscall.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
#include "aarch64/syscall.h"
2020
#elif defined(LIBC_TARGET_ARCH_IS_ARM)
2121
#include "arm/syscall.h"
22-
#elif defined(LIBC_TARGET_ARCH_IS_RISCV64)
23-
#include "riscv64/syscall.h"
22+
#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
23+
#include "riscv/syscall.h"
2424
#endif
2525

2626
namespace LIBC_NAMESPACE {

libc/src/__support/macros/properties/architectures.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
#define LIBC_TARGET_ARCH_IS_AARCH64
4646
#endif
4747

48-
#if (defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_ARM))
48+
#if defined(LIBC_TARGET_ARCH_IS_AARCH64) || defined(LIBC_TARGET_ARCH_IS_ARM)
4949
#define LIBC_TARGET_ARCH_IS_ANY_ARM
5050
#endif
5151

@@ -57,8 +57,7 @@
5757
#define LIBC_TARGET_ARCH_IS_RISCV32
5858
#endif
5959

60-
#if (defined(LIBC_TARGET_ARCH_IS_RISCV64) || \
61-
defined(LIBC_TARGET_ARCH_IS_RISCV32))
60+
#if defined(LIBC_TARGET_ARCH_IS_RISCV64) || defined(LIBC_TARGET_ARCH_IS_RISCV32)
6261
#define LIBC_TARGET_ARCH_IS_ANY_RISCV
6362
#endif
6463

0 commit comments

Comments
 (0)