@@ -113,3 +113,285 @@ cc_library(
113113        ":orc_rt_common_headers" ,
114114    ],
115115)
116+ 
117+ BUILTINS_CRTBEGIN_SRCS  =  ["lib/builtins/crtbegin.c" ]
118+ 
119+ filegroup (
120+     name  =  "builtins_crtbegin_src" ,
121+     srcs  =  BUILTINS_CRTBEGIN_SRCS ,
122+ )
123+ 
124+ BUILTINS_CRTEND_SRCS  =  ["lib/builtins/crtend.c" ]
125+ 
126+ filegroup (
127+     name  =  "builtins_crtend_src" ,
128+     srcs  =  BUILTINS_CRTEND_SRCS ,
129+ )
130+ 
131+ BUILTINS_HOSTED_SRCS  =  [
132+     "lib/builtins/clear_cache.c" ,
133+     "lib/builtins/emutls.c" ,
134+     "lib/builtins/enable_execute_stack.c" ,
135+     "lib/builtins/eprintf.c" ,
136+ ]
137+ 
138+ # Source files in the builtins library that build on top of libc and are only 
139+ # appropriate in hosted environments. 
140+ filegroup (
141+     name  =  "builtins_hosted_srcs" ,
142+     srcs  =  BUILTINS_HOSTED_SRCS ,
143+ )
144+ 
145+ BUILTINS_BF16_SRCS_PATTERNS  =  [
146+     "lib/builtins/*bf*.c" ,
147+ ]
148+ 
149+ # Source files for the 16-bit Brain floating-point number builtins. 
150+ filegroup (
151+     name  =  "builtins_bf16_srcs" ,
152+     srcs  =  glob (
153+         BUILTINS_BF16_SRCS_PATTERNS ,
154+         allow_empty  =  True ,
155+     ),
156+ )
157+ 
158+ BUILTINS_X86_FP80_SRCS_PATTERNS  =  [
159+     # `xc` marks 80-bit complex number builtins. 
160+     "lib/builtins/*xc*.c" ,
161+ 
162+     # `xf` marks 80-bit floating-point builtins. 
163+     "lib/builtins/*xf*.c" ,
164+ ]
165+ 
166+ # Source files for the 80-bit floating-point and complex number builtins. 
167+ filegroup (
168+     name  =  "builtins_x86_fp80_srcs" ,
169+     srcs  =  glob (
170+         BUILTINS_X86_FP80_SRCS_PATTERNS ,
171+         allow_empty  =  True ,
172+         exclude  =  BUILTINS_BF16_SRCS_PATTERNS ,
173+     ),
174+ )
175+ 
176+ BUILTINS_TF_SRCS_PATTERNS  =  [
177+     # `tc` marks 128-bit complex number builtins. 
178+     "lib/builtins/*tc*.c" ,
179+ 
180+     # `tf` marks 128-bit floating-point builtins. 
181+     "lib/builtins/*tf*.c" ,
182+ ]
183+ 
184+ BUILTINS_TF_EXCLUDES  =  (
185+     BUILTINS_HOSTED_SRCS  + 
186+     BUILTINS_BF16_SRCS_PATTERNS  + 
187+     BUILTINS_X86_FP80_SRCS_PATTERNS 
188+ )
189+ 
190+ # Source files for the 128-bit floating-point and complex number builtins. 
191+ filegroup (
192+     name  =  "builtins_tf_srcs" ,
193+     srcs  =  glob (
194+         BUILTINS_TF_SRCS_PATTERNS ,
195+         allow_empty  =  True ,
196+         exclude  =  BUILTINS_TF_EXCLUDES ,
197+     ),
198+ )
199+ 
200+ BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS  =  [
201+     "lib/builtins/atomic_*.c" ,
202+ ]
203+ 
204+ # Source files for macOS atomic builtins. 
205+ filegroup (
206+     name  =  "builtins_macos_atomic_srcs" ,
207+     srcs  =  glob (
208+         BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS ,
209+         allow_empty  =  True ,
210+     ),
211+ )
212+ 
213+ # A list of (pat, size, model) tuples for AArch64's outline atomics. 
214+ AARCH64_OUTLINE_ATOMICS  =  [
215+     (pat , size , model )
216+     for  pat  in  [
217+         "cas" ,
218+         "swp" ,
219+         "ldadd" ,
220+         "ldclr" ,
221+         "ldeor" ,
222+         "ldset" ,
223+     ]
224+     for  size  in  [
225+         "1" ,
226+         "2" ,
227+         "4" ,
228+         "8" ,
229+         "16" ,
230+     ]
231+     for  model  in  [
232+         "1" ,
233+         "2" ,
234+         "3" ,
235+         "4" ,
236+     ]
237+     if  pat  ==  "cas"  or  size  !=  "16" 
238+ ]
239+ 
240+ AARCH64_OUTLINE_ATOMICS_FMT  =  "lib/builtins/aarch64/outline_atomic_{0}_{1}_{2}.S" 
241+ 
242+ # lse.S is compiled multiple times with different macros as the input. Model 
243+ # this as a genrule producing individual files with the macros at the start. 
244+ [[genrule (
245+     name  =  "builtins_aarch64_outline_atomic_"  +  pat  +  size  +  "_"  +  model ,
246+     srcs  =  ["lib/builtins/aarch64/lse.S" ],
247+     outs  =  [AARCH64_OUTLINE_ATOMICS_FMT .format (pat , size , model )],
248+     cmd  =  (
249+         "echo '#define L_"  +  pat  +  "' >> $(OUTS) && "  + 
250+         "echo '#define SIZE "  +  size  +  "' >> $(OUTS) && "  + 
251+         "echo '#define MODEL "  +  model  +  "' >> $(OUTS) && "  + 
252+         "cat $(SRCS) >> $(OUTS)" 
253+     ),
254+ )] for  (pat , size , model ) in  AARCH64_OUTLINE_ATOMICS ]
255+ 
256+ # Source files for the AArch64 architecture-specific builtins. 
257+ filegroup (
258+     name  =  "builtins_aarch64_srcs" ,
259+     srcs  =  [
260+         "lib/builtins/cpu_model/aarch64.c" ,
261+         "lib/builtins/cpu_model/aarch64.h" ,
262+     ] +  [
263+         AARCH64_OUTLINE_ATOMICS_FMT .format (pat , size , model )
264+         for  (pat , size , model ) in  AARCH64_OUTLINE_ATOMICS 
265+     ] +  glob (
266+         [
267+             "lib/builtins/cpu_model/AArch64*.inc" ,
268+             "lib/builtins/cpu_model/aarch64/**/*.inc" ,
269+             "lib/builtins/aarch64/*.S" ,
270+             "lib/builtins/aarch64/*.c" ,
271+             "lib/builtins/aarch64/*.cpp" ,
272+         ],
273+         allow_empty  =  True ,
274+         exclude  =  [
275+             # This file isn't intended to directly compile, and instead is used 
276+             # above to generate a collection of outline atomic helpers. 
277+             "lib/builtins/aarch64/lse.S" ,
278+         ],
279+     ),
280+ )
281+ 
282+ BUILTINS_ARM_VFP_SRCS_PATTERNS  =  [
283+     "lib/builtins/arm/*vfp*.S" ,
284+     "lib/builtins/arm/*vfp*.c" ,
285+     "lib/builtins/arm/*vfp*.cpp" ,
286+ ]
287+ 
288+ # Source files for the ARM VFP-specific builtins. 
289+ filegroup (
290+     name  =  "builtins_arm_vfp_srcs" ,
291+     srcs  =  glob (
292+         BUILTINS_ARM_VFP_SRCS_PATTERNS ,
293+         allow_empty  =  True ,
294+     ),
295+ )
296+ 
297+ # Source files for the ARM architecture-specific builtins. 
298+ filegroup (
299+     name  =  "builtins_arm_srcs" ,
300+     srcs  =  glob (
301+         [
302+             "lib/builtins/arm/*.S" ,
303+             "lib/builtins/arm/*.c" ,
304+             "lib/builtins/arm/*.cpp" ,
305+         ],
306+         allow_empty  =  True ,
307+         exclude  =  BUILTINS_ARM_VFP_SRCS_PATTERNS ,
308+     ),
309+ )
310+ 
311+ # Source files for the PPC architecture-specific builtins. 
312+ filegroup (
313+     name  =  "builtins_ppc_srcs" ,
314+     srcs  =  glob (
315+         [
316+             "lib/builtins/ppc/*.S" ,
317+             "lib/builtins/ppc/*.c" ,
318+             "lib/builtins/ppc/*.cpp" ,
319+         ],
320+         allow_empty  =  True ,
321+     ),
322+ )
323+ 
324+ # Source files for the RISC-V architecture-specific builtins. 
325+ filegroup (
326+     name  =  "builtins_riscv_srcs" ,
327+     srcs  =  glob (
328+         [
329+             "lib/builtins/riscv/*.S" ,
330+             "lib/builtins/riscv/*.c" ,
331+             "lib/builtins/riscv/*.cpp" ,
332+         ],
333+         allow_empty  =  True ,
334+     ),
335+ )
336+ 
337+ # Source files for the x86 architecture specific builtins (both 32-bit and 
338+ # 64-bit). 
339+ filegroup (
340+     name  =  "builtins_x86_arch_srcs" ,
341+     srcs  =  [
342+         "lib/builtins/cpu_model/x86.c" ,
343+         "lib/builtins/i386/fp_mode.c" ,
344+     ],
345+ )
346+ 
347+ # Source files for the x86-64 architecture specific builtins. 
348+ filegroup (
349+     name  =  "builtins_x86_64_srcs" ,
350+     srcs  =  glob (
351+         [
352+             "lib/builtins/x86_64/*.c" ,
353+             "lib/builtins/x86_64/*.cpp" ,
354+             "lib/builtins/x86_64/*.S" ,
355+         ],
356+         allow_empty  =  True ,
357+     ),
358+ )
359+ 
360+ # Source files for the 32-bit-specific x86 architecture specific builtins. 
361+ filegroup (
362+     name  =  "builtins_i386_srcs" ,
363+     srcs  =  glob (
364+         [
365+             "lib/builtins/i386/*.S" ,
366+             "lib/builtins/i386/*.c" ,
367+             "lib/builtins/i386/*.cpp" ,
368+         ],
369+         allow_empty  =  True ,
370+         exclude  =  [
371+             # This file is used for both i386 and x86_64 and so included in the 
372+             # broader x86 sources. 
373+             "lib/builtins/i386/fp_mode.c" ,
374+         ],
375+     ),
376+ )
377+ 
378+ # Source files for portable components of the compiler builtins library. 
379+ filegroup (
380+     name  =  "builtins_generic_srcs" ,
381+     srcs  =  ["lib/builtins/cpu_model/cpu_model.h" ] +  glob (
382+         [
383+             "lib/builtins/*.c" ,
384+             "lib/builtins/*.cpp" ,
385+             "lib/builtins/*.h" ,
386+             "lib/builtins/*.inc" ,
387+         ],
388+         allow_empty  =  True ,
389+         exclude  =  (
390+             BUILTINS_CRTBEGIN_SRCS  + 
391+             BUILTINS_CRTEND_SRCS  + 
392+             BUILTINS_TF_EXCLUDES  + 
393+             BUILTINS_TF_SRCS_PATTERNS  + 
394+             BUILTINS_MACOS_ATOMIC_SRCS_PATTERNS 
395+         ),
396+     ),
397+ )
0 commit comments