Skip to content

[TableGen] Emit llvm::is_contained for CheckOpcode predicate #134057

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

Merged
merged 3 commits into from
Apr 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/test/TableGen/MacroFusion.td
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def TestBothFusionPredicate: Fusion<"test-both-fusion-predicate", "HasBothFusion
[BothFusionPredicate]>;

def TestFusion: SimpleFusion<"test-fusion", "HasTestFusion", "Test Fusion",
CheckOpcode<[Inst0]>,
CheckOpcode<[Inst0, Inst1]>,
CheckAll<[
CheckOpcode<[Inst1]>,
CheckRegOperand<0, X0>
Expand Down Expand Up @@ -162,7 +162,7 @@ def TestSingleFusion: SingleFusion<"test-single-fusion", "HasTestSingleFusion",
// CHECK-PREDICATOR-NEXT: return true;
// CHECK-PREDICATOR-NEXT: {
// CHECK-PREDICATOR-NEXT: const MachineInstr *MI = FirstMI;
// CHECK-PREDICATOR-NEXT: if (( MI->getOpcode() != Test::Inst0 ))
// CHECK-PREDICATOR-NEXT: if (!llvm::is_contained({Test::Inst0, Test::Inst1}, MI->getOpcode()))
// CHECK-PREDICATOR-NEXT: return false;
// CHECK-PREDICATOR-NEXT: }
// CHECK-PREDICATOR-NEXT: if (!SecondMI.getOperand(0).getReg().isVirtual()) {
Expand Down
23 changes: 9 additions & 14 deletions llvm/utils/TableGen/Common/PredicateExpander.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS, const Record *Inst) {
void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
ArrayRef<const Record *> Opcodes) {
assert(!Opcodes.empty() && "Expected at least one opcode to check!");
bool First = true;

if (Opcodes.size() == 1) {
OS << "( ";
Expand All @@ -152,19 +151,15 @@ void PredicateExpander::expandCheckOpcode(raw_ostream &OS,
return;
}

OS << '(';
++Indent;
for (const Record *Rec : Opcodes) {
OS << '\n' << Indent;
if (!First)
OS << (shouldNegate() ? "&& " : "|| ");

expandCheckOpcode(OS, Rec);
First = false;
}

--Indent;
OS << '\n' << Indent << ')';
if (shouldNegate())
OS << '!';
OS << "llvm::is_contained(";
ListSeparator Sep;
OS << '{';
for (const Record *Inst : Opcodes)
OS << Sep << Inst->getValueAsString("Namespace") << "::" << Inst->getName();
OS << '}';
OS << ", MI" << (isByRef() ? "." : "->") << "getOpcode())";
}

void PredicateExpander::expandCheckPseudo(raw_ostream &OS,
Expand Down