Commit c49fad1d by Zachary Snow

drop unneeded module-scoped references

parent 086eb786
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
* Fixed module-level localparams being needlessly inlined when forming longest * Fixed module-level localparams being needlessly inlined when forming longest
static prefixes, which could cause deep recursion and run out of memory on static prefixes, which could cause deep recursion and run out of memory on
some designs some designs
* Fixed unneeded scoping of constant function calls used in type lookups
### Other Enhancements ### Other Enhancements
......
...@@ -122,6 +122,11 @@ traverseExprM (Cast (Right size) expr) = do ...@@ -122,6 +122,11 @@ traverseExprM (Cast (Right size) expr) = do
expr' <- traverseExprM expr expr' <- traverseExprM expr
size' <- traverseExprM size size' <- traverseExprM size
elaborateSizeCast size' expr' elaborateSizeCast size' expr'
traverseExprM orig@(Dot (Ident x) f) = do
unneeded <- unneededModuleScope x f
return $ if unneeded
then Ident f
else orig
traverseExprM other = traverseExprM other =
traverseSinglyNestedExprsM traverseExprM other traverseSinglyNestedExprsM traverseExprM other
>>= traverseExprTypesM traverseTypeM >>= traverseExprTypesM traverseTypeM
...@@ -150,6 +155,21 @@ isStringParam (Ident x) = do ...@@ -150,6 +155,21 @@ isStringParam (Ident x) = do
Just (_, _, typ) -> typ == TypeOf (Ident x) Just (_, _, typ) -> typ == TypeOf (Ident x)
isStringParam _ = return False isStringParam _ = return False
-- checks if referring to part.wire is needlessly explicit
unneededModuleScope :: Identifier -> Identifier -> ST Bool
unneededModuleScope part wire = do
accessesLocal <- localAccessesM wire
if accessesLocal == accessesTop then
return True
else if head accessesLocal == head accessesTop then do
details <- lookupElemM wire
return $ case details of
Just (accessesFound, _, _) -> accessesTop == accessesFound
_ -> False
else
return False
where accessesTop = [Access part Nil, Access wire Nil]
-- convert TypeOf in a Type -- convert TypeOf in a Type
traverseTypeM :: Type -> ST Type traverseTypeM :: Type -> ST Type
traverseTypeM (TypeOf expr) = traverseTypeM (TypeOf expr) =
......
module top;
function automatic integer incr;
input integer inp;
return inp + 1;
endfunction
parameter P = 3;
logic [incr(P):0] x;
logic [$bits(x) * 2:0] y, z;
if (1) begin
assign top.y = {top.x, x};
end
if (1) begin : blk
wire x;
assign z = {blk.x, top.x};
end
endmodule
affirm top.y
affirm top.x
affirm blk.x
affirm incr
reject top.incr
module top;
parameter P = 3;
wire [P + 1:0] x;
wire [2 * P + 4:0] y, z;
assign y = {x, x};
generate
if (1) begin : blk
wire x;
end
endgenerate
assign z = {blk.x, x};
endmodule
...@@ -45,6 +45,24 @@ assertConverts() { ...@@ -45,6 +45,24 @@ assertConverts() {
ac_tmpa=$SHUNIT_TMPDIR/ac-conv-tmpa.v ac_tmpa=$SHUNIT_TMPDIR/ac-conv-tmpa.v
convert "1st conversion of $ac_file" $ac_tmpa $ac_file convert "1st conversion of $ac_file" $ac_tmpa $ac_file
# check for un/expected output in the converted result
ac_pats=$ac_file.pat
if [ -f $ac_pats ]; then
while read line; do
rule=${line:0:6}
pattern=${line:7}
grep -G "$pattern" < $ac_tmpa > /dev/null
matches=$?
if [ $rule == "affirm" ]; then
assertTrue "conversion of $ac_file does not contain $pattern" $matches
elif [ $rule == "reject" ]; then
assertFalse "conversion of $ac_file contains $pattern" $matches
else
fail "unknown rule type: '$rule'"
fi
done < $ac_pats
fi
ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v ac_tmpb=$SHUNIT_TMPDIR/ac-conv-tmpb.v
convert "2nd conversion of $ac_file" $ac_tmpb $ac_tmpa convert "2nd conversion of $ac_file" $ac_tmpb $ac_tmpa
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment