Skip to content

Commit

Permalink
LLVM backend: on Windows use clang instead of llc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rversteegen authored and jayrm committed Aug 7, 2021
1 parent dfdee71 commit d9dbec9
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 6 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 45 additions & 6 deletions src/compiler/fbc.bas
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand Down

0 comments on commit d9dbec9

Please sign in to comment.