-
Notifications
You must be signed in to change notification settings - Fork 13.4k
ObjcRuntime.h: Add mips64, aarch64, and riscv64 to non-legacy dispatch #76694
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Conversation
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-clang-driver @llvm/pr-subscribers-clang Author: Hugo Melder (hmelder) ChangesThis PR updates the list of architectures for which libobjc2 has fast-path objc_msgSend implementations. Related to: gnustep/libobjc2#261 Full diff: https://github.com/llvm/llvm-project/pull/76694.diff 1 Files Affected:
diff --git a/clang/include/clang/Basic/ObjCRuntime.h b/clang/include/clang/Basic/ObjCRuntime.h
index 500b2462f00773..29392ad0a0f577 100644
--- a/clang/include/clang/Basic/ObjCRuntime.h
+++ b/clang/include/clang/Basic/ObjCRuntime.h
@@ -101,10 +101,17 @@ class ObjCRuntime {
// The GNUstep runtime uses a newer dispatch method by default from
// version 1.6 onwards
if (getKind() == GNUstep && getVersion() >= VersionTuple(1, 6)) {
- if (Arch == llvm::Triple::arm ||
- Arch == llvm::Triple::x86 ||
- Arch == llvm::Triple::x86_64)
- return false;
+ switch (Arch) {
+ case llvm::Triple::arm:
+ case llvm::Triple::x86:
+ case llvm::Triple::x86_64:
+ case llvm::Triple::aarch64:
+ case llvm::Triple::mips64:
+ case llvm::Triple::riscv64:
+ return false;
+ default:
+ return true;
+ }
}
else if ((getKind() == MacOSX) && isNonFragile() &&
(getVersion() >= VersionTuple(10, 0)) &&
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
if (Arch == llvm::Triple::arm || | ||
Arch == llvm::Triple::x86 || | ||
Arch == llvm::Triple::x86_64) | ||
switch (Arch) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version check above is not quite right for these.
AArch64 support is in 1.9.
RV64 in 2.2.
I think mips64 is correct (it looks like I added the code 9 years ago, which probably lines up with the 1.6 release).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The version check above is not quite right for these.
This was my first approach, but it seems like GNUstep and libobjc2 unit tests are always emitting -fobjc-runtime=gnustep-2.0
So one would need to change this flag in the build configuration everytime libobjc2 gets updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can do the version check and update the libobjc2 README to properly document this. I probably need to rewrite the detection in gnustep-make too -_-
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was my first approach, but it seems like GNUstep and libobjc2 unit tests are always emitting -fobjc-runtime=gnustep-2.0
That's fine. We should bump that in both places to the correct version. It's better than having the compiler emit things that are not supported when targeting a specific version of the runtime.
This should also come with a test to make sure that we’re generating objc_msgSend or the lookup functions with the runtime versions after / before the support for these architectures, respectively. |
Is libobjc2 included in the LLVM CI? I cannot find the place in the workflow where it is installed. |
No, clang tests are not executable. This test is the right approximate shape:
The RUN line invokes clang in a few different configurations (you want to invoke it with the |
It seems like isLegacyDispatchDefaultForArch is only called by the driver, and not when passing llvm-project/clang/lib/Driver/ToolChains/Clang.cpp Lines 3935 to 3953 in 11ac97c
Using the driver instead of the frontend does not work as there are platform checks in Example on macOS: clang: error: GNUstep Objective-C runtime version 2 incompatible with target binary format The result is that without specifying Do you have an idea on how we can test this instead? Tested with #flags="-fobjc-dispatch-method=mixed"
flags=""
rt=gnustep-2.0
triple="x86_64-unknown-freebsd"
build-llvm/bin/clang -cc1\
-triple ${triple} \
-fobjc-runtime=${rt} ${flags} \
-emit-llvm -o - gnustep2-message-dispatch.m | less gnustep2-message-dispatch.m// DEFINE: %{triple} =
// DEFINE: %{ver} =
// DEFINE: %{prefix} = CHECK-MSG-SEND
// DEFINE: %{check} = %clang_cc1 -triple %{triple} -fobjc-runtime=gnustep-%{ver} -emit-llvm -o - %s | FileCheck %s -check-prefix %{prefix}
// REDEFINE: %{ver} = 1.6
// REDEFINE: %{triple} = x86_64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = arm-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{prefix} = CHECK-MSG-LOOKUP
// REDEFINE: %{triple} = aarch64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = mips64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = riscv64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{ver} = 1.9
// REDEFINE: %{prefix} = CHECK-MSG-SEND
// REDEFINE: %{triple} = x86_64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = arm-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = aarch64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = mips64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{prefix} = CHECK-MSG-LOOKUP
// REDEFINE: %{triple} = riscv64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{ver} = 2.2
// REDEFINE: %{prefix} = CHECK-MSG-SEND
// REDEFINE: %{triple} = x86_64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = arm-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = aarch64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = mips64-unknown-freebsd
// RUN: %{check}
// REDEFINE: %{triple} = riscv64-unknown-freebsd
// RUN: %{check}
typedef struct {
int x;
int y;
int z[10];
} MyPoint;
void f0(id a) {
int i;
MyPoint pt = { 1, 2};
// CHECK-MSG-SEND: call {{.*}} @objc_msgSend
// CHECK-MSG-LOOKUP: call {{.*}} @objc_msg_lookup(
[a print0];
// CHECK-MSG-SEND: call {{.*}} @objc_msgSend
// CHECK-MSG-LOOKUP: call {{.*}} @objc_msg_lookup(
[a print1: 10];
// CHECK-MSG-SEND: call {{.*}} @objc_msgSend
// CHECK-MSG-LOOKUP: call {{.*}} @objc_msg_lookup(
[a print2: 10 and: "hello" and: 2.2];
// CHECK-MSG-SEND: call {{.*}} @objc_msgSend
// CHECK-MSG-LOOKUP: call {{.*}} @objc_msg_lookup(
[a takeStruct: pt ];
} |
I assume we can split the test into two parts:
|
Definition of -fobjc-dispatch-method:
Which is used in CGObjCGNU::GenerateMessageSend |
Ah, I forgot that was how it propagated. I think we only need the driver tests, there should be existing checks for the dispatch-method thing. |
Should be ready now! |
A lot of formatting changes seem to have crept into unrelated bits of the code, please can you revert them? You can use the clang-format-diff script to format only the bits that you’ve changed. |
Done. Sorry for the messy commit history. |
LGTM. @rjmccall, do you want to take a look? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if @davidchisnall's okay with it.
Forces Clang to use the fast path, which is not enabled by default on arm64 even though it's supported in the runtime. Can be removed when Clang 18 containing this patch is available via the Android SDK: llvm/llvm-project#76694
This PR updates the list of architectures for which libobjc2 has fast-path objc_msgSend implementations.
Related to: gnustep/libobjc2#261