Use trigrams to speed up SpecialCaseList.
authorIvan Krasin <krasin@chromium.org>
Thu, 1 Dec 2016 02:54:54 +0000 (02:54 +0000)
committerIvan Krasin <krasin@chromium.org>
Thu, 1 Dec 2016 02:54:54 +0000 (02:54 +0000)
commit3dade419bff12f1c67fd5d4256a5e7f2338f1160
treefeb518f639418621ba7432b3f619abdacff605cb
parentfb8c2a4a6b9fb72430903677fc1ffc46e27160f4
Use trigrams to speed up SpecialCaseList.

Summary:
it's often the case when the rules in the SpecialCaseList
are of the form hel.o*bar. That gives us a chance to build
trigram index to quickly discard 99% of inputs without
running a full regex. A similar idea was used in Google Code Search
as described in the blog post:
https://swtch.com/~rsc/regexp/regexp4.html

The check is defeated, if there's at least one regex
more complicated than that. In this case, all inputs
will go through the regex. That said, the real-world
rules are often simple or can be simplied. That considerably
speeds up compiling Chromium with CFI and UBSan.

As measured on Chromium's content_message_generator.cc:

before, CFI: 44 s
after, CFI: 23 s
after, CFI, no blacklist: 23 s (~1% slower, but 3 runs were unable to show the difference)
after, regular compilation to bitcode: 23 s

Reviewers: pcc

Subscribers: mgorny, llvm-commits

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

llvm-svn: 288303
llvm/include/llvm/Support/TrigramIndex.h [new file with mode: 0644]
llvm/lib/Support/CMakeLists.txt
llvm/lib/Support/SpecialCaseList.cpp
llvm/lib/Support/TrigramIndex.cpp [new file with mode: 0644]
llvm/unittests/Support/CMakeLists.txt
llvm/unittests/Support/SpecialCaseListTest.cpp
llvm/unittests/Support/TrigramIndexTest.cpp [new file with mode: 0644]