This is an archive of the discontinued LLVM Phabricator instance.

Allow type-mismatching RAUW of values in metadata, and add C API.
AbandonedPublic

Authored by maleadt on May 11 2022, 7:30 AM.

Details

Summary

When replacing a value that's referred to by module metadata, one needs to use RAUW to update that metadata. RAUW however doesn't work when the type of the value changes, e.g., when replacing a function with one that takes an additional argument. This kind of IR happens with e.g. the nvvm.annotations metadata, which contains a reference to a LLVM::Function value. It seems to make sense to relax the type equality assertion when only replacing values in metadata (see also: https://discourse.llvm.org/t/replacing-module-metadata-uses-of-function/62431). This change does exactly that, while additionally exposing that functionality to C.

Diff Detail

Event Timeline

maleadt created this revision.May 11 2022, 7:30 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: hiraditya. · View Herald Transcript
maleadt requested review of this revision.May 11 2022, 7:30 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 11 2022, 7:30 AM
maleadt added a subscriber: Restricted Project.May 11 2022, 7:42 AM
sebastian-ne accepted this revision.Jun 20 2022, 1:37 AM
sebastian-ne added a subscriber: nikic.

Since there have been no other reactions and I think this is a reasonable patch, I’ll accept it.
Please wait a day before submitting it in case others have comments.

This revision is now accepted and ready to land.Jun 20 2022, 1:37 AM
nikic requested changes to this revision.Jun 20 2022, 1:54 AM

I don't think this change makes sense on a couple of levels:

  • I don't believe that ValueAsMetadata::handleRAUW() is intended as a public API at all.
  • The original problem seems like a bug in GlobalDCE -- did anyone investigate why it happens?
  • With opaque pointers the replacement doesn't use a bitcast anyway, so the issue is "fixed" as a side-effect. As this API will only go into LLVM 15, it would not be useful.
This revision now requires changes to proceed.Jun 20 2022, 1:54 AM
maleadt abandoned this revision.Jul 15 2022, 2:58 AM
  • With opaque pointers the replacement doesn't use a bitcast anyway, so the issue is "fixed" as a side-effect. As this API will only go into LLVM 15, it would not be useful.

Ah yes, plain RAUW without bitcast just works fine on LLVM 15 with opaque pointers.