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

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


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-bolt

Author: Nicholas (liusy58)

<details>
<summary>Changes</summary>

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
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;

``````````

</details>


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


More information about the llvm-commits mailing list