Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DONOTMERGE] Debug x86 darwin issue #57821

Draft
wants to merge 20 commits into
base: master
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
JULIAHOME := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))
$(shell mkdir -p deps/srccache && curl -L https://buildkite.com/organizations/julialang/pipelines/yggdrasil/builds/18641/jobs/01959975-326e-4669-bbc7-1d71e996d9c8/artifacts/01959cef-8c11-491c-b86d-46e643505db3 > deps/srccache/libLLVM.v19.1.7+1.x86_64-apple-darwin-llvm_version+19.tar.gz)
include $(JULIAHOME)/Make.inc
# import LLVM_SHARED_LIB_NAME
include $(JULIAHOME)/deps/llvm-ver.make

Check warning on line 6 in Makefile

View workflow job for this annotation

GitHub Actions / Check whitespace

Whitespace check

trailing whitespace
# Make sure the user didn't try to build in a path that will confuse the shell or make
METACHARACTERS := [][?*{}() $$%:;&|!\#,\\`\": ]\|/\./\|/\.\./
ifneq (,$(findstring ',$(value BUILDROOT)))
Expand Down
482 changes: 0 additions & 482 deletions deps/checksums/llvm

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion deps/llvm-ver.make
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ ifeq ($(LLVM_VER_PATCH),)
LLVM_VER_PATCH := 0
endif

LLVM_SHARED_LIB_VER_SUFFIX := $(LLVM_VER_MAJ)jl
LLVM_SHARED_LIB_VER_SUFFIX := 20jl
# e.g.: "libLLVM-14jl"
LLVM_SHARED_LIB_NAME := libLLVM-$(LLVM_SHARED_LIB_VER_SUFFIX)
LLVM_SHARED_LINK_FLAG := -lLLVM-$(LLVM_SHARED_LIB_VER_SUFFIX)
Expand Down
8 changes: 4 additions & 4 deletions deps/tools/jlchecksum
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ find_checksum()
fi
done
if [ ! -f "$DEPSDIR/checksums/$BASENAME/$CHECKSUM_TYPE" ]; then
if [ "${TAGGED_RELEASE_BANNER:-}" ]; then
echo "WARNING: $CHECKSUM_TYPE checksum for $BASENAME not found in deps/checksums/, failing release build." >&2
exit 3
fi
# if [ "${TAGGED_RELEASE_BANNER:-}" ]; then
# echo "WARNING: $CHECKSUM_TYPE checksum for $BASENAME not found in deps/checksums/, failing release build." >&2
# exit 3
# fi
echo "WARNING: $CHECKSUM_TYPE checksum for $BASENAME not found in deps/checksums/, autogenerating..." >&2

# Generate as many checksum types as we can
Expand Down
4 changes: 4 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5824,7 +5824,11 @@ static void emit_phinode_assign(jl_codectx_t &ctx, ssize_t idx, jl_value_t *r)
unsigned nb = jl_datatype_size(phiType);
dest = emit_static_alloca(ctx, nb, align);
phi = cast<AllocaInst>(dest->clone());
#if JL_LLVM_VERSION >= 200000
phi->insertBefore(dest->getIterator());
#else
phi->insertBefore(dest);
#endif
ctx.builder.CreateMemCpy(phi, align, dest, align, nb, false);
ctx.builder.CreateLifetimeEnd(dest);
}
Expand Down
3 changes: 2 additions & 1 deletion src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#include <llvm/ExecutionEngine/Orc/DebugObjectManagerPlugin.h>
#include <llvm/ExecutionEngine/Orc/TargetProcess/JITLoaderGDB.h>
#if JL_LLVM_VERSION >= 200000
#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h"
#include <llvm/ExecutionEngine/Orc/AbsoluteSymbols.h>
#include <llvm/ExecutionEngine/Orc/EHFrameRegistrationPlugin.h>
#endif
#if JL_LLVM_VERSION >= 180000
#include <llvm/ExecutionEngine/Orc/Debugging/DebugInfoSupport.h>
Expand Down
4 changes: 4 additions & 0 deletions src/llvm-julia-licm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ static void moveInstructionBefore(Instruction &I, Instruction &Dest,
MemorySSAUpdater &MSSAU,
ScalarEvolution *SE,
MemorySSA::InsertionPlace Place = MemorySSA::BeforeTerminator) {
#if JL_LLVM_VERSION >= 200000
I.moveBefore(Dest.getIterator());
#else
I.moveBefore(&Dest);
#endif
if (MSSAU.getMemorySSA())
if (MemoryUseOrDef *OldMemAcc = cast_or_null<MemoryUseOrDef>(
MSSAU.getMemorySSA()->getMemoryAccess(&I)))
Expand Down
74 changes: 68 additions & 6 deletions src/llvm-late-gc-lowering.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// This file is a part of Julia. License is MIT: https://julialang.org/license

#include "llvm-gc-interface-passes.h"
#include "llvm/IR/Intrinsics.h"
#include "llvm/Support/Casting.h"

#define DEBUG_TYPE "late_lower_gcroot"

Expand Down Expand Up @@ -171,12 +173,12 @@
(void)LI;
break;
}
else if (auto II = dyn_cast<IntrinsicInst>(CurrentV)) {
// Some intrinsics behave like LoadInst followed by a SelectInst
// This should never happen in a derived addrspace (since those cannot be stored to memory)
// so we don't need to lift these operations, but we do need to check if it's loaded and continue walking the base pointer
else if (auto *II = dyn_cast<IntrinsicInst>(CurrentV)) {
if (II->getIntrinsicID() == Intrinsic::masked_load ||
II->getIntrinsicID() == Intrinsic::masked_gather) {
// Some intrinsics behave like LoadInst followed by a SelectInst
// This should never happen in a derived addrspace (since those cannot be stored to memory)
// so we don't need to lift these operations, but we do need to check if it's loaded and continue walking the base pointer
if (auto VTy = dyn_cast<VectorType>(II->getType())) {
if (hasLoadedTy(VTy->getElementType())) {
Value *Mask = II->getOperand(2);
Expand Down Expand Up @@ -205,16 +207,36 @@
// In general a load terminates a walk
break;
}
else if (II->getIntrinsicID() == Intrinsic::vector_extract) {
if (auto VTy = dyn_cast<VectorType>(II->getType())) {
if (hasLoadedTy(VTy->getElementType())) {
Value *Idx = II->getOperand(1);
if (!isa<ConstantInt>(Idx)) {
assert(isa<UndefValue>(Idx) && "unimplemented");
(void)Idx;
}
CurrentV = II->getOperand(0);
fld_idx = -1;
continue;
}
}
break;
} else {
// Unknown Intrinsic
break;
}
}
else if (auto CI = dyn_cast<CallInst>(CurrentV)) {
auto callee = CI->getCalledFunction();
if (callee && callee->getName() == "julia.gc_loaded") {
CurrentV = CI->getArgOperand(0);
continue;
}
// Unkown Call

Check warning on line 235 in src/llvm-late-gc-lowering.cpp

View workflow job for this annotation

GitHub Actions / Check for new typos

perhaps "Unkown" should be "Unknown".
break;
}
else {
// Unknown Instruction
break;
}
}
Expand Down Expand Up @@ -530,6 +552,22 @@
Numbers = NumberAll(S, IEI->getOperand(0));
int ElNumber = Number(S, IEI->getOperand(1));
Numbers[idx] = ElNumber;
// C++17
// } else if (auto *II = dyn_cast<IntrinsicInst>(CurrentV); II && II->getIntrinsicID() == Intrinsic::vector_insert) {
} else if (isa<IntrinsicInst>(CurrentV) && cast<IntrinsicInst>(CurrentV)->getIntrinsicID() == Intrinsic::vector_insert) {
auto *II = dyn_cast<IntrinsicInst>(CurrentV);
// Vector insert is a bit like a shuffle so use the same approach
SmallVector<int, 0> Numbers1 = NumberAll(S, II->getOperand(0));
SmallVector<int, 0> Numbers2 = NumberAll(S, II->getOperand(1));
unsigned first_idx = cast<ConstantInt>(II->getOperand(2))->getZExtValue();
for (unsigned i = 0; i < Numbers1.size(); ++i) {
if (i < first_idx)
Numbers.push_back(Numbers1[i]);
else if (i - first_idx < Numbers2.size())
Numbers.push_back(Numbers2[i - first_idx]);
else
Numbers.push_back(Numbers1[i]);
}
} else if (auto *IVI = dyn_cast<InsertValueInst>(CurrentV)) {
Numbers = NumberAll(S, IVI->getAggregateOperand());
auto Tracked = TrackCompositeType(IVI->getType());
Expand Down Expand Up @@ -1206,6 +1244,10 @@
}
}
}
if (II->getIntrinsicID() == Intrinsic::vector_extract || II->getIntrinsicID() == Intrinsic::vector_insert) {
// These are not real defs
continue;
}
}
auto callee = CI->getCalledFunction();
if (callee && callee == typeof_func) {
Expand Down Expand Up @@ -2372,7 +2414,11 @@
// free to rewrite them if convenient. We need to change
// it back here for the store.
assert(Val->getType() == T_prjlvalue);
#if JL_LLVM_VERSION >= 200000
new StoreInst(Val, slotAddress, InsertBefore->getIterator());
#else
new StoreInst(Val, slotAddress, InsertBefore);
#endif
}

void LateLowerGCFrame::PlaceGCFrameReset(State &S, unsigned R, unsigned MinColorRoot,
Expand All @@ -2382,10 +2428,18 @@
auto slotAddress = CallInst::Create(
getOrDeclare(jl_intrinsics::getGCFrameSlot),
{GCFrame, ConstantInt::get(Type::getInt32Ty(InsertBefore->getContext()), Colors[R] + MinColorRoot)},
#if JL_LLVM_VERSION >= 200000
"gc_slot_addr_" + StringRef(std::to_string(Colors[R] + MinColorRoot)), InsertBefore->getIterator());
#else
"gc_slot_addr_" + StringRef(std::to_string(Colors[R] + MinColorRoot)), InsertBefore);
#endif
// Reset the slot to NULL.
Value *Val = ConstantPointerNull::get(T_prjlvalue);
#if JL_LLVM_VERSION >= 200000
new StoreInst(Val, slotAddress, InsertBefore->getIterator());
#else
new StoreInst(Val, slotAddress, InsertBefore);
#endif
}

