Skip to content

Commit 0eaaf20

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 11eb950 commit 0eaaf20

File tree

2 files changed

+15
-16
lines changed

2 files changed

+15
-16
lines changed

src/gc-mmtk.c

-2
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

+15-14
Original file line numberDiff line numberDiff line change
@@ -2577,22 +2577,23 @@ bool LateLowerGCFrame::runOnFunction(Function &F, bool *CFGModified) {
25772577

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

2588-
Value *callee = CI->getCalledOperand();
2589-
assert(callee);
2590-
2591-
auto GCAllocBytes = getOrNull(jl_intrinsics::GCAllocBytes);
2592-
if (GCAllocBytes == callee) {
2582+
if (GCAllocBytes) {
2583+
for (auto it = GCAllocBytes->user_begin(); it != GCAllocBytes->user_end(); ) {
2584+
if (auto *CI = dyn_cast<CallInst>(*it)) {
25932585
*CFGModified = true;
2594-
replaceInstruction(CI, lowerGCAllocBytesLate(CI, F), it);
2595-
continue;
2586+
2587+
Value *callee = CI->getCalledOperand();
2588+
assert(callee == GCAllocBytes);
2589+
2590+
auto newI = lowerGCAllocBytesLate(CI, F);
2591+
if (newI != CI) {
2592+
++it;
2593+
CI->replaceAllUsesWith(newI);
2594+
CI->eraseFromParent();
2595+
continue;
2596+
}
25962597
}
25972598
++it;
25982599
}

0 commit comments

Comments
 (0)