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

Erich Keane via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 3 09:18:14 PDT 2019


erichkeane 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:
> 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.




================
Comment at: clang/lib/CodeGen/CodeGenModule.cpp:2961
+      auto *GA = llvm::GlobalAlias::create(
+         DeclTy, 0, getFunctionLinkage(GD), AliasName, IFunc, &getModule());
+      const auto *D = GD.getDecl();
----------------
I think the alias always needs LinkOnceODR linkage, to match the (new) IFunc linkage.


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