mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-10-07 19:03:57 +00:00
[libc] Enable running libc unit tests on AMDGPU
The previous patches added the necessary support for global constructors used to register tests. This patch enables the AMDGPU target to build and run the unit tests on the GPU. Currently this only tests the `ctype` tests, but adding more should be straightforward from here on. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D149517
This commit is contained in:
parent
17faae95d7
commit
632fa3798c
@ -5,10 +5,6 @@
|
||||
# Initialize ALL_CPU_FEATURES as empty list.
|
||||
set(ALL_CPU_FEATURES "")
|
||||
|
||||
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
|
||||
set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX AVX2 AVX512F AVX512BW FMA)
|
||||
set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
|
||||
@ -26,6 +22,10 @@ list(SORT ALL_CPU_FEATURES)
|
||||
# <list of cpu features>
|
||||
# )
|
||||
function(cpu_supports output_var features)
|
||||
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
unset(${output_var} PARENT_SCOPE)
|
||||
return()
|
||||
endif()
|
||||
_intersection(var "${LIBC_CPU_FEATURES}" "${features}")
|
||||
if("${var}" STREQUAL "${features}")
|
||||
set(${output_var} TRUE PARENT_SCOPE)
|
||||
|
@ -56,19 +56,8 @@ set(TARGET_LIBC_ENTRYPOINTS
|
||||
|
||||
# stdlib.h entrypoints
|
||||
libc.src.stdlib.abs
|
||||
libc.src.stdlib.atoi
|
||||
libc.src.stdlib.atof
|
||||
libc.src.stdlib.atol
|
||||
libc.src.stdlib.atoll
|
||||
libc.src.stdlib.labs
|
||||
libc.src.stdlib.llabs
|
||||
libc.src.stdlib.strtod
|
||||
libc.src.stdlib.strtof
|
||||
libc.src.stdlib.strtol
|
||||
libc.src.stdlib.strtold
|
||||
libc.src.stdlib.strtoll
|
||||
libc.src.stdlib.strtoul
|
||||
libc.src.stdlib.strtoull
|
||||
|
||||
# stdlib.h entrypoints
|
||||
libc.src.stdlib._Exit
|
||||
|
@ -85,17 +85,17 @@ stdlib.h
|
||||
Function Name Available RPC Required
|
||||
============= ========= ============
|
||||
abs |check|
|
||||
atoi |check|
|
||||
atof |check|
|
||||
atol |check|
|
||||
atoll |check|
|
||||
atoi
|
||||
atof
|
||||
atol
|
||||
atoll
|
||||
labs |check|
|
||||
llabs |check|
|
||||
strtod |check|
|
||||
strtof |check|
|
||||
strtol |check|
|
||||
strtold |check|
|
||||
strtoll |check|
|
||||
strtoul |check|
|
||||
strtoull |check|
|
||||
strtod
|
||||
strtof
|
||||
strtol
|
||||
strtold
|
||||
strtoll
|
||||
strtoul
|
||||
strtoull
|
||||
============= ========= ============
|
||||
|
@ -22,7 +22,7 @@ if(LIBC_TARGET_ARCHITECTURE_IS_GPU AND
|
||||
return()
|
||||
endif()
|
||||
|
||||
if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
if(NOT LIBC_GPU_TARGET_ARCHITECTURE_IS_NVPTX)
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(utils)
|
||||
endif()
|
||||
|
@ -138,3 +138,12 @@ foreach(lib LibcFPTestHelpers LibcFPExceptionHelpers LibcMemoryHelpers
|
||||
target_compile_options(${lib} PRIVATE -fno-exceptions -fno-rtti)
|
||||
target_link_libraries(${lib} LibcUnitTest)
|
||||
endforeach()
|
||||
|
||||
# The GPU needs these flags applied to override the system triple.
|
||||
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
foreach(lib LibcMemoryHelpers)
|
||||
target_include_directories(${lib} PRIVATE ${LIBC_BUILD_DIR}/include)
|
||||
target_compile_options(${lib}
|
||||
PRIVATE ${LIBC_HERMETIC_TEST_COMPILE_OPTIONS} -ffreestanding -nostdlib -nostdlib++)
|
||||
endforeach()
|
||||
endif()
|
||||
|
@ -9,7 +9,7 @@ function(add_fp_unittest name)
|
||||
|
||||
if(MATH_UNITTEST_NEED_MPFR)
|
||||
if(NOT LIBC_TESTS_CAN_USE_MPFR)
|
||||
message("WARNING: Math test ${name} will be skipped as MPFR library is not available.")
|
||||
message(VERBOSE "Math test ${name} will be skipped as MPFR library is not available.")
|
||||
return()
|
||||
endif()
|
||||
endif()
|
||||
|
@ -54,15 +54,18 @@ add_libc_test(
|
||||
libc.src.__support.CPP.string_view
|
||||
)
|
||||
|
||||
add_libc_test(
|
||||
arg_list_test
|
||||
SUITE
|
||||
libc-support-tests
|
||||
SRCS
|
||||
arg_list_test.cpp
|
||||
DEPENDS
|
||||
libc.src.__support.arg_list
|
||||
)
|
||||
# The GPU does not support varargs currently.
|
||||
if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
add_libc_test(
|
||||
arg_list_test
|
||||
SUITE
|
||||
libc-support-tests
|
||||
SRCS
|
||||
arg_list_test.cpp
|
||||
DEPENDS
|
||||
libc.src.__support.arg_list
|
||||
)
|
||||
endif()
|
||||
|
||||
add_libc_test(
|
||||
uint_test
|
||||
|
@ -1,6 +1,7 @@
|
||||
if(NOT (TARGET libc.src.__support.threads.mutex))
|
||||
if(NOT (TARGET libc.src.__support.threads.mutex) OR LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
# Not all platforms have a mutex implementation. If mutex is unvailable,
|
||||
# we just skip everything about files.
|
||||
# we just skip everything about files. The GPU does not currently support
|
||||
# files as well.
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
@ -90,10 +90,11 @@ TEST_F(LlvmLibcBlockStoreTest, PopulateAndIterateReverse10) {
|
||||
populate_and_iterate<4, 10, true>();
|
||||
}
|
||||
|
||||
TEST_F(LlvmLibcBlockStoreTest, Back) {
|
||||
back_test<false>();
|
||||
back_test<true>();
|
||||
}
|
||||
TEST_F(LlvmLibcBlockStoreTest, Back) { back_test<false>(); }
|
||||
|
||||
// FIXME: Combing this test with the above test makes the AMDGPU backend
|
||||
// generate code which hangs. This should be fixed in the clang compiler.
|
||||
TEST_F(LlvmLibcBlockStoreTest, BackReverse) { back_test<true>(); }
|
||||
|
||||
TEST_F(LlvmLibcBlockStoreTest, Empty) {
|
||||
empty_test<false>();
|
||||
|
@ -1,4 +1,4 @@
|
||||
if(NOT LLVM_LIBC_FULL_BUILD)
|
||||
if(NOT LLVM_LIBC_FULL_BUILD OR LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
return()
|
||||
endif()
|
||||
|
||||
|
@ -318,6 +318,10 @@ add_libc_unittest(
|
||||
libc.src.stdio.setvbuf
|
||||
)
|
||||
|
||||
if(LIBC_TARGET_ARCHITECTURE_IS_GPU)
|
||||
return()
|
||||
endif()
|
||||
|
||||
add_subdirectory(printf_core)
|
||||
add_subdirectory(scanf_core)
|
||||
add_subdirectory(testdata)
|
||||
|
@ -120,7 +120,7 @@ template <auto Func> struct StrrchrTest : public __llvm_libc::testing::Test {
|
||||
}
|
||||
|
||||
void findsLastBehindFirstNullTerminator() {
|
||||
const char src[6] = {'a', 'a', '\0', 'b', '\0', 'c'};
|
||||
static const char src[6] = {'a', 'a', '\0', 'b', '\0', 'c'};
|
||||
// 'b' is behind a null terminator, so should not be found.
|
||||
ASSERT_STREQ(Func(src, 'b'), nullptr);
|
||||
// Same goes for 'c'.
|
||||
|
Loading…
Reference in New Issue
Block a user