From aca610813d6a8839b4afec6f5fc7fb77e54be7cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Lindqvist?= Date: Mon, 27 Jul 2015 11:26:48 +0200 Subject: [PATCH] compiler.cfg.representations.selection: use a union instead of a generic to see if an insn is peephole-optimizable + test --- .../selection/selection-tests.factor | 9 ++++ .../selection/selection.factor | 50 +++++++++---------- 2 files changed, 33 insertions(+), 26 deletions(-) create mode 100644 basis/compiler/cfg/representations/selection/selection-tests.factor diff --git a/basis/compiler/cfg/representations/selection/selection-tests.factor b/basis/compiler/cfg/representations/selection/selection-tests.factor new file mode 100644 index 0000000000..f853e2dfdf --- /dev/null +++ b/basis/compiler/cfg/representations/selection/selection-tests.factor @@ -0,0 +1,9 @@ +USING: compiler.cfg.instructions +compiler.cfg.representations.selection tools.test ; +IN: compiler.cfg.representations.selection.tests + +{ t t f } [ + T{ ##load-integer } peephole-optimizable? + T{ ##shr-imm } peephole-optimizable? + T{ ##call } peephole-optimizable? +] unit-test diff --git a/basis/compiler/cfg/representations/selection/selection.factor b/basis/compiler/cfg/representations/selection/selection.factor index 81e8fb6048..1175113774 100644 --- a/basis/compiler/cfg/representations/selection/selection.factor +++ b/basis/compiler/cfg/representations/selection/selection.factor @@ -88,39 +88,37 @@ UNION: inert-arithmetic-tag-untag-insn ##sub-imm ; UNION: inert-bitwise-tag-untag-insn -##and-imm -##or-imm -##xor-imm ; + ##and-imm + ##or-imm + ##xor-imm ; -GENERIC: has-peephole-opts? ( insn -- ? ) - -M: insn has-peephole-opts? drop f ; -M: ##load-integer has-peephole-opts? drop t ; -M: ##load-reference has-peephole-opts? drop t ; -M: ##neg has-peephole-opts? drop t ; -M: ##not has-peephole-opts? drop t ; -M: inert-tag-untag-insn has-peephole-opts? drop t ; -M: inert-arithmetic-tag-untag-insn has-peephole-opts? drop t ; -M: inert-bitwise-tag-untag-insn has-peephole-opts? drop t ; -M: ##mul-imm has-peephole-opts? drop t ; -M: ##shl-imm has-peephole-opts? drop t ; -M: ##shr-imm has-peephole-opts? drop t ; -M: ##sar-imm has-peephole-opts? drop t ; -M: ##compare-integer-imm has-peephole-opts? drop t ; -M: ##compare-integer has-peephole-opts? drop t ; -M: ##compare-integer-imm-branch has-peephole-opts? drop t ; -M: ##compare-integer-branch has-peephole-opts? drop t ; -M: ##test-imm has-peephole-opts? drop t ; -M: ##test has-peephole-opts? drop t ; -M: ##test-imm-branch has-peephole-opts? drop t ; -M: ##test-branch has-peephole-opts? drop t ; +UNION: peephole-optimizable + ##load-integer + ##load-reference + ##neg + ##not + inert-tag-untag-insn + inert-arithmetic-tag-untag-insn + inert-bitwise-tag-untag-insn + ##mul-imm + ##shl-imm + ##shr-imm + ##sar-imm + ##compare-integer-imm + ##compare-integer + ##compare-integer-imm-branch + ##compare-integer-branch + ##test-imm + ##test + ##test-imm-branch + ##test-branch ; GENERIC: compute-insn-costs ( insn -- ) M: insn compute-insn-costs drop ; M: vreg-insn compute-insn-costs - dup has-peephole-opts? 2 5 ? '[ _ increase-costs ] each-rep ; + dup peephole-optimizable? 2 5 ? '[ _ increase-costs ] each-rep ; : compute-costs ( cfg -- ) init-costs