r348600 - Make CPUDispatch resolver emit dependent functions.

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 7 07:31:24 PST 2018


Author: erichkeane
Date: Fri Dec  7 07:31:23 2018
New Revision: 348600

URL: http://llvm.org/viewvc/llvm-project?rev=348600&view=rev
Log:
Make CPUDispatch resolver emit dependent functions.

Inline cpu_specific versions referenced before the cpu_dispatch function
weren't properly emitted, since they hadn't been referred to.  This
patch ensures that during resolver generation that all appropriate
versions are emitted.

Change-Id: I94c3766aaf9c75ca07a0ad8258efdbb834654ff8

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGen/attr-target-mv.c
    cfe/trunk/test/CodeGenCXX/attr-cpuspecific.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=348600&r1=348599&r2=348600&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Fri Dec  7 07:31:23 2018
@@ -2585,11 +2585,22 @@ void CodeGenModule::emitCPUDispatchDefin
 
     llvm::Constant *Func = GetGlobalValue(MangledName);
 
-    if (!Func)
+    if (!Func) {
+      GlobalDecl ExistingDecl = Manglings.lookup(MangledName);
+      if (ExistingDecl.getDecl() &&
+          ExistingDecl.getDecl()->getAsFunction()->isDefined()) {
+        EmitGlobalFunctionDefinition(ExistingDecl, nullptr);
+        Func = GetGlobalValue(MangledName);
+      } else {
+        if (!ExistingDecl.getDecl())
+          ExistingDecl = GD.getWithMultiVersionIndex(Index);
+
       Func = GetOrCreateLLVMFunction(
-          MangledName, DeclTy, GD.getWithMultiVersionIndex(Index),
+          MangledName, DeclTy, ExistingDecl,
           /*ForVTable=*/false, /*DontDefer=*/true,
           /*IsThunk=*/false, llvm::AttributeList(), ForDefinition);
+      }
+    }
 
     llvm::SmallVector<StringRef, 32> Features;
     Target.getCPUSpecificCPUDispatchFeatures(II->getName(), Features);

Modified: cfe/trunk/test/CodeGen/attr-target-mv.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-target-mv.c?rev=348600&r1=348599&r2=348600&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-target-mv.c (original)
+++ cfe/trunk/test/CodeGen/attr-target-mv.c Fri Dec  7 07:31:23 2018
@@ -223,10 +223,12 @@ void bar5() {
 // WINDOWS: define linkonce_odr dso_local void @foo_decls()
 // WINDOWS: define linkonce_odr dso_local void @foo_decls.sse4.2()
 
+// LINUX: define linkonce void @foo_multi(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // LINUX: define linkonce void @foo_multi.avx_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // LINUX: define linkonce void @foo_multi.fma4_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // LINUX: define linkonce void @foo_multi.arch_ivybridge_fma4_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})
 
+// WINDOWS: define linkonce_odr dso_local void @foo_multi(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // WINDOWS: define linkonce_odr dso_local void @foo_multi.avx_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // WINDOWS: define linkonce_odr dso_local void @foo_multi.fma4_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})
 // WINDOWS: define linkonce_odr dso_local void @foo_multi.arch_ivybridge_fma4_sse4.2(i32 %{{[^,]+}}, double %{{[^\)]+}})

Modified: cfe/trunk/test/CodeGenCXX/attr-cpuspecific.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-cpuspecific.cpp?rev=348600&r1=348599&r2=348600&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/attr-cpuspecific.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/attr-cpuspecific.cpp Fri Dec  7 07:31:23 2018
@@ -16,8 +16,11 @@ void foo() {
 // LINUX: define void (%struct.S*)* @_ZN1S4FuncEv.resolver
 // LINUX: ret void (%struct.S*)* @_ZN1S4FuncEv.S
 // LINUX: ret void (%struct.S*)* @_ZN1S4FuncEv.O
+// LINUX: declare void @_ZN1S4FuncEv.S
+// LINUX: define linkonce_odr void @_ZN1S4FuncEv.O
 
 // WINDOWS: define dso_local void @"?Func at S@@QEAAXXZ"(%struct.S*)
 // WINDOWS: musttail call void @"?Func at S@@QEAAXXZ.S"(%struct.S* %0)
 // WINDOWS: musttail call void @"?Func at S@@QEAAXXZ.O"(%struct.S* %0)
-
+// WINDOWS: declare dso_local void @"?Func at S@@QEAAXXZ.S"
+// WINDOWS: define linkonce_odr dso_local void @"?Func at S@@QEAAXXZ.O"




More information about the cfe-commits mailing list