From 7283f48a05de46fe8721ee6c29b1b6427e7d1a33 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Tue, 28 Jun 2022 11:25:54 +0200 Subject: [IR] Remove support for insertvalue constant expression This removes the insertvalue constant expression, as part of https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179. This is very similar to the extractvalue removal from D125795. insertvalue is also not supported in bitcode, so no auto-ugprade is necessary. ConstantExpr::getInsertValue() can be replaced with IRBuilder::CreateInsertValue() or ConstantFoldInsertValueInstruction(), depending on whether a constant result is required (with the latter being fallible). The ConstantExpr::hasIndices() and ConstantExpr::getIndices() methods also go away here, because there are no longer any constant expressions with indices. Differential Revision: https://reviews.llvm.org/D128719 --- llvm/lib/IR/Constants.cpp | 44 ++------------------------------------------ 1 file changed, 2 insertions(+), 42 deletions(-) (limited to 'llvm/lib/IR/Constants.cpp') diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 0bf5e09..961e528 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -547,8 +547,6 @@ void llvm::deleteConstant(Constant *C) { delete static_cast(C); else if (isa(C)) delete static_cast(C); - else if (isa(C)) - delete static_cast(C); else if (isa(C)) delete static_cast(C); else if (isa(C)) @@ -1488,14 +1486,6 @@ bool ConstantExpr::isCompare() const { return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp; } -bool ConstantExpr::hasIndices() const { - return getOpcode() == Instruction::InsertValue; -} - -ArrayRef ConstantExpr::getIndices() const { - return cast(this)->Indices; -} - unsigned ConstantExpr::getPredicate() const { return cast(this)->predicate; } @@ -1539,9 +1529,6 @@ Constant *ConstantExpr::getWithOperands(ArrayRef Ops, Type *Ty, OnlyIfReducedTy); case Instruction::ExtractElement: return ConstantExpr::getExtractElement(Ops[0], Ops[1], OnlyIfReducedTy); - case Instruction::InsertValue: - return ConstantExpr::getInsertValue(Ops[0], Ops[1], getIndices(), - OnlyIfReducedTy); case Instruction::FNeg: return ConstantExpr::getFNeg(Ops[0]); case Instruction::ShuffleVector: @@ -2517,7 +2504,7 @@ Constant *ConstantExpr::getGetElementPtr(Type *Ty, Constant *C, if (InRangeIndex && *InRangeIndex < 63) SubClassOptionalData |= (*InRangeIndex + 1) << 1; const ConstantExprKeyType Key(Instruction::GetElementPtr, ArgVec, 0, - SubClassOptionalData, None, None, Ty); + SubClassOptionalData, None, Ty); LLVMContextImpl *pImpl = C->getContext().pImpl; return pImpl->ExprConstants.getOrCreate(ReqTy, Key); @@ -2638,36 +2625,12 @@ Constant *ConstantExpr::getShuffleVector(Constant *V1, Constant *V2, // Look up the constant in the table first to ensure uniqueness Constant *ArgVec[] = {V1, V2}; - ConstantExprKeyType Key(Instruction::ShuffleVector, ArgVec, 0, 0, None, Mask); + ConstantExprKeyType Key(Instruction::ShuffleVector, ArgVec, 0, 0, Mask); LLVMContextImpl *pImpl = ShufTy->getContext().pImpl; return pImpl->ExprConstants.getOrCreate(ShufTy, Key); } -Constant *ConstantExpr::getInsertValue(Constant *Agg, Constant *Val, - ArrayRef Idxs, - Type *OnlyIfReducedTy) { - assert(Agg->getType()->isFirstClassType() && - "Non-first-class type for constant insertvalue expression"); - - assert(ExtractValueInst::getIndexedType(Agg->getType(), - Idxs) == Val->getType() && - "insertvalue indices invalid!"); - Type *ReqTy = Val->getType(); - - if (Constant *FC = ConstantFoldInsertValueInstruction(Agg, Val, Idxs)) - return FC; - - if (OnlyIfReducedTy == ReqTy) - return nullptr; - - Constant *ArgVec[] = { Agg, Val }; - const ConstantExprKeyType Key(Instruction::InsertValue, ArgVec, 0, 0, Idxs); - - LLVMContextImpl *pImpl = Agg->getContext().pImpl; - return pImpl->ExprConstants.getOrCreate(ReqTy, Key); -} - Constant *ConstantExpr::getNeg(Constant *C, bool HasNUW, bool HasNSW) { assert(C->getType()->isIntOrIntVectorTy() && "Cannot NEG a nonintegral value!"); @@ -3517,9 +3480,6 @@ Instruction *ConstantExpr::getAsInstruction(Instruction *InsertBefore) const { return InsertElementInst::Create(Ops[0], Ops[1], Ops[2], "", InsertBefore); case Instruction::ExtractElement: return ExtractElementInst::Create(Ops[0], Ops[1], "", InsertBefore); - case Instruction::InsertValue: - return InsertValueInst::Create(Ops[0], Ops[1], getIndices(), "", - InsertBefore); case Instruction::ShuffleVector: return new ShuffleVectorInst(Ops[0], Ops[1], getShuffleMask(), "", InsertBefore); -- cgit v1.1