This is an archive of the discontinued LLVM Phabricator instance.

[CGProfile] allows undef in metadata node storing function pointers
AbandonedPublic

Authored by ychen on Aug 24 2021, 10:09 AM.

Details

Summary

Commits like e5d958c may RAUW with undef value. It seems better to allow
this pattern in IR verifier rather than fixing the RAUWs for e5d958c and
future commits.

Diff Detail

Event Timeline

ychen created this revision.Aug 24 2021, 10:09 AM
ychen requested review of this revision.Aug 24 2021, 10:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 24 2021, 10:09 AM

Since it looks like there are a fair number of places in LLVM that replace metadata uses with undef, is it the case that the verifier handles these more gracefully elsewhere?

It used to be that when GlobalValue-derived Constants were removed, then metadata would point at null instead. Not sure if that changed at some point, or if this is a unique code path, but it's not clear whether having two possible "no value" values (undef vs. null) is a good idea.

Can you explain why https://reviews.llvm.org/rGe5d958c45629ccd2f5b5f7432756be1d0fcf052c used undef instead of null? Should it use null instead?

It used to be that when GlobalValue-derived Constants were removed, then metadata would point at null instead. Not sure if that changed at some point, or if this is a unique code path, but it's not clear whether having two possible "no value" values (undef vs. null) is a good idea.

Can you explain why https://reviews.llvm.org/rGe5d958c45629ccd2f5b5f7432756be1d0fcf052c used undef instead of null? Should it use null instead?

Ah, that was the commit that changed it. It used to hit this logic:

Value::~Value() {
  // Notify all ValueHandles (if present) that this value is going away.
  if (HasValueHandle)
    ValueHandleBase::ValueIsDeleted(this);
  if (isUsedByMetadata())
    ValueAsMetadata::handleDeletion(this);

  // Remove associated metadata from context.
  if (HasMetadata)
    clearMetadata();

Maybe that commit should be reverted.

It used to be that when GlobalValue-derived Constants were removed, then metadata would point at null instead. Not sure if that changed at some point, or if this is a unique code path, but it's not clear whether having two possible "no value" values (undef vs. null) is a good idea.

Can you explain why https://reviews.llvm.org/rGe5d958c45629ccd2f5b5f7432756be1d0fcf052c used undef instead of null? Should it use null instead?

Ah, that was the commit that changed it. It used to hit this logic:

Value::~Value() {
  // Notify all ValueHandles (if present) that this value is going away.
  if (HasValueHandle)
    ValueHandleBase::ValueIsDeleted(this);
  if (isUsedByMetadata())
    ValueAsMetadata::handleDeletion(this);

  // Remove associated metadata from context.
  if (HasMetadata)
    clearMetadata();

Maybe that commit should be reverted.

Thank you! It looks like so indeed. Basically ReplaceableMetadataImpl::replaceAllUsesWith removed the null Value from the metadata nodes, right?

ychen abandoned this revision.Oct 12 2021, 7:33 PM