@@ -103,7 +103,6 @@ void FinalLowerGC::lowerNewGCFrame(CallInst *target, Function &F)
103
103
builder.CreateMemSet (gcframe, Constant::getNullValue (Type::getInt8Ty (F.getContext ())), ptrsize * (nRoots + 2 ), Align (16 ), tbaa_gcframe);
104
104
105
105
target->replaceAllUsesWith (gcframe);
106
- target->eraseFromParent ();
107
106
}
108
107
109
108
void FinalLowerGC::lowerPushGCFrame (CallInst *target, Function &F)
@@ -131,7 +130,6 @@ void FinalLowerGC::lowerPushGCFrame(CallInst *target, Function &F)
131
130
gcframe,
132
131
pgcstack,
133
132
Align (sizeof (void *)));
134
- target->eraseFromParent ();
135
133
}
136
134
137
135
void FinalLowerGC::lowerPopGCFrame (CallInst *target, Function &F)
@@ -150,7 +148,6 @@ void FinalLowerGC::lowerPopGCFrame(CallInst *target, Function &F)
150
148
pgcstack,
151
149
Align (sizeof (void *)));
152
150
inst->setMetadata (LLVMContext::MD_tbaa, tbaa_gcframe);
153
- target->eraseFromParent ();
154
151
}
155
152
156
153
void FinalLowerGC::lowerGetGCFrameSlot (CallInst *target, Function &F)
@@ -170,7 +167,6 @@ void FinalLowerGC::lowerGetGCFrameSlot(CallInst *target, Function &F)
170
167
auto gep = builder.CreateInBoundsGEP (T_prjlvalue, gcframe, index);
171
168
gep->takeName (target);
172
169
target->replaceAllUsesWith (gep);
173
- target->eraseFromParent ();
174
170
}
175
171
176
172
void FinalLowerGC::lowerQueueGCRoot (CallInst *target, Function &F)
@@ -187,7 +183,6 @@ void FinalLowerGC::lowerSafepoint(CallInst *target, Function &F)
187
183
IRBuilder<> builder (target);
188
184
Value* signal_page = target->getOperand (0 );
189
185
builder.CreateLoad (T_size, signal_page, true );
190
- target->eraseFromParent ();
191
186
}
192
187
193
188
#ifdef MMTK_GC
@@ -252,7 +247,7 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
252
247
253
248
// Should we generate fastpath allocation sequence here? We should always generate fastpath here for MMTk.
254
249
// Setting this to false will increase allocation overhead a lot, and should only be used for debugging.
255
- const bool INLINE_FASTPATH_ALLOCATION = true ;
250
+ const bool INLINE_FASTPATH_ALLOCATION = false ;
256
251
257
252
if (INLINE_FASTPATH_ALLOCATION) {
258
253
// Assuming we use the first immix allocator.
@@ -307,12 +302,12 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
307
302
builder.CreateStore (new_cursor, cursor_ptr);
308
303
309
304
// ptls->gc_num.allocd += osize;
310
- auto pool_alloc_pos = ConstantInt::get (Type::getInt64Ty (target->getContext ()), offsetof (jl_tls_states_t , gc_tls) + offsetof (jl_gc_tls_states_t , gc_num));
311
- auto pool_alloc_i8 = builder.CreateGEP (Type::getInt8Ty (target->getContext ()), ptls, pool_alloc_pos);
312
- auto pool_alloc_tls = builder.CreateBitCast (pool_alloc_i8, PointerType::get (Type::getInt64Ty (target->getContext ()), 0 ), " pool_alloc" );
313
- auto pool_allocd = builder.CreateLoad (Type::getInt64Ty (target->getContext ()), pool_alloc_tls);
314
- auto pool_allocd_total = builder.CreateAdd (pool_allocd, pool_osize);
315
- builder.CreateStore (pool_allocd_total, pool_alloc_tls);
305
+ // auto pool_alloc_pos = ConstantInt::get(Type::getInt64Ty(target->getContext()), offsetof(jl_tls_states_t, gc_tls) + offsetof(jl_gc_tls_states_t, gc_num));
306
+ // auto pool_alloc_i8 = builder.CreateGEP(Type::getInt8Ty(target->getContext()), ptls, pool_alloc_pos);
307
+ // auto pool_alloc_tls = builder.CreateBitCast(pool_alloc_i8, PointerType::get(Type::getInt64Ty(target->getContext()), 0), "pool_alloc");
308
+ // auto pool_allocd = builder.CreateLoad(Type::getInt64Ty(target->getContext()), pool_alloc_tls);
309
+ // auto pool_allocd_total = builder.CreateAdd(pool_allocd, pool_osize);
310
+ // builder.CreateStore(pool_allocd_total, pool_alloc_tls);
316
311
317
312
auto v_raw = builder.CreateNSWAdd (result, ConstantInt::get (Type::getInt64Ty (target->getContext ()), sizeof (jl_taggedvalue_t )));
318
313
auto v_as_ptr = builder.CreateIntToPtr (v_raw, poolAllocFunc->getReturnType ());
@@ -321,14 +316,14 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
321
316
phiNode->addIncoming (new_call, slowpath);
322
317
phiNode->addIncoming (v_as_ptr, fastpath);
323
318
phiNode->takeName (target);
324
-
319
+
325
320
target->replaceAllUsesWith (phiNode);
326
- target->eraseFromParent ();
327
321
return ;
328
322
} else {
329
323
auto pool_offs = ConstantInt::get (Type::getInt32Ty (F.getContext ()), 1 );
330
324
newI = builder.CreateCall (poolAllocFunc, { ptls, pool_offs, pool_osize_i32, type });
331
- derefBytes = sizeof (void *);
325
+ if (sz > 0 )
326
+ derefBytes = sz;
332
327
}
333
328
#endif // MMTK_GC
334
329
}
@@ -346,7 +341,6 @@ void FinalLowerGC::lowerGCAllocBytes(CallInst *target, Function &F)
346
341
newI->addDereferenceableRetAttr (derefBytes);
347
342
newI->takeName (target);
348
343
target->replaceAllUsesWith (newI);
349
- target->eraseFromParent ();
350
344
}
351
345
352
346
bool FinalLowerGC::runOnFunction (Function &F)
@@ -372,21 +366,23 @@ bool FinalLowerGC::runOnFunction(Function &F)
372
366
373
367
// Lower all calls to supported intrinsics.
374
368
for (auto &BB : F) {
375
- for (auto &I : make_early_inc_range (BB)) {
376
- auto *CI = dyn_cast<CallInst>(&I);
377
- if (!CI)
369
+ for (auto it = BB.begin (); it != BB.end ();) {
370
+ auto *CI = dyn_cast<CallInst>(&*it);
371
+ if (!CI) {
372
+ ++it;
378
373
continue ;
374
+ }
379
375
380
376
Value *callee = CI->getCalledOperand ();
381
377
assert (callee);
382
378
383
379
#define LOWER_INTRINSIC (INTRINSIC, LOWER_INTRINSIC_FUNC ) \
384
- do { \
385
- auto intrinsic = getOrNull (jl_intrinsics::INTRINSIC); \
386
- if (intrinsic == callee) { \
387
- LOWER_INTRINSIC_FUNC (CI, F ); \
388
- } \
389
- } while ( 0 )
380
+ auto INTRINSIC = getOrNull (jl_intrinsics::INTRINSIC); \
381
+ if (INTRINSIC == callee) { \
382
+ LOWER_INTRINSIC_FUNC (CI, F); \
383
+ it = CI-> eraseFromParent ( ); \
384
+ continue ; \
385
+ } \
390
386
391
387
LOWER_INTRINSIC (newGCFrame, lowerNewGCFrame);
392
388
LOWER_INTRINSIC (pushGCFrame, lowerPushGCFrame);
@@ -396,14 +392,13 @@ bool FinalLowerGC::runOnFunction(Function &F)
396
392
LOWER_INTRINSIC (queueGCRoot, lowerQueueGCRoot);
397
393
LOWER_INTRINSIC (safepoint, lowerSafepoint);
398
394
399
-
400
395
#ifdef MMTK_GC
401
396
LOWER_INTRINSIC (writeBarrier1, lowerWriteBarrier1);
402
397
LOWER_INTRINSIC (writeBarrier2, lowerWriteBarrier2);
403
398
LOWER_INTRINSIC (writeBarrier1Slow, lowerWriteBarrier1Slow);
404
399
LOWER_INTRINSIC (writeBarrier2Slow, lowerWriteBarrier2Slow);
405
400
#endif
406
-
401
+ ++it;
407
402
408
403
#undef LOWER_INTRINSIC
409
404
}
0 commit comments