Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 4 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ static Value *stringConstPtr(
ctxt.resize(28);
ctxt[25] = ctxt[26] = ctxt[27] = '.';
}
GlobalVariable *gv = get_pointer_to_constant(emission_context, Data, "_j_str_" + StringRef(ctxt.data(), ctxt.size()), *M);
// Doesn't need to be aligned, we shouldn't operate on these like julia objects
GlobalVariable *gv = get_pointer_to_constant(emission_context, Data, Align(1), "_j_str_" + StringRef(ctxt.data(), ctxt.size()), *M);
Value *zero = ConstantInt::get(Type::getInt32Ty(irbuilder.getContext()), 0);
Value *Args[] = { zero, zero };
auto gep = irbuilder.CreateInBoundsGEP(gv->getValueType(),
Expand Down Expand Up @@ -918,7 +919,7 @@ static Value *data_pointer(jl_codectx_t &ctx, const jl_cgval_t &x)
if (x.constant) {
Constant *val = julia_const_to_llvm(ctx, x.constant);
if (val)
data = get_pointer_to_constant(ctx.emission_context, val, "_j_const", *jl_Module);
data = get_pointer_to_constant(ctx.emission_context, val, Align(jl_is_datatype(x.typ) && jl_struct_try_layout((jl_datatype_t*)x.typ) ? julia_alignment(x.typ) : JL_HEAP_ALIGNMENT), "_j_const", *jl_Module);
else
data = literal_pointer_val(ctx, x.constant);
}
Expand Down Expand Up @@ -1106,7 +1107,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p, bool maybenull
if (justtag && jt->smalltag) {
ptr = ConstantInt::get(expr_type, jt->smalltag << 4);
if (ctx.emission_context.imaging)
ptr = get_pointer_to_constant(ctx.emission_context, ptr, StringRef("_j_smalltag_") + jl_symbol_name(jt->name->name), *jl_Module);
ptr = get_pointer_to_constant(ctx.emission_context, ptr, Align(julia_alignment((jl_value_t *)jl_datatype_type)), StringRef("_j_smalltag_") + jl_symbol_name(jt->name->name), *jl_Module);
}
else if (ctx.emission_context.imaging)
ptr = ConstantExpr::getBitCast(literal_pointer_val_slot(ctx, (jl_value_t*)jt), datatype_or_p->getType());
Expand Down
11 changes: 6 additions & 5 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ static jl_cgval_t emit_new_struct(jl_codectx_t &ctx, jl_value_t *ty, size_t narg
static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, const jl_cgval_t *argv, size_t nargs, jl_value_t *rt);

static Value *literal_pointer_val(jl_codectx_t &ctx, jl_value_t *p);
static GlobalVariable *prepare_global_in(Module *M, GlobalVariable *G);
static unsigned julia_alignment(jl_value_t *jt);

static GlobalVariable *prepare_global_in(Module *M, JuliaVariable *G)
{
Expand Down Expand Up @@ -1811,7 +1811,7 @@ static inline GlobalVariable *prepare_global_in(Module *M, GlobalVariable *G)

// --- convenience functions for tagging llvm values with julia types ---

static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_context, Constant *val, const Twine &name, Module &M)
static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_context, Constant *val, Align align, const Twine &name, Module &M)
{
GlobalVariable *&gv = emission_context.mergedConstants[val];
auto get_gv = [&](const Twine &name) {
Expand All @@ -1823,6 +1823,7 @@ static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_con
val,
name);
gv->setUnnamedAddr(GlobalValue::UnnamedAddr::Global);
gv->setAlignment(align);
return gv;
};
if (gv == nullptr) {
Expand Down Expand Up @@ -1943,7 +1944,7 @@ static inline jl_cgval_t value_to_pointer(jl_codectx_t &ctx, Value *v, jl_value_
{
Value *loc;
if (valid_as_globalinit(v)) { // llvm can't handle all the things that could be inside a ConstantExpr
loc = get_pointer_to_constant(ctx.emission_context, cast<Constant>(v), "_j_const", *jl_Module);
loc = get_pointer_to_constant(ctx.emission_context, cast<Constant>(v), Align(jl_is_datatype(typ) && jl_struct_try_layout((jl_datatype_t*)typ) ? julia_alignment(typ) : JL_HEAP_ALIGNMENT), "_j_const", *jl_Module);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
loc = get_pointer_to_constant(ctx.emission_context, cast<Constant>(v), Align(jl_is_datatype(typ) && jl_struct_try_layout((jl_datatype_t*)typ) ? julia_alignment(typ) : JL_HEAP_ALIGNMENT), "_j_const", *jl_Module);
assert(jl_is_concrete_type(typ)); // not legal to have an unboxed abstract type
loc = get_pointer_to_constant(ctx.emission_context, cast<Constant>(v), Align(julia_alignment(typ)), "_j_const", *jl_Module);

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assertion isn't holding, is it actually valid?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The assert is right, but the callee now is not right anymore. You need to switch to using the copy-constructor, so the type is correct (the tindex argument to value_to_pointer is no longer legal as a means of folding this together):

diff --git a/src/codegen.cpp b/src/codegen.cpp
index 5b0bf1bc98..11fa7474ba 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -2317,7 +2317,7 @@ static jl_cgval_t convert_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_
                 new_tindex = ConstantInt::get(getInt8Ty(ctx.builder.getContext()), new_idx);
                 if (v.V && !v.ispointer()) {
                     // TODO: remove this branch once all consumers of v.TIndex understand how to handle a non-ispointer value
-                    return value_to_pointer(ctx, v.V, typ, new_tindex);
+                    return jl_cgval_t(value_to_pointer(ctx, v.V, v.typ), typ, new_tindex);
                 }
             }
             else if (jl_subtype(v.typ, typ)) {

(fwiw, the TODO there is about places like this needing to be fixed to use the max-align from jl_islayout_inline instead when deciding how to spill it)

}
else {
loc = emit_static_alloca(ctx, v->getType());
Expand Down Expand Up @@ -7663,7 +7664,7 @@ static jl_llvm_functions_t
Type *vtype = julia_type_to_llvm(ctx, jt, &isboxed);
assert(!isboxed);
assert(!type_is_ghost(vtype) && "constants should already be handled");
Value *lv = new AllocaInst(vtype, M->getDataLayout().getAllocaAddrSpace(), NULL, Align(jl_datatype_align(jt)), jl_symbol_name(s), /*InsertBefore*/ctx.topalloca);
Value *lv = new AllocaInst(vtype, M->getDataLayout().getAllocaAddrSpace(), nullptr, Align(jl_datatype_align(jt)), jl_symbol_name(s), /*InsertBefore*/ctx.topalloca);
if (CountTrackedPointers(vtype).count) {
StoreInst *SI = new StoreInst(Constant::getNullValue(vtype), lv, false, Align(sizeof(void*)));
SI->insertAfter(ctx.topalloca);
Expand All @@ -7683,7 +7684,7 @@ static jl_llvm_functions_t
(va && (int)i == ctx.vaSlot) || // or it's the va arg tuple
i == 0) { // or it is the first argument (which isn't in `argArray`)
AllocaInst *av = new AllocaInst(ctx.types().T_prjlvalue, M->getDataLayout().getAllocaAddrSpace(),
jl_symbol_name(s), /*InsertBefore*/ctx.topalloca);
nullptr, Align(jl_is_datatype(jt) && jl_struct_try_layout((jl_datatype_t*)jt) ? julia_alignment(jt) : JL_HEAP_ALIGNMENT), jl_symbol_name(s), /*InsertBefore*/ctx.topalloca);
StoreInst *SI = new StoreInst(Constant::getNullValue(ctx.types().T_prjlvalue), av, false, Align(sizeof(void*)));
SI->insertAfter(ctx.topalloca);
varinfo.boxroot = av;
Expand Down
5 changes: 2 additions & 3 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2386,8 +2386,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
if (isLoadFromConstGV(LI, task_local) && getLoadValueAlign(LI) < 16) {
Type *T_int64 = Type::getInt64Ty(LI->getContext());
auto op = ConstantAsMetadata::get(ConstantInt::get(T_int64, 16));
LI->setMetadata(LLVMContext::MD_align,
MDNode::get(LI->getContext(), { op }));
LI->setMetadata(LLVMContext::MD_align, MDNode::get(LI->getContext(), { op }));
}
}
// As a last resort, if we didn't manage to strip down the tag
Expand Down Expand Up @@ -2468,7 +2467,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) {
}
ReplacementArgs.push_back(nframeargs == 0 ?
(llvm::Value*)ConstantPointerNull::get(T_pprjlvalue) :
(allocaAddressSpace ? Builder.CreateAddrSpaceCast(Frame, T_prjlvalue->getPointerTo(0)) : Frame));
Builder.CreateAddrSpaceCast(Frame, T_prjlvalue->getPointerTo(0)));
ReplacementArgs.push_back(ConstantInt::get(T_int32, nframeargs));
if (callee == call2_func) {
// move trailing arg to the end now
Expand Down