diff options
author | Dimitry Andric <dim@FreeBSD.org> | 2022-07-14 18:58:48 +0000 |
---|---|---|
committer | Dimitry Andric <dim@FreeBSD.org> | 2023-02-08 19:03:59 +0000 |
commit | 753f127f3ace09432b2baeffd71a308760641a62 (patch) | |
tree | 97694ab339c0ca6145ebb429c7505019565b9a60 /contrib/llvm-project/llvm/lib/IR | |
parent | 81ad626541db97eb356e2c1d4a20eb2a26a766ab (diff) | |
parent | 1f917f69ff07f09b6dbb670971f57f8efe718b84 (diff) | |
download | src-753f127f3ace09432b2baeffd71a308760641a62.tar.gz src-753f127f3ace09432b2baeffd71a308760641a62.zip |
Merge llvm-project main llvmorg-15-init-16436-g18a6ab5b8d1f
This updates llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and
openmp to llvmorg-15-init-16436-g18a6ab5b8d1f.
PR: 265425
MFC after: 2 weeks
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR')
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/AsmWriter.cpp | 14 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/ConstantFold.cpp | 27 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Constants.cpp | 183 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/ConstantsContext.h | 60 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Core.cpp | 86 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/InlineAsm.cpp | 43 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Instructions.cpp | 17 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/IntrinsicInst.cpp | 10 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp | 5 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Metadata.cpp | 7 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Module.cpp | 12 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/OptBisect.cpp | 7 | ||||
-rw-r--r-- | contrib/llvm-project/llvm/lib/IR/PassRegistry.cpp | 10 |
13 files changed, 168 insertions, 313 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/AsmWriter.cpp b/contrib/llvm-project/llvm/lib/IR/AsmWriter.cpp index 596348ddb462..a29040b8c2aa 100644 --- a/contrib/llvm-project/llvm/lib/IR/AsmWriter.cpp +++ b/contrib/llvm-project/llvm/lib/IR/AsmWriter.cpp @@ -1590,10 +1590,6 @@ static void WriteConstantInternal(raw_ostream &Out, const Constant *CV, Out << ", "; } - if (CE->hasIndices()) - for (unsigned I : CE->getIndices()) - Out << ", " << I; - if (CE->isCast()) { Out << " to "; WriterCtx.TypePrinter->print(CE->getType(), Out); @@ -3542,8 +3538,8 @@ void AssemblyWriter::printGlobal(const GlobalVariable *GV) { Out << ", no_sanitize_address"; if (MD.NoHWAddress) Out << ", no_sanitize_hwaddress"; - if (MD.NoMemtag) - Out << ", no_sanitize_memtag"; + if (MD.Memtag) + Out << ", sanitize_memtag"; if (MD.IsDynInit) Out << ", sanitize_address_dyninit"; } @@ -4299,9 +4295,9 @@ void AssemblyWriter::printInstruction(const Instruction &I) { bool PrintAllTypes = false; Type *TheType = Operand->getType(); - // Select, Store and ShuffleVector always print all types. - if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) - || isa<ReturnInst>(I)) { + // Select, Store, ShuffleVector and CmpXchg always print all types. + if (isa<SelectInst>(I) || isa<StoreInst>(I) || isa<ShuffleVectorInst>(I) || + isa<ReturnInst>(I) || isa<AtomicCmpXchgInst>(I)) { PrintAllTypes = true; } else { for (unsigned i = 1, E = I.getNumOperands(); i != E; ++i) { diff --git a/contrib/llvm-project/llvm/lib/IR/ConstantFold.cpp b/contrib/llvm-project/llvm/lib/IR/ConstantFold.cpp index 41b4f2919221..98adff107cec 100644 --- a/contrib/llvm-project/llvm/lib/IR/ConstantFold.cpp +++ b/contrib/llvm-project/llvm/lib/IR/ConstantFold.cpp @@ -1218,9 +1218,13 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, if (Instruction::isIntDivRem(Opcode) && C2Splat->isNullValue()) return PoisonValue::get(VTy); if (Constant *C1Splat = C1->getSplatValue()) { - return ConstantVector::getSplat( - VTy->getElementCount(), - ConstantExpr::get(Opcode, C1Splat, C2Splat)); + Constant *Res = + ConstantExpr::isDesirableBinOp(Opcode) + ? ConstantExpr::get(Opcode, C1Splat, C2Splat) + : ConstantFoldBinaryInstruction(Opcode, C1Splat, C2Splat); + if (!Res) + return nullptr; + return ConstantVector::getSplat(VTy->getElementCount(), Res); } } @@ -1237,7 +1241,12 @@ Constant *llvm::ConstantFoldBinaryInstruction(unsigned Opcode, Constant *C1, if (Instruction::isIntDivRem(Opcode) && RHS->isNullValue()) return PoisonValue::get(VTy); - Result.push_back(ConstantExpr::get(Opcode, LHS, RHS)); + Constant *Res = ConstantExpr::isDesirableBinOp(Opcode) + ? ConstantExpr::get(Opcode, LHS, RHS) + : ConstantFoldBinaryInstruction(Opcode, LHS, RHS); + if (!Res) + return nullptr; + Result.push_back(Res); } return ConstantVector::get(Result); @@ -2218,9 +2227,15 @@ Constant *llvm::ConstantFoldGetElementPtr(Type *PointeeTy, Constant *C, : cast<FixedVectorType>(CurrIdx->getType())->getNumElements(), Factor); - NewIdxs[i] = ConstantExpr::getSRem(CurrIdx, Factor); + NewIdxs[i] = + ConstantFoldBinaryInstruction(Instruction::SRem, CurrIdx, Factor); + + Constant *Div = + ConstantFoldBinaryInstruction(Instruction::SDiv, CurrIdx, Factor); - Constant *Div = ConstantExpr::getSDiv(CurrIdx, Factor); + // We're working on either ConstantInt or vectors of ConstantInt, + // so these should always fold. + assert(NewIdxs[i] != nullptr && Div != nullptr && "Should have folded"); unsigned CommonExtendedWidth = std::max(PrevIdx->getType()->getScalarSizeInBits(), diff --git a/contrib/llvm-project/llvm/lib/IR/Constants.cpp b/contrib/llvm-project/llvm/lib/IR/Constants.cpp index 0bf5e09d6647..f9800cc0c07c 100644 --- a/contrib/llvm-project/llvm/lib/IR/Constants.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Constants.cpp @@ -547,8 +547,6 @@ void llvm::deleteConstant(Constant *C) { delete static_cast<InsertElementConstantExpr *>(C); else if (isa<ShuffleVectorConstantExpr>(C)) delete static_cast<ShuffleVectorConstantExpr *>(C); - else if (isa<InsertValueConstantExpr>(C)) - delete static_cast<InsertValueConstantExpr *>(C); else if (isa<GetElementPtrConstantExpr>(C)) delete static_cast<GetElementPtrConstantExpr *>(C); else if (isa<CompareConstantExpr>(C)) @@ -561,51 +559,6 @@ void llvm::deleteConstant(Constant *C) { } } -static bool canTrapImpl(const Constant *C, - SmallPtrSetImpl<const Constant *> &NonTrappingOps) { - assert(C->getType()->isFirstClassType() && - "Cannot evaluate non-first-class types!"); - // ConstantExpr or ConstantAggregate trap if any operands can trap. - if (isa<ConstantExpr>(C) || isa<ConstantAggregate>(C)) { - for (unsigned i = 0, e = C->getNumOperands(); i != e; ++i) { - const Constant *Op = cast<Constant>(C->getOperand(i)); - if (isa<ConstantExpr>(Op) || isa<ConstantAggregate>(Op)) { - if (NonTrappingOps.insert(Op).second && canTrapImpl(Op, NonTrappingOps)) - return true; - } - } - } - - // The only leafs that can trap are constant expressions. - const ConstantExpr *CE = dyn_cast<ConstantExpr>(C); - if (!CE) - return false; - - // Otherwise, only specific operations can trap. - switch (CE->getOpcode()) { - default: - return false; - case Instruction::SDiv: - case Instruction::SRem: - // Signed div/rem can trap for SignedMin / -1. - if (!CE->getOperand(0)->isNotMinSignedValue() && - (!isa<ConstantInt>(CE->getOperand(1)) || - CE->getOperand(1)->isAllOnesValue())) - return true; - LLVM_FALLTHROUGH; - case Instruction::UDiv: - case Instruction::URem: - // Div and rem can trap if the RHS is not known to be non-zero. - return !isa<ConstantInt>(CE->getOperand(1)) || - CE->getOperand(1)->isNullValue(); - } -} - -bool Constant::canTrap() const { - SmallPtrSet<const Constant *, 4> NonTrappingOps; - return canTrapImpl(this, NonTrappingOps); -} - /// Check if C contains a GlobalValue for which Predicate is true. static bool ConstHasGlobalValuePredicate(const Constant *C, @@ -1488,14 +1441,6 @@ bool ConstantExpr::isCompare() const { return getOpcode() == Instruction::ICmp || getOpcode() == Instruction::FCmp; } -bool ConstantExpr::hasIndices() const { - return getOpcode() == Instruction::InsertValue; -} - -ArrayRef<unsigned> ConstantExpr::getIndices() const { - return cast<InsertValueConstantExpr>(this)->Indices; -} - unsigned ConstantExpr::getPredicate() const { return cast<CompareConstantExpr>(this)->predicate; } @@ -1539,9 +1484,6 @@ Constant *ConstantExpr::getWithOperands(ArrayRef<Constant *> 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: @@ -2324,6 +2266,8 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2, // Check the operands for consistency first. assert(Instruction::isBinaryOp(Opcode) && "Invalid opcode in binary constant expression"); + assert(isSupportedBinOp(Opcode) && + "Binop not supported as constant expression"); assert(C1->getType() == C2->getType() && "Operand types in binary constant expression should match"); @@ -2378,6 +2322,60 @@ Constant *ConstantExpr::get(unsigned Opcode, Constant *C1, Constant *C2, return pImpl->ExprConstants.getOrCreate(C1->getType(), Key); } +bool ConstantExpr::isDesirableBinOp(unsigned Opcode) { + switch (Opcode) { + case Instruction::UDiv: + case Instruction::SDiv: + case Instruction::URem: + case Instruction::SRem: + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: + return false; + case Instruction::Add: + case Instruction::Sub: + case Instruction::Mul: + case Instruction::Shl: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::And: + case Instruction::Or: + case Instruction::Xor: + return true; + default: + llvm_unreachable("Argument must be binop opcode"); + } +} + +bool ConstantExpr::isSupportedBinOp(unsigned Opcode) { + switch (Opcode) { + case Instruction::UDiv: + case Instruction::SDiv: + case Instruction::URem: + case Instruction::SRem: + case Instruction::FAdd: + case Instruction::FSub: + case Instruction::FMul: + case Instruction::FDiv: + case Instruction::FRem: + return false; + case Instruction::Add: + case Instruction::Sub: + case Instruction::Mul: + case Instruction::Shl: + case Instruction::LShr: + case Instruction::AShr: + case Instruction::And: + case Instruction::Or: + case Instruction::Xor: + return true; + default: + llvm_unreachable("Argument must be binop opcode"); + } +} + Constant *ConstantExpr::getSizeOf(Type* Ty) { // sizeof is implemented as: (i64) gep (Ty*)null, 1 // Note that a non-inbounds gep is used, as null isn't within any object. @@ -2517,7 +2515,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 +2636,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<unsigned> 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!"); @@ -2694,10 +2668,6 @@ Constant *ConstantExpr::getAdd(Constant *C1, Constant *C2, return get(Instruction::Add, C1, C2, Flags); } -Constant *ConstantExpr::getFAdd(Constant *C1, Constant *C2) { - return get(Instruction::FAdd, C1, C2); -} - Constant *ConstantExpr::getSub(Constant *C1, Constant *C2, bool HasNUW, bool HasNSW) { unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | @@ -2705,10 +2675,6 @@ Constant *ConstantExpr::getSub(Constant *C1, Constant *C2, return get(Instruction::Sub, C1, C2, Flags); } -Constant *ConstantExpr::getFSub(Constant *C1, Constant *C2) { - return get(Instruction::FSub, C1, C2); -} - Constant *ConstantExpr::getMul(Constant *C1, Constant *C2, bool HasNUW, bool HasNSW) { unsigned Flags = (HasNUW ? OverflowingBinaryOperator::NoUnsignedWrap : 0) | @@ -2716,36 +2682,6 @@ Constant *ConstantExpr::getMul(Constant *C1, Constant *C2, return get(Instruction::Mul, C1, C2, Flags); } -Constant *ConstantExpr::getFMul(Constant *C1, Constant *C2) { - return get(Instruction::FMul, C1, C2); -} - -Constant *ConstantExpr::getUDiv(Constant *C1, Constant *C2, bool isExact) { - return get(Instruction::UDiv, C1, C2, - isExact ? PossiblyExactOperator::IsExact : 0); -} - -Constant *ConstantExpr::getSDiv(Constant *C1, Constant *C2, bool isExact) { - return get(Instruction::SDiv, C1, C2, - isExact ? PossiblyExactOperator::IsExact : 0); -} - -Constant *ConstantExpr::getFDiv(Constant *C1, Constant *C2) { - return get(Instruction::FDiv, C1, C2); -} - -Constant *ConstantExpr::getURem(Constant *C1, Constant *C2) { - return get(Instruction::URem, C1, C2); -} - -Constant *ConstantExpr::getSRem(Constant *C1, Constant *C2) { - return get(Instruction::SRem, C1, C2); -} - -Constant *ConstantExpr::getFRem(Constant *C1, Constant *C2) { - return get(Instruction::FRem, C1, C2); -} - Constant *ConstantExpr::getAnd(Constant *C1, Constant *C2) { return get(Instruction::And, C1, C2); } @@ -3517,9 +3453,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); diff --git a/contrib/llvm-project/llvm/lib/IR/ConstantsContext.h b/contrib/llvm-project/llvm/lib/IR/ConstantsContext.h index 21ef1c0d9f64..1d74e2d49f35 100644 --- a/contrib/llvm-project/llvm/lib/IR/ConstantsContext.h +++ b/contrib/llvm-project/llvm/lib/IR/ConstantsContext.h @@ -209,37 +209,6 @@ public: } }; -/// InsertValueConstantExpr - This class is private to -/// Constants.cpp, and is used behind the scenes to implement -/// insertvalue constant exprs. -class InsertValueConstantExpr final : public ConstantExpr { -public: - InsertValueConstantExpr(Constant *Agg, Constant *Val, - ArrayRef<unsigned> IdxList, Type *DestTy) - : ConstantExpr(DestTy, Instruction::InsertValue, &Op<0>(), 2), - Indices(IdxList.begin(), IdxList.end()) { - Op<0>() = Agg; - Op<1>() = Val; - } - - // allocate space for exactly one operand - void *operator new(size_t S) { return User::operator new(S, 2); } - void operator delete(void *Ptr) { User::operator delete(Ptr); } - - /// Indices - These identify the position for the insertion. - const SmallVector<unsigned, 4> Indices; - - /// Transparently provide more efficient getOperand methods. - DECLARE_TRANSPARENT_OPERAND_ACCESSORS(Value); - - static bool classof(const ConstantExpr *CE) { - return CE->getOpcode() == Instruction::InsertValue; - } - static bool classof(const Value *V) { - return isa<ConstantExpr>(V) && classof(cast<ConstantExpr>(V)); - } -}; - /// GetElementPtrConstantExpr - This class is private to Constants.cpp, and is /// used behind the scenes to implement getelementpr constant exprs. class GetElementPtrConstantExpr final : public ConstantExpr { @@ -333,11 +302,6 @@ struct OperandTraits<ShuffleVectorConstantExpr> DEFINE_TRANSPARENT_OPERAND_ACCESSORS(ShuffleVectorConstantExpr, Value) template <> -struct OperandTraits<InsertValueConstantExpr> - : public FixedNumOperandTraits<InsertValueConstantExpr, 2> {}; -DEFINE_TRANSPARENT_OPERAND_ACCESSORS(InsertValueConstantExpr, Value) - -template <> struct OperandTraits<GetElementPtrConstantExpr> : public VariadicOperandTraits<GetElementPtrConstantExpr, 1> {}; @@ -472,7 +436,6 @@ private: uint8_t SubclassOptionalData; uint16_t SubclassData; ArrayRef<Constant *> Ops; - ArrayRef<unsigned> Indexes; ArrayRef<int> ShuffleMask; Type *ExplicitTy; @@ -482,12 +445,6 @@ private: return None; } - static ArrayRef<unsigned> getIndicesIfValid(const ConstantExpr *CE) { - if (CE->hasIndices()) - return CE->getIndices(); - return None; - } - static Type *getSourceElementTypeIfValid(const ConstantExpr *CE) { if (auto *GEPCE = dyn_cast<GetElementPtrConstantExpr>(CE)) return GEPCE->getSourceElementType(); @@ -498,18 +455,17 @@ public: ConstantExprKeyType(unsigned Opcode, ArrayRef<Constant *> Ops, unsigned short SubclassData = 0, unsigned short SubclassOptionalData = 0, - ArrayRef<unsigned> Indexes = None, ArrayRef<int> ShuffleMask = None, Type *ExplicitTy = nullptr) : Opcode(Opcode), SubclassOptionalData(SubclassOptionalData), - SubclassData(SubclassData), Ops(Ops), Indexes(Indexes), - ShuffleMask(ShuffleMask), ExplicitTy(ExplicitTy) {} + SubclassData(SubclassData), Ops(Ops), ShuffleMask(ShuffleMask), + ExplicitTy(ExplicitTy) {} ConstantExprKeyType(ArrayRef<Constant *> Operands, const ConstantExpr *CE) : Opcode(CE->getOpcode()), SubclassOptionalData(CE->getRawSubclassOptionalData()), SubclassData(CE->isCompare() ? CE->getPredicate() : 0), Ops(Operands), - Indexes(getIndicesIfValid(CE)), ShuffleMask(getShuffleMaskIfValid(CE)), + ShuffleMask(getShuffleMaskIfValid(CE)), ExplicitTy(getSourceElementTypeIfValid(CE)) {} ConstantExprKeyType(const ConstantExpr *CE, @@ -517,7 +473,7 @@ public: : Opcode(CE->getOpcode()), SubclassOptionalData(CE->getRawSubclassOptionalData()), SubclassData(CE->isCompare() ? CE->getPredicate() : 0), - Indexes(getIndicesIfValid(CE)), ShuffleMask(getShuffleMaskIfValid(CE)), + ShuffleMask(getShuffleMaskIfValid(CE)), ExplicitTy(getSourceElementTypeIfValid(CE)) { assert(Storage.empty() && "Expected empty storage"); for (unsigned I = 0, E = CE->getNumOperands(); I != E; ++I) @@ -528,8 +484,7 @@ public: bool operator==(const ConstantExprKeyType &X) const { return Opcode == X.Opcode && SubclassData == X.SubclassData && SubclassOptionalData == X.SubclassOptionalData && Ops == X.Ops && - Indexes == X.Indexes && ShuffleMask == X.ShuffleMask && - ExplicitTy == X.ExplicitTy; + ShuffleMask == X.ShuffleMask && ExplicitTy == X.ExplicitTy; } bool operator==(const ConstantExpr *CE) const { @@ -544,8 +499,6 @@ public: for (unsigned I = 0, E = Ops.size(); I != E; ++I) if (Ops[I] != CE->getOperand(I)) return false; - if (Indexes != getIndicesIfValid(CE)) - return false; if (ShuffleMask != getShuffleMaskIfValid(CE)) return false; if (ExplicitTy != getSourceElementTypeIfValid(CE)) @@ -557,7 +510,6 @@ public: return hash_combine( Opcode, SubclassOptionalData, SubclassData, hash_combine_range(Ops.begin(), Ops.end()), - hash_combine_range(Indexes.begin(), Indexes.end()), hash_combine_range(ShuffleMask.begin(), ShuffleMask.end()), ExplicitTy); } @@ -583,8 +535,6 @@ public: return new InsertElementConstantExpr(Ops[0], Ops[1], Ops[2]); case Instruction::ShuffleVector: return new ShuffleVectorConstantExpr(Ops[0], Ops[1], ShuffleMask); - case Instruction::InsertValue: - return new InsertValueConstantExpr(Ops[0], Ops[1], Indexes, Ty); case Instruction::GetElementPtr: return GetElementPtrConstantExpr::Create(ExplicitTy, Ops[0], Ops.slice(1), Ty, SubclassOptionalData); diff --git a/contrib/llvm-project/llvm/lib/IR/Core.cpp b/contrib/llvm-project/llvm/lib/IR/Core.cpp index 4b9189ca5baa..08b7b0e1f956 100644 --- a/contrib/llvm-project/llvm/lib/IR/Core.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Core.cpp @@ -74,13 +74,16 @@ void LLVMDisposeMessage(char *Message) { /*===-- Operations on contexts --------------------------------------------===*/ -static ManagedStatic<LLVMContext> GlobalContext; +static LLVMContext &getGlobalContext() { + static LLVMContext GlobalContext; + return GlobalContext; +} LLVMContextRef LLVMContextCreate() { return wrap(new LLVMContext()); } -LLVMContextRef LLVMGetGlobalContext() { return wrap(&*GlobalContext); } +LLVMContextRef LLVMGetGlobalContext() { return wrap(&getGlobalContext()); } void LLVMContextSetDiagnosticHandler(LLVMContextRef C, LLVMDiagnosticHandler Handler, @@ -251,7 +254,7 @@ LLVMDiagnosticSeverity LLVMGetDiagInfoSeverity(LLVMDiagnosticInfoRef DI) { /*===-- Operations on modules ---------------------------------------------===*/ LLVMModuleRef LLVMModuleCreateWithName(const char *ModuleID) { - return wrap(new Module(ModuleID, *GlobalContext)); + return wrap(new Module(ModuleID, getGlobalContext())); } LLVMModuleRef LLVMModuleCreateWithNameInContext(const char *ModuleID, @@ -1571,11 +1574,6 @@ LLVMValueRef LLVMConstNUWAdd(LLVMValueRef LHSConstant, unwrap<Constant>(RHSConstant))); } -LLVMValueRef LLVMConstFAdd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFAdd(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - LLVMValueRef LLVMConstSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { return wrap(ConstantExpr::getSub(unwrap<Constant>(LHSConstant), unwrap<Constant>(RHSConstant))); @@ -1593,11 +1591,6 @@ LLVMValueRef LLVMConstNUWSub(LLVMValueRef LHSConstant, unwrap<Constant>(RHSConstant))); } -LLVMValueRef LLVMConstFSub(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFSub(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - LLVMValueRef LLVMConstMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { return wrap(ConstantExpr::getMul(unwrap<Constant>(LHSConstant), unwrap<Constant>(RHSConstant))); @@ -1615,53 +1608,6 @@ LLVMValueRef LLVMConstNUWMul(LLVMValueRef LHSConstant, unwrap<Constant>(RHSConstant))); } -LLVMValueRef LLVMConstFMul(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFMul(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstUDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getUDiv(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstExactUDiv(LLVMValueRef LHSConstant, - LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getExactUDiv(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstSDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getSDiv(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstExactSDiv(LLVMValueRef LHSConstant, - LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getExactSDiv(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstFDiv(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFDiv(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstURem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getURem(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstSRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getSRem(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - -LLVMValueRef LLVMConstFRem(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { - return wrap(ConstantExpr::getFRem(unwrap<Constant>(LHSConstant), - unwrap<Constant>(RHSConstant))); -} - LLVMValueRef LLVMConstAnd(LLVMValueRef LHSConstant, LLVMValueRef RHSConstant) { return wrap(ConstantExpr::getAnd(unwrap<Constant>(LHSConstant), unwrap<Constant>(RHSConstant))); @@ -1875,14 +1821,6 @@ LLVMValueRef LLVMConstShuffleVector(LLVMValueRef VectorAConstant, IntMask)); } -LLVMValueRef LLVMConstInsertValue(LLVMValueRef AggConstant, - LLVMValueRef ElementValueConstant, - unsigned *IdxList, unsigned NumIdx) { - return wrap(ConstantExpr::getInsertValue(unwrap<Constant>(AggConstant), - unwrap<Constant>(ElementValueConstant), - makeArrayRef(IdxList, NumIdx))); -} - LLVMValueRef LLVMConstInlineAsm(LLVMTypeRef Ty, const char *AsmString, const char *Constraints, LLVMBool HasSideEffects, @@ -2843,6 +2781,10 @@ void LLVMInstructionEraseFromParent(LLVMValueRef Inst) { unwrap<Instruction>(Inst)->eraseFromParent(); } +void LLVMDeleteInstruction(LLVMValueRef Inst) { + unwrap<Instruction>(Inst)->deleteValue(); +} + LLVMIntPredicate LLVMGetICmpPredicate(LLVMValueRef Inst) { if (ICmpInst *I = dyn_cast<ICmpInst>(unwrap(Inst))) return (LLVMIntPredicate)I->getPredicate(); @@ -3079,8 +3021,6 @@ unsigned LLVMGetNumIndices(LLVMValueRef Inst) { return EV->getNumIndices(); if (auto *IV = dyn_cast<InsertValueInst>(I)) return IV->getNumIndices(); - if (auto *CE = dyn_cast<ConstantExpr>(I)) - return CE->getIndices().size(); llvm_unreachable( "LLVMGetNumIndices applies only to extractvalue and insertvalue!"); } @@ -3091,8 +3031,6 @@ const unsigned *LLVMGetIndices(LLVMValueRef Inst) { return EV->getIndices().data(); if (auto *IV = dyn_cast<InsertValueInst>(I)) return IV->getIndices().data(); - if (auto *CE = dyn_cast<ConstantExpr>(I)) - return CE->getIndices().data(); llvm_unreachable( "LLVMGetIndices applies only to extractvalue and insertvalue!"); } @@ -3664,6 +3602,8 @@ static AtomicRMWInst::BinOp mapFromLLVMRMWBinOp(LLVMAtomicRMWBinOp BinOp) { case LLVMAtomicRMWBinOpUMin: return AtomicRMWInst::UMin; case LLVMAtomicRMWBinOpFAdd: return AtomicRMWInst::FAdd; case LLVMAtomicRMWBinOpFSub: return AtomicRMWInst::FSub; + case LLVMAtomicRMWBinOpFMax: return AtomicRMWInst::FMax; + case LLVMAtomicRMWBinOpFMin: return AtomicRMWInst::FMin; } llvm_unreachable("Invalid LLVMAtomicRMWBinOp value!"); @@ -3684,6 +3624,8 @@ static LLVMAtomicRMWBinOp mapToLLVMRMWBinOp(AtomicRMWInst::BinOp BinOp) { case AtomicRMWInst::UMin: return LLVMAtomicRMWBinOpUMin; case AtomicRMWInst::FAdd: return LLVMAtomicRMWBinOpFAdd; case AtomicRMWInst::FSub: return LLVMAtomicRMWBinOpFSub; + case AtomicRMWInst::FMax: return LLVMAtomicRMWBinOpFMax; + case AtomicRMWInst::FMin: return LLVMAtomicRMWBinOpFMin; default: break; } diff --git a/contrib/llvm-project/llvm/lib/IR/InlineAsm.cpp b/contrib/llvm-project/llvm/lib/IR/InlineAsm.cpp index 203ad6dae1ff..c75b1aa7c1d6 100644 --- a/contrib/llvm-project/llvm/lib/IR/InlineAsm.cpp +++ b/contrib/llvm-project/llvm/lib/IR/InlineAsm.cpp @@ -19,6 +19,7 @@ #include "llvm/IR/Value.h" #include "llvm/Support/Casting.h" #include "llvm/Support/Compiler.h" +#include "llvm/Support/Errc.h" #include <algorithm> #include <cassert> #include <cctype> @@ -33,9 +34,10 @@ InlineAsm::InlineAsm(FunctionType *FTy, const std::string &asmString, AsmString(asmString), Constraints(constraints), FTy(FTy), HasSideEffects(hasSideEffects), IsAlignStack(isAlignStack), Dialect(asmDialect), CanThrow(canThrow) { +#ifndef NDEBUG // Do various checks on the constraint string and type. - assert(Verify(getFunctionType(), constraints) && - "Function type not legal for constraints!"); + cantFail(verify(getFunctionType(), constraints)); +#endif } InlineAsm *InlineAsm::get(FunctionType *FTy, StringRef AsmString, @@ -248,15 +250,19 @@ InlineAsm::ParseConstraints(StringRef Constraints) { return Result; } -/// Verify - Verify that the specified constraint string is reasonable for the -/// specified function type, and otherwise validate the constraint string. -bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) { - if (Ty->isVarArg()) return false; +static Error makeStringError(const char *Msg) { + return createStringError(errc::invalid_argument, Msg); +} + +Error InlineAsm::verify(FunctionType *Ty, StringRef ConstStr) { + if (Ty->isVarArg()) + return makeStringError("inline asm cannot be variadic"); ConstraintInfoVector Constraints = ParseConstraints(ConstStr); // Error parsing constraints. - if (Constraints.empty() && !ConstStr.empty()) return false; + if (Constraints.empty() && !ConstStr.empty()) + return makeStringError("failed to parse constraints"); unsigned NumOutputs = 0, NumInputs = 0, NumClobbers = 0; unsigned NumIndirect = 0; @@ -265,7 +271,9 @@ bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) { switch (Constraint.Type) { case InlineAsm::isOutput: if ((NumInputs-NumIndirect) != 0 || NumClobbers != 0) - return false; // outputs before inputs and clobbers. + return makeStringError("output constraint occurs after input " + "or clobber constraint"); + if (!Constraint.isIndirect) { ++NumOutputs; break; @@ -273,7 +281,9 @@ bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) { ++NumIndirect; LLVM_FALLTHROUGH; // We fall through for Indirect Outputs. case InlineAsm::isInput: - if (NumClobbers) return false; // inputs before clobbers. + if (NumClobbers) + return makeStringError("input constraint occurs after clobber " + "constraint"); ++NumInputs; break; case InlineAsm::isClobber: @@ -284,18 +294,23 @@ bool InlineAsm::Verify(FunctionType *Ty, StringRef ConstStr) { switch (NumOutputs) { case 0: - if (!Ty->getReturnType()->isVoidTy()) return false; + if (!Ty->getReturnType()->isVoidTy()) + return makeStringError("inline asm without outputs must return void"); break; case 1: - if (Ty->getReturnType()->isStructTy()) return false; + if (Ty->getReturnType()->isStructTy()) + return makeStringError("inline asm with one output cannot return struct"); break; default: StructType *STy = dyn_cast<StructType>(Ty->getReturnType()); if (!STy || STy->getNumElements() != NumOutputs) - return false; + return makeStringError("number of output constraints does not match " + "number of return struct elements"); break; } - if (Ty->getNumParams() != NumInputs) return false; - return true; + if (Ty->getNumParams() != NumInputs) + return makeStringError("number of input constraints does not match number " + "of parameters"); + return Error::success(); } diff --git a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp index 6a91edb75dd2..b333f40f3ce9 100644 --- a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp @@ -1696,6 +1696,10 @@ StringRef AtomicRMWInst::getOperationName(BinOp Op) { return "fadd"; case AtomicRMWInst::FSub: return "fsub"; + case AtomicRMWInst::FMax: + return "fmax"; + case AtomicRMWInst::FMin: + return "fmin"; case AtomicRMWInst::BAD_BINOP: return "<invalid operation>"; } @@ -4423,10 +4427,9 @@ MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() { assert(SI.getNumSuccessors() == Weights->size() && "num of prof branch_weights must accord with num of successors"); - bool AllZeroes = - all_of(Weights.getValue(), [](uint32_t W) { return W == 0; }); + bool AllZeroes = all_of(Weights.value(), [](uint32_t W) { return W == 0; }); - if (AllZeroes || Weights.getValue().size() < 2) + if (AllZeroes || Weights.value().size() < 2) return nullptr; return MDBuilder(SI.getParent()->getContext()).createBranchWeights(*Weights); @@ -4460,8 +4463,8 @@ SwitchInstProfUpdateWrapper::removeCase(SwitchInst::CaseIt I) { // Copy the last case to the place of the removed one and shrink. // This is tightly coupled with the way SwitchInst::removeCase() removes // the cases in SwitchInst::removeCase(CaseIt). - Weights.getValue()[I->getCaseIndex() + 1] = Weights.getValue().back(); - Weights.getValue().pop_back(); + Weights.value()[I->getCaseIndex() + 1] = Weights.value().back(); + Weights.value().pop_back(); } return SI.removeCase(I); } @@ -4474,10 +4477,10 @@ void SwitchInstProfUpdateWrapper::addCase( if (!Weights && W && *W) { Changed = true; Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0); - Weights.getValue()[SI.getNumSuccessors() - 1] = *W; + Weights.value()[SI.getNumSuccessors() - 1] = *W; } else if (Weights) { Changed = true; - Weights.getValue().push_back(W.value_or(0)); + Weights.value().push_back(W.value_or(0)); } if (Weights) assert(SI.getNumSuccessors() == Weights->size() && diff --git a/contrib/llvm-project/llvm/lib/IR/IntrinsicInst.cpp b/contrib/llvm-project/llvm/lib/IR/IntrinsicInst.cpp index b132a9dcb812..65a9a32ad2c5 100644 --- a/contrib/llvm-project/llvm/lib/IR/IntrinsicInst.cpp +++ b/contrib/llvm-project/llvm/lib/IR/IntrinsicInst.cpp @@ -223,13 +223,13 @@ ConstrainedFPIntrinsic::getExceptionBehavior() const { bool ConstrainedFPIntrinsic::isDefaultFPEnvironment() const { Optional<fp::ExceptionBehavior> Except = getExceptionBehavior(); if (Except) { - if (Except.getValue() != fp::ebIgnore) + if (Except.value() != fp::ebIgnore) return false; } Optional<RoundingMode> Rounding = getRoundingMode(); if (Rounding) { - if (Rounding.getValue() != RoundingMode::NearestTiesToEven) + if (Rounding.value() != RoundingMode::NearestTiesToEven) return false; } @@ -364,13 +364,13 @@ VPIntrinsic::getVectorLengthParamPos(Intrinsic::ID IntrinsicID) { MaybeAlign VPIntrinsic::getPointerAlignment() const { Optional<unsigned> PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID()); assert(PtrParamOpt && "no pointer argument!"); - return getParamAlign(PtrParamOpt.getValue()); + return getParamAlign(PtrParamOpt.value()); } /// \return The pointer operand of this load,store, gather or scatter. Value *VPIntrinsic::getMemoryPointerParam() const { if (auto PtrParamOpt = getMemoryPointerParamPos(getIntrinsicID())) - return getArgOperand(PtrParamOpt.getValue()); + return getArgOperand(PtrParamOpt.value()); return nullptr; } @@ -391,7 +391,7 @@ Value *VPIntrinsic::getMemoryDataParam() const { auto DataParamOpt = getMemoryDataParamPos(getIntrinsicID()); if (!DataParamOpt) return nullptr; - return getArgOperand(DataParamOpt.getValue()); + return getArgOperand(DataParamOpt.value()); } Optional<unsigned> VPIntrinsic::getMemoryDataParamPos(Intrinsic::ID VPID) { diff --git a/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp b/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp index 06b3a3afef9d..d7aaf0008564 100644 --- a/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp +++ b/contrib/llvm-project/llvm/lib/IR/LLVMContextImpl.cpp @@ -27,7 +27,6 @@ #include "llvm/Support/CommandLine.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" -#include "llvm/Support/ManagedStatic.h" #include "llvm/Support/TypeSize.h" #include <cassert> #include <utility> @@ -241,7 +240,7 @@ void LLVMContextImpl::getSyncScopeNames( /// singleton OptBisect if not explicitly set. OptPassGate &LLVMContextImpl::getOptPassGate() const { if (!OPG) - OPG = &(*OptBisector); + OPG = &getOptBisector(); return *OPG; } @@ -260,7 +259,7 @@ bool LLVMContextImpl::getOpaquePointers() { } void LLVMContextImpl::setOpaquePointers(bool OP) { - assert((!OpaquePointers || OpaquePointers.getValue() == OP) && + assert((!OpaquePointers || OpaquePointers.value() == OP) && "Cannot change opaque pointers mode once set"); OpaquePointers = OP; } diff --git a/contrib/llvm-project/llvm/lib/IR/Metadata.cpp b/contrib/llvm-project/llvm/lib/IR/Metadata.cpp index ae2401026ebf..2a1a514922fd 100644 --- a/contrib/llvm-project/llvm/lib/IR/Metadata.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Metadata.cpp @@ -592,13 +592,6 @@ MDNode::Header::~Header() { (void)(O - 1)->~MDOperand(); } -void *MDNode::Header::getLargePtr() const { - static_assert(alignof(LargeStorageVector) <= alignof(Header), - "LargeStorageVector too strongly aligned"); - return reinterpret_cast<char *>(const_cast<Header *>(this)) - - sizeof(LargeStorageVector); -} - void *MDNode::Header::getSmallPtr() { static_assert(alignof(MDOperand) <= alignof(Header), "MDOperand too strongly aligned"); diff --git a/contrib/llvm-project/llvm/lib/IR/Module.cpp b/contrib/llvm-project/llvm/lib/IR/Module.cpp index 5cd74d53da75..b51ea45f651a 100644 --- a/contrib/llvm-project/llvm/lib/IR/Module.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Module.cpp @@ -714,6 +714,18 @@ void Module::setStackProtectorGuardReg(StringRef Reg) { addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-reg", ID); } +StringRef Module::getStackProtectorGuardSymbol() const { + Metadata *MD = getModuleFlag("stack-protector-guard-symbol"); + if (auto *MDS = dyn_cast_or_null<MDString>(MD)) + return MDS->getString(); + return {}; +} + +void Module::setStackProtectorGuardSymbol(StringRef Symbol) { + MDString *ID = MDString::get(getContext(), Symbol); + addModuleFlag(ModFlagBehavior::Error, "stack-protector-guard-symbol", ID); +} + int Module::getStackProtectorGuardOffset() const { Metadata *MD = getModuleFlag("stack-protector-guard-offset"); if (auto *CI = mdconst::dyn_extract_or_null<ConstantInt>(MD)) diff --git a/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp b/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp index 418311eac814..c9054dba344a 100644 --- a/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp +++ b/contrib/llvm-project/llvm/lib/IR/OptBisect.cpp @@ -23,7 +23,7 @@ using namespace llvm; static cl::opt<int> OptBisectLimit("opt-bisect-limit", cl::Hidden, cl::init(OptBisect::Disabled), cl::Optional, cl::cb<void, int>([](int Limit) { - llvm::OptBisector->setLimit(Limit); + llvm::getOptBisector().setLimit(Limit); }), cl::desc("Maximum optimization to perform")); @@ -52,4 +52,7 @@ bool OptBisect::checkPass(const StringRef PassName, const int OptBisect::Disabled; -ManagedStatic<OptBisect> llvm::OptBisector; +OptBisect &llvm::getOptBisector() { + static OptBisect OptBisector; + return OptBisector; +} diff --git a/contrib/llvm-project/llvm/lib/IR/PassRegistry.cpp b/contrib/llvm-project/llvm/lib/IR/PassRegistry.cpp index 94f607afec47..6c22fcd34769 100644 --- a/contrib/llvm-project/llvm/lib/IR/PassRegistry.cpp +++ b/contrib/llvm-project/llvm/lib/IR/PassRegistry.cpp @@ -15,21 +15,15 @@ #include "llvm/ADT/STLExtras.h" #include "llvm/Pass.h" #include "llvm/PassInfo.h" -#include "llvm/Support/ManagedStatic.h" #include <cassert> #include <memory> #include <utility> using namespace llvm; -// FIXME: We use ManagedStatic to erase the pass registrar on shutdown. -// Unfortunately, passes are registered with static ctors, and having -// llvm_shutdown clear this map prevents successful resurrection after -// llvm_shutdown is run. Ideally we should find a solution so that we don't -// leak the map, AND can still resurrect after shutdown. -static ManagedStatic<PassRegistry> PassRegistryObj; PassRegistry *PassRegistry::getPassRegistry() { - return &*PassRegistryObj; + static PassRegistry PassRegistryObj; + return &PassRegistryObj; } //===----------------------------------------------------------------------===// |