diff options
author | Momchil Velikov <momchil.velikov@arm.com> | 2022-01-31 10:48:14 +0000 |
---|---|---|
committer | Momchil Velikov <momchil.velikov@arm.com> | 2022-01-31 12:13:50 +0000 |
commit | 5a90b1e4e5ddd59d78a5daa8972df8db35db1a67 (patch) | |
tree | c95dcab3d7ef8422c71206db8e30902c5526aa04 | |
parent | 2d1390efbe610ff15a8cfc6d40f6e8eaa74355b6 (diff) |
Save some `std::string` allocations/deallocations when formatting attributes (NFC)
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D118451
-rw-r--r-- | llvm/lib/IR/Attributes.cpp | 47 |
1 files changed, 14 insertions, 33 deletions
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp index c92bacaee36d..1d56ef01c4e0 100644 --- a/llvm/lib/IR/Attributes.cpp +++ b/llvm/lib/IR/Attributes.cpp @@ -390,26 +390,15 @@ std::string Attribute::getAsString(bool InAttrGrp) const { // align=4 // alignstack=8 // - if (hasAttribute(Attribute::Alignment)) { - std::string Result; - Result += "align"; - Result += (InAttrGrp) ? "=" : " "; - Result += utostr(getValueAsInt()); - return Result; - } + if (hasAttribute(Attribute::Alignment)) + return (InAttrGrp ? "align=" + Twine(getValueAsInt()) + : "align " + Twine(getValueAsInt())) + .str(); auto AttrWithBytesToString = [&](const char *Name) { - std::string Result; - Result += Name; - if (InAttrGrp) { - Result += "="; - Result += utostr(getValueAsInt()); - } else { - Result += "("; - Result += utostr(getValueAsInt()); - Result += ")"; - } - return Result; + return (InAttrGrp ? Name + ("=" + Twine(getValueAsInt())) + : Name + ("(" + Twine(getValueAsInt())) + ")") + .str(); }; if (hasAttribute(Attribute::StackAlignment)) @@ -426,26 +415,18 @@ std::string Attribute::getAsString(bool InAttrGrp) const { Optional<unsigned> NumElems; std::tie(ElemSize, NumElems) = getAllocSizeArgs(); - std::string Result = "allocsize("; - Result += utostr(ElemSize); - if (NumElems.hasValue()) { - Result += ','; - Result += utostr(*NumElems); - } - Result += ')'; - return Result; + return (NumElems + ? "allocsize(" + Twine(ElemSize) + "," + Twine(*NumElems) + ")" + : "allocsize(" + Twine(ElemSize) + ")") + .str(); } if (hasAttribute(Attribute::VScaleRange)) { unsigned MinValue = getVScaleRangeMin(); Optional<unsigned> MaxValue = getVScaleRangeMax(); - - std::string Result = "vscale_range("; - Result += utostr(MinValue); - Result += ','; - Result += utostr(MaxValue.getValueOr(0)); - Result += ')'; - return Result; + return ("vscale_range(" + Twine(MinValue) + "," + + Twine(MaxValue.getValueOr(0)) + ")") + .str(); } // Convert target-dependent attributes to strings of the form: |