Skip to content

Commit 71b6b9b

Browse files
oharboeclaude
andcommitted
flow: write failed.odb/.sdc when any step fails
A failure .odb saves running a step again to see the state it failed in. Until now a few hand-picked calls wrote one; any other failure left nothing. flow.sh now runs each step's script through run_step.tcl. With WRITE_ON_FAILURE=1, the default, an error anywhere in the step writes $RESULTS_DIR/failed.sdc and failed.odb, then the step fails with the original error. `make web_failed.odb` opens it through the existing RESULTS_ODB wildcard. flow.sh removes a checkpoint left by an earlier step, so the files always belong to the last failure. Signed-off-by: Øyvind Harboe <oyvind.harboe@zylin.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 2385fd3 commit 71b6b9b

6 files changed

Lines changed: 49 additions & 5 deletions

File tree

‎docs/contrib/MakefileContract.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,9 @@ Several of the rules exist for them.
7979
variable and is recorded.
8080
*Breaks:* caching a step's result, the QoR check against a baseline, and
8181
bisecting a regression.
82-
- **A failing step never calls `exit`.** It writes `<step>-failed.odb` and
83-
calls `error`, as `flow/scripts/global_place.tcl` does.
82+
- **A failing step never calls `exit`.** It calls `error`, and
83+
`flow/scripts/run_step.tcl` writes `failed.odb` and `failed.sdc`
84+
(`WRITE_ON_FAILURE`).
8485
*Breaks:* the log and the exit status stop saying where the step failed,
8586
and there is no checkpoint to inspect.
8687
- **A `PRE_<STEP>_TCL` hook never runs before the design is loaded.** Hooks

‎docs/contrib/TclContract.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ to follow.
7070
*Breaks:* the guard is a code path no CI run exercises, and a missing
7171
variable or file shows up later, somewhere else, as a wrong result.
7272
- **A failing step never writes the file a successful step writes.** It
73-
writes `<step>-failed.odb` and calls `error`, as
74-
`flow/scripts/global_place.tcl` does.
73+
calls `error`, and `flow/scripts/run_step.tcl` writes `failed.odb` and
74+
`failed.sdc` (`WRITE_ON_FAILURE`).
7575
*Breaks:* make, and any flow built on it, takes the file as proof that the
7676
step succeeded.
7777
- **A script never adds error numbers or checks that belong in OpenROAD.**

‎docs/user/FlowVariables.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ configuration file.
350350
| <a name="VIA_IN_PIN_MIN_LAYER"></a>VIA_IN_PIN_MIN_LAYER| Passed as -via_in_pin_bottom_layer to pin_access and detailed_route.| |
351351
| <a name="WIRE_LOAD_MODEL"></a>WIRE_LOAD_MODEL| Name of a Liberty wire_load group applied with set_wire_load_model whenever open.tcl reads timing. OpenSTA applies a wire-load model only to nets without parasitics, so it gives wire delay to timing read before placement and leaves placed and routed timing unaffected. An unknown name is an error. Empty, the default, applies none. A platform whose libraries define no wire_load group can supply one in a Liberty file listed in ADDITIONAL_LIBS.| |
352352
| <a name="WRITE_ODB_AND_SDC_EACH_STAGE"></a>WRITE_ODB_AND_SDC_EACH_STAGE| Save out .sdc and .odb file after each stage, useful to disable when using a single OpenROAD instance to run all stages of the flow.| 1|
353+
| <a name="WRITE_ON_FAILURE"></a>WRITE_ON_FAILURE| If set to 1, a step that fails writes the design as it was at the failure to $RESULTS_DIR/failed.odb and failed.sdc, then fails with the original error. `make web_failed.odb` opens it. Set to 0 where writing a large design on failure costs too much time or disk.| 1|
353354
| <a name="YOSYS_FLAGS"></a>YOSYS_FLAGS| Flags to pass to yosys.| -v 3|
354355
## synth variables
355356

