-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[TableGen] CodeGenInstAlias: reduce calls to isSubClassOf. NFCI #170767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TableGen] CodeGenInstAlias: reduce calls to isSubClassOf. NFCI #170767
Conversation
Created using spr 1.3.8-beta.1
|
@llvm/pr-subscribers-tablegen Author: Alexander Richardson (arichardson) ChangesAdd a Full diff: https://github.com/llvm/llvm-project/pull/170767.diff 3 Files Affected:
diff --git a/llvm/utils/TableGen/Common/CodeGenInstAlias.cpp b/llvm/utils/TableGen/Common/CodeGenInstAlias.cpp
index 6c1a3e9977c28..4fbf1f3f1a4fc 100644
--- a/llvm/utils/TableGen/Common/CodeGenInstAlias.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenInstAlias.cpp
@@ -44,11 +44,7 @@ static Expected<ResultOperand> matchSimpleOperand(const Init *Arg,
const StringInit *ArgName,
const Record *Op,
const CodeGenTarget &T) {
- if (Op->isSubClassOf("RegisterClass") ||
- Op->isSubClassOf("RegisterOperand")) {
- const Record *OpRC =
- Op->isSubClassOf("RegisterClass") ? Op : Op->getValueAsDef("RegClass");
-
+ if (const Record *OpRC = T.getAsRegClassLike(Op)) {
if (const auto *ArgDef = dyn_cast<DefInit>(Arg)) {
const Record *ArgRec = ArgDef->getDef();
@@ -111,11 +107,9 @@ static Expected<ResultOperand> matchSimpleOperand(const Init *Arg,
return ResultOperand::createRecord(ArgName->getAsUnquotedString(),
ArgDef->getDef());
}
-
- return createStringError("argument must be a subclass of Operand");
}
-
- llvm_unreachable("Unknown operand kind");
+ return createStringError("argument must be a subclass of 'Operand' but got " +
+ Op->getName() + " instead");
}
static Expected<ResultOperand> matchComplexOperand(const Init *Arg,
diff --git a/llvm/utils/TableGen/Common/CodeGenTarget.cpp b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
index 9b05bcc76bf33..f093a61e5a6f6 100644
--- a/llvm/utils/TableGen/Common/CodeGenTarget.cpp
+++ b/llvm/utils/TableGen/Common/CodeGenTarget.cpp
@@ -227,12 +227,14 @@ const Record *CodeGenTarget::getInitValueAsRegClassLike(const Init *V) const {
const DefInit *VDefInit = dyn_cast<DefInit>(V);
if (!VDefInit)
return nullptr;
+ return getAsRegClassLike(VDefInit->getDef());
+}
- const Record *RegClass = VDefInit->getDef();
- if (RegClass->isSubClassOf("RegisterOperand"))
- return RegClass->getValueAsDef("RegClass");
+const Record *CodeGenTarget::getAsRegClassLike(const Record *Rec) const {
+ if (Rec->isSubClassOf("RegisterOperand"))
+ return Rec->getValueAsDef("RegClass");
- return RegClass->isSubClassOf("RegisterClassLike") ? RegClass : nullptr;
+ return Rec->isSubClassOf("RegisterClassLike") ? Rec : nullptr;
}
CodeGenSchedModels &CodeGenTarget::getSchedModels() const {
diff --git a/llvm/utils/TableGen/Common/CodeGenTarget.h b/llvm/utils/TableGen/Common/CodeGenTarget.h
index 5a9be8617dc18..d7390c72ea352 100644
--- a/llvm/utils/TableGen/Common/CodeGenTarget.h
+++ b/llvm/utils/TableGen/Common/CodeGenTarget.h
@@ -165,6 +165,7 @@ class CodeGenTarget {
/// return the Record. This is used as a convenience function to handle direct
/// RegisterClass references, or those wrapped in a RegisterOperand.
const Record *getInitValueAsRegClassLike(const Init *V) const;
+ const Record *getAsRegClassLike(const Record *V) const;
CodeGenSchedModels &getSchedModels() const;
|
s-barannikov
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
… NFCI Add a `getAsRegClassLike()` helper to CodeGenTarget that handles the `isSubClassOf` calls internally. This slightly reduces duplicated code since it can be shared with `getInitValueAsRegClassLike()`. Also change the llvm_unreachable at the end of this function to an actual error since it could be reachable with bad inputs. Reviewed By: s-barannikov, arsenm Pull Request: llvm/llvm-project#170767
Add a
getAsRegClassLike()helper to CodeGenTarget that handles theisSubClassOfcalls internally. This slightly reduces duplicated codesince it can be shared with
getInitValueAsRegClassLike().Also change the llvm_unreachable at the end of this function to an
actual error since it could be reachable with bad inputs.