[PATCH] D71582: llvm-diff: Perform structural comparison on GlobalVariables, if possible

Dominic Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 17:12:32 PST 2019


ddcc created this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
ddcc added a reviewer: rjmccall.

Names of GlobalVariables may not be preserved depending on compilation options, so prefer a structural diff


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D71582

Files:
  llvm/tools/llvm-diff/DifferenceEngine.cpp


Index: llvm/tools/llvm-diff/DifferenceEngine.cpp
===================================================================
--- llvm/tools/llvm-diff/DifferenceEngine.cpp
+++ llvm/tools/llvm-diff/DifferenceEngine.cpp
@@ -732,5 +732,13 @@
 
 bool DifferenceEngine::equivalentAsOperands(GlobalValue *L, GlobalValue *R) {
   if (globalValueOracle) return (*globalValueOracle)(L, R);
+
+  if (isa<GlobalVariable>(L) && isa<GlobalVariable>(R)) {
+    GlobalVariable *GVL = cast<GlobalVariable>(L);
+    GlobalVariable *GVR = cast<GlobalVariable>(R);
+    if (GVL->hasUniqueInitializer() && GVR->hasUniqueInitializer())
+      return GVL->getInitializer() == GVR->getInitializer();
+  }
+
   return L->getName() == R->getName();
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71582.234195.patch
Type: text/x-patch
Size: 718 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191217/feaa8a26/attachment.bin>


More information about the llvm-commits mailing list