[llvm] r184592 - Improve the time it takes to generating dwarf for assembly source files

Eric Christopher echristo at gmail.com
Fri Jun 21 14:09:32 PDT 2013


On Fri, Jun 21, 2013 at 2:03 PM, Kevin Enderby <enderby at apple.com> wrote:
>
> On Jun 21, 2013, at 1:59 PM, Eric Christopher <echristo at gmail.com> wrote:
>
>>> 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
>>>
>>
>> *blink* 11 minutes to 3 seconds? Nice work :)
>
> It is a big machine generated assembly file:
>
> % wc mscorlib.dll.E
>   221672  403313 7088742 mscorlib.dll.E
>

Wow. And still awesome :)

-eric

>>
>> -eric
>>
>>> rdar://14156934
>>>
>>> Modified:
>>>    llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>>
>>> Modified: llvm/trunk/lib/MC/MCParser/AsmParser.cpp
>>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCParser/AsmParser.cpp?rev=184592&r1=184591&r2=184592&view=diff
>>> ==============================================================================
>>> --- llvm/trunk/lib/MC/MCParser/AsmParser.cpp (original)
>>> +++ llvm/trunk/lib/MC/MCParser/AsmParser.cpp Fri Jun 21 15:51:39 2013
>>> @@ -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(ParseStat
>>>         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);
>>>     }
>>>
>>>
>>>
>>> _______________________________________________
>>> llvm-commits mailing list
>>> llvm-commits at cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>



More information about the llvm-commits mailing list