From f3ffee601c1746eafa9a6684541e90d182c9126e Mon Sep 17 00:00:00 2001 From: jyli0116 Date: Mon, 9 Jun 2025 09:02:56 +0100 Subject: [GISel][AArch64] Allow PatLeafs to be imported in GISel which were previously causing warnings (#140935) Previously PatLeafs could not be imported, causing the following warnings to be emitted when running tblgen with `-warn-on-skipped-patterns:` ``` /work/clean/llvm/lib/Target/AArch64/AArch64InstrInfo.td:2631:1: warning: Skipped pattern: Src pattern child has unsupported predicate def : Pat<(i64 (mul top32Zero:$Rn, top32Zero:$Rm)), ^ ``` These changes allow the patterns to now be imported successfully. --- llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp') diff --git a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp index a87aa8b03d03..d33c0dba91fd 100644 --- a/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp +++ b/llvm/utils/TableGen/Common/CodeGenDAGPatterns.cpp @@ -899,6 +899,11 @@ TreePredicateFn::TreePredicateFn(TreePattern *N) : PatFragRec(N) { assert( (!hasPredCode() || !hasImmCode()) && ".td file corrupt: can't have a node predicate *and* an imm predicate"); + + if (hasGISelPredicateCode() && hasGISelLeafPredicateCode()) + PrintFatalError(getOrigPatFragRecord()->getRecord()->getLoc(), + ".td file corrupt: can't have GISelPredicateCode *and* " + "GISelLeafPredicateCode"); } bool TreePredicateFn::hasPredCode() const { @@ -1293,8 +1298,20 @@ bool TreePredicateFn::hasGISelPredicateCode() const { } std::string TreePredicateFn::getGISelPredicateCode() const { - return std::string( - PatFragRec->getRecord()->getValueAsString("GISelPredicateCode")); + return PatFragRec->getRecord()->getValueAsString("GISelPredicateCode").str(); +} + +bool TreePredicateFn::hasGISelLeafPredicateCode() const { + return PatFragRec->getRecord() + ->getValueAsOptionalString("GISelLeafPredicateCode") + .has_value(); +} + +std::string TreePredicateFn::getGISelLeafPredicateCode() const { + return PatFragRec->getRecord() + ->getValueAsOptionalString("GISelLeafPredicateCode") + .value_or(StringRef()) + .str(); } StringRef TreePredicateFn::getImmType() const { -- cgit v1.2.3