diff options
author | Haicheng Wu <haicheng@codeaurora.org> | 2018-05-19 18:00:02 +0000 |
---|---|---|
committer | Haicheng Wu <haicheng@codeaurora.org> | 2018-05-19 18:00:02 +0000 |
commit | 69ba0613f2b9ae20fc00fc547fd125d52629d5a6 (patch) | |
tree | a12a88faf0947c93cc6ce5f2d3b6c9ee2ff367a4 /llvm/lib/CodeGen/GlobalMerge.cpp | |
parent | 9968e0dd4975d3939e7810ac9e6c52cea7f1aeb1 (diff) | |
download | bcm5719-llvm-69ba0613f2b9ae20fc00fc547fd125d52629d5a6.tar.gz bcm5719-llvm-69ba0613f2b9ae20fc00fc547fd125d52629d5a6.zip |
[GlobalMerge] Exit early if only one global is to be merged
To save some compilation time and prevent some unnecessary changes.
Differential Revision: https://reviews.llvm.org/D46640
llvm-svn: 332813
Diffstat (limited to 'llvm/lib/CodeGen/GlobalMerge.cpp')
-rw-r--r-- | llvm/lib/CodeGen/GlobalMerge.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/GlobalMerge.cpp b/llvm/lib/CodeGen/GlobalMerge.cpp index cda5861f676..fbf94d2bb7f 100644 --- a/llvm/lib/CodeGen/GlobalMerge.cpp +++ b/llvm/lib/CodeGen/GlobalMerge.cpp @@ -445,6 +445,7 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, LLVM_DEBUG(dbgs() << " Trying to merge set, starts with #" << GlobalSet.find_first() << "\n"); + bool Changed = false; ssize_t i = GlobalSet.find_first(); while (i != -1) { ssize_t j = 0; @@ -469,6 +470,12 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, } } + // Exit early if there is only one global to merge. + if (Tys.size() < 2) { + i = j; + continue; + } + // If merged variables doesn't have external linkage, we needn't to expose // the symbol after merging. GlobalValue::LinkageTypes Linkage = HasExternal @@ -526,10 +533,11 @@ bool GlobalMerge::doMerge(const SmallVectorImpl<GlobalVariable *> &Globals, NumMerged++; } + Changed = true; i = j; } - return true; + return Changed; } void GlobalMerge::collectUsedGlobalVariables(Module &M) { |