Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4124,7 +4124,7 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool is_promotab
if (!box) {
bool do_promote = vinfo.promotion_point;
if (do_promote && is_promotable && vinfo.inline_roots.empty()) {
auto IP = ctx.builder.saveIP();
IRBuilderBase::InsertPointGuard IP(ctx.builder);
ctx.builder.SetInsertPoint(vinfo.promotion_point);
box = emit_allocobj(ctx, (jl_datatype_t*)jt, true);
Value *decayed = decay_derived(ctx, box);
Expand All @@ -4136,7 +4136,6 @@ static Value *boxed(jl_codectx_t &ctx, const jl_cgval_t &vinfo, bool is_promotab
originalAlloca->replaceAllUsesWith(decayed);
// end illegal IR
originalAlloca->eraseFromParent();
ctx.builder.restoreIP(IP);
}
else {
auto arg_typename = [&] JL_NOTSAFEPOINT {
Expand Down Expand Up @@ -4463,7 +4462,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
jl_value_t *jtype = jl_svecref(sty->types, i); // n.b. ty argument must be concrete
jl_cgval_t fval_info = argv[i];

IRBuilderBase::InsertPoint savedIP;
std::optional<IRBuilderBase::InsertPointGuard> savedIP;
emit_typecheck(ctx, fval_info, jtype, "new");
fval_info = update_julia_type(ctx, fval_info, jtype);
if (fval_info.typ == jl_bottom_type)
Expand All @@ -4485,7 +4484,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
fval_info.inline_roots.empty() && inline_roots.empty() && // these need to be compatible, if they were to be implemented
fval_info.promotion_point && fval_info.promotion_point->getParent() == ctx.builder.GetInsertBlock();
if (field_promotable) {
savedIP = ctx.builder.saveIP();
savedIP.emplace(ctx.builder);
ctx.builder.SetInsertPoint(fval_info.promotion_point);
}
if (!init_as_value) {
Expand Down Expand Up @@ -4613,9 +4612,6 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
else
assert(false);
}
if (field_promotable) {
ctx.builder.restoreIP(savedIP);
}
}
if (init_as_value) {
for (size_t i = nargs; i < nf; i++) {
Expand All @@ -4633,15 +4629,14 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
}
if (nargs < nf) {
assert(!init_as_value);
IRBuilderBase::InsertPoint savedIP = ctx.builder.saveIP();
IRBuilderBase::InsertPointGuard savedIP(ctx.builder);
if (promotion_point)
ctx.builder.SetInsertPoint(promotion_point);
if (strct) {
jl_aliasinfo_t ai = jl_aliasinfo_t::fromTBAA(ctx, ctx.tbaa().tbaa_stack);
promotion_point = ai.decorateInst(ctx.builder.CreateMemSet(strct, ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0),
jl_datatype_size(ty), Align(julia_alignment(ty))));
}
ctx.builder.restoreIP(savedIP);
}
if (type_is_ghost(lt))
return mark_julia_const(ctx, sty->instance);
Expand Down
5 changes: 3 additions & 2 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include <set>
#include <unordered_set>
#include <functional>
#include <memory>
#include <optional>

// target machine computation
#include <llvm/CodeGen/TargetSubtargetInfo.h>
Expand Down Expand Up @@ -2449,15 +2451,14 @@ static inline jl_cgval_t value_to_pointer(jl_codectx_t &ctx, const jl_cgval_t &v
jl_datatype_t *dt = (jl_datatype_t *)v.typ;
size_t npointers = dt->layout->first_ptr >= 0 ? dt->layout->npointers : 0;
if (npointers > 0) {
auto InsertPoint = ctx.builder.saveIP();
IRBuilderBase::InsertPointGuard InsertPoint(ctx.builder);
ctx.builder.SetInsertPoint(ctx.topalloca->getParent(), ++ctx.topalloca->getIterator());
for (size_t i = 0; i < npointers; i++) {
// make sure these are nullptr early from LLVM's perspective, in case it decides to SROA it
Value *ptr_field = emit_ptrgep(ctx, loc, jl_ptr_offset(dt, i) * sizeof(void *));
ctx.builder.CreateAlignedStore(
Constant::getNullValue(ctx.types().T_prjlvalue), ptr_field, Align(sizeof(void *)));
}
ctx.builder.restoreIP(InsertPoint);
}
auto tbaa = v.V == nullptr ? ctx.tbaa().tbaa_gcframe : ctx.tbaa().tbaa_stack;
auto stack_ai = jl_aliasinfo_t::fromTBAA(ctx, tbaa);
Expand Down
Loading