mirror of
https://github.com/justinethier/cyclone.git
synced 2025-07-15 16:57:35 +02:00
Allow inline of ref for an if condition
If the if condition is a single ref, it should be OK to inline that.
This commit is contained in:
parent
7538d90b63
commit
e97234905a
1 changed files with 35 additions and 1 deletions
|
@ -497,6 +497,38 @@
|
||||||
)
|
)
|
||||||
;; Check for primitive calls that can be optimized out
|
;; Check for primitive calls that can be optimized out
|
||||||
(and
|
(and
|
||||||
|
#;(begin
|
||||||
|
(trace:error `(DEBUG
|
||||||
|
,exp
|
||||||
|
,(every
|
||||||
|
(lambda (param)
|
||||||
|
(with-var param (lambda (var)
|
||||||
|
;(trace:error `(DEBUG ,param ,(adbv:ref-by var)))
|
||||||
|
(and
|
||||||
|
;; If param is never referenced, then prim is being
|
||||||
|
;; called for side effects, possibly on a global
|
||||||
|
(not (null? (adbv:ref-by var)))
|
||||||
|
;; Need to keep variable because it is mutated
|
||||||
|
(not (adbv:reassigned? var))
|
||||||
|
))))
|
||||||
|
(ast:lambda-formals->list (car exp)))
|
||||||
|
;; Check all args are valid primitives that can be inlined
|
||||||
|
,(every
|
||||||
|
(lambda (arg)
|
||||||
|
(and (prim-call? arg)
|
||||||
|
(not (prim:cont? (car arg)))))
|
||||||
|
(cdr exp))
|
||||||
|
;; Disallow primitives that allocate a new obj,
|
||||||
|
;; because if the object is mutated all copies
|
||||||
|
;; must be modified.
|
||||||
|
,(one-instance-of-new-mutable-obj?
|
||||||
|
(cdr exp)
|
||||||
|
(ast:lambda-formals->list (car exp)))
|
||||||
|
,(inline-prim-call?
|
||||||
|
(ast:lambda-body (car exp))
|
||||||
|
(prim-calls->arg-variables (cdr exp))
|
||||||
|
(ast:lambda-formals->list (car exp)))))
|
||||||
|
#t)
|
||||||
;; Double-check parameter can be optimized-out
|
;; Double-check parameter can be optimized-out
|
||||||
(every
|
(every
|
||||||
(lambda (param)
|
(lambda (param)
|
||||||
|
@ -628,6 +660,7 @@
|
||||||
((member exp args)
|
((member exp args)
|
||||||
(set-car! arg-used #t))
|
(set-car! arg-used #t))
|
||||||
((member exp ivars)
|
((member exp ivars)
|
||||||
|
;;(trace:error `(inline-ok? return #f ,exp ,ivars ,args))
|
||||||
(return #f))
|
(return #f))
|
||||||
(else
|
(else
|
||||||
#t)))
|
#t)))
|
||||||
|
@ -649,7 +682,8 @@
|
||||||
(inline-ok? (set!->var exp) ivars args arg-used return)
|
(inline-ok? (set!->var exp) ivars args arg-used return)
|
||||||
(inline-ok? (set!->exp exp) ivars args arg-used return))
|
(inline-ok? (set!->exp exp) ivars args arg-used return))
|
||||||
((if? exp)
|
((if? exp)
|
||||||
(inline-ok? (if->condition exp) ivars args arg-used return)
|
(if (not (ref? (if->condition exp)))
|
||||||
|
(inline-ok? (if->condition exp) ivars args arg-used return))
|
||||||
(inline-ok? (if->then exp) ivars args arg-used return)
|
(inline-ok? (if->then exp) ivars args arg-used return)
|
||||||
(inline-ok? (if->else exp) ivars args arg-used return))
|
(inline-ok? (if->else exp) ivars args arg-used return))
|
||||||
((app? exp)
|
((app? exp)
|
||||||
|
|
Loading…
Add table
Reference in a new issue