Skip to content

Commit

Permalink
Opaque pointer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
pchintalapudi committed Mar 6, 2022
1 parent db28215 commit 82962be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ else
ifeq ($(OS), Darwin)
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM
else
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM-13jl
CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM-14jl
endif
endif
endif
Expand Down
74 changes: 37 additions & 37 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1978,43 +1978,43 @@ static void emit_memcpy_llvm(jl_codectx_t &ctx, Value *dst, MDNode *tbaa_dst, Va
// If the types are small and simple, use load and store directly.
// Going through memcpy can cause LLVM (e.g. SROA) to create bitcasts between float and int
// that interferes with other optimizations.
if (sz <= 64) {
// The size limit is arbitrary but since we mainly care about floating points and
// machine size vectors this should be enough.
const DataLayout &DL = jl_Module->getDataLayout();
auto srcty = cast<PointerType>(src->getType());
//TODO unsafe nonopaque pointer
auto srcel = srcty->getElementType();
auto dstty = cast<PointerType>(dst->getType());
//TODO unsafe nonopaque pointer
auto dstel = dstty->getElementType();
if (srcel->isArrayTy() && srcel->getArrayNumElements() == 1) {
src = ctx.builder.CreateConstInBoundsGEP2_32(srcel, src, 0, 0);
srcel = srcel->getArrayElementType();
srcty = srcel->getPointerTo();
}
if (dstel->isArrayTy() && dstel->getArrayNumElements() == 1) {
dst = ctx.builder.CreateConstInBoundsGEP2_32(dstel, dst, 0, 0);
dstel = dstel->getArrayElementType();
dstty = dstel->getPointerTo();
}

llvm::Type *directel = nullptr;
if (srcel->isSized() && srcel->isSingleValueType() && DL.getTypeStoreSize(srcel) == sz) {
directel = srcel;
dst = emit_bitcast(ctx, dst, srcty);
}
else if (dstel->isSized() && dstel->isSingleValueType() &&
DL.getTypeStoreSize(dstel) == sz) {
directel = dstel;
src = emit_bitcast(ctx, src, dstty);
}
if (directel) {
auto val = tbaa_decorate(tbaa_src, ctx.builder.CreateAlignedLoad(directel, src, Align(align), is_volatile));
tbaa_decorate(tbaa_dst, ctx.builder.CreateAlignedStore(val, dst, Align(align), is_volatile));
return;
}
}
// if (sz <= 64) {
// // The size limit is arbitrary but since we mainly care about floating points and
// // machine size vectors this should be enough.
// const DataLayout &DL = jl_Module->getDataLayout();
// auto srcty = cast<PointerType>(src->getType());
// //TODO unsafe nonopaque pointer
// auto srcel = srcty->getElementType();
// auto dstty = cast<PointerType>(dst->getType());
// //TODO unsafe nonopaque pointer
// auto dstel = dstty->getElementType();
// if (srcel->isArrayTy() && srcel->getArrayNumElements() == 1) {
// src = ctx.builder.CreateConstInBoundsGEP2_32(srcel, src, 0, 0);
// srcel = srcel->getArrayElementType();
// srcty = srcel->getPointerTo();
// }
// if (dstel->isArrayTy() && dstel->getArrayNumElements() == 1) {
// dst = ctx.builder.CreateConstInBoundsGEP2_32(dstel, dst, 0, 0);
// dstel = dstel->getArrayElementType();
// dstty = dstel->getPointerTo();
// }

// llvm::Type *directel = nullptr;
// if (srcel->isSized() && srcel->isSingleValueType() && DL.getTypeStoreSize(srcel) == sz) {
// directel = srcel;
// dst = emit_bitcast(ctx, dst, srcty);
// }
// else if (dstel->isSized() && dstel->isSingleValueType() &&
// DL.getTypeStoreSize(dstel) == sz) {
// directel = dstel;
// src = emit_bitcast(ctx, src, dstty);
// }
// if (directel) {
// auto val = tbaa_decorate(tbaa_src, ctx.builder.CreateAlignedLoad(directel, src, Align(align), is_volatile));
// tbaa_decorate(tbaa_dst, ctx.builder.CreateAlignedStore(val, dst, Align(align), is_volatile));
// return;
// }
// }
// the memcpy intrinsic does not allow to specify different alias tags
// for the load part (x.tbaa) and the store part (ctx.tbaa().tbaa_stack).
// since the tbaa lattice has to be a tree we have unfortunately
Expand Down

0 comments on commit 82962be

Please sign in to comment.