Mercurial > urweb
comparison src/mono_reduce.sml @ 1820:3c56aa6a0f55
Reduce default inlining thresholds; improve a let-substitution optimization to compensate
author | Adam Chlipala <adam@chlipala.net> |
---|---|
date | Fri, 14 Sep 2012 07:35:48 -0400 |
parents | 148203744882 |
children | 216e92b39fc1 |
comparison
equal
deleted
inserted
replaced
1819:c9c38157d0d3 | 1820:3c56aa6a0f55 |
---|---|
311 fun reduce file = | 311 fun reduce file = |
312 let | 312 let |
313 val (timpures, impures, absCounts) = | 313 val (timpures, impures, absCounts) = |
314 foldl (fn ((d, _), (timpures, impures, absCounts)) => | 314 foldl (fn ((d, _), (timpures, impures, absCounts)) => |
315 let | 315 let |
316 fun countAbs (e, _) = | 316 fun countAbs env e = |
317 case e of | 317 case #1 e of |
318 EAbs (_, _, _, e) => 1 + countAbs e | 318 EAbs (x, t, _, e) => 1 + countAbs (E.pushERel env x t NONE) e |
319 | _ => 0 | 319 | _ => |
320 let | |
321 fun remaining e = | |
322 case #1 e of | |
323 ENamed n => IM.find (absCounts, n) | |
324 | EApp (e, arg) => | |
325 if simpleImpure (timpures, impures) env arg then | |
326 NONE | |
327 else | |
328 (case remaining e of | |
329 NONE => NONE | |
330 | SOME n => if n > 0 then | |
331 SOME (n - 1) | |
332 else | |
333 NONE) | |
334 | _ => NONE | |
335 in | |
336 getOpt (remaining e, 0) | |
337 end | |
320 in | 338 in |
321 case d of | 339 case d of |
322 DDatatype dts => | 340 DDatatype dts => |
323 (if List.exists (fn (_, _, cs) => | 341 (if List.exists (fn (_, _, cs) => |
324 List.exists (fn (_, _, NONE) => false | 342 List.exists (fn (_, _, NONE) => false |
333 (timpures, | 351 (timpures, |
334 if simpleImpure (timpures, impures) E.empty e then | 352 if simpleImpure (timpures, impures) E.empty e then |
335 IS.add (impures, n) | 353 IS.add (impures, n) |
336 else | 354 else |
337 impures, | 355 impures, |
338 IM.insert (absCounts, n, countAbs e)) | 356 IM.insert (absCounts, n, countAbs E.empty e)) |
339 | DValRec vis => | 357 | DValRec vis => |
340 (timpures, | 358 (timpures, |
341 if List.exists (fn (_, _, _, e, _) => simpleImpure (timpures, impures) E.empty e) vis then | 359 if List.exists (fn (_, _, _, e, _) => simpleImpure (timpures, impures) E.empty e) vis then |
342 foldl (fn ((_, n, _, _, _), impures) => | 360 foldl (fn ((_, n, _, _, _), impures) => |
343 IS.add (impures, n)) impures vis | 361 IS.add (impures, n)) impures vis |
344 else | 362 else |
345 impures, | 363 impures, |
346 foldl (fn ((x, n, _, e, _), absCounts) => | 364 foldl (fn ((x, n, _, e, _), absCounts) => |
347 IM.insert (absCounts, n, countAbs e)) | 365 IM.insert (absCounts, n, countAbs E.empty e)) |
348 absCounts vis) | 366 absCounts vis) |
349 | _ => (timpures, impures, absCounts) | 367 | _ => (timpures, impures, absCounts) |
350 end) | 368 end) |
351 (IS.empty, IS.empty, IM.empty) file | 369 (IS.empty, IS.empty, IM.empty) file |
352 | 370 |