Fix constant propagating DPI-written variables (#7074)
This commit is contained in:
parent
7d71c3bb76
commit
e0c626e48a
|
|
@ -171,7 +171,8 @@ public:
|
||||||
entr.init(false);
|
entr.init(false);
|
||||||
} else {
|
} else {
|
||||||
if (AstConst* const constp = entr.constNodep()) {
|
if (AstConst* const constp = entr.constNodep()) {
|
||||||
if (!varrefp->varp()->isSigPublic() && !varrefp->varp()->isVirtIface()) {
|
if (!varrefp->varp()->isSigPublic() && !varrefp->varp()->isWrittenByDpi()
|
||||||
|
&& !varrefp->varp()->isVirtIface()) {
|
||||||
// Aha, variable is constant; substitute in.
|
// Aha, variable is constant; substitute in.
|
||||||
// We'll later constant propagate
|
// We'll later constant propagate
|
||||||
UINFO(4, " replaceconst: " << varrefp);
|
UINFO(4, " replaceconst: " << varrefp);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// -*- mode: C++; c-file-style: "cc-mode" -*-
|
||||||
|
//*************************************************************************
|
||||||
|
//
|
||||||
|
// This program is free software; you can redistribute it and/or modify it
|
||||||
|
// under the terms of either the GNU Lesser General Public License Version 3
|
||||||
|
// or the Perl Artistic License Version 2.0.
|
||||||
|
// SPDX-FileCopyrightText: 2026-2026 Wilson Snyder
|
||||||
|
// SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
//
|
||||||
|
//*************************************************************************
|
||||||
|
|
||||||
|
#include "svdpi.h"
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
extern "C" void setDpi(int value);
|
||||||
|
|
||||||
|
extern "C" void setViaDpi(int value) {
|
||||||
|
std::cout << "setViaDpi " << value << std::endl;
|
||||||
|
setDpi(value);
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||||
|
#
|
||||||
|
# This program is free software; you can redistribute it and/or modify it
|
||||||
|
# under the terms of either the GNU Lesser General Public License Version 3
|
||||||
|
# or the Perl Artistic License Version 2.0.
|
||||||
|
# SPDX-FileCopyrightText: 2026 Wilson Snyder
|
||||||
|
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
|
||||||
|
|
||||||
|
import vltest_bootstrap
|
||||||
|
|
||||||
|
test.scenarios('vlt_all')
|
||||||
|
|
||||||
|
test.compile(verilator_flags2=["--binary", "--stats", test.top_filename.replace(".v", ".cpp")])
|
||||||
|
|
||||||
|
test.execute()
|
||||||
|
|
||||||
|
test.file_grep_not(test.stats, r'Optimizations, Lifetime constant prop')
|
||||||
|
test.file_grep_not(test.stats, r'Optimizations, Lifetime assign deletions')
|
||||||
|
|
||||||
|
test.passes()
|
||||||
|
|
@ -0,0 +1,31 @@
|
||||||
|
// DESCRIPTION: Verilator: Verilog Test module
|
||||||
|
//
|
||||||
|
// This file ONLY is placed under the Creative Commons Public Domain.
|
||||||
|
// SPDX-FileCopyrightText: 2026 Wilson Snyder
|
||||||
|
// SPDX-License-Identifier: CC0-1.0
|
||||||
|
|
||||||
|
`define stop $stop
|
||||||
|
`define check(got ,exp) do if ((got) !== (exp)) begin $write("%%Error: %s:%0d: got='h%x exp='h%x\n", `__FILE__,`__LINE__, (got), (exp)); `stop; end while(0)
|
||||||
|
|
||||||
|
module t;
|
||||||
|
|
||||||
|
int dpiSet = 0;
|
||||||
|
function automatic void setDpi(int value);
|
||||||
|
dpiSet = value;
|
||||||
|
endfunction
|
||||||
|
export "DPI-C" function setDpi;
|
||||||
|
import "DPI-C" context function void setViaDpi(int value); // calls setDpi(value)
|
||||||
|
|
||||||
|
initial begin
|
||||||
|
dpiSet = 13;
|
||||||
|
setViaDpi(14);
|
||||||
|
`check(dpiSet, 14);
|
||||||
|
dpiSet = 15;
|
||||||
|
setViaDpi(16);
|
||||||
|
`check(dpiSet, 16);
|
||||||
|
dpiSet = 17;
|
||||||
|
setViaDpi(18);
|
||||||
|
`check(dpiSet, 18);
|
||||||
|
end
|
||||||
|
|
||||||
|
endmodule
|
||||||
Loading…
Reference in New Issue