DwarfCompileUnit::getOrCreateSourceID() is often called many times in sequence with the same DIFile. This is currently very expensive, because it involves creating a string from directory and file name and looking it up in a string map. This patch remembers the last DIFile and its ID and directly returns that.
This gives a geomean -1.3% compile-time improvement on O0-g: http://llvm-compile-time-tracker.com/compare.php?from=0d1308a7b77c9ed87386c22a728a6c97e2fb4887&to=0524863ab347cbb6f897844203d066869b8bee31&stat=instructions
Disclaimer: I'm not familiar with the area, but this kind of caching looks legal to me.