aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/TableGen
diff options
context:
space:
mode:
authorVisoiu Mistrih Francis <890283+francisvm@users.noreply.github.com>2024-01-10 06:59:38 -0800
committerGitHub <noreply@github.com>2024-01-10 06:59:38 -0800
commitfef2fc3400eb5a22a5ccc96bd3862bec0058d305 (patch)
treee1b2c556bb9dc64bc141fb86c0f9fe5622dd969a /llvm/lib/TableGen
parent45be680b1ae51866568b1794fa6f59190042ee92 (diff)
downloadllvm-fef2fc3400eb5a22a5ccc96bd3862bec0058d305.zip
llvm-fef2fc3400eb5a22a5ccc96bd3862bec0058d305.tar.gz
llvm-fef2fc3400eb5a22a5ccc96bd3862bec0058d305.tar.bz2
[TableGen] Support non-def operators in !getdagop (#77531)
`!getdagop` expects the dag operator to be a def, and errors out if it's not. While that's true in most cases, when multiclasses are involved, the late resolution of the dag operator can result in it not being a def yet, but still have a proper type, wich is required to check against the optional parameter Ty in `!getdagop<Ty>`. e.g, in the following dag: ``` (!cast<TestInstruction>(TestInstructionAndPattern::NAME) foo) ``` the operator is a UnOpInit, but all we need here is to check its type. This fixes a bug where !getdagop is used to query the dag operator that is dependent on the multiclass, which is not yet resolved to a def. Once the folding is performed, the field becomes a record that can be queried.
Diffstat (limited to 'llvm/lib/TableGen')
-rw-r--r--llvm/lib/TableGen/Record.cpp15
1 files changed, 8 insertions, 7 deletions
diff --git a/llvm/lib/TableGen/Record.cpp b/llvm/lib/TableGen/Record.cpp
index aa981fd..2b3e8a0 100644
--- a/llvm/lib/TableGen/Record.cpp
+++ b/llvm/lib/TableGen/Record.cpp
@@ -923,15 +923,16 @@ Init *UnOpInit::Fold(Record *CurRec, bool IsFinal) const {
case GETDAGOP:
if (DagInit *Dag = dyn_cast<DagInit>(LHS)) {
- DefInit *DI = DefInit::get(Dag->getOperatorAsDef({}));
- if (!DI->getType()->typeIsA(getType())) {
+ // TI is not necessarily a def due to the late resolution in multiclasses,
+ // but has to be a TypedInit.
+ auto *TI = cast<TypedInit>(Dag->getOperator());
+ if (!TI->getType()->typeIsA(getType())) {
PrintFatalError(CurRec->getLoc(),
- Twine("Expected type '") +
- getType()->getAsString() + "', got '" +
- DI->getType()->getAsString() + "' in: " +
- getAsString() + "\n");
+ Twine("Expected type '") + getType()->getAsString() +
+ "', got '" + TI->getType()->getAsString() +
+ "' in: " + getAsString() + "\n");
} else {
- return DI;
+ return Dag->getOperator();
}
}
break;