[llvm] 44a3241 - [NFC] Replace some attribute methods that use confusing indexes
Arthur Eubanks via llvm-commits
llvm-commits at lists.llvm.org
Thu Aug 19 14:10:39 PDT 2021
Author: Arthur Eubanks
Date: 2021-08-19T14:10:26-07:00
New Revision: 44a3241f10558ce86aac7f3b3c87da9f5abf3189
URL: https://github.com/llvm/llvm-project/commit/44a3241f10558ce86aac7f3b3c87da9f5abf3189
DIFF: https://github.com/llvm/llvm-project/commit/44a3241f10558ce86aac7f3b3c87da9f5abf3189.diff
LOG: [NFC] Replace some attribute methods that use confusing indexes
Added:
Modified:
llvm/include/llvm/IR/Attributes.h
llvm/include/llvm/IR/Function.h
llvm/include/llvm/IR/InstrTypes.h
llvm/lib/IR/Attributes.cpp
llvm/lib/IR/Instructions.cpp
llvm/lib/IR/Value.cpp
llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Attributes.h b/llvm/include/llvm/IR/Attributes.h
index 36dc563041e1f..97f0985839d7d 100644
--- a/llvm/include/llvm/IR/Attributes.h
+++ b/llvm/include/llvm/IR/Attributes.h
@@ -657,16 +657,13 @@ class AttributeList {
/// \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,
- uint64_t Bytes) const;
+ 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 @@ class AttributeList {
/// 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
- /// arg.
- uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
- return getDereferenceableBytes(ArgNo + FirstArgIndex);
- }
+ /// 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).
- uint64_t getDereferenceableOrNullBytes(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 getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
- return getDereferenceableOrNullBytes(ArgNo + FirstArgIndex);
- }
+ /// Get the number of dereferenceable_or_null bytes (or zero if unknown) of an
+ /// arg.
+ uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const;
/// Return the attributes at the index as a string.
std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
diff --git a/llvm/include/llvm/IR/Function.h b/llvm/include/llvm/IR/Function.h
index c0318861c5a72..98dff3c684e63 100644
--- a/llvm/include/llvm/IR/Function.h
+++ b/llvm/include/llvm/IR/Function.h
@@ -476,26 +476,12 @@ class Function : public GlobalObject, public ilist_node<Function> {
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.
diff --git a/llvm/include/llvm/IR/InstrTypes.h b/llvm/include/llvm/IR/InstrTypes.h
index 55ab5bce20c72..ed4fa878b2b1f 100644
--- a/llvm/include/llvm/IR/InstrTypes.h
+++ b/llvm/include/llvm/IR/InstrTypes.h
@@ -1601,9 +1601,16 @@ class CallBase : public Instruction {
}
/// 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 @@ class CallBase : public Instruction {
/// 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 bytes for a call or
+ /// parameter (0=unknown).
+ 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 call or
+ /// Extract the number of dereferenceable_or_null bytes for a
/// parameter (0=unknown).
- uint64_t getDereferenceableOrNullBytes(unsigned i) const {
- return Attrs.getDereferenceableOrNullBytes(i);
+ uint64_t getParamDereferenceableOrNullBytes(unsigned i) const {
+ return Attrs.getParamDereferenceableOrNullBytes(i);
}
/// Return true if the return value is known to be not null.
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 0bb6dbe48ef37..d8765ccbd6b76 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1335,12 +1335,19 @@ AttributeList AttributeList::removeAttributes(LLVMContext &C,
return getImpl(C, AttrSets);
}
-AttributeList AttributeList::addDereferenceableAttr(LLVMContext &C,
- unsigned Index,
- uint64_t Bytes) const {
+AttributeList AttributeList::addDereferenceableRetAttr(LLVMContext &C,
+ uint64_t Bytes) const {
AttrBuilder B;
B.addDereferenceableAttr(Bytes);
- return addAttributes(C, Index, B);
+ return addRetAttributes(C, B);
+}
+
+AttributeList AttributeList::addDereferenceableParamAttr(LLVMContext &C,
+ unsigned Index,
+ uint64_t Bytes) const {
+ AttrBuilder B;
+ B.addDereferenceableAttr(Bytes);
+ 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::getParamDereferenceableBytes(unsigned Index) const {
+ return getParamAttrs(Index).getDereferenceableBytes();
+}
+
+uint64_t AttributeList::getRetDereferenceableOrNullBytes() const {
+ return getRetAttrs().getDereferenceableOrNullBytes();
}
-uint64_t AttributeList::getDereferenceableOrNullBytes(unsigned Index) const {
- return getAttributes(Index).getDereferenceableOrNullBytes();
+uint64_t
+AttributeList::getParamDereferenceableOrNullBytes(unsigned Index) const {
+ return getParamAttrs(Index).getDereferenceableOrNullBytes();
}
std::string AttributeList::getAsString(unsigned Index, bool InAttrGrp) const {
diff --git a/llvm/lib/IR/Instructions.cpp b/llvm/lib/IR/Instructions.cpp
index 652a87d929ab2..16507f5bcdef2 100644
--- a/llvm/lib/IR/Instructions.cpp
+++ b/llvm/lib/IR/Instructions.cpp
@@ -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;
diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
index 1c595651b3d72..da67da1ac6c59 100644
--- a/llvm/lib/IR/Value.cpp
+++ b/llvm/lib/IR/Value.cpp
@@ -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)) {
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
index f8af9dbe73546..e483d286b1284 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPromoteAlloca.cpp
@@ -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);
}
}
diff --git a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
index 76b088cb5519f..f0b85c154d11c 100644
--- a/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
+++ b/llvm/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
@@ -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())
diff --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 1e03c8dbd0371..d8f0d08c275ab 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -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))
More information about the llvm-commits
mailing list