Skip to content

Commit 84316bf

Browse files
committed
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 4f0f23b commit 84316bf

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
@@ -2598,22 +2598,23 @@ bool LateLowerGCFrame::runOnFunction(Function &F, bool *CFGModified) {
25982598

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

2609-
Value *callee = CI->getCalledOperand();
2610-
assert(callee);
2611-
2612-
auto GCAllocBytes = getOrNull(jl_intrinsics::GCAllocBytes);
2613-
if (GCAllocBytes == callee) {
2603+
if (GCAllocBytes) {
2604+
for (auto it = GCAllocBytes->user_begin(); it != GCAllocBytes->user_end(); ) {
2605+
if (auto *CI = dyn_cast<CallInst>(*it)) {
26142606
*CFGModified = true;
2615-
replaceInstruction(CI, lowerGCAllocBytesLate(CI, F), it);
2616-
continue;
2607+
2608+
Value *callee = CI->getCalledOperand();
2609+
assert(callee == GCAllocBytes);
2610+
2611+
auto newI = lowerGCAllocBytesLate(CI, F);
2612+
if (newI != CI) {
2613+
++it;
2614+
CI->replaceAllUsesWith(newI);
2615+
CI->eraseFromParent();
2616+
continue;
2617+
}
26172618
}
26182619
++it;
26192620
}

0 commit comments

Comments
 (0)