[clang] 7b66160 - Fix Target Multiversioning renaming.

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 9 08:29:34 PDT 2020


Author: Erich Keane
Date: 2020-03-09T08:29:18-07:00
New Revision: 7b661608287e84d6bec24262a0a42c1d8b65fcc6

URL: https://github.com/llvm/llvm-project/commit/7b661608287e84d6bec24262a0a42c1d8b65fcc6
DIFF: https://github.com/llvm/llvm-project/commit/7b661608287e84d6bec24262a0a42c1d8b65fcc6.diff

LOG: Fix Target Multiversioning renaming.

The initial implementation only did 'first declaration renaming' when
a default version came after. This is insufficient in cases where a
default does not exist, so this patch makes sure that we do the renaming
in all cases.

This renaming is necessary because we emit the first declaration before
knowing that it IS a target multiversion function, which would change
its name. The second declaration (the one that caused the
multiversioning) then needs to make sure that the first one has its name
changed to be consistent with the resolver usage.

Added: 
    

Modified: 
    clang/lib/CodeGen/CodeGenModule.cpp
    clang/test/CodeGen/attr-target-mv.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp
index 0ee315776d33..415633536ad8 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -3141,8 +3141,7 @@ llvm::Constant *CodeGenModule::GetOrCreateLLVMFunction(
       (void)OpenMPRuntime->emitDeclareVariant(GD, /*IsForDefinition=*/true);
 
     if (FD->isMultiVersion()) {
-      const auto *TA = FD->getAttr<TargetAttr>();
-      if (TA && TA->isDefaultVersion())
+      if (FD->hasAttr<TargetAttr>())
         UpdateMultiVersionNames(GD, FD);
       if (!IsForDefinition)
         return GetOrCreateMultiVersionResolver(GD, Ty, FD);

diff  --git a/clang/test/CodeGen/attr-target-mv.c b/clang/test/CodeGen/attr-target-mv.c
index c0c3de5f991a..c089b06d238c 100644
--- a/clang/test/CodeGen/attr-target-mv.c
+++ b/clang/test/CodeGen/attr-target-mv.c
@@ -47,6 +47,9 @@ void bar5() {
   fwd_decl_avx();
 }
 
+int __attribute__((target("avx"))) changed_to_mv(void) { return 0;}
+int __attribute__((target("fma4"))) changed_to_mv(void) { return 1;}
+
 // LINUX: @foo.ifunc = weak_odr ifunc i32 (), i32 ()* ()* @foo.resolver
 // LINUX: @foo_inline.ifunc = weak_odr ifunc i32 (), i32 ()* ()* @foo_inline.resolver
 // LINUX: @foo_decls.ifunc = weak_odr ifunc void (), void ()* ()* @foo_decls.resolver
@@ -194,6 +197,12 @@ void bar5() {
 // WINDOWS: call i32 @fwd_decl_avx.avx
 // WINDOWS: call i32 @fwd_decl_avx
 
+// LINUX: define i32 @changed_to_mv.avx()
+// LINUX: define i32 @changed_to_mv.fma4()
+
+// WINDOWS: define dso_local i32 @changed_to_mv.avx()
+// WINDOWS: define dso_local i32 @changed_to_mv.fma4()
+
 // LINUX: declare i32 @foo.arch_sandybridge()
 // WINDOWS: declare dso_local i32 @foo.arch_sandybridge()
 


        


More information about the cfe-commits mailing list