py/emit: Suppress unreachable bytecode/native code that follows jump.
This new logic tracks when an unconditional jump/raise occurs in the
emitted code stream (bytecode or native machine code) and suppresses all
subsequent code, until a label is assigned. This eliminates a lot of
cases of dead code, with relatively simple logic.
This commit combined with the previous one (that removed the existing
dead-code finding logic) has the following code size change:
bare-arm: -16 -0.028%
minimal x86: -60 -0.036%
unix x64: -368 -0.070%
unix nanbox: -80 -0.017%
stm32: -204 -0.052% PYBV10
cc3200: +0 +0.000%
esp8266: -232 -0.033% GENERIC
esp32: -224 -0.015% GENERIC[incl -40(data)]
mimxrt: -192 -0.054% TEENSY40
renesas-ra: -200 -0.032% RA6M2_EK
nrf: +28 +0.015% pca10040
rp2: -256 -0.050% PICO
samd: -12 -0.009% ADAFRUIT_ITSYBITSY_M4_EXPRESS
Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
@@ -1966,6 +1966,7 @@ STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) {
|
||||
need_stack_settled(emit);
|
||||
ASM_JUMP(emit->as, label);
|
||||
emit_post(emit);
|
||||
mp_asm_base_suppress_code(&emit->as->base);
|
||||
}
|
||||
|
||||
STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) {
|
||||
@@ -2810,6 +2811,7 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) {
|
||||
}
|
||||
// TODO probably make this 1 call to the runtime (which could even call convert, native_raise(obj, type))
|
||||
emit_call(emit, MP_F_NATIVE_RAISE);
|
||||
mp_asm_base_suppress_code(&emit->as->base);
|
||||
}
|
||||
|
||||
STATIC void emit_native_yield(emit_t *emit, int kind) {
|
||||
|
||||
Reference in New Issue
Block a user