@@ -673,6 +674,7 @@ configuration file.
673674
- [SWAP_ARITH_OPERATORS](#SWAP_ARITH_OPERATORS)
674675
- [SYNTH_WRAPPED_OPERATORS](#SYNTH_WRAPPED_OPERATORS)
675676
- [WRITE_ODB_AND_SDC_EACH_STAGE](#WRITE_ODB_AND_SDC_EACH_STAGE)
677+
- [WRITE_ON_FAILURE](#WRITE_ON_FAILURE)
676678

677679
## generate_abstract variables
678680

‎flow/scripts/flow.sh‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,19 @@ RUN_CMD="${RUN_CMD:-$PYTHON_EXE $SCRIPTS_DIR/run_command.py}"
1010

1111
echo "Running $2.tcl, stage $1"
1212

13+
# A failure checkpoint belongs to the step that failed last; one left by
14+
# an earlier run is not this step's.
15+
rm -f "$RESULTS_DIR/failed.odb" "$RESULTS_DIR/failed.sdc"
16+
1317
(
1418
trap 'mv "$LOG_DIR/$1.tmp.log" "$LOG_DIR/$1.log"' EXIT
19+
export STEP_TCL="$SCRIPTS_DIR/$2.tcl"
1520

1621
eval "$OPENROAD_EXE $OPENROAD_ARGS -exit \"$SCRIPTS_DIR/noop.tcl\"" \
1722
>"$LOG_DIR/$1.tmp.log" 2>&1
1823

1924
$RUN_CMD --log "$(realpath "$LOG_DIR/$1.tmp.log")" --append --tee -- \
20-
$OPENROAD_CMD -no_splash "$SCRIPTS_DIR/$2.tcl" -metrics "$LOG_DIR/$1.json"
25+
$OPENROAD_CMD -no_splash "$SCRIPTS_DIR/run_step.tcl" -metrics "$LOG_DIR/$1.json"
2126
)
2227

2328
# Log the hash for this step. The summary "make elapsed" in "make finish",

‎flow/scripts/run_step.tcl‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Runs one step's script, $STEP_TCL, for flow.sh. With WRITE_ON_FAILURE=1,
2+
# an error anywhere in the step writes the design as it was at the failure
3+
# to $RESULTS_DIR/failed.odb and failed.sdc, so it can be inspected without
4+
# running the step again; the step then fails with the original error.
5+
6+
proc write_failure_checkpoint { } {
7+
if { !$::env(WRITE_ON_FAILURE) } {
8+
return
9+
}
10+
set chip [[ord::get_db] getChip]
11+
if { $chip == "NULL" || [$chip getBlock] == "NULL" } {
12+
puts "No design loaded, no failure checkpoint written"
13+
return
14+
}
15+
puts "Writing failure checkpoint $::env(RESULTS_DIR)/failed.odb"
16+
write_sdc -no_timestamp $::env(RESULTS_DIR)/failed.sdc
17+
write_db $::env(RESULTS_DIR)/failed.odb
18+
}
19+
20+
if { [catch { uplevel #0 [list source $::env(STEP_TCL)] } msg opts] } {
21+
set info [dict get $opts -errorinfo]
22+
set code [dict get $opts -errorcode]
23+
if { [catch { write_failure_checkpoint } checkpoint_error] } {
24+
puts "Warning: failure checkpoint not written: $checkpoint_error"
25+
}
26+
error $msg $info $code
27+
}

‎flow/scripts/variables.yaml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1764,6 +1764,15 @@ WRITE_ODB_AND_SDC_EACH_STAGE:
17641764
stages:
17651765
- All stages
17661766
default: 1
1767+
WRITE_ON_FAILURE:
1768+
description: >
1769+
If set to 1, a step that fails writes the design as it was at the
1770+
failure to $RESULTS_DIR/failed.odb and failed.sdc, then fails with
1771+
the original error. `make web_failed.odb` opens it. Set to 0 where
1772+
writing a large design on failure costs too much time or disk.
1773+
stages:
1774+
- All stages
1775+
default: 1
17671776
LEC_CHECK:
17681777
description: >
17691778
Perform formal equivalence checks between before and after netlists.

0 commit comments

Comments
 (0)