[SourceMgr/MLIR diagnostics] Introduce a new method to speed things up
authorChris Lattner <clattner@nondot.org>
Sat, 25 Apr 2020 19:02:12 +0000 (12:02 -0700)
committerChris Lattner <clattner@nondot.org>
Sat, 25 Apr 2020 21:06:44 +0000 (14:06 -0700)
commit969e7edd88ceb4791eb1cac22828290f0ae30b3d
tree07cabe5b88b0dac88b9867a10b9987760382dd6c
parenta0a55b7903d8f4c66ba88561ed32e01652334536
[SourceMgr/MLIR diagnostics] Introduce a new method to speed things up

Summary:
This introduces a new SourceMgr::FindLocForLineAndColumn method that
uses the OffsetCache in SourceMgr::SrcBuffer to do do a constant time
lookup for the line number (once the cache is populated).

Use this method in MLIR's SourceMgrDiagnosticHandler::convertLocToSMLoc,
replacing the O(n) scanning logic.  This resolves a long standing TODO
in MLIR, and makes one of my usecases go dramatically faster (which is
currently producing many diagnostics in a 40MB SourceBuffer).

NFC, this is just a performance speedup and cleanup.

Reviewers: rriddle!, ftynse!

Subscribers: hiraditya, mehdi_amini, rriddle, jpienaar, shauheen, antiagainst, nicolasvasilache, arpith-jacob, mgester, lucyrfox, liufengdb, Joonsoo, grosul1, frgossen, Kayjukh, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D78868
llvm/include/llvm/Support/SourceMgr.h
llvm/lib/Support/SourceMgr.cpp
mlir/lib/IR/Diagnostics.cpp