[PATCH] D67058: [clang][CodeGen] Add alias for cpu_dispatch function with IFunc

Sr.Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Sep 4 06:06:24 PDT 2019


zsrkmyn added inline comments.


================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2957
+    if (!AliasFunc) {
+      auto *IFunc = cast<llvm::GlobalIFunc>(GetOrCreateLLVMFunction(
+          AliasName, DeclTy, GD, /*ForVTable=*/false, /*DontDefer=*/true,
----------------
erichkeane wrote:
> erichkeane wrote:
> > I think we want this in GetOrCreateMultiVersionResolver, so that it gets created when the ifunc does.  That way you just need a "FD->isCPUDispatchMultiVersion() || isCPUSpecificMultiVersion()" check inside the supportsIFunc branch.
> After discussing this offline, I believe this is the right function to create the alias.  The motivating example is:
> 
>     // TU1:
>     __attribute__((cpu_dispatch(a,b,c))) void foo(void);
> 
>     // TU2:
>     extern void foo(void);
> 
> Currently, TU1 doesn't bother to emit the ifunc, because we've attached emitting this to when this is referenced.
> 
> We made that choice because we expected TU2 to mark 'foo' as cpu_dispatch/cpu_specific in SOME way.  I believe that it is harmless to emit the ifunc all the time, which this is attempting to do.  However, this needs to change the ifunc to have LinkOnceODR linkage in GetOrCreateMultiVersionResolver, otherwise this can cause linker errors.
> 
> 
I've finished most parts. But I think we should also set the resolver to have LinkOnceODR Linkage. Otherwise, we cannot have the cpu_dispatch declaration in multiple TUs.

However there's no 'weak' symbol on Windows, so even setting the resolver linkage to LinkOnceODR cannot solve the duplicate defined symbol problem on Windows. Do you have any suggestions on it? :-)


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D67058/new/

https://reviews.llvm.org/D67058





More information about the cfe-commits mailing list