-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a warning for large unrolled loops #234
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3031,12 +3031,19 @@ def stmt_select(stmt, location, scope): | |
else_dead = True | ||
break | ||
|
||
iterations = len(clauses) | ||
if else_dead: | ||
(last_cond, last_stmt) = clauses.pop(-1) | ||
assert last_cond.constant and last_cond.value | ||
if_chain = last_stmt | ||
else: | ||
if_chain = codegen_statement(else_ast, location, scope) | ||
if iterations > WBIGUNROLL.limit and isinstance(lst, List): | ||
report(WBIGUNROLL(stmt.site, | ||
'#'*(stmt.site.dml_version() != (1, 2)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space around binop There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a stylistic choice we can quibble about: when combining There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here we don't combine And I agree that PEP-8 is not always optimal; in particular, I find There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I mean... we are, though the
Not on the same syntactic level, the
vs.
And that does apply to
It's not as obviously clear at a glance that the
If you insist on spacing, I would do the above. even though i kinda hate it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I didn't see the If you ask me what I prefer, then it's the normal python idiom for expressing when a value depends on a condition:
I quite strongly dislike the use of bools for arithmetic on iterables. But I tolerate it since it doesn't break any agreed-upon style. |
||
+ 'select', | ||
iterations)) | ||
|
||
for (cond, stmt) in reversed(clauses): | ||
if_chain = mkIf(cond.site, cond, stmt, if_chain) | ||
return [if_chain] | ||
|
@@ -3162,6 +3169,10 @@ def foreach_constant_list(site, itername, lst, statement, location, scope): | |
stmt) | ||
spec.append(mkCompound(site, decls + [stmt])) | ||
|
||
if len(spec) > WBIGUNROLL.limit and isinstance(lst, List): | ||
report(WBIGUNROLL(site, | ||
'#'*(site.dml_version() != (1, 2)) + 'foreach', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. space around binop |
||
len(spec))) | ||
return [mkUnrolledLoop(site, spec, | ||
context.label if context.used else None)] | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,6 +198,30 @@ class suppress_WLOGMIXUP(CompatFeature): | |
short = "Suppress the warning 'WLOGMIXUP' by default" | ||
last_api_version = api_6 | ||
|
||
@feature | ||
class suppress_WBIGUNROLL(CompatFeature): | ||
'''This compatibility feature makes it so the warning `WBIGUNROLL` is | ||
suppressed by default. `WBIGUNROLL` warns about `#foreach` and `#select` | ||
statements that compile to large unrolled loops — for more | ||
information, see the documentation of `WBIGUNROLL` in the | ||
[Messages](messages.html) section. | ||
Comment on lines
+206
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. better with a direct link, add There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, seems that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whaaat There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Though There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
wait. What experiment did you do, that made you say this?
Looking at this, I don't understand why the hyperlink syntax would pick out and work specifically with If this doesn't work, maybe the better approach is to just tweak There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I looked at the generated messages.html, and also typed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... huh! |
||
|
||
`WBIGUNROLL` is suppressed by default below Simics API version 8 in order | ||
to avoid overwhelming users with warnings. Addressing occurences of large | ||
unrolled loops should be done before or as part of migration to Simics API | ||
version 8. | ||
|
||
Passing `--no-compat=suppress_WBUGUNROLL` to DMLC has almost the same effect | ||
as passing `--warn=WBIGUNROLL`; either will cause DMLC to report the warning | ||
even when the Simics API version in use is below 8. The only difference | ||
between these two options is that if `--no-compat=suppress_WBIGUNROLL` is | ||
used (and `--warn=WBIGUNROLL` is not), then `WBIGUNROLL` may still be | ||
explicitly suppressed via `--no-warn=WBIGUNROLL`. In contrast, | ||
`--warn=WBIGUNROLL` doesn't allow for `WBIGUNROLL` to be suppressed at | ||
all.''' | ||
Comment on lines
+219
to
+221
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's somewhat weird, when you pass In any case, I think we can drop this paragraph entirely; there is no essential difference and the main reason for a compat feature is for consistency with other things that change with API 8. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with dropping the explanation of the difference; that was inherited from the description of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Agreed |
||
short = "Suppress the warning 'WBIGUNROLL' by default" | ||
last_api_version = api_7 | ||
|
||
@feature | ||
class legacy_attributes(CompatFeature): | ||
'''This compatibility feature makes DMLC register all attributes using the | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
© 2024 Intel Corporation | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
dml 1.2; | ||
|
||
device test; | ||
|
||
/// COMPILE-ONLY | ||
/// NO-CC | ||
|
||
/// DMLC-FLAG --no-compat=suppress_WBIGUNROLL | ||
|
||
/// SCAN-FOR-TAGS suppress_WBIGUNROLL.dml | ||
import "suppress_WBIGUNROLL.dml"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
© 2024 Intel Corporation | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
dml 1.2; | ||
|
||
device test; | ||
|
||
/// COMPILE-ONLY | ||
/// NO-CC | ||
|
||
/// DMLC-FLAG --simics-api=7 | ||
|
||
import "suppress_WBIGUNROLL.dml"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
© 2024 Intel Corporation | ||
SPDX-License-Identifier: MPL-2.0 | ||
*/ | ||
dml 1.2; | ||
|
||
mandolaerik marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// expectations in this file are selectively enabled using SCAN-FOR-TAGS | ||
|
||
data int zero = 0; | ||
|
||
parameter zeroes_64 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero]; | ||
|
||
// Sixtyfourth zero is constant | ||
parameter zeroes_65 = [$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, $zero, | ||
$zero, $zero, $zero, $zero, $zero, $zero, $zero, 0, | ||
$zero]; | ||
|
||
bank b { | ||
register regs[i in 0..64] size 4 @ undefined; | ||
} | ||
|
||
method init { | ||
local int nonconstant; | ||
|
||
// no warning | ||
foreach x in ($zeroes_64) assert true; | ||
// The else branch is not considered an iteration | ||
select x in ($zeroes_64) where (x == nonconstant) { | ||
assert true; | ||
} else assert true; | ||
|
||
/// WARNING WBIGUNROLL | ||
foreach x in ($zeroes_65) assert true; | ||
/// WARNING WBIGUNROLL | ||
select x in ($zeroes_65) where (x == nonconstant) { | ||
assert true; | ||
} else assert true; | ||
|
||
// no warning | ||
foreach x in ($zeroes_65) { | ||
// As sixtyfourth bit is constant 0, DML 1.2 semantics eliminates this | ||
// if, and subsequently causes that iteration to be omitted from | ||
// codegen entirely; reducing the total count to 64 | ||
if (x != 0) assert true; | ||
} | ||
|
||
// As sixtyfourth bit is constant 0, select can cut short at it, reducing | ||
// the total number of iterations to 64 | ||
select x in ($zeroes_65) where (x == 0) { | ||
assert true; | ||
} else assert true; | ||
|
||
// As sixtyfourth bit is constant 0, select can omit the check and thus | ||
// iteration for it, reducing the total number of iterations to 64 | ||
select x in ($zeroes_65) where (x != 0) { | ||
assert true; | ||
} else assert true; | ||
|
||
|
||
// WBIGUNROLL is only reported for compile-time lists defined via list | ||
// syntax, not the object lists generated by DMLC | ||
// no warning | ||
foreach x in ($b.unmapped_registers) assert true; | ||
select x in ($b.unmapped_registers) where (x == nonconstant) { | ||
assert true; | ||
} else assert true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enabled by