This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Globals used only in "main" can more easily be localized
AbandonedPublic

Authored by vaivaswatha on Dec 25 2015, 6:54 AM.

Details

Reviewers
jmolloy
hfinkel
Summary

This change relaxes the condition for a global, that is only used in "main", to be localized. This relaxation partially undoes the change done in http://reviews.llvm.org/rL253168.

This is required because the condition that was added earlier, that a store to the global needs to dominate all other references to it in the function is not necessary if the only function that accesses the global is "main". So, similar to the condition prior to the above mentioned change, this change allows "main" as an exception.

Diff Detail

Event Timeline

vaivaswatha retitled this revision from to [GlobalOpt] Globals used only in "main" can more easily be localized.
vaivaswatha updated this object.
vaivaswatha added reviewers: jmolloy, hfinkel.
vaivaswatha added a subscriber: llvm-commits.
jmolloy requested changes to this revision.Jan 6 2016, 5:34 AM
jmolloy edited edge metadata.

Hi,

No, this is not correct. The behaviour was very deliberately changed in r253168. main() is not guaranteed to be non-recursive in C, D, Python, Ruby, Rust or any other language. The only language I know that gives that guarantee is C++, and there was a corresponding change in Clang to mark "main" as norecurse in C++ mode.

Yes, I'm aware this can pessimize some C programs (notably a popular embedded benchmark). However correctness must trump performance when there is no alternative!

James

This revision now requires changes to proceed.Jan 6 2016, 5:34 AM
vaivaswatha abandoned this revision.Jan 6 2016, 5:37 AM