Skip to content

Commit 10a4f1e

Browse files
committed
[RISCV] Add helper functions to exploit similarity of some RISCVISAInfo::checkDependency() error strings. NFC
1 parent d489b7c commit 10a4f1e

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

llvm/lib/TargetParser/RISCVISAInfo.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,16 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
721721
return RISCVISAInfo::postProcessAndChecking(std::move(ISAInfo));
722722
}
723723

724+
static Error getIncompatibleError(StringRef Ext1, StringRef Ext2) {
725+
return getError("'" + Ext1 + "' and '" + Ext2 +
726+
"' extensions are incompatible");
727+
}
728+
729+
static Error getExtensionRequiresError(StringRef Ext, StringRef ReqExt) {
730+
return getError("'" + Ext + "' requires '" + ReqExt +
731+
"' extension to also be specified");
732+
}
733+
724734
Error RISCVISAInfo::checkDependency() {
725735
bool HasE = Exts.count("e") != 0;
726736
bool HasI = Exts.count("i") != 0;
@@ -733,29 +743,24 @@ Error RISCVISAInfo::checkDependency() {
733743
bool HasZcmt = Exts.count("zcmt") != 0;
734744

735745
if (HasI && HasE)
736-
return getError("'I' and 'E' extensions are incompatible");
746+
return getIncompatibleError("I", "E");
737747

738748
if (HasF && HasZfinx)
739-
return getError("'f' and 'zfinx' extensions are incompatible");
749+
return getIncompatibleError("f", "zfinx");
740750

741751
if (HasZvl && !HasVector)
742-
return getError(Twine("'") + "zvl*b" +
743-
"' requires 'v' or 'zve*' extension to also be specified");
752+
return getExtensionRequiresError("zvl*b", "v' or 'zve*");
744753

745754
if (!HasVector)
746755
for (auto Ext :
747756
{"zvbb", "zvbc32e", "zvkb", "zvkg", "zvkgs", "zvkned", "zvknha", "zvksed", "zvksh"})
748757
if (Exts.count(Ext))
749-
return getError(
750-
Twine("'") + Ext +
751-
"' requires 'v' or 'zve*' extension to also be specified");
758+
return getExtensionRequiresError(Ext, "v' or 'zve*");
752759

753760
if (!Exts.count("zve64x"))
754761
for (auto Ext : {"zvknhb", "zvbc"})
755762
if (Exts.count(Ext))
756-
return getError(
757-
Twine("'") + Ext +
758-
"' requires 'v' or 'zve64*' extension to also be specified");
763+
return getExtensionRequiresError(Ext, "v' or 'zve64*");
759764

760765
if ((HasZcmt || Exts.count("zcmp")) && HasD && (HasC || Exts.count("zcd")))
761766
return getError(Twine("'") + (HasZcmt ? "zcmt" : "zcmp") +
@@ -769,19 +774,17 @@ Error RISCVISAInfo::checkDependency() {
769774
if (!(Exts.count("a") || Exts.count("zaamo")))
770775
for (auto Ext : {"zacas", "zabha"})
771776
if (Exts.count(Ext))
772-
return getError(
773-
Twine("'") + Ext +
774-
"' requires 'a' or 'zaamo' extension to also be specified");
777+
return getExtensionRequiresError(Ext, "a' or 'zaamo");
775778

776779
if (Exts.count("xwchc") != 0) {
777780
if (XLen != 32)
778781
return getError("'Xwchc' is only supported for 'rv32'");
779782

780783
if (HasD)
781-
return getError("'D' and 'Xwchc' extensions are incompatible");
784+
return getIncompatibleError("D", "Xwchc");
782785

783786
if (Exts.count("zcb") != 0)
784-
return getError("'Xwchc' and 'Zcb' extensions are incompatible");
787+
return getIncompatibleError("Xwchc", "Zcb");
785788
}
786789

787790
return Error::success();

0 commit comments

Comments
 (0)