aboutsummaryrefslogtreecommitdiff
path: root/src/codegen.cpp
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-02-19 21:30:36 -0500
committerAndrew Kelley <andrew@ziglang.org>2020-02-19 21:30:36 -0500
commit84f1893c18c4ef12dbe268ed6d11a11966a9d447 (patch)
treee2c3e3600464c62589a63c7f1bb0f7ffda3fee16 /src/codegen.cpp
parent96f45c27b65307fe4abd5d1fb1cf314b1f493d8e (diff)
downloadzig-84f1893c18c4ef12dbe268ed6d11a11966a9d447.tar.gz
zig-84f1893c18c4ef12dbe268ed6d11a11966a9d447.zip
remove the concept of "sub-architecture"
in favor of CPU features. Also rearrange the `std.Target` data structure. * note: `@import("builtin")` was already deprecated in favor of `@import("std").builtin`. * `std.builtin.arch` is now deprecated in favor of `std.builtin.cpu.arch`. * `std.Target.CpuFeatures.Cpu` is now `std.Target.Cpu.Model`. * `std.Target.CpuFeatures` is now `std.Target.Cpu`. * `std.Target` no longer has an `arch` field. Instead it has a `cpu` field, which has `arch`, `model`, and `features`. * `std.Target` no longer has a `cpu_features` field. * `std.Target.Arch` is moved to `std.Target.Cpu.Arch` and it is an enum instead of a tagged union. * `std.Target.parseOs` is moved to `std.Target.Os.parse`. * `std.Target.parseAbi` is moved to `std.Target.Abi.parse`. * `std.Target.parseArchSub` is only for arch now and moved to `std.Target.Cpu.Arch.parse`. * `std.Target.parse` is improved to accept CPU name and features. * `std.Target.Arch.getBaselineCpuFeatures` is moved to `std.Target.Cpu.baseline`. * `std.Target.allCpus` is renamed to `std.Target.allCpuModels`. * `std.Target.defaultAbi` is moved to `std.Target.Abi.default`. * Significant cleanup of aarch64 and arm CPU features, resulting in the needed bit count for cpu feature set going from 174 to 138. * Add `std.Target.Cpu.Feature.Set.addFeatureSet` for merging feature sets together. `-target-feature` and `-target-cpu` are removed in favor of `-mcpu`, to conform to established conventions, and it gains additional power to support cpu features. The syntax is: -mcpu=name+on1+on2-off1-off2 closes #4261
Diffstat (limited to 'src/codegen.cpp')
-rw-r--r--src/codegen.cpp43
1 files changed, 17 insertions, 26 deletions
diff --git a/src/codegen.cpp b/src/codegen.cpp
index a28d2d469d..0c35bcd1ed 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -8624,14 +8624,11 @@ Buf *codegen_generate_builtin_source(CodeGen *g) {
buf_appendf(contents, "pub const arch = %s;\n", cur_arch);
buf_appendf(contents, "pub const abi = Abi.%s;\n", cur_abi);
{
- buf_append_str(contents, "pub const cpu_features: CpuFeatures = ");
- if (g->zig_target->cpu_features != nullptr) {
- const char *ptr;
- size_t len;
- stage2_cpu_features_get_builtin_str(g->zig_target->cpu_features, &ptr, &len);
- buf_append_mem(contents, ptr, len);
+ buf_append_str(contents, "pub const cpu: Cpu = ");
+ if (g->zig_target->builtin_str != nullptr) {
+ buf_append_str(contents, g->zig_target->builtin_str);
} else {
- buf_append_str(contents, "arch.getBaselineCpuFeatures();\n");
+ buf_append_str(contents, "Target.Cpu.baseline(arch);\n");
}
}
if (g->libc_link_lib != nullptr && g->zig_target->glibc_version != nullptr) {
@@ -8734,11 +8731,8 @@ static Error define_builtin_compile_vars(CodeGen *g) {
cache_int(&cache_hash, g->zig_target->vendor);
cache_int(&cache_hash, g->zig_target->os);
cache_int(&cache_hash, g->zig_target->abi);
- if (g->zig_target->cpu_features != nullptr) {
- const char *ptr;
- size_t len;
- stage2_cpu_features_get_cache_hash(g->zig_target->cpu_features, &ptr, &len);
- cache_str(&cache_hash, ptr);
+ if (g->zig_target->cache_hash != nullptr) {
+ cache_str(&cache_hash, g->zig_target->cache_hash);
}
if (g->zig_target->glibc_version != nullptr) {
cache_int(&cache_hash, g->zig_target->glibc_version->major);
@@ -8873,9 +8867,11 @@ static void init(CodeGen *g) {
}
// Override CPU and features if defined by user.
- if (g->zig_target->cpu_features != nullptr) {
- target_specific_cpu_args = stage2_cpu_features_get_llvm_cpu(g->zig_target->cpu_features);
- target_specific_features = stage2_cpu_features_get_llvm_features(g->zig_target->cpu_features);
+ if (g->zig_target->llvm_cpu_name != nullptr) {
+ target_specific_cpu_args = g->zig_target->llvm_cpu_name;
+ }
+ if (g->zig_target->llvm_cpu_features != nullptr) {
+ target_specific_features = g->zig_target->llvm_cpu_features;
}
if (g->verbose_llvm_cpu_features) {
fprintf(stderr, "name=%s triple=%s\n", buf_ptr(g->root_out_name), buf_ptr(&g->llvm_triple_str));
@@ -9190,19 +9186,17 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
args.append("-target");
args.append(buf_ptr(&g->llvm_triple_str));
- const char *llvm_cpu = stage2_cpu_features_get_llvm_cpu(g->zig_target->cpu_features);
- if (llvm_cpu != nullptr) {
+ if (g->zig_target->llvm_cpu_name != nullptr) {
args.append("-Xclang");
args.append("-target-cpu");
args.append("-Xclang");
- args.append(llvm_cpu);
+ args.append(g->zig_target->llvm_cpu_name);
}
- const char *llvm_target_features = stage2_cpu_features_get_llvm_features(g->zig_target->cpu_features);
- if (llvm_target_features != nullptr) {
+ if (g->zig_target->llvm_cpu_features != nullptr) {
args.append("-Xclang");
args.append("-target-feature");
args.append("-Xclang");
- args.append(llvm_target_features);
+ args.append(g->zig_target->llvm_cpu_features);
}
}
@@ -10406,11 +10400,8 @@ static Error check_cache(CodeGen *g, Buf *manifest_dir, Buf *digest) {
cache_int(ch, g->zig_target->vendor);
cache_int(ch, g->zig_target->os);
cache_int(ch, g->zig_target->abi);
- if (g->zig_target->cpu_features != nullptr) {
- const char *ptr;
- size_t len;
- stage2_cpu_features_get_cache_hash(g->zig_target->cpu_features, &ptr, &len);
- cache_str(ch, ptr);
+ if (g->zig_target->cache_hash != nullptr) {
+ cache_str(ch, g->zig_target->cache_hash);
}
if (g->zig_target->glibc_version != nullptr) {
cache_int(ch, g->zig_target->glibc_version->major);