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

Commit 0ae9ce0

Browse files
committed
[Weekly]: Merge from branch main of upstream
1 parent e198a2e commit 0ae9ce0

20 files changed

+688
-45
lines changed

CMakeLists.txt

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ option(
134134
the tools every time you update llvm-project."
135135
ON
136136
)
137+
option(
138+
APPLY_LLVM_PERFORMANCE_PATCHES
139+
"During checkout, apply optional downstream patches to
140+
llvm-project to improve performance."
141+
)
137142
set(
138143
FVP_INSTALL_DIR
139144
"${CMAKE_CURRENT_SOURCE_DIR}/fvp/install" CACHE STRING
@@ -281,24 +286,17 @@ if(NOT (LLVM_TOOLCHAIN_C_LIBRARY STREQUAL llvmlibc)) # libc in a separate repo?
281286
read_repo_version(${LLVM_TOOLCHAIN_C_LIBRARY} ${LLVM_TOOLCHAIN_C_LIBRARY})
282287
endif()
283288

284-
# The patches are generated from custom branch, with followin command:
285-
# git format-patch -k origin/main
286-
# The patches apply cleanly against llvm-project commit
287-
# 327124ece7d59de56ca0f9faa2cd82af68c011b9.
288-
set(
289-
llvm_project_patches
290-
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0001-libc-tests-with-picolibc-xfail-one-remaining-test.patch
291-
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0002-libc-tests-with-picolibc-disable-large-tests.patch
292-
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0003-Disable-failing-compiler-rt-test.patch
293-
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0004-libc-tests-with-picolibc-XFAIL-uses-of-atomics.patch
294-
${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project/0005-libc-tests-with-picolibc-mark-two-more-large-tests.patch
295-
)
289+
set(LLVM_PATCH_COMMAND ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch_llvm.py ${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project)
290+
if(APPLY_LLVM_PERFORMANCE_PATCHES)
291+
set(LLVM_PATCH_COMMAND ${LLVM_PATCH_COMMAND} && ${Python3_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/cmake/patch_llvm.py ${CMAKE_CURRENT_SOURCE_DIR}/patches/llvm-project-perf)
292+
endif()
293+
296294
FetchContent_Declare(llvmproject
297295
GIT_REPOSITORY https://github.com/llvm/llvm-project.git
298296
GIT_TAG "${llvmproject_TAG}"
299297
GIT_SHALLOW "${llvmproject_SHALLOW}"
300298
GIT_PROGRESS TRUE
301-
PATCH_COMMAND git reset --quiet --hard && git clean --quiet --force -dx && git am -k --ignore-whitespace --3way ${llvm_project_patches}
299+
PATCH_COMMAND ${LLVM_PATCH_COMMAND}
302300
# Add the llvm subdirectory later to ensure that
303301
# LLVMEmbeddedToolchainForArm is the first project declared.
304302
# Otherwise CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT
@@ -381,6 +379,12 @@ if(LLVM_TOOLCHAIN_C_LIBRARY STREQUAL llvmlibc)
381379
COMPONENT llvm-toolchain-llvmlibc-configs
382380
)
383381

382+
install(
383+
DIRECTORY
384+
${CMAKE_CURRENT_SOURCE_DIR}/llvmlibc-samples/src
385+
DESTINATION samples
386+
COMPONENT llvm-toolchain-llvmlibc-configs
387+
)
384388
# We aren't yet able to build C++ libraries to go with llvm-libc
385389
set(CXX_LIBS OFF)
386390

@@ -1261,6 +1265,7 @@ function(
12611265
-DLIBCXX_INCLUDE_BENCHMARKS=OFF
12621266
-DLIBCXX_TEST_PARAMS=executor=${test_executor}
12631267
-DLIBCXX_SHARED_OUTPUT_NAME="c++-shared"
1268+
-DLIBUNWIND_ENABLE_ASSERTIONS=OFF
12641269
-DLIBUNWIND_ENABLE_SHARED=OFF
12651270
-DLIBUNWIND_ENABLE_STATIC=ON
12661271
-DLIBUNWIND_IS_BAREMETAL=ON
@@ -1779,9 +1784,9 @@ add_library_variants_for_cpu(
17791784
)
17801785
add_library_variants_for_cpu(
17811786
armv7r
1782-
SUFFIX soft_vfpv3_d16
1783-
COMPILE_FLAGS "-mfloat-abi=softfp -march=armv7r -mfpu=vfpv3-d16"
1784-
MULTILIB_FLAGS "--target=armv7r-unknown-none-eabi -mfpu=vfpv3-d16"
1787+
SUFFIX soft_vfpv3xd
1788+
COMPILE_FLAGS "-mfloat-abi=softfp -march=armv7r -mfpu=vfpv3xd"
1789+
MULTILIB_FLAGS "--target=armv7r-unknown-none-eabi -mfpu=vfpv3xd"
17851790
PICOLIBC_BUILD_TYPE "release"
17861791
QEMU_MACHINE "none"
17871792
QEMU_CPU "cortex-r5f"

Omax.cfg

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
-mllvm -unroll-max-iteration-count-to-analyze=20 \
66
-mllvm -lsr-complexity-limit=1073741823 \
77
-mllvm -force-attribute=main:norecurse \
8+
-mllvm -enable-dfa-jump-thread \
9+
-mllvm -enable-loop-flatten \
10+
-mllvm -enable-unroll-and-jam \

OmaxLTO.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
-flto=full \
22
-fvirtual-function-elimination \
3-
-fwhole-program-vtables
3+
-fwhole-program-vtables \
4+
-mllvm -extra-LTO-loop-unroll=true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ and/or increased memory usage during linking. Some of the options in the config
172172
corresponding optimisation passes in the [LLVM project](https://github.com/llvm/llvm-project)
173173
to find out more. Users are also encouraged to create their own configs and tune their own
174174
flag parameters.
175+
Information on LLVM Embedded Toolchain for Arm specific optimization flags is available in [Optimization Flags](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/blob/main/docs/optimization-flags.md)
175176

176177
Binary releases of the LLVM Embedded Toolchain for Arm are based on release
177178
branches of the upstream LLVM Project, thus can safely be used with all tools

cmake/patch_llvm.py

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Script to apply a set of patches to llvm-project sources.
5+
"""
6+
7+
import argparse
8+
import os
9+
import pathlib
10+
import subprocess
11+
import sys
12+
13+
14+
def main():
15+
parser = argparse.ArgumentParser(description=__doc__)
16+
parser.add_argument(
17+
"patchdir",
18+
help="Set of patches to apply. This should be a directory containing one or more ordered *.patch files.",
19+
)
20+
parser.add_argument(
21+
"--llvm_dir",
22+
help="Directory of the llvm-project git checkout, if not the current directory.",
23+
)
24+
parser.add_argument(
25+
"--method",
26+
choices=["am", "apply"],
27+
default="apply",
28+
help="Git command to use. git am will add each patch as a commit, whereas git apply will leave patched changes staged.",
29+
)
30+
parser.add_argument(
31+
"--reset",
32+
help="Clean and hard reset the repo to a specified commit before patching.",
33+
)
34+
parser.add_argument(
35+
"--restore_on_fail",
36+
action="store_true",
37+
help="If a patch in a series cannot be applied, restore the original state instead of leaving patches missing. Return code will be 2 instead of 1.",
38+
)
39+
args = parser.parse_args()
40+
41+
if args.llvm_dir:
42+
git_cmd = ["git", "-C", args.llvm_dir]
43+
else:
44+
git_cmd = ["git"]
45+
46+
if args.reset:
47+
reset_args = git_cmd + ["reset", "--quiet", "--hard", args.reset]
48+
subprocess.check_output(reset_args)
49+
clean_args = git_cmd + ["clean", "--quiet", "--force", "-dx", args.reset]
50+
subprocess.check_output(clean_args)
51+
52+
abs_patch_dir = os.path.abspath(args.patchdir)
53+
patch_list = list(pathlib.Path(abs_patch_dir).glob("*.patch"))
54+
patch_list.sort()
55+
56+
print(f"Found {len(patch_list)} patches to apply:")
57+
print("\n".join(p.name for p in patch_list))
58+
59+
if args.method == "am":
60+
merge_args = git_cmd + ["am", "-k", "--ignore-whitespace", "--3way"]
61+
for patch in patch_list:
62+
merge_args.append(str(patch))
63+
p = subprocess.run(merge_args, capture_output=True, text=True)
64+
print(p.stdout)
65+
print(p.stderr)
66+
67+
if p.returncode == 0:
68+
print(f"All patches applied.")
69+
sys.exit(0)
70+
if args.restore_on_fail:
71+
# Check that the operation can be aborted.
72+
# git am doesn't give any specific return codes,
73+
# so check for unresolved working files.
74+
rebase_apply_path = os.path.join(".git", "rebase-apply")
75+
if args.llvm_dir:
76+
rebase_apply_path = os.path.join(args.llvm_dir, rebase_apply_path)
77+
if os.path.isdir(rebase_apply_path):
78+
print("Aborting git am...")
79+
subprocess.run(git_cmd + ["am", "--abort"], check=True)
80+
print(f"Abort successful.")
81+
sys.exit(2)
82+
else:
83+
print("Unable to abort.")
84+
sys.exit(1)
85+
else:
86+
applied_patches = []
87+
for current_patch in patch_list:
88+
print(f"Checking {current_patch.name}...")
89+
# Check that the patch applies before trying to apply it.
90+
apply_check_args = git_cmd + [
91+
"apply",
92+
"--ignore-whitespace",
93+
"--3way",
94+
"--check",
95+
str(current_patch),
96+
]
97+
p_check = subprocess.run(apply_check_args)
98+
99+
if p_check.returncode == 0:
100+
# Patch will apply.
101+
print(f"Applying {current_patch.name}...")
102+
apply_args = git_cmd + [
103+
"apply",
104+
"--ignore-whitespace",
105+
"--3way",
106+
str(current_patch),
107+
]
108+
apply_args = subprocess.run(apply_args, check=True)
109+
applied_patches.append(current_patch)
110+
else:
111+
# Patch won't apply.
112+
print(f"Unable to apply {current_patch.name}")
113+
if args.restore_on_fail:
114+
# Remove any patches that have already been applied.
115+
while len(applied_patches) > 0:
116+
previous_patch = applied_patches.pop()
117+
print(f"Reversing {previous_patch.name}...")
118+
reverse_args = git_cmd + [
119+
"apply",
120+
"--ignore-whitespace",
121+
"--3way",
122+
"--reverse",
123+
str(previous_patch),
124+
]
125+
p_check = subprocess.run(reverse_args, check=True)
126+
print(
127+
f"Rollback successful, failure occured on {current_patch.name}"
128+
)
129+
sys.exit(2)
130+
sys.exit(1)
131+
print(f"All patches applied.")
132+
133+
134+
main()

docs/Screenshot_L4R5.png

881 Bytes
Loading

docs/Screenshot_U5A9.png

1.6 KB
Loading

docs/building-from-source.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,12 @@ The same build directory can be used for both native and MinGW toolchains.
148148

149149
See [patches](https://github.com/ARM-software/LLVM-embedded-toolchain-for-Arm/tree/main/patches)
150150
directory for the current set of differences from upstream.
151+
152+
The patches for llvm-project are split between two folders, llvm-project and
153+
llvm-project-perf. The former are generally required for building and
154+
successfully running all tests. The patches in llvm-project-perf are optional,
155+
and designed to improve performance in certain circumstances.
156+
157+
To reduce divergence from upstream and potential patch conflicts, the
158+
performance patches are not applied by default, but can be enabled for an
159+
automatic checkout with the APPLY_LLVM_PERFORMANCE_PATCHES option.

docs/llvmlibc.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,21 @@ following command line options, in addition to `--target`, `-march` or
5454
`__llvm_libc_heap_limit` in addition to whatever other memory layout
5555
you want.
5656

57+
* LLVM libc does not define errno. If you are using a function that
58+
sets errno then you must implement the function `int *__llvm_libc_errno()`
59+
that returns the address of your definition of errno.
60+
5761
For example:
5862

5963
```
6064
clang --config=llvmlibc.cfg --target=arm-none-eabi -march=armv7m -o hello hello.c -lsemihost -lcrt0 -Wl,--defsym=__stack=0x200000
6165
```
6266

67+
## Samples
68+
69+
The overlay package installs a llvmlibc directory in the samples/src
70+
directory containing sample programs that use LLVM libc.
71+
6372
## Limitations of LLVM libc in LLVM Embedded Toolchain for Arm
6473

6574
At present, this toolchain does not build any C++ libraries to go with

docs/optimization-flags.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
Additional optimization flags
2+
=============================
3+
4+
## Additional loop unroll in the LTO pipeline
5+
In some cases it is benefitial to perform an additional loop unroll pass so that extra information becomes available to later passes, e.g. SROA.
6+
Use cases where this could be beneficial - multiple (N>=4) nested loops.
7+
8+
### Usage:
9+
-mllvm -extra-LTO-loop-unroll=true/false

0 commit comments

Comments
 (0)