diff options
author | Kevin Enderby <enderby@apple.com> | 2013-06-21 20:51:39 +0000 |
---|---|---|
committer | Kevin Enderby <enderby@apple.com> | 2013-06-21 20:51:39 +0000 |
commit | a89594947ef50b77935c70e10b402337ce47e3ed (patch) | |
tree | ff69bdd82a8ffb95134f55f5d3b02fd6bcef14cd /lib/MC/MCParser | |
parent | 72d59c7999c4ed2c37334d2db189efa37d406379 (diff) | |
download | external_llvm-a89594947ef50b77935c70e10b402337ce47e3ed.zip external_llvm-a89594947ef50b77935c70e10b402337ce47e3ed.tar.gz external_llvm-a89594947ef50b77935c70e10b402337ce47e3ed.tar.bz2 |
Improve the time it takes to generating dwarf for assembly source files
that have been run through the 'C' pre-processor.
The implementation of SrcMgr.FindLineNumber() is slow but OK if
it uses its cache when called multiple times with an SMLoc that is
forward of the previous call.
In the case of generating dwarf for assembly source files that have
been run through the 'C' pre-processor we need to calculate the
logical line number based on the last parsed cpp hash file line
comment. And the current code calls SrcMgr.FindLineNumber()
twice to do this causing its cache not to work and results in very
slow compile times:
% time /Volumes/SandBox/build-llvm/Debug+Asserts/bin/llvm-mc -triple thumbv7-apple-ios -filetype=obj -o /tmp/x.o mscorlib.dll.E -g
672.542u 0.299s 11:13.15 99.9% 0+0k 0+2io 2106pf+0w
So we save the info from the last parsed cpp hash file line comment
to avoid making the second call to SrcMgr.FindLineNumber() most times
and end up with compile times like:
% time /Volumes/SandBox/build-llvm/Debug+Asserts/bin/llvm-mc -triple thumbv7-apple-ios -filetype=obj -o /tmp/x.o mscorlib.dll.E -g
3.404u 0.104s 0:03.80 92.1% 0+0k 0+3io 2105pf+0w
rdar://14156934
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184592 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/MC/MCParser')
-rw-r--r-- | lib/MC/MCParser/AsmParser.cpp | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/lib/MC/MCParser/AsmParser.cpp b/lib/MC/MCParser/AsmParser.cpp index 167e641..9a753cb 100644 --- a/lib/MC/MCParser/AsmParser.cpp +++ b/lib/MC/MCParser/AsmParser.cpp @@ -160,6 +160,13 @@ private: int64_t CppHashLineNumber; SMLoc CppHashLoc; int CppHashBuf; + /// When generating dwarf for assembly source files we need to calculate the + /// logical line number based on the last parsed cpp hash file line comment + /// and current line. Since this is slow and messes up the SourceMgr's + /// cache we save the last info we queried with SrcMgr.FindLineNumber(). + SMLoc LastQueryIDLoc; + int LastQueryBuffer; + unsigned LastQueryLine; /// AssemblerDialect. ~OU means unset value and use value provided by MAI. unsigned AssemblerDialect; @@ -1519,7 +1526,18 @@ bool AsmParser::ParseStatement(ParseStatementInfo &Info) { getStreamer().EmitDwarfFileDirective( getContext().nextGenDwarfFileNumber(), StringRef(), CppHashFilename); - unsigned CppHashLocLineNo = SrcMgr.FindLineNumber(CppHashLoc,CppHashBuf); + // Since SrcMgr.FindLineNumber() is slow and messes up the SourceMgr's + // cache with the different Loc from the call above we save the last + // info we queried here with SrcMgr.FindLineNumber(). + unsigned CppHashLocLineNo; + if (LastQueryIDLoc == CppHashLoc && LastQueryBuffer == CppHashBuf) + CppHashLocLineNo = LastQueryLine; + else { + CppHashLocLineNo = SrcMgr.FindLineNumber(CppHashLoc, CppHashBuf); + LastQueryLine = CppHashLocLineNo; + LastQueryIDLoc = CppHashLoc; + LastQueryBuffer = CppHashBuf; + } Line = CppHashLineNumber - 1 + (Line - CppHashLocLineNo); } |