Skip to content

Commit

Permalink
fix latest LLVM 11 compatibility issues
Browse files Browse the repository at this point in the history
- `CompositeType` and `SequentialType` classes have been removed
- `FileLineInfoSpecifier::Default` has been renamed to `RawValue`
- `CreateMemCpy` now takes `MaybeAlign`s instead of `unsigned`s
  • Loading branch information
yhls committed Apr 8, 2020
1 parent 7daa424 commit 4f8866e
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 18 deletions.
8 changes: 8 additions & 0 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1710,11 +1710,19 @@ static jl_cgval_t emit_ccall(jl_codectx_t &ctx, jl_value_t **args, size_t nargs)

ctx.builder.CreateMemCpy(
ctx.builder.CreateIntToPtr(destp, T_pint8),
#if JL_LLVM_VERSION >= 110000
MaybeAlign(1),
#else
1,
#endif
ctx.builder.CreateIntToPtr(
emit_unbox(ctx, T_size, src, (jl_value_t*)jl_voidpointer_type),
T_pint8),
#if JL_LLVM_VERSION >= 110000
MaybeAlign(0),
#else
0,
#endif
emit_unbox(ctx, T_size, n, (jl_value_t*)jl_ulong_type),
false);
JL_GC_POP();
Expand Down
21 changes: 18 additions & 3 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1341,9 +1341,16 @@ static void emit_write_multibarrier(jl_codectx_t&, Value*, Value*);

