This is an archive of the discontinued LLVM Phabricator instance.

[GlobalOpt] Collect initializer when building GlobalPart.
ClosedPublic

Authored by fhahn on Mar 7 2023, 5:11 AM.

Details

Summary

Update the code to collect the initializer when collecting the types for
a global, as suggested by @nikic in D144476.

This replaces code which bailed out if *any* part doesn't have an
initializer with a continue to just skip parts which don't have an
initializer.

Depends on D145489.

Diff Detail

Event Timeline

fhahn created this revision.Mar 7 2023, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2023, 5:11 AM
fhahn requested review of this revision.Mar 7 2023, 5:11 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 7 2023, 5:11 AM
nikic added inline comments.Mar 7 2023, 6:13 AM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
388–390

or so to only compute this once?

fhahn updated this revision to Diff 503303.Mar 8 2023, 3:41 AM

Only call ConstantFoldLoadFromConst when new entry has been inserted.

fhahn marked an inline comment as done.Mar 8 2023, 3:42 AM
fhahn added inline comments.
llvm/lib/Transforms/IPO/GlobalOpt.cpp
388–390

Yeah that's better, updated!

nikic added inline comments.Mar 8 2023, 8:45 AM
llvm/lib/Transforms/IPO/GlobalOpt.cpp
393

Can drop braces

580

Hm, if this happens, won't we leave behind references to a removed global? I think we need to make sure all initializers are known upfront, e.g. in the above offset checking loop.

fhahn updated this revision to Diff 504147.Mar 10 2023, 7:37 AM
fhahn marked an inline comment as done.

Bail out if global initializer cannot be evaluated (test added in a011823bff4d5399).

nikic accepted this revision.Mar 17 2023, 6:29 AM

LGTM

This revision is now accepted and ready to land.Mar 17 2023, 6:29 AM
This revision was automatically updated to reflect the committed changes.