[llvm] [Bazel] Export compiler-rt builtins sources (PR #157200)
Chandler Carruth via llvm-commits
llvm-commits at lists.llvm.org
Sat Sep 6 17:27:36 PDT 2025
================
@@ -113,3 +113,305 @@ cc_library(
":orc_rt_common_headers",
],
)
+
+BUILTINS_CRTBEGIN_SRCS = ["lib/builtins/crtbegin.c"]
+
+filegroup(
+ name = "builtins_crtbegin_src",
+ srcs = BUILTINS_CRTBEGIN_SRCS,
+)
+
+BUILTINS_CRTEND_SRCS = ["lib/builtins/crtend.c"]
+
+filegroup(
+ name = "builtins_crtend_src",
+ srcs = BUILTINS_CRTEND_SRCS,
+)
+
+BUILTINS_HOSTED_SRCS = [
+ "lib/builtins/clear_cache.c",
+ "lib/builtins/emutls.c",
+ "lib/builtins/enable_execute_stack.c",
+ "lib/builtins/eprintf.c",
+]
+
+# Source files in the builtins library that build on top of libc and are only
+# appropriate in hosted environments.
+filegroup(
+ name = "builtins_hosted_srcs",
+ srcs = BUILTINS_HOSTED_SRCS,
+)
+
+BUILTINS_BF16_SRCS_PATTERNS = [
+ "lib/builtins/*bf*.c",
+]
+
+# Source files for the 16-bit Brain floating-point number builtins.
+filegroup(
+ name = "builtins_bf16_srcs",
+ srcs = glob(BUILTINS_BF16_SRCS_PATTERNS),
+)
+
+BUILTINS_X86_FP80_SRCS_PATTERNS = [
+ # `xc` marks 80-bit complex number builtins.
+ "lib/builtins/*xc*.c",
+
+ # `xf` marks 80-bit floating-point builtins.
+ "lib/builtins/*xf*.c",
+]
+
+# Source files for the 80-bit floating-point and complex number builtins.
+filegroup(
+ name = "builtins_x86_fp80_srcs",
+ srcs = glob(
+ BUILTINS_X86_FP80_SRCS_PATTERNS,
+ exclude = BUILTINS_BF16_SRCS_PATTERNS,
+ ),
+)
+
+BUILTINS_TF_SRCS_PATTERNS = [
+ # `tc` marks 128-bit complex number builtins.
+ "lib/builtins/*tc*.c",
+
+ # `tf` marks 128-bit floating-point builtins.
+ "lib/builtins/*tf*.c",
+]
+
+BUILTINS_TF_EXCLUDES = (
+ BUILTINS_HOSTED_SRCS +
+ BUILTINS_BF16_SRCS_PATTERNS +
+ BUILTINS_X86_FP80_SRCS_PATTERNS
+)
+
+# Source files for the 128-bit floating-point and complex number builtins.
+filegroup(
+ name = "builtins_tf_srcs",
+ srcs = glob(
+ BUILTINS_TF_SRCS_PATTERNS,
+ exclude = BUILTINS_TF_EXCLUDES,
+ ),
+)
+
+BUILTNS_ATOMICS_SRCS = ["lib/builtins/atomic.c"]
+
+filegroup(
+ name = "builtins_atomics_srcs",
+ srcs = BUILTNS_ATOMICS_SRCS + ["lib/builtins/assembly.h"],
+)
+
+BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS = [
+ "lib/builtins/atomic_*.c",
+]
+
+# Source files for macOS atomic builtins.
+filegroup(
+ name = "builtins_macos_atomic_srcs",
+ srcs = glob(BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS),
+)
+
+# Apple-platform specific SME source file.
+filegroup(
+ name = "builtins_aarch64_apple_sme_srcs",
+ srcs = ["lib/builtins/aarch64/arm_apple_sme_abi.s"],
+)
+
+# Non-Apple platform SME sources. These sources assume function
+# multi-versioning, `-fno-builtin`, `__ARM_UNALIGNED` feature support, and FP
+# availability. Other configurations will need to add a new filegroup if
+# desired.
+filegroup(
+ name = "builtins_aarch64_sme_srcs",
+ srcs = [
+ "lib/builtins/aarch64/sme-abi.S",
+ "lib/builtins/aarch64/sme-abi-assert.c",
+ ] + glob(["lib/builtins/aarch64/sme-libc-opt-*.S"]),
+)
+
+# A list of (pat, size, model) tuples for AArch64's outline atomics.
+AARCH64_OUTLINE_ATOMICS = [
+ (pat, size, model)
+ for pat in [
+ "cas",
+ "swp",
+ "ldadd",
+ "ldclr",
+ "ldeor",
+ "ldset",
+ ]
+ for size in [
+ "1",
+ "2",
+ "4",
+ "8",
+ "16",
+ ]
+ for model in [
+ "1",
+ "2",
+ "3",
+ "4",
+ ]
+ if pat == "cas" or size != "16"
+]
+
+AARCH64_OUTLINE_ATOMICS_FMT = "lib/builtins/aarch64/outline_atomic_{0}{1}_{2}.S"
+
+# lse.S is compiled multiple times with different macros as the input. Model
+# this as a genrule producing individual files with the macros at the start.
+[[genrule(
+ name = "builtins_aarch64_outline_atomic_" + pat + size + "_" + model,
+ srcs = ["lib/builtins/aarch64/lse.S"],
+ outs = [AARCH64_OUTLINE_ATOMICS_FMT.format(pat, size, model)],
+ cmd = (
+ "echo '#define L_" + pat + "' >> $(OUTS) && " +
+ "echo '#define SIZE " + size + "' >> $(OUTS) && " +
+ "echo '#define MODEL " + model + "' >> $(OUTS) && " +
+ "cat $(SRCS) >> $(OUTS)"
+ ),
+)] for (pat, size, model) in AARCH64_OUTLINE_ATOMICS]
----------------
chandlerc wrote:
My thought was precisely that by keeping these as `.S` files we can have `clang` do this for us while assembling.
Downstream, this pattern has been working well for some time, so I'm hesitant to change it to a more complex thing at this stage. We can revisit of course if anyone encounters problems with this approach.
https://github.com/llvm/llvm-project/pull/157200
More information about the llvm-commits
mailing list