From 33f6b281902751d4ec3ca2e430f823d0393e682d Mon Sep 17 00:00:00 2001 From: wangjue Date: Fri, 18 Apr 2025 08:15:07 +0000 Subject: [PATCH 1/2] [BOLT] Fix the inaccurate profile data check --- bolt/lib/Profile/DataReader.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp index f2e999bbfdc6d..d40ae1ab6d3e9 100644 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -524,6 +524,9 @@ float DataReader::evaluateProfileData(BinaryFunction &BF, // when we identify tail calls, so they are still represented // by regular branch instructions and we need isBranch() here. MCInst *Instr = BF.getInstructionAtOffset(BI.From.Offset); + // If it's a RISCV PseudoCALL - fix it + if (!Instr && BC.isRISCV()) + Instr = BF.getInstructionAtOffset(BI.From.Offset + 4); // If it's a prefix - skip it. if (Instr && BC.MIB->isPrefix(*Instr)) Instr = BF.getInstructionAtOffset(BI.From.Offset + 1); From 4c5413fd4a3d9399531d0355d04b1bf7dfa8a637 Mon Sep 17 00:00:00 2001 From: wangjue Date: Wed, 23 Apr 2025 07:35:40 +0000 Subject: [PATCH 2/2] [BOLT] Use the isRISCVCall function to determine whether it is auipc+jalr instruction --- bolt/lib/Core/BinaryFunction.cpp | 8 ++++++++ bolt/lib/Profile/DataReader.cpp | 3 --- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/bolt/lib/Core/BinaryFunction.cpp b/bolt/lib/Core/BinaryFunction.cpp index 184a4462b356a..6e258da5ee83a 100644 --- a/bolt/lib/Core/BinaryFunction.cpp +++ b/bolt/lib/Core/BinaryFunction.cpp @@ -4658,10 +4658,18 @@ MCInst *BinaryFunction::getInstructionAtOffset(uint64_t Offset) { if (!BB) return nullptr; + MCInst preInst; for (MCInst &Inst : *BB) { constexpr uint32_t InvalidOffset = std::numeric_limits::max(); if (Offset == BC.MIB->getOffsetWithDefault(Inst, InvalidOffset)) return &Inst; + // If it's a RISCV PseudoCALL - fix it + if (BC.isRISCV() && + Offset == BC.MIB->getOffsetWithDefault(Inst, InvalidOffset) - 4) { + if (BC.MIB->isRISCVCall(preInst, Inst)) + return &Inst; + } + preInst = Inst; } if (MCInst *LastInstr = BB->getLastNonPseudoInstr()) { diff --git a/bolt/lib/Profile/DataReader.cpp b/bolt/lib/Profile/DataReader.cpp index d40ae1ab6d3e9..f2e999bbfdc6d 100644 --- a/bolt/lib/Profile/DataReader.cpp +++ b/bolt/lib/Profile/DataReader.cpp @@ -524,9 +524,6 @@ float DataReader::evaluateProfileData(BinaryFunction &BF, // when we identify tail calls, so they are still represented // by regular branch instructions and we need isBranch() here. MCInst *Instr = BF.getInstructionAtOffset(BI.From.Offset); - // If it's a RISCV PseudoCALL - fix it - if (!Instr && BC.isRISCV()) - Instr = BF.getInstructionAtOffset(BI.From.Offset + 4); // If it's a prefix - skip it. if (Instr && BC.MIB->isPrefix(*Instr)) Instr = BF.getInstructionAtOffset(BI.From.Offset + 1);