diff options
author | Nikita Popov <npopov@redhat.com> | 2023-11-07 09:34:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-07 09:34:16 +0100 |
commit | 17764d2c87bad3b9654b7310c9936c0d15e9bf96 (patch) | |
tree | 7a9d3c480c4601c656440b83033759a115ddf7f6 /llvm/lib | |
parent | a5c1ecada27a84161e8d947b4f4564c785aa3807 (diff) | |
download | llvm-17764d2c87bad3b9654b7310c9936c0d15e9bf96.zip llvm-17764d2c87bad3b9654b7310c9936c0d15e9bf96.tar.gz llvm-17764d2c87bad3b9654b7310c9936c0d15e9bf96.tar.bz2 |
[IR] Remove FP cast constant expressions (#71408)
Remove support for the fptrunc, fpext, fptoui, fptosi, uitofp and sitofp
constant expressions. All places creating them have been removed
beforehand, so this just removes the APIs and uses of these constant
expressions in tests.
With this, the only remaining FP operation that still has constant
expression support is fcmp.
This is part of
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/AsmParser/LLParser.cpp | 18 | ||||
-rw-r--r-- | llvm/lib/IR/Constants.cpp | 96 | ||||
-rw-r--r-- | llvm/lib/IR/Core.cpp | 35 |
3 files changed, 14 insertions, 135 deletions
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp index d3abd16..95fe5ed 100644 --- a/llvm/lib/AsmParser/LLParser.cpp +++ b/llvm/lib/AsmParser/LLParser.cpp @@ -3805,14 +3805,8 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { } case lltok::kw_trunc: - case lltok::kw_fptrunc: - case lltok::kw_fpext: case lltok::kw_bitcast: case lltok::kw_addrspacecast: - case lltok::kw_uitofp: - case lltok::kw_sitofp: - case lltok::kw_fptoui: - case lltok::kw_fptosi: case lltok::kw_inttoptr: case lltok::kw_ptrtoint: { unsigned Opc = Lex.getUIntVal(); @@ -3868,6 +3862,18 @@ bool LLParser::parseValID(ValID &ID, PerFunctionState *PFS, Type *ExpectedTy) { return error(ID.Loc, "zext constexprs are no longer supported"); case lltok::kw_sext: return error(ID.Loc, "sext constexprs are no longer supported"); + case lltok::kw_fptrunc: + return error(ID.Loc, "fptrunc constexprs are no longer supported"); + case lltok::kw_fpext: + return error(ID.Loc, "fpext constexprs are no longer supported"); + case lltok::kw_uitofp: + return error(ID.Loc, "uitofp constexprs are no longer supported"); + case lltok::kw_sitofp: + return error(ID.Loc, "sitofp constexprs are no longer supported"); + case lltok::kw_fptoui: + return error(ID.Loc, "fptoui constexprs are no longer supported"); + case lltok::kw_fptosi: + return error(ID.Loc, "fptosi constexprs are no longer supported"); case lltok::kw_icmp: case lltok::kw_fcmp: { unsigned PredVal, Opc = Lex.getUIntVal(); diff --git a/llvm/lib/IR/Constants.cpp b/llvm/lib/IR/Constants.cpp index 16072d2..4e48069 100644 --- a/llvm/lib/IR/Constants.cpp +++ b/llvm/lib/IR/Constants.cpp @@ -1968,18 +1968,6 @@ Constant *ConstantExpr::getCast(unsigned oc, Constant *C, Type *Ty, llvm_unreachable("Invalid cast opcode"); case Instruction::Trunc: return getTrunc(C, Ty, OnlyIfReduced); - case Instruction::FPTrunc: - return getFPTrunc(C, Ty, OnlyIfReduced); - case Instruction::FPExt: - return getFPExtend(C, Ty, OnlyIfReduced); - case Instruction::UIToFP: - return getUIToFP(C, Ty, OnlyIfReduced); - case Instruction::SIToFP: - return getSIToFP(C, Ty, OnlyIfReduced); - case Instruction::FPToUI: - return getFPToUI(C, Ty, OnlyIfReduced); - case Instruction::FPToSI: - return getFPToSI(C, Ty, OnlyIfReduced); case Instruction::PtrToInt: return getPtrToInt(C, Ty, OnlyIfReduced); case Instruction::IntToPtr: @@ -2023,18 +2011,6 @@ Constant *ConstantExpr::getPointerBitCastOrAddrSpaceCast(Constant *S, return getBitCast(S, Ty); } -Constant *ConstantExpr::getFPCast(Constant *C, Type *Ty) { - assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && - "Invalid cast"); - unsigned SrcBits = C->getType()->getScalarSizeInBits(); - unsigned DstBits = Ty->getScalarSizeInBits(); - if (SrcBits == DstBits) - return C; // Avoid a useless cast - Instruction::CastOps opcode = - (SrcBits > DstBits ? Instruction::FPTrunc : Instruction::FPExt); - return getCast(opcode, C, Ty); -} - Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) { #ifndef NDEBUG bool fromVec = isa<VectorType>(C->getType()); @@ -2049,74 +2025,6 @@ Constant *ConstantExpr::getTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) { return getFoldedCast(Instruction::Trunc, C, Ty, OnlyIfReduced); } -Constant *ConstantExpr::getFPTrunc(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && - C->getType()->getScalarSizeInBits() > Ty->getScalarSizeInBits()&& - "This is an illegal floating point truncation!"); - return getFoldedCast(Instruction::FPTrunc, C, Ty, OnlyIfReduced); -} - -Constant *ConstantExpr::getFPExtend(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isFPOrFPVectorTy() && Ty->isFPOrFPVectorTy() && - C->getType()->getScalarSizeInBits() < Ty->getScalarSizeInBits()&& - "This is an illegal floating point extension!"); - return getFoldedCast(Instruction::FPExt, C, Ty, OnlyIfReduced); -} - -Constant *ConstantExpr::getUIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() && - "This is an illegal uint to floating point cast!"); - return getFoldedCast(Instruction::UIToFP, C, Ty, OnlyIfReduced); -} - -Constant *ConstantExpr::getSIToFP(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isIntOrIntVectorTy() && Ty->isFPOrFPVectorTy() && - "This is an illegal sint to floating point cast!"); - return getFoldedCast(Instruction::SIToFP, C, Ty, OnlyIfReduced); -} - -Constant *ConstantExpr::getFPToUI(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() && - "This is an illegal floating point to uint cast!"); - return getFoldedCast(Instruction::FPToUI, C, Ty, OnlyIfReduced); -} - -Constant *ConstantExpr::getFPToSI(Constant *C, Type *Ty, bool OnlyIfReduced) { -#ifndef NDEBUG - bool fromVec = isa<VectorType>(C->getType()); - bool toVec = isa<VectorType>(Ty); -#endif - assert((fromVec == toVec) && "Cannot convert from scalar to/from vector"); - assert(C->getType()->isFPOrFPVectorTy() && Ty->isIntOrIntVectorTy() && - "This is an illegal floating point to sint cast!"); - return getFoldedCast(Instruction::FPToSI, C, Ty, OnlyIfReduced); -} - Constant *ConstantExpr::getPtrToInt(Constant *C, Type *DstTy, bool OnlyIfReduced) { assert(C->getType()->isPtrOrPtrVectorTy() && @@ -2292,14 +2200,14 @@ bool ConstantExpr::isSupportedCastOp(unsigned Opcode) { switch (Opcode) { case Instruction::ZExt: case Instruction::SExt: - return false; - case Instruction::Trunc: case Instruction::FPTrunc: case Instruction::FPExt: case Instruction::UIToFP: case Instruction::SIToFP: case Instruction::FPToUI: case Instruction::FPToSI: + return false; + case Instruction::Trunc: case Instruction::PtrToInt: case Instruction::IntToPtr: case Instruction::BitCast: diff --git a/llvm/lib/IR/Core.cpp b/llvm/lib/IR/Core.cpp index 076d108..004b0e8 100644 --- a/llvm/lib/IR/Core.cpp +++ b/llvm/lib/IR/Core.cpp @@ -1744,36 +1744,6 @@ LLVMValueRef LLVMConstTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { unwrap(ToType))); } -LLVMValueRef LLVMConstFPTrunc(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getFPTrunc(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - -LLVMValueRef LLVMConstFPExt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getFPExtend(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - -LLVMValueRef LLVMConstUIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getUIToFP(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - -LLVMValueRef LLVMConstSIToFP(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getSIToFP(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - -LLVMValueRef LLVMConstFPToUI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getFPToUI(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - -LLVMValueRef LLVMConstFPToSI(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getFPToSI(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - LLVMValueRef LLVMConstPtrToInt(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { return wrap(ConstantExpr::getPtrToInt(unwrap<Constant>(ConstantVal), unwrap(ToType))); @@ -1807,11 +1777,6 @@ LLVMValueRef LLVMConstPointerCast(LLVMValueRef ConstantVal, unwrap(ToType))); } -LLVMValueRef LLVMConstFPCast(LLVMValueRef ConstantVal, LLVMTypeRef ToType) { - return wrap(ConstantExpr::getFPCast(unwrap<Constant>(ConstantVal), - unwrap(ToType))); -} - LLVMValueRef LLVMConstExtractElement(LLVMValueRef VectorConstant, LLVMValueRef IndexConstant) { return wrap(ConstantExpr::getExtractElement(unwrap<Constant>(VectorConstant), |