This is an archive of the discontinued LLVM Phabricator instance.

Fix quadratic LexicalScopes::constructScopeNest(...), NFC
ClosedPublic

Authored by jmaessen on May 15 2020, 12:50 PM.

Details

Summary

NO FUNCTIONAL CHANGE. Algorithmic complexity fix.

Our team at Facebook is currently constructing a compile backended by
LLVM. We sometimes have functions with large numbers of sibling basic
blocks (usually with an error path exit from each one). This was
triggering the qudratic behavior in this function - after visiting
each child llvm would re-scan the parent from the beginning again. We
modify the work stack to record the next index to be worked on
alongside the pointer. This avoids the need to linearly search for
the next unfinished child.

Note that I am not a committer at present, and will need the help of a committer to land this.

Test Plan:
cmake -G Ninja ...x86... -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;debuginfo-tests;lld;opt" ...
ninja check

Diff Detail

Event Timeline

jmaessen created this revision.May 15 2020, 12:50 PM
Herald added a project: Restricted Project. · View Herald TranscriptMay 15 2020, 12:50 PM
jmaessen retitled this revision from Fix quadratic LexicalScopes::constructScopeNest(...) to Fix quadratic LexicalScopes::constructScopeNest(...), NFC.May 15 2020, 1:05 PM
jmaessen edited the summary of this revision. (Show Details)May 15 2020, 1:11 PM
jmaessen added reviewers: jmorse, aprantl.
dblaikie accepted this revision.May 18 2020, 1:41 PM

Looks good - once the variable names are fixed up to match LLVM conventions. Thanks!

llvm/lib/CodeGen/LexicalScopes.cpp
241–243

Please fix/ensure the names of variables conform with the LLVM naming conventions (Upper case-starting camelcase)

This revision is now accepted and ready to land.May 18 2020, 1:41 PM
jmorse accepted this revision.May 19 2020, 8:26 AM

LGTM with one nit inline and Davids recommendations done. Thanks for finding this! I can land it when you're ready, please provide a name and email to be set as the git commit author.

llvm/lib/CodeGen/LexicalScopes.cpp
247

IMO this comment isn't necessary, because it's describing the relationship between the new code and old code, which is best put in a commit message. After this lands, the DFSIn / DFSOut values of an unvisited scope shouldn't be something a reader would consider at all.

That being said, would you be able to add a comment about the overall purpose of the function somewhere, i.e. "Visit each scope in depth-first order, with the current exploration state kept as a tree in WorkStack", or similar.

dblaikie added inline comments.May 19 2020, 11:34 AM
llvm/lib/CodeGen/LexicalScopes.cpp
247

+1

jmaessen marked 3 inline comments as done.May 21 2020, 7:11 AM
jmaessen updated this revision to Diff 265504.May 21 2020, 7:31 AM

Address review comments

Name: Jan-Willem Maessen
email: <llvm phabricator username>@fb.com

jmaessen updated this revision to Diff 267954.Jun 2 2020, 12:23 PM

Fix non-compliant var name i and remove useless comment.

Sorry for the delay, I've just pushed this up in rG3610d31e7a366, Phab should automagically close this in a moment. You might get emails from the CI buildbots as your email address is in the author field; I'll keep an eye on them in case something goes wrong and it needs reverting. LLVMs buildbots roll multiple commits together for testing, so it's a noisy process.

Many thanks for the patch!

This revision was automatically updated to reflect the committed changes.