@@ -8267,18 +8267,18 @@ static jl_llvm_functions_t
8267
8267
8268
8268
// step 7. allocate local variables slots
8269
8269
// must be in the first basic block for the llvm mem2reg pass to work
8270
- auto allocate_local = [&](jl_varinfo_t &varinfo, jl_sym_t *s) {
8270
+ auto allocate_local = [&ctx, &dbuilder, &debuginfo, topdebugloc, va, debug_enabled, M ](jl_varinfo_t &varinfo, jl_sym_t *s, int i ) {
8271
8271
jl_value_t *jt = varinfo.value.typ;
8272
8272
assert(!varinfo.boxroot); // variables shouldn't have memory locs already
8273
8273
if (varinfo.value.constant) {
8274
8274
// no need to explicitly load/store a constant/ghost value
8275
8275
alloc_def_flag(ctx, varinfo);
8276
8276
return;
8277
8277
}
8278
- else if (varinfo.isArgument && !(specsig && i == ( size_t ) ctx.vaSlot )) {
8279
- // if we can unbox it, just use the input pointer
8280
- if (i != ( size_t )ctx. vaSlot && jl_is_concrete_immutable (jt) )
8281
- return ;
8278
+ else if (varinfo.isArgument && (!va || ctx.vaSlot == -1 || i != ctx.vaSlot)) {
8279
+ // just use the input pointer, if we have it
8280
+ // (we will need to attach debuginfo later to it )
8281
+ return;
8282
8282
}
8283
8283
else if (jl_is_uniontype(jt)) {
8284
8284
bool allunbox;
@@ -8289,6 +8289,7 @@ static jl_llvm_functions_t
8289
8289
varinfo.value = mark_julia_slot(lv, jt, NULL, ctx.tbaa().tbaa_stack);
8290
8290
varinfo.pTIndex = emit_static_alloca(ctx, getInt8Ty(ctx.builder.getContext()));
8291
8291
setName(ctx.emission_context, varinfo.pTIndex, "tindex");
8292
+ // TODO: attach debug metadata to this variable
8292
8293
}
8293
8294
else if (allunbox) {
8294
8295
// all ghost values just need a selector allocated
@@ -8297,6 +8298,7 @@ static jl_llvm_functions_t
8297
8298
varinfo.pTIndex = lv;
8298
8299
varinfo.value.tbaa = NULL;
8299
8300
varinfo.value.isboxed = false;
8301
+ // TODO: attach debug metadata to this variable
8300
8302
}
8301
8303
if (lv || allunbox)
8302
8304
alloc_def_flag(ctx, varinfo);
@@ -8323,29 +8325,21 @@ static jl_llvm_functions_t
8323
8325
}
8324
8326
return;
8325
8327
}
8326
- if (!varinfo.isArgument || // always need a slot if the variable is assigned
8327
- specsig || // for arguments, give them stack slots if they aren't in `argArray` (otherwise, will use that pointer)
8328
- (va && (int )i == ctx.vaSlot ) || // or it's the va arg tuple
8329
- i == 0 ) { // or it is the first argument (which isn't in `argArray`)
8330
- AllocaInst *av = new AllocaInst (ctx.types ().T_prjlvalue , M->getDataLayout ().getAllocaAddrSpace (),
8331
- nullptr , Align (sizeof (jl_value_t *)), jl_symbol_name (s), /* InsertBefore*/ ctx.topalloca );
8332
- StoreInst *SI = new StoreInst (Constant::getNullValue (ctx.types ().T_prjlvalue ), av, false , Align (sizeof (void *)));
8333
- SI->insertAfter (ctx.topalloca );
8334
- varinfo.boxroot = av;
8335
- if (debug_enabled && varinfo.dinfo ) {
8336
- DIExpression *expr;
8337
- if ((Metadata*)varinfo.dinfo ->getType () == debuginfo.jl_pvalue_dillvmt ) {
8338
- expr = dbuilder.createExpression ();
8339
- }
8340
- else {
8341
- SmallVector<uint64_t , 8 > addr;
8342
- addr.push_back (llvm::dwarf::DW_OP_deref);
8343
- expr = dbuilder.createExpression (addr);
8344
- }
8345
- dbuilder.insertDeclare (av, varinfo.dinfo , expr,
8346
- topdebugloc,
8347
- ctx.builder .GetInsertBlock ());
8348
- }
8328
+ // otherwise give it a boxroot in this function
8329
+ AllocaInst *av = new AllocaInst(ctx.types().T_prjlvalue, M->getDataLayout().getAllocaAddrSpace(),
8330
+ nullptr, Align(sizeof(jl_value_t*)), jl_symbol_name(s), /*InsertBefore*/ctx.topalloca);
8331
+ StoreInst *SI = new StoreInst(Constant::getNullValue(ctx.types().T_prjlvalue), av, false, Align(sizeof(void*)));
8332
+ SI->insertAfter(ctx.topalloca);
8333
+ varinfo.boxroot = av;
8334
+ if (debug_enabled && varinfo.dinfo) {
8335
+ SmallVector<uint64_t, 1> addr;
8336
+ DIExpression *expr;
8337
+ if ((Metadata*)varinfo.dinfo->getType() != debuginfo.jl_pvalue_dillvmt)
8338
+ addr.push_back(llvm::dwarf::DW_OP_deref);
8339
+ expr = dbuilder.createExpression(addr);
8340
+ dbuilder.insertDeclare(av, varinfo.dinfo, expr,
8341
+ topdebugloc,
8342
+ ctx.builder.GetInsertBlock());
8349
8343
}
8350
8344
};
8351
8345
@@ -8359,7 +8353,7 @@ static jl_llvm_functions_t
8359
8353
varinfo.usedUndef = false;
8360
8354
continue;
8361
8355
}
8362
- allocate_local (varinfo, s);
8356
+ allocate_local(varinfo, s, (int)i );
8363
8357
}
8364
8358
8365
8359
std::map<int, int> upsilon_to_phic;
@@ -8402,7 +8396,7 @@ static jl_llvm_functions_t
8402
8396
vi.used = true;
8403
8397
vi.isVolatile = true;
8404
8398
vi.value = mark_julia_type(ctx, (Value*)NULL, false, typ);
8405
- allocate_local (vi, jl_symbol (" phic" ));
8399
+ allocate_local(vi, jl_symbol("phic"), -1 );
8406
8400
}
8407
8401
}
8408
8402
}
@@ -8542,7 +8536,7 @@ static jl_llvm_functions_t
8542
8536
ctx.builder.CreateAlignedLoad(ctx.types().T_prjlvalue, argPtr, Align(sizeof(void*))),
8543
8537
false, vi.value.typ));
8544
8538
theArg = mark_julia_type(ctx, load, true, vi.value.typ);
8545
- if (debug_enabled && vi.dinfo && !vi.boxroot && !vi. value . V ) {
8539
+ if (debug_enabled && vi.dinfo && !vi.boxroot) {
8546
8540
SmallVector<uint64_t, 8> addr;
8547
8541
addr.push_back(llvm::dwarf::DW_OP_deref);
8548
8542
addr.push_back(llvm::dwarf::DW_OP_plus_uconst);
@@ -8561,21 +8555,15 @@ static jl_llvm_functions_t
8561
8555
assert(vi.value.V == NULL && "unexpected variable slot created for argument");
8562
8556
// keep track of original (possibly boxed) value to avoid re-boxing or moving
8563
8557
vi.value = theArg;
8564
- if (specsig && theArg.V && debug_enabled && vi.dinfo ) {
8565
- SmallVector<uint64_t , 8 > addr;
8566
- Value *parg;
8558
+ if (debug_enabled && vi.dinfo && theArg.V) {
8567
8559
if (theArg.ispointer()) {
8568
- parg = theArg.V ;
8569
- if ((Metadata*)vi.dinfo ->getType () != debuginfo.jl_pvalue_dillvmt )
8570
- addr.push_back (llvm::dwarf::DW_OP_deref);
8560
+ dbuilder.insertDeclare(theArg.V, vi.dinfo, dbuilder.createExpression(),
8561
+ topdebugloc, ctx.builder.GetInsertBlock());
8571
8562
}
8572
8563
else {
8573
- parg = ctx. builder . CreateAlloca (theArg.V -> getType (), NULL , jl_symbol_name (s));
8574
- ctx.builder .CreateStore (theArg. V , parg );
8564
+ dbuilder.insertDbgValueIntrinsic (theArg.V, vi.dinfo, dbuilder.createExpression(),
8565
+ topdebugloc, ctx.builder.GetInsertBlock() );
8575
8566
}
8576
- dbuilder.insertDeclare (parg, vi.dinfo , dbuilder.createExpression (addr),
8577
- topdebugloc,
8578
- ctx.builder .GetInsertBlock ());
8579
8567
}
8580
8568
}
8581
8569
else {
0 commit comments