Skip to content

Commit

Permalink
[NFC][LLVM][SVE] Refactor predicate register ASM constraint parsing t…
Browse files Browse the repository at this point in the history
…o use std::optional.
  • Loading branch information
paulwalker-arm committed Nov 3, 2023
1 parent 97a238e commit 5148501
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions llvm/lib/Target/AArch64/AArch64ISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10163,14 +10163,15 @@ const char *AArch64TargetLowering::LowerXConstraint(EVT ConstraintVT) const {
return "r";
}

enum PredicateConstraint { Uph, Upl, Upa, Invalid };
enum class PredicateConstraint { Uph, Upl, Upa };

static PredicateConstraint parsePredicateConstraint(StringRef Constraint) {
return StringSwitch<PredicateConstraint>(Constraint)
static std::optional<PredicateConstraint>
parsePredicateConstraint(StringRef Constraint) {
return StringSwitch<std::optional<PredicateConstraint>>(Constraint)
.Case("Uph", PredicateConstraint::Uph)
.Case("Upl", PredicateConstraint::Upl)
.Case("Upa", PredicateConstraint::Upa)
.Default(PredicateConstraint::Invalid);
.Default(std::nullopt);
}

static const TargetRegisterClass *
Expand All @@ -10180,8 +10181,6 @@ getPredicateRegisterClass(PredicateConstraint Constraint, EVT VT) {
return nullptr;

switch (Constraint) {
default:
return nullptr;
case PredicateConstraint::Uph:
return VT == MVT::aarch64svcount ? &AArch64::PNR_p8to15RegClass
: &AArch64::PPR_p8to15RegClass;
Expand All @@ -10192,6 +10191,8 @@ getPredicateRegisterClass(PredicateConstraint Constraint, EVT VT) {
return VT == MVT::aarch64svcount ? &AArch64::PNRRegClass
: &AArch64::PPRRegClass;
}

llvm_unreachable("Missing PredicateConstraint!");
}

// The set of cc code supported is from
Expand Down Expand Up @@ -10289,9 +10290,8 @@ AArch64TargetLowering::getConstraintType(StringRef Constraint) const {
case 'S': // A symbolic address
return C_Other;
}
} else if (parsePredicateConstraint(Constraint) !=
PredicateConstraint::Invalid)
return C_RegisterClass;
} else if (parsePredicateConstraint(Constraint))
return C_RegisterClass;
else if (parseConstraintCode(Constraint) != AArch64CC::Invalid)
return C_Other;
return TargetLowering::getConstraintType(Constraint);
Expand Down Expand Up @@ -10325,7 +10325,7 @@ AArch64TargetLowering::getSingleConstraintMatchWeight(
weight = CW_Constant;
break;
case 'U':
if (parsePredicateConstraint(constraint) != PredicateConstraint::Invalid)
if (parsePredicateConstraint(constraint))
weight = CW_Register;
break;
}
Expand Down Expand Up @@ -10382,9 +10382,9 @@ AArch64TargetLowering::getRegForInlineAsmConstraint(
break;
}
} else {
PredicateConstraint PC = parsePredicateConstraint(Constraint);
if (const TargetRegisterClass *RegClass = getPredicateRegisterClass(PC, VT))
return std::make_pair(0U, RegClass);
if (const auto PC = parsePredicateConstraint(Constraint))
if (const auto *RegClass = getPredicateRegisterClass(*PC, VT))
return std::make_pair(0U, RegClass);
}
if (StringRef("{cc}").equals_insensitive(Constraint) ||
parseConstraintCode(Constraint) != AArch64CC::Invalid)
Expand Down

0 comments on commit 5148501

Please sign in to comment.