void LateLowerGCFrame::PlaceGCFrameStores(State &S, unsigned MinColorRoot,
Expand All @@ -2406,7 +2460,7 @@
for (int Idx : *LastLive) {
if (Colors[Idx] >= PreAssignedColors && !HasBitSet(NowLive, Idx)) {
PlaceGCFrameReset(S, Idx, MinColorRoot, Colors, GCFrame,
S.ReverseSafepointNumbering[*rit]);
S.ReverseSafepointNumbering[*rit]);
}
}
// store values which are alive in this safepoint but
Expand Down Expand Up @@ -2438,7 +2492,7 @@
getOrDeclare(jl_intrinsics::newGCFrame),
{ConstantInt::get(T_int32, 0)},
"gcframe");
gcframe->insertBefore(&*F->getEntryBlock().begin());
gcframe->insertBefore(F->getEntryBlock().begin());

auto pushGcframe = CallInst::Create(
getOrDeclare(jl_intrinsics::pushGCFrame),
Expand Down Expand Up @@ -2536,7 +2590,11 @@
assert(Elem->getType() == T_prjlvalue);
//auto Idxs = ArrayRef<unsigned>(Tracked[i]);
//Value *Elem = ExtractScalar(Base, true, Idxs, SI);
#if JL_LLVM_VERSION >= 200000
Value *shadowStore = new StoreInst(Elem, slotAddress, SI->getIterator());
#else
Value *shadowStore = new StoreInst(Elem, slotAddress, SI);
#endif
(void)shadowStore;
// TODO: shadowStore->setMetadata(LLVMContext::MD_tbaa, tbaa_gcframe);
AllocaSlot++;
Expand All @@ -2554,7 +2612,11 @@
auto popGcframe = CallInst::Create(
getOrDeclare(jl_intrinsics::popGCFrame),
{gcframe});
#if JL_LLVM_VERSION >= 200000
popGcframe->insertBefore(BB.getTerminator()->getIterator());
#else
popGcframe->insertBefore(BB.getTerminator());
#endif
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/llvm-propagate-addrspaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,11 @@ bool propagateJuliaAddrspaces(Function &F) {
PropagateJuliaAddrspacesVisitor visitor;
visitor.visit(F);
for (auto it : visitor.ToInsert)
#if JL_LLVM_VERSION >= 200000
it.first->insertBefore(it.second->getIterator());
#else
it.first->insertBefore(it.second);
#endif
for (Instruction *I : visitor.ToDelete)
I->eraseFromParent();
visitor.ToInsert.clear();
Expand Down
8 changes: 8 additions & 0 deletions src/llvm-ptls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter,
adoptFunc->copyMetadata(pgcstack_getter, 0);
}
adopt->setCalledFunction(adoptFunc);
#if JL_LLVM_VERSION >= 200000
adopt->insertBefore(slowTerm->getIterator());
#else
adopt->insertBefore(slowTerm);
#endif
phi->addIncoming(adopt, slowTerm->getParent());
// emit fast branch code
builder.SetInsertPoint(fastTerm->getParent());
Expand Down Expand Up @@ -237,7 +241,11 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter,
builder.SetInsertPoint(pgcstack);
auto phi = builder.CreatePHI(T_pppjlvalue, 2, "pgcstack");
pgcstack->replaceAllUsesWith(phi);
#if JL_LLVM_VERSION >= 200000
pgcstack->moveBefore(slowTerm->getIterator());
#else
pgcstack->moveBefore(slowTerm);
#endif
// refresh the basic block in the builder
builder.SetInsertPoint(pgcstack);
auto getter = builder.CreateLoad(T_pgcstack_getter, pgcstack_func_slot);
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/gcroots.ll
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ define i8 @gather_arrayptrs_alltrue() {
; OPAQUE: %gcframe = alloca ptr addrspace(10), i32 3


; OPAQUE: %arrayptrs = call <2 x ptr addrspace(13)> @llvm.masked.gather.v2p13.v2p11(<2 x ptr addrspace(11)> %arrayptrptrs, i32 16, <2 x i1> <i1 true, i1 true>, <2 x ptr addrspace(13)> zeroinitializer)
; OPAQUE: %arrayptrs = call <2 x ptr addrspace(13)> @llvm.masked.gather.v2p13.v2p11(<2 x ptr addrspace(11)> %arrayptrptrs, i32 16, <2 x i1> {{(<i1 true, i1 true>|splat \(i1 true\))}}, <2 x ptr addrspace(13)> zeroinitializer)
; OPAQUE: [[GEP0:%.*]] = getelementptr inbounds ptr addrspace(10), ptr %gcframe, i32 2
; OPAQUE: store ptr addrspace(10) %obj1, ptr [[GEP0]]
;
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/image-codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# RUN: export JULIA_LLVM_ARGS="--print-before=loop-vectorize --print-module-scope"
# RUN: rm -rf %t
# RUN: mkdir %t
# RUN: julia --image-codegen --startup-file=no %s 2> %t/output.txt
# RUN: julia --image-codegen -t1,0 --startup-file=no %s 2> %t/output.txt
# RUN: FileCheck %s < %t/output.txt

# COM: checks that global variables compiled in imaging codegen
Expand Down
15 changes: 15 additions & 0 deletions test/llvmpasses/late-lower-gc.ll
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,21 @@ define {} addrspace(10)* @gclift_switch({} addrspace(13)* addrspace(10)* %input,
ret {} addrspace(10)* %ret
}

; Shouldn't hang
define void @vector_insert(<4 x {} addrspace(10)* > %0, <2 x {} addrspace(10)* > %1) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%2 = call <4 x {} addrspace(10)*> @llvm.vector.insert.v4p10.v2p10(<4 x {} addrspace(10)*> %0, <2 x {} addrspace(10)*> %1, i64 2)
ret void
}

define void @vector_extract(<4 x {} addrspace(10)* > %0, <2 x {} addrspace(10)* > %1) {
top:
%pgcstack = call {}*** @julia.get_pgcstack()
%2 = call <2 x {} addrspace(10)*> @llvm.vector.extract.v2p10.v4p10(<4 x {} addrspace(10)* > %0, i64 2)
ret void
}

define void @decayar([2 x {} addrspace(10)* addrspace(11)*] %ar) {
%v2 = call {}*** @julia.get_pgcstack()
%e0 = extractvalue [2 x {} addrspace(10)* addrspace(11)*] %ar, 0
Expand Down
Loading