compiler: improve target features support

This commit is contained in:
Laytan Laats
2024-05-01 22:12:37 +02:00
parent ff0973e0f5
commit 25f1d0906d
19 changed files with 1067 additions and 205 deletions
+22
View File
@@ -184,6 +184,8 @@ struct TypeProc {
isize specialization_count;
ProcCallingConvention calling_convention;
i32 variadic_index;
String require_target_feature;
String enable_target_feature;
// TODO(bill): Make this a flag set rather than bools
bool variadic;
bool require_results;
@@ -2991,7 +2993,22 @@ gb_internal Type *union_tag_type(Type *u) {
return t_uint;
}
gb_internal int matched_target_features(TypeProc *t) {
if (t->require_target_feature.len == 0) {
return 0;
}
int matches = 0;
String_Iterator it = {t->require_target_feature, 0};
for (;;) {
String str = string_split_iterator(&it, ',');
if (str == "") break;
if (check_target_feature_is_valid_for_target_arch(str, nullptr)) {
matches += 1;
}
}
return matches;
}
enum ProcTypeOverloadKind {
ProcOverload_Identical, // The types are identical
@@ -3003,6 +3020,7 @@ enum ProcTypeOverloadKind {
ProcOverload_ResultCount,
ProcOverload_ResultTypes,
ProcOverload_Polymorphic,
ProcOverload_TargetFeatures,
ProcOverload_NotProcedure,
@@ -3060,6 +3078,10 @@ gb_internal ProcTypeOverloadKind are_proc_types_overload_safe(Type *x, Type *y)
}
}
if (matched_target_features(&px) != matched_target_features(&py)) {
return ProcOverload_TargetFeatures;
}
if (px.params != nullptr && py.params != nullptr) {
Entity *ex = px.params->Tuple.variables[0];
Entity *ey = py.params->Tuple.variables[0];