From 941c8e0ea50bb063689e926e67f81f73c015c94a Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Wed, 8 Jun 2022 17:29:42 +0200 Subject: [Bitcode] Support expanding constant expressions into instructions This implements an autoupgrade from constant expressions to instructions, which is needed for https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. The basic approach is that constant expressions (CST_CODE_CE_* records) now initially only create a BitcodeConstant value that holds opcode, flags and operands IDs. Then, when the value actually gets used, it can be converted either into a constant expression (if that expression type is still supported) or into a sequence of instructions. As currently all expressions are still supported, -expand-constant-exprs is added for testing purposes, to force expansion. PHI nodes require special handling, because the constant expression needs to be evaluated on the incoming edge. We do this by putting it into a temporary block and then wiring it up appropriately afterwards (for non-critical edges, we could also move the instructions into the predecessor). This also removes the need for the forward referenced constants machinery, as the BitcodeConstants only hold value IDs. At the point where the value is actually materialized, no forward references are needed anymore. Differential Revision: https://reviews.llvm.org/D127729 --- llvm/lib/Bitcode/Reader/MetadataLoader.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/MetadataLoader.cpp') diff --git a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp index f5166a7..0d57ae4 100644 --- a/llvm/lib/Bitcode/Reader/MetadataLoader.cpp +++ b/llvm/lib/Bitcode/Reader/MetadataLoader.cpp @@ -1227,7 +1227,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( } MetadataList.assignValue( - LocalAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty, TyID)), + LocalAsMetadata::get(ValueList.getValueFwdRef( + Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)), NextMetadataNo); NextMetadataNo++; break; @@ -1247,8 +1248,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( if (Ty->isMetadataTy()) Elts.push_back(getMD(Record[i + 1])); else if (!Ty->isVoidTy()) { - auto *MD = ValueAsMetadata::get( - ValueList.getValueFwdRef(Record[i + 1], Ty, TyID)); + auto *MD = ValueAsMetadata::get(ValueList.getValueFwdRef( + Record[i + 1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)); assert(isa(MD) && "Expected non-function-local metadata"); Elts.push_back(MD); @@ -1269,7 +1270,8 @@ Error MetadataLoader::MetadataLoaderImpl::parseOneMetadata( return error("Invalid record"); MetadataList.assignValue( - ValueAsMetadata::get(ValueList.getValueFwdRef(Record[1], Ty, TyID)), + ValueAsMetadata::get(ValueList.getValueFwdRef( + Record[1], Ty, TyID, /*ConstExprInsertBB*/ nullptr)), NextMetadataNo); NextMetadataNo++; break; -- cgit v1.1