aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/lib/IR/Instructions.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/Instructions.cpp')
-rw-r--r--contrib/llvm-project/llvm/lib/IR/Instructions.cpp60
1 files changed, 45 insertions, 15 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp
index 7798af3b19b9..6a91edb75dd2 100644
--- a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp
+++ b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp
@@ -128,7 +128,7 @@ Value *PHINode::removeIncomingValue(unsigned Idx, bool DeletePHIIfEmpty) {
// If the PHI node is dead, because it has zero entries, nuke it now.
if (getNumOperands() == 0 && DeletePHIIfEmpty) {
// If anyone is using this PHI, make them use a dummy value instead...
- replaceAllUsesWith(UndefValue::get(getType()));
+ replaceAllUsesWith(PoisonValue::get(getType()));
eraseFromParent();
}
return Removed;
@@ -325,13 +325,13 @@ bool CallBase::isReturnNonNull() const {
return false;
}
-Value *CallBase::getReturnedArgOperand() const {
+Value *CallBase::getArgOperandWithAttribute(Attribute::AttrKind Kind) const {
unsigned Index;
- if (Attrs.hasAttrSomewhere(Attribute::Returned, &Index))
+ if (Attrs.hasAttrSomewhere(Kind, &Index))
return getArgOperand(Index - AttributeList::FirstArgIndex);
if (const Function *F = getCalledFunction())
- if (F->getAttributes().hasAttrSomewhere(Attribute::Returned, &Index))
+ if (F->getAttributes().hasAttrSomewhere(Kind, &Index))
return getArgOperand(Index - AttributeList::FirstArgIndex);
return nullptr;
@@ -372,6 +372,27 @@ bool CallBase::hasFnAttrOnCalledFunction(StringRef Kind) const {
return false;
}
+template <typename AK>
+Attribute CallBase::getFnAttrOnCalledFunction(AK Kind) const {
+ // Operand bundles override attributes on the called function, but don't
+ // override attributes directly present on the call instruction.
+ if (isFnAttrDisallowedByOpBundle(Kind))
+ return Attribute();
+ Value *V = getCalledOperand();
+ if (auto *CE = dyn_cast<ConstantExpr>(V))
+ if (CE->getOpcode() == BitCast)
+ V = CE->getOperand(0);
+
+ if (auto *F = dyn_cast<Function>(V))
+ return F->getAttributes().getFnAttr(Kind);
+
+ return Attribute();
+}
+
+template Attribute
+CallBase::getFnAttrOnCalledFunction(Attribute::AttrKind Kind) const;
+template Attribute CallBase::getFnAttrOnCalledFunction(StringRef Kind) const;
+
void CallBase::getOperandBundlesAsDefs(
SmallVectorImpl<OperandBundleDef> &Defs) const {
for (unsigned i = 0, e = getNumOperandBundles(); i != e; ++i)
@@ -482,9 +503,10 @@ CallBase *CallBase::removeOperandBundle(CallBase *CB, uint32_t ID,
bool CallBase::hasReadingOperandBundles() const {
// Implementation note: this is a conservative implementation of operand
- // bundle semantics, where *any* non-assume operand bundle forces a callsite
- // to be at least readonly.
- return hasOperandBundles() && getIntrinsicID() != Intrinsic::assume;
+ // bundle semantics, where *any* non-assume operand bundle (other than
+ // ptrauth) forces a callsite to be at least readonly.
+ return hasOperandBundlesOtherThan(LLVMContext::OB_ptrauth) &&
+ getIntrinsicID() != Intrinsic::assume;
}
//===----------------------------------------------------------------------===//
@@ -2194,7 +2216,13 @@ bool ShuffleVectorInst::isIdentityMask(ArrayRef<int> Mask) {
bool ShuffleVectorInst::isReverseMask(ArrayRef<int> Mask) {
if (!isSingleSourceMask(Mask))
return false;
- for (int i = 0, NumElts = Mask.size(); i < NumElts; ++i) {
+
+ // The number of elements in the mask must be at least 2.
+ int NumElts = Mask.size();
+ if (NumElts < 2)
+ return false;
+
+ for (int i = 0; i < NumElts; ++i) {
if (Mask[i] == -1)
continue;
if (Mask[i] != (NumElts - 1 - i) && Mask[i] != (NumElts + NumElts - 1 - i))
@@ -3060,16 +3088,18 @@ unsigned CastInst::isEliminableCastPair(
return 0;
}
case 8: {
- // ext, trunc -> bitcast, if the SrcTy and DstTy are same size
+ // ext, trunc -> bitcast, if the SrcTy and DstTy are the same
// ext, trunc -> ext, if sizeof(SrcTy) < sizeof(DstTy)
// ext, trunc -> trunc, if sizeof(SrcTy) > sizeof(DstTy)
unsigned SrcSize = SrcTy->getScalarSizeInBits();
unsigned DstSize = DstTy->getScalarSizeInBits();
- if (SrcSize == DstSize)
+ if (SrcTy == DstTy)
return Instruction::BitCast;
- else if (SrcSize < DstSize)
+ if (SrcSize < DstSize)
return firstOp;
- return secondOp;
+ if (SrcSize > DstSize)
+ return secondOp;
+ return 0;
}
case 9:
// zext, sext -> zext, because sext can't sign extend after zext
@@ -4447,7 +4477,7 @@ void SwitchInstProfUpdateWrapper::addCase(
Weights.getValue()[SI.getNumSuccessors() - 1] = *W;
} else if (Weights) {
Changed = true;
- Weights.getValue().push_back(W.getValueOr(0));
+ Weights.getValue().push_back(W.value_or(0));
}
if (Weights)
assert(SI.getNumSuccessors() == Weights->size() &&
@@ -4467,7 +4497,7 @@ SwitchInstProfUpdateWrapper::CaseWeightOpt
SwitchInstProfUpdateWrapper::getSuccessorWeight(unsigned idx) {
if (!Weights)
return None;
- return Weights.getValue()[idx];
+ return (*Weights)[idx];
}
void SwitchInstProfUpdateWrapper::setSuccessorWeight(
@@ -4479,7 +4509,7 @@ void SwitchInstProfUpdateWrapper::setSuccessorWeight(
Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);
if (Weights) {
- auto &OldW = Weights.getValue()[idx];
+ auto &OldW = (*Weights)[idx];
if (*W != OldW) {
Changed = true;
OldW = *W;