[llvm] [AMDGPU] Use synthetic fixtures for generic feature validation tests (PR #225551)
Chinmay Deshpande via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 23 09:51:33 PDT 2026
https://github.com/chinmaydd updated https://github.com/llvm/llvm-project/pull/225551
>From 13e6f6277c0292e470b8d2b96cdbf230620826bc Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande <chdeshpa at amd.com>
Date: Tue, 22 Sep 2026 19:05:13 -0400
Subject: [PATCH 1/2] [AMDGPU] Avoid repeated parsing in generic classification
test
Parse AMDGPU.td once and assert real feature classifications directly. Keep validation of real generic targets and use AMDGPUTargetDefGenericFeatures.td for validation diagnostics.
Addresses the timeout reported on #223179. Local test time drops from 79.59s to 11.28s; both classification and generic feature validation tests pass.
Change-Id: Ic93ed7843d48230cf61c196502b51d7900dc3329
---
.../AMDGPUTargetDefGenericClassification.td | 99 +++++++------------
1 file changed, 34 insertions(+), 65 deletions(-)
diff --git a/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td b/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
index 51cef25a874e1..4b683d726ebb0 100644
--- a/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
+++ b/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
@@ -1,71 +1,40 @@
-// RUN: split-file %s %t
-// RUN: llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/valid.td \
-// RUN: | FileCheck %t/valid.td
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-bug.td 2>&1 \
-// RUN: | FileCheck %t/missing-generic.td -DDIR=%t -DFEATURE=user-sgpr-init16-bug --implicit-check-not="error:"
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-priority.td 2>&1 \
-// RUN: | FileCheck %t/missing-generic.td -DDIR=%t -DFEATURE=required-export-priority --implicit-check-not="error:"
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-timing.td 2>&1 \
-// RUN: | FileCheck %t/missing-generic.td -DDIR=%t -DFEATURE=gfx125x-lowest-rate-wmma --implicit-check-not="error:"
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-banks.td 2>&1 \
-// RUN: | FileCheck %t/missing-generic.td -DDIR=%t -DFEATURE=ldsbankcount32 --implicit-check-not="error:"
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-lds-size.td 2>&1 \
-// RUN: | FileCheck %t/missing-generic.td -DDIR=%t -DFEATURE=addressablelocalmemorysize65536 --implicit-check-not="error:"
-// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/capability.td 2>&1 \
-// RUN: | FileCheck %t/capability.td -DFILE=%t/capability.td --implicit-check-not="error:"
+// RUN: llvm-tblgen -gen-amdgpu-target-def -I %p/../../include -I %p/../../lib/Target/AMDGPU %s \
+// RUN: | FileCheck %s
-//--- common.td
+// Parse the real target only once: loading all AMDGPU instruction definitions
+// for each negative case can exceed the test timeout. The lightweight
+// AMDGPUTargetDefGenericFeatures.td test covers the validation diagnostics.
include "AMDGPU.td"
-def EmptyGPU : AMDGPUProcessorModel<"gfx999", NoSchedModel, [], [9, 9, 9]>;
-
-//--- valid.td
-include "common.td"
-// Check the real generic targets, including gfx11's combined workarounds,
-// gfx12-5's fixup and WMMA timing, and gfx9-4's LDS size and bank count.
+// Check the classification of the real workarounds, fixup, timing, and numeric
+// features, including features that are not exposed in the frontend bitset.
+foreach Feature = [FeatureUserSGPRInit16Bug,
+ FeatureMADIntraFwdBug,
+ FeatureMSAALoadDstSelBug,
+ FeaturePrivEnabledTrap2NopBug,
+ FeatureVALUTransUseHazard,
+ FeatureRequiredExportPriority,
+ FeatureSetregVGPRMSBFixup,
+ FeatureGFX125xLowestRateWMMA,
+ FeatureLDSBankCount16,
+ FeatureLDSBankCount32,
+ FeatureLDSBankCount64,
+ FeatureAddressableLocalMemorySize32768,
+ FeatureAddressableLocalMemorySize65536,
+ FeatureAddressableLocalMemorySize163840,
+ FeatureAddressableLocalMemorySize196608,
+ FeatureAddressableLocalMemorySize327680] in
+ assert !isa<AMDGPUGenericAnyFeature>(Feature),
+ Feature.Name # " must use the any-covered-GPU rule";
+
+// Instruction capabilities keep the all-covered-GPUs rule. RequiresCOV6 is a
+// generic-target requirement, not a feature supplied by a covered GPU.
+foreach Feature = [FeatureWMMA256bInsts, FeatureRequiresCOV6] in
+ assert !not(!isa<AMDGPUGenericAnyFeature>(Feature)),
+ Feature.Name # " must not use the any-covered-GPU rule";
+
+// Also validate the real generic targets, including gfx11's combined
+// workarounds, gfx12-5's fixup and WMMA timing, and gfx9-4's LDS properties.
// CHECK: GK_GFX9_4_GENERIC
// CHECK: GK_GFX11_GENERIC
// CHECK: GK_GFX12_5_GENERIC
-
-//--- missing-bug.td
-include "common.td"
-defvar CheckedFeature = FeatureUserSGPRInit16Bug;
-include "missing-generic.td"
-
-//--- missing-priority.td
-include "common.td"
-defvar CheckedFeature = FeatureRequiredExportPriority;
-include "missing-generic.td"
-
-//--- missing-timing.td
-include "common.td"
-defvar CheckedFeature = FeatureGFX125xLowestRateWMMA;
-include "missing-generic.td"
-
-//--- missing-banks.td
-include "common.td"
-defvar CheckedFeature = FeatureLDSBankCount32;
-include "missing-generic.td"
-
-//--- missing-lds-size.td
-include "common.td"
-defvar CheckedFeature = FeatureAddressableLocalMemorySize65536;
-include "missing-generic.td"
-
-//--- missing-generic.td
-// Classified backend-only features still need support from a covered GPU.
-// Included files use the native path separator after the include directory.
-// CHECK: [[DIR]]{{[/\\]}}missing-generic.td:[[#@LINE+1]]:1: error: generic target 'gfx9-9-generic' exposes feature '[[FEATURE]]' not supported by any covered GPU
-def : AMDGPUProcessorModel<"gfx9-9-generic", NoSchedModel, [CheckedFeature], [9, 9, 0]> {
- let CoveredGPUs = [EmptyGPU];
-}
-
-//--- capability.td
-include "common.td"
-def WMMAGPU : AMDGPUProcessorModel<"gfx998", NoSchedModel,
- [FeatureWMMA256bInsts], [9, 9, 8]>;
-// Instruction support keeps the default all-covered-GPUs rule.
-// CHECK: [[FILE]]:[[#@LINE+1]]:1: error: generic target 'gfx9-9-generic' exposes feature 'wmma-256b-insts' not supported by covered GPU 'gfx999'
-def : AMDGPUProcessorModel<"gfx9-9-generic", NoSchedModel, [FeatureWMMA256bInsts], [9, 9, 0]> {
- let CoveredGPUs = [WMMAGPU, EmptyGPU];
-}
>From f364fce86b4c0e33a6625e780dd03a76bd62b51f Mon Sep 17 00:00:00 2001
From: Chinmay Deshpande <chdeshpa at amd.com>
Date: Wed, 23 Sep 2026 11:56:33 -0400
Subject: [PATCH 2/2] [AMDGPU] Use synthetic fixtures for generic feature
validation tests
Remove the classification test that includes the full AMDGPU target. Real targets are validated when generating AMDGPUTargetParserDef.inc during the build.
Extend the lightweight generic feature tests to cover inherited classifications of backend-only features, support through member-side implications, and unsupported generic-side implied features.
Change-Id: I54dd16affdc93039ce9d2dba9c99e036bd4afe48
Validation: all four AMDGPU target-definition lit tests pass; the enhanced generic feature test takes 3.44 seconds.
---
.../AMDGPUTargetDefGenericClassification.td | 40 -------------------
.../AMDGPUTargetDefGenericFeatures.td | 23 ++++++++++-
2 files changed, 21 insertions(+), 42 deletions(-)
delete mode 100644 llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
diff --git a/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td b/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
deleted file mode 100644
index 4b683d726ebb0..0000000000000
--- a/llvm/test/TableGen/AMDGPUTargetDefGenericClassification.td
+++ /dev/null
@@ -1,40 +0,0 @@
-// RUN: llvm-tblgen -gen-amdgpu-target-def -I %p/../../include -I %p/../../lib/Target/AMDGPU %s \
-// RUN: | FileCheck %s
-
-// Parse the real target only once: loading all AMDGPU instruction definitions
-// for each negative case can exceed the test timeout. The lightweight
-// AMDGPUTargetDefGenericFeatures.td test covers the validation diagnostics.
-include "AMDGPU.td"
-
-// Check the classification of the real workarounds, fixup, timing, and numeric
-// features, including features that are not exposed in the frontend bitset.
-foreach Feature = [FeatureUserSGPRInit16Bug,
- FeatureMADIntraFwdBug,
- FeatureMSAALoadDstSelBug,
- FeaturePrivEnabledTrap2NopBug,
- FeatureVALUTransUseHazard,
- FeatureRequiredExportPriority,
- FeatureSetregVGPRMSBFixup,
- FeatureGFX125xLowestRateWMMA,
- FeatureLDSBankCount16,
- FeatureLDSBankCount32,
- FeatureLDSBankCount64,
- FeatureAddressableLocalMemorySize32768,
- FeatureAddressableLocalMemorySize65536,
- FeatureAddressableLocalMemorySize163840,
- FeatureAddressableLocalMemorySize196608,
- FeatureAddressableLocalMemorySize327680] in
- assert !isa<AMDGPUGenericAnyFeature>(Feature),
- Feature.Name # " must use the any-covered-GPU rule";
-
-// Instruction capabilities keep the all-covered-GPUs rule. RequiresCOV6 is a
-// generic-target requirement, not a feature supplied by a covered GPU.
-foreach Feature = [FeatureWMMA256bInsts, FeatureRequiresCOV6] in
- assert !not(!isa<AMDGPUGenericAnyFeature>(Feature)),
- Feature.Name # " must not use the any-covered-GPU rule";
-
-// Also validate the real generic targets, including gfx11's combined
-// workarounds, gfx12-5's fixup and WMMA timing, and gfx9-4's LDS properties.
-// CHECK: GK_GFX9_4_GENERIC
-// CHECK: GK_GFX11_GENERIC
-// CHECK: GK_GFX12_5_GENERIC
diff --git a/llvm/test/TableGen/AMDGPUTargetDefGenericFeatures.td b/llvm/test/TableGen/AMDGPUTargetDefGenericFeatures.td
index d1520f12d29b9..6d36fd7805dae 100644
--- a/llvm/test/TableGen/AMDGPUTargetDefGenericFeatures.td
+++ b/llvm/test/TableGen/AMDGPUTargetDefGenericFeatures.td
@@ -9,6 +9,8 @@
// RUN: | FileCheck %t/implied-all.td -DFILE=%t/implied-all.td --implicit-check-not="error:"
// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/missing-private.td 2>&1 \
// RUN: | FileCheck %t/missing-private.td -DFILE=%t/missing-private.td --implicit-check-not="error:"
+// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/implied-private.td 2>&1 \
+// RUN: | FileCheck %t/implied-private.td -DFILE=%t/implied-private.td --implicit-check-not="error:"
// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/numeric-mismatch.td 2>&1 \
// RUN: | FileCheck %t/numeric-mismatch.td -DFILE=%t/numeric-mismatch.td --implicit-check-not="error:"
// RUN: not llvm-tblgen -gen-amdgpu-target-def -I %t -I %p/../../include -I %p/../../lib/Target/AMDGPU %t/empty-members.td 2>&1 \
@@ -25,6 +27,8 @@
// RUN: | FileCheck %t/r600-member.td -DFILE=%t/r600-member.td --implicit-check-not="error:"
//--- common.td
+// Exercise the validation rules with small synthetic targets. The real targets
+// are validated when AMDGPUTargetParserDef.inc is generated during the build.
include "llvm/Target/Target.td"
include "AMDGPUTargetParser.td"
def MyTarget : Target;
@@ -37,7 +41,13 @@ class NumericFeature<int value> : AMDGPUGenericAnyFeature<
def FeatureAnySmall : NumericFeature<4>;
def FeatureAnyB : NumericFeature<8>;
def FeatureAnyLarge : NumericFeature<16>;
-def FeaturePrivate : AMDGPUGenericAnyFeature<"private", "HasPrivate", "true", "">;
+// Classification inherited through a subclass also applies to backend-only
+// features, which must participate in validation without being emitted.
+class PrivateFeature : AMDGPUGenericAnyFeature<
+ "private", "HasPrivate", "true", "">;
+def FeaturePrivate : PrivateFeature;
+def FeatureImpliesPrivate : SubtargetFeature<
+ "implies-private", "HasImpliesPrivate", "true", "", [FeaturePrivate]>;
def FeatureImpliesA : SubtargetFeature<
"implies-a", "HasImpliesA", "true", "", [FeatureAnyA]>;
def FeatureImpliesB : SubtargetFeature<
@@ -55,7 +65,7 @@ include "common.td"
def GFX900 : AMDGPUProcessorModel<"gfx900", NoSchedModel,
[FeatureAll, FeatureAnyA, FeatureAnySmall], [9, 0, 0]>;
def GFX901 : AMDGPUProcessorModel<"gfx901", NoSchedModel,
- [FeatureAll, FeatureImpliesB, FeaturePrivate], [9, 0, 1]>;
+ [FeatureAll, FeatureImpliesB, FeatureImpliesPrivate], [9, 0, 1]>;
// Different members supply different marked features. Follow Implies on both
// the generic and the members, and check marked backend-only features too.
def : AMDGPUProcessorModel<"gfx9-generic", NoSchedModel,
@@ -103,6 +113,15 @@ def : AMDGPUProcessorModel<"gfx9-generic", NoSchedModel, [FeaturePrivate], [9, 0
let CoveredGPUs = [GFX900];
}
+//--- implied-private.td
+include "common.td"
+def GFX900 : AMDGPUProcessorModel<"gfx900", NoSchedModel, [], [9, 0, 0]>;
+// An unclassified backend-only parent must not hide a classified dependency.
+// CHECK: [[FILE]]:[[#@LINE+1]]:1: error: generic target 'gfx9-generic' exposes feature 'private' not supported by any covered GPU
+def : AMDGPUProcessorModel<"gfx9-generic", NoSchedModel, [FeatureImpliesPrivate], [9, 0, 0]> {
+ let CoveredGPUs = [GFX900];
+}
+
//--- numeric-mismatch.td
include "common.td"
def GFX900 : AMDGPUProcessorModel<"gfx900", NoSchedModel, [FeatureAnySmall], [9, 0, 0]>;
More information about the llvm-commits
mailing list