This is an archive of the discontinued LLVM Phabricator instance.

[IR] Remove support for extractvalue constant expression
ClosedPublic

Authored by nikic on May 17 2022, 7:55 AM.

Details

Summary

This removes the extractvalue constant expression, as part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. extractvalue is already not supported in bitcode, so we do not need to worry about auto-upgrade.

Uses of ConstantExpr::getExtractValue() should be replaced with IRBuilder::CreateExtractValue() (if the fact that the result is constant is not important) or ConstantFoldExtractValueInstruction() (if it is). Though for this particular case, it is also possible and probably a bit more elegant to use getAggregateElement() instead.

The C API function LLVMConstExtractValue() is removed, as the underlying constant expression no longer exists. Instead, LLVMBuildExtractValue() should be used (which will constant fold or create an instruction). Depending on the use-case, LLVMGetAggregateElement() may also be used instead.

Depends on D128213.

Diff Detail

Event Timeline

nikic created this revision.May 17 2022, 7:55 AM
nikic requested review of this revision.May 17 2022, 7:55 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 17 2022, 7:55 AM
nikic updated this revision to Diff 437080.EditedJun 15 2022, 1:45 AM

Remove more leftovers.

nikic edited the summary of this revision. (Show Details)Jun 15 2022, 1:45 AM
nikic updated this revision to Diff 438598.Jun 21 2022, 2:02 AM
nikic edited the summary of this revision. (Show Details)

Remove hack.

I'm in favor of doing this, and the change looks mostly straightforward. However, I wonder if, since it is a breaking change in the C ABI, we shouldn't have at least one release cycle where LLVMConstExtractValue (and other functions that are planned to be removed) are marked as deprecated.

nikic updated this revision to Diff 438699.Jun 21 2022, 7:32 AM

Add release notes.

nikic added a comment.Jun 21 2022, 8:01 AM

I'm in favor of doing this, and the change looks mostly straightforward. However, I wonder if, since it is a breaking change in the C ABI, we shouldn't have at least one release cycle where LLVMConstExtractValue (and other functions that are planned to be removed) are marked as deprecated.

I don't think that's necessary. Per https://llvm.org/docs/DeveloperPolicy.html#c-api-changes C API stability is "best effort", presumably exactly for cases like this (the underlying functionality that is being exported simply no longer exists). I don't think unavoidable changes to the C API should hold back changes, especially as the impact on the C and C++ APIs is the same here. Of course, we should have a release note for the change, which I have now added.

Something we should consider though is whether we need to export any additional APIs -- and I think, in this case we probably should. Without LLVMConstExtractValue, there is no longer a good way to get an element from a constant aggregate. Weirdly, the C API does export the ConstantDataSequential-specific getElementAsConstant() method, but not the general getAggregateElement() method. We probably should export that one.

Less relevant for extractvalue, but possibly for other constant expressions, do we need to export any of the ConstantFoldXYZ APIs? Those would be the fallible replacements for LLVMConstXYZ.

I'm in favor of doing this, and the change looks mostly straightforward. However, I wonder if, since it is a breaking change in the C ABI, we shouldn't have at least one release cycle where LLVMConstExtractValue (and other functions that are planned to be removed) are marked as deprecated.

I don't think that's necessary. Per https://llvm.org/docs/DeveloperPolicy.html#c-api-changes C API stability is "best effort", presumably exactly for cases like this (the underlying functionality that is being exported simply no longer exists). I don't think unavoidable changes to the C API should hold back changes, especially as the impact on the C and C++ APIs is the same here. Of course, we should have a release note for the change, which I have now added.

Yeah, that's fair.

Less relevant for extractvalue, but possibly for other constant expressions, do we need to export any of the ConstantFoldXYZ APIs? Those would be the fallible replacements for LLVMConstXYZ.

I doubt it. The C API already has LLVMBuildXYZ functions which will do constant folding.

nikic updated this revision to Diff 439367.Jun 23 2022, 6:08 AM
nikic edited the summary of this revision. (Show Details)

Rebase over committed patches.

reames accepted this revision.Jun 27 2022, 11:37 AM
reames added a subscriber: reames.

LGTM

This revision is now accepted and ready to land.Jun 27 2022, 11:37 AM
This revision was landed with ongoing or failed builds.Jun 28 2022, 1:40 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2022, 1:40 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
llvm/test/Assembler/unsupported-constexprs.ll