summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmir Ayupov <aaupov@fb.com>2023-05-08 18:53:48 -0700
committerAmir Ayupov <aaupov@fb.com>2023-05-08 18:54:29 -0700
commit6fcb91b2f756857f1295a28990738b5b6f924226 (patch)
tree648f167a07d7cfd897aafa22e7a1d526d7c179ef
parent19941b0468c746a8d7ea543600fb491fe9808b04 (diff)
downloadllvm-6fcb91b2f756857f1295a28990738b5b6f924226.tar.gz
[BOLT] Use opcode name in hashBlock
Use MCInst opcode name instead of opcode value in hashing. Opcode values are unstable wrt changes to target tablegen definitions, and we notice that as output mismatches in NFC testing. This makes BOLT YAML profile tied to a particular LLVM revision which is less portable than offset-based fdata profile. Switch to using opcode names which have 1:1 mapping with opcode values for any given LLVM revision, and are stable wrt modifications to .td files (except of course modifications to names themselves). Test Plan: D150154 is a test commit adding new X86 instruction which shifts opcode values. With current change, pre-aggregated-perf.test passes in nfc check mode. Without current change, pre-aggregated-perf.test expectedly fails. Reviewed By: #bolt, rafauler Differential Revision: https://reviews.llvm.org/D150005
-rw-r--r--bolt/lib/Core/HashUtilities.cpp11
1 files changed, 5 insertions, 6 deletions
diff --git a/bolt/lib/Core/HashUtilities.cpp b/bolt/lib/Core/HashUtilities.cpp
index 1c980e003f88..0752eaeabef8 100644
--- a/bolt/lib/Core/HashUtilities.cpp
+++ b/bolt/lib/Core/HashUtilities.cpp
@@ -13,6 +13,7 @@
#include "bolt/Core/HashUtilities.h"
#include "bolt/Core/BinaryContext.h"
#include "bolt/Core/BinaryFunction.h"
+#include "llvm/MC/MCInstPrinter.h"
namespace llvm {
namespace bolt {
@@ -116,13 +117,11 @@ std::string hashBlock(BinaryContext &BC, const BinaryBasicBlock &BB,
if (IsX86 && BC.MIB->isConditionalBranch(Inst))
Opcode = BC.MIB->getShortBranchOpcode(Opcode);
- if (Opcode == 0)
+ if (Opcode == 0) {
HashString.push_back(0);
-
- while (Opcode) {
- uint8_t LSB = Opcode & 0xff;
- HashString.push_back(LSB);
- Opcode = Opcode >> 8;
+ } else {
+ StringRef OpcodeName = BC.InstPrinter->getOpcodeName(Opcode);
+ HashString.append(OpcodeName.str());
}
for (const MCOperand &Op : MCPlus::primeOperands(Inst))