[PATCH] D150005: [BOLT] Use opcode name in hashBlock

Amir Ayupov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 5 15:37:30 PDT 2023


Amir created this revision.
Amir added a reviewer: bolt.
Herald added a reviewer: rafauler.
Herald added subscribers: treapster, ayermolo.
Herald added a reviewer: maksfb.
Herald added a project: All.
Amir requested review of this revision.
Herald added subscribers: llvm-commits, yota9.
Herald added a project: LLVM.

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).


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D150005

Files:
  bolt/lib/Core/HashUtilities.cpp


Index: bolt/lib/Core/HashUtilities.cpp
===================================================================
--- bolt/lib/Core/HashUtilities.cpp
+++ 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 @@
     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))


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150005.519995.patch
Type: text/x-patch
Size: 915 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230505/0607be1c/attachment.bin>


More information about the llvm-commits mailing list