Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions clang/lib/Basic/SourceManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -907,19 +907,23 @@ getExpansionLocSlowCase(SourceLocation Loc) const {

SourceLocation SourceManager::getSpellingLocSlowCase(SourceLocation Loc) const {
do {
FileIDAndOffset LocInfo = getDecomposedLoc(Loc);
Loc = getSLocEntry(LocInfo.first).getExpansion().getSpellingLoc();
Loc = Loc.getLocWithOffset(LocInfo.second);
const SLocEntry &Entry = getSLocEntry(getFileID(Loc));
Loc = Entry.getExpansion().getSpellingLoc().getLocWithOffset(
Loc.getOffset() - Entry.getOffset());
} while (!Loc.isFileID());
return Loc;
}

SourceLocation SourceManager::getFileLocSlowCase(SourceLocation Loc) const {
do {
if (isMacroArgExpansion(Loc))
Loc = getImmediateSpellingLoc(Loc);
else
Loc = getImmediateExpansionRange(Loc).getBegin();
const SLocEntry &Entry = getSLocEntry(getFileID(Loc));
const ExpansionInfo &ExpInfo = Entry.getExpansion();
if (ExpInfo.isMacroArgExpansion()) {
Loc = ExpInfo.getSpellingLoc().getLocWithOffset(Loc.getOffset() -
Entry.getOffset());
} else {
Loc = ExpInfo.getExpansionLocStart();
}
Comment on lines +919 to +926
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look correct, but I guess I'm surprised there's any measurable impact on performance; are there performance measurement numbers for these changes? (We have https://llvm-compile-time-tracker.com/ to help measure that sort of thing, FWIW.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably you are correct.
But it looks nicer that way. The performance depends how macro heavy is the source code. I bet you can save a few seconds on the large codebases.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found the old code to be easier to understand what was going on, so I worry about premature optimization without some idea of measurements. CC @erichkeane @Sirraide @Endilll for some other opinions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run the performance test on this RP somehow? Although I doubt that there will be any significant change.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, both of these cases are a little tougher to read for me. I'd like to see the perf measurements. I think @Endilll knows how to start them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that PR is more relevant in the context of #163982

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we run the performance test on this RP somehow? Although I doubt that there will be any significant change.

Unfortunately, not trivially; you can contact Nikita to have your fork added (https://llvm-compile-time-tracker.com/about.php) but that may take a while given the upcoming dev conference and folks being busy with that. I think it'd be fine if there were some local tests on whatever project you have that's super macro heavy, something as simple as "average of 1234ms before this patch and 567ms after the patch on my machine" would perhaps help.

Basically, if there's a measurable performance improvement, we can hold our nose on slightly reduced readability, but if there's no measurable performance improvement, there's less of a case for taking the patch..

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that helps, here you can follow what LLVM compiler time tracker does.

Copy link
Contributor Author

@SergejSalnikov SergejSalnikov Oct 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tested the following 3 PRs together, but I don't know how to interpret the results.
#163982
#164269
#163982

full report

} while (!Loc.isFileID());
return Loc;
}
Expand Down
Loading