From a91802ecba0a10f86d098a33e27cad8db1955905 Mon Sep 17 00:00:00 2001 From: Steven Johnson Date: Fri, 20 Jan 2023 14:03:57 -0800 Subject: [PATCH] Post changes from #7291 to Codegen_Xtensa --- src/CodeGen_Xtensa.cpp | 102 ++++++++++++++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 21 deletions(-) diff --git a/src/CodeGen_Xtensa.cpp b/src/CodeGen_Xtensa.cpp index 2f90b5db2522..6b0798e02bae 100644 --- a/src/CodeGen_Xtensa.cpp +++ b/src/CodeGen_Xtensa.cpp @@ -159,6 +159,24 @@ void CodeGen_Xtensa::compile(const LoweredFunc &f, const std::map `void const*` ucon. In most cases this will be ignored + // (and probably dead-stripped), but in these cases it's critical. + // + // (Note that we don't check to see if c_plus_plus_name_mangling is + // enabled, since that would have to be done on the caller side, and + // this is purely a callee-side fix.) + if (f.linkage != LinkageType::Internal && + output_kind == CPlusPlusImplementation && + target.has_feature(Target::CPlusPlusMangling) && + get_target().has_feature(Target::UserContext)) { + + Type ucon_type = Type(); + for (const auto &arg : args) { + if (arg.name == "__user_context") { + ucon_type = arg.type; + break; + } + } + if (ucon_type == type_of()) { + stream << "\nHALIDE_FUNCTION_ATTRS\n"; + stream << "int " << simple_name << "("; + emit_arg_decls(type_of()); + stream << ") "; + open_scope(); + stream << get_indent() << " return " << simple_name << "("; + const char *comma = ""; + for (const auto &arg : args) { + if (arg.name == "__user_context") { + // Add an explicit cast here so we won't call ourselves into oblivion + stream << "(void const *)"; + } + stream << comma << print_name(arg.name); + if (arg.is_buffer()) { + stream << "_buffer"; + } + comma = ", "; + } + stream << ");\n"; + close_scope(""); + } + } + + if (f.linkage == LinkageType::ExternalPlusArgv || f.linkage == LinkageType::ExternalPlusMetadata) { // Emit the argv version emit_argv_wrapper(simple_name, args); + } - // And also the metadata. + if (f.linkage == LinkageType::ExternalPlusMetadata) { + // Emit the metadata. emit_metadata_getter(simple_name, args, metadata_name_map); }