Skip to content

[NFC] Reduce copies created of ConstantRange when getting ConstantRangeAttributes. #90335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/include/llvm/IR/Attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ class Attribute {

/// Return the attribute's value as a ConstantRange. This requires the
/// attribute to be a ConstantRange attribute.
ConstantRange getValueAsConstantRange() const;
const ConstantRange &getValueAsConstantRange() const;

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

/// Returns the value of the range attribute.
ConstantRange getRange() const;
const ConstantRange &getRange() const;

/// The Attribute is converted to a string of equivalent mnemonic. This
/// is, presumably, for writing out the mnemonics for the assembly writer.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/IR/AttributeImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class AttributeImpl : public FoldingSetNode {

Type *getValueAsType() const;

ConstantRange getValueAsConstantRange() const;
const ConstantRange &getValueAsConstantRange() const;

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

ConstantRange getConstantRangeValue() const { return CR; }
const ConstantRange &getConstantRangeValue() const { return CR; }
};

class AttributeBitSet {
Expand Down
8 changes: 4 additions & 4 deletions llvm/lib/IR/Attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -444,7 +444,7 @@ FPClassTest Attribute::getNoFPClass() const {
return static_cast<FPClassTest>(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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -735,7 +735,7 @@ Type *AttributeImpl::getValueAsType() const {
return static_cast<const TypeAttributeImpl *>(this)->getTypeValue();
}

ConstantRange AttributeImpl::getValueAsConstantRange() const {
const ConstantRange &AttributeImpl::getValueAsConstantRange() const {
assert(isConstantRangeAttribute());
return static_cast<const ConstantRangeAttributeImpl *>(this)
->getConstantRangeValue();
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/IR/Verifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,8 @@ void Verifier::verifyParameterAttrs(AttributeSet Attrs, Type *Ty,
"Invalid value for 'nofpclass' test mask", V);
}
if (Attrs.hasAttribute(Attribute::Range)) {
auto CR = Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
const ConstantRange &CR =
Attrs.getAttribute(Attribute::Range).getValueAsConstantRange();
Check(Ty->isIntOrIntVectorTy(CR.getBitWidth()),
"Range bit width must match type bit width!", V);
}
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Transforms/Utils/FunctionComparator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ int FunctionComparator::cmpAttrs(const AttributeList L,
if (LA.getKindAsEnum() != RA.getKindAsEnum())
return cmpNumbers(LA.getKindAsEnum(), RA.getKindAsEnum());

ConstantRange LCR = LA.getRange();
ConstantRange RCR = RA.getRange();
const ConstantRange &LCR = LA.getRange();
const ConstantRange &RCR = RA.getRange();
if (int Res = cmpAPInts(LCR.getLower(), RCR.getLower()))
return Res;
if (int Res = cmpAPInts(LCR.getUpper(), RCR.getUpper()))
Expand Down
Loading