@@ -111,12 +111,21 @@ AtomicOrdering get_llvm_atomic_order(enum jl_memory_order order)
111
111
static Value *stringConstPtr (
112
112
jl_codegen_params_t &emission_context,
113
113
IRBuilder<> &irbuilder,
114
- const std::string &txt)
114
+ const Twine &txt)
115
115
{
116
116
Module *M = jl_builderModule (irbuilder);
117
- StringRef ctxt (txt.c_str (), txt.size () + 1 );
118
- Constant *Data = ConstantDataArray::get (irbuilder.getContext (), arrayRefFromStringRef (ctxt));
119
- GlobalVariable *gv = get_pointer_to_constant (emission_context, Data, " _j_str" , *M);
117
+ SmallVector<char , 128 > ctxt;
118
+ txt.toVector (ctxt);
119
+ // null-terminate the string
120
+ ctxt.push_back (0 );
121
+ Constant *Data = ConstantDataArray::get (irbuilder.getContext (), ctxt);
122
+ ctxt.pop_back ();
123
+ // We use this for the name of the gv, so cap its size to avoid memory blowout
124
+ if (ctxt.size () > 28 ) {
125
+ ctxt.resize (28 );
126
+ ctxt[25 ] = ctxt[26 ] = ctxt[27 ] = ' .' ;
127
+ }
128
+ GlobalVariable *gv = get_pointer_to_constant (emission_context, Data, " _j_str_" + StringRef (ctxt.data (), ctxt.size ()), *M);
120
129
Value *zero = ConstantInt::get (Type::getInt32Ty (irbuilder.getContext ()), 0 );
121
130
Value *Args[] = { zero, zero };
122
131
auto gep = irbuilder.CreateInBoundsGEP (gv->getValueType (),
@@ -1097,7 +1106,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p, bool maybenull
1097
1106
if (justtag && jt->smalltag ) {
1098
1107
ptr = ConstantInt::get (expr_type, jt->smalltag << 4 );
1099
1108
if (ctx.emission_context .imaging )
1100
- ptr = get_pointer_to_constant (ctx.emission_context , ptr, " _j_tag " , *jl_Module);
1109
+ ptr = get_pointer_to_constant (ctx.emission_context , ptr, StringRef ( " _j_smalltag_ " ) + jl_symbol_name (jt-> name -> name ) , *jl_Module);
1101
1110
}
1102
1111
else if (ctx.emission_context .imaging )
1103
1112
ptr = ConstantExpr::getBitCast (literal_pointer_val_slot (ctx, (jl_value_t *)jt), datatype_or_p->getType ());
@@ -1278,27 +1287,27 @@ static Value *emit_datatype_name(jl_codectx_t &ctx, Value *dt)
1278
1287
// the error is always thrown. This may cause non dominated use
1279
1288
// of SSA value error in the verifier.
1280
1289
1281
- static void just_emit_error (jl_codectx_t &ctx, Function *F, const std::string &txt)
1290
+ static void just_emit_error (jl_codectx_t &ctx, Function *F, const Twine &txt)
1282
1291
{
1283
1292
++EmittedErrors;
1284
1293
ctx.builder .CreateCall (F, stringConstPtr (ctx.emission_context , ctx.builder , txt));
1285
1294
}
1286
1295
1287
- static void emit_error (jl_codectx_t &ctx, Function *F, const std::string &txt)
1296
+ static void emit_error (jl_codectx_t &ctx, Function *F, const Twine &txt)
1288
1297
{
1289
1298
just_emit_error (ctx, F, txt);
1290
1299
ctx.builder .CreateUnreachable ();
1291
1300
BasicBlock *cont = BasicBlock::Create (ctx.builder .getContext (), " after_error" , ctx.f );
1292
1301
ctx.builder .SetInsertPoint (cont);
1293
1302
}
1294
1303
1295
- static void emit_error (jl_codectx_t &ctx, const std::string &txt)
1304
+ static void emit_error (jl_codectx_t &ctx, const Twine &txt)
1296
1305
{
1297
1306
emit_error (ctx, prepare_call (jlerror_func), txt);
1298
1307
}
1299
1308
1300
1309
// DO NOT PASS IN A CONST CONDITION!
1301
- static void error_unless (jl_codectx_t &ctx, Value *cond, const std::string &msg)
1310
+ static void error_unless (jl_codectx_t &ctx, Value *cond, const Twine &msg)
1302
1311
{
1303
1312
++EmittedConditionalErrors;
1304
1313
BasicBlock *failBB = BasicBlock::Create (ctx.builder .getContext (), " fail" , ctx.f );
@@ -1451,14 +1460,14 @@ static Value *emit_typeof(jl_codectx_t &ctx, Value *v, bool maybenull, bool just
1451
1460
1452
1461
static Value *boxed (jl_codectx_t &ctx, const jl_cgval_t &v, bool is_promotable=false );
1453
1462
1454
- static void just_emit_type_error (jl_codectx_t &ctx, const jl_cgval_t &x, Value *type, const std::string &msg)
1463
+ static void just_emit_type_error (jl_codectx_t &ctx, const jl_cgval_t &x, Value *type, const Twine &msg)
1455
1464
{
1456
1465
Value *msg_val = stringConstPtr (ctx.emission_context , ctx.builder , msg);
1457
1466
ctx.builder .CreateCall (prepare_call (jltypeerror_func),
1458
1467
{ msg_val, maybe_decay_untracked (ctx, type), mark_callee_rooted (ctx, boxed (ctx, x))});
1459
1468
}
1460
1469
1461
- static void emit_type_error (jl_codectx_t &ctx, const jl_cgval_t &x, Value *type, const std::string &msg)
1470
+ static void emit_type_error (jl_codectx_t &ctx, const jl_cgval_t &x, Value *type, const Twine &msg)
1462
1471
{
1463
1472
just_emit_type_error (ctx, x, type, msg);
1464
1473
ctx.builder .CreateUnreachable ();
@@ -1538,7 +1547,7 @@ static Value *emit_exactly_isa(jl_codectx_t &ctx, const jl_cgval_t &arg, jl_data
1538
1547
}
1539
1548
1540
1549
static std::pair<Value*, bool > emit_isa (jl_codectx_t &ctx, const jl_cgval_t &x,
1541
- jl_value_t *type, const std::string * msg);
1550
+ jl_value_t *type, const Twine & msg);
1542
1551
1543
1552
static void emit_isa_union (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type,
1544
1553
SmallVectorImpl<std::pair<std::pair<BasicBlock*,BasicBlock*>,Value*>> &bbs)
@@ -1550,15 +1559,15 @@ static void emit_isa_union(jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *t
1550
1559
return ;
1551
1560
}
1552
1561
BasicBlock *enter = ctx.builder .GetInsertBlock ();
1553
- Value *v = emit_isa (ctx, x, type, nullptr ).first ;
1562
+ Value *v = emit_isa (ctx, x, type, Twine () ).first ;
1554
1563
BasicBlock *exit = ctx.builder .GetInsertBlock ();
1555
1564
bbs.emplace_back (std::make_pair (enter, exit), v);
1556
1565
BasicBlock *isaBB = BasicBlock::Create (ctx.builder .getContext (), " isa" , ctx.f );
1557
1566
ctx.builder .SetInsertPoint (isaBB);
1558
1567
}
1559
1568
1560
1569
// Should agree with `_can_optimize_isa` above
1561
- static std::pair<Value*, bool > emit_isa (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const std::string * msg)
1570
+ static std::pair<Value*, bool > emit_isa (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const Twine & msg)
1562
1571
{
1563
1572
++EmittedIsa;
1564
1573
// TODO: The subtype check below suffers from incorrectness issues due to broken
@@ -1578,8 +1587,8 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
1578
1587
known_isa = false ;
1579
1588
}
1580
1589
if (known_isa) {
1581
- if (!*known_isa && msg) {
1582
- emit_type_error (ctx, x, literal_pointer_val (ctx, type), * msg);
1590
+ if (!*known_isa && ! msg. isTriviallyEmpty () ) {
1591
+ emit_type_error (ctx, x, literal_pointer_val (ctx, type), msg);
1583
1592
}
1584
1593
return std::make_pair (ConstantInt::get (getInt1Ty (ctx.builder .getContext ()), *known_isa), true );
1585
1594
}
@@ -1611,7 +1620,7 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
1611
1620
if (jl_has_intersect_type_not_kind (type) || jl_has_intersect_type_not_kind (intersected_type)) {
1612
1621
Value *vx = boxed (ctx, x);
1613
1622
Value *vtyp = track_pjlvalue (ctx, literal_pointer_val (ctx, type));
1614
- if (msg && * msg == " typeassert" ) {
1623
+ if (msg. isSingleStringRef () && msg. getSingleStringRef () == " typeassert" ) {
1615
1624
ctx.builder .CreateCall (prepare_call (jltypeassert_func), { vx, vtyp });
1616
1625
return std::make_pair (ConstantInt::get (getInt1Ty (ctx.builder .getContext ()), 1 ), true );
1617
1626
}
@@ -1672,16 +1681,16 @@ static std::pair<Value*, bool> emit_isa(jl_codectx_t &ctx, const jl_cgval_t &x,
1672
1681
static Value *emit_isa_and_defined (jl_codectx_t &ctx, const jl_cgval_t &val, jl_value_t *typ)
1673
1682
{
1674
1683
return emit_nullcheck_guard (ctx, val.ispointer () ? val.V : nullptr , [&] {
1675
- return emit_isa (ctx, val, typ, nullptr ).first ;
1684
+ return emit_isa (ctx, val, typ, Twine () ).first ;
1676
1685
});
1677
1686
}
1678
1687
1679
1688
1680
- static void emit_typecheck (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const std::string &msg)
1689
+ static void emit_typecheck (jl_codectx_t &ctx, const jl_cgval_t &x, jl_value_t *type, const Twine &msg)
1681
1690
{
1682
1691
Value *istype;
1683
1692
bool handled_msg;
1684
- std::tie (istype, handled_msg) = emit_isa (ctx, x, type, & msg);
1693
+ std::tie (istype, handled_msg) = emit_isa (ctx, x, type, msg);
1685
1694
if (!handled_msg) {
1686
1695
++EmittedTypechecks;
1687
1696
BasicBlock *failBB = BasicBlock::Create (ctx.builder .getContext (), " fail" , ctx.f );
@@ -1709,7 +1718,7 @@ static Value *emit_isconcrete(jl_codectx_t &ctx, Value *typ)
1709
1718
return isconcrete;
1710
1719
}
1711
1720
1712
- static void emit_concretecheck (jl_codectx_t &ctx, Value *typ, const std::string &msg)
1721
+ static void emit_concretecheck (jl_codectx_t &ctx, Value *typ, const Twine &msg)
1713
1722
{
1714
1723
++EmittedConcretechecks;
1715
1724
assert (typ->getType () == ctx.types ().T_prjlvalue );
@@ -1930,7 +1939,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
1930
1939
Value *parent, // for the write barrier, NULL if no barrier needed
1931
1940
bool isboxed, AtomicOrdering Order, AtomicOrdering FailOrder, unsigned alignment,
1932
1941
bool needlock, bool issetfield, bool isreplacefield, bool isswapfield, bool ismodifyfield,
1933
- bool maybe_null_if_boxed, const jl_cgval_t *modifyop, const std::string &fname)
1942
+ bool maybe_null_if_boxed, const jl_cgval_t *modifyop, const Twine &fname)
1934
1943
{
1935
1944
auto newval = [&](const jl_cgval_t &lhs) {
1936
1945
const jl_cgval_t argv[3 ] = { cmp, lhs, rhs };
@@ -2057,7 +2066,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
2057
2066
else if (!isboxed) {
2058
2067
assert (jl_is_concrete_type (jltype));
2059
2068
needloop = ((jl_datatype_t *)jltype)->layout ->haspadding ;
2060
- Value *SameType = emit_isa (ctx, cmp, jltype, nullptr ).first ;
2069
+ Value *SameType = emit_isa (ctx, cmp, jltype, Twine () ).first ;
2061
2070
if (SameType != ConstantInt::getTrue (ctx.builder .getContext ())) {
2062
2071
BasicBlock *SkipBB = BasicBlock::Create (ctx.builder .getContext (), " skip_xchg" , ctx.f );
2063
2072
BasicBlock *BB = BasicBlock::Create (ctx.builder .getContext (), " ok_xchg" , ctx.f );
@@ -2306,7 +2315,7 @@ static Value *julia_bool(jl_codectx_t &ctx, Value *cond)
2306
2315
2307
2316
// --- accessing the representations of built-in data types ---
2308
2317
2309
- static void emit_atomic_error (jl_codectx_t &ctx, const std::string &msg)
2318
+ static void emit_atomic_error (jl_codectx_t &ctx, const Twine &msg)
2310
2319
{
2311
2320
emit_error (ctx, prepare_call (jlatomicerror_func), msg);
2312
2321
}
@@ -3668,7 +3677,7 @@ static void emit_unionmove(jl_codectx_t &ctx, Value *dest, MDNode *tbaa_dst, con
3668
3677
}
3669
3678
3670
3679
3671
- static void emit_cpointercheck (jl_codectx_t &ctx, const jl_cgval_t &x, const std::string &msg)
3680
+ static void emit_cpointercheck (jl_codectx_t &ctx, const jl_cgval_t &x, const Twine &msg)
3672
3681
{
3673
3682
++EmittedCPointerChecks;
3674
3683
Value *t = emit_typeof (ctx, x, false , false );
@@ -3776,7 +3785,7 @@ static jl_cgval_t emit_setfield(jl_codectx_t &ctx,
3776
3785
jl_cgval_t rhs, jl_cgval_t cmp,
3777
3786
bool wb, AtomicOrdering Order, AtomicOrdering FailOrder,
3778
3787
bool needlock, bool issetfield, bool isreplacefield, bool isswapfield, bool ismodifyfield,
3779
- const jl_cgval_t *modifyop, const std::string &fname)
3788
+ const jl_cgval_t *modifyop, const Twine &fname)
3780
3789
{
3781
3790
auto get_objname = [&]() {
3782
3791
return strct.V ? strct.V ->getName () : StringRef (" " );
0 commit comments