[llvm] 6dcd9f5 - [Attributes] Merge calls to getFnAttribute/hasFnAttribute using Attribute::isValid. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sat Aug 29 00:24:02 PDT 2020
Author: Craig Topper
Date: 2020-08-29T00:23:13-07:00
New Revision: 6dcd9f517e96a0ed418539b55decd10aae014752
URL: https://github.com/llvm/llvm-project/commit/6dcd9f517e96a0ed418539b55decd10aae014752
DIFF: https://github.com/llvm/llvm-project/commit/6dcd9f517e96a0ed418539b55decd10aae014752.diff
LOG: [Attributes] Merge calls to getFnAttribute/hasFnAttribute using Attribute::isValid. NFC
Rather than calling hasFnAttribute and then calling getFnAttribute
if the attribute exists, its better to just call getFnAttribute and
then check if we got a valid attribute back.
Added:
Modified:
llvm/lib/IR/Attributes.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Attributes.cpp b/llvm/lib/IR/Attributes.cpp
index 03939ee89cd9..157f9a79e4ef 100644
--- a/llvm/lib/IR/Attributes.cpp
+++ b/llvm/lib/IR/Attributes.cpp
@@ -1937,21 +1937,19 @@ static void adjustCallerStackProbes(Function &Caller, const Function &Callee) {
/// that is no larger.
static void
adjustCallerStackProbeSize(Function &Caller, const Function &Callee) {
- if (Callee.hasFnAttribute("stack-probe-size")) {
- uint64_t CalleeStackProbeSize;
- Callee.getFnAttribute("stack-probe-size")
- .getValueAsString()
- .getAsInteger(0, CalleeStackProbeSize);
- if (Caller.hasFnAttribute("stack-probe-size")) {
- uint64_t CallerStackProbeSize;
- Caller.getFnAttribute("stack-probe-size")
- .getValueAsString()
- .getAsInteger(0, CallerStackProbeSize);
+ Attribute CalleeAttr = Callee.getFnAttribute("stack-probe-size");
+ if (CalleeAttr.isValid()) {
+ Attribute CallerAttr = Caller.getFnAttribute("stack-probe-size");
+ if (CallerAttr.isValid()) {
+ uint64_t CallerStackProbeSize, CalleeStackProbeSize;
+ CallerAttr.getValueAsString().getAsInteger(0, CallerStackProbeSize);
+ CalleeAttr.getValueAsString().getAsInteger(0, CalleeStackProbeSize);
+
if (CallerStackProbeSize > CalleeStackProbeSize) {
- Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
+ Caller.addFnAttr(CalleeAttr);
}
} else {
- Caller.addFnAttr(Callee.getFnAttribute("stack-probe-size"));
+ Caller.addFnAttr(CalleeAttr);
}
}
}
@@ -1967,18 +1965,15 @@ adjustCallerStackProbeSize(Function &Caller, const Function &Callee) {
/// handled as part of inline cost analysis.
static void
adjustMinLegalVectorWidth(Function &Caller, const Function &Callee) {
- if (Caller.hasFnAttribute("min-legal-vector-width")) {
- if (Callee.hasFnAttribute("min-legal-vector-width")) {
- uint64_t CallerVectorWidth;
- Caller.getFnAttribute("min-legal-vector-width")
- .getValueAsString()
- .getAsInteger(0, CallerVectorWidth);
- uint64_t CalleeVectorWidth;
- Callee.getFnAttribute("min-legal-vector-width")
- .getValueAsString()
- .getAsInteger(0, CalleeVectorWidth);
+ Attribute CallerAttr = Caller.getFnAttribute("min-legal-vector-width");
+ if (CallerAttr.isValid()) {
+ Attribute CalleeAttr = Callee.getFnAttribute("min-legal-vector-width");
+ if (CalleeAttr.isValid()) {
+ uint64_t CallerVectorWidth, CalleeVectorWidth;
+ CallerAttr.getValueAsString().getAsInteger(0, CallerVectorWidth);
+ CalleeAttr.getValueAsString().getAsInteger(0, CalleeVectorWidth);
if (CallerVectorWidth < CalleeVectorWidth)
- Caller.addFnAttr(Callee.getFnAttribute("min-legal-vector-width"));
+ Caller.addFnAttr(CalleeAttr);
} else {
// If the callee doesn't have the attribute then we don't know anything
// and must drop the attribute from the caller.
More information about the llvm-commits
mailing list