Skip to content

Perf/lexer faster slow get char and size #70543

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

serge-sans-paille
Copy link
Collaborator

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Oct 28, 2023
@serge-sans-paille serge-sans-paille force-pushed the perf/lexer-faster-slow-get-char-and-size branch from 867ef93 to c9d34da Compare October 28, 2023 08:19
@cor3ntin
Copy link
Contributor

Do you have benchmarks?
I wonder if we should use a small struct instead of pair, it would be slightly easier to maintain I think.
Looks good otherwise.

@tbaederr
Copy link
Contributor

Do you have benchmarks? I wonder if we should use a small struct instead of pair, it would be slightly easier to maintain I think. Looks good otherwise.

See the commit: c9d34da

Instead of passing the Size by reference, assuming it is initialized,
return it alongside the expected char result as a POD.

This makes the interface less error prone: previous interface expected
the Size reference to be initialized, and it was often forgotten,
leading to uninitialized variable usage. This patch fixes the issue.

This also generates faster code, as the returned POD (a char and an
unsigned) fits in 64 bits. The speedup according to compile time tracker
reach -O.7%, with a good number of -0.4%. Details are available on

        https://llvm-compile-time-tracker.com/compare.php?from=3fe63f81fcb999681daa11b2890c82fda3aaeef5&to=fc76a9202f737472ecad4d6e0b0bf87a013866f3&stat=instructions:u

And icing on the cake, on my setup it also shaves 2kB out of
libclang-cpp :-)
@serge-sans-paille serge-sans-paille force-pushed the perf/lexer-faster-slow-get-char-and-size branch from c9d34da to 7bbcabd Compare October 28, 2023 20:04
@serge-sans-paille
Copy link
Collaborator Author

serge-sans-paille commented Oct 28, 2023

@cor3ntin yep, looks better with a small struct, update pushed

if (C1 != '0')
return false;
char C2 = Lexer::getCharAndSizeNoWarn(Start + Size, Size, LangOpts);

auto CharAndSize2 =
Copy link
Contributor

Choose a reason for hiding this comment

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

You can reuse CharAndSize here

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, but I find it less confusing like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I won't insist!

@github-actions
Copy link

github-actions bot commented Oct 29, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@serge-sans-paille serge-sans-paille force-pushed the perf/lexer-faster-slow-get-char-and-size branch from a20790e to 3bf6120 Compare October 29, 2023 07:06
Copy link
Contributor

@cor3ntin cor3ntin left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@serge-sans-paille serge-sans-paille merged commit d8f5a18 into llvm:main Oct 29, 2023
@rorth
Copy link
Collaborator

rorth commented Oct 29, 2023

This patch broke builders like Solaris/amd64 that include clang-tools-extra.

@nico
Copy link
Contributor

nico commented Oct 29, 2023

This breaks building: http://45.33.8.238/linux/121901/step_4.txt

Please take a look and revert for now if it takes a while to fix.

nico added a commit that referenced this pull request Oct 30, 2023
@nico
Copy link
Contributor

nico commented Oct 30, 2023

Reverted in 1c876ff for now.

searlmc1 pushed a commit to ROCm/llvm-project that referenced this pull request Oct 30, 2023
merges to d346c82 [OpenMP] Associate the KernelEnvironment with the GenericKernelTy (llvm#70383)
 and reverts to buy time to inegrate it in properly.

Also brings in 8f5a18b6e58 Perf/lexer faster slow get char and size (llvm#70543)
  which is reverted upstream 9 commits later.

Change-Id: Idb81b74c26b78bff856d7e4119036918629e47f9
@serge-sans-paille
Copy link
Collaborator Author

recommited as 8116b6d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants