Skip to content

Commit

Permalink
[CMake][compiler-rt][AArch64] Avoid preprocessing LSE builtins separa…
Browse files Browse the repository at this point in the history
…tely

Invoking the preprocessor ourselves is fragile and would require us to replicate CMake's handling of definitions, compiler flags, etc for proper compatibility.
In my toolchain builds this notably resulted in a bunch of warnings from unused flags as my CMAKE_C_FLAGS includes CPU-specific optimization options.
Notably this part was already duplicating the logic for VISIBILITY_HIDDEN define.

Instead, symlink the files and set the proper set of defines on each.
This should also be faster as we avoid invoking the compiler multiple times.

Fixes https://llvm.org/PR48494

Reviewed By: ilinpv

Differential Revision: https://reviews.llvm.org/D93178
  • Loading branch information
tambry committed Dec 14, 2020
1 parent 7de9c61 commit 33b740f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 16 deletions.
25 changes: 10 additions & 15 deletions compiler-rt/lib/builtins/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -509,31 +509,24 @@ set(aarch64_SOURCES
)

# Generate outline atomics helpers from lse.S base
set(CUSTOM_FLAGS ${CMAKE_C_FLAGS})
if(NOT ANDROID)
append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG -DVISIBILITY_HIDDEN CUSTOM_FLAGS)
endif()
append_list_if(COMPILER_RT_HAS_ASM_LSE -DHAS_ASM_LSE CUSTOM_FLAGS)
string(REPLACE " " "\t" CUSTOM_FLAGS "${CUSTOM_FLAGS}")
set(OA_HELPERS_DIR "${CMAKE_CURRENT_BINARY_DIR}/outline_atomic_helpers.dir")
file(MAKE_DIRECTORY ${OA_HELPERS_DIR})
file(MAKE_DIRECTORY "${OA_HELPERS_DIR}")

foreach(pat cas swp ldadd ldclr ldeor ldset)
foreach(size 1 2 4 8 16)
foreach(model 1 2 3 4)
if(pat STREQUAL "cas" OR NOT size STREQUAL "16")
set(helper_asm ${OA_HELPERS_DIR}/outline_atomic_${pat}${size}_${model}.S)
set(helper_asm "${OA_HELPERS_DIR}/outline_atomic_${pat}${size}_${model}.S")
add_custom_command(
OUTPUT ${helper_asm}
COMMAND ${CMAKE_C_COMPILER} -E ${CUSTOM_FLAGS} -DL_${pat} -DSIZE=${size} -DMODEL=${model}
${CMAKE_CURRENT_SOURCE_DIR}/aarch64/lse.S -o ${helper_asm}
DEPENDS aarch64/lse.S assembly.h
COMMAND ${CMAKE_COMMAND} -E create_symlink "${CMAKE_CURRENT_SOURCE_DIR}/aarch64/lse.S" "${helper_asm}"
)
set_source_files_properties(${helper_asm} PROPERTIES GENERATED TRUE)
set(aarch64_SOURCES
${aarch64_SOURCES}
${helper_asm}
set_source_files_properties("${helper_asm}"
PROPERTIES
COMPILE_DEFINITIONS "L_${pat};SIZE=${size};MODEL=${model}"
INCLUDE_DIRECTORIES "${CMAKE_CURRENT_SOURCE_DIR}"
)
list(APPEND aarch64_SOURCES "${helper_asm}")
endif()
endforeach(model)
endforeach(size)
Expand Down Expand Up @@ -687,6 +680,8 @@ else ()
append_list_if(COMPILER_RT_HAS_VISIBILITY_HIDDEN_FLAG VISIBILITY_HIDDEN BUILTIN_DEFS)
endif()

append_list_if(COMPILER_RT_HAS_ASM_LSE HAS_ASM_LSE BUILTIN_DEFS)

foreach (arch ${BUILTIN_SUPPORTED_ARCH})
if (CAN_TARGET_${arch})
# For ARM archs, exclude any VFP builtins if VFP is not supported
Expand Down
2 changes: 1 addition & 1 deletion compiler-rt/lib/builtins/aarch64/lse.S
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include "../assembly.h"
#include "assembly.h"

// Out-of-line LSE atomics helpers. Ported from libgcc library.
// N = {1, 2, 4, 8}
Expand Down

0 comments on commit 33b740f

Please sign in to comment.