Skip to content

Commit b4f2a71

Browse files
committed
[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.
1 parent 4a1c33d commit b4f2a71

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

llvm/include/llvm/Target/Target.td

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,11 @@ class HwModeSelect<list<HwMode> Ms> {
5454
// patterns.
5555
class ValueTypeByHwMode<list<HwMode> Ms, list<ValueType> Ts>
5656
: HwModeSelect<Ms>, ValueType<0, 0> {
57-
// The length of this list must be the same as the length of Ms.
5857
list<ValueType> Objects = Ts;
58+
59+
// The length of this list must be the same as the length of Ms.
60+
assert !eq(!size(Objects), !size(Modes)),
61+
"The Objects and Modes lists must be the same length";
5962
}
6063

6164
// A class that implements a counterpart of PtrValueType, which is
@@ -79,8 +82,11 @@ class RegInfo<int RS, int SS, int SA> {
7982
// The register size/alignment information, parameterized by a HW mode.
8083
class RegInfoByHwMode<list<HwMode> Ms = [], list<RegInfo> Ts = []>
8184
: HwModeSelect<Ms> {
82-
// The length of this list must be the same as the length of Ms.
8385
list<RegInfo> Objects = Ts;
86+
87+
// The length of this list must be the same as the length of Ms.
88+
assert !eq(!size(Objects), !size(Modes)),
89+
"The Objects and Modes lists must be the same length";
8490
}
8591

8692
class SubRegRange<int size, int offset = 0> {
@@ -90,8 +96,11 @@ class SubRegRange<int size, int offset = 0> {
9096

9197
class SubRegRangeByHwMode<list<HwMode> Ms = [], list<SubRegRange> Ts = []>
9298
: HwModeSelect<Ms> {
93-
// The length of this list must be the same as the length of Ms.
9499
list<SubRegRange> Objects = Ts;
100+
101+
// The length of this list must be the same as the length of Ms.
102+
assert !eq(!size(Objects), !size(Modes)),
103+
"The Objects and Modes lists must be the same length";
95104
}
96105

97106
// SubRegIndex - Use instances of SubRegIndex to identify subregisters.
@@ -575,8 +584,11 @@ class InstructionEncoding {
575584
// to encode and decode based on HwMode.
576585
class EncodingByHwMode<list<HwMode> Ms = [], list<InstructionEncoding> Ts = []>
577586
: HwModeSelect<Ms> {
578-
// The length of this list must be the same as the length of Ms.
579587
list<InstructionEncoding> Objects = Ts;
588+
589+
// The length of this list must be the same as the length of Ms.
590+
assert !eq(!size(Objects), !size(Modes)),
591+
"The Objects and Modes lists must be the same length";
580592
}
581593

582594
//===----------------------------------------------------------------------===//

0 commit comments

Comments
 (0)