[llvm] [AMDGPU][TableGen][NFC] Combine predicates without using classes. (PR #82346)

Ivan Kosarev via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 20 03:41:10 PST 2024


https://github.com/kosarev created https://github.com/llvm/llvm-project/pull/82346

Saves generating ~1200 instances of the PredConcat TableGen class.

Also removes the default predicates from resulting predicate lists.

>From 52c5d57f98a55ef07595e321c247d5beb3cedb20 Mon Sep 17 00:00:00 2001
From: Ivan Kosarev <ivan.kosarev at amd.com>
Date: Mon, 19 Feb 2024 18:49:20 +0000
Subject: [PATCH] [AMDGPU][TableGen][NFC] Combine predicates without using
 classes.

Saves generating ~1200 instances of the PredConcat TableGen class.

Also removes the default predicates from resulting predicate lists.
---
 llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td b/llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td
index 6c7c91ef464dfd..7c990aa6b2eb60 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUPredicateControl.td
@@ -11,11 +11,6 @@ def TruePredicate : Predicate<"">;
 // FIXME: Tablegen should specially supports this
 def FalsePredicate : Predicate<"false">;
 
-// Add a predicate to the list if does not already exist to deduplicate it.
-class PredConcat<Predicate pred, list<Predicate> lst> {
-  list<Predicate> ret = !listconcat(lst, !listremove([pred], lst));
-}
-
 // Prevent using other kinds of predicates where True16 predicates are
 // expected by giving them their own class.
 class True16PredicateClass<string cond> : Predicate<cond>;
@@ -28,9 +23,8 @@ class PredicateControl {
   True16PredicateClass True16Predicate = NoTrue16Predicate;
   list<Predicate> OtherPredicates = [];
   list<Predicate> Predicates =
-      PredConcat<SubtargetPredicate,
-      PredConcat<AssemblerPredicate,
-      PredConcat<WaveSizePredicate,
-      PredConcat<True16Predicate,
-      OtherPredicates>.ret>.ret>.ret>.ret;
+      !foldl(OtherPredicates, [SubtargetPredicate, AssemblerPredicate,
+                               WaveSizePredicate, True16Predicate],
+             preds, p,
+             preds # !listremove([p], [TruePredicate, NoTrue16Predicate] # preds));
 }



More information about the llvm-commits mailing list