authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-21 12:14:43-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-01-21 12:14:43-05:00
log91ecce3bc05abb6677b389cbc7af403584d9cc7d
tree08cd205a53b75bdf7f8f8b3ff13175be539e9590
parent6793af8d8b370cefc0a1fccbcf1c9fd1a24c7378
signaturelock-open Commit is signed but in an unrecognized format.

fix cache of cpu features


1 files changed, 11 insertions(+), 20 deletions(-)

src-self-hosted/stage1.zig+11-20
...@@ -13,6 +13,7 @@ const Target = std.Target;...@@ -13,6 +13,7 @@ const Target = std.Target;
13const self_hosted_main = @import("main.zig");13const self_hosted_main = @import("main.zig");
14const errmsg = @import("errmsg.zig");14const errmsg = @import("errmsg.zig");
15const DepTokenizer = @import("dep_tokenizer.zig").Tokenizer;15const DepTokenizer = @import("dep_tokenizer.zig").Tokenizer;
16const assert = std.debug.assert;
1617
17var stderr_file: fs.File = undefined;18var stderr_file: fs.File = undefined;
18var stderr: *io.OutStream(fs.File.WriteError) = undefined;19var stderr: *io.OutStream(fs.File.WriteError) = undefined;
...@@ -675,7 +676,7 @@ const Stage2CpuFeatures = struct {...@@ -675,7 +676,7 @@ const Stage2CpuFeatures = struct {
675 });676 });
676 errdefer allocator.free(builtin_str);677 errdefer allocator.free(builtin_str);
677678
678 const cache_hash = try std.fmt.allocPrint0(allocator, "{}\n{x}", .{ cpu.name, cpu.features });679 const cache_hash = try std.fmt.allocPrint0(allocator, "{}\n{x}", .{ cpu.name, cpu.features.bytes });
679 errdefer allocator.free(cache_hash);680 errdefer allocator.free(cache_hash);
680681
681 self.* = Self{682 self.* = Self{
...@@ -696,29 +697,19 @@ const Stage2CpuFeatures = struct {...@@ -696,29 +697,19 @@ const Stage2CpuFeatures = struct {
696 ) ![*:0]const u8 {697 ) ![*:0]const u8 {
697 var llvm_features_buffer = try std.Buffer.initSize(allocator, 0);698 var llvm_features_buffer = try std.Buffer.initSize(allocator, 0);
698 defer llvm_features_buffer.deinit();699 defer llvm_features_buffer.deinit();
699 // First, disable all features.700
700 // This way, we only get the ones the user requests.
701 const all_features = arch.allFeaturesList();701 const all_features = arch.allFeaturesList();
702 for (all_features) |feature| {
703 if (feature.llvm_name) |llvm_name| {
704 try llvm_features_buffer.append("-");
705 try llvm_features_buffer.append(llvm_name);
706 try llvm_features_buffer.append(",");
707 }
708 }
709 for (all_features) |feature, index| {702 for (all_features) |feature, index| {
710 if (!feature_set.isEnabled(@intCast(u8, index))) continue;703 const llvm_name = feature.llvm_name orelse continue;
711704
712 if (feature.llvm_name) |llvm_name| {705 const plus_or_minus = "-+"[@boolToInt(feature_set.isEnabled(@intCast(u8, index)))];
713 try llvm_features_buffer.append("+");706 try llvm_features_buffer.appendByte(plus_or_minus);
714 try llvm_features_buffer.append(llvm_name);707 try llvm_features_buffer.append(llvm_name);
715 try llvm_features_buffer.append(",");708 try llvm_features_buffer.append(",");
716 }
717 }709 }
710 assert(mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ","));
711 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
718712
719 if (mem.endsWith(u8, llvm_features_buffer.toSliceConst(), ",")) {
720 llvm_features_buffer.shrink(llvm_features_buffer.len() - 1);
721 }
722 return llvm_features_buffer.toOwnedSlice().ptr;713 return llvm_features_buffer.toOwnedSlice().ptr;
723 }714 }
724715
...@@ -730,7 +721,7 @@ const Stage2CpuFeatures = struct {...@@ -730,7 +721,7 @@ const Stage2CpuFeatures = struct {
730 const self = try allocator.create(Self);721 const self = try allocator.create(Self);
731 errdefer allocator.destroy(self);722 errdefer allocator.destroy(self);
732723
733 const cache_hash = try std.fmt.allocPrint0(allocator, "\n{x}", .{feature_set});724 const cache_hash = try std.fmt.allocPrint0(allocator, "\n{}", .{feature_set.bytes});
734 errdefer allocator.free(cache_hash);725 errdefer allocator.free(cache_hash);
735726
736 const generic_arch_name = arch.genericName();727 const generic_arch_name = arch.genericName();