[PATCH] D31232: [IR] Use a binary search in DataLayout::getAlignmentInfo

Craig Topper via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 21 20:21:17 PDT 2017


craig.topper created this revision.

We currently do a linear scan through all of the Alignments array entries anytime getAlignmentInfo is called. I noticed while profiling compile time on a -O2 opt run that this function can be called quite frequently and was showing about as about 1% of the time in callgrind.

This patch puts the Alignments array into a sorted order by type and then by bitwidth. We can then do a binary search. And use the sorted nature to handle the special cases for INTEGER_ALIGN. Some of this is modeled after the sorting/searching we do for pointers already.

This reduced the time spent in this routine by about 2/3 in the one compilation I was looking at.

We could maybe improve this more by using a DenseMap to cache the results, but just sorting was easy and didn't require extra data structure. And I think it made the integer handling simpler.


https://reviews.llvm.org/D31232

Files:
  include/llvm/IR/DataLayout.h
  lib/IR/DataLayout.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31232.92590.patch
Type: text/x-patch
Size: 6819 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170322/b4fa6b5a/attachment.bin>


More information about the llvm-commits mailing list