Skip to content
This repository was archived by the owner on Feb 26, 2025. It is now read-only.

Commit af14922

Browse files
committed
Merge branch "main-lva" in branch
1 parent b52e2a4 commit af14922

File tree

89 files changed

+7310
-1688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+7310
-1688
lines changed

CMakeLists.txt

Lines changed: 122 additions & 1547 deletions
Large diffs are not rendered by default.

Omax.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@
88
-mllvm -enable-dfa-jump-thread \
99
-mllvm -enable-loop-flatten \
1010
-mllvm -enable-unroll-and-jam \
11+
-mllvm -enable-inline-memcpy-ld-st

arm-multilib/CMakeLists.txt

Lines changed: 298 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,298 @@
1+
#
2+
# Copyright (c) 2024, Arm Limited and affiliates.
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# CMake build for a multilib layout of library variants, with each
19+
# variant in a subdirectory and a multilib.yaml file to map flags to
20+
# a variant.
21+
22+
cmake_minimum_required(VERSION 3.20)
23+
24+
project(arm-multilib)
25+
26+
# Root directory of the repo.
27+
set(TOOLCHAIN_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/..)
28+
29+
# Cache variables to be set by user
30+
set(MULTILIB_JSON "" CACHE STRING "JSON file to load library definitions from.")
31+
set(ENABLE_VARIANTS "all" CACHE STRING "Semicolon separated list of variants to build, or \"all\". Must match entries in the json.")
32+
set(C_LIBRARY "picolibc" CACHE STRING "Which C library to use.")
33+
set_property(CACHE C_LIBRARY PROPERTY STRINGS picolibc newlib llvmlibc)
34+
set(LLVM_BINARY_DIR "" CACHE PATH "Path to LLVM toolchain build or install root.")
35+
set(LIBC_HDRGEN "" CACHE PATH "Path to prebuilt lbc-hdrgen if not included in LLVM binaries set by LLVM_BINARY_DIR")
36+
option(
37+
ENABLE_FVP_TESTING
38+
"Tests using FVP need to be explictly enabled."
39+
)
40+
set(
41+
FVP_INSTALL_DIR
42+
"" CACHE STRING
43+
"The directory in which the FVP models are installed. These are not
44+
included in this repository, but can be downloaded by the script
45+
fvp/get_fvps.sh"
46+
)
47+
set(FVP_CONFIG_DIR "${TOOLCHAIN_SOURCE_DIR}/fvp/config" CACHE STRING "The directory in which the FVP models are installed.")
48+
49+
# If a compiler launcher such as ccache has been set, it should be
50+
# passed down to each subproject build.
51+
set(compiler_launcher_cmake_args "")
52+
if(CMAKE_C_COMPILER_LAUNCHER)
53+
list(APPEND compiler_launcher_cmake_args "-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}")
54+
endif()
55+
if(CMAKE_CXX_COMPILER_LAUNCHER)
56+
list(APPEND compiler_launcher_cmake_args "-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}")
57+
endif()
58+
59+
# Arguments to pass down to the library projects.
60+
foreach(arg
61+
LLVM_BINARY_DIR
62+
LIBC_HDRGEN
63+
FVP_INSTALL_DIR
64+
FVP_CONFIG_DIR
65+
)
66+
if(${arg})
67+
list(APPEND passthrough_dirs "-D${arg}=${${arg}}")
68+
endif()
69+
endforeach()
70+
71+
include(ExternalProject)
72+
include(${TOOLCHAIN_SOURCE_DIR}/cmake/fetch_llvm.cmake)
73+
list(APPEND passthrough_dirs "-DFETCHCONTENT_SOURCE_DIR_LLVMPROJECT=${FETCHCONTENT_SOURCE_DIR_LLVMPROJECT}")
74+
if(C_LIBRARY STREQUAL picolibc)
75+
include(${TOOLCHAIN_SOURCE_DIR}/cmake/fetch_picolibc.cmake)
76+
list(APPEND passthrough_dirs "-DFETCHCONTENT_SOURCE_DIR_PICOLIBC=${FETCHCONTENT_SOURCE_DIR_PICOLIBC}")
77+
elseif(C_LIBRARY STREQUAL newlib)
78+
include(${TOOLCHAIN_SOURCE_DIR}/cmake/fetch_newlib.cmake)
79+
list(APPEND passthrough_dirs "-DFETCHCONTENT_SOURCE_DIR_NEWLIB=${FETCHCONTENT_SOURCE_DIR_NEWLIB}")
80+
endif()
81+
82+
# Target for any dependencies to build the runtimes project.
83+
add_custom_target(runtimes-depends)
84+
85+
# If building llvm-libc, ensure libc-hdrgen is available.
86+
if(C_LIBRARY STREQUAL llvmlibc)
87+
if(NOT LIBC_HDRGEN)
88+
if(EXISTS ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
89+
set(LIBC_HDRGEN ${LLVM_BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
90+
else()
91+
ExternalProject_Add(
92+
libc_hdrgen
93+
SOURCE_DIR ${llvmproject_SOURCE_DIR}/llvm
94+
CMAKE_ARGS
95+
-DLLVM_ENABLE_RUNTIMES=libc
96+
-DLLVM_LIBC_FULL_BUILD=ON
97+
-DCMAKE_BUILD_TYPE=Debug
98+
BUILD_COMMAND ${CMAKE_COMMAND} --build . --target libc-hdrgen
99+
INSTALL_COMMAND ${CMAKE_COMMAND} -E true
100+
CONFIGURE_HANDLED_BY_BUILD TRUE
101+
)
102+
ExternalProject_Get_property(libc_hdrgen BINARY_DIR)
103+
set(LIBC_HDRGEN ${BINARY_DIR}/bin/libc-hdrgen${CMAKE_EXECUTABLE_SUFFIX})
104+
add_dependencies(runtimes-depends libc_hdrgen)
105+
endif()
106+
endif()
107+
list(APPEND passthrough_dirs "-DLIBC_HDRGEN=${LIBC_HDRGEN}")
108+
endif()
109+
110+
# Create one target to run all the tests.
111+
add_custom_target(check-${C_LIBRARY})
112+
add_custom_target(check-compiler-rt)
113+
add_custom_target(check-cxx)
114+
add_custom_target(check-cxxabi)
115+
add_custom_target(check-unwind)
116+
117+
add_custom_target(check-all)
118+
add_dependencies(
119+
check-all
120+
check-${C_LIBRARY}
121+
check-compiler-rt
122+
check-cxx
123+
check-cxxabi
124+
check-unwind
125+
)
126+
127+
# Read the JSON file to load a multilib configuration.
128+
file(READ ${MULTILIB_JSON} multilib_json_str)
129+
string(JSON multilib_defs GET ${multilib_json_str} "libs")
130+
131+
string(JSON lib_count LENGTH ${multilib_defs})
132+
math(EXPR lib_count_dec "${lib_count} - 1")
133+
134+
foreach(lib_idx RANGE ${lib_count_dec})
135+
string(JSON lib_def GET ${multilib_defs} ${lib_idx})
136+
string(JSON variant GET ${lib_def} "variant")
137+
138+
if(variant IN_LIST ENABLE_VARIANTS OR ENABLE_VARIANTS STREQUAL "all")
139+
string(JSON variant_multilib_flags GET ${lib_def} "flags")
140+
# Placeholder libraries won't have a json, so store the error in
141+
# a variable so a fatal error isn't generated.
142+
string(JSON variant_json ERROR_VARIABLE json_error GET ${lib_def} "json")
143+
144+
if(NOT variant_json STREQUAL "json-NOTFOUND")
145+
# Sort by target triple
146+
if(variant MATCHES "^aarch64")
147+
set(parent_dir_name aarch64-none-elf)
148+
else()
149+
set(parent_dir_name arm-none-eabi)
150+
endif()
151+
set(destination_directory "${CMAKE_CURRENT_BINARY_DIR}/multilib/${parent_dir_name}/${variant}")
152+
install(
153+
DIRECTORY ${destination_directory}
154+
DESTINATION ${parent_dir_name}
155+
)
156+
set(variant_json_file ${CMAKE_CURRENT_SOURCE_DIR}/json/variants/${variant_json})
157+
158+
# Read info from the variant specific json.
159+
file(READ ${variant_json_file} variant_json_str)
160+
string(JSON test_executor GET ${variant_json_str} "args" "common" "TEST_EXECUTOR")
161+
162+
# FVP testing should default to off, so override any
163+
# settings from the JSON.
164+
if(test_executor STREQUAL "fvp" AND NOT ${ENABLE_FVP_TESTING})
165+
set(additional_cmake_args "-DENABLE_LIBC_TESTS=OFF" "-DENABLE_COMPILER_RT_TESTS=OFF" "-DENABLE_LIBCXX_TESTS=OFF")
166+
set(read_ENABLE_LIBC_TESTS "OFF")
167+
set(read_ENABLE_COMPILER_RT_TESTS "OFF")
168+
set(read_ENABLE_LIBCXX_TESTS "OFF")
169+
else()
170+
# From the json, check which tests are enabled.
171+
foreach(test_enable_var
172+
ENABLE_LIBC_TESTS
173+
ENABLE_COMPILER_RT_TESTS
174+
ENABLE_LIBCXX_TESTS
175+
)
176+
string(JSON read_${test_enable_var} ERROR_VARIABLE json_error GET ${variant_json_str} "args" ${C_LIBRARY} ${test_enable_var})
177+
if(read_${test_enable_var} STREQUAL "json-NOTFOUND")
178+
string(JSON read_${test_enable_var} ERROR_VARIABLE json_error GET ${variant_json_str} "args" "common" ${test_enable_var})
179+
if(read_${test_enable_var} STREQUAL "json-NOTFOUND")
180+
set(read_${test_enable_var} "OFF")
181+
endif()
182+
endif()
183+
endforeach()
184+
endif()
185+
186+
ExternalProject_Add(
187+
runtimes-${variant}
188+
PREFIX ${CMAKE_BINARY_DIR}/lib-builds
189+
SOURCE_DIR ${TOOLCHAIN_SOURCE_DIR}/arm-runtimes
190+
INSTALL_DIR ${destination_directory}
191+
DEPENDS runtimes-depends
192+
CMAKE_ARGS
193+
${compiler_launcher_cmake_args}
194+
${passthrough_dirs}
195+
${additional_cmake_args}
196+
-DVARIANT_JSON=${variant_json_file}
197+
-DC_LIBRARY=${C_LIBRARY}
198+
-DCMAKE_INSTALL_PREFIX=<INSTALL_DIR>
199+
STEP_TARGETS build install
200+
USES_TERMINAL_CONFIGURE FALSE
201+
USES_TERMINAL_BUILD TRUE
202+
USES_TERMINAL_TEST TRUE
203+
LIST_SEPARATOR ,
204+
CONFIGURE_HANDLED_BY_BUILD TRUE
205+
TEST_EXCLUDE_FROM_MAIN TRUE
206+
)
207+
set(check_targets "")
208+
if(read_ENABLE_LIBC_TESTS)
209+
list(APPEND check_targets check-${C_LIBRARY})
210+
endif()
211+
if(read_ENABLE_COMPILER_RT_TESTS)
212+
list(APPEND check_targets check-compiler-rt)
213+
endif()
214+
if(read_ENABLE_LIBCXX_TESTS)
215+
list(APPEND check_targets check-cxx)
216+
list(APPEND check_targets check-cxxabi)
217+
list(APPEND check_targets check-unwind)
218+
endif()
219+
foreach(check_target ${check_targets})
220+
ExternalProject_Add_Step(
221+
runtimes-${variant}
222+
${check_target}
223+
COMMAND "${CMAKE_COMMAND}" --build <BINARY_DIR> --target ${check_target}
224+
USES_TERMINAL TRUE
225+
EXCLUDE_FROM_MAIN TRUE
226+
ALWAYS TRUE
227+
)
228+
ExternalProject_Add_StepTargets(runtimes-${variant} ${check_target})
229+
ExternalProject_Add_StepDependencies(
230+
runtimes-${variant}
231+
${check_target}
232+
runtimes-${variant}-build
233+
)
234+
add_custom_target(${check_target}-${variant})
235+
add_dependencies(${check_target} runtimes-${variant}-${check_target})
236+
add_dependencies(${check_target}-${variant} runtimes-${variant}-${check_target})
237+
endforeach()
238+
239+
# Add the variant to the multilib yaml
240+
string(APPEND multilib_yaml_content "- Dir: ${parent_dir_name}/${variant}\n")
241+
string(APPEND multilib_yaml_content " Flags:\n")
242+
string(REPLACE " " ";" multilib_flags_list ${variant_multilib_flags})
243+
foreach(flag ${multilib_flags_list})
244+
string(APPEND multilib_yaml_content " - ${flag}\n")
245+
endforeach()
246+
string(APPEND multilib_yaml_content " Group: stdlibs\n")
247+
else()
248+
# In place of a json, an error message is expected.
249+
string(JSON variant_error_msg GET ${lib_def} "error")
250+
251+
string(APPEND multilib_yaml_content "- Error: \"${variant_error_msg}\"\n")
252+
string(APPEND multilib_yaml_content " Flags:\n")
253+
string(REPLACE " " ";" multilib_flags_list ${variant_multilib_flags})
254+
foreach(flag ${multilib_flags_list})
255+
string(APPEND multilib_yaml_content " - ${flag}\n")
256+
endforeach()
257+
string(APPEND multilib_yaml_content " Group: stdlibs\n")
258+
endif()
259+
endif()
260+
261+
endforeach()
262+
263+
# Multilib file is generated in two parts.
264+
# 1. Template is filled with multilib flags from json
265+
configure_file(
266+
${CMAKE_CURRENT_SOURCE_DIR}/multilib.yaml.in
267+
${CMAKE_CURRENT_BINARY_DIR}/multilib-without-fpus.yaml
268+
@ONLY
269+
)
270+
271+
# 2. multilib-generate.py maps compiler command line options to flags
272+
add_custom_command(
273+
OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/multilib-fpus.yaml
274+
COMMAND ${Python3_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/multilib-generate.py"
275+
"--clang=${LLVM_BINARY_DIR}/bin/clang${CMAKE_EXECUTABLE_SUFFIX}"
276+
"--llvm-source=${FETCHCONTENT_SOURCE_DIR_LLVMPROJECT}"
277+
>> ${CMAKE_CURRENT_BINARY_DIR}/multilib-fpus.yaml
278+
)
279+
280+
# Combine the two parts.
281+
add_custom_command(
282+
OUTPUT
283+
${CMAKE_CURRENT_BINARY_DIR}/multilib/multilib.yaml
284+
COMMAND
285+
${CMAKE_COMMAND} -E cat
286+
${CMAKE_CURRENT_BINARY_DIR}/multilib-without-fpus.yaml
287+
${CMAKE_CURRENT_BINARY_DIR}/multilib-fpus.yaml
288+
> ${CMAKE_CURRENT_BINARY_DIR}/multilib/multilib.yaml
289+
DEPENDS
290+
${CMAKE_CURRENT_BINARY_DIR}/multilib-without-fpus.yaml
291+
${CMAKE_CURRENT_BINARY_DIR}/multilib-fpus.yaml
292+
)
293+
294+
add_custom_target(multilib-yaml ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/multilib/multilib.yaml)
295+
install(
296+
FILES ${CMAKE_CURRENT_BINARY_DIR}/multilib/multilib.yaml
297+
DESTINATION .
298+
)

0 commit comments

Comments
 (0)