LLVM: simplify target initialization and support more targets #16437
+68
−139
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The LLVM bindings only expose the targets that the Crystal compiler itself supports, and each target copy-pastes the LibLLVM bindings and LLVM init methods which should use a macro.
I introduce a
LibLLVM::ALL_TARGETSconstant that's only used in macros to check if a known target has been built and generate the bindings and init methods accordingly.The constant is a Hash because we need the original LLVM target name (e.g.The constant is now an Array.AArch64) and Crystal chose to use lowercased symbols and aliases (e.g.aarch64). Maybe it should be an Array and macros usetarget.id.downcaseinstead 🤔The
@@initialized_class variables are now an atomic, and the dead@@initializedhas been removed.The list of targets is duplicated with theThe list has been extracted toscripts/generate_llvm_version_info.crfile but the script musn't loadsrc/llvm/lib_llvm.cr. Maybe the target list could be extracted into another file 🤔src/llvm/lib_llvm/config.cr.