-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc][bazel] Add Bazel rules for rand/srand functions. #159617
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
Conversation
These functions are unlikely to be used in the overlay mode (since they are stateful), but internal llvm-libc implementation is used in tests for FMA family of functions, so we need Bazel support for them to ensure proper test coverage.
@llvm/pr-subscribers-libc Author: Alexey Samsonov (vonosmas) ChangesThese functions are unlikely to be used in the overlay mode (since they are stateful), but internal llvm-libc implementation is used in tests for FMA family of functions, so we need Bazel support for them to ensure proper test coverage. Full diff: https://github.com/llvm/llvm-project/pull/159617.diff 2 Files Affected:
diff --git a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
index cee92f2cc56c4..67c292f08be73 100644
--- a/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/BUILD.bazel
@@ -278,6 +278,14 @@ libc_support_library(
hdrs = ["hdr/stdio_overlay.h"],
)
+libc_support_library(
+ name = "hdr_stdlib_macros",
+ hdrs = ["hdr/stdlib_macros.h"],
+ deps = [
+ ":hdr_stdlib_overlay",
+ ],
+)
+
libc_support_library(
name = "hdr_stdlib_overlay",
hdrs = ["hdr/stdlib_overlay.h"],
@@ -5066,6 +5074,41 @@ libc_function(
],
)
+libc_support_library(
+ name = "rand_util",
+ srcs = ["src/stdlib/rand_util.cpp"],
+ hdrs = ["src/stdlib/rand_util.h"],
+ deps = [
+ ":__support_cpp_atomic",
+ ":__support_macros_attributes",
+ ":__support_macros_config",
+ ],
+)
+
+libc_function(
+ name = "rand",
+ srcs = ["src/stdlib/rand.cpp"],
+ hdrs = ["src/stdlib/rand.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":__support_threads_sleep",
+ ":hdr_stdlib_macros",
+ ":rand_util",
+ ],
+)
+
+libc_function(
+ name = "srand",
+ srcs = ["src/stdlib/srand.cpp"],
+ hdrs = ["src/stdlib/srand.h"],
+ deps = [
+ ":__support_common",
+ ":__support_macros_config",
+ ":rand_util",
+ ],
+)
+
libc_support_library(
name = "str_from_util",
hdrs = ["src/stdlib/str_from_util.h"],
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
index ce92ca8caa6f4..fd4389e8c0579 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdlib/BUILD.bazel
@@ -159,6 +159,15 @@ libc_test(
],
)
+libc_test(
+ name = "rand_test",
+ srcs = ["rand_test.cpp"],
+ deps = [
+ "//libc:rand",
+ "//libc:srand",
+ ],
+)
+
libc_test_library(
name = "strfrom_test_helper",
hdrs = ["StrfromTest.h"],
|
If this is only for internal it would probably be better to make an internal randomness function that takes the state as an argument instead of it being a global. I already do that in a few places. |
Good point. Yes, the file in question is |
Yes, we should definitely remove the |
Do you think we should just move the current |
That's what I would assume, we already have a bunch of these floating around so we could consolidate. I have used both 32-bit and 64-bit versions of xorshift* for most of my PRNG needs. You could extract those to a common header and replace the uses there. Off the top of my head, the GPU benchmarks, allocator, and allocator test. Potentially you could replace the implementation of |
These functions are unlikely to be used in the overlay mode (since they are stateful), but internal llvm-libc implementation is used in tests for FMA family of functions, so we need Bazel support for them to ensure proper test coverage.