Implement Attribute Target MultiVersioning
GCC's attribute 'target', in addition to being an optimization hint,
also allows function multiversioning. We currently have the former
implemented, this is the latter's implementation.
This works by enabling functions with the same name/signature to coexist,
so that they can all be emitted. Multiversion state is stored in the
FunctionDecl itself, and SemaDecl manages the definitions.
Note that it ends up having to permit redefinition of functions so
that they can all be emitted. Additionally, all versions of the function
must be emitted, so this also manages that.
Note that this includes some additional rules that GCC does not, since
defining something as a MultiVersion function after a usage has been made illegal.
The only 'history rewriting' that happens is if a function is emitted before
it has been converted to a multiversion'ed function, at which point its name
needs to be changed.
Function templates and virtual functions are NOT yet supported (not supported
in GCC either).
Additionally, constructors/destructors are disallowed, but the former is
planned.
llvm-svn: 322028
2018-01-09 05:34:17 +08:00
|
|
|
// RUN: %clang_cc1 -std=c++11 -triple x86_64-linux-gnu -fmodules -emit-llvm %s -o - | FileCheck %s
|
|
|
|
#pragma clang module build A
|
|
|
|
module A {}
|
|
|
|
#pragma clang module contents
|
|
|
|
#pragma clang module begin A
|
|
|
|
__attribute__((target("default"))) void f();
|
|
|
|
__attribute__((target("sse4.2"))) void f();
|
|
|
|
#pragma clang module end
|
|
|
|
#pragma clang module endbuild
|
|
|
|
|
|
|
|
#pragma clang module build B
|
|
|
|
module B {}
|
|
|
|
#pragma clang module contents
|
|
|
|
#pragma clang module begin B
|
|
|
|
__attribute__((target("default"))) void f();
|
|
|
|
__attribute__((target("sse4.2"))) void f();
|
|
|
|
#pragma clang module end
|
|
|
|
#pragma clang module endbuild
|
|
|
|
|
|
|
|
#pragma clang module import A
|
|
|
|
#pragma clang module import B
|
|
|
|
void g() { f(); }
|
|
|
|
|
|
|
|
// Negative tests to validate that the resolver only calls each 1x.
|
2019-09-11 09:54:48 +08:00
|
|
|
// CHECK: define weak_odr void ()* @_Z1fv.resolver
|
Implement Attribute Target MultiVersioning
GCC's attribute 'target', in addition to being an optimization hint,
also allows function multiversioning. We currently have the former
implemented, this is the latter's implementation.
This works by enabling functions with the same name/signature to coexist,
so that they can all be emitted. Multiversion state is stored in the
FunctionDecl itself, and SemaDecl manages the definitions.
Note that it ends up having to permit redefinition of functions so
that they can all be emitted. Additionally, all versions of the function
must be emitted, so this also manages that.
Note that this includes some additional rules that GCC does not, since
defining something as a MultiVersion function after a usage has been made illegal.
The only 'history rewriting' that happens is if a function is emitted before
it has been converted to a multiversion'ed function, at which point its name
needs to be changed.
Function templates and virtual functions are NOT yet supported (not supported
in GCC either).
Additionally, constructors/destructors are disallowed, but the former is
planned.
llvm-svn: 322028
2018-01-09 05:34:17 +08:00
|
|
|
// CHECK: ret void ()* @_Z1fv.sse4.2
|
|
|
|
// CHECK-NOT: ret void ()* @_Z1fv.sse4.2
|
|
|
|
// CHECK: ret void ()* @_Z1fv
|
|
|
|
// CHECK-NOT: ret void ()* @_Z1fv
|