Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for --mcpu native #10264

Merged
merged 4 commits into from
Jan 18, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/compiler/crystal/command.cr
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,11 @@ class Crystal::Command
link_flags << some_link_flags
end
opts.on("--mcpu CPU", "Target specific cpu type") do |cpu|
compiler.mcpu = cpu
if cpu == "native"
compiler.mcpu = LLVM.host_cpu_name
else
compiler.mcpu = cpu
end
end
opts.on("--mattr CPU", "Target specific features") do |features|
compiler.mattr = features
Expand Down
4 changes: 4 additions & 0 deletions src/llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ module LLVM
end
end

def self.host_cpu_name : String
String.new LibLLVM.get_host_cpu_name
end

def self.normalize_triple(triple : String)
normalized = LibLLVMExt.normalize_target_triple(triple)
normalized = LLVM.string_and_dispose(normalized)
Expand Down
1 change: 1 addition & 0 deletions src/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ lib LibLLVM
fun get_named_function = LLVMGetNamedFunction(mod : ModuleRef, name : UInt8*) : ValueRef
fun get_named_global = LLVMGetNamedGlobal(mod : ModuleRef, name : UInt8*) : ValueRef
fun get_count_params = LLVMCountParams(fn : ValueRef) : UInt
fun get_host_cpu_name = LLVMGetHostCPUName : UInt8*
fun get_param = LLVMGetParam(fn : ValueRef, index : Int32) : ValueRef
fun get_param_types = LLVMGetParamTypes(function_type : TypeRef, dest : TypeRef*)
fun get_params = LLVMGetParams(fn : ValueRef, params : ValueRef*)
Expand Down