on master help sign in
i|javascript: make inliner more aggressive
commitaddaeecac5ba84a8f7a05c290926c01fdb21d4f2 authorraichoo <raichoo@googlemail.com> dateTue 21 Jan 2014, 19:29 (13 years ago) parentf5cad0d
1 file changed+16−8
src/IRTS/CodegenJavaScript.hs+16−8
src/IRTS/CodegenJavaScript.hs+16−8
@@ -314,6 +314,9 @@ jsSubst var new (JSIndex obj field) =
314314jsSubst var new (JSCond conds) =
315315 JSCond (map ((jsSubst var new) *** (jsSubst var new)) conds)
316316
317+jsSubst var new (JSAssign lhs rhs) =
318+ JSAssign (jsSubst var new lhs) (jsSubst var new rhs)
319+
317320jsSubst _ _ js = js
318321
319322
@@ -328,16 +331,24 @@ isJSConstant js
328331 | otherwise = False
329332
330333inlineJS :: JS -> JS
334+inlineJS (JSReturn (JSApp (JSFunction ["cse"] body) [val@(JSVar _)])) =
335+ inlineJS $ jsSubst "cse" val body
336+
337+inlineJS (JSReturn (JSApp (JSFunction [arg] cond@(JSCond _)) [val])) =
338+ JSSeq [ JSAlloc arg (Just (inlineJS val))
339+ , inlineJS cond
340+ ]
341+
331342inlineJS (JSApp (JSProj (JSFunction args (JSReturn body)) "apply") [
332− JSThis,JSProj (JSIdent var) "vars"
343+ JSThis,JSProj var "vars"
333344 ])
334− | var /= "cse" =
335− inlineApply args body 0
345+ | var /= JSIdent "cse" =
346+ inlineApply args body 0
336347 where
337− inlineApply [] body _ = body
348+ inlineApply [] body _ = inlineJS body
338349 inlineApply (a:as) body n =
339350 inlineApply as (
340− jsSubst a (JSIndex (JSProj (JSIdent var) "vars") (JSNum (JSInt n))) body
351+ jsSubst a (JSIndex (JSProj var "vars") (JSNum (JSInt n))) body
341352 ) (n + 1)
342353
343354inlineJS (JSApp (JSIdent "__IDR__mEVAL0") [val])
@@ -348,9 +359,6 @@ inlineJS (JSApp (JSIdent "__IDRRT__tailcall") [
348359 ])
349360 | isJSConstant val = val
350361
351−inlineJS (JSApp (JSFunction [] (JSSeq ret)) []) =
352− JSApp (JSFunction [] (JSSeq (map inlineJS ret))) []
353−
354362inlineJS (JSApp (JSFunction [arg] (JSReturn ret)) [val])
355363 | JSNew con [tag, vals] <- ret
356364 , opt <- inlineJS val =