Skip to content

Commit

Permalink
Make --jit work without --no-save
Browse files Browse the repository at this point in the history
  • Loading branch information
nickg committed Dec 9, 2023
1 parent 32d4403 commit d220d91
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 19 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## Unreleased changes
- The `--jit` elaboration option no longer requires `--no-save`.

## Version 1.11.0 - 2023-12-06
- New command `--cover-export` exports coverage data in the Cobertura
Expand Down
4 changes: 1 addition & 3 deletions nvc.1
Original file line number Diff line number Diff line change
Expand Up @@ -287,9 +287,7 @@ been executed often enough in the interpreter to be deemed worthwhile.
This dramatically reduces elaboration time at the cost of increased
memory and CPU usage while the simulation is executing. This option is
beneficial for short-running simulations where the performance gain from
ahead-of-time compilation is not so significant. The
.Fl \-no-save
option must also be specified.
ahead-of-time compilation is not so significant.
.\" --no-collapse
.It Fl \-no-collapse
Do not collapse ports into a single signal. Normally if a signal at one
Expand Down
35 changes: 22 additions & 13 deletions src/nvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
{ 0, 0, 0, 0 }
};

bool use_jit = false;
bool use_jit = false, no_save = false;
cover_mask_t cover_mask = 0;
char *cover_spec_file = NULL;
int cover_array_limit = 0;
Expand Down Expand Up @@ -391,6 +391,7 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
break;
case 'N':
opt_set_int(OPT_NO_SAVE, 1);
no_save = true;
break;
case 'C':
opt_set_int(OPT_NO_COLLAPSE, 1);
Expand All @@ -416,9 +417,6 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
}
}

if (use_jit && !opt_get_int(OPT_NO_SAVE))
fatal("$bold$--jit$$ option requires $bold$--no-save$$");

set_top_level(argv, next_cmd);

progress("initialising");
Expand Down Expand Up @@ -471,15 +469,25 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)
if (error_count() > 0)
return EXIT_FAILURE;

if (!opt_get_int(OPT_NO_SAVE)) {
const bool aot_codegen = !use_jit NOT_LLVM_ONLY(&& false);

char *pack_name LOCAL = xasprintf("_%s.pack", istr(top_level));
char *dll_name LOCAL = xasprintf("_%s." DLL_EXT, istr(tree_ident(top)));

// Delete any existing generated code to avoid accidentally loading
// the wrong version later
lib_delete(work, pack_name);
lib_delete(work, dll_name);

if (!no_save) {
lib_save(work);
progress("saving library");
}

#ifndef ENABLE_LLVM
char *name LOCAL = xasprintf("_%s.pack", istr(top_level));
FILE *f = lib_fopen(work, name, "wb");
if (!no_save && !aot_codegen) {
FILE *f = lib_fopen(work, pack_name, "wb");
if (f == NULL)
fatal_errno("fopen: %s", name);
fatal_errno("fopen: %s", pack_name);

ident_t b0 = tree_ident(tree_stmt(top, 0));
ident_t root = ident_prefix(lib_name(work), b0, '.');
Expand All @@ -489,10 +497,11 @@ static int elaborate(int argc, char **argv, cmd_state_t *state)

jit_write_pack(state->jit, vu, f);
fclose(f);
#endif

progress("writing JIT pack");
}

if (!use_jit) {
if (aot_codegen) {
LLVM_ONLY(cgen(top, state->registry, state->jit));

// Must discard current JIT state to load AOT library later
Expand Down Expand Up @@ -787,14 +796,14 @@ static int run_cmd(int argc, char **argv, cmd_state_t *state)

#ifdef ENABLE_LLVM
jit_load_dll(state->jit, tree_ident(top));
#else
#endif

char *name LOCAL = xasprintf("_%s.pack", istr(top_level));
FILE *f = lib_fopen(lib_work(), name, "rb");
if (f != NULL) {
jit_load_pack(state->jit, f);
fclose(f);
}
#endif

jit_reset(state->jit);
jit_enable_runtime(state->jit, true);
Expand Down
38 changes: 38 additions & 0 deletions test/regress/cmdline9.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
set -xe

nvc -a - <<EOF
entity cmdline9 is
end entity;
architecture test of cmdline9 is
begin
p: assert false;
end architecture;
EOF

nvc -e cmdline9

ls -l work

[ -f work/_WORK.CMDLINE9.elab.so ] || exit 99

nvc -r cmdline9 && exit 66

nvc -a - <<EOF
entity cmdline9 is
end entity;
architecture test of cmdline9 is
begin
p: process is
begin
report "running new code";
wait;
end process;
end architecture;
EOF

nvc -e cmdline9 --jit
nvc -r cmdline9

[ ! -f work/_WORK.CMDLINE9.elab.so ] || exit 22
1 change: 1 addition & 0 deletions test/regress/testlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -909,3 +909,4 @@ issue809 normal,2008
range3 normal,2008
issue810 normal,2008
elab40 normal,2008
cmdline9 shell,slow
7 changes: 4 additions & 3 deletions test/run_regr.c
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,9 @@ static bool run_test(test_t *test)
}
}

if (force_jit)
push_arg(&args, "--jit");

if ((test->flags & F_FAIL) || broken_libc) {
if (run_cmd(outf, &args) != RUN_OK) {
failed(NULL);
Expand All @@ -909,10 +912,8 @@ static bool run_test(test_t *test)
if (test->heapsz != NULL)
push_arg(&args, "-H%s", test->heapsz);
}
else if (force_jit) {
else
push_arg(&args, "--no-save");
push_arg(&args, "--jit");
}

push_arg(&args, "-r");

Expand Down

0 comments on commit d220d91

Please sign in to comment.