Skip to content

Commit 3d65bd9

Browse files
authored
[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.
1 parent ad7ee90 commit 3d65bd9

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

llvm/include/llvm/IR/Attributes.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ class Attribute {
224224

225225
/// Return the attribute's value as a ConstantRange. This requires the
226226
/// attribute to be a ConstantRange attribute.
227-
ConstantRange getValueAsConstantRange() const;
227+
const ConstantRange &getValueAsConstantRange() const;
228228

229229
/// Returns the alignment field of an attribute as a byte alignment
230230
/// value.
@@ -265,7 +265,7 @@ class Attribute {
265265
FPClassTest getNoFPClass() const;
266266

267267
/// Returns the value of the range attribute.
268-
ConstantRange getRange() const;
268+
const ConstantRange &getRange() const;
269269

270270
/// The Attribute is converted to a string of equivalent mnemonic. This
271271
/// is, presumably, for writing out the mnemonics for the assembly writer.

llvm/lib/IR/AttributeImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class AttributeImpl : public FoldingSetNode {
7777

7878
Type *getValueAsType() const;
7979

80-
ConstantRange getValueAsConstantRange() const;
80+
const ConstantRange &getValueAsConstantRange() const;
8181

8282
/// Used when sorting the attributes.
8383
bool operator<(const AttributeImpl &AI) const;
@@ -219,7 +219,7 @@ class ConstantRangeAttributeImpl : public EnumAttributeImpl {
219219
ConstantRangeAttributeImpl(Attribute::AttrKind Kind, const ConstantRange &CR)
220220
: EnumAttributeImpl(ConstantRangeAttrEntry, Kind), CR(CR) {}
221221

222-
ConstantRange getConstantRangeValue() const { return CR; }
222+
const ConstantRange &getConstantRangeValue() const { return CR; }
223223
};
224224

225225
class AttributeBitSet {

llvm/lib/IR/Attributes.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,7 @@ Type *Attribute::getValueAsType() const {
360360
return pImpl->getValueAsType();
361361
}
362362

363-
ConstantRange Attribute::getValueAsConstantRange() const {
363+
const ConstantRange &Attribute::getValueAsConstantRange() const {
364364
assert(isConstantRangeAttribute() &&
365365
"Invalid attribute type to get the value as a ConstantRange!");
366366
return pImpl->getValueAsConstantRange();
@@ -444,7 +444,7 @@ FPClassTest Attribute::getNoFPClass() const {
444444
return static_cast<FPClassTest>(pImpl->getValueAsInt());
445445
}
446446

447-
ConstantRange Attribute::getRange() const {
447+
const ConstantRange &Attribute::getRange() const {
448448
assert(hasAttribute(Attribute::Range) &&
449449
"Trying to get range args from non-range attribute");
450450
return pImpl->getValueAsConstantRange();
@@ -607,7 +607,7 @@ std::string Attribute::getAsString(bool InAttrGrp) const {
607607
if (hasAttribute(Attribute::Range)) {
608608
std::string Result;
609609
raw_string_ostream OS(Result);
610-
ConstantRange CR = getValueAsConstantRange();
610+
const ConstantRange &CR = getValueAsConstantRange();
611611
OS << "range(";
612612
OS << "i" << CR.getBitWidth() << " ";
613613
OS << CR.getLower() << ", " << CR.getUpper();
@@ -735,7 +735,7 @@ Type *AttributeImpl::getValueAsType() const {
735735
return static_cast<const TypeAttributeImpl *>(this)->getTypeValue();
736736
}
737737

738-
ConstantRange AttributeImpl::getValueAsConstantRange() const {
738+
const ConstantRange &AttributeImpl::getValueAsConstantRange() const {
739739
assert(isConstantRangeAttribute());
740740
return static_cast<const ConstantRangeAttributeImpl *>(this)
741741
->getConstantRangeValue();

llvm/lib/IR/Verifier.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,8 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
20652065
"Invalid value for 'nofpclass' test mask", V);
20662066
}
20672067
if (Attrs.hasAttribute(Attribute::Range)) {
2068-
auto CR = Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
2068+
const ConstantRange &CR =
2069+
Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
20692070
Check(Ty->isIntOrIntVectorTy(CR.getBitWidth()),
20702071
"Range bit width must match type bit width!", V);
20712072
}

llvm/lib/Transforms/Utils/FunctionComparator.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,8 @@ int FunctionComparator::cmpAttrs(const AttributeList L,
148148
if (LA.getKindAsEnum() != RA.getKindAsEnum())
149149
return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());
150150

151-
ConstantRange LCR = LA.getRange();
152-
ConstantRange RCR = RA.getRange();
151+
const ConstantRange &LCR = LA.getRange();
152+
const ConstantRange &RCR = RA.getRange();
153153
if (int Res = cmpAPInts(LCR.getLower(), RCR.getLower()))
154154
return Res;
155155
if (int Res = cmpAPInts(LCR.getUpper(), RCR.getUpper()))

0 commit comments

Comments
 (0)