[llvm] 79b4c89 - llvm-diff: Perform structural comparison on GlobalVariables, if possible

Dominic Chen via llvm-commits llvm-commits at lists.llvm.org
Tue Dec 17 11:22:53 PST 2019


Author: Dominic Chen
Date: 2019-12-17T14:21:48-05:00
New Revision: 79b4c897b8ea5d28af1a2455c7409fc0df803079

URL: https://github.com/llvm/llvm-project/commit/79b4c897b8ea5d28af1a2455c7409fc0df803079
DIFF: https://github.com/llvm/llvm-project/commit/79b4c897b8ea5d28af1a2455c7409fc0df803079.diff

LOG: llvm-diff: Perform structural comparison on GlobalVariables, if possible

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

Subscribers: llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71582

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/tools/llvm-
diff /DifferenceEngine.cpp b/llvm/tools/llvm-
diff /DifferenceEngine.cpp
index bc93ece86490..564ce7870592 100644
--- a/llvm/tools/llvm-
diff /DifferenceEngine.cpp
+++ b/llvm/tools/llvm-
diff /DifferenceEngine.cpp
@@ -732,5 +732,14 @@ void DifferenceEngine::
diff (Module *L, Module *R) {
 
 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->hasLocalLinkage() && GVL->hasUniqueInitializer() &&
+        GVR->hasLocalLinkage() && GVR->hasUniqueInitializer())
+      return GVL->getInitializer() == GVR->getInitializer();
+  }
+
   return L->getName() == R->getName();
 }


        


More information about the llvm-commits mailing list