]> granicus.if.org Git - llvm/commit
[IR] Use a binary search in DataLayout::getAlignmentInfo
authorCraig Topper <craig.topper@gmail.com>
Thu, 23 Mar 2017 06:15:56 +0000 (06:15 +0000)
committerCraig Topper <craig.topper@gmail.com>
Thu, 23 Mar 2017 06:15:56 +0000 (06:15 +0000)
commitba5e42097673772536f380ab4bf7c3e6bf47c8b2
treea3edf3f7edc706607a1bb0031fa4543a7d413c5f
parenta3bd80e90a19de9697c378e6fa3946e12ac3e122
[IR] Use a binary search in DataLayout::getAlignmentInfo

Summary:
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.

Reviewers: sanjoy, davide, majnemer, resistor, arsenm, mehdi_amini

Reviewed By: arsenm

Subscribers: arsenm, llvm-commits

Differential Revision: https://reviews.llvm.org/D31232

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298579 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/DataLayout.h
lib/IR/DataLayout.cpp