/// dereferenceable_or_null attribute.
uint64_t getDereferenceableOrNullBytes() const;
- /// Returns the argument numbers for the allocsize attribute (or pair(0, 0)
- /// if not known).
+ /// Returns the argument numbers for the allocsize attribute.
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
/// Returns the minimum value for the vscale_range attribute.
Type *getPreallocatedType() const;
Type *getInAllocaType() const;
Type *getElementType() const;
- std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
+ Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const;
unsigned getVScaleRangeMin() const;
Optional<unsigned> getVScaleRangeMax() const;
UWTableKind getUWTableKind() const;
/// Retrieve the inalloca type.
Type *getInAllocaType() const { return getTypeAttr(Attribute::InAlloca); }
- /// Retrieve the allocsize args, if the allocsize attribute exists. If it
- /// doesn't exist, pair(0, 0) is returned.
- std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
+ /// Retrieve the allocsize args, or None if the attribute does not exist.
+ Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const;
/// Add integer attribute with raw value (packed/encoded if necessary).
AttrBuilder &addRawIntAttr(Attribute::AttrKind Kind, uint64_t Value);
MaybeAlign getStackAlignment() const;
uint64_t getDereferenceableBytes() const;
uint64_t getDereferenceableOrNullBytes() const;
- std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
+ Optional<std::pair<unsigned, Optional<unsigned>>> getAllocSizeArgs() const;
unsigned getVScaleRangeMin() const;
Optional<unsigned> getVScaleRangeMax() const;
UWTableKind getUWTableKind() const;
return SetNode ? SetNode->getAttributeType(Attribute::ElementType) : nullptr;
}
-std::pair<unsigned, Optional<unsigned>> AttributeSet::getAllocSizeArgs() const {
- return SetNode ? SetNode->getAllocSizeArgs()
- : std::pair<unsigned, Optional<unsigned>>(0, 0);
+Optional<std::pair<unsigned, Optional<unsigned>>>
+AttributeSet::getAllocSizeArgs() const {
+ if (SetNode)
+ return SetNode->getAllocSizeArgs();
+ return None;
}
unsigned AttributeSet::getVScaleRangeMin() const {
return 0;
}
-std::pair<unsigned, Optional<unsigned>>
+Optional<std::pair<unsigned, Optional<unsigned>>>
AttributeSetNode::getAllocSizeArgs() const {
if (auto A = findEnumAttribute(Attribute::AllocSize))
return A->getAllocSizeArgs();
- return std::make_pair(0, 0);
+ return None;
}
unsigned AttributeSetNode::getVScaleRangeMin() const {
return addAttribute(Attribute::get(Ctx, Kind, Value));
}
-std::pair<unsigned, Optional<unsigned>> AttrBuilder::getAllocSizeArgs() const {
- return unpackAllocSizeArgs(getRawIntAttr(Attribute::AllocSize).value_or(0));
+Optional<std::pair<unsigned, Optional<unsigned>>>
+AttrBuilder::getAllocSizeArgs() const {
+ Attribute A = getAttribute(Attribute::AllocSize);
+ if (A.isValid())
+ return A.getAllocSizeArgs();
+ return None;
}
AttrBuilder &AttrBuilder::addAlignmentAttr(MaybeAlign Align) {
"Attribute 'jumptable' requires 'unnamed_addr'", V);
}
- if (Attrs.hasFnAttr(Attribute::AllocSize)) {
- std::pair<unsigned, Optional<unsigned>> Args =
- Attrs.getFnAttrs().getAllocSizeArgs();
-
+ if (auto Args = Attrs.getFnAttrs().getAllocSizeArgs()) {
auto CheckParam = [&](StringRef Name, unsigned ParamNo) {
if (ParamNo >= FT->getNumParams()) {
CheckFailed("'allocsize' " + Name + " argument is out of bounds", V);
return true;
};
- if (!CheckParam("element size", Args.first))
+ if (!CheckParam("element size", Args->first))
return;
- if (Args.second && !CheckParam("number of elements", *Args.second))
+ if (Args->second && !CheckParam("number of elements", *Args->second))
return;
}
ArgAttributes.push_back(InvokeAL.getParamAttrs(I));
AttrBuilder FnAttrs(CI->getContext(), InvokeAL.getFnAttrs());
- if (FnAttrs.contains(Attribute::AllocSize)) {
+ if (auto Args = FnAttrs.getAllocSizeArgs()) {
// The allocsize attribute (if any) referes to parameters by index and needs
// to be adjusted.
- unsigned SizeArg;
- Optional<unsigned> NEltArg;
- std::tie(SizeArg, NEltArg) = FnAttrs.getAllocSizeArgs();
+ auto [SizeArg, NEltArg] = *Args;
SizeArg += 1;
if (NEltArg)
NEltArg = NEltArg.value() + 1;