[clang] [FMV] Emit the resolver along with the default version definition. (PR #84405)

Jon Roelofs via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 16:03:46 PDT 2024


================
@@ -84,9 +84,33 @@ int hoo(void) {
   return fp1() + fp2();
 }
 
+// This should generate one target version but no resolver.
+__attribute__((target_version("default"))) int unused_with_forward_default_decl(void);
+__attribute__((target_version("mops"))) int unused_with_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+extern int unused_with_implicit_extern_forward_default_decl(void);
+__attribute__((target_version("dotprod")))
+int unused_with_implicit_extern_forward_default_decl(void) { return 0; }
 
+// This should also generate one target version but no resolver.
+__attribute__((target_version("aes"))) int unused_with_default_decl(void) { return 0; }
+__attribute__((target_version("default"))) int unused_with_default_decl(void);
 
+// This should generate two target versions and the resolver.
+__attribute__((target_version("sve"))) int unused_with_default_def(void) { return 0; }
+__attribute__((target_version("default"))) int unused_with_default_def(void) { return 1; }
+
+// This should also generate two target versions and the resolver.
+__attribute__((target_version("fp16"))) int unused_with_implicit_default_def(void) { return 0; }
+int unused_with_implicit_default_def(void) { return 1; }
+
+// This should also generate two target versions and the resolver.
+int unused_with_implicit_forward_default_def(void) { return 0; }
+__attribute__((target_version("lse"))) int unused_with_implicit_forward_default_def(void) { return 1; }
+
+// This should generate a normal function.
+__attribute__((target_version("rdm"))) int unused_without_default(void) { return 0; }
----------------
jroelofs wrote:

IIUC this breaks a use case I am _very_ interested in:

header.h:
```
int defined_in_separate_files(void);
```

feature_a.c:
```
#include <header.h>
__attribute__((target_version("featurea")))
int defined_in_separate_files(void) { return 1; }
```

feature_b.c:
```
#include <header.h>
__attribute__((target_version("featureb")))
int defined_in_separate_files(void) { return 2; }
```

default.c:
```
#include <header.h>

__attribute__((target_version("rdm")))
int defined_in_separate_files(void);

__attribute__((target_version("lse")))
int defined_in_separate_files(void);

__attribute__((target_version("default")))
int defined_in_separate_files(void) { return 0; }
```

In my experience, the functions that my users want to multi-version tend to be pretty large and live in separate files, organized per architectural feature that they want to take advantage of.

At the very least it adds a sharp edge: they need to declare the default version in each TU, or put it in a private header shared between them.

https://github.com/llvm/llvm-project/pull/84405


More information about the cfe-commits mailing list