void NeonVectorBackend::visit(const Nodecl::VectorAdd& n) { walk(n.get_lhs()); walk(n.get_rhs()); TL::Type t = n.get_type(); ERROR_CONDITION(!t.is_vector(), "Invalid type", 0); TL::Type element = t.vector_element(); ERROR_CONDITION(!element.is_float(), "Not implemented: %s", print_declarator(element.get_internal_type())); TL::Symbol builtin_fun = TL::Scope::get_global_scope().get_symbol_from_name("vaddq_f32"); ERROR_CONDITION(!builtin_fun.is_valid(), "Symbol not found", 0); n.replace( Nodecl::FunctionCall::make( builtin_fun.make_nodecl(/* set_ref_type */ true), Nodecl::List::make( n.get_lhs(), n.get_rhs()), /* alternate-name */ Nodecl::NodeclBase::null(), /* function-form */ Nodecl::NodeclBase::null(), n.get_type(), n.get_locus() ) ); }
const char* fortran_print_type_str(type_t* t) { t = no_ref(t); if (is_error_type(t)) { return "<error-type>"; } if (is_hollerith_type(t)) { return "HOLLERITH"; } const char* result = ""; char is_pointer = 0; if (is_pointer_type(t)) { is_pointer = 1; t = pointer_type_get_pointee_type(t); } struct array_spec_tag { nodecl_t lower; nodecl_t upper; char is_undefined; } array_spec_list[MCXX_MAX_ARRAY_SPECIFIER] = { { nodecl_null(), nodecl_null(), 0 } }; int array_spec_idx; for (array_spec_idx = MCXX_MAX_ARRAY_SPECIFIER - 1; fortran_is_array_type(t); array_spec_idx--) { if (array_spec_idx < 0) { internal_error("too many array dimensions %d\n", MCXX_MAX_ARRAY_SPECIFIER); } if (!array_type_is_unknown_size(t)) { array_spec_list[array_spec_idx].lower = array_type_get_array_lower_bound(t); array_spec_list[array_spec_idx].upper = array_type_get_array_upper_bound(t); } else { array_spec_list[array_spec_idx].is_undefined = 1; } t = array_type_get_element_type(t); } char is_array = (array_spec_idx != (MCXX_MAX_ARRAY_SPECIFIER - 1)); if (is_bool_type(t) || is_integer_type(t) || is_floating_type(t) || is_double_type(t) || is_complex_type(t)) { const char* type_name = NULL; char c[128] = { 0 }; if (is_bool_type(t)) { type_name = "LOGICAL"; } else if (is_integer_type(t)) { type_name = "INTEGER"; } else if (is_floating_type(t)) { type_name = "REAL"; } else if (is_complex_type(t)) { type_name = "COMPLEX"; } else { internal_error("unreachable code", 0); } size_t size = type_get_size(t); if (is_floating_type(t)) { // KIND of floats is their size in byes (using the bits as in IEEE754) size = (floating_type_get_info(t)->bits) / 8; } else if (is_complex_type(t)) { // KIND of a complex is the KIND of its component type type_t* f = complex_type_get_base_type(t); size = (floating_type_get_info(f)->bits) / 8; } snprintf(c, 127, "%s(%zd)", type_name, size); c[127] = '\0'; result = uniquestr(c); } else if (is_class_type(t)) { scope_entry_t* entry = named_type_get_symbol(t); char c[128] = { 0 }; snprintf(c, 127, "TYPE(%s)", entry->symbol_name); c[127] = '\0'; result = uniquestr(c); } else if (fortran_is_character_type(t)) { nodecl_t length = array_type_get_array_size_expr(t); char c[128] = { 0 }; snprintf(c, 127, "CHARACTER(LEN=%s)", nodecl_is_null(length) ? "*" : codegen_to_str(length, nodecl_retrieve_context(length))); c[127] = '\0'; result = uniquestr(c); } else if (is_function_type(t)) { result = "PROCEDURE"; } else { const char* non_printable = NULL; uniquestr_sprintf(&non_printable, "non-fortran type '%s'", print_declarator(t)); return non_printable; } if (is_pointer) { result = strappend(result, ", POINTER"); } if (is_array) { array_spec_idx++; result = strappend(result, ", DIMENSION("); while (array_spec_idx <= (MCXX_MAX_ARRAY_SPECIFIER - 1)) { if (!array_spec_list[array_spec_idx].is_undefined) { result = strappend(result, codegen_to_str(array_spec_list[array_spec_idx].lower, nodecl_retrieve_context(array_spec_list[array_spec_idx].lower))); result = strappend(result, ":"); result = strappend(result, codegen_to_str(array_spec_list[array_spec_idx].upper, nodecl_retrieve_context(array_spec_list[array_spec_idx].upper))); } else { result = strappend(result, ":"); } if ((array_spec_idx + 1) <= (MCXX_MAX_ARRAY_SPECIFIER - 1)) { result = strappend(result, ", "); } array_spec_idx++; } result = strappend(result, ")"); } return result; }
static type_t* solve_spu_overload_name(scope_entry_t* overloaded_function, AST* arguments, int num_arguments) { // Why people insists on having overload in C? char name[256]; // From gcc source at maximum 16 are defined const int max_valid_overloads = 24; char found_match = 0; type_t* result = NULL; DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Trying to figure out the exact version of '%s' given the following %d arguments\n", overloaded_function->symbol_name, num_arguments); int j; for (j = 0; j < num_arguments; j++) { fprintf(stderr, "SPU-BUILTIN: [%d] %s\n", j, print_declarator(ASTExprType(arguments[j]), overloaded_function->decl_context)); } } int i; for (i = 0; (i < max_valid_overloads) && !found_match; i++) { snprintf(name, 255, "%s_%d", overloaded_function->symbol_name, i); name[255] = '\0'; scope_entry_list_t *entry_list = query_unqualified_name_str(overloaded_function->decl_context, name); // Let's assume no more overloads have been defined if (entry_list == NULL) { break; } scope_entry_t* current_entry = entry_list->entry; type_t* current_function_type = current_entry->type_information; DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Checking with builtin '%s' of type '%s'\n", current_entry->symbol_name, print_declarator(current_function_type, overloaded_function->decl_context)); } if (!is_function_type(current_function_type)) { internal_error("spu builtin '%s' without function type\n", current_entry); } // Don't know if this case is considered but let's be kind with this crazy SDK if (num_arguments != function_type_get_num_parameters(current_function_type)) { continue; } int j; char all_arguments_matched = 1; for (j = 0; (j < num_arguments) && all_arguments_matched; j++) { type_t* argument_type = ASTExprType(arguments[j]); all_arguments_matched = all_arguments_matched && equivalent_types(argument_type, function_type_get_parameter_type_num(current_function_type, j), overloaded_function->decl_context); } if (all_arguments_matched) { DEBUG_CODE() { fprintf(stderr, "SPU-BUILTIN: Builtin '%s' of type '%s' matched!\n", current_entry->symbol_name, print_declarator(current_function_type, overloaded_function->decl_context)); } result = current_function_type; found_match = 1; } } return result; }