diff options
Diffstat (limited to 'contrib/llvm-project/llvm/lib/IR/Instructions.cpp')
| -rw-r--r-- | contrib/llvm-project/llvm/lib/IR/Instructions.cpp | 193 | 
1 files changed, 98 insertions, 95 deletions
diff --git a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp index 90cb2c26e082..c264277fa53c 100644 --- a/contrib/llvm-project/llvm/lib/IR/Instructions.cpp +++ b/contrib/llvm-project/llvm/lib/IR/Instructions.cpp @@ -38,6 +38,7 @@  #include "llvm/Support/Casting.h"  #include "llvm/Support/ErrorHandling.h"  #include "llvm/Support/MathExtras.h" +#include "llvm/Support/TypeSize.h"  #include <algorithm>  #include <cassert>  #include <cstdint> @@ -45,12 +46,6 @@  using namespace llvm; -static cl::opt<bool> SwitchInstProfUpdateWrapperStrict( -    "switch-inst-prof-update-wrapper-strict", cl::Hidden, -    cl::desc("Assert that prof branch_weights metadata is valid when creating " -             "an instance of SwitchInstProfUpdateWrapper"), -    cl::init(false)); -  //===----------------------------------------------------------------------===//  //                            AllocaInst Class  //===----------------------------------------------------------------------===// @@ -1222,41 +1217,45 @@ AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, const Twine &Name,  AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,                         const Twine &Name, Instruction *InsertBefore) -  : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/0, Name, InsertBefore) {} +    : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertBefore) { +}  AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize,                         const Twine &Name, BasicBlock *InsertAtEnd) -  : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/0, Name, InsertAtEnd) {} +    : AllocaInst(Ty, AddrSpace, ArraySize, /*Align=*/None, Name, InsertAtEnd) {}  AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, -                       unsigned Align, const Twine &Name, +                       MaybeAlign Align, const Twine &Name,                         Instruction *InsertBefore) -  : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca, -                     getAISize(Ty->getContext(), ArraySize), InsertBefore), -    AllocatedType(Ty) { -  setAlignment(Align); +    : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca, +                       getAISize(Ty->getContext(), ArraySize), InsertBefore), +      AllocatedType(Ty) { +  setAlignment(MaybeAlign(Align));    assert(!Ty->isVoidTy() && "Cannot allocate void!");    setName(Name);  }  AllocaInst::AllocaInst(Type *Ty, unsigned AddrSpace, Value *ArraySize, -                       unsigned Align, const Twine &Name, +                       MaybeAlign Align, const Twine &Name,                         BasicBlock *InsertAtEnd) -  : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca, -                     getAISize(Ty->getContext(), ArraySize), InsertAtEnd), +    : UnaryInstruction(PointerType::get(Ty, AddrSpace), Alloca, +                       getAISize(Ty->getContext(), ArraySize), InsertAtEnd),        AllocatedType(Ty) {    setAlignment(Align);    assert(!Ty->isVoidTy() && "Cannot allocate void!");    setName(Name);  } -void AllocaInst::setAlignment(unsigned Align) { -  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); -  assert(Align <= MaximumAlignment && +void AllocaInst::setAlignment(MaybeAlign Align) { +  assert((!Align || *Align <= MaximumAlignment) &&           "Alignment is greater than MaximumAlignment!");    setInstructionSubclassData((getSubclassDataFromInstruction() & ~31) | -                             (Log2_32(Align) + 1)); -  assert(getAlignment() == Align && "Alignment representation error!"); +                             encode(Align)); +  if (Align) +    assert(getAlignment() == Align->value() && +           "Alignment representation error!"); +  else +    assert(getAlignment() == 0 && "Alignment representation error!");  }  bool AllocaInst::isArrayAllocation() const { @@ -1298,36 +1297,36 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name,  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,                     Instruction *InsertBef) -    : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertBef) {} +    : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertBef) {}  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,                     BasicBlock *InsertAE) -    : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/0, InsertAE) {} +    : LoadInst(Ty, Ptr, Name, isVolatile, /*Align=*/None, InsertAE) {}  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, -                   unsigned Align, Instruction *InsertBef) +                   MaybeAlign Align, Instruction *InsertBef)      : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,                 SyncScope::System, InsertBef) {}  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, -                   unsigned Align, BasicBlock *InsertAE) +                   MaybeAlign Align, BasicBlock *InsertAE)      : LoadInst(Ty, Ptr, Name, isVolatile, Align, AtomicOrdering::NotAtomic,                 SyncScope::System, InsertAE) {}  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, -                   unsigned Align, AtomicOrdering Order, -                   SyncScope::ID SSID, Instruction *InsertBef) +                   MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID, +                   Instruction *InsertBef)      : UnaryInstruction(Ty, Load, Ptr, InsertBef) {    assert(Ty == cast<PointerType>(Ptr->getType())->getElementType());    setVolatile(isVolatile); -  setAlignment(Align); +  setAlignment(MaybeAlign(Align));    setAtomic(Order, SSID);    AssertOK();    setName(Name);  }  LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile, -                   unsigned Align, AtomicOrdering Order, SyncScope::ID SSID, +                   MaybeAlign Align, AtomicOrdering Order, SyncScope::ID SSID,                     BasicBlock *InsertAE)      : UnaryInstruction(Ty, Load, Ptr, InsertAE) {    assert(Ty == cast<PointerType>(Ptr->getType())->getElementType()); @@ -1338,13 +1337,12 @@ LoadInst::LoadInst(Type *Ty, Value *Ptr, const Twine &Name, bool isVolatile,    setName(Name);  } -void LoadInst::setAlignment(unsigned Align) { -  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); -  assert(Align <= MaximumAlignment && +void LoadInst::setAlignment(MaybeAlign Align) { +  assert((!Align || *Align <= MaximumAlignment) &&           "Alignment is greater than MaximumAlignment!");    setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) | -                             ((Log2_32(Align)+1)<<1)); -  assert(getAlignment() == Align && "Alignment representation error!"); +                             (encode(Align) << 1)); +  assert(getAlign() == Align && "Alignment representation error!");  }  //===----------------------------------------------------------------------===// @@ -1370,30 +1368,28 @@ StoreInst::StoreInst(Value *val, Value *addr, BasicBlock *InsertAtEnd)  StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,                       Instruction *InsertBefore) -    : StoreInst(val, addr, isVolatile, /*Align=*/0, InsertBefore) {} +    : StoreInst(val, addr, isVolatile, /*Align=*/None, InsertBefore) {}  StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,                       BasicBlock *InsertAtEnd) -    : StoreInst(val, addr, isVolatile, /*Align=*/0, InsertAtEnd) {} +    : StoreInst(val, addr, isVolatile, /*Align=*/None, InsertAtEnd) {} -StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align, +StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,                       Instruction *InsertBefore)      : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,                  SyncScope::System, InsertBefore) {} -StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, unsigned Align, +StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align,                       BasicBlock *InsertAtEnd)      : StoreInst(val, addr, isVolatile, Align, AtomicOrdering::NotAtomic,                  SyncScope::System, InsertAtEnd) {} -StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, -                     unsigned Align, AtomicOrdering Order, -                     SyncScope::ID SSID, +StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align, +                     AtomicOrdering Order, SyncScope::ID SSID,                       Instruction *InsertBefore) -  : Instruction(Type::getVoidTy(val->getContext()), Store, -                OperandTraits<StoreInst>::op_begin(this), -                OperandTraits<StoreInst>::operands(this), -                InsertBefore) { +    : Instruction(Type::getVoidTy(val->getContext()), Store, +                  OperandTraits<StoreInst>::op_begin(this), +                  OperandTraits<StoreInst>::operands(this), InsertBefore) {    Op<0>() = val;    Op<1>() = addr;    setVolatile(isVolatile); @@ -1402,14 +1398,12 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,    AssertOK();  } -StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, -                     unsigned Align, AtomicOrdering Order, -                     SyncScope::ID SSID, +StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile, MaybeAlign Align, +                     AtomicOrdering Order, SyncScope::ID SSID,                       BasicBlock *InsertAtEnd) -  : Instruction(Type::getVoidTy(val->getContext()), Store, -                OperandTraits<StoreInst>::op_begin(this), -                OperandTraits<StoreInst>::operands(this), -                InsertAtEnd) { +    : Instruction(Type::getVoidTy(val->getContext()), Store, +                  OperandTraits<StoreInst>::op_begin(this), +                  OperandTraits<StoreInst>::operands(this), InsertAtEnd) {    Op<0>() = val;    Op<1>() = addr;    setVolatile(isVolatile); @@ -1418,13 +1412,12 @@ StoreInst::StoreInst(Value *val, Value *addr, bool isVolatile,    AssertOK();  } -void StoreInst::setAlignment(unsigned Align) { -  assert((Align & (Align-1)) == 0 && "Alignment is not a power of 2!"); -  assert(Align <= MaximumAlignment && +void StoreInst::setAlignment(MaybeAlign Alignment) { +  assert((!Alignment || *Alignment <= MaximumAlignment) &&           "Alignment is greater than MaximumAlignment!");    setInstructionSubclassData((getSubclassDataFromInstruction() & ~(31 << 1)) | -                             ((Log2_32(Align)+1) << 1)); -  assert(getAlignment() == Align && "Alignment representation error!"); +                             (encode(Alignment) << 1)); +  assert(getAlign() == Alignment && "Alignment representation error!");  }  //===----------------------------------------------------------------------===// @@ -1789,7 +1782,7 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,                                       const Twine &Name,                                       Instruction *InsertBefore)  : Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(), -                cast<VectorType>(Mask->getType())->getNumElements()), +                cast<VectorType>(Mask->getType())->getElementCount()),                ShuffleVector,                OperandTraits<ShuffleVectorInst>::op_begin(this),                OperandTraits<ShuffleVectorInst>::operands(this), @@ -1806,7 +1799,7 @@ ShuffleVectorInst::ShuffleVectorInst(Value *V1, Value *V2, Value *Mask,                                       const Twine &Name,                                       BasicBlock *InsertAtEnd)  : Instruction(VectorType::get(cast<VectorType>(V1->getType())->getElementType(), -                cast<VectorType>(Mask->getType())->getNumElements()), +                cast<VectorType>(Mask->getType())->getElementCount()),                ShuffleVector,                OperandTraits<ShuffleVectorInst>::op_begin(this),                OperandTraits<ShuffleVectorInst>::operands(this), @@ -2047,7 +2040,7 @@ bool ShuffleVectorInst::isExtractSubvectorMask(ArrayRef<int> Mask,      SubIndex = Offset;    } -  if (0 <= SubIndex) { +  if (0 <= SubIndex && SubIndex + (int)Mask.size() <= NumSrcElts) {      Index = SubIndex;      return true;    } @@ -2979,8 +2972,8 @@ bool CastInst::isCastable(Type *SrcTy, Type *DestTy) {        }    // Get the bit sizes, we'll need these -  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr -  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr +  TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr +  TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr    // Run through the possibilities ...    if (DestTy->isIntegerTy()) {               // Casting to integral @@ -3027,7 +3020,7 @@ bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {    if (VectorType *SrcVecTy = dyn_cast<VectorType>(SrcTy)) {      if (VectorType *DestVecTy = dyn_cast<VectorType>(DestTy)) { -      if (SrcVecTy->getNumElements() == DestVecTy->getNumElements()) { +      if (SrcVecTy->getElementCount() == DestVecTy->getElementCount()) {          // An element by element cast. Valid if casting the elements is valid.          SrcTy = SrcVecTy->getElementType();          DestTy = DestVecTy->getElementType(); @@ -3041,12 +3034,12 @@ bool CastInst::isBitCastable(Type *SrcTy, Type *DestTy) {      }    } -  unsigned SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr -  unsigned DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr +  TypeSize SrcBits = SrcTy->getPrimitiveSizeInBits();   // 0 for ptr +  TypeSize DestBits = DestTy->getPrimitiveSizeInBits(); // 0 for ptr    // Could still have vectors of pointers if the number of elements doesn't    // match -  if (SrcBits == 0 || DestBits == 0) +  if (SrcBits.getKnownMinSize() == 0 || DestBits.getKnownMinSize() == 0)      return false;    if (SrcBits != DestBits) @@ -3897,7 +3890,7 @@ SwitchInstProfUpdateWrapper::getProfBranchWeightsMD(const SwitchInst &SI) {  }  MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() { -  assert(State == Changed && "called only if metadata has changed"); +  assert(Changed && "called only if metadata has changed");    if (!Weights)      return nullptr; @@ -3916,17 +3909,12 @@ MDNode *SwitchInstProfUpdateWrapper::buildProfBranchWeightsMD() {  void SwitchInstProfUpdateWrapper::init() {    MDNode *ProfileData = getProfBranchWeightsMD(SI); -  if (!ProfileData) { -    State = Initialized; +  if (!ProfileData)      return; -  }    if (ProfileData->getNumOperands() != SI.getNumSuccessors() + 1) { -    State = Invalid; -    if (SwitchInstProfUpdateWrapperStrict) -      llvm_unreachable("number of prof branch_weights metadata operands does " -                       "not correspond to number of succesors"); -    return; +    llvm_unreachable("number of prof branch_weights metadata operands does " +                     "not correspond to number of succesors");    }    SmallVector<uint32_t, 8> Weights; @@ -3935,7 +3923,6 @@ void SwitchInstProfUpdateWrapper::init() {      uint32_t CW = C->getValue().getZExtValue();      Weights.push_back(CW);    } -  State = Initialized;    this->Weights = std::move(Weights);  } @@ -3944,7 +3931,7 @@ SwitchInstProfUpdateWrapper::removeCase(SwitchInst::CaseIt I) {    if (Weights) {      assert(SI.getNumSuccessors() == Weights->size() &&             "num of prof branch_weights must accord with num of successors"); -    State = Changed; +    Changed = true;      // 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). @@ -3959,15 +3946,12 @@ void SwitchInstProfUpdateWrapper::addCase(      SwitchInstProfUpdateWrapper::CaseWeightOpt W) {    SI.addCase(OnVal, Dest); -  if (State == Invalid) -    return; -    if (!Weights && W && *W) { -    State = Changed; +    Changed = true;      Weights = SmallVector<uint32_t, 8>(SI.getNumSuccessors(), 0);      Weights.getValue()[SI.getNumSuccessors() - 1] = *W;    } else if (Weights) { -    State = Changed; +    Changed = true;      Weights.getValue().push_back(W ? *W : 0);    }    if (Weights) @@ -3978,11 +3962,9 @@ void SwitchInstProfUpdateWrapper::addCase(  SymbolTableList<Instruction>::iterator  SwitchInstProfUpdateWrapper::eraseFromParent() {    // Instruction is erased. Mark as unchanged to not touch it in the destructor. -  if (State != Invalid) { -    State = Initialized; -    if (Weights) -      Weights->resize(0); -  } +  Changed = false; +  if (Weights) +    Weights->resize(0);    return SI.eraseFromParent();  } @@ -3995,7 +3977,7 @@ SwitchInstProfUpdateWrapper::getSuccessorWeight(unsigned idx) {  void SwitchInstProfUpdateWrapper::setSuccessorWeight(      unsigned idx, SwitchInstProfUpdateWrapper::CaseWeightOpt W) { -  if (!W || State == Invalid) +  if (!W)      return;    if (!Weights && *W) @@ -4004,7 +3986,7 @@ void SwitchInstProfUpdateWrapper::setSuccessorWeight(    if (Weights) {      auto &OldW = Weights.getValue()[idx];      if (*W != OldW) { -      State = Changed; +      Changed = true;        OldW = *W;      }    } @@ -4102,6 +4084,22 @@ void IndirectBrInst::removeDestination(unsigned idx) {  }  //===----------------------------------------------------------------------===// +//                            FreezeInst Implementation +//===----------------------------------------------------------------------===// + +FreezeInst::FreezeInst(Value *S, +                       const Twine &Name, Instruction *InsertBefore) +    : UnaryInstruction(S->getType(), Freeze, S, InsertBefore) { +  setName(Name); +} + +FreezeInst::FreezeInst(Value *S, +                       const Twine &Name, BasicBlock *InsertAtEnd) +    : UnaryInstruction(S->getType(), Freeze, S, InsertAtEnd) { +  setName(Name); +} + +//===----------------------------------------------------------------------===//  //                           cloneImpl() implementations  //===----------------------------------------------------------------------===// @@ -4137,9 +4135,9 @@ InsertValueInst *InsertValueInst::cloneImpl() const {  }  AllocaInst *AllocaInst::cloneImpl() const { -  AllocaInst *Result = new AllocaInst(getAllocatedType(), -                                      getType()->getAddressSpace(), -                                      (Value *)getOperand(0), getAlignment()); +  AllocaInst *Result = +      new AllocaInst(getAllocatedType(), getType()->getAddressSpace(), +                     (Value *)getOperand(0), MaybeAlign(getAlignment()));    Result->setUsedWithInAlloca(isUsedWithInAlloca());    Result->setSwiftError(isSwiftError());    return Result; @@ -4147,13 +4145,14 @@ AllocaInst *AllocaInst::cloneImpl() const {  LoadInst *LoadInst::cloneImpl() const {    return new LoadInst(getType(), getOperand(0), Twine(), isVolatile(), -                      getAlignment(), getOrdering(), getSyncScopeID()); +                      MaybeAlign(getAlignment()), getOrdering(), +                      getSyncScopeID());  }  StoreInst *StoreInst::cloneImpl() const {    return new StoreInst(getOperand(0), getOperand(1), isVolatile(), -                       getAlignment(), getOrdering(), getSyncScopeID()); - +                       MaybeAlign(getAlignment()), getOrdering(), +                       getSyncScopeID());  }  AtomicCmpXchgInst *AtomicCmpXchgInst::cloneImpl() const { @@ -4316,3 +4315,7 @@ UnreachableInst *UnreachableInst::cloneImpl() const {    LLVMContext &Context = getContext();    return new UnreachableInst(Context);  } + +FreezeInst *FreezeInst::cloneImpl() const { +  return new FreezeInst(getOperand(0)); +}  | 
