Skip to content

Commit 1fa02b9

Browse files
authored
[BOLT][AArch64] Speedup computeInstructionSize (#121106)
AArch64 instructions have a fixed size 4 bytes, no need to compute.
1 parent e83e0c3 commit 1fa02b9

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

bolt/include/bolt/Core/BinaryContext.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,6 +1363,12 @@ class BinaryContext {
13631363
if (std::optional<uint32_t> Size = MIB->getSize(Inst))
13641364
return *Size;
13651365

1366+
if (MIB->isPseudo(Inst))
1367+
return 0;
1368+
1369+
if (std::optional<uint32_t> Size = MIB->getInstructionSize(Inst))
1370+
return *Size;
1371+
13661372
if (!Emitter)
13671373
Emitter = this->MCE.get();
13681374
SmallString<256> Code;

bolt/include/bolt/Core/MCPlusBuilder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,6 +1204,11 @@ class MCPlusBuilder {
12041204
/// Get instruction size specified via annotation.
12051205
std::optional<uint32_t> getSize(const MCInst &Inst) const;
12061206

1207+
/// Get target-specific instruction size.
1208+
virtual std::optional<uint32_t> getInstructionSize(const MCInst &Inst) const {
1209+
return std::nullopt;
1210+
}
1211+
12071212
/// Set instruction size.
12081213
void setSize(MCInst &Inst, uint32_t Size) const;
12091214

bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,11 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
17921792
}
17931793

17941794
uint16_t getMinFunctionAlignment() const override { return 4; }
1795+
1796+
std::optional<uint32_t>
1797+
getInstructionSize(const MCInst &Inst) const override {
1798+
return 4;
1799+
}
17951800
};
17961801

17971802
} // end anonymous namespace

0 commit comments

Comments
 (0)