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
This commit is contained in:
Dominic Chen 2019-12-16 19:01:26 -05:00
parent a4e1819c16
commit 79b4c897b8
No known key found for this signature in database
GPG Key ID: 7661C15B1B8EC438
1 changed files with 9 additions and 0 deletions

View File

@ -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();
}