From d9dbec906d78b645b548cd997b500e54633d160d Mon Sep 17 00:00:00 2001 From: Ralph Versteegen Date: Wed, 6 Jan 2021 02:07:55 +1300 Subject: [PATCH] LLVM backend: on Windows use clang instead of llc llc.exe is not included with the LLVM official Windows binaries. clang can compile .ll files too but requires different args. This behaviour is gated by __FB_WIN32__ because there doesn't seem to be an existing way to check whether a tool exists. It would be better to fallback to clang only if llc doesn't exist (for example I see it is missing from at least some Android NDK toolchains too). Tested on Linux, not Windows. --- changelog.txt | 1 + src/compiler/fbc.bas | 51 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 46 insertions(+), 6 deletions(-) diff --git a/changelog.txt b/changelog.txt index e6c7515120..fb903429c4 100644 --- a/changelog.txt +++ b/changelog.txt @@ -197,6 +197,7 @@ Version 1.08.0 - C backend: inline asm - don't add rsp/esp to the clobber list, it's deprecated in newer gcc versions and silently ignored in older versions - github #309: token pasting operator '##' allows pasting of single '_' characters - fbc: re-add __FB_GUI__ intrinsic define - the change was clobbered for a time during fbc 1.08.0 development after basic-macros were added +- llvm backend on Windows invokes clang.exe instead of llc.exe (which usually doesn't exist) Version 1.07.0 diff --git a/src/compiler/fbc.bas b/src/compiler/fbc.bas index 6f589de05b..840918422b 100644 --- a/src/compiler/fbc.bas +++ b/src/compiler/fbc.bas @@ -3082,6 +3082,11 @@ private function hCompileXpm( ) as integer function = TRUE end function +#if defined( __FB_WIN32__ ) + '' LLVM official Windows binary distributions lack llc.exe, use clang instead + #define NO_LLC +#endif + private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as integer dim as string ln, asmfile @@ -3190,13 +3195,34 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege end select case FB_BACKEND_LLVM + #ifdef NO_LLC + ln += "-S " + '' Silence "overriding the module target triple" warning. Maybe warning + '' that the target should be declared in the .ll instead. + ln += "-Wno-override-module " + '' Tell clang we're using system as, so don't use extensions in the asm + ln += "-no-integrated-as " + #endif + select case( fbGetCpuFamily( ) ) case FB_CPUFAMILY_X86 - ln += "-march=x86 " + #ifdef NO_LLC + ln += "--target=i686 " + #else + ln += "-march=x86 " + #endif case FB_CPUFAMILY_X86_64 - ln += "-march=x86-64 " + #ifdef NO_LLC + ln += "--target=x86_64 " + #else + ln += "-march=x86-64 " + #endif case FB_CPUFAMILY_ARM - ln += "-march=arm " + #ifdef NO_LLC + ln += "--target=armv7a " + #else + ln += "-march=arm " + #endif case FB_CPUFAMILY_AARCH64 '' From the GCC manual: '' -march=name @@ -3230,7 +3256,11 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege '' is tuned to perform well across a range of target '' processors implementing the target architecture. - ln += "-march=armv8-a " + #ifdef NO_LLC + ln += "--target=armv8a " + #else + ln += "-march=armv8-a " + #endif end select if( fbGetOption( FB_COMPOPT_PIC ) ) then @@ -3242,7 +3272,11 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege select case( fbGetCpuFamily( ) ) case FB_CPUFAMILY_X86, FB_CPUFAMILY_X86_64 if( fbGetOption( FB_COMPOPT_ASMSYNTAX ) = FB_ASMSYNTAX_INTEL ) then - ln += "--x86-asm-syntax=intel " + #ifdef NO_LLC + ln += "-masm=intel " + #else + ln += "--x86-asm-syntax=intel " + #endif end if end select @@ -3260,7 +3294,12 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege end if function = fbcRunBin( "compiling C", gcc, ln ) case FB_BACKEND_LLVM - function = fbcRunBin( "compiling LLVM IR", FBCTOOL_LLC, ln ) + #ifdef NO_LLC + const compiler = FBCTOOL_CLANG + #else + const compiler = FBCTOOL_LLC + #endif + function = fbcRunBin( "compiling LLVM IR", compiler, ln ) end select end function