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

Rahman Lavaee via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 13 15:34:35 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.
----------------
rlavaee wrote:

Although I think this sentence is a bit ambiguous. Maybe rephrase to say "The control flow graph is uniquely represented by its level-order traversal". BTW, do you enforce any order on the traversal of the successors? If you don't, it won't be unique.

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


More information about the llvm-commits mailing list