Skip to content

Add LLVM.init_native_target and LLVM.init_all_targets#15466

Merged
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/llvm-init-target
Feb 21, 2025
Merged

Add LLVM.init_native_target and LLVM.init_all_targets#15466
straight-shoota merged 2 commits intocrystal-lang:masterfrom
HertzDevil:feature/llvm-init-target

Conversation

@HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Feb 13, 2025

LLVM's targets need to be initialized before they can be used. The Crystal compiler does this in Crystal::Codegen::Target#to_target_machine, but for external code that uses the LLVM wrappers directly, there is no simple way to do this. This PR adds two convenience methods which are more or less equivalent to LLVM's LLVMInitializeNativeTarget and LLVMInitializeAllTargets, both static line functions in llvm-c/Target.h, except the latter only initializes targets already supported by Crystal itself (e.g. no RISC-V or PowerPC at the moment even if llvm-config indicates their availability).

Co-authored-by: Johannes Müller <straightshoota@gmail.com>
@straight-shoota straight-shoota added this to the 1.16.0 milestone Feb 20, 2025
@straight-shoota straight-shoota merged commit 3af8697 into crystal-lang:master Feb 21, 2025
57 checks passed
@HertzDevil HertzDevil deleted the feature/llvm-init-target branch February 22, 2025 00:10
kojix2 pushed a commit to kojix2/crystal that referenced this pull request Feb 23, 2025
…ng#15466)

LLVM's targets need to be initialized before they can be used. The Crystal compiler does this in `Crystal::Codegen::Target#to_target_machine`, but for external code that uses the LLVM wrappers directly, there is no simple way to do this. This PR adds two convenience methods which are more or less equivalent to LLVM's `LLVMInitializeNativeTarget` and `LLVMInitializeAllTargets`, both static line functions in `llvm-c/Target.h`, except the latter only initializes targets already supported by Crystal itself (e.g. no RISC-V or PowerPC at the moment even if `llvm-config` indicates their availability).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants