[llvm] Add a pass to calculate machine function's cfg hash to detect whether… (PR #84145)

via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 17 23:44:19 PDT 2024


================
@@ -0,0 +1,79 @@
+//===-- MachineFunctionHashBuilder.cpp ----------------------------------*-
+// 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
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// This file contains the implementation of pass about calculating machine
+/// function hash.
+//===----------------------------------------------------------------------===//
+#include "llvm/CodeGen/MachineFunctionHashBuilder.h"
+#include "llvm/ADT/StringMap.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/CommandLine.h"
+#include "llvm/Support/MD5.h"
+#include "llvm/Support/raw_ostream.h"
+#include <queue>
+#include <unordered_map>
+#include <unordered_set>
+
+using namespace llvm;
+static cl::opt<bool>
+    MFCFGHashDump("mf-cfg-hash-dump",
+                  cl::desc("Dump machine function's control flow grpah hash"),
+                  cl::init(false), cl::Hidden);
+
+// Calculate machine function hash in level order traversal.
+// For each machine basic block, using its mbb's BaseID,
+// size of successors and  successors' mbb's BaseID to update hash.
+// These informations can make graph unique.
+static uint64_t calculateMBBCFGHash(MachineFunction &MF) {
+  std::unordered_set<MachineBasicBlock *> Visited;
+  MD5 Hash;
+  std::queue<MachineBasicBlock *> Q;
----------------
lifengxiang1025 wrote:

Done.

https://github.com/llvm/llvm-project/pull/84145


More information about the llvm-commits mailing list