diff --git a/bolt/include/bolt/Core/BinaryContext.h b/bolt/include/bolt/Core/BinaryContext.h index 115e59ca0697e5..94fe4aa8aa0e57 100644 --- a/bolt/include/bolt/Core/BinaryContext.h +++ b/bolt/include/bolt/Core/BinaryContext.h @@ -1363,6 +1363,12 @@ class BinaryContext { if (std::optional Size = MIB->getSize(Inst)) return *Size; + if (MIB->isPseudo(Inst)) + return 0; + + if (std::optional Size = MIB->getInstructionSize(Inst)) + return *Size; + if (!Emitter) Emitter = this->MCE.get(); SmallString<256> Code; diff --git a/bolt/include/bolt/Core/MCPlusBuilder.h b/bolt/include/bolt/Core/MCPlusBuilder.h index 3634fed9757ceb..5d77e6faff2fc6 100644 --- a/bolt/include/bolt/Core/MCPlusBuilder.h +++ b/bolt/include/bolt/Core/MCPlusBuilder.h @@ -1204,6 +1204,11 @@ class MCPlusBuilder { /// Get instruction size specified via annotation. std::optional getSize(const MCInst &Inst) const; + /// Get target-specific instruction size. + virtual std::optional getInstructionSize(const MCInst &Inst) const { + return std::nullopt; + } + /// Set instruction size. void setSize(MCInst &Inst, uint32_t Size) const; diff --git a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp index 679c9774c767f7..d752751c17932a 100644 --- a/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp +++ b/bolt/lib/Target/AArch64/AArch64MCPlusBuilder.cpp @@ -1792,6 +1792,11 @@ class AArch64MCPlusBuilder : public MCPlusBuilder { } uint16_t getMinFunctionAlignment() const override { return 4; } + + std::optional + getInstructionSize(const MCInst &Inst) const override { + return 4; + } }; } // end anonymous namespace