From 3d65bd935a91439c483c56a966edc283a2b1130d Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Thu, 2 May 2024 03:48:23 +0200 Subject: [NFC] Reduce copies created of ConstantRange when getting ConstantRangeAttributes (#90335) Think that it can be good to reduce the number of copies created when working with ConstantRangeAttributes. --- llvm/lib/IR/Attributes.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'llvm/lib/IR/Attributes.cpp') diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index c6e511b..c8d6bdd 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -360,7 +360,7 @@ Type *Attribute::getValueAsType() const { return pImpl->getValueAsType(); } -ConstantRange Attribute::getValueAsConstantRange() const { +const ConstantRange &Attribute::getValueAsConstantRange() const { assert(isConstantRangeAttribute() && "Invalid attribute type to get the value as a ConstantRange!"); return pImpl->getValueAsConstantRange(); @@ -444,7 +444,7 @@ FPClassTest Attribute::getNoFPClass() const { return static_cast(pImpl->getValueAsInt()); } -ConstantRange Attribute::getRange() const { +const ConstantRange &Attribute::getRange() const { assert(hasAttribute(Attribute::Range) && "Trying to get range args from non-range attribute"); return pImpl->getValueAsConstantRange(); @@ -607,7 +607,7 @@ std::string Attribute::getAsString(bool InAttrGrp) const { if (hasAttribute(Attribute::Range)) { std::string Result; raw_string_ostream OS(Result); - ConstantRange CR = getValueAsConstantRange(); + const ConstantRange &CR = getValueAsConstantRange(); OS << "range("; OS << "i" << CR.getBitWidth() << " "; OS << CR.getLower() << ", " << CR.getUpper(); @@ -735,7 +735,7 @@ Type *AttributeImpl::getValueAsType() const { return static_cast(this)->getTypeValue(); } -ConstantRange AttributeImpl::getValueAsConstantRange() const { +const ConstantRange &AttributeImpl::getValueAsConstantRange() const { assert(isConstantRangeAttribute()); return static_cast(this) ->getConstantRangeValue(); -- cgit v1.1