From aaf3afccffd0b45c0cea16421b5c9384e2c8d5f3 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 8 Jan 2016 01:16:39 +0000 Subject: [PATCH] IntEqClasses: Let join() return the new leader The new leader is known anyway so we can return it for some micro optimization in code where it is easy to pass along the result to the next join(). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@257130 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/ADT/IntEqClasses.h | 8 ++++---- lib/Support/IntEqClasses.cpp | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/llvm/ADT/IntEqClasses.h b/include/llvm/ADT/IntEqClasses.h index 8e75c48e376..0baee2f11a7 100644 --- a/include/llvm/ADT/IntEqClasses.h +++ b/include/llvm/ADT/IntEqClasses.h @@ -53,10 +53,10 @@ public: NumClasses = 0; } - /// join - Join the equivalence classes of a and b. After joining classes, - /// findLeader(a) == findLeader(b). - /// This requires an uncompressed map. - void join(unsigned a, unsigned b); + /// Join the equivalence classes of a and b. After joining classes, + /// findLeader(a) == findLeader(b). This requires an uncompressed map. + /// Returns the new leader. + unsigned join(unsigned a, unsigned b); /// findLeader - Compute the leader of a's equivalence class. This is the /// smallest member of the class. diff --git a/lib/Support/IntEqClasses.cpp b/lib/Support/IntEqClasses.cpp index 11344956e4c..ff213570807 100644 --- a/lib/Support/IntEqClasses.cpp +++ b/lib/Support/IntEqClasses.cpp @@ -29,7 +29,7 @@ void IntEqClasses::grow(unsigned N) { EC.push_back(EC.size()); } -void IntEqClasses::join(unsigned a, unsigned b) { +unsigned IntEqClasses::join(unsigned a, unsigned b) { assert(NumClasses == 0 && "join() called after compress()."); unsigned eca = EC[a]; unsigned ecb = EC[b]; @@ -41,6 +41,8 @@ void IntEqClasses::join(unsigned a, unsigned b) { EC[b] = eca, b = ecb, ecb = EC[b]; else EC[a] = ecb, a = eca, eca = EC[a]; + + return eca; } unsigned IntEqClasses::findLeader(unsigned a) const { -- 2.34.1