Skip to content

Commit

Permalink
[BOLT][AArch64] Speedup computeInstructionSize (llvm#121106)
Browse files Browse the repository at this point in the history
AArch64 instructions have a fixed size 4 bytes, no need to compute.
  • Loading branch information
liusy58 authored Jan 17, 2025
1 parent e83e0c3 commit 1fa02b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bolt/include/bolt/Core/BinaryContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -1363,6 +1363,12 @@ class BinaryContext {
if (std::optional<uint32_t> Size = MIB->getSize(Inst))
return *Size;

if (MIB->isPseudo(Inst))
return 0;

if (std::optional<uint32_t> Size = MIB->getInstructionSize(Inst))
return *Size;

if (!Emitter)
Emitter = this->MCE.get();
SmallString<256> Code;
Expand Down
5 changes: 5 additions & 0 deletions bolt/include/bolt/Core/MCPlusBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1204,6 +1204,11 @@ class MCPlusBuilder {
/// Get instruction size specified via annotation.
std::optional<uint32_t> getSize(const MCInst &Inst) const;

/// Get target-specific instruction size.
virtual std::optional<uint32_t> getInstructionSize(const MCInst &Inst) const {
return std::nullopt;
}

/// Set instruction size.
void setSize(MCInst &Inst, uint32_t Size) const;

Expand Down
5 changes: 5 additions & 0 deletions bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,11 @@ class AArch64MCPlusBuilder : public MCPlusBuilder {
}

uint16_t getMinFunctionAlignment() const override { return 4; }

std::optional<uint32_t>
getInstructionSize(const MCInst &Inst) const override {
return 4;
}
};

} // end anonymous namespace
Expand Down

0 comments on commit 1fa02b9

Please sign in to comment.