Skip to content

Commit 2b617d6

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 8f15667 + 12b8253 commit 2b617d6

File tree

6 files changed

+20
-1
lines changed

6 files changed

+20
-1
lines changed

include/kllvm/codegen/Util.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ llvm::Function *get_or_insert_function(llvm::Module *module, Ts &&...args) {
4242

4343
char const *get_collection_alloc_fn(sort_category cat);
4444

45+
void insert_call_to_clear(llvm::BasicBlock *bb);
46+
4547
} // namespace kllvm
4648

4749
#endif // KLLVM_UTIL_H

include/runtime/alloc.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ void *kore_alloc_always_gc(size_t requested);
3737
// if the swapOld flag is set, it also swaps the two semispaces of the old
3838
// generation
3939
void kore_alloc_swap(bool swap_old);
40+
// resets the alwaysgcspace, freeing all memory allocated by it
41+
void kore_clear(void);
4042
// resizes the last allocation into the young generation
4143
void *kore_resize_last_alloc(void *oldptr, size_t newrequest, size_t last_size);
4244
// allocator hook for the GMP library

lib/codegen/Decision.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1156,6 +1156,7 @@ void make_step_function(
11561156

11571157
init_choice_buffer(
11581158
dt, module, block, pre_stuck, fail, &choice_buffer, &choice_depth, &jump);
1159+
insert_call_to_clear(block);
11591160

11601161
llvm::AllocaInst *has_search_results = nullptr;
11611162
if (search) {
@@ -1387,6 +1388,7 @@ void make_step_function(
13871388
init_choice_buffer(
13881389
res.dt, module, block, pre_stuck, fail, &choice_buffer, &choice_depth,
13891390
&jump);
1391+
insert_call_to_clear(block);
13901392

13911393
llvm::BranchInst::Create(stuck, pre_stuck);
13921394
std::vector<llvm::PHINode *> phis;

lib/codegen/Util.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,13 @@ char const *get_collection_alloc_fn(sort_category cat) {
6868
}
6969
}
7070

71+
void insert_call_to_clear(llvm::BasicBlock *bb) {
72+
llvm::Module *module = bb->getParent()->getParent();
73+
auto *kore_clear = get_or_insert_function(
74+
module, "kore_clear",
75+
llvm::FunctionType::get(
76+
llvm::Type::getVoidTy(module->getContext()), {}, false));
77+
llvm::CallInst::Create(kore_clear, {}, "", bb);
78+
}
79+
7180
} // namespace kllvm

runtime/alloc/alloc.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ bool youngspace_almost_full(size_t threshold) {
5858

5959
void kore_alloc_swap(bool swap_old) {
6060
arena_swap_and_clear(&youngspace);
61-
arena_clear(&alwaysgcspace);
6261
if (swap_old) {
6362
arena_swap_and_clear(&oldspace);
6463
}
6564
}
6665

66+
void kore_clear() {
67+
arena_clear(&alwaysgcspace);
68+
}
69+
6770
void set_kore_memory_functions_for_gmp() {
6871
mp_set_memory_functions(kore_alloc_mp, kore_realloc_mp, kore_free);
6972
}

runtime/collect/collect.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) {
354354

355355
void free_all_kore_mem() {
356356
kore_collect(nullptr, 0, nullptr);
357+
kore_clear();
357358
}
358359

359360
bool is_collection() {

0 commit comments

Comments
 (0)