summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorStepan Dyatkovskiy <stpworld@narod.ru>2014-05-16 08:55:34 +0000
committerStepan Dyatkovskiy <stpworld@narod.ru>2014-05-16 08:55:34 +0000
commit5c2cc2506d8ab70a1a9688f0de7793933ece6f48 (patch)
treed1bf602b2725f5a59b0fe81d84e6d0133586b4f4 /llvm/lib
parentb397fea9ab68a2f00ae6050fdcd055e6513a2b89 (diff)
downloadbcm5719-llvm-5c2cc2506d8ab70a1a9688f0de7793933ece6f48.tar.gz
bcm5719-llvm-5c2cc2506d8ab70a1a9688f0de7793933ece6f48.zip
MergeFunctions Pass, introduced total ordering among function attributes.
This patch belongs to patch series that improves MergeFunctions performance time from O(N*N) to O(N*log(N)). llvm-svn: 208953
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Transforms/IPO/MergeFunctions.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/IPO/MergeFunctions.cpp b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
index 3a287e0f218..55d199ee7ba 100644
--- a/llvm/lib/Transforms/IPO/MergeFunctions.cpp
+++ b/llvm/lib/Transforms/IPO/MergeFunctions.cpp
@@ -367,6 +367,8 @@ private:
int cmpAPInt(const APInt &L, const APInt &R) const;
int cmpAPFloat(const APFloat &L, const APFloat &R) const;
+ int cmpStrings(StringRef L, StringRef R) const;
+ int cmpAttrs(const AttributeSet L, const AttributeSet R) const;
// The two functions undergoing comparison.
const Function *F1, *F2;
@@ -432,6 +434,40 @@ int FunctionComparator::cmpAPFloat(const APFloat &L, const APFloat &R) const {
return cmpAPInt(L.bitcastToAPInt(), R.bitcastToAPInt());
}
+int FunctionComparator::cmpStrings(StringRef L, StringRef R) const {
+ // Prevent heavy comparison, compare sizes first.
+ if (int Res = cmpNumbers(L.size(), R.size()))
+ return Res;
+
+ // Compare strings lexicographically only when it is necessary: only when
+ // strings are equal in size.
+ return L.compare(R);
+}
+
+int FunctionComparator::cmpAttrs(const AttributeSet L,
+ const AttributeSet R) const {
+ if (int Res = cmpNumbers(L.getNumSlots(), R.getNumSlots()))
+ return Res;
+
+ for (unsigned i = 0, e = L.getNumSlots(); i != e; ++i) {
+ AttributeSet::iterator LI = L.begin(i), LE = L.end(i), RI = R.begin(i),
+ RE = R.end(i);
+ for (; LI != LE && RI != RE; ++LI, ++RI) {
+ Attribute LA = *LI;
+ Attribute RA = *RI;
+ if (LA < RA)
+ return -1;
+ if (RA < LA)
+ return 1;
+ }
+ if (LI != LE)
+ return 1;
+ if (RI != RE)
+ return -1;
+ }
+ return 0;
+}
+
/// Constants comparison:
/// 1. Check whether type of L constant could be losslessly bitcasted to R
/// type.
OpenPOWER on IntegriCloud