Debian Codegraph @

utils/bazel/llvm-project-overlay/compiler-rt/BUILD.bazel

raw
1 # This file is licensed under the Apache License v2.0 with LLVM Exceptions.
2 # See https://llvm.org/LICENSE.txt for license information.
3 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5 load("@rules_cc//cc:defs.bzl", "cc_library")
6
7 package(
8 default_visibility = ["//visibility:public"],
9 features = ["layering_check"],
10 )
11
12 licenses(["notice"])
13
14 cc_library(
15 name = "config",
16 defines = select({
17 "@platforms//os:linux": [
18 "COMPILER_RT_HAS_ATOMICS=1",
19 "COMPILER_RT_HAS_FCNTL_LCK=1",
20 "COMPILER_RT_HAS_UNAME=1",
21 ],
22 # Will raise error unless supported platforms.
23 }),
24 target_compatible_with = select({
25 "@platforms//os:linux": [],
26 "//conditions:default": ["@platforms//:incompatible"],
27 }),
28 )
29
30 WIN32_ONLY_FILES = [
31 "lib/profile/WindowsMMap.c",
32 ]
33
34 cc_library(
35 name = "profile",
36 srcs = glob(
37 [
38 "lib/profile/*.c",
39 "lib/profile/*.cpp",
40 "lib/profile/*.h",
41 ],
42 exclude = WIN32_ONLY_FILES,
43 ) + select({
44 "@platforms//os:windows": WIN32_ONLY_FILES,
45 "//conditions:default": [],
46 }),
47 hdrs = glob([
48 "include/profile/*.h",
49 "include/profile/*.inc",
50 ]),
51 includes = [
52 "include",
53 ],
54 linkstatic = True,
55 deps = [
56 ":config",
57 ],
58 )
59
60 cc_library(
61 name = "orc_rt_common_headers",
62 hdrs = [
63 "lib/orc/adt.h",
64 "lib/orc/bitmask_enum.h",
65 "lib/orc/common.h",
66 "lib/orc/compiler.h",
67 "lib/orc/debug.h",
68 "lib/orc/endianness.h",
69 "lib/orc/error.h",
70 "lib/orc/executor_address.h",
71 "lib/orc/executor_symbol_def.h",
72 "lib/orc/interval_map.h",
73 "lib/orc/interval_set.h",
74 "lib/orc/jit_dispatch.h",
75 "lib/orc/record_section_tracker.h",
76 "lib/orc/rtti.h",
77 "lib/orc/simple_packed_serialization.h",
78 "lib/orc/stl_extras.h",
79 "lib/orc/string_pool.h",
80 "lib/orc/unique_function.h",
81 "lib/orc/wrapper_function_utils.h",
82 ],
83 strip_include_prefix = "lib/orc",
84 )
85
86 cc_library(
87 name = "orc_rt",
88 srcs = [
89 "lib/orc/debug.cpp",
90 "lib/orc/dlfcn_wrapper.cpp",
91 "lib/orc/log_error_to_stderr.cpp",
92 "lib/orc/rtti.cpp",
93 "lib/orc/run_program_wrapper.cpp",
94 ] + select({
95 "@platforms//os:macos": [
96 "lib/orc/macho_platform.cpp",
97 "lib/orc/macho_platform.h",
98 "lib/orc/macho_tlv.arm64.S",
99 "lib/orc/macho_tlv.x86-64.S",
100 ],
101 "@platforms//os:linux": [
102 "lib/orc/elfnix_platform.cpp",
103 "lib/orc/elfnix_platform.h",
104 "lib/orc/elfnix_tls.aarch64.S",
105 "lib/orc/elfnix_tls.ppc64.S",
106 "lib/orc/elfnix_tls.x86-64.S",
107 ],
108 }),
109 hdrs = glob(["include/orc_rt/*.h"]),
110 includes = ["include"],
111 linkstatic = True,
112 deps = [
113 ":orc_rt_common_headers",
114 ],
115 )
116
117 filegroup(
118 name = "fuzzer_installed_hdrs",
119 srcs = glob(["include/fuzzer/*.h"]),
120 )
121
122 filegroup(
123 name = "profile_installed_hdrs",
124 srcs = glob(["include/profile/*.h"]),
125 )
126
127 filegroup(
128 name = "sanitizer_installed_hdrs",
129 srcs = glob(["include/sanitizer/*.h"]),
130 )
131
132 BUILTINS_CRTBEGIN_SRCS = ["lib/builtins/crtbegin.c"]
133
134 filegroup(
135 name = "builtins_crtbegin_src",
136 srcs = BUILTINS_CRTBEGIN_SRCS,
137 )
138
139 BUILTINS_CRTEND_SRCS = ["lib/builtins/crtend.c"]
140
141 filegroup(
142 name = "builtins_crtend_src",
143 srcs = BUILTINS_CRTEND_SRCS,
144 )
145
146 BUILTINS_HOSTED_SRCS = [
147 "lib/builtins/clear_cache.c",
148 "lib/builtins/emutls.c",
149 "lib/builtins/enable_execute_stack.c",
150 "lib/builtins/eprintf.c",
151 ]
152
153 # Source files in the builtins library that build on top of libc and are only
154 # appropriate in hosted environments.
155 filegroup(
156 name = "builtins_hosted_srcs",
157 srcs = BUILTINS_HOSTED_SRCS,
158 )
159
160 BUILTINS_BF16_SRCS_PATTERNS = [
161 "lib/builtins/*bf*.c",
162 ]
163
164 # Source files for the 16-bit Brain floating-point number builtins.
165 filegroup(
166 name = "builtins_bf16_srcs",
167 srcs = glob(BUILTINS_BF16_SRCS_PATTERNS),
168 )
169
170 BUILTINS_X86_FP80_SRCS_PATTERNS = [
171 # `xc` marks 80-bit complex number builtins.
172 "lib/builtins/*xc*.c",
173
174 # `xf` marks 80-bit floating-point builtins.
175 "lib/builtins/*xf*.c",
176 ]
177
178 # Source files for the 80-bit floating-point and complex number builtins.
179 filegroup(
180 name = "builtins_x86_fp80_srcs",
181 srcs = glob(
182 BUILTINS_X86_FP80_SRCS_PATTERNS,
183 exclude = BUILTINS_BF16_SRCS_PATTERNS,
184 ),
185 )
186
187 BUILTINS_TF_SRCS_PATTERNS = [
188 # `tc` marks 128-bit complex number builtins.
189 "lib/builtins/*tc*.c",
190
191 # `tf` marks 128-bit floating-point builtins.
192 "lib/builtins/*tf*.c",
193 ]
194
195 BUILTINS_TF_EXCLUDES = (
196 BUILTINS_HOSTED_SRCS +
197 BUILTINS_BF16_SRCS_PATTERNS +
198 BUILTINS_X86_FP80_SRCS_PATTERNS
199 )
200
201 # Source files for the 128-bit floating-point and complex number builtins.
202 filegroup(
203 name = "builtins_tf_srcs",
204 srcs = glob(
205 BUILTINS_TF_SRCS_PATTERNS,
206 exclude = BUILTINS_TF_EXCLUDES,
207 ),
208 )
209
210 BUILTNS_ATOMICS_SRCS = ["lib/builtins/atomic.c"]
211
212 filegroup(
213 name = "builtins_atomics_srcs",
214 srcs = BUILTNS_ATOMICS_SRCS + ["lib/builtins/assembly.h"],
215 )
216
217 BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS = [
218 "lib/builtins/atomic_*.c",
219 ]
220
221 # Source files for macOS atomic builtins.
222 filegroup(
223 name = "builtins_macos_atomic_srcs",
224 srcs = glob(BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS),
225 )
226
227 # Apple-platform specific SME source file.
228 filegroup(
229 name = "builtins_aarch64_apple_sme_srcs",
230 srcs = ["lib/builtins/aarch64/arm_apple_sme_abi.s"],
231 )
232
233 # Non-Apple platform SME sources. These sources assume function
234 # multi-versioning, `-fno-builtin`, `__ARM_UNALIGNED` feature support, and FP
235 # availability. Other configurations will need to add a new filegroup if
236 # desired.
237 filegroup(
238 name = "builtins_aarch64_sme_srcs",
239 srcs = [
240 "lib/builtins/aarch64/sme-abi.S",
241 "lib/builtins/aarch64/sme-abi-assert.c",
242 ] + glob(["lib/builtins/aarch64/sme-libc-opt-*.S"]),
243 )
244
245 # A list of (pat, size, model) tuples for AArch64's outline atomics.
246 AARCH64_OUTLINE_ATOMICS = [
247 (pat, size, model)
248 for pat in [
249 "cas",
250 "swp",
251 "ldadd",
252 "ldclr",
253 "ldeor",
254 "ldset",
255 ]
256 for size in [
257 "1",
258 "2",
259 "4",
260 "8",
261 "16",
262 ]
263 for model in [
264 "1",
265 "2",
266 "3",
267 "4",
268 ]
269 if pat == "cas" or size != "16"
270 ]
271
272 AARCH64_OUTLINE_ATOMICS_FMT = "lib/builtins/aarch64/outline_atomic_{0}{1}_{2}.S"
273
274 # lse.S is compiled multiple times with different macros as the input. Model
275 # this as a genrule producing individual files with the macros at the start.
276 [[genrule(
277 name = "builtins_aarch64_outline_atomic_" + pat + size + "_" + model,
278 srcs = ["lib/builtins/aarch64/lse.S"],
279 outs = [AARCH64_OUTLINE_ATOMICS_FMT.format(pat, size, model)],
280 cmd = (
281 "echo '#define L_" + pat + "' >> $(OUTS) && " +
282 "echo '#define SIZE " + size + "' >> $(OUTS) && " +
283 "echo '#define MODEL " + model + "' >> $(OUTS) && " +
284 "cat $(SRCS) >> $(OUTS)"
285 ),
286 )] for (pat, size, model) in AARCH64_OUTLINE_ATOMICS]
287
288 # Source files for the AArch64 architecture-specific builtins.
289 filegroup(
290 name = "builtins_aarch64_srcs",
291 srcs = [
292 "lib/builtins/cpu_model/aarch64.c",
293 "lib/builtins/cpu_model/aarch64.h",
294 ] + [
295 AARCH64_OUTLINE_ATOMICS_FMT.format(pat, size, model)
296 for (pat, size, model) in AARCH64_OUTLINE_ATOMICS
297 ] + glob(
298 [
299 "lib/builtins/cpu_model/AArch64*.inc",
300 "lib/builtins/cpu_model/aarch64/**/*.inc",
301 "lib/builtins/aarch64/*.S",
302 "lib/builtins/aarch64/*.c",
303 "lib/builtins/aarch64/*.cpp",
304 ],
305 allow_empty = True,
306 exclude = [
307 # This file isn't intended to directly compile, and instead is used
308 # above to generate a collection of outline atomic helpers.
309 "lib/builtins/aarch64/lse.S",
310 # These files are provided by SME-specific file groups above.
311 "lib/builtins/aarch64/*sme*",
312 ],
313 ),
314 )
315
316 BUILTINS_ARM_VFP_SRCS_PATTERNS = [
317 "lib/builtins/arm/*vfp*.S",
318 "lib/builtins/arm/*vfp*.c",
319 "lib/builtins/arm/*vfp*.cpp",
320 ]
321
322 # Source files for the ARM VFP-specific builtins.
323 filegroup(
324 name = "builtins_arm_vfp_srcs",
325 srcs = glob(
326 BUILTINS_ARM_VFP_SRCS_PATTERNS,
327 allow_empty = True,
328 ),
329 )
330
331 # Source files for the ARM architecture-specific builtins.
332 filegroup(
333 name = "builtins_arm_srcs",
334 srcs = glob(
335 [
336 "lib/builtins/arm/*.S",
337 "lib/builtins/arm/*.c",
338 "lib/builtins/arm/*.cpp",
339 ],
340 allow_empty = True,
341 exclude = BUILTINS_ARM_VFP_SRCS_PATTERNS,
342 ),
343 )
344
345 # Source files for the PPC architecture-specific builtins.
346 filegroup(
347 name = "builtins_ppc_srcs",
348 srcs = glob(
349 [
350 "lib/builtins/ppc/*.S",
351 "lib/builtins/ppc/*.c",
352 "lib/builtins/ppc/*.cpp",
353 ],
354 allow_empty = True,
355 ),
356 )
357
358 # Source files for the RISC-V architecture-specific builtins.
359 filegroup(
360 name = "builtins_riscv_srcs",
361 srcs = glob(
362 [
363 "lib/builtins/riscv/*.S",
364 "lib/builtins/riscv/*.c",
365 "lib/builtins/riscv/*.cpp",
366 ],
367 allow_empty = True,
368 ),
369 )
370
371 # Source files for the x86 architecture specific builtins (both 32-bit and
372 # 64-bit).
373 filegroup(
374 name = "builtins_x86_arch_srcs",
375 srcs = [
376 "lib/builtins/cpu_model/x86.c",
377 "lib/builtins/i386/fp_mode.c",
378 ],
379 )
380
381 # Source files for the x86-64 architecture specific builtins.
382 filegroup(
383 name = "builtins_x86_64_srcs",
384 srcs = glob(
385 [
386 "lib/builtins/x86_64/*.S",
387 "lib/builtins/x86_64/*.c",
388 "lib/builtins/x86_64/*.cpp",
389 ],
390 allow_empty = True,
391 ),
392 )
393
394 # Source files for the 32-bit-specific x86 architecture specific builtins.
395 filegroup(
396 name = "builtins_i386_srcs",
397 srcs = glob(
398 [
399 "lib/builtins/i386/*.S",
400 "lib/builtins/i386/*.c",
401 "lib/builtins/i386/*.cpp",
402 ],
403 allow_empty = True,
404 exclude = [
405 # This file is used for both i386 and x86_64 and so included in the
406 # broader x86 sources.
407 "lib/builtins/i386/fp_mode.c",
408 ],
409 ),
410 )
411
412 # Source files for portable components of the compiler builtins library.
413 filegroup(
414 name = "builtins_generic_srcs",
415 srcs = ["lib/builtins/cpu_model/cpu_model.h"] + glob(
416 [
417 "lib/builtins/*.c",
418 "lib/builtins/*.cpp",
419 "lib/builtins/*.h",
420 "lib/builtins/*.inc",
421 ],
422 allow_empty = True,
423 exclude = (
424 BUILTINS_CRTBEGIN_SRCS +
425 BUILTINS_CRTEND_SRCS +
426 BUILTINS_TF_EXCLUDES +
427 BUILTINS_TF_SRCS_PATTERNS +
428 BUILTNS_ATOMICS_SRCS +
429 BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS
430 ),
431 ),
432 )