
It was raised in https://github.com/llvm/llvm-project/issues/81494 that we are not generating correct code when there is no TU-local caller. The suggestion was to emit a resolver: * Whenever there is a use in the TU. * When the TU has a definition of the default version. See the comment for more details: https://github.com/llvm/llvm-project/issues/81494#issuecomment-1985963497 This got addressed with https://github.com/llvm/llvm-project/pull/84405. Generating a resolver on use means that we may end up with multiple resolvers across different translation units. Those resolvers may not be the same because each translation unit may contain different version declarations (user's fault). Therefore the order of linking the final image determines which of these weak symbols gets selected, resulting in non consisted behavior. I am proposing to stop emitting a resolver on use and only do so in the translation unit which contains the default definition. This way we guarantee the existence of a single resolver. Now, when a versioned function is used we want to emit a declaration of the function symbol omitting the multiversion mangling. I have added a requirement to ACLE mandating that all the function versions are declared in the translation unit which contains the default definition: https://github.com/ARM-software/acle/pull/328
111 lines
4.3 KiB
C++
111 lines
4.3 KiB
C++
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --check-globals all --include-generated-funcs --version 5
|
|
// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-llvm %s -o - | FileCheck %s
|
|
|
|
namespace Name {
|
|
int __attribute((target_version("default"))) foo() { return 0; }
|
|
}
|
|
|
|
namespace Name {
|
|
int __attribute((target_version("sve"))) foo() { return 1; }
|
|
}
|
|
|
|
int bar() { return Name::foo(); }
|
|
|
|
namespace OtherName {
|
|
int __attribute((target_version("sve"))) foo() { return 2; }
|
|
}
|
|
|
|
int baz() { return OtherName::foo(); }
|
|
|
|
namespace Foo {
|
|
int bar();
|
|
__attribute((target_version("default"))) int bar() { return 0; }
|
|
__attribute((target_version("mops"))) int bar() { return 1; }
|
|
}
|
|
|
|
//.
|
|
// CHECK: @__aarch64_cpu_features = external dso_local global { i64 }
|
|
// CHECK: @_ZN4Name3fooEv = weak_odr ifunc i32 (), ptr @_ZN4Name3fooEv.resolver
|
|
// CHECK: @_ZN3Foo3barEv = weak_odr ifunc i32 (), ptr @_ZN3Foo3barEv.resolver
|
|
//.
|
|
// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv._Msve(
|
|
// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: ret i32 1
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_Z3barv(
|
|
// CHECK-SAME: ) #[[ATTR1:[0-9]+]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZN4Name3fooEv()
|
|
// CHECK-NEXT: ret i32 [[CALL]]
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_ZN9OtherName3fooEv._Msve(
|
|
// CHECK-SAME: ) #[[ATTR0]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: ret i32 2
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_Z3bazv(
|
|
// CHECK-SAME: ) #[[ATTR1]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: [[CALL:%.*]] = call noundef i32 @_ZN9OtherName3fooEv()
|
|
// CHECK-NEXT: ret i32 [[CALL]]
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_ZN3Foo3barEv.default(
|
|
// CHECK-SAME: ) #[[ATTR1]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: ret i32 0
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_ZN3Foo3barEv._Mmops(
|
|
// CHECK-SAME: ) #[[ATTR3:[0-9]+]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: ret i32 1
|
|
//
|
|
//
|
|
// CHECK-LABEL: define dso_local noundef i32 @_ZN4Name3fooEv.default(
|
|
// CHECK-SAME: ) #[[ATTR1]] {
|
|
// CHECK-NEXT: [[ENTRY:.*:]]
|
|
// CHECK-NEXT: ret i32 0
|
|
//
|
|
//
|
|
// CHECK-LABEL: define weak_odr ptr @_ZN4Name3fooEv.resolver() comdat {
|
|
// CHECK-NEXT: [[RESOLVER_ENTRY:.*:]]
|
|
// CHECK-NEXT: call void @__init_cpu_features_resolver()
|
|
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
|
|
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 1073741824
|
|
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 1073741824
|
|
// CHECK-NEXT: [[TMP3:%.*]] = and i1 true, [[TMP2]]
|
|
// CHECK-NEXT: br i1 [[TMP3]], label %[[RESOLVER_RETURN:.*]], label %[[RESOLVER_ELSE:.*]]
|
|
// CHECK: [[RESOLVER_RETURN]]:
|
|
// CHECK-NEXT: ret ptr @_ZN4Name3fooEv._Msve
|
|
// CHECK: [[RESOLVER_ELSE]]:
|
|
// CHECK-NEXT: ret ptr @_ZN4Name3fooEv.default
|
|
//
|
|
//
|
|
// CHECK-LABEL: define weak_odr ptr @_ZN3Foo3barEv.resolver() comdat {
|
|
// CHECK-NEXT: [[RESOLVER_ENTRY:.*:]]
|
|
// CHECK-NEXT: call void @__init_cpu_features_resolver()
|
|
// CHECK-NEXT: [[TMP0:%.*]] = load i64, ptr @__aarch64_cpu_features, align 8
|
|
// CHECK-NEXT: [[TMP1:%.*]] = and i64 [[TMP0]], 576460752303423488
|
|
// CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 576460752303423488
|
|
// CHECK-NEXT: [[TMP3:%.*]] = and i1 true, [[TMP2]]
|
|
// CHECK-NEXT: br i1 [[TMP3]], label %[[RESOLVER_RETURN:.*]], label %[[RESOLVER_ELSE:.*]]
|
|
// CHECK: [[RESOLVER_RETURN]]:
|
|
// CHECK-NEXT: ret ptr @_ZN3Foo3barEv._Mmops
|
|
// CHECK: [[RESOLVER_ELSE]]:
|
|
// CHECK-NEXT: ret ptr @_ZN3Foo3barEv.default
|
|
//
|
|
//.
|
|
// CHECK: attributes #[[ATTR0]] = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
|
|
// CHECK: attributes #[[ATTR1]] = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" }
|
|
// CHECK: attributes #[[ATTR2:[0-9]+]] = { "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+fp-armv8,+fullfp16,+neon,+sve" }
|
|
// CHECK: attributes #[[ATTR3]] = { mustprogress noinline nounwind optnone "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-features"="+mops" }
|
|
//.
|
|
// CHECK: [[META0:![0-9]+]] = !{i32 1, !"wchar_size", i32 4}
|
|
// CHECK: [[META1:![0-9]+]] = !{!"{{.*}}clang version {{.*}}"}
|
|
//.
|