Removing linkage name from iree_vm_module_lookup_function_by_ordinal. (#7266)

Internal names are no longer returned so the normal iree_vm_function_name
call can get the same value without as much out-ptr magic.
diff --git a/bindings/python/iree/runtime/vm.cc b/bindings/python/iree/runtime/vm.cc
index d49cf01..4bef4f6 100644
--- a/bindings/python/iree/runtime/vm.cc
+++ b/bindings/python/iree/runtime/vm.cc
@@ -725,10 +725,8 @@
         for (size_t ordinal = 0; ordinal < sig.export_function_count;
              ++ordinal) {
           iree_vm_function_t f;
-          iree_string_view_t linkage_name;
           auto status = iree_vm_module_lookup_function_by_ordinal(
-              self.raw_ptr(), IREE_VM_FUNCTION_LINKAGE_EXPORT, ordinal, &f,
-              &linkage_name);
+              self.raw_ptr(), IREE_VM_FUNCTION_LINKAGE_EXPORT, ordinal, &f);
           if (iree_status_is_not_found(status)) {
             iree_status_ignore(status);
             break;
diff --git a/iree/hal/local/loaders/vmvx_module_loader.c b/iree/hal/local/loaders/vmvx_module_loader.c
index 85aebda..036daa2 100644
--- a/iree/hal/local/loaders/vmvx_module_loader.c
+++ b/iree/hal/local/loaders/vmvx_module_loader.c
@@ -105,7 +105,7 @@
     for (iree_host_size_t i = 0; i < executable->entry_fn_count; ++i) {
       status = iree_vm_module_lookup_function_by_ordinal(
           bytecode_module, IREE_VM_FUNCTION_LINKAGE_EXPORT, i,
-          &executable->entry_fns[i], NULL);
+          &executable->entry_fns[i]);
       if (!iree_status_is_ok(status)) break;
       status = iree_hal_vmvx_executable_verify_entry_point(
           &executable->entry_fns[i]);
diff --git a/iree/samples/vulkan/vulkan_inference_gui.cc b/iree/samples/vulkan/vulkan_inference_gui.cc
index f30b810..f520a35 100644
--- a/iree/samples/vulkan/vulkan_inference_gui.cc
+++ b/iree/samples/vulkan/vulkan_inference_gui.cc
@@ -241,11 +241,11 @@
                  << bytecode_module_signature.export_function_count
                  << "> exported functions:";
   for (int i = 0; i < bytecode_module_signature.export_function_count; ++i) {
-    iree_string_view_t function_name;
-    iree_vm_function_signature_t function_signature;
-    IREE_CHECK_OK(bytecode_module->get_function(
-        bytecode_module->self, IREE_VM_FUNCTION_LINKAGE_EXPORT, i,
-        /*out_function=*/nullptr, &function_name, &function_signature));
+    iree_vm_function_t function;
+    IREE_CHECK_OK(iree_vm_module_lookup_function_by_ordinal(
+        bytecode_module, IREE_VM_FUNCTION_LINKAGE_EXPORT, i, &function));
+    auto function_name = iree_vm_function_name(&function);
+    auto function_signature = iree_vm_function_signature(&function);
     IREE_LOG(INFO) << "  " << i << ": '"
                    << std::string(function_name.data, function_name.size)
                    << "' with calling convention '"
diff --git a/iree/tools/iree-benchmark-module-main.cc b/iree/tools/iree-benchmark-module-main.cc
index 673adc3..04c7e65 100644
--- a/iree/tools/iree-benchmark-module-main.cc
+++ b/iree/tools/iree-benchmark-module-main.cc
@@ -234,23 +234,22 @@
 
   iree_status_t RegisterAllExportedFunctions() {
     IREE_TRACE_SCOPE0("IREEBenchmark::RegisterAllExportedFunctions");
-    iree_vm_function_t function;
     iree_vm_module_signature_t signature =
         input_module_->signature(input_module_->self);
     for (iree_host_size_t i = 0; i < signature.export_function_count; ++i) {
-      iree_string_view_t export_name;
-      IREE_CHECK_OK(input_module_->get_function(
-          input_module_->self, IREE_VM_FUNCTION_LINKAGE_EXPORT, i, &function,
-          &export_name, nullptr));
+      iree_vm_function_t function;
+      IREE_RETURN_IF_ERROR(iree_vm_module_lookup_function_by_ordinal(
+          input_module_, IREE_VM_FUNCTION_LINKAGE_EXPORT, i, &function));
+      iree_string_view_t function_name = iree_vm_function_name(&function);
 
       // We run anything with the 'benchmark' attribute.
       // If the attribute is not present we'll run anything that looks runnable.
       bool known_benchmark = !iree_string_view_is_empty(
           iree_vm_function_reflection_attr(&function, IREE_SV("benchmark")));
       if (!known_benchmark) {
-        if (iree_string_view_starts_with(export_name,
+        if (iree_string_view_starts_with(function_name,
                                          iree_make_cstring_view("__")) ||
-            iree_string_view_find_char(export_name, '$', 0) !=
+            iree_string_view_find_char(function_name, '$', 0) !=
                 IREE_STRING_VIEW_NPOS) {
           // Skip internal or special functions.
           continue;
@@ -270,7 +269,8 @@
       }
 
       iree::RegisterModuleBenchmarks(
-          std::string(export_name.data, export_name.size), context_, function,
+          std::string(function_name.data, function_name.size), context_,
+          function,
           /*inputs=*/nullptr);
     }
     return iree_ok_status();
diff --git a/iree/tools/iree-check-module-main.cc b/iree/tools/iree-check-module-main.cc
index 1983e81..a8f14e6 100644
--- a/iree/tools/iree-check-module-main.cc
+++ b/iree/tools/iree-check-module-main.cc
@@ -119,16 +119,15 @@
   for (iree_host_size_t ordinal = 0;
        ordinal < module_signature.export_function_count; ++ordinal) {
     iree_vm_function_t function;
-    iree_string_view_t export_name;
-    IREE_RETURN_IF_ERROR(iree_vm_module_lookup_function_by_ordinal(
-                             input_module, IREE_VM_FUNCTION_LINKAGE_EXPORT,
-                             ordinal, &function, &export_name),
-                         "looking up function export %zu", ordinal);
+    IREE_RETURN_IF_ERROR(
+        iree_vm_module_lookup_function_by_ordinal(
+            input_module, IREE_VM_FUNCTION_LINKAGE_EXPORT, ordinal, &function),
+        "looking up function export %zu", ordinal);
+    iree_string_view_t function_name = iree_vm_function_name(&function);
 
-    iree_string_view_t module_name = iree_vm_module_name(input_module);
-    if (iree_string_view_starts_with(export_name,
+    if (iree_string_view_starts_with(function_name,
                                      iree_make_cstring_view("__")) ||
-        iree_string_view_find_char(export_name, '$', 0) !=
+        iree_string_view_find_char(function_name, '$', 0) !=
             IREE_STRING_VIEW_NPOS) {
       // Skip internal or special functions.
       continue;
@@ -144,13 +143,14 @@
       return iree_make_status(IREE_STATUS_INVALID_ARGUMENT,
                               "expected function with no inputs or outputs, "
                               "but export '%.*s' has signature '%.*s'",
-                              (int)export_name.size, export_name.data,
+                              (int)function_name.size, function_name.data,
                               (int)signature.calling_convention.size,
                               signature.calling_convention.data);
     }
 
+    iree_string_view_t module_name = iree_vm_module_name(input_module);
     ::testing::RegisterTest(
-        module_name.data, export_name.data, nullptr,
+        module_name.data, function_name.data, nullptr,
         std::to_string(ordinal).c_str(), __FILE__, __LINE__,
         [&instance, modules, function]() -> CheckModuleTest* {
           return new CheckModuleTest(instance, modules, function);
diff --git a/iree/tools/iree-run-mlir-main.cc b/iree/tools/iree-run-mlir-main.cc
index c37bd18..cd695dd 100644
--- a/iree/tools/iree-run-mlir-main.cc
+++ b/iree/tools/iree-run-mlir-main.cc
@@ -263,10 +263,10 @@
 Status EvaluateFunction(iree_vm_context_t* context,
                         iree_hal_allocator_t* allocator,
                         iree_vm_function_t function,
-                        iree_string_view_t export_name) {
+                        iree_string_view_t function_name) {
   IREE_TRACE_SCOPE();
 
-  std::cout << "EXEC @" << std::string(export_name.data, export_name.size)
+  std::cout << "EXEC @" << std::string(function_name.data, function_name.size)
             << std::endl;
 
   // Parse input values from the flags.
@@ -326,14 +326,14 @@
   // Evaluate all exported functions.
   auto run_function = [&](int ordinal) -> Status {
     iree_vm_function_t function;
-    iree_string_view_t export_name;
     IREE_RETURN_IF_ERROR(iree_vm_module_lookup_function_by_ordinal(
                              bytecode_module, IREE_VM_FUNCTION_LINKAGE_EXPORT,
-                             ordinal, &function, &export_name),
+                             ordinal, &function),
                          "Looking up function export %d", ordinal);
-    if (iree_string_view_starts_with(export_name,
+    iree_string_view_t function_name = iree_vm_function_name(&function);
+    if (iree_string_view_starts_with(function_name,
                                      iree_make_cstring_view("__")) ||
-        iree_string_view_find_char(export_name, '$', 0) !=
+        iree_string_view_find_char(function_name, '$', 0) !=
             IREE_STRING_VIEW_NPOS) {
       // Skip internal or special functions.
       return OkStatus();
@@ -352,7 +352,7 @@
     // Invoke the function and print results.
     IREE_RETURN_IF_ERROR(
         EvaluateFunction(context, iree_hal_device_allocator(device), function,
-                         export_name),
+                         function_name),
         "Evaluating export function %d", ordinal);
 
     iree_vm_context_release(context);
diff --git a/iree/vm/bytecode_dispatch_test.cc b/iree/vm/bytecode_dispatch_test.cc
index ec62fa9..dc7dcf4 100644
--- a/iree/vm/bytecode_dispatch_test.cc
+++ b/iree/vm/bytecode_dispatch_test.cc
@@ -52,11 +52,12 @@
     iree_vm_module_signature_t signature = module->signature(module->self);
     test_params.reserve(test_params.size() + signature.export_function_count);
     for (int i = 0; i < signature.export_function_count; ++i) {
-      iree_string_view_t name;
-      IREE_CHECK_OK(module->get_function(module->self,
-                                         IREE_VM_FUNCTION_LINKAGE_EXPORT, i,
-                                         nullptr, &name, nullptr));
-      test_params.push_back({module_file, std::string(name.data, name.size)});
+      iree_vm_function_t function;
+      IREE_CHECK_OK(iree_vm_module_lookup_function_by_ordinal(
+          module, IREE_VM_FUNCTION_LINKAGE_EXPORT, i, &function));
+      iree_string_view_t function_name = iree_vm_function_name(&function);
+      test_params.push_back(
+          {module_file, std::string(function_name.data, function_name.size)});
     }
     iree_vm_module_release(module);
   }
diff --git a/iree/vm/module.c b/iree/vm/module.c
index 0a4e44d..9703b5b 100644
--- a/iree/vm/module.c
+++ b/iree/vm/module.c
@@ -253,10 +253,9 @@
 
 IREE_API_EXPORT iree_status_t iree_vm_module_lookup_function_by_ordinal(
     const iree_vm_module_t* module, iree_vm_function_linkage_t linkage,
-    iree_host_size_t ordinal, iree_vm_function_t* out_function,
-    iree_string_view_t* linkage_name) {
+    iree_host_size_t ordinal, iree_vm_function_t* out_function) {
   return module->get_function(module->self, linkage, ordinal, out_function,
-                              /*out_name=*/linkage_name,
+                              /*out_name=*/NULL,
                               /*out_signature=*/NULL);
 }
 
diff --git a/iree/vm/module.h b/iree/vm/module.h
index 69f06e5..db7d516 100644
--- a/iree/vm/module.h
+++ b/iree/vm/module.h
@@ -392,16 +392,9 @@
     iree_string_view_t name, iree_vm_function_t* out_function);
 
 // Looks up a function with the given ordinal and linkage in the |module|.
-// If |linkage_name| is not null, then it will be populated with the name
-// of the linkage record (i.e. the actual exported name vs the internal
-// name which would be returned in a subsequent call to iree_vm_function_name).
-// TODO(laurenzo): Remove out_linkage_name in favore of a LINKAGE_PUBLIC (with
-// the name that you'd get from a function_name call on that being the public
-// name).
 IREE_API_EXPORT iree_status_t iree_vm_module_lookup_function_by_ordinal(
     const iree_vm_module_t* module, iree_vm_function_linkage_t linkage,
-    iree_host_size_t ordinal, iree_vm_function_t* out_function,
-    iree_string_view_t* out_linkage_name);
+    iree_host_size_t ordinal, iree_vm_function_t* out_function);
 
 // Resolves a stack |frame| from the module to a |out_source_location|, if
 // debug information is available.