[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.
This commit is contained in:
Craig Topper 2020-08-28 23:15:34 -07:00
parent c1b3e32118
commit 6dcd9f517e
1 changed files with 18 additions and 23 deletions

View File

@ -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.