[llvm] Adding Matching and Inference Functionality to Propeller-PR2 (PR #162963)
    via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Oct 22 20:48:49 PDT 2025
    
    
  
================
@@ -0,0 +1,125 @@
+//===- llvm/CodeGen/MachineBlockHashInfo.h ----------------------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+// Compute the hashes of basic blocks.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CODEGEN_MACHINEBLOCKHASHINFO_H
+#define LLVM_CODEGEN_MACHINEBLOCKHASHINFO_H
+
+#include "llvm/CodeGen/MachineFunctionPass.h"
+
+namespace llvm {
+
+/// An object wrapping several components of a basic block hash. The combined
+/// (blended) hash is represented and stored as one uint64_t, while individual
+/// components are of smaller size (e.g., uint16_t or uint8_t).
+struct BlendedBlockHash {
+public:
+  explicit BlendedBlockHash(uint16_t Offset, uint16_t OpcodeHash,
+                            uint16_t InstrHash, uint16_t NeighborHash)
+      : Offset(Offset), OpcodeHash(OpcodeHash), InstrHash(InstrHash),
+        NeighborHash(NeighborHash) {}
+
+  explicit BlendedBlockHash(uint64_t CombinedHash) {
+
+    Offset = CombinedHash & 0xffff;
+
+    CombinedHash >>= 16;
+    OpcodeHash = CombinedHash & 0xffff;
+
+    CombinedHash >>= 16;
+    InstrHash = CombinedHash & 0xffff;
+
+    CombinedHash >>= 16;
+    NeighborHash = CombinedHash & 0xffff;
+  }
+
+  /// Combine the blended hash into uint64_t.
+  uint64_t combine() const {
+
+    uint64_t Hash = 0;
+
+    Hash |= uint64_t(NeighborHash);
+    Hash <<= 16;
+
+    Hash |= uint64_t(InstrHash);
+    Hash <<= 16;
+
+    Hash |= uint64_t(OpcodeHash);
+    Hash <<= 16;
+
+    Hash |= uint64_t(Offset);
+
+    return Hash;
+  }
+
+  /// Compute a distance between two given blended hashes. The smaller the
+  /// distance, the more similar two blocks are. For identical basic blocks,
+  /// the distance is zero.
+  /// Since OpcodeHash is highly stable, we consider a match good only if
+  /// the OpcodeHashes are identical. Mismatched OpcodeHashes lead to low
+  /// matching accuracy, and poor matches undermine the quality of final
+  /// inference. Notably, during inference, we also consider the matching
+  /// ratio of basic blocks (BBs). For MachineFunctions with a low matching
----------------
wdx727 wrote:
Done.
https://github.com/llvm/llvm-project/pull/162963
    
    
More information about the llvm-commits
mailing list