llvm.org GIT mirror llvm / 99d0015
Introduce a new array_pod_sort function and switch LSR to use it instead of std::sort. This shrinks the release-asserts LSR.o file by 1100 bytes of code on my system. We should start using array_pod_sort where possible. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60335 91177308-0d34-0410-b5e6-96231b3b80d8 Chris Lattner 11 years ago
2 changed file(s) with 39 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
203203 }
204204
205205 //===----------------------------------------------------------------------===//
206 // Extra additions to arrays
206 // Extra additions for arrays
207207 //===----------------------------------------------------------------------===//
208208
209209 /// Find where an array ends (for ending iterators)
220220 return N;
221221 }
222222
223 /// array_pod_sort_comparator - This is helper function for array_pod_sort,
224 /// which does a memcmp of a specific size.
225 template
226 static inline int array_pod_sort_comparator(const void *P1, const void *P2) {
227 if (Size == sizeof(char))
228 return *(const char*)P1 - *(const char*)P2;
229 if (Size == sizeof(int))
230 return *(const int*)P1 - *(const int*)P2;
231 if (Size == sizeof(long long))
232 return *(const long long*)P1 - *(const long long*)P2;
233 if (Size == sizeof(intptr_t))
234 return *(intptr_t*)P1 - *(intptr_t*)P2;
235 return memcmp(P1, P2, Size);
236 }
237
238 /// array_pod_sort - This sorts an array with the specified start and end
239 /// extent. This is just like std::sort, except that it calls qsort instead of
240 /// using an inlined template. qsort is slightly slower than std::sort, but
241 /// most sorts are not performance critical in LLVM and std::sort has to be
242 /// template instantiated for each type, leading to significant measured code
243 /// bloat. This function should generally be used instead of std::sort where
244 /// possible.
245 ///
246 /// This function assumes that you have simple POD-like types that can be
247 /// compared with memcmp and can be moved with memcpy. If this isn't true, you
248 /// should use std::sort.
249 ///
250 /// NOTE: If qsort_r were portable, we could allow a custom comparator and
251 /// default to std::less.
252 template
253 static inline void array_pod_sort(IteratorTy Start, IteratorTy End) {
254 // Don't dereference start iterator of empty sequence.
255 if (Start == End) return;
256 qsort(Start, End-Start, sizeof(*Start),
257 array_pod_sort_comparator);
258 }
259
223260 } // End llvm namespace
224261
225262 #endif
242242 // Sort the deadinsts list so that we can trivially eliminate duplicates as we
243243 // go. The code below never adds a non-dead instruction to the worklist, but
244244 // callers may not be so careful.
245 std::sort(DeadInsts.begin(), DeadInsts.end());
245 array_pod_sort(DeadInsts.begin(), DeadInsts.end());
246246
247247 // Drop duplicate instructions and those with uses.
248248 for (unsigned i = 0, e = DeadInsts.size()-1; i < e; ++i) {