forked from OSchip/llvm-project
[NFC] Replace some attribute methods that use confusing indexes
This commit is contained in:
parent
10a126325d
commit
44a3241f10
|
@ -657,16 +657,13 @@ public:
|
|||
|
||||
/// \brief Add the dereferenceable attribute to the attribute set at the given
|
||||
/// index. Returns a new list because attribute lists are immutable.
|
||||
LLVM_NODISCARD AttributeList addDereferenceableAttr(LLVMContext &C,
|
||||
unsigned Index,
|
||||
LLVM_NODISCARD AttributeList addDereferenceableRetAttr(LLVMContext &C,
|
||||
uint64_t Bytes) const;
|
||||
|
||||
/// \brief Add the dereferenceable attribute to the attribute set at the given
|
||||
/// arg index. Returns a new list because attribute lists are immutable.
|
||||
LLVM_NODISCARD AttributeList addDereferenceableParamAttr(
|
||||
LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const {
|
||||
return addDereferenceableAttr(C, ArgNo + FirstArgIndex, Bytes);
|
||||
}
|
||||
LLVMContext &C, unsigned ArgNo, uint64_t Bytes) const;
|
||||
|
||||
/// Add the dereferenceable_or_null attribute to the attribute set at
|
||||
/// the given index. Returns a new list because attribute lists are immutable.
|
||||
|
@ -827,24 +824,20 @@ public:
|
|||
/// Get the stack alignment.
|
||||
MaybeAlign getStackAlignment(unsigned Index) const;
|
||||
|
||||
/// Get the number of dereferenceable bytes (or zero if unknown).
|
||||
uint64_t getDereferenceableBytes(unsigned Index) const;
|
||||
/// Get the number of dereferenceable bytes (or zero if unknown) of the return
|
||||
/// value.
|
||||
uint64_t getRetDereferenceableBytes() const;
|
||||
|
||||
/// Get the number of dereferenceable bytes (or zero if unknown) of an
|
||||
/// Get the number of dereferenceable bytes (or zero if unknown) of an arg.
|
||||
uint64_t getParamDereferenceableBytes(unsigned Index) const;
|
||||
|
||||
/// Get the number of dereferenceable_or_null bytes (or zero if unknown) of
|
||||
/// the return value.
|
||||
uint64_t getRetDereferenceableOrNullBytes() const;
|
||||
|
||||
/// Get the number of dereferenceable_or_null bytes (or zero if unknown) of an
|
||||
/// arg.
|
||||
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
||||
return getDereferenceableBytes(ArgNo + FirstArgIndex);
|
||||
}
|
||||
|
||||
/// Get the number of dereferenceable_or_null bytes (or zero if
|
||||
/// unknown).
|
||||
uint64_t getDereferenceableOrNullBytes(unsigned Index) const;
|
||||
|
||||
/// Get the number of dereferenceable_or_null bytes (or zero if
|
||||
/// unknown) of an arg.
|
||||
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
|
||||
return getDereferenceableOrNullBytes(ArgNo + FirstArgIndex);
|
||||
}
|
||||
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const;
|
||||
|
||||
/// Return the attributes at the index as a string.
|
||||
std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
|
||||
|
|
|
@ -476,26 +476,12 @@ public:
|
|||
return AttributeSets.getParamByRefType(ArgNo);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable bytes for a call or
|
||||
/// parameter (0=unknown).
|
||||
/// @param i AttributeList index, referring to a return value or argument.
|
||||
uint64_t getDereferenceableBytes(unsigned i) const {
|
||||
return AttributeSets.getDereferenceableBytes(i);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable bytes for a parameter.
|
||||
/// @param ArgNo Index of an argument, with 0 being the first function arg.
|
||||
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
||||
return AttributeSets.getParamDereferenceableBytes(ArgNo);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable_or_null bytes for a call or
|
||||
/// parameter (0=unknown).
|
||||
/// @param i AttributeList index, referring to a return value or argument.
|
||||
uint64_t getDereferenceableOrNullBytes(unsigned i) const {
|
||||
return AttributeSets.getDereferenceableOrNullBytes(i);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable_or_null bytes for a
|
||||
/// parameter.
|
||||
/// @param ArgNo AttributeList ArgNo, referring to an argument.
|
||||
|
|
|
@ -1601,9 +1601,16 @@ public:
|
|||
}
|
||||
|
||||
/// adds the dereferenceable attribute to the list of attributes.
|
||||
void addDereferenceableAttr(unsigned i, uint64_t Bytes) {
|
||||
void addDereferenceableParamAttr(unsigned i, uint64_t Bytes) {
|
||||
AttributeList PAL = getAttributes();
|
||||
PAL = PAL.addDereferenceableAttr(getContext(), i, Bytes);
|
||||
PAL = PAL.addDereferenceableParamAttr(getContext(), i, Bytes);
|
||||
setAttributes(PAL);
|
||||
}
|
||||
|
||||
/// adds the dereferenceable attribute to the list of attributes.
|
||||
void addDereferenceableRetAttr(uint64_t Bytes) {
|
||||
AttributeList PAL = getAttributes();
|
||||
PAL = PAL.addDereferenceableRetAttr(getContext(), Bytes);
|
||||
setAttributes(PAL);
|
||||
}
|
||||
|
||||
|
@ -1795,14 +1802,26 @@ public:
|
|||
|
||||
/// Extract the number of dereferenceable bytes for a call or
|
||||
/// parameter (0=unknown).
|
||||
uint64_t getDereferenceableBytes(unsigned i) const {
|
||||
return Attrs.getDereferenceableBytes(i);
|
||||
uint64_t getRetDereferenceableBytes() const {
|
||||
return Attrs.getRetDereferenceableBytes();
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable_or_null bytes for a call or
|
||||
/// Extract the number of dereferenceable bytes for a call or
|
||||
/// parameter (0=unknown).
|
||||
uint64_t getDereferenceableOrNullBytes(unsigned i) const {
|
||||
return Attrs.getDereferenceableOrNullBytes(i);
|
||||
uint64_t getParamDereferenceableBytes(unsigned i) const {
|
||||
return Attrs.getParamDereferenceableBytes(i);
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable_or_null bytes for a call
|
||||
/// (0=unknown).
|
||||
uint64_t getRetDereferenceableOrNullBytes() const {
|
||||
return Attrs.getRetDereferenceableOrNullBytes();
|
||||
}
|
||||
|
||||
/// Extract the number of dereferenceable_or_null bytes for a
|
||||
/// parameter (0=unknown).
|
||||
uint64_t getParamDereferenceableOrNullBytes(unsigned i) const {
|
||||
return Attrs.getParamDereferenceableOrNullBytes(i);
|
||||
}
|
||||
|
||||
/// Return true if the return value is known to be not null.
|
||||
|
|
|
@ -1335,12 +1335,19 @@ AttributeList AttributeList::removeAttributes(LLVMContext &C,
|
|||
return getImpl(C, AttrSets);
|
||||
}
|
||||
|
||||
AttributeList AttributeList::addDereferenceableAttr(LLVMContext &C,
|
||||
AttributeList AttributeList::addDereferenceableRetAttr(LLVMContext &C,
|
||||
uint64_t Bytes) const {
|
||||
AttrBuilder B;
|
||||
B.addDereferenceableAttr(Bytes);
|
||||
return addRetAttributes(C, B);
|
||||
}
|
||||
|
||||
AttributeList AttributeList::addDereferenceableParamAttr(LLVMContext &C,
|
||||
unsigned Index,
|
||||
uint64_t Bytes) const {
|
||||
AttrBuilder B;
|
||||
B.addDereferenceableAttr(Bytes);
|
||||
return addAttributes(C, Index, B);
|
||||
return addParamAttributes(C, Index, B);
|
||||
}
|
||||
|
||||
AttributeList
|
||||
|
@ -1459,12 +1466,21 @@ MaybeAlign AttributeList::getStackAlignment(unsigned Index) const {
|
|||
return getAttributes(Index).getStackAlignment();
|
||||
}
|
||||
|
||||
uint64_t AttributeList::getDereferenceableBytes(unsigned Index) const {
|
||||
return getAttributes(Index).getDereferenceableBytes();
|
||||
uint64_t AttributeList::getRetDereferenceableBytes() const {
|
||||
return getRetAttrs().getDereferenceableBytes();
|
||||
}
|
||||
|
||||
uint64_t AttributeList::getDereferenceableOrNullBytes(unsigned Index) const {
|
||||
return getAttributes(Index).getDereferenceableOrNullBytes();
|
||||
uint64_t AttributeList::getParamDereferenceableBytes(unsigned Index) const {
|
||||
return getParamAttrs(Index).getDereferenceableBytes();
|
||||
}
|
||||
|
||||
uint64_t AttributeList::getRetDereferenceableOrNullBytes() const {
|
||||
return getRetAttrs().getDereferenceableOrNullBytes();
|
||||
}
|
||||
|
||||
uint64_t
|
||||
AttributeList::getParamDereferenceableOrNullBytes(unsigned Index) const {
|
||||
return getParamAttrs(Index).getDereferenceableOrNullBytes();
|
||||
}
|
||||
|
||||
std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
|
||||
|
|
|
@ -318,9 +318,8 @@ bool CallBase::isReturnNonNull() const {
|
|||
if (hasRetAttr(Attribute::NonNull))
|
||||
return true;
|
||||
|
||||
if (getDereferenceableBytes(AttributeList::ReturnIndex) > 0 &&
|
||||
!NullPointerIsDefined(getCaller(),
|
||||
getType()->getPointerAddressSpace()))
|
||||
if (getRetDereferenceableBytes() > 0 &&
|
||||
!NullPointerIsDefined(getCaller(), getType()->getPointerAddressSpace()))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
|
|
@ -852,10 +852,9 @@ uint64_t Value::getPointerDereferenceableBytes(const DataLayout &DL,
|
|||
CanBeNull = true;
|
||||
}
|
||||
} else if (const auto *Call = dyn_cast<CallBase>(this)) {
|
||||
DerefBytes = Call->getDereferenceableBytes(AttributeList::ReturnIndex);
|
||||
DerefBytes = Call->getRetDereferenceableBytes();
|
||||
if (DerefBytes == 0) {
|
||||
DerefBytes =
|
||||
Call->getDereferenceableOrNullBytes(AttributeList::ReturnIndex);
|
||||
DerefBytes = Call->getRetDereferenceableOrNullBytes();
|
||||
CanBeNull = true;
|
||||
}
|
||||
} else if (const LoadInst *LI = dyn_cast<LoadInst>(this)) {
|
||||
|
|
|
@ -260,7 +260,7 @@ AMDGPUPromoteAllocaImpl::getLocalSizeYZ(IRBuilder<> &Builder) {
|
|||
DispatchPtr->addRetAttr(Attribute::NonNull);
|
||||
|
||||
// Size of the dispatch packet struct.
|
||||
DispatchPtr->addDereferenceableAttr(AttributeList::ReturnIndex, 64);
|
||||
DispatchPtr->addDereferenceableRetAttr(64);
|
||||
|
||||
Type *I32Ty = Type::getInt32Ty(Mod->getContext());
|
||||
Value *CastDispatchPtr = Builder.CreateBitCast(
|
||||
|
@ -1065,9 +1065,9 @@ bool AMDGPUPromoteAllocaImpl::handleAlloca(AllocaInst &I, bool SufficientLDS) {
|
|||
MI->getRawSource(), MI->getSourceAlign(),
|
||||
MI->getLength(), MI->isVolatile());
|
||||
|
||||
for (unsigned I = 1; I != 3; ++I) {
|
||||
if (uint64_t Bytes = Intr->getDereferenceableBytes(I)) {
|
||||
B->addDereferenceableAttr(I, Bytes);
|
||||
for (unsigned I = 0; I != 2; ++I) {
|
||||
if (uint64_t Bytes = Intr->getParamDereferenceableBytes(I)) {
|
||||
B->addDereferenceableParamAttr(I, Bytes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2655,14 +2655,15 @@ template <typename AttrHolder>
|
|||
static void RemoveNonValidAttrAtIndex(LLVMContext &Ctx, AttrHolder &AH,
|
||||
unsigned Index) {
|
||||
AttrBuilder R;
|
||||
if (AH.getDereferenceableBytes(Index))
|
||||
AttributeSet AS = AH.getAttributes().getAttributes(Index);
|
||||
if (AS.getDereferenceableBytes())
|
||||
R.addAttribute(Attribute::get(Ctx, Attribute::Dereferenceable,
|
||||
AH.getDereferenceableBytes(Index)));
|
||||
if (AH.getDereferenceableOrNullBytes(Index))
|
||||
AS.getDereferenceableBytes()));
|
||||
if (AS.getDereferenceableOrNullBytes())
|
||||
R.addAttribute(Attribute::get(Ctx, Attribute::DereferenceableOrNull,
|
||||
AH.getDereferenceableOrNullBytes(Index)));
|
||||
AS.getDereferenceableOrNullBytes()));
|
||||
for (auto Attr : ParamAttrsToStrip)
|
||||
if (AH.getAttributes().hasAttribute(Index, Attr))
|
||||
if (AS.hasAttribute(Attr))
|
||||
R.addAttribute(Attr);
|
||||
|
||||
if (!R.empty())
|
||||
|
|
|
@ -142,12 +142,10 @@ static void annotateDereferenceableBytes(CallInst *CI,
|
|||
unsigned AS = CI->getArgOperand(ArgNo)->getType()->getPointerAddressSpace();
|
||||
if (!llvm::NullPointerIsDefined(F, AS) ||
|
||||
CI->paramHasAttr(ArgNo, Attribute::NonNull))
|
||||
DerefBytes = std::max(CI->getDereferenceableOrNullBytes(
|
||||
ArgNo + AttributeList::FirstArgIndex),
|
||||
DerefBytes = std::max(CI->getParamDereferenceableOrNullBytes(ArgNo),
|
||||
DereferenceableBytes);
|
||||
|
||||
if (CI->getDereferenceableBytes(ArgNo + AttributeList::FirstArgIndex) <
|
||||
DerefBytes) {
|
||||
if (CI->getParamDereferenceableBytes(ArgNo) < DerefBytes) {
|
||||
CI->removeParamAttr(ArgNo, Attribute::Dereferenceable);
|
||||
if (!llvm::NullPointerIsDefined(F, AS) ||
|
||||
CI->paramHasAttr(ArgNo, Attribute::NonNull))
|
||||
|
|
Loading…
Reference in New Issue