Skip to content

Commit 08bda7f

Browse files
committed
Address Erik's feedback
1 parent d9e78d1 commit 08bda7f

File tree

3 files changed

+32
-28
lines changed

3 files changed

+32
-28
lines changed

py/dml/codegen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3055,7 +3055,7 @@ def stmt_select(stmt, location, scope):
30553055
if_chain = last_stmt
30563056
else:
30573057
if_chain = codegen_statement(else_ast, location, scope)
3058-
if iterations > 50 and isinstance(lst, List):
3058+
if iterations > WBIGUNROLL.limit and isinstance(lst, List):
30593059
report(WBIGUNROLL(stmt.site,
30603060
'#'*(stmt.site.dml_version() != (1, 2))
30613061
+ 'select',
@@ -3186,7 +3186,7 @@ def foreach_constant_list(site, itername, lst, statement, location, scope):
31863186
stmt)
31873187
spec.append(mkCompound(site, decls + [stmt]))
31883188

3189-
if len(spec) > 50 and isinstance(lst, List):
3189+
if len(spec) > WBIGUNROLL.limit and isinstance(lst, List):
31903190
report(WBIGUNROLL(site,
31913191
'#'*(site.dml_version() != (1, 2)) + 'foreach',
31923192
len(spec)))

py/dml/messages.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,16 +2012,17 @@ class WHOOKSEND(DMLWarning):
20122012
+ "information about the differences between 'send' and 'send_now'")
20132013

20142014
class WBIGUNROLL(DMLWarning):
2015-
"""
2015+
limit = 64
2016+
__doc__ = f"""
20162017
A `#select` or `#foreach` statement was specified which caused DMLC to
20172018
study the body and generate duplicated C code for it a large number of
2018-
times (more than 50 times.) This can dramatically increase both DMLC and
2019-
GCC compile times and code size, if not crash DMLC outright.
2019+
times (more than {limit} times.) This can dramatically increase both DMLC
2020+
and GCC compile times and code size, if not crash DMLC outright.
20202021
20212022
To address this, you have two options:
20222023
* Ensure most iterations can be entirely eliminated at compile-time by
20232024
DMLC. For `#select`, this can be done by ensuring that the `where` check
2024-
will be a constant (typically a constant equality) for most if not all
2025+
will be a constant value (e.g. a constant equality) for most if not all
20252026
items of the specified list. For `#foreach`, encase the body in an `#if`
20262027
check that is false for most items of the specified list.
20272028
* Don't use `#select` or `#foreach`. Represent the specified compile-time

test/1.2/errors/T_WBIGUNROLL.dml

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,61 +11,64 @@ device test;
1111

1212
data int zero = 0;
1313

14-
parameter zeroes_50 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
14+
parameter zeroes_64 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
1515
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
1616
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
1717
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
1818
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
1919
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
20-
$zero, $zero];
20+
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
21+
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero];
2122

22-
// Fiftieth zero is constant
23-
parameter zeroes_51 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
23+
// Sixtyfourth zero is constant
24+
parameter zeroes_65 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
25+
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
2426
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
2527
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
2628
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
2729
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
2830
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero,
29-
$zero, 0, $zero];
31+
$zero, $zero, $zero, $zero, $zero, $zero, $zero, 0,
32+
$zero];
3033

3134
bank b {
32-
register regs[i in 0..50] size 4 @ undefined;
35+
register regs[i in 0..64] size 4 @ undefined;
3336
}
3437

3538
method init {
36-
local int i;
39+
local int nonconstant;
3740

3841
// no warning
39-
foreach x in ($zeroes_50) assert true;
42+
foreach x in ($zeroes_64) assert true;
4043
// The else branch is not considered an iteration
41-
select x in ($zeroes_50) where (x == i) {
44+
select x in ($zeroes_64) where (x == nonconstant) {
4245
assert true;
4346
} else assert true;
4447

4548
/// WARNING WBIGUNROLL
46-
foreach x in ($zeroes_51) assert true;
49+
foreach x in ($zeroes_65) assert true;
4750
/// WARNING WBIGUNROLL
48-
select x in ($zeroes_51) where (x == i) {
51+
select x in ($zeroes_65) where (x == nonconstant) {
4952
assert true;
5053
} else assert true;
5154

5255
// no warning
53-
foreach x in ($zeroes_51) {
54-
// As fiftieth bit is constant 0, DML 1.2 semantics eliminates this if
55-
// entirely, and subsequently causes that iteration to be omitted from
56-
// codegen entirely; reducing the total count to 50
56+
foreach x in ($zeroes_65) {
57+
// As sixtyfourth bit is constant 0, DML 1.2 semantics eliminates this
58+
// if, and subsequently causes that iteration to be omitted from
59+
// codegen entirely; reducing the total count to 64
5760
if (x != 0) assert true;
5861
}
5962

60-
// As fiftieth bit is constant 0, select can cut short at it, reducing the
61-
// total number of iterations to 50
62-
select x in ($zeroes_50) where (x == 0) {
63+
// As sixtyfourth bit is constant 0, select can cut short at it, reducing
64+
// the total number of iterations to 64
65+
select x in ($zeroes_65) where (x == 0) {
6366
assert true;
6467
} else assert true;
6568

66-
// As fiftieth bit is constant 0, select can omit the check and thus
67-
// iteration for it, reducing the total number of iterations to 50
68-
select x in ($zeroes_50) where (x == 1) {
69+
// As sixtyfourth bit is constant 0, select can omit the check and thus
70+
// iteration for it, reducing the total number of iterations to 64
71+
select x in ($zeroes_65) where (x != 0) {
6972
assert true;
7073
} else assert true;
7174

@@ -74,7 +77,7 @@ method init {
7477
// syntax, not the object lists generated by DMLC
7578
// no warning
7679
foreach x in ($b.unmapped_registers) assert true;
77-
select x in ($b.unmapped_registers) where (i == 0) {
80+
select x in ($b.unmapped_registers) where (x == nonconstant) {
7881
assert true;
7982
} else assert true;
8083
}

0 commit comments

Comments
 (0)