Skip to content

[BOLT][AArch64] Speedup computeInstructionSize #121106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
Merged

Conversation

liusy58
Copy link
Contributor

@liusy58 liusy58 commented Dec 25, 2024

AArch64 instructions have a fixed size 4 bytes, no need to compute.

@llvmbot
Copy link
Member

llvmbot commented Dec 25, 2024

@llvm/pr-subscribers-bolt

Author: Nicholas (liusy58)

Changes

AArch64 instructions has a fixed size 4 bytes, no need to compute.


Full diff: https://github.com/llvm/llvm-project/pull/121106.diff

1 Files Affected:

  • (modified) bolt/include/bolt/Core/BinaryContext.h (+9-1)
diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h
index 115e59ca0697e5..22764098700214 100644
--- a/bolt/include/bolt/Core/BinaryContext.h
+++ b/bolt/include/bolt/Core/BinaryContext.h
@@ -1362,7 +1362,15 @@ class BinaryContext {
                          const MCCodeEmitter *Emitter = nullptr) const {
     if (std::optional<uint32_t> Size = MIB->getSize(Inst))
       return *Size;
-
+    // Pseudo instrs will not be emiitted and have no size.
+    if (MIB->isPseudo(Inst)) {
+      return 0;
+    }
+    // Directly return 4 because AArch64 instructions always have a
+    // fixed size of 4 bytes.
+    if (isAArch64()) {
+      return 4;
+    }
     if (!Emitter)
       Emitter = this->MCE.get();
     SmallString<256> Code;

@liusy58
Copy link
Contributor Author

liusy58 commented Dec 25, 2024

Every patch requires testing, but I haven't found a suitable way to evaluate its performance. Any suggestions


std::optional<uint32_t>
getInstructionSize(const MCInst &Inst) const override {
if (isPseudo(Inst)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (isPseudo(Inst)) {
if (isPseudo(Inst))
return 0;
return 4;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BTW maybe move isPseudo check to computeInstructionSize?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done~

Copy link
Member

@yota9 yota9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM Thanks, just fix a small nit with brackets, thanks!

@liusy58
Copy link
Contributor Author

liusy58 commented Jan 10, 2025

@yota9 hi, I have updated, please review again!

@liusy58 liusy58 requested a review from yota9 January 13, 2025 03:02
Copy link
Member

@yota9 yota9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@liusy58 liusy58 merged commit 1fa02b9 into llvm:main Jan 17, 2025
7 checks passed
@liusy58 liusy58 deleted the test branch January 17, 2025 01:48
liusy58 added a commit to liusy58/llvm-project that referenced this pull request Jan 17, 2025
AArch64 instructions have a fixed size 4 bytes, no need to compute.
liusy58 added a commit to liusy58/llvm-project that referenced this pull request Jan 17, 2025
AArch64 instructions have a fixed size 4 bytes, no need to compute.
liusy58 added a commit to liusy58/llvm-project that referenced this pull request Jan 17, 2025
AArch64 instructions have a fixed size 4 bytes, no need to compute.
liusy58 added a commit to liusy58/llvm-project that referenced this pull request Jan 17, 2025
AArch64 instructions have a fixed size 4 bytes, no need to compute.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants