@@ -3026,12 +3026,15 @@ static Value *emit_genericmemoryelsize(jl_codectx_t &ctx, Value *v, jl_value_t *
3026
3026
size_t sz = sty->layout ->size ;
3027
3027
if (sty->layout ->flags .arrayelem_isunion )
3028
3028
sz++;
3029
- return ConstantInt::get (ctx.types ().T_size , sz);
3029
+ auto elsize = ConstantInt::get (ctx.types ().T_size , sz);
3030
+ return elsize;
3030
3031
}
3031
3032
else {
3032
3033
Value *t = emit_typeof (ctx, v, false , false , true );
3033
3034
Value *elsize = emit_datatype_size (ctx, t, add_isunion);
3034
- return ctx.builder .CreateZExt (elsize, ctx.types ().T_size );
3035
+ elsize = ctx.builder .CreateZExt (elsize, ctx.types ().T_size );
3036
+ setName (ctx.emission_context , elsize, " elsize" );
3037
+ return elsize;
3035
3038
}
3036
3039
}
3037
3040
@@ -3066,6 +3069,7 @@ static Value *emit_genericmemorylen(jl_codectx_t &ctx, Value *addr, jl_value_t *
3066
3069
MDBuilder MDB (ctx.builder .getContext ());
3067
3070
auto rng = MDB.createRange (Constant::getNullValue (ctx.types ().T_size ), ConstantInt::get (ctx.types ().T_size , genericmemoryype_maxsize (typ)));
3068
3071
LI->setMetadata (LLVMContext::MD_range, rng);
3072
+ setName (ctx.emission_context , LI, " memory_len" );
3069
3073
return LI;
3070
3074
}
3071
3075
@@ -3075,7 +3079,7 @@ static Value *emit_genericmemoryptr(jl_codectx_t &ctx, Value *mem, const jl_data
3075
3079
Value *addr = mem;
3076
3080
addr = decay_derived (ctx, addr);
3077
3081
addr = ctx.builder .CreateStructGEP (ctx.types ().T_jlgenericmemory , addr, 1 );
3078
- setName (ctx.emission_context , addr, " .data_ptr " );
3082
+ setName (ctx.emission_context , addr, " memory_data_ptr " );
3079
3083
PointerType *PPT = cast<PointerType>(ctx.types ().T_jlgenericmemory ->getElementType (1 ));
3080
3084
LoadInst *LI = ctx.builder .CreateAlignedLoad (PPT, addr, Align (sizeof (char *)));
3081
3085
LI->setOrdering (AtomicOrdering::NotAtomic);
@@ -3087,6 +3091,7 @@ static Value *emit_genericmemoryptr(jl_codectx_t &ctx, Value *mem, const jl_data
3087
3091
assert (AS == AddressSpace::Loaded);
3088
3092
ptr = ctx.builder .CreateCall (prepare_call (gc_loaded_func), { mem, ptr });
3089
3093
}
3094
+ setName (ctx.emission_context , ptr, " memory_data" );
3090
3095
return ptr;
3091
3096
}
3092
3097
@@ -4195,6 +4200,7 @@ static jl_cgval_t _emit_memoryref(jl_codectx_t &ctx, Value *mem, Value *data, co
4195
4200
Value *ref = Constant::getNullValue (get_memoryref_type (ctx.builder .getContext (), ctx.types ().T_size , layout, 0 ));
4196
4201
ref = ctx.builder .CreateInsertValue (ref, data, 0 );
4197
4202
ref = ctx.builder .CreateInsertValue (ref, mem, 1 );
4203
+ setName (ctx.emission_context , ref, " memory_ref" );
4198
4204
return mark_julia_type (ctx, ref, false , typ);
4199
4205
}
4200
4206
@@ -4215,6 +4221,7 @@ static Value *emit_memoryref_FCA(jl_codectx_t &ctx, const jl_cgval_t &ref, const
4215
4221
LoadInst *load = ctx.builder .CreateLoad (type, data_pointer (ctx, ref));
4216
4222
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA (ctx, ref.tbaa );
4217
4223
ai.decorateInst (load);
4224
+ setName (ctx.emission_context , load, " memory_ref_FCA" );
4218
4225
return load;
4219
4226
}
4220
4227
else {
@@ -4231,9 +4238,12 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
4231
4238
return jl_cgval_t ();
4232
4239
Value *V = emit_memoryref_FCA (ctx, ref, layout);
4233
4240
Value *data = CreateSimplifiedExtractValue (ctx, V, 0 );
4241
+ maybeSetName (ctx.emission_context , data, " memoryref_data" );
4234
4242
Value *mem = CreateSimplifiedExtractValue (ctx, V, 1 );
4243
+ maybeSetName (ctx.emission_context , mem, " memoryref_mem" );
4235
4244
Value *i = emit_unbox (ctx, ctx.types ().T_size , idx, (jl_value_t *)jl_long_type);
4236
4245
Value *offset = ctx.builder .CreateSub (i, ConstantInt::get (ctx.types ().T_size , 1 ));
4246
+ setName (ctx.emission_context , offset, " memoryref_offset" );
4237
4247
Value *elsz = emit_genericmemoryelsize (ctx, mem, ref.typ , false );
4238
4248
bool bc = bounds_check_enabled (ctx, inbounds);
4239
4249
#if 1
@@ -4245,12 +4255,14 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
4245
4255
bool isghost = layout->size == 0 ;
4246
4256
if ((!isboxed && isunion) || isghost) {
4247
4257
newdata = ctx.builder .CreateAdd (data, offset);
4258
+ setName (ctx.emission_context , newdata, " memoryref_data+offset" );
4248
4259
if (bc) {
4249
4260
BasicBlock *failBB, *endBB;
4250
4261
failBB = BasicBlock::Create (ctx.builder .getContext (), " oob" );
4251
4262
endBB = BasicBlock::Create (ctx.builder .getContext (), " idxend" );
4252
4263
Value *mlen = emit_genericmemorylen (ctx, mem, ref.typ );
4253
4264
Value *inbound = ctx.builder .CreateICmpULT (newdata, mlen);
4265
+ setName (ctx.emission_context , offset, " memoryref_isinbounds" );
4254
4266
ctx.builder .CreateCondBr (inbound, endBB, failBB);
4255
4267
failBB->insertInto (ctx.f );
4256
4268
ctx.builder .SetInsertPoint (failBB);
@@ -4278,10 +4290,13 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
4278
4290
// and we can further rearrange that as ovflw = !( offset+len < len+len ) as unsigned math
4279
4291
Value *mlen = emit_genericmemorylen (ctx, mem, ref.typ );
4280
4292
ovflw = ctx.builder .CreateICmpUGE (ctx.builder .CreateAdd (offset, mlen), ctx.builder .CreateNUWAdd (mlen, mlen));
4293
+ setName (ctx.emission_context , ovflw, " memoryref_ovflw" );
4281
4294
}
4282
4295
#endif
4283
4296
boffset = ctx.builder .CreateMul (offset, elsz);
4284
- newdata = ctx.builder .CreateInBoundsGEP (getInt8Ty (ctx.builder .getContext ()), data, boffset);
4297
+ setName (ctx.emission_context , boffset, " memoryref_byteoffset" );
4298
+ newdata = ctx.builder .CreateGEP (getInt8Ty (ctx.builder .getContext ()), data, boffset);
4299
+ setName (ctx.emission_context , newdata, " memoryref_data_byteoffset" );
4285
4300
(void )boffset; // LLVM is very bad at handling GEP with types different from the load
4286
4301
if (bc) {
4287
4302
BasicBlock *failBB, *endBB;
@@ -4304,8 +4319,11 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg
4304
4319
ctx.builder.CreatePtrToInt(newdata, ctx.types().T_size),
4305
4320
ctx.builder.CreatePtrToInt(mptr, ctx.types().T_size));
4306
4321
Value *blen = ctx.builder.CreateMul(mlen, elsz, "", true, true);
4322
+ setName(ctx.emission_context, blen, "memoryref_bytelen");
4307
4323
Value *inbound = ctx.builder.CreateICmpULT(bidx0, blen);
4324
+ setName(ctx.emission_context, inbound, "memoryref_isinbounds");
4308
4325
inbound = ctx.builder.CreateAnd(ctx.builder.CreateNot(ovflw), inbound);
4326
+ setName(ctx.emission_context, inbound, "memoryref_isinbounds¬ovflw");
4309
4327
#else
4310
4328
Value *idx0; // (newdata - mptr) / elsz
4311
4329
idx0 = ctx.builder .CreateSub (
@@ -4342,8 +4360,10 @@ static jl_cgval_t emit_memoryref_offset(jl_codectx_t &ctx, const jl_cgval_t &ref
4342
4360
offset = ctx.builder .CreateSub (
4343
4361
ctx.builder .CreatePtrToInt (data, ctx.types ().T_size ),
4344
4362
ctx.builder .CreatePtrToInt (mptr, ctx.types ().T_size ));
4363
+ setName (ctx.emission_context , offset, " memoryref_offset" );
4345
4364
Value *elsz = emit_genericmemoryelsize (ctx, mem, ref.typ , false );
4346
4365
offset = ctx.builder .CreateExactUDiv (offset, elsz);
4366
+ setName (ctx.emission_context , offset, " memoryref_offsetidx" );
4347
4367
}
4348
4368
offset = ctx.builder .CreateAdd (offset, ConstantInt::get (ctx.types ().T_size , 1 ));
4349
4369
return mark_julia_type (ctx, offset, false , jl_long_type);
@@ -4352,7 +4372,9 @@ static jl_cgval_t emit_memoryref_offset(jl_codectx_t &ctx, const jl_cgval_t &ref
4352
4372
static Value *emit_memoryref_mem (jl_codectx_t &ctx, const jl_cgval_t &ref, const jl_datatype_layout_t *layout)
4353
4373
{
4354
4374
Value *V = emit_memoryref_FCA (ctx, ref, layout);
4355
- return CreateSimplifiedExtractValue (ctx, V, 1 );
4375
+ V = CreateSimplifiedExtractValue (ctx, V, 1 );
4376
+ maybeSetName (ctx.emission_context , V, " memoryref_mem" );
4377
+ return V;
4356
4378
}
4357
4379
4358
4380
static Value *emit_memoryref_ptr (jl_codectx_t &ctx, const jl_cgval_t &ref, const jl_datatype_layout_t *layout)
@@ -4374,13 +4396,15 @@ static Value *emit_memoryref_ptr(jl_codectx_t &ctx, const jl_cgval_t &ref, const
4374
4396
data = ctx.builder .CreateCall (prepare_call (gc_loaded_func), { mem, data });
4375
4397
if (!GEPlist.empty ()) {
4376
4398
for (auto &GEP : make_range (GEPlist.rbegin (), GEPlist.rend ())) {
4377
- Instruction *GEP2 = GEP->clone ();
4399
+ GetElementPtrInst *GEP2 = cast<GetElementPtrInst>( GEP->clone () );
4378
4400
GEP2->mutateType (PointerType::get (GEP->getResultElementType (), AS));
4379
4401
GEP2->setOperand (GetElementPtrInst::getPointerOperandIndex (), data);
4402
+ GEP2->setIsInBounds (true );
4380
4403
ctx.builder .Insert (GEP2);
4381
4404
data = GEP2;
4382
4405
}
4383
4406
}
4407
+ setName (ctx.emission_context , data, " memoryref_data" );
4384
4408
return data;
4385
4409
}
4386
4410
0 commit comments