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

Don't enable optional ARM Cortex-M series CPU features by default #18498

Merged
merged 3 commits into from
Jan 10, 2024
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
14 changes: 3 additions & 11 deletions lib/std/Target/arm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2204,9 +2204,7 @@ pub const cpu = struct {
.name = "cortex_m33",
.llvm_name = "cortex-m33",
.features = featureSet(&[_]Feature{
.dsp,
.fix_cmse_cve_2021_35465,
.fp_armv8d16sp,
.loop_align,
.no_branch_predictor,
.slowfpvfmx,
Expand All @@ -2219,9 +2217,7 @@ pub const cpu = struct {
.name = "cortex_m35p",
.llvm_name = "cortex-m35p",
.features = featureSet(&[_]Feature{
.dsp,
.fix_cmse_cve_2021_35465,
.fp_armv8d16sp,
.loop_align,
.no_branch_predictor,
.slowfpvfmx,
Expand All @@ -2240,17 +2236,15 @@ pub const cpu = struct {
.slowfpvmlx,
.use_misched,
.v7em,
.vfp4d16sp,
}),
};
pub const cortex_m55 = CpuModel{
.name = "cortex_m55",
.llvm_name = "cortex-m55",
.features = featureSet(&[_]Feature{
.dsp,
.fix_cmse_cve_2021_35465,
.fp_armv8d16,
.loop_align,
.mve_fp,
.no_branch_predictor,
.slowfpvmlx,
.use_misched,
Expand All @@ -2261,7 +2255,6 @@ pub const cpu = struct {
.name = "cortex_m7",
.llvm_name = "cortex-m7",
.features = featureSet(&[_]Feature{
.fp_armv8d16,
.use_mipipeliner,
.use_misched,
.v7em,
Expand All @@ -2271,9 +2264,8 @@ pub const cpu = struct {
.name = "cortex_m85",
.llvm_name = "cortex-m85",
.features = featureSet(&[_]Feature{
.fp_armv8d16,
.mve_fp,
.pacbti,
.dsp,
.trustzone,
.use_misched,
.v8_1m_main,
}),
Expand Down
90 changes: 73 additions & 17 deletions tools/update_cpu_features.zig
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const FeatureOverride = struct {
flatten: bool = false,
zig_name: ?[]const u8 = null,
desc: ?[]const u8 = null,
omit_deps: []const []const u8 = &.{},
extra_deps: []const []const u8 = &.{},
};

Expand Down Expand Up @@ -378,6 +379,31 @@ const llvm_targets = [_]LlvmTarget{
.llvm_name = "cortex-a710",
.flatten = true,
},
.{
.llvm_name = "cortex-m4",
.omit_deps = &.{"vfp4d16sp"},
},
.{
.llvm_name = "cortex-m7",
.omit_deps = &.{"fp_armv8d16"},
},
.{
.llvm_name = "cortex-m33",
.omit_deps = &.{ "fp_armv8d16sp", "dsp" },
},
.{
.llvm_name = "cortex-m35p",
.omit_deps = &.{ "fp_armv8d16sp", "dsp" },
},
.{
.llvm_name = "cortex-m55",
.omit_deps = &.{ "mve_fp", "fp_armv8d16" },
},
.{
.llvm_name = "cortex-m85",
.omit_deps = &.{ "mve_fp", "pacbti", "fp_armv8d16" },
.extra_deps = &.{"trustzone"},
},
.{
.llvm_name = "cortex-x1c",
.flatten = true,
Expand Down Expand Up @@ -1114,18 +1140,8 @@ fn processOneTarget(job: Job) anyerror!void {
var deps = std.ArrayList([]const u8).init(arena);
var omit = false;
var flatten = false;
const implies = kv.value_ptr.object.get("Implies").?.array;
for (implies.items) |imply| {
const other_key = imply.object.get("def").?.string;
const other_obj = &root_map.getPtr(other_key).?.object;
const other_llvm_name = other_obj.get("Name").?.string;
const other_zig_name = (try llvmNameToZigNameOmit(
arena,
llvm_target,
other_llvm_name,
)) orelse continue;
try deps.append(other_zig_name);
}
var omit_deps: []const []const u8 = &.{};
var extra_deps: []const []const u8 = &.{};
for (llvm_target.feature_overrides) |feature_override| {
if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
if (feature_override.omit) {
Expand All @@ -1142,12 +1158,30 @@ fn processOneTarget(job: Job) anyerror!void {
if (feature_override.desc) |override_desc| {
desc = override_desc;
}
for (feature_override.extra_deps) |extra_dep| {
try deps.append(extra_dep);
}
omit_deps = feature_override.omit_deps;
extra_deps = feature_override.extra_deps;
break;
}
}
const implies = kv.value_ptr.object.get("Implies").?.array;
for (implies.items) |imply| {
const other_key = imply.object.get("def").?.string;
const other_obj = &root_map.getPtr(other_key).?.object;
const other_llvm_name = other_obj.get("Name").?.string;
const other_zig_name = (try llvmNameToZigNameOmit(
arena,
llvm_target,
other_llvm_name,
)) orelse continue;
for (omit_deps) |omit_dep| {
if (mem.eql(u8, other_zig_name, omit_dep)) break;
} else {
try deps.append(other_zig_name);
}
}
for (extra_deps) |extra_dep| {
try deps.append(extra_dep);
}
const feature: Feature = .{
.llvm_name = llvm_name,
.zig_name = zig_name,
Expand All @@ -1170,6 +1204,21 @@ fn processOneTarget(job: Job) anyerror!void {

var zig_name = try llvmNameToZigName(arena, llvm_name);
var deps = std.ArrayList([]const u8).init(arena);
var omit_deps: []const []const u8 = &.{};
var extra_deps: []const []const u8 = &.{};
for (llvm_target.feature_overrides) |feature_override| {
if (mem.eql(u8, llvm_name, feature_override.llvm_name)) {
if (feature_override.omit) {
continue :root_it;
}
if (feature_override.zig_name) |override_name| {
zig_name = override_name;
}
omit_deps = feature_override.omit_deps;
extra_deps = feature_override.extra_deps;
break;
}
}
const features = kv.value_ptr.object.get("Features").?.array;
for (features.items) |feature| {
const feature_key = feature.object.get("def").?.string;
Expand All @@ -1181,7 +1230,14 @@ fn processOneTarget(job: Job) anyerror!void {
llvm_target,
feature_llvm_name,
)) orelse continue;
try deps.append(feature_zig_name);
for (omit_deps) |omit_dep| {
if (mem.eql(u8, feature_zig_name, omit_dep)) break;
} else {
try deps.append(feature_zig_name);
}
}
for (extra_deps) |extra_dep| {
try deps.append(extra_dep);
}
const tune_features = kv.value_ptr.object.get("TuneFeatures").?.array;
for (tune_features.items) |feature| {
Expand Down Expand Up @@ -1228,7 +1284,7 @@ fn processOneTarget(job: Job) anyerror!void {
mem.sort(Feature, all_features.items, {}, featureLessThan);
mem.sort(Cpu, all_cpus.items, {}, cpuLessThan);

const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "target" });
const target_sub_path = try fs.path.join(arena, &.{ "lib", "std", "Target" });
var target_dir = try job.zig_src_dir.makeOpenPath(target_sub_path, .{});
defer target_dir.close();

Expand Down