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 all 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
1 change: 1 addition & 0 deletions man/crystal.1
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ Dump LLVM assembly file to output directory.
Pass additional flags to the linker. Though you can specify those flags on the source code, this is useful for passing environment specific information directly to the linker, like non-standard library paths or names. For more information on specifying linker flags on source, you can read the "C bindings" section of the documentation available on the official web site.
.It Fl -mcpu Ar CPU
Specify a specific CPU to generate code for. This will pass a -mcpu flag to LLVM, and is only intended to be used for cross-compilation. For a list of available CPUs, invoke "llvm-as < /dev/null | llc -march=xyz -mcpu=help".
Passing --mcpu native will pass the host CPU name to tune performance for the host.
.It Fl -mattr Ar CPU
Override or control specific attributes of the target, such as whether SIMD operations are enabled or not. The default set of attributes is set by the current CPU. This will pass a -mattr flag to LLVM, and is only intended to be used for cross-compilation. For a list of available attributes, invoke "llvm-as < /dev/null | llc -march=xyz -mattr=help".
.It Fl -mcmodel default|kernel|small|medium|large
Expand Down
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