This is an archive of the discontinued LLVM Phabricator instance.

[IR] Allow available_externally GlobalAlias
ClosedPublic

Authored by MaskRay on Nov 4 2022, 9:46 AM.

Details

Summary

GlobalVariable and Function can be available_externally. GlobalAlias is used
similarly. Allowing available_externally is a natural extension and helps
ThinLTO discard GlobalAlias in a non-prevailing COMDAT (see D135427).

For now, available_externally GlobalAlias must point to an
available_externally GlobalValue (not ConstantExpr).

Diff Detail

Event Timeline

MaskRay created this revision.Nov 4 2022, 9:46 AM
MaskRay requested review of this revision.Nov 4 2022, 9:46 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 4 2022, 9:46 AM
nikic added inline comments.Nov 4 2022, 9:59 AM
llvm/lib/IR/Verifier.cpp
820

Why is an available_externally alias allowed to point to a declaration?

849

This looks unnecessary, as you adjusted isValidLinkage()?

MaskRay updated this revision to Diff 473281.Nov 4 2022, 10:08 AM
MaskRay marked an inline comment as done.

address comments

llvm/lib/IR/Verifier.cpp
820

An available_externally alias may refer to another available_externally GlobalValue. This is the case when an alias is in a non-prevailing COMDAT after my pending ThinLTO change.

tejohnson added inline comments.Nov 4 2022, 3:57 PM
llvm/lib/IR/Verifier.cpp
820

If the aliasee is available_externally you should check that the alias is as well.

MaskRay updated this revision to Diff 473383.Nov 4 2022, 6:05 PM
MaskRay marked 2 inline comments as done.

enhance verifier

tejohnson accepted this revision.Nov 4 2022, 7:09 PM

lgtm but wait to see if @nikic has any follow on questions

This revision is now accepted and ready to land.Nov 4 2022, 7:09 PM
nikic added a comment.Nov 5 2022, 1:31 AM

For the record, the current restriction was introduced in https://github.com/llvm/llvm-project/commit/8934577171b967cc23186c2ffa0a0c4b54a8d992. The commit message mentions that available_externally aliases, if introduced, should always have a declaration-for-linker aliasee. Just want to confirm that it is fine to not have that restriction, as implemented here.

llvm/lib/IR/Verifier.cpp
824

Shouldn't this be isDeclarationForLinker?

nikic added inline comments.Nov 5 2022, 1:34 AM
llvm/docs/LangRef.rst
911

This needs to be updated.

MaskRay updated this revision to Diff 473445.Nov 5 2022, 11:04 AM
MaskRay marked an inline comment as done.
MaskRay edited the summary of this revision. (Show Details)

make available_externally alias stricter

MaskRay marked an inline comment as done.Nov 5 2022, 11:04 AM
MaskRay added inline comments.
llvm/lib/IR/Verifier.cpp
824

hasAvailableExternallyLinkage has precluded one condition of isDeclarationForLinker so isDeclaration suffices.

MaskRay updated this revision to Diff 473446.Nov 5 2022, 11:05 AM

fix typo in LangRef: alias=>aliasee

nikic added a comment.Nov 6 2022, 9:26 AM

Looks reasonable to me.

llvm/docs/LangRef.rst
913

not -> no?

llvm/lib/IR/Verifier.cpp
822

I think it would be slightly more elegant to put this into an else branch rather than check for available_externally again here.

MaskRay updated this revision to Diff 473504.Nov 6 2022, 10:34 AM
MaskRay marked 2 inline comments as done.

address comments

This revision was automatically updated to reflect the committed changes.