[PATCH] D106128: [lld-macho] Use immediate encodings for bind opcodes
Vincent Lee via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 15 22:33:13 PDT 2021
thevinster created this revision.
Herald added a reviewer: int3.
Herald added a reviewer: gkm.
Herald added a project: lld-macho.
Herald added a reviewer: lld-macho.
thevinster requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Implement pass 3 of bind opcodes from ld64. This change
is already behind an O2 <https://reviews.llvm.org/owners/package/2/> flag so it shouldn't impact current performance.
I verified ld64's output with the output LLD and they were both emitting
the same optimized bind opcodes (although in a slightly different order).
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D106128
Files:
lld/MachO/SyntheticSections.cpp
lld/test/MachO/bind-opcodes.s
Index: lld/test/MachO/bind-opcodes.s
===================================================================
--- lld/test/MachO/bind-opcodes.s
+++ lld/test/MachO/bind-opcodes.s
@@ -9,6 +9,7 @@
## 1/ We emit exactly one BIND_OPCODE_SET_SYMBOL_TRAILING_FLAGS_IMM per symbol.
## 2/ Combine BIND_OPCODE_DO_BIND and BIND_OPCODE_ADD_ADDR_ULEB pairs.
## 3/ Compact BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
+## 4/ Use BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED if possible.
# RUN: obj2yaml %t/test | FileCheck %s
# CHECK: BindOpcodes:
@@ -54,9 +55,8 @@
# CHECK-NEXT: Imm: 0
# CHECK-NEXT: ULEBExtraData: [ 0xFFFFFFFFFFFFEFD0 ]
# CHECK-NEXT: Symbol: ''
-# CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
-# CHECK-NEXT: Imm: 0
-# CHECK-NEXT: ULEBExtraData: [ 0x8 ]
+# CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED
+# CHECK-NEXT: Imm: 1
# CHECK-NEXT: Symbol: ''
# CHECK-NEXT: Opcode: BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB
# CHECK-NEXT: Imm: 0
Index: lld/MachO/SyntheticSections.cpp
===================================================================
--- lld/MachO/SyntheticSections.cpp
+++ lld/MachO/SyntheticSections.cpp
@@ -361,6 +361,16 @@
if (i == opcodes.size())
opcodes[pWrite] = opcodes[i - 1];
opcodes.resize(pWrite + 1);
+
+ // Pass 3: Use immediate encodings
+ for (BindIR* p = &opcodes[0]; p->opcode != BIND_OPCODE_DONE; ++p) {
+ if ((p->opcode == BIND_OPCODE_DO_BIND_ADD_ADDR_ULEB)
+ && (p->data < (15*sizeof(uint64_t)))
+ && ((p->data % sizeof(uint64_t)) == 0)) {
+ p->opcode = BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED;
+ p->data = p->data/sizeof(uint64_t);
+ }
+ }
}
static void flushOpcodes(const BindIR &op, raw_svector_ostream &os) {
@@ -384,6 +394,9 @@
encodeULEB128(op.consecutiveCount, os);
encodeULEB128(op.data, os);
break;
+ case BIND_OPCODE_DO_BIND_ADD_ADDR_IMM_SCALED:
+ os << static_cast<uint8_t>(op.opcode | op.data);
+ break;
default:
llvm_unreachable("cannot bind to an unrecognized symbol");
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106128.359222.patch
Type: text/x-patch
Size: 2135 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210716/423d3a79/attachment.bin>
More information about the llvm-commits
mailing list