From 07aee7525f51d0ddc5aa90574293f2cad8a7db67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Sun, 27 Mar 2016 19:14:29 +0200 Subject: [PATCH] compiler.cfg.save-contexts: ##save-context isn't need in front of ##call-gc The reason is because the minor-gc primitive itself saves the context. Not inlining context saves, saves 20 bytes/call site. --- .../compiler/cfg/save-contexts/save-contexts-docs.factor | 7 ++++--- .../compiler/cfg/save-contexts/save-contexts-tests.factor | 3 ++- basis/compiler/cfg/save-contexts/save-contexts.factor | 8 +++++++- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/basis/compiler/cfg/save-contexts/save-contexts-docs.factor b/basis/compiler/cfg/save-contexts/save-contexts-docs.factor index c2ccd26ec5..20c8001163 100644 --- a/basis/compiler/cfg/save-contexts/save-contexts-docs.factor +++ b/basis/compiler/cfg/save-contexts/save-contexts-docs.factor @@ -1,5 +1,5 @@ USING: compiler.cfg compiler.cfg.instructions help.markup help.syntax -math sequences kernel ; +kernel math memory sequences ; IN: compiler.cfg.save-contexts HELP: insert-save-contexts @@ -17,9 +17,10 @@ HELP: save-context-offset { $description { $link ##save-context } " must be placed after instructions that modify the context, or instructions that read parameter registers." } ; ARTICLE: "compiler.cfg.save-contexts" "Insert context saves" -"Inserts " { $link ##save-context } " in blocks that need them." +"Inserts " { $link ##save-context } " in blocks that need them. If an instruction does something that might trigger a GC sweep, such as calling a C function, then the context must be saved before." $nl "Main word:" -{ $subsections insert-save-contexts } ; +{ $subsections insert-save-contexts } +{ $notes "The " { ##call-gc } " instruction does not need a context save because the primitive implementing the instruction (" { $link minor-gc } ") already saves the context for us." } ; ABOUT: "compiler.cfg.save-contexts" diff --git a/basis/compiler/cfg/save-contexts/save-contexts-tests.factor b/basis/compiler/cfg/save-contexts/save-contexts-tests.factor index b42bd3f5d3..b54bda7334 100644 --- a/basis/compiler/cfg/save-contexts/save-contexts-tests.factor +++ b/basis/compiler/cfg/save-contexts/save-contexts-tests.factor @@ -5,7 +5,7 @@ cpu.x86.assembler.operands cpu.architecture ; IN: compiler.cfg.save-contexts.tests ! insns-needs-save-context? -{ t f } [ +{ f f t } [ { T{ ##call-gc } } insns-needs-save-context? @@ -13,6 +13,7 @@ IN: compiler.cfg.save-contexts.tests T{ ##add f 1 2 3 } T{ ##branch } } insns-needs-save-context? + { T{ ##alien-invoke } } insns-needs-save-context? ] unit-test H{ } clone representations set diff --git a/basis/compiler/cfg/save-contexts/save-contexts.factor b/basis/compiler/cfg/save-contexts/save-contexts.factor index ef7474395f..19f43bfc11 100644 --- a/basis/compiler/cfg/save-contexts/save-contexts.factor +++ b/basis/compiler/cfg/save-contexts/save-contexts.factor @@ -9,8 +9,14 @@ UNION: context-modifier ##phi ##inc ##callback-inputs ; : save-context-offset ( insns -- n ) [ context-modifier? not ] find drop ; +UNION: needs-save-context-insn + ##alien-invoke + ##alien-indirect + ##box-long-long + ##box ; + : insns-needs-save-context? ( insns -- ? ) - [ gc-map-insn? ] any? ; + [ needs-save-context-insn? ] any? ; : insert-save-context ( insns -- insns' ) dup insns-needs-save-context? [