Skip to content

Commit 67b2ec1

Browse files
authored
Using LLVM uses instead of going through every instruction (#74)
* Adding support for MMTk (non-moving Immix) * Replacing loop over instructions by loop over uses * Minor * Incrementing the iterator before erasing the instruction * Minor
1 parent 2adbdb4 commit 67b2ec1

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/gc-mmtk.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,6 @@ inline jl_value_t *jl_gc_alloc_(jl_ptls_t ptls, size_t sz, void *ty)
946946
return v;
947947
}
948948

949-
950-
951949
// allocation wrappers that track allocation and let collection run
952950
JL_DLLEXPORT void *jl_gc_counted_malloc(size_t sz)
953951
{

src/llvm-late-gc-lowering.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2607,22 +2607,23 @@ bool LateLowerGCFrame::runOnFunction(Function &F, bool *CFGModified) {
26072607

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

2618-
Value *callee = CI->getCalledOperand();
2619-
assert(callee);
2620-
2621-
auto GCAllocBytes = getOrNull(jl_intrinsics::GCAllocBytes);
2622-
if (GCAllocBytes == callee) {
2612+
if (GCAllocBytes) {
2613+
for (auto it = GCAllocBytes->user_begin(); it != GCAllocBytes->user_end(); ) {
2614+
if (auto *CI = dyn_cast<CallInst>(*it)) {
26232615
*CFGModified = true;
2624-
replaceInstruction(CI, lowerGCAllocBytesLate(CI, F), it);
2625-
continue;
2616+
2617+
Value *callee = CI->getCalledOperand();
2618+
assert(callee == GCAllocBytes);
2619+
2620+
auto newI = lowerGCAllocBytesLate(CI, F);
2621+
if (newI != CI) {
2622+
++it;
2623+
CI->replaceAllUsesWith(newI);
2624+
CI->eraseFromParent();
2625+
continue;
2626+
}
26262627
}
26272628
++it;
26282629
}

0 commit comments

Comments
 (0)