From 6dbdfb3cd51d8f7c90556f659d5cfe7bd7d92e95 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Fri, 10 Jan 2025 14:17:47 +0800 Subject: [PATCH] arch/arm: Add LLVM configuration to CMake Added LLVM-specific configuration variables to ARM architecture CMake files: - LLVM_ARCHTYPE for architecture variant (thumbv6m, thumbv7a, etc) - LLVM_CPUTYPE for CPU target (cortex-m0, cortex-a5, etc) - LLVM_ABITYPE for ABI (eabi/eabihf) These changes enable LLVM/Clang toolchain support while maintaining compatibility with existing GCC configurations. The LLVM variables are set based on the same architecture/CPU/FPU configurations used for GCC flags. Signed-off-by: Huang Qi --- arch/arm/src/cmake/armv6-m.cmake | 5 +++++ arch/arm/src/cmake/armv7-a.cmake | 16 ++++++++++++++++ arch/arm/src/cmake/armv7-m.cmake | 19 +++++++++++++++++++ arch/arm/src/cmake/armv8-m.cmake | 25 +++++++++++++++++++++++++ 4 files changed, 65 insertions(+) diff --git a/arch/arm/src/cmake/armv6-m.cmake b/arch/arm/src/cmake/armv6-m.cmake index 32596ab689..5d52da216d 100644 --- a/arch/arm/src/cmake/armv6-m.cmake +++ b/arch/arm/src/cmake/armv6-m.cmake @@ -21,3 +21,8 @@ # ############################################################################## add_compile_options(-mcpu=cortex-m0 -mthumb -mfloat-abi=soft) + +# LLVM Configuration +set(LLVM_ARCHTYPE thumbv6m) +set(LLVM_ABITYPE eabi) +set(LLVM_CPUTYPE cortex-m0) diff --git a/arch/arm/src/cmake/armv7-a.cmake b/arch/arm/src/cmake/armv7-a.cmake index a061cdffe8..ddd02c324b 100644 --- a/arch/arm/src/cmake/armv7-a.cmake +++ b/arch/arm/src/cmake/armv7-a.cmake @@ -24,12 +24,28 @@ set(PLATFORM_FLAGS) if(CONFIG_ARCH_CORTEXA5) list(APPEND PLATFORM_FLAGS -mcpu=cortex-a5) + set(LLVM_CPUTYPE cortex-a5) elseif(CONFIG_ARCH_CORTEXA7) list(APPEND PLATFORM_FLAGS -mcpu=cortex-a7) + set(LLVM_CPUTYPE cortex-a7) elseif(CONFIG_ARCH_CORTEXA8) list(APPEND PLATFORM_FLAGS -mcpu=cortex-a8) + set(LLVM_CPUTYPE cortex-a8) elseif(CONFIG_ARCH_CORTEXA9) list(APPEND PLATFORM_FLAGS -mcpu=cortex-a9) + set(LLVM_CPUTYPE cortex-a9) +endif() + +if(CONFIG_ARM_THUMB) + set(LLVM_ARCHTYPE thumbv7a) +else() + set(LLVM_ARCHTYPE armv7-a) +endif() + +if(CONFIG_ARCH_FPU) + set(LLVM_ABITYPE eabihf) +else() + set(LLVM_ABITYPE eabi) endif() if(NOT CONFIG_ARM_DPFPU32) diff --git a/arch/arm/src/cmake/armv7-m.cmake b/arch/arm/src/cmake/armv7-m.cmake index 73ef08d18c..1f6d121e78 100644 --- a/arch/arm/src/cmake/armv7-m.cmake +++ b/arch/arm/src/cmake/armv7-m.cmake @@ -38,4 +38,23 @@ else() # gcc set(TOOLCHAIN_ARCH_FILE armv7-m_gcc) endif() +# LLVM Configuration +if(CONFIG_ARCH_CORTEXM3) + set(LLVM_ARCHTYPE thumbv7m) + set(LLVM_CPUTYPE cortex-m3) +else() + set(LLVM_ARCHTYPE thumbv7em) + if(CONFIG_ARCH_CORTEXM4) + set(LLVM_CPUTYPE cortex-m4) + elseif(CONFIG_ARCH_CORTEXM7) + set(LLVM_CPUTYPE cortex-m7) + endif() +endif() + +if(CONFIG_ARCH_FPU) + set(LLVM_ABITYPE eabihf) +else() + set(LLVM_ABITYPE eabi) +endif() + include(${TOOLCHAIN_ARCH_FILE}) diff --git a/arch/arm/src/cmake/armv8-m.cmake b/arch/arm/src/cmake/armv8-m.cmake index fef71a4984..71a8747e56 100644 --- a/arch/arm/src/cmake/armv8-m.cmake +++ b/arch/arm/src/cmake/armv8-m.cmake @@ -22,6 +22,31 @@ set(PLATFORM_FLAGS) +# LLVM Configuration +if(CONFIG_ARCH_CORTEXM23) + set(LLVM_ARCHTYPE thumbv8m.base) + set(LLVM_CPUTYPE cortex-m23) +elseif(CONFIG_ARCH_CORTEXM33) + set(LLVM_ARCHTYPE thumbv8m.main) + set(LLVM_CPUTYPE cortex-m33) +elseif(CONFIG_ARCH_CORTEXM35P) + set(LLVM_ARCHTYPE thumbv8m.main) + set(LLVM_CPUTYPE cortex-m35p) +elseif(CONFIG_ARCH_CORTEXM55) + set(LLVM_ARCHTYPE thumbv8.1m.main) + set(LLVM_CPUTYPE cortex-m55) +elseif(CONFIG_ARCH_CORTEXM85) + set(LLVM_ARCHTYPE thumbv8.1m.main) + set(LLVM_CPUTYPE cortex-m85) +endif() + +# Set ABI type based on FPU configuration +if(CONFIG_ARCH_FPU) + set(LLVM_ABITYPE eabihf) +else() + set(LLVM_ABITYPE eabi) +endif() + if(CONFIG_ARM_DSP) set(EXTCPUFLAGS +dsp) endif()