[llvm] [NFC] Add assert to validate `Objects` list for HwModeSelect (PR #123794)
Rahul Joshi via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 21 10:04:24 PST 2025
https://github.com/jurahul created https://github.com/llvm/llvm-project/pull/123794
- Add asserts to validate that the `Objects` and `Modes` lists for various `HwModeSelect` subclasses are of same length.
>From b4f2a7151b5811c56475ead808e57c5bf0223c75 Mon Sep 17 00:00:00 2001
From: Rahul Joshi <rjoshi at nvidia.com>
Date: Tue, 21 Jan 2025 10:00:50 -0800
Subject: [PATCH] [NFC] Add assert to validate `Objects` list for HwModeSelect
- Add asserts to validate that the `Objects` and `Modes` lists
for various `HwModeSelect` subclasses are of same length.
---
llvm/include/llvm/Target/Target.td | 20 ++++++++++++++++----
1 file changed, 16 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/Target/Target.td b/llvm/include/llvm/Target/Target.td
index 3e037affe1cfd2..4c3a88c4a65f39 100644
--- a/llvm/include/llvm/Target/Target.td
+++ b/llvm/include/llvm/Target/Target.td
@@ -54,8 +54,11 @@ class HwModeSelect<list<HwMode> Ms> {
// patterns.
class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
: HwModeSelect<Ms>, ValueType<0, 0> {
- // The length of this list must be the same as the length of Ms.
list<ValueType> Objects = Ts;
+
+ // The length of this list must be the same as the length of Ms.
+ assert !eq(!size(Objects), !size(Modes)),
+ "The Objects and Modes lists must be the same length";
}
// A class that implements a counterpart of PtrValueType, which is
@@ -79,8 +82,11 @@ class RegInfo<int RS, int SS, int SA> {
// The register size/alignment information, parameterized by a HW mode.
class RegInfoByHwMode<list<HwMode> Ms = [], list<RegInfo> Ts = []>
: HwModeSelect<Ms> {
- // The length of this list must be the same as the length of Ms.
list<RegInfo> Objects = Ts;
+
+ // The length of this list must be the same as the length of Ms.
+ assert !eq(!size(Objects), !size(Modes)),
+ "The Objects and Modes lists must be the same length";
}
class SubRegRange<int size, int offset = 0> {
@@ -90,8 +96,11 @@ class SubRegRange<int size, int offset = 0> {
class SubRegRangeByHwMode<list<HwMode> Ms = [], list<SubRegRange> Ts = []>
: HwModeSelect<Ms> {
- // The length of this list must be the same as the length of Ms.
list<SubRegRange> Objects = Ts;
+
+ // The length of this list must be the same as the length of Ms.
+ assert !eq(!size(Objects), !size(Modes)),
+ "The Objects and Modes lists must be the same length";
}
// SubRegIndex - Use instances of SubRegIndex to identify subregisters.
@@ -575,8 +584,11 @@ class InstructionEncoding {
// to encode and decode based on HwMode.
class EncodingByHwMode<list<HwMode> Ms = [], list<InstructionEncoding> Ts = []>
: HwModeSelect<Ms> {
- // The length of this list must be the same as the length of Ms.
list<InstructionEncoding> Objects = Ts;
+
+ // The length of this list must be the same as the length of Ms.
+ assert !eq(!size(Objects), !size(Modes)),
+ "The Objects and Modes lists must be the same length";
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list