Skip to content

Commit d9dbec9

Browse files
rversteegenjayrm
authored andcommitted
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.
1 parent dfdee71 commit d9dbec9

File tree

2 files changed

+46
-6
lines changed

2 files changed

+46
-6
lines changed

changelog.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ Version 1.08.0
197197
- 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
198198
- github #309: token pasting operator '##' allows pasting of single '_' characters
199199
- 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
200+
- llvm backend on Windows invokes clang.exe instead of llc.exe (which usually doesn't exist)
200201

201202

202203
Version 1.07.0

src/compiler/fbc.bas

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3082,6 +3082,11 @@ private function hCompileXpm( ) as integer
30823082
function = TRUE
30833083
end function
30843084

3085+
#if defined( __FB_WIN32__ )
3086+
'' LLVM official Windows binary distributions lack llc.exe, use clang instead
3087+
#define NO_LLC
3088+
#endif
3089+
30853090
private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as integer
30863091
dim as string ln, asmfile
30873092

@@ -3190,13 +3195,34 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege
31903195
end select
31913196

31923197
case FB_BACKEND_LLVM
3198+
#ifdef NO_LLC
3199+
ln += "-S "
3200+
'' Silence "overriding the module target triple" warning. Maybe warning
3201+
'' that the target should be declared in the .ll instead.
3202+
ln += "-Wno-override-module "
3203+
'' Tell clang we're using system as, so don't use extensions in the asm
3204+
ln += "-no-integrated-as "
3205+
#endif
3206+
31933207
select case( fbGetCpuFamily( ) )
31943208
case FB_CPUFAMILY_X86
3195-
ln += "-march=x86 "
3209+
#ifdef NO_LLC
3210+
ln += "--target=i686 "
3211+
#else
3212+
ln += "-march=x86 "
3213+
#endif
31963214
case FB_CPUFAMILY_X86_64
3197-
ln += "-march=x86-64 "
3215+
#ifdef NO_LLC
3216+
ln += "--target=x86_64 "
3217+
#else
3218+
ln += "-march=x86-64 "
3219+
#endif
31983220
case FB_CPUFAMILY_ARM
3199-
ln += "-march=arm "
3221+
#ifdef NO_LLC
3222+
ln += "--target=armv7a "
3223+
#else
3224+
ln += "-march=arm "
3225+
#endif
32003226
case FB_CPUFAMILY_AARCH64
32013227
'' From the GCC manual:
32023228
'' -march=name
@@ -3230,7 +3256,11 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege
32303256
'' is tuned to perform well across a range of target
32313257
'' processors implementing the target architecture.
32323258

3233-
ln += "-march=armv8-a "
3259+
#ifdef NO_LLC
3260+
ln += "--target=armv8a "
3261+
#else
3262+
ln += "-march=armv8-a "
3263+
#endif
32343264
end select
32353265

32363266
if( fbGetOption( FB_COMPOPT_PIC ) ) then
@@ -3242,7 +3272,11 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege
32423272
select case( fbGetCpuFamily( ) )
32433273
case FB_CPUFAMILY_X86, FB_CPUFAMILY_X86_64
32443274
if( fbGetOption( FB_COMPOPT_ASMSYNTAX ) = FB_ASMSYNTAX_INTEL ) then
3245-
ln += "--x86-asm-syntax=intel "
3275+
#ifdef NO_LLC
3276+
ln += "-masm=intel "
3277+
#else
3278+
ln += "--x86-asm-syntax=intel "
3279+
#endif
32463280
end if
32473281
end select
32483282

@@ -3260,7 +3294,12 @@ private function hCompileStage2Module( byval module as FBCIOFILE ptr ) as intege
32603294
end if
32613295
function = fbcRunBin( "compiling C", gcc, ln )
32623296
case FB_BACKEND_LLVM
3263-
function = fbcRunBin( "compiling LLVM IR", FBCTOOL_LLC, ln )
3297+
#ifdef NO_LLC
3298+
const compiler = FBCTOOL_CLANG
3299+
#else
3300+
const compiler = FBCTOOL_LLC
3301+
#endif
3302+
function = fbcRunBin( "compiling LLVM IR", compiler, ln )
32643303
end select
32653304
end function
32663305

0 commit comments

Comments
 (0)