Skip to content

Commit

Permalink
Using LLVM uses instead of going through every instruction (#74)
Browse files Browse the repository at this point in the history
* Adding support for MMTk (non-moving Immix)

* Replacing loop over instructions by loop over uses

* Minor

* Incrementing the iterator before erasing the instruction

* Minor
  • Loading branch information
udesou authored Nov 27, 2024
1 parent 2adbdb4 commit 67b2ec1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/gc-mmtk.c
Original file line number Diff line number Diff line change
Expand Up @@ -946,8 +946,6 @@ inline jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
return v;
}



// allocation wrappers that track allocation and let collection run
JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
{
Expand Down
29 changes: 15 additions & 14 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2607,22 +2607,23 @@ bool LateLowerGCFrame::runOnFunction(Function &F, bool *CFGModified) {

#ifdef MMTK_GC
// We lower the julia.gc_alloc_bytes intrinsic in this pass to insert slowpath/fastpath blocks for MMTk
for (BasicBlock &BB : F) {
for (auto it = BB.begin(); it != BB.end();) {
auto *CI = dyn_cast<CallInst>(&*it);
if (!CI) {
++it;
continue;
}
auto GCAllocBytes = getOrNull(jl_intrinsics::GCAllocBytes);

Value *callee = CI->getCalledOperand();
assert(callee);

auto GCAllocBytes = getOrNull(jl_intrinsics::GCAllocBytes);
if (GCAllocBytes == callee) {
if (GCAllocBytes) {
for (auto it = GCAllocBytes->user_begin(); it != GCAllocBytes->user_end(); ) {
if (auto *CI = dyn_cast<CallInst>(*it)) {
*CFGModified = true;
replaceInstruction(CI, lowerGCAllocBytesLate(CI, F), it);
continue;

Value *callee = CI->getCalledOperand();
assert(callee == GCAllocBytes);

auto newI = lowerGCAllocBytesLate(CI, F);
if (newI != CI) {
++it;
CI->replaceAllUsesWith(newI);
CI->eraseFromParent();
continue;
}
}
++it;
}
Expand Down

0 comments on commit 67b2ec1

Please sign in to comment.