std::vector<unsigned> first_ptr(Type *T)
{
if (isa<CompositeType>(T)) {
if (!isa<StructType>(T) && cast<SequentialType>(T)->getNumElements() == 0)
return {};
if (isa<StructType>(T) || isa<ArrayType>(T) || isa<VectorType>(T)) {
if (!isa<StructType>(T)) {
uint64_t num_elements;
if (auto *AT = dyn_cast<ArrayType>(T))
num_elements = AT->getNumElements();
else if (auto *VT = dyn_cast<VectorType>(T))
num_elements = VT->getNumElements();
if (num_elements == 0)
return {};
}
unsigned i = 0;
for (Type *ElTy : T->subtypes()) {
if (isa<PointerType>(ElTy) && ElTy->getPointerAddressSpace() == AddressSpace::Tracked) {
Expand Down Expand Up @@ -1524,7 +1531,11 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
// for the load part (x.tbaa) and the store part (tbaa_stack).
// since the tbaa lattice has to be a tree we have unfortunately
// x.tbaa ∪ tbaa_stack = tbaa_root if x.tbaa != tbaa_stack
#if JL_LLVM_VERSION >= 110000
ctx.builder.CreateMemCpy(dst, MaybeAlign(align), src, MaybeAlign(0), sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#else
ctx.builder.CreateMemCpy(dst, align, src, 0, sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#endif
}

static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Value *src, MDNode *tbaa_src,
Expand All @@ -1534,7 +1545,11 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
emit_memcpy_llvm(ctx, dst, tbaa_dst, src, tbaa_src, const_sz->getZExtValue(), align, is_volatile);
return;
}
#if JL_LLVM_VERSION >= 110000
ctx.builder.CreateMemCpy(dst, MaybeAlign(align), src, MaybeAlign(0), sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#else
ctx.builder.CreateMemCpy(dst, align, src, 0, sz, is_volatile, MDNode::getMostGenericTBAA(tbaa_dst, tbaa_src));
#endif
}

template<typename T1>
Expand Down
10 changes: 10 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3264,7 +3264,11 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
Value *isboxed = ctx.builder.CreateICmpNE(
ctx.builder.CreateAnd(Tindex_phi, ConstantInt::get(T_int8, 0x80)),
ConstantInt::get(T_int8, 0));
#if JL_LLVM_VERSION >= 110000
ctx.builder.CreateMemCpy(phi, MaybeAlign(min_align), dest, MaybeAlign(0), nbytes, false);
#else
ctx.builder.CreateMemCpy(phi, min_align, dest, 0, nbytes, false);
#endif
ctx.builder.CreateLifetimeEnd(dest);
Value *ptr = ctx.builder.CreateSelect(isboxed,
maybe_bitcast(ctx, decay_derived(ptr_phi), T_pint8),
Expand Down Expand Up @@ -3304,9 +3308,15 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
// here it's moved into phi in the successor (from dest)
dest = emit_static_alloca(ctx, vtype);
Value *phi = emit_static_alloca(ctx, vtype);
#if JL_LLVM_VERSION >= 110000
ctx.builder.CreateMemCpy(phi, MaybeAlign(julia_alignment(phiType)),
dest, MaybeAlign(0),
jl_datatype_size(phiType), false);
#else
ctx.builder.CreateMemCpy(phi, julia_alignment(phiType),
dest, 0,
jl_datatype_size(phiType), false);
#endif
ctx.builder.CreateLifetimeEnd(dest);
slot = mark_julia_slot(phi, phiType, NULL, tbaa_stack);
}
Expand Down
9 changes: 7 additions & 2 deletions src/disasm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,8 +900,13 @@ static void jl_dump_asm_internal(
if (pass != 0 && nextLineAddr != (uint64_t)-1 && Index + Fptr + slide == nextLineAddr) {
if (di_ctx) {
std::string buf;
DILineInfoSpecifier infoSpec(DILineInfoSpecifier::FileLineInfoKind::Default,
DILineInfoSpecifier::FunctionNameKind::ShortName);
DILineInfoSpecifier infoSpec(
#if JL_LLVM_VERSION >= 110000
DILineInfoSpecifier::FileLineInfoKind::RawValue,
#else
DILineInfoSpecifier::FileLineInfoKind::Default,
#endif
DILineInfoSpecifier::FunctionNameKind::ShortName);
DIInliningInfo dbg = di_ctx->getInliningInfoForAddress(makeAddress(Section, Index + Fptr + slide), infoSpec);
if (dbg.getNumberOfFrames()) {
dbgctx.emit_lineinfo(buf, dbg);
Expand Down
14 changes: 9 additions & 5 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ static Constant *julia_const_to_llvm(jl_codectx_t &ctx, const void *ptr, jl_data
return ConstantInt::get(lt, val);
}

CompositeType *lct = cast<CompositeType>(lt);
size_t nf = jl_datatype_nfields(bt);
std::vector<Constant*> fields(0);
for (size_t i = 0; i < nf; i++) {
Expand All @@ -200,7 +199,12 @@ static Constant *julia_const_to_llvm(jl_codectx_t &ctx, const void *ptr, jl_data
assert(!jl_field_isptr(bt, i));
unsigned llvm_idx = isa<StructType>(lt) ? convert_struct_offset(lt, offs) : i;
while (fields.size() < llvm_idx)
fields.push_back(UndefValue::get(lct->getTypeAtIndex(fields.size())));
fields.push_back(
#if JL_LLVM_VERSION >= 110000
UndefValue::get(GetElementPtrInst::getTypeAtIndex(lt, fields.size())));
#else
UndefValue::get(cast<CompositeType>(lt)->getTypeAtIndex(fields.size())));
#endif
const uint8_t *ov = (const uint8_t*)ptr + offs;
if (jl_is_uniontype(ft)) {
// compute the same type layout as julia_struct_to_llvm
Expand Down Expand Up @@ -255,11 +259,11 @@ static Constant *julia_const_to_llvm(jl_codectx_t &ctx, const void *ptr, jl_data
}
}

if (lct->isVectorTy())
if (lt->isVectorTy())
return ConstantVector::get(fields);
if (StructType *st = dyn_cast<StructType>(lct))
if (StructType *st = dyn_cast<StructType>(lt))
return ConstantStruct::get(st, fields);
ArrayType *at = cast<ArrayType>(lct);
ArrayType *at = cast<ArrayType>(lt);
return ConstantArray::get(at, fields);
}

Expand Down
7 changes: 6 additions & 1 deletion src/llvm-alloc-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,13 @@ static bool hasObjref(Type *ty)
{
if (auto ptrty = dyn_cast<PointerType>(ty))
return ptrty->getAddressSpace() == AddressSpace::Tracked;
#if JL_LLVM_VERSION >= 110000
if (isa<ArrayType>(ty) || isa<VectorType>(ty))
return GetElementPtrInst::getTypeAtIndex(ty, (uint64_t)0);
#else
if (auto seqty = dyn_cast<SequentialType>(ty))
return hasObjref(seqty->getElementType());
#endif
if (auto structty = dyn_cast<StructType>(ty)) {
for (auto elty: structty->elements()) {
if (hasObjref(elty)) {
Expand Down Expand Up @@ -504,7 +509,7 @@ bool Optimizer::AllocUseInfo::addMemOp(Instruction *inst, unsigned opno, uint32_
if (size >= UINT32_MAX - offset)
return false;
memop.size = size;
memop.isaggr = isa<CompositeType>(elty);
memop.isaggr = isa<StructType>(elty) || isa<ArrayType>(elty) || isa<VectorType>(elty);
memop.isobjref = hasObjref(elty);
auto &field = getField(offset, size, elty);
if (field.first != offset || field.second.size != size)
Expand Down
30 changes: 23 additions & 7 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,22 +388,29 @@ CountTrackedPointers::CountTrackedPointers(Type *T) {
if (T->getPointerAddressSpace() != AddressSpace::Tracked)
derived = true;
}
} else if (isa<CompositeType>(T)) {
} else if (isa<StructType>(T) || isa<ArrayType>(T) || isa<VectorType>(T)) {
for (Type *ElT : T->subtypes()) {
auto sub = CountTrackedPointers(ElT);
count += sub.count;
all &= sub.all;
derived |= sub.derived;
}
if (isa<SequentialType>(T))
count *= cast<SequentialType>(T)->getNumElements();
if (isa<ArrayType>(T))
count *= cast<ArrayType>(T)->getNumElements();
else if (isa<VectorType>(T))
count *= cast<VectorType>(T)->getNumElements();
}
if (count == 0)
all = false;
}

unsigned getCompositeNumElements(Type *T) {
return isa<StructType>(T) ? T->getStructNumElements() : cast<SequentialType>(T)->getNumElements();
if (isa<StructType>(T))
return T->getStructNumElements();
else if (auto *AT = dyn_cast<ArrayType>(T))
return AT->getNumElements();
else if (auto *VT = dyn_cast<VectorType>(T))
return VT->getNumElements();
}

// Walk through a Type, and record the element path to every tracked value inside
Expand All @@ -412,11 +419,15 @@ void TrackCompositeType(Type *T, std::vector<unsigned> &Idxs, std::vector<std::v
if (T->getPointerAddressSpace() == AddressSpace::Tracked)
Numberings.push_back(Idxs);
}
else if (isa<CompositeType>(T)) {
else if (isa<StructType>(T) || isa<ArrayType>(T) || isa<VectorType>(T)) {
unsigned Idx, NumEl = getCompositeNumElements(T);
for (Idx = 0; Idx < NumEl; Idx++) {
Idxs.push_back(Idx);
Type *ElT = cast<CompositeType>(T)->getTypeAtIndex(Idx);
#if JL_LLVM_VERSION >= 110000
Type *ElT = GetElementPtrInst::getTypeAtIndex(T, Idx);
#else
Type *ElT = cast<CompositeType>(T)->getTypeAtIndex(Idx);
#endif
TrackCompositeType(ElT, Idxs, Numberings);
Idxs.pop_back();
}
Expand Down Expand Up @@ -551,7 +562,12 @@ Value *LateLowerGCFrame::MaybeExtractScalar(State &S, std::pair<Value*,int> ValE
auto IdxsNotVec = Idxs.slice(0, Idxs.size() - 1);
Type *FinalT = ExtractValueInst::getIndexedType(V->getType(), IdxsNotVec);
bool IsVector = isa<VectorType>(FinalT);
PointerType *T = cast<PointerType>(cast<CompositeType>(FinalT)->getTypeAtIndex(Idxs.back()));
PointerType *T = cast<PointerType>(
#if JL_LLVM_VERSION >= 110000
GetElementPtrInst::getTypeAtIndex(FinalT, Idxs.back()));
#else
cast<CompositeType>(FinalT)->getTypeAtIndex(Idxs.back()));
#endif
if (T->getAddressSpace() != AddressSpace::Tracked) {
// if V isn't tracked, get the shadow def
auto Numbers = NumberAllBase(S, V);
Expand Down

0 comments on commit 4f8866e

Please sign in to comment.