@@ -240,6 +240,7 @@ static Type *T_void;
240
240
// type-based alias analysis nodes. Indentation of comments indicates hierarchy.
241
241
static MDNode* tbaa_user; // User data
242
242
static MDNode* tbaa_value; // Julia value
243
+ static MDNode* tbaa_immut; // Data inside a heap-allocated immutable
243
244
static MDNode* tbaa_array; // Julia array
244
245
static MDNode* tbaa_arrayptr; // The pointer inside a jl_array_t
245
246
static MDNode* tbaa_arraysize; // A size in a jl_array_t
@@ -1487,13 +1488,14 @@ static Value *emit_getfield(jl_value_t *expr, jl_sym_t *name, jl_codectx_t *ctx)
1487
1488
ConstantInt::get (T_size,
1488
1489
sty->fields [idx].offset + sizeof (void *)));
1489
1490
JL_GC_POP ();
1491
+ MDNode *tbaa = sty->mutabl ? tbaa_user : tbaa_immut;
1490
1492
if (sty->fields [idx].isptr ) {
1491
- Value *fldv = builder.CreateLoad (builder.CreateBitCast (addr,jl_ppvalue_llvmt));
1493
+ Value *fldv = tbaa_decorate (tbaa, builder.CreateLoad (builder.CreateBitCast (addr,jl_ppvalue_llvmt) ));
1492
1494
null_pointer_check (fldv, ctx);
1493
1495
return fldv;
1494
1496
}
1495
1497
else {
1496
- return typed_load (addr, ConstantInt::get (T_size, 0 ), jfty, ctx);
1498
+ return typed_load (addr, ConstantInt::get (T_size, 0 ), jfty, ctx, tbaa );
1497
1499
}
1498
1500
}
1499
1501
else {
@@ -1551,7 +1553,7 @@ static void emit_setfield(jl_datatype_t *sty, Value *strct, size_t idx,
1551
1553
builder.CreateBitCast (addr, jl_ppvalue_llvmt));
1552
1554
}
1553
1555
else {
1554
- typed_store (addr, ConstantInt::get (T_size, 0 ), rhs, jfty, ctx);
1556
+ typed_store (addr, ConstantInt::get (T_size, 0 ), rhs, jfty, ctx, sty-> mutabl ? tbaa_user : tbaa_immut );
1555
1557
}
1556
1558
}
1557
1559
else {
@@ -2064,7 +2066,7 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
2064
2066
assert (((jl_datatype_t *)ety)->instance != NULL );
2065
2067
return literal_pointer_val (((jl_datatype_t *)ety)->instance );
2066
2068
}
2067
- return typed_load (emit_arrayptr (ary, args[1 ], ctx), idx, ety, ctx);
2069
+ return typed_load (emit_arrayptr (ary, args[1 ], ctx), idx, ety, ctx, tbaa_user );
2068
2070
}
2069
2071
}
2070
2072
}
@@ -2097,7 +2099,7 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
2097
2099
else {
2098
2100
typed_store (emit_arrayptr (ary,args[1 ],ctx), idx,
2099
2101
ety==(jl_value_t *)jl_any_type ? emit_expr (args[2 ],ctx) : emit_unboxed (args[2 ],ctx),
2100
- ety, ctx);
2102
+ ety, ctx, tbaa_user );
2101
2103
}
2102
2104
JL_GC_POP ();
2103
2105
return ary;
@@ -2152,7 +2154,7 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
2152
2154
idx = emit_bounds_check (idx, ConstantInt::get (T_size, nfields), ctx);
2153
2155
Value *ptr = data_pointer (strct);
2154
2156
JL_GC_POP ();
2155
- return typed_load (ptr, idx, jt, ctx);
2157
+ return typed_load (ptr, idx, jt, ctx, stt-> mutabl ? tbaa_user : tbaa_immut );
2156
2158
}
2157
2159
else {
2158
2160
idx = builder.CreateSub (idx, ConstantInt::get (T_size, 1 ));
@@ -2179,7 +2181,7 @@ static Value *emit_known_call(jl_value_t *ff, jl_value_t **args, size_t nargs,
2179
2181
jl_value_t *jt = jl_t0 (stt->types );
2180
2182
idx = emit_bounds_check (idx, ConstantInt::get (T_size, nfields), ctx);
2181
2183
Value *ptr = builder.CreateGEP (tempSpace, ConstantInt::get (T_size, 0 ));
2182
- fld = typed_load (ptr, idx, jt, ctx);
2184
+ fld = typed_load (ptr, idx, jt, ctx, stt-> mutabl ? tbaa_user : tbaa_immut );
2183
2185
builder.CreateCall (Intrinsic::getDeclaration (jl_Module,Intrinsic::stackrestore),
2184
2186
stacksave);
2185
2187
}
@@ -4188,6 +4190,7 @@ static void init_julia_llvm_env(Module *m)
4188
4190
MDNode* tbaa_root = mbuilder->createTBAARoot (" jtbaa" );
4189
4191
tbaa_user = tbaa_make_child (" jtbaa_user" ,tbaa_root);
4190
4192
tbaa_value = tbaa_make_child (" jtbaa_value" ,tbaa_root);
4193
+ tbaa_immut = tbaa_make_child (" jtbaa_immut" ,tbaa_root);
4191
4194
tbaa_array = tbaa_make_child (" jtbaa_array" ,tbaa_value);
4192
4195
tbaa_arrayptr = tbaa_make_child (" jtbaa_arrayptr" ,tbaa_array);
4193
4196
tbaa_arraysize = tbaa_make_child (" jtbaa_arraysize" ,tbaa_array);
0 commit comments