[llvm] [BOLT][AArch64] Speedup `computeInstructionSize` (PR #121106)

via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 25 03:47:12 PST 2024


https://github.com/liusy58 created https://github.com/llvm/llvm-project/pull/121106

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

>From 8aa3cb5087521eb001ffe82d6f34b8a1a0fe6cb6 Mon Sep 17 00:00:00 2001
From: liusy58 <liusy58 at linux.alibaba.com>
Date: Wed, 25 Dec 2024 19:45:08 +0800
Subject: [PATCH] [BOLT][AArch64]  Speedup `computeInstructionSize`

---
 bolt/include/bolt/Core/BinaryContext.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

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;



More information about the llvm-commits mailing list