Reclaim unused memory after i-sel
fcb3c9b35f20da1d396ab756d7ff877f529f3a532067bd697e459ed3c46623a4
Re-use memory for function instruction selection.
1 parent
9cb6526b
lib/std/arch/rv64.rad
+4 -0
| 336 | 336 | let dataSyms = storage.dataSyms[..dataSymCount]; |
|
| 337 | 337 | ||
| 338 | 338 | for i in 0..program.fns.len { |
|
| 339 | 339 | let func = program.fns[i]; |
|
| 340 | 340 | if not func.isExtern { |
|
| 341 | + | let checkpoint = alloc::save(arena); |
|
| 341 | 342 | let ralloc = try! regalloc::allocate(func, &config, arena); |
|
| 342 | 343 | isel::selectFn(&mut e, dataSyms, &ralloc, func); |
|
| 344 | + | ||
| 345 | + | // Reclaim unused memory after instruction selection. |
|
| 346 | + | alloc::restore(arena, checkpoint); |
|
| 343 | 347 | } |
|
| 344 | 348 | } |
|
| 345 | 349 | // Patch entry jump now that we know where the default function is. |
|
| 346 | 350 | // Nb. we use a two-instruction jump even if it isn't always needed. |
|
| 347 | 351 | if let target = defaultName { |
lib/std/lang/alloc.rad
+11 -0
| 57 | 57 | /// Does not zero the memory. |
|
| 58 | 58 | pub fn reset(arena: *mut Arena) { |
|
| 59 | 59 | arena.offset = 0; |
|
| 60 | 60 | } |
|
| 61 | 61 | ||
| 62 | + | /// Save the current arena state for later restoration. |
|
| 63 | + | pub fn save(arena: *Arena) -> u32 { |
|
| 64 | + | return arena.offset; |
|
| 65 | + | } |
|
| 66 | + | ||
| 67 | + | /// Restore the arena to a previously saved state, reclaiming all |
|
| 68 | + | /// allocations made since that point. |
|
| 69 | + | pub fn restore(arena: *mut Arena, savedOffset: u32) { |
|
| 70 | + | arena.offset = savedOffset; |
|
| 71 | + | } |
|
| 72 | + | ||
| 62 | 73 | /// Returns the number of bytes currently allocated. |
|
| 63 | 74 | pub fn used(arena: *Arena) -> u32 { |
|
| 64 | 75 | return arena.offset; |
|
| 65 | 76 | } |
|
| 66 | 77 |