From d534080c65d4d490020aaa4d71f19ec7a88cdc64 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:22:31 +0000 Subject: [PATCH 01/16] Adapt to "CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker (#100310)" https://github.com/llvm/llvm-project/commit/9a258664024d12a06ba8eb9344e270a9bb5f5d87 --- src/codegen.cpp | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index fe2bd4fc3d097..efa4d8ee47d8c 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -76,6 +76,7 @@ #include "llvm/Support/Path.h" // for llvm::sys::path #include #include +#include #ifdef USE_ITTAPI #include "ittapi/ittnotify.h" @@ -10565,17 +10566,29 @@ namespace llvm { class MachineBasicBlock; class MachineFunction; raw_ostream& operator<<(raw_ostream &OS, const MachineBasicBlock &MBB); - void printMIR(raw_ostream &OS, const MachineFunction &MF); +#if JL_LLVM_VERSION >= 200000 + void printMIR(raw_ostream &OS, const MachineModuleInfo &MMI, + const MachineFunction &MF); +#else +void printMIR(raw_ostream &OS, const MachineFunction &MF); +#endif } extern "C" void jl_dump_llvm_mbb(void *v) { errs() << *(llvm::MachineBasicBlock*)v; } +#if JL_LLVM_VERSION >= 200000 +extern "C" void jl_dump_llvm_mfunction(void *m, void *v) +{ + llvm::printMIR(errs(), *(llvm::MachineModuleInfo*)v, + *(llvm::MachineFunction*)v); +} +#else extern "C" void jl_dump_llvm_mfunction(void *v) { llvm::printMIR(errs(), *(llvm::MachineFunction*)v); } - +#endif extern void jl_write_bitcode_func(void *F, char *fname) { std::error_code EC; From d2c8ae3e9417448006773ac57123f6457fc61c9a Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:23:45 +0000 Subject: [PATCH 02/16] Adapt to "[DataLayout] Remove clear and reset methods (NFC) (#102993)" https://github.com/llvm/llvm-project/commit/b1aa0b0b88a0bca2553f8c6d6c52ec3b7205064b --- src/jitlayers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 80642bef95619..5671027faca34 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -1956,7 +1956,7 @@ void fixupTM(TargetMachine &TM) { llvm::DataLayout jl_create_datalayout(TargetMachine &TM) { // Mark our address spaces as non-integral auto jl_data_layout = TM.createDataLayout(); - jl_data_layout.reset(jl_data_layout.getStringRepresentation() + "-ni:10:11:12:13"); + jl_data_layout = DataLayout(jl_data_layout.getStringRepresentation() + "-ni:10:11:12:13"); return jl_data_layout; } From 8de4aae2f47732ce50be8876a8e418204b7fb671 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:25:05 +0000 Subject: [PATCH 03/16] Adapt to "[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)" https://github.com/llvm/llvm-project/commit/2f50b280dc8e995ef67ad31a5f71adc4c270890d --- src/codegen.cpp | 2 +- src/llvm-alloc-opt.cpp | 10 +++++----- src/llvm-julia-licm.cpp | 2 +- src/llvm-late-gc-lowering.cpp | 24 ++++++++++++++---------- src/llvm-multiversioning.cpp | 6 +++--- src/llvm-ptls.cpp | 4 ++-- 6 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index efa4d8ee47d8c..5cbca62a6f54b 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2352,7 +2352,7 @@ static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_con static AllocaInst *emit_static_alloca(jl_codectx_t &ctx, Type *lty, Align align) { ++EmittedAllocas; - return new AllocaInst(lty, ctx.topalloca->getModule()->getDataLayout().getAllocaAddrSpace(), nullptr, align, "", /*InsertBefore=*/ctx.topalloca); + return new AllocaInst(lty, ctx.topalloca->getModule()->getDataLayout().getAllocaAddrSpace(), nullptr, align, "", /*InsertBefore=*/ctx.topalloca->getIterator()); } static AllocaInst *emit_static_alloca(jl_codectx_t &ctx, unsigned nb, Align align) diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index 7dd794a4d8847..7928d6824fb7d 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -427,12 +427,12 @@ void Optimizer::insertLifetimeEnd(Value *ptr, Constant *sz, Instruction *insert) } break; } - CallInst::Create(pass.lifetime_end, {sz, ptr}, "", insert); + CallInst::Create(pass.lifetime_end, {sz, ptr}, "", insert->getIterator()); } void Optimizer::insertLifetime(Value *ptr, Constant *sz, Instruction *orig) { - CallInst::Create(pass.lifetime_start, {sz, ptr}, "", orig); + CallInst::Create(pass.lifetime_start, {sz, ptr}, "", orig->getIterator()); BasicBlock *def_bb = orig->getParent(); std::set bbs{def_bb}; auto &DT = getDomTree(); @@ -630,7 +630,7 @@ void Optimizer::replaceIntrinsicUseWith(IntrinsicInst *call, Intrinsic::ID ID, auto newF = Intrinsic::getDeclaration(call->getModule(), ID, overloadTys); assert(newF->getFunctionType() == newfType); newF->setCallingConv(call->getCallingConv()); - auto newCall = CallInst::Create(newF, args, "", call); + auto newCall = CallInst::Create(newF, args, "", call->getIterator()); newCall->setTailCallKind(call->getTailCallKind()); auto old_attrs = call->getAttributes(); newCall->setAttributes(AttributeList::get(pass.getLLVMContext(), getFnAttrs(old_attrs), @@ -795,7 +795,7 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref, AllocF SmallVector IdxOperands(gep->idx_begin(), gep->idx_end()); auto new_gep = GetElementPtrInst::Create(gep->getSourceElementType(), new_i, IdxOperands, - gep->getName(), gep); + gep->getName(), gep->getIterator()); new_gep->setIsInBounds(gep->isInBounds()); new_gep->takeName(gep); new_gep->copyMetadata(*gep); @@ -1238,7 +1238,7 @@ void Optimizer::splitOnStack(CallInst *orig_inst) bundle = OperandBundleDef("jl_roots", std::move(operands)); break; } - auto new_call = CallInst::Create(call, bundles, call); + auto new_call = CallInst::Create(call, bundles, call->getIterator()); new_call->takeName(call); call->replaceAllUsesWith(new_call); call->eraseFromParent(); diff --git a/src/llvm-julia-licm.cpp b/src/llvm-julia-licm.cpp index baf844dffa89c..e09f5cad92102 100644 --- a/src/llvm-julia-licm.cpp +++ b/src/llvm-julia-licm.cpp @@ -238,7 +238,7 @@ struct JuliaLICM : public JuliaPassContext { }); for (unsigned i = 1; i < exit_pts.size(); i++) { // Clone exit - auto CI = CallInst::Create(call, {}, exit_pts[i]); + auto CI = CallInst::Create(call, {}, exit_pts[i]->getIterator()); exit_pts[i] = CI; createNewInstruction(CI, call, MSSAU); LLVM_DEBUG(dbgs() << "Cloned and sunk gc_preserve_end: " << *CI << "\n"); diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index 1b7551f33ebcd..c39a46b9276d1 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -348,10 +348,10 @@ void LateLowerGCFrame::LiftSelect(State &S, SelectInst *SI) { if (isa(Cond->getType())) { Cond = ExtractElementInst::Create(Cond, ConstantInt::get(Type::getInt32Ty(Cond->getContext()), i), - "", SI); + "", SI->getIterator()); } assert(FalseElem->getType() == TrueElem->getType()); - SelectInst *SelectBase = SelectInst::Create(Cond, TrueElem, FalseElem, "gclift", SI); + SelectInst *SelectBase = SelectInst::Create(Cond, TrueElem, FalseElem, "gclift", SI->getIterator()); int Number = ++S.MaxPtrNumber; S.AllPtrNumbering[SelectBase] = Number; S.ReversePtrNumbering[Number] = SelectBase; @@ -389,7 +389,7 @@ void LateLowerGCFrame::LiftPhi(State &S, PHINode *Phi) { Numbers.resize(NumRoots); } for (unsigned i = 0; i < NumRoots; ++i) { - PHINode *lift = PHINode::Create(T_prjlvalue, Phi->getNumIncomingValues(), "gclift", Phi); + PHINode *lift = PHINode::Create(T_prjlvalue, Phi->getNumIncomingValues(), "gclift", Phi->getIterator()); int Number = ++S.MaxPtrNumber; S.AllPtrNumbering[lift] = Number; S.ReversePtrNumbering[Number] = lift; @@ -1970,7 +1970,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { if (T_prjlvalue) { T_pprjlvalue = T_prjlvalue->getPointerTo(); Frame = new AllocaInst(T_prjlvalue, allocaAddressSpace, - ConstantInt::get(T_int32, maxframeargs), "jlcallframe", StartOff); + ConstantInt::get(T_int32, maxframeargs), "jlcallframe", StartOff->getIterator()); } SmallVector write_barriers; for (BasicBlock &BB : F) { @@ -2011,13 +2011,13 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { /* No replacement */ } else if (pointer_from_objref_func != nullptr && callee == pointer_from_objref_func) { auto *obj = CI->getOperand(0); - auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI); + auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI->getIterator()); ASCI->takeName(CI); CI->replaceAllUsesWith(ASCI); UpdatePtrNumbering(CI, ASCI, S); } else if (gc_loaded_func != nullptr && callee == gc_loaded_func) { auto *obj = CI->getOperand(1); - auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI); + auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI->getIterator()); ASCI->takeName(CI); CI->replaceAllUsesWith(ASCI); UpdatePtrNumbering(CI, ASCI, S); @@ -2170,7 +2170,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { FunctionType *FTy = callee == call3_func ? JuliaType::get_jlfunc3_ty(CI->getContext()) : callee == call2_func ? JuliaType::get_jlfunc2_ty(CI->getContext()) : JuliaType::get_jlfunc_ty(CI->getContext()); - CallInst *NewCall = CallInst::Create(FTy, new_callee, ReplacementArgs, "", CI); + CallInst *NewCall = CallInst::Create(FTy, new_callee, ReplacementArgs, "", CI->getIterator()); NewCall->setTailCallKind(CI->getTailCallKind()); auto callattrs = CI->getAttributes(); callattrs = AttributeList::get(CI->getContext(), getFnAttrs(callattrs), getRetAttrs(callattrs), {}); @@ -2216,7 +2216,11 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { continue; } else { // remove operand bundle +#if JL_LLVM_VERSION >= 200000 + CallInst *NewCall = CallInst::Create(CI, None, CI->getIterator()); +#else CallInst *NewCall = CallInst::Create(CI, None, CI); +#endif NewCall->takeName(CI); NewCall->copyMetadata(*CI); CI->replaceAllUsesWith(NewCall); @@ -2283,14 +2287,14 @@ void LateLowerGCFrame::PlaceGCFrameStore(State &S, unsigned R, unsigned MinColor auto slotAddress = CallInst::Create( getOrDeclare(jl_intrinsics::getGCFrameSlot), {GCFrame, ConstantInt::get(Type::getInt32Ty(InsertBefore->getContext()), Colors[R] + MinColorRoot)}, - "gc_slot_addr_" + StringRef(std::to_string(Colors[R] + MinColorRoot)), InsertBefore); + "gc_slot_addr_" + StringRef(std::to_string(Colors[R] + MinColorRoot)), InsertBefore->getIterator()); Value *Val = GetPtrForNumber(S, R, InsertBefore); // Pointee types don't have semantics, so the optimizer is // free to rewrite them if convenient. We need to change // it back here for the store. assert(Val->getType() == T_prjlvalue); - new StoreInst(Val, slotAddress, InsertBefore); + new StoreInst(Val, slotAddress, InsertBefore->getIterator()); } void LateLowerGCFrame::PlaceGCFrameReset(State &S, unsigned R, unsigned MinColorRoot, @@ -2451,7 +2455,7 @@ void LateLowerGCFrame::PlaceRootsAndUpdateCalls(ArrayRef Colors, int PreAss assert(Elem->getType() == T_prjlvalue); //auto Idxs = ArrayRef(Tracked[i]); //Value *Elem = ExtractScalar(Base, true, Idxs, SI); - Value *shadowStore = new StoreInst(Elem, slotAddress, SI); + Value *shadowStore = new StoreInst(Elem, slotAddress, SI->getIterator()); (void)shadowStore; // TODO: shadowStore->setMetadata(LLVMContext::MD_tbaa, tbaa_gcframe); AllocaSlot++; diff --git a/src/llvm-multiversioning.cpp b/src/llvm-multiversioning.cpp index a76d076ebd6f3..2961a77e08390 100644 --- a/src/llvm-multiversioning.cpp +++ b/src/llvm-multiversioning.cpp @@ -767,7 +767,7 @@ std::pair CloneCtx::get_reloc_slot(Function *F) const } template -static Value *rewrite_inst_use(const Stack& stack, Type *T_size, Value *replace, Instruction *insert_before) +static Value *rewrite_inst_use(const Stack& stack, Type *T_size, Value *replace, InsertPosition& insert_before) { SmallVector args; uint32_t nlevel = stack.size(); @@ -828,9 +828,9 @@ static void replaceUsesWithLoad(Function &F, Type *T_size, I2GV should_replace, GlobalVariable *slot = should_replace(*use_i); if (!slot) continue; - Instruction *insert_before = use_i; + InsertPosition insert_before = use_i->getIterator(); if (auto phi = dyn_cast(use_i)) - insert_before = phi->getIncomingBlock(*info.use)->getTerminator(); + insert_before = phi->getIncomingBlock(*info.use)->getTerminator()->getIterator(); Instruction *ptr = new LoadInst(F.getType(), slot, "", false, insert_before); ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(ptr->getContext(), None)); diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index 15f5a5574a6d3..58fdd8aafa383 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -190,7 +190,7 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, phi->addIncoming(pgcstack, fastTerm->getParent()); // emit pre-return cleanup if (CountTrackedPointers(pgcstack->getParent()->getParent()->getReturnType()).count == 0) { - auto last_gc_state = PHINode::Create(Type::getInt8Ty(pgcstack->getContext()), 2, "", phi); + auto last_gc_state = PHINode::Create(Type::getInt8Ty(pgcstack->getContext()), 2, "", phi->getIterator()); // if we called jl_adopt_thread, we must end this cfunction back in the safe-state last_gc_state->addIncoming(ConstantInt::get(Type::getInt8Ty(M->getContext()), JL_GC_STATE_SAFE), slowTerm->getParent()); last_gc_state->addIncoming(prior, fastTerm->getParent()); @@ -282,7 +282,7 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, if (TargetTriple.isOSDarwin()) { assert(sizeof(k) == sizeof(uintptr_t)); Constant *key = ConstantInt::get(T_size, (uintptr_t)k); - auto new_pgcstack = CallInst::Create(FT_pgcstack_getter, val, {key}, "", pgcstack); + auto new_pgcstack = CallInst::Create(FT_pgcstack_getter, val, {key}, "", pgcstack->getIterator()); new_pgcstack->takeName(pgcstack); pgcstack->replaceAllUsesWith(new_pgcstack); pgcstack->eraseFromParent(); From 82edf1c41e41ff32f99974c3883c6a980379d711 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:26:04 +0000 Subject: [PATCH 04/16] Adapt to "[NFC] Move intrinsic related functions to Intrinsic namespace (#110125)" https://github.com/llvm/llvm-project/commit/1b7b3b8d354a28f5fb1381c61c5663819d29a974 --- src/ccall.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ccall.cpp b/src/ccall.cpp index c35979eb85b1d..025958c9d36e0 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -2099,7 +2099,11 @@ jl_cgval_t function_sig_t::emit_a_ccall( } else if (f_name.starts_with("llvm.")) { // compute and verify auto-mangling for intrinsic name +#if JL_LLVM_VERSION >= 200000 + auto ID = Intrinsic::lookupIntrinsicID(f_name); +#else auto ID = Function::lookupIntrinsicID(f_name); +#endif if (ID != Intrinsic::not_intrinsic) { // Accumulate an array of overloaded types for the given intrinsic // and compute the new name mangling schema From 8fd770162eaa97c60736c69d20d8b15ed9e6c4ef Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:47:08 +0000 Subject: [PATCH 05/16] Adapt to "[NFC] Rename Intrinsic::getDeclaration to getOrInsertDeclaration (#111752)" https://github.com/llvm/llvm-project/commit/fa789dffb1e12c2aece0187aeacc48dfb1768340 --- src/ccall.cpp | 4 ++ src/cgutils.cpp | 28 ++++++++++++ src/codegen.cpp | 20 +++++++++ src/intrinsics.cpp | 72 +++++++++++++++++++++++++++++++ src/llvm-alloc-opt.cpp | 12 ++++++ src/llvm-propagate-addrspaces.cpp | 8 ++++ 6 files changed, 144 insertions(+) diff --git a/src/ccall.cpp b/src/ccall.cpp index 025958c9d36e0..dca58f2feef82 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -2115,7 +2115,11 @@ jl_cgval_t function_sig_t::emit_a_ccall( if (res == Intrinsic::MatchIntrinsicTypes_Match) { bool matchvararg = !Intrinsic::matchIntrinsicVarArg(functype->isVarArg(), TableRef); if (matchvararg) { +#if JL_LLVM_VERSION >= 200000 + Function *intrinsic = Intrinsic::getOrInsertDeclaration(jl_Module, ID, overloadTys); +#else Function *intrinsic = Intrinsic::getDeclaration(jl_Module, ID, overloadTys); +#endif assert(intrinsic->getFunctionType() == functype); if (intrinsic->getName() == f_name || Intrinsic::getBaseName(ID) == f_name) llvmf = intrinsic; diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 39879503596fe..470bce56d7829 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -3672,7 +3672,11 @@ static Value *box_union(jl_codectx_t &ctx, const jl_cgval_t &vinfo, const SmallB ctx.builder.CreateBr(postBB); } else if (!vinfo.Vboxed) { +#if JL_LLVM_VERSION >= 200000 + Function *trap_func = Intrinsic::getOrInsertDeclaration( +#else Function *trap_func = Intrinsic::getDeclaration( +#endif ctx.f->getParent(), Intrinsic::trap); ctx.builder.CreateCall(trap_func); @@ -3716,7 +3720,11 @@ static Function *mangleIntrinsic(IntrinsicInst *call) //mangling based on replac assert(matchvararg); (void)matchvararg; } +#if JL_LLVM_VERSION >= 200000 + auto newF = Intrinsic::getOrInsertDeclaration(call->getModule(), ID, overloadTys); +#else auto newF = Intrinsic::getDeclaration(call->getModule(), ID, overloadTys); +#endif assert(newF->getFunctionType() == newfType); newF->setCallingConv(call->getCallingConv()); return newF; @@ -3852,7 +3860,11 @@ static void emit_unionmove(jl_codectx_t &ctx, Value *dest, MDNode *tbaa_dst, con if (nb > 0) { if (!src_ptr) { Function *trap_func = +#if JL_LLVM_VERSION >= 200000 + Intrinsic::getOrInsertDeclaration(ctx.f->getParent(), Intrinsic::trap); +#else Intrinsic::getDeclaration(ctx.f->getParent(), Intrinsic::trap); +#endif ctx.builder.CreateCall(trap_func); ctx.builder.CreateUnreachable(); return; @@ -3867,7 +3879,11 @@ static void emit_unionmove(jl_codectx_t &ctx, Value *dest, MDNode *tbaa_dst, con counter); ctx.builder.SetInsertPoint(defaultBB); if (!skip && allunboxed && (src.V == NULL || isa(src.V))) { +#if JL_LLVM_VERSION >= 200000 + Function *trap_func = Intrinsic::getOrInsertDeclaration( +#else Function *trap_func = Intrinsic::getDeclaration( +#endif ctx.f->getParent(), Intrinsic::trap); ctx.builder.CreateCall(trap_func); @@ -4559,14 +4575,22 @@ static jl_cgval_t emit_memorynew(jl_codectx_t &ctx, jl_datatype_t *typ, jl_cgval auto cg_typ = literal_pointer_val(ctx, (jl_value_t*) typ); auto cg_elsz = ConstantInt::get(T_size, elsz); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee intr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::smul_with_overflow, ArrayRef(T_size)); +#else FunctionCallee intr = Intrinsic::getDeclaration(jl_Module, Intrinsic::smul_with_overflow, ArrayRef(T_size)); +#endif // compute nbytes with possible overflow Value *prod_with_overflow = ctx.builder.CreateCall(intr, {nel_unboxed, cg_elsz}); Value *nbytes = ctx.builder.CreateExtractValue(prod_with_overflow, 0); Value *overflow = ctx.builder.CreateExtractValue(prod_with_overflow, 1); if (isunion) { // if isunion, we need to allocate the union selector bytes as well +#if JL_LLVM_VERSION >= 200000 + intr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::sadd_with_overflow, ArrayRef(T_size)); +#else intr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sadd_with_overflow, ArrayRef(T_size)); +#endif Value *add_with_overflow = ctx.builder.CreateCall(intr, {nel_unboxed, nbytes}); nbytes = ctx.builder.CreateExtractValue(add_with_overflow, 0); Value *overflow1 = ctx.builder.CreateExtractValue(add_with_overflow, 1); @@ -4694,7 +4718,11 @@ static jl_cgval_t emit_memoryref(jl_codectx_t &ctx, const jl_cgval_t &ref, jl_cg Value *boffset; #if 0 if (bc) { +#if JL_LLVM_VERSION >= 200000 + auto *MulF = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::smul_with_overflow, offset->getType()); +#else auto *MulF = Intrinsic::getDeclaration(jl_Module, Intrinsic::smul_with_overflow, offset->getType()); +#endif CallInst *Mul = ctx.builder.CreateCall(MulF, {offset, elsz}); boffset = ctx.builder.CreateExtractValue(Mul, 0); ovflw = ctx.builder.CreateExtractValue(Mul, 1); diff --git a/src/codegen.cpp b/src/codegen.cpp index 5cbca62a6f54b..b03eee755e498 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -2626,7 +2626,11 @@ static void alloc_def_flag(jl_codectx_t &ctx, jl_varinfo_t& vi) static void CreateTrap(IRBuilder<> &irbuilder, bool create_new_block) { Function *f = irbuilder.GetInsertBlock()->getParent(); +#if JL_LLVM_VERSION >= 200000 + Function *trap_func = Intrinsic::getOrInsertDeclaration( +#else Function *trap_func = Intrinsic::getDeclaration( +#endif f->getParent(), Intrinsic::trap); irbuilder.CreateCall(trap_func); @@ -2649,7 +2653,11 @@ static void CreateConditionalAbort(IRBuilder<> &irbuilder, Value *test) BasicBlock *postBB = BasicBlock::Create(irbuilder.getContext(), "post_abort", f); irbuilder.CreateCondBr(test, abortBB, postBB); irbuilder.SetInsertPoint(abortBB); +#if JL_LLVM_VERSION >= 200000 + Function *trap_func = Intrinsic::getOrInsertDeclaration( +#else Function *trap_func = Intrinsic::getDeclaration( +#endif f->getParent(), Intrinsic::trap); irbuilder.CreateCall(trap_func); @@ -3607,7 +3615,11 @@ static Value *emit_bitsunion_compare(jl_codectx_t &ctx, const jl_cgval_t &arg1, counter); assert(allunboxed); (void)allunboxed; ctx.builder.SetInsertPoint(defaultBB); +#if JL_LLVM_VERSION >= 200000 + Function *trap_func = Intrinsic::getOrInsertDeclaration( +#else Function *trap_func = Intrinsic::getDeclaration( +#endif ctx.f->getParent(), Intrinsic::trap); ctx.builder.CreateCall(trap_func); @@ -7938,8 +7950,16 @@ static Function *gen_cfun_wrapper( Function::arg_iterator AI = cw_make->arg_begin(); Argument *Tramp = &*AI; ++AI; Argument *NVal = &*AI; ++AI; +#if JL_LLVM_VERSION >= 200000 + Function *init_trampoline = Intrinsic::getOrInsertDeclaration(cw_make->getParent(), Intrinsic::init_trampoline); +#else Function *init_trampoline = Intrinsic::getDeclaration(cw_make->getParent(), Intrinsic::init_trampoline); +#endif +#if JL_LLVM_VERSION >= 200000 + Function *adjust_trampoline = Intrinsic::getOrInsertDeclaration(cw_make->getParent(), Intrinsic::adjust_trampoline); +#else Function *adjust_trampoline = Intrinsic::getDeclaration(cw_make->getParent(), Intrinsic::adjust_trampoline); +#endif cwbuilder.CreateCall(init_trampoline, { Tramp, cw, diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 4006397d08ea1..fa77203521e7d 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -1506,17 +1506,29 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRefgetType() == y->getType()); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee minintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::minimum, ArrayRef(t)); +#else FunctionCallee minintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::minimum, ArrayRef(t)); +#endif return ctx.builder.CreateCall(minintr, {x, y}); } case max_float: { assert(x->getType() == y->getType()); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee maxintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::maximum, ArrayRef(t)); +#else FunctionCallee maxintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::maximum, ArrayRef(t)); +#endif return ctx.builder.CreateCall(maxintr, {x, y}); } case min_float_fast: { assert(x->getType() == y->getType()); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee minintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::minimum, ArrayRef(t)); +#else FunctionCallee minintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::minimum, ArrayRef(t)); +#endif auto call = ctx.builder.CreateCall(minintr, {x, y}); auto fmf = call->getFastMathFlags(); fmf.setFast(); @@ -1525,7 +1537,11 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRefgetType() == y->getType()); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee maxintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::maximum, ArrayRef(t)); +#else FunctionCallee maxintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::maximum, ArrayRef(t)); +#endif auto call = ctx.builder.CreateCall(maxintr, {x, y}); auto fmf = call->getFastMathFlags(); fmf.setFast(); @@ -1539,7 +1555,11 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRefgetType() == x->getType()); assert(z->getType() == y->getType()); +#if JL_LLVM_VERSION >= 200000 + FunctionCallee fmaintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::fma, ArrayRef(t)); +#else FunctionCallee fmaintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fma, ArrayRef(t)); +#endif return ctx.builder.CreateCall(fmaintr, {x, y, z}); } case muladd_float: { @@ -1569,7 +1589,11 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRef= 200000 + FunctionCallee intr = Intrinsic::getOrInsertDeclaration(jl_Module, intr_id, ArrayRef(t)); +#else FunctionCallee intr = Intrinsic::getDeclaration(jl_Module, intr_id, ArrayRef(t)); +#endif Value *tupval = ctx.builder.CreateCall(intr, {x, y}); jl_value_t *params[2]; @@ -1680,30 +1704,54 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRef= 200000 + FunctionCallee bswapintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::bswap, ArrayRef(t)); //TODO: Move to deduction guides +#else FunctionCallee bswapintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::bswap, ArrayRef(t)); //TODO: Move to deduction guides +#endif return ctx.builder.CreateCall(bswapintr, x); // when we drop LLVM 15 } case ctpop_int: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee ctpopintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::ctpop, ArrayRef(t)); +#else FunctionCallee ctpopintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctpop, ArrayRef(t)); +#endif return ctx.builder.CreateCall(ctpopintr, x); } case ctlz_int: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee ctlz = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::ctlz, ArrayRef(t)); +#else FunctionCallee ctlz = Intrinsic::getDeclaration(jl_Module, Intrinsic::ctlz, ArrayRef(t)); +#endif y = ConstantInt::get(getInt1Ty(ctx.builder.getContext()), 0); return ctx.builder.CreateCall(ctlz, {x, y}); } case cttz_int: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee cttz = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::cttz, ArrayRef(t)); +#else FunctionCallee cttz = Intrinsic::getDeclaration(jl_Module, Intrinsic::cttz, ArrayRef(t)); +#endif y = ConstantInt::get(getInt1Ty(ctx.builder.getContext()), 0); return ctx.builder.CreateCall(cttz, {x, y}); } case abs_float: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee absintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::fabs, ArrayRef(t)); +#else FunctionCallee absintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::fabs, ArrayRef(t)); +#endif return ctx.builder.CreateCall(absintr, x); } case copysign_float: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee copyintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::copysign, ArrayRef(t)); +#else FunctionCallee copyintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::copysign, ArrayRef(t)); +#endif return ctx.builder.CreateCall(copyintr, {x, y}); } case flipsign_int: { @@ -1722,27 +1770,51 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, ArrayRef= 200000 + FunctionCallee ceilintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::ceil, ArrayRef(t)); +#else FunctionCallee ceilintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::ceil, ArrayRef(t)); +#endif return ctx.builder.CreateCall(ceilintr, x); } case floor_llvm: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee floorintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::floor, ArrayRef(t)); +#else FunctionCallee floorintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::floor, ArrayRef(t)); +#endif return ctx.builder.CreateCall(floorintr, x); } case trunc_llvm: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee truncintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::trunc, ArrayRef(t)); +#else FunctionCallee truncintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::trunc, ArrayRef(t)); +#endif return ctx.builder.CreateCall(truncintr, x); } case rint_llvm: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee rintintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::rint, ArrayRef(t)); +#else FunctionCallee rintintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::rint, ArrayRef(t)); +#endif return ctx.builder.CreateCall(rintintr, x); } case sqrt_llvm: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee sqrtintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::sqrt, ArrayRef(t)); +#else FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, ArrayRef(t)); +#endif return ctx.builder.CreateCall(sqrtintr, x); } case sqrt_llvm_fast: { +#if JL_LLVM_VERSION >= 200000 + FunctionCallee sqrtintr = Intrinsic::getOrInsertDeclaration(jl_Module, Intrinsic::sqrt, ArrayRef(t)); +#else FunctionCallee sqrtintr = Intrinsic::getDeclaration(jl_Module, Intrinsic::sqrt, ArrayRef(t)); +#endif return math_builder(ctx, true)().CreateCall(sqrtintr, x); } diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index 7928d6824fb7d..4c22a289a5367 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -627,7 +627,11 @@ void Optimizer::replaceIntrinsicUseWith(IntrinsicInst *call, Intrinsic::ID ID, assert(matchvararg); (void)matchvararg; } +#if JL_LLVM_VERSION >= 200000 + auto newF = Intrinsic::getOrInsertDeclaration(call->getModule(), ID, overloadTys); +#else auto newF = Intrinsic::getDeclaration(call->getModule(), ID, overloadTys); +#endif assert(newF->getFunctionType() == newfType); newF->setCallingConv(call->getCallingConv()); auto newCall = CallInst::Create(newF, args, "", call->getIterator()); @@ -1283,8 +1287,16 @@ bool AllocOpt::doInitialization(Module &M) DL = &M.getDataLayout(); +#if JL_LLVM_VERSION >= 200000 + lifetime_start = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::lifetime_start, { PointerType::get(M.getContext(), DL->getAllocaAddrSpace()) }); +#else lifetime_start = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_start, { PointerType::get(M.getContext(), DL->getAllocaAddrSpace()) }); +#endif +#if JL_LLVM_VERSION >= 200000 + lifetime_end = Intrinsic::getOrInsertDeclaration(&M, Intrinsic::lifetime_end, { PointerType::get(M.getContext(), DL->getAllocaAddrSpace()) }); +#else lifetime_end = Intrinsic::getDeclaration(&M, Intrinsic::lifetime_end, { PointerType::get(M.getContext(), DL->getAllocaAddrSpace()) }); +#endif return true; } diff --git a/src/llvm-propagate-addrspaces.cpp b/src/llvm-propagate-addrspaces.cpp index 06a52ad3dcb43..55c9e731e1525 100644 --- a/src/llvm-propagate-addrspaces.cpp +++ b/src/llvm-propagate-addrspaces.cpp @@ -244,7 +244,11 @@ void PropagateJuliaAddrspacesVisitor::visitMemSetInst(MemSetInst &MI) { Value *Replacement = LiftPointer(MI.getModule(), MI.getRawDest()); if (!Replacement) return; +#if JL_LLVM_VERSION >= 200000 + Function *TheFn = Intrinsic::getOrInsertDeclaration(MI.getModule(), Intrinsic::memset, +#else Function *TheFn = Intrinsic::getDeclaration(MI.getModule(), Intrinsic::memset, +#endif {Replacement->getType(), MI.getOperand(1)->getType()}); MI.setCalledFunction(TheFn); MI.setArgOperand(0, Replacement); @@ -269,7 +273,11 @@ void PropagateJuliaAddrspacesVisitor::visitMemTransferInst(MemTransferInst &MTI) } if (Dest == MTI.getRawDest() && Src == MTI.getRawSource()) return; +#if JL_LLVM_VERSION >= 200000 + Function *TheFn = Intrinsic::getOrInsertDeclaration(MTI.getModule(), MTI.getIntrinsicID(), +#else Function *TheFn = Intrinsic::getDeclaration(MTI.getModule(), MTI.getIntrinsicID(), +#endif {Dest->getType(), Src->getType(), MTI.getOperand(2)->getType()}); MTI.setCalledFunction(TheFn); From 599fdd6e65229a4cba84448de9d07c0ee7ab89b2 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:30:02 +0000 Subject: [PATCH 06/16] Adapt to "[PassBuilder] Add ThinOrFullLTOPhase to early simplication EP call backs (#114547)" https://github.com/llvm/llvm-project/commit/dc45ff1d2a01ff68326c6444dba683cf66d80651 --- src/pipeline.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/pipeline.cpp b/src/pipeline.cpp index d0456844e92c6..b938ec3c45522 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -238,7 +238,11 @@ namespace { std::enable_if_t(nullptr))::value, void> invokeEarlySimplificationCallbacks(ModulePassManager &MPM, PB_t *PB, OptimizationLevel O) JL_NOTSAFEPOINT { static_assert(std::is_same::value, "Expected PassBuilder as second argument!"); if (!PB) return; +#if JL_LLVM_VERSION >= 200000 + PB->invokePipelineEarlySimplificationEPCallbacks(MPM, O, ThinOrFullLTOPhase::None); +#else PB->invokePipelineEarlySimplificationEPCallbacks(MPM, O); +#endif } template std::enable_if_t(nullptr))::value, void> invokeCGSCCCallbacks(CGSCCPassManager &CGPM, PB_t *PB, OptimizationLevel O) JL_NOTSAFEPOINT { From 4a7d193e35bb507ff9d63d47daa7259c131e9001 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:31:31 +0000 Subject: [PATCH 07/16] Adapt to "[PassBuilder] Add ThinOrFullLTOPhase to optimizer pipeline (#114577)" https://github.com/llvm/llvm-project/commit/390300d9f41df6ad71f0f4196ef4885d4bd5dc48 --- src/pipeline.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/pipeline.cpp b/src/pipeline.cpp index b938ec3c45522..0843aa01e5696 100644 --- a/src/pipeline.cpp +++ b/src/pipeline.cpp @@ -254,7 +254,11 @@ namespace { std::enable_if_t(nullptr))::value, void> invokeOptimizerEarlyCallbacks(ModulePassManager &MPM, PB_t *PB, OptimizationLevel O) JL_NOTSAFEPOINT { static_assert(std::is_same::value, "Expected PassBuilder as second argument!"); if (!PB) return; +#if JL_LLVM_VERSION >= 200000 + PB->invokeOptimizerEarlyEPCallbacks(MPM, O, ThinOrFullLTOPhase::None); +#else PB->invokeOptimizerEarlyEPCallbacks(MPM, O); +#endif } template std::enable_if_t(nullptr))::value, void> invokeLateLoopOptimizationCallbacks(LoopPassManager &LPM, PB_t *PB, OptimizationLevel O) JL_NOTSAFEPOINT { @@ -284,7 +288,11 @@ namespace { std::enable_if_t(nullptr))::value, void> invokeOptimizerLastCallbacks(ModulePassManager &MPM, PB_t *PB, OptimizationLevel O) JL_NOTSAFEPOINT { static_assert(std::is_same::value, "Expected PassBuilder as second argument!"); if (!PB) return; +#if JL_LLVM_VERSION >= 200000 + PB->invokeOptimizerLastEPCallbacks(MPM, O, ThinOrFullLTOPhase::None); +#else PB->invokeOptimizerLastEPCallbacks(MPM, O); +#endif } // Fallbacks From e46fa359ab496bdc49caa968ecf6b00c318fdfc4 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:32:12 +0000 Subject: [PATCH 08/16] Adapt to "[llvm] Deprecate Type::getPointerTo() (#113331)" https://github.com/llvm/llvm-project/commit/29e467fc78eb8b4308b57272ca4ad0d1f744f25f --- src/aotcompile.cpp | 10 +++++----- src/ccall.cpp | 10 +++++----- src/cgutils.cpp | 4 ++-- src/codegen.cpp | 24 ++++++++++++------------ src/intrinsics.cpp | 6 +++--- src/llvm-codegen-shared.h | 14 +++++--------- src/llvm-final-gc-lowering.cpp | 2 +- src/llvm-late-gc-lowering.cpp | 4 ++-- src/llvm-multiversioning.cpp | 6 +++--- src/llvm-pass-helpers.cpp | 2 +- src/llvm-ptls.cpp | 2 +- 11 files changed, 40 insertions(+), 44 deletions(-) diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index d91da9c64cda9..d0adcb21362f4 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -1698,7 +1698,7 @@ static void construct_vars(Module &M, Partition &partition, StringRef suffix) { // Now commit the fvars, gvars, and idxs auto T_size = M.getDataLayout().getIntPtrType(M.getContext()); - emit_table(M, fvars, "jl_fvars", T_size->getPointerTo()); + emit_table(M, fvars, "jl_fvars", PointerType::getUnqual(T_size->getContext())); emit_offset_table(M, T_size, gvars, "jl_gvar", suffix); auto fidxs = ConstantDataArray::get(M.getContext(), fvar_idxs); auto fidxs_var = new GlobalVariable(M, fidxs->getType(), true, @@ -2077,7 +2077,7 @@ void jl_dump_native_impl(void *native_code, dataM.setPICLevel(PICLevel::BigPIC); auto &Context = dataM.getContext(); - Type *T_psize = dataM.getDataLayout().getIntPtrType(Context)->getPointerTo(); + Type *T_psize = PointerType::getUnqual(Context); // This should really be in jl_create_native, but we haven't // yet set the target triple binary format correctly at that @@ -2183,9 +2183,9 @@ void jl_dump_native_impl(void *native_code, GlobalValue *jlRTLD_DEFAULT_var = jl_emit_RTLD_DEFAULT_var(&metadataM); Type *T_size = DL.getIntPtrType(Context); - Type *T_psize = T_size->getPointerTo(); + Type *T_psize = PointerType::getUnqual(T_size->getContext()); - auto FT = FunctionType::get(Type::getInt8Ty(Context)->getPointerTo()->getPointerTo(), {}, false); + auto FT = FunctionType::get(PointerType::getUnqual(Context), {}, false); auto F = Function::Create(FT, Function::ExternalLinkage, "get_jl_RTLD_DEFAULT_handle_addr", metadataM); llvm::IRBuilder<> builder(BasicBlock::Create(Context, "top", F)); builder.CreateRet(jlRTLD_DEFAULT_var); @@ -2197,7 +2197,7 @@ void jl_dump_native_impl(void *native_code, // Windows expect that the function `_DllMainStartup` is present in an dll. // Normal compilers use something like Zig's crtdll.c instead we provide a // a stub implementation. - auto T_pvoid = Type::getInt8Ty(Context)->getPointerTo(); + auto T_pvoid = PointerType::getUnqual(Context); auto T_int32 = Type::getInt32Ty(Context); auto FT = FunctionType::get(T_int32, {T_pvoid, T_int32, T_pvoid}, false); auto F = Function::Create(FT, Function::ExternalLinkage, "_DllMainCRTStartup", metadataM); diff --git a/src/ccall.cpp b/src/ccall.cpp index dca58f2feef82..ff7f1b63f00d9 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -105,7 +105,7 @@ static bool runtime_sym_gvs(jl_codectx_t &ctx, const char *f_lib, const char *f_ name += f_name; name += "_"; name += std::to_string(jl_atomic_fetch_add_relaxed(&globalUniqueGeneratedNames, 1)); - auto T_pvoidfunc = JuliaType::get_pvoidfunc_ty(M->getContext()); + auto T_pvoidfunc = getPointerTy(M->getContext()); llvmgv = new GlobalVariable(*M, T_pvoidfunc, false, GlobalVariable::ExternalLinkage, Constant::getNullValue(T_pvoidfunc), name); @@ -133,7 +133,7 @@ static Value *runtime_sym_lookup( // *llvmgv = jl_load_and_lookup(f_lib, f_name, libptrgv); // } // return (*llvmgv) - auto T_pvoidfunc = JuliaType::get_pvoidfunc_ty(irbuilder.getContext()); + auto T_pvoidfunc = getPointerTy(irbuilder.getContext()); BasicBlock *enter_bb = irbuilder.GetInsertBlock(); BasicBlock *dlsym_lookup = BasicBlock::Create(irbuilder.getContext(), "dlsym"); BasicBlock *ccall_bb = BasicBlock::Create(irbuilder.getContext(), "ccall"); @@ -197,7 +197,7 @@ static Value *runtime_sym_lookup( PointerType *funcptype, const char *f_lib, jl_value_t *lib_expr, const char *f_name, Function *f) { - auto T_pvoidfunc = JuliaType::get_pvoidfunc_ty(ctx.builder.getContext()); + auto T_pvoidfunc = getPointerTy(ctx.builder.getContext()); GlobalVariable *libptrgv; GlobalVariable *llvmgv; bool runtime_lib; @@ -244,7 +244,7 @@ static GlobalVariable *emit_plt_thunk( plt->setAttributes(attrs); if (cc != CallingConv::C) plt->setCallingConv(cc); - auto T_pvoidfunc = JuliaType::get_pvoidfunc_ty(M->getContext()); + auto T_pvoidfunc = getPointerTy(M->getContext()); GlobalVariable *got = new GlobalVariable(*M, T_pvoidfunc, false, GlobalVariable::ExternalLinkage, plt, @@ -2140,7 +2140,7 @@ jl_cgval_t function_sig_t::emit_a_ccall( } else if (symarg.fptr != NULL) { ++LiteralCCalls; - Type *funcptype = functype->getPointerTo(0); + Type *funcptype = PointerType::getUnqual(functype->getContext()); llvmf = literal_static_pointer_val((void*)(uintptr_t)symarg.fptr, funcptype); setName(ctx.emission_context, llvmf, "ccall_fptr"); } diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 470bce56d7829..ff8095daa3dc6 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -123,7 +123,7 @@ static Value *stringConstPtr( // 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); // AddrSpaceCast in case globals are in non-0 AS - return irbuilder.CreateAddrSpaceCast(gv, gv->getValueType()->getPointerTo(0)); + return irbuilder.CreateAddrSpaceCast(gv, PointerType::getUnqual(gv->getContext())); } @@ -1336,7 +1336,7 @@ static Value *emit_typeof(jl_codectx_t &ctx, const jl_cgval_t &p, bool maybenull Value *tindex = ctx.builder.CreateAnd(p.TIndex, ConstantInt::get(getInt8Ty(ctx.builder.getContext()), 0x7f)); bool allunboxed = is_uniontype_allunboxed(p.typ); Type *expr_type = justtag ? ctx.types().T_size : ctx.types().T_pjlvalue; - Value *datatype_or_p = Constant::getNullValue(expr_type->getPointerTo()); + Value *datatype_or_p = Constant::getNullValue(PointerType::getUnqual(expr_type->getContext())); unsigned counter = 0; for_each_uniontype_small( [&](unsigned idx, jl_datatype_t *jt) { diff --git a/src/codegen.cpp b/src/codegen.cpp index b03eee755e498..627f6ce1aac28 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -824,7 +824,7 @@ static const auto jlhasnofield_func = new JuliaFunction<>{ static const auto jlboundserrorv_func = new JuliaFunction{ XSTR(jl_bounds_error_ints), [](LLVMContext &C, Type *T_size) { return FunctionType::get(getVoidTy(C), - {PointerType::get(JuliaType::get_jlvalue_ty(C), AddressSpace::CalleeRooted), T_size->getPointerTo(), T_size}, false); }, + {PointerType::get(JuliaType::get_jlvalue_ty(C), AddressSpace::CalleeRooted), PointerType::getUnqual(T_size->getContext()), T_size}, false); }, get_attrs_noreturn, }; static const auto jlboundserror_func = new JuliaFunction{ @@ -1292,13 +1292,13 @@ static const auto memcmp_func = new JuliaFunction{ }; static const auto jldlsym_func = new JuliaFunction<>{ XSTR(jl_load_and_lookup), - [](LLVMContext &C) { return FunctionType::get(JuliaType::get_pvoidfunc_ty(C), - {getPointerTy(C), getPointerTy(C), PointerType::get(getPointerTy(C), 0)}, false); }, + [](LLVMContext &C) { return FunctionType::get(getPointerTy(C), + {getPointerTy(C), getPointerTy(C), getPointerTy(C)}, false); }, nullptr, }; static const auto jllazydlsym_func = new JuliaFunction<>{ XSTR(jl_lazy_load_and_lookup), - [](LLVMContext &C) { return FunctionType::get(JuliaType::get_pvoidfunc_ty(C), + [](LLVMContext &C) { return FunctionType::get(getPointerTy(C), {JuliaType::get_prjlvalue_ty(C), getPointerTy(C)}, false); }, nullptr, }; @@ -1365,7 +1365,7 @@ static const auto jlgetcfunctiontrampoline_func = new JuliaFunction<>{ T_pjlvalue, // result getPointerTy(C), // cache T_pjlvalue, // fill - FunctionType::get(getPointerTy(C), { getPointerTy(C), T_ppjlvalue }, false)->getPointerTo(), // trampoline + getPointerTy(C), // trampoline T_pjlvalue, // env T_derived, // vals }, false); @@ -1444,7 +1444,7 @@ static const auto box_ssavalue_func = new JuliaFunction{ }; static const auto jlgetbuiltinfptr_func = new JuliaFunction<>{ XSTR(jl_get_builtin_fptr), - [](LLVMContext &C) { return FunctionType::get(get_func_sig(C)->getPointerTo(), + [](LLVMContext &C) { return FunctionType::get(getPointerTy(C), {JuliaType::get_prjlvalue_ty(C)}, false); }, nullptr, }; @@ -1524,7 +1524,7 @@ static const auto julia_call = new JuliaFunction<>{ [](LLVMContext &C) { auto T_prjlvalue = JuliaType::get_prjlvalue_ty(C); return FunctionType::get(T_prjlvalue, - {get_func_sig(C)->getPointerTo(), + {getPointerTy(C), T_prjlvalue}, // %f true); }, // %args get_attrs_basic, @@ -1537,7 +1537,7 @@ static const auto julia_call2 = new JuliaFunction<>{ [](LLVMContext &C) { auto T_prjlvalue = JuliaType::get_prjlvalue_ty(C); return FunctionType::get(T_prjlvalue, - {get_func2_sig(C)->getPointerTo(), + {getPointerTy(C), T_prjlvalue, // %arg1 T_prjlvalue}, // %f true); }, // %args @@ -1551,7 +1551,7 @@ static const auto julia_call3 = new JuliaFunction<>{ auto T_prjlvalue = JuliaType::get_prjlvalue_ty(C); Type *T = PointerType::get(JuliaType::get_jlvalue_ty(C), AddressSpace::Derived); return FunctionType::get(T_prjlvalue, - {get_func3_sig(C)->getPointerTo(), + {getPointerTy(C), T}, // %f true); }, // %args get_attrs_basic, @@ -5528,7 +5528,7 @@ static jl_cgval_t emit_call_specfun_boxed(jl_codectx_t &ctx, jl_value_t *jlretty std::string namep("p"); namep += specFunctionObject; GlobalVariable *GV = cast_or_null(jl_Module->getNamedValue(namep)); - Type *pfunc = ctx.types().T_jlfunc->getPointerTo(); + Type *pfunc = PointerType::getUnqual(ctx.builder.getContext()); if (GV == nullptr) { GV = new GlobalVariable(*jl_Module, pfunc, false, GlobalVariable::ExternalLinkage, @@ -8310,7 +8310,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t ¶ms, Module if (props.union_bytes) { props.cc = jl_returninfo_t::Union; Type *AT = ArrayType::get(getInt8Ty(M->getContext()), props.union_bytes); - fsig.push_back(AT->getPointerTo()); + fsig.push_back(PointerType::getUnqual(M->getContext())); argnames.push_back("union_bytes_return"); Type *pair[] = { T_prjlvalue, getInt8Ty(M->getContext()) }; rt = StructType::get(M->getContext(), ArrayRef(pair)); @@ -8339,7 +8339,7 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t ¶ms, Module props.union_align = props.union_minalign = julia_alignment(jlrettype); // sret is always passed from alloca assert(M); - fsig.push_back(rt->getPointerTo(M->getDataLayout().getAllocaAddrSpace())); + fsig.push_back(PointerType::get(M->getContext(), M->getDataLayout().getAllocaAddrSpace())); argnames.push_back("sret_return"); srt = rt; rt = getVoidTy(M->getContext()); diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index fa77203521e7d..6993196b49016 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -790,7 +790,7 @@ static jl_cgval_t emit_pointerref(jl_codectx_t &ctx, ArrayRef argv) Type *ptrty = julia_type_to_llvm(ctx, ety, &isboxed); assert(!isboxed); if (!type_is_ghost(ptrty)) { - Value *thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); + Value *thePtr = emit_unbox(ctx, PointerType::getUnqual(ptrty->getContext()), e, e.typ); thePtr = ctx.builder.CreateInBoundsGEP(ptrty, thePtr, im1); auto load = typed_load(ctx, thePtr, nullptr, ety, ctx.tbaa().tbaa_data, nullptr, isboxed, AtomicOrdering::NotAtomic, false, align_nb); setName(ctx.emission_context, load.V, "pointerref"); @@ -982,7 +982,7 @@ static jl_cgval_t emit_atomic_pointerref(jl_codectx_t &ctx, ArrayRef Type *ptrty = julia_type_to_llvm(ctx, ety, &isboxed); assert(!isboxed); if (!type_is_ghost(ptrty)) { - Value *thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); + Value *thePtr = emit_unbox(ctx, PointerType::getUnqual(ptrty->getContext()), e, e.typ); auto load = typed_load(ctx, thePtr, nullptr, ety, ctx.tbaa().tbaa_data, nullptr, isboxed, llvm_order, false, nb); setName(ctx.emission_context, load.V, "atomic_pointerref"); return load; @@ -1076,7 +1076,7 @@ static jl_cgval_t emit_atomic_pointerop(jl_codectx_t &ctx, intrinsic f, ArrayRef assert(!isboxed); Value *thePtr; if (!type_is_ghost(ptrty)) - thePtr = emit_unbox(ctx, ptrty->getPointerTo(), e, e.typ); + thePtr = emit_unbox(ctx, PointerType::getUnqual(ptrty->getContext()), e, e.typ); else thePtr = nullptr; // could use any value here, since typed_store will not use it jl_cgval_t ret = typed_store(ctx, thePtr, x, y, ety, ctx.tbaa().tbaa_data, nullptr, nullptr, isboxed, diff --git a/src/llvm-codegen-shared.h b/src/llvm-codegen-shared.h index d474fb4f61183..cfdb8eb5b1a99 100644 --- a/src/llvm-codegen-shared.h +++ b/src/llvm-codegen-shared.h @@ -34,19 +34,19 @@ namespace JuliaType { } static inline llvm::PointerType* get_pjlvalue_ty(llvm::LLVMContext &C, unsigned addressSpace=0) { - return llvm::PointerType::get(get_jlvalue_ty(C), addressSpace); + return llvm::PointerType::get(C, addressSpace); } static inline llvm::PointerType* get_prjlvalue_ty(llvm::LLVMContext &C) { - return llvm::PointerType::get(get_jlvalue_ty(C), AddressSpace::Tracked); + return llvm::PointerType::get(C, AddressSpace::Tracked); } static inline llvm::PointerType* get_ppjlvalue_ty(llvm::LLVMContext &C) { - return llvm::PointerType::get(get_pjlvalue_ty(C), 0); + return llvm::PointerType::get(C, 0); } static inline llvm::PointerType* get_pprjlvalue_ty(llvm::LLVMContext &C) { - return llvm::PointerType::get(get_prjlvalue_ty(C), 0); + return llvm::PointerType::get(C, 0); } static inline auto get_jlfunc_ty(llvm::LLVMContext &C) { @@ -95,10 +95,6 @@ namespace JuliaType { static inline auto get_voidfunc_ty(llvm::LLVMContext &C) { return llvm::FunctionType::get(llvm::Type::getVoidTy(C), /*isVarArg*/false); } - - static inline auto get_pvoidfunc_ty(llvm::LLVMContext &C) { - return get_voidfunc_ty(C)->getPointerTo(); - } } // return how many Tracked pointers are in T (count > 0), @@ -228,7 +224,7 @@ static inline void emit_gc_safepoint(llvm::IRBuilder<> &builder, llvm::Type *T_s else { Function *F = M->getFunction("julia.safepoint"); if (!F) { - FunctionType *FT = FunctionType::get(Type::getVoidTy(C), {T_size->getPointerTo()}, false); + FunctionType *FT = FunctionType::get(Type::getVoidTy(C), {PointerType::getUnqual(T_size->getContext())}, false); F = Function::Create(FT, Function::ExternalLinkage, "julia.safepoint", M); F->setMemoryEffects(MemoryEffects::inaccessibleOrArgMemOnly()); } diff --git a/src/llvm-final-gc-lowering.cpp b/src/llvm-final-gc-lowering.cpp index 76dcd944890ab..4e539fea8f25f 100644 --- a/src/llvm-final-gc-lowering.cpp +++ b/src/llvm-final-gc-lowering.cpp @@ -22,7 +22,7 @@ void FinalLowerGC::lowerNewGCFrame(CallInst *target, Function &F) auto gcframe_alloca = builder.CreateAlloca(T_prjlvalue, ConstantInt::get(Type::getInt32Ty(F.getContext()), nRoots + 2)); gcframe_alloca->setAlignment(Align(16)); // addrspacecast as needed for non-0 alloca addrspace - auto gcframe = cast(builder.CreateAddrSpaceCast(gcframe_alloca, T_prjlvalue->getPointerTo(0))); + auto gcframe = cast(builder.CreateAddrSpaceCast(gcframe_alloca, PointerType::getUnqual(T_prjlvalue->getContext()))); gcframe->takeName(target); // Zero out the GC frame. diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index c39a46b9276d1..60054b994d39a 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -1968,7 +1968,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { AllocaInst *Frame = nullptr; unsigned allocaAddressSpace = F.getParent()->getDataLayout().getAllocaAddrSpace(); if (T_prjlvalue) { - T_pprjlvalue = T_prjlvalue->getPointerTo(); + T_pprjlvalue = PointerType::getUnqual(T_prjlvalue->getContext()); Frame = new AllocaInst(T_prjlvalue, allocaAddressSpace, ConstantInt::get(T_int32, maxframeargs), "jlcallframe", StartOff->getIterator()); } @@ -2159,7 +2159,7 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { } ReplacementArgs.push_back(nframeargs == 0 ? (llvm::Value*)ConstantPointerNull::get(T_pprjlvalue) : - Builder.CreateAddrSpaceCast(Frame, T_prjlvalue->getPointerTo(0))); + Builder.CreateAddrSpaceCast(Frame, PointerType::getUnqual(T_prjlvalue->getContext()))); ReplacementArgs.push_back(ConstantInt::get(T_int32, nframeargs)); if (callee == call2_func) { // move trailing arg to the end now diff --git a/src/llvm-multiversioning.cpp b/src/llvm-multiversioning.cpp index 2961a77e08390..61058f7af08cd 100644 --- a/src/llvm-multiversioning.cpp +++ b/src/llvm-multiversioning.cpp @@ -884,11 +884,11 @@ static void emit_table(Module &M, Type *T_size, ArrayRef vars, String uint32_t nvars = vars.size(); SmallVector castvars(nvars); for (size_t i = 0; i < nvars; i++) - castvars[i] = ConstantExpr::getBitCast(vars[i], T_size->getPointerTo()); + castvars[i] = ConstantExpr::getBitCast(vars[i], PointerType::getUnqual(T_size->getContext())); auto gv = new GlobalVariable(M, T_size, true, GlobalValue::ExternalLinkage, ConstantInt::get(T_size, nvars), name + "_count" + suffix); gv->setVisibility(GlobalValue::HiddenVisibility); gv->setDSOLocal(true); - ArrayType *vars_type = ArrayType::get(T_size->getPointerTo(), nvars); + ArrayType *vars_type = ArrayType::get(PointerType::getUnqual(T_size->getContext()), nvars); gv = new GlobalVariable(M, vars_type, false, GlobalVariable::ExternalLinkage, ConstantArray::get(vars_type, castvars), @@ -962,7 +962,7 @@ void CloneCtx::emit_metadata() { SmallVector idxs; SmallVector fptrs; - Type *Tfptr = T_size->getPointerTo(); + Type *Tfptr = PointerType::getUnqual(T_size->getContext()); for (uint32_t i = 0; i < ntargets; i++) { auto tgt = linearized[i]; auto &spec = specs[i]; diff --git a/src/llvm-pass-helpers.cpp b/src/llvm-pass-helpers.cpp index 9d415d923ecb6..214e99a03d9f2 100644 --- a/src/llvm-pass-helpers.cpp +++ b/src/llvm-pass-helpers.cpp @@ -255,7 +255,7 @@ namespace jl_intrinsics { SAFEPOINT_NAME, [](Type *T_size) { auto &ctx = T_size->getContext(); - auto T_psize = T_size->getPointerTo(); + auto T_psize = PointerType::getUnqual(ctx); auto intrinsic = Function::Create( FunctionType::get( Type::getVoidTy(ctx), diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index 58fdd8aafa383..1bc05c4ce0af8 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -312,7 +312,7 @@ bool LowerPTLS::run(bool *CFGModified) assert(sizeof(jl_pgcstack_key_t) == sizeof(uintptr_t)); FT_pgcstack_getter = FunctionType::get(FT_pgcstack_getter->getReturnType(), {T_size}, false); } - T_pgcstack_getter = FT_pgcstack_getter->getPointerTo(); + T_pgcstack_getter = PointerType::getUnqual(FT_pgcstack_getter->getContext()); T_pppjlvalue = cast(FT_pgcstack_getter->getReturnType()); if (imaging_mode) { pgcstack_func_slot = create_hidden_global(T_pgcstack_getter, "jl_pgcstack_func_slot"); From b7c9384f00e243838affd7ed310a3d608504a806 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:32:39 +0000 Subject: [PATCH 09/16] Adapt to "[ORC] Move absoluteSymbols from Core.h to new AbsoluteSymbols.h header. NFC." https://github.com/llvm/llvm-project/commit/dc11c0601577afb8f67513d041ee25dabe3555b9 --- src/jitlayers.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 5671027faca34..74b5975582eeb 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -14,6 +14,7 @@ #include #include #include +#include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h" #if JL_LLVM_VERSION >= 180000 #include #include From d70f5be56e47ec382446b685587c9e238b648814 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 21:34:36 +0000 Subject: [PATCH 10/16] Rename `LLVMTargetMachine` to `CodeGenCommonTMImpl` Adapt to https://github.com/llvm/llvm-project/commit/bb3f5e1fed7c6ba733b7f273e93f5d3930976185 --- src/disasm.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/disasm.cpp b/src/disasm.cpp index 6a7985bd7ec1b..3e87e253bf983 100644 --- a/src/disasm.cpp +++ b/src/disasm.cpp @@ -99,6 +99,9 @@ // for outputting assembly #include #include +#if JL_LLVM_VERSION >= 200000 +#include +#endif #include #include #include @@ -1135,7 +1138,11 @@ static void jl_dump_asm_internal( /// addPassesToX helper drives creation and initialization of TargetPassConfig. static MCContext * +#if JL_LLVM_VERSION >= 200000 +addPassesToGenerateCode(CodeGenTargetMachineImpl *TM, PassManagerBase &PM) { +#else addPassesToGenerateCode(LLVMTargetMachine *TM, PassManagerBase &PM) { +#endif TargetPassConfig *PassConfig = TM->createPassConfig(PM); PassConfig->setDisableVerify(false); PM.add(PassConfig); @@ -1236,7 +1243,11 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const f->addFnAttr(Attribute::NoUnwind); }); auto TMBase = jl_ExecutionEngine->cloneTargetMachine(); +#if JL_LLVM_VERSION >= 200000 + CodeGenTargetMachineImpl *TM = static_cast(TMBase.get()); +#else LLVMTargetMachine *TM = static_cast(TMBase.get()); +#endif legacy::PassManager PM; addTargetPasses(&PM, TM->getTargetTriple(), TM->getTargetIRAnalysis()); if (emit_mc) { @@ -1254,7 +1265,7 @@ jl_value_t *jl_dump_function_asm_impl(jl_llvmf_dump_t* dump, char emit_mc, const if (!Context) return jl_an_empty_string; Context->setGenDwarfForAssembly(false); - // Duplicate LLVMTargetMachine::addAsmPrinter here so we can set the asm dialect and add the custom annotation printer + // Duplicate CodeGenTargetMachineImpl::addAsmPrinter here so we can set the asm dialect and add the custom annotation printer const MCSubtargetInfo &STI = *TM->getMCSubtargetInfo(); const MCAsmInfo &MAI = *TM->getMCAsmInfo(); const MCRegisterInfo &MRI = *TM->getMCRegisterInfo(); From 532e1cdb1cd4301273590da76752ee3f577e482b Mon Sep 17 00:00:00 2001 From: Zentrik Date: Mon, 10 Feb 2025 22:01:43 +0000 Subject: [PATCH 11/16] Adapt to "[PowerPC] Update data layout aligment of i128 to 16 (#118004)" https://github.com/llvm/llvm-project/commit/a13ec9cd54deba3a6779ce1114503cf86a3f8658 --- src/julia_internal.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/julia_internal.h b/src/julia_internal.h index dff1d90aecd2d..231804e785ed8 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -105,8 +105,8 @@ JL_DLLIMPORT void __tsan_switch_to_fiber(void *fiber, unsigned flags); #ifndef _OS_WINDOWS_ #if defined(_CPU_ARM_) || defined(_CPU_PPC_) || defined(_CPU_WASM_) #define MAX_ALIGN 8 - #elif defined(_CPU_AARCH64_) || defined(_CPU_RISCV64_) || (JL_LLVM_VERSION >= 180000 && (defined(_CPU_X86_64_) || defined(_CPU_X86_))) - // int128 is 16 bytes aligned on aarch64 and riscv, and on x86 with LLVM >= 18 + #elif defined(_CPU_AARCH64_) || defined(_CPU_RISCV64_) || (JL_LLVM_VERSION >= 180000 && (defined(_CPU_X86_64_) || defined(_CPU_X86_)) || (JL_LLVM_VERSION >= 200000 && defined(_CPU_PPC64_))) + // int128 is 16 bytes aligned on aarch64 and riscv, and on x86 with LLVM >= 18 and on ppc64 with LLVM >= 20 #define MAX_ALIGN 16 #elif defined(_P64) // Generically we assume MAX_ALIGN is sizeof(void*) From 8b56b2ee844b476f20eb0b45abc9334a7fc0ef6c Mon Sep 17 00:00:00 2001 From: Zentrik Date: Tue, 11 Feb 2025 21:38:32 +0000 Subject: [PATCH 12/16] fixup! Adapt to "[ORC] Move absoluteSymbols from Core.h to new AbsoluteSymbols.h header. NFC." --- src/jitlayers.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index 74b5975582eeb..7d95c8b2db2a6 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -14,7 +14,9 @@ #include #include #include +#if JL_LLVM_VERSION >= 200000 #include "llvm/ExecutionEngine/Orc/AbsoluteSymbols.h" +#endif #if JL_LLVM_VERSION >= 180000 #include #include From 12b40d368a3cd64794fcef2a824b28b4046c3479 Mon Sep 17 00:00:00 2001 From: Zentrik Date: Tue, 11 Feb 2025 21:42:21 +0000 Subject: [PATCH 13/16] fixup! Adapt to "[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)" --- src/codegen.cpp | 10 +++++++--- src/llvm-alloc-opt.cpp | 20 +++++++++++++++++++ src/llvm-julia-licm.cpp | 4 ++++ src/llvm-late-gc-lowering.cpp | 37 +++++++++++++++++++++++++++++++++-- src/llvm-multiversioning.cpp | 12 ++++++++++++ src/llvm-ptls.cpp | 8 ++++++++ 6 files changed, 86 insertions(+), 5 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 627f6ce1aac28..54db41552966d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -1357,7 +1357,6 @@ static const auto jlgetcfunctiontrampoline_func = new JuliaFunction<>{ [](LLVMContext &C) { auto T_pjlvalue = PointerType::get(C, 0); auto T_prjlvalue = PointerType::get(C, AddressSpace::Tracked); - auto T_ppjlvalue = PointerType::get(C, 0); auto T_derived = PointerType::get(C, AddressSpace::Derived); return FunctionType::get(T_prjlvalue, { @@ -2352,7 +2351,13 @@ static GlobalVariable *get_pointer_to_constant(jl_codegen_params_t &emission_con static AllocaInst *emit_static_alloca(jl_codectx_t &ctx, Type *lty, Align align) { ++EmittedAllocas; - return new AllocaInst(lty, ctx.topalloca->getModule()->getDataLayout().getAllocaAddrSpace(), nullptr, align, "", /*InsertBefore=*/ctx.topalloca->getIterator()); + return new AllocaInst(lty, ctx.topalloca->getModule()->getDataLayout().getAllocaAddrSpace(), nullptr, align, "", +#if JL_LLVM_VERSION >= 200000 + /*InsertBefore=*/ctx.topalloca->getIterator() +#else + /*InsertBefore=*/ctx.topalloca +#endif + ); } static AllocaInst *emit_static_alloca(jl_codectx_t &ctx, unsigned nb, Align align) @@ -8309,7 +8314,6 @@ static jl_returninfo_t get_specsig_function(jl_codegen_params_t ¶ms, Module union_alloca_type((jl_uniontype_t*)jlrettype, allunbox, props.union_bytes, props.union_align, props.union_minalign); if (props.union_bytes) { props.cc = jl_returninfo_t::Union; - Type *AT = ArrayType::get(getInt8Ty(M->getContext()), props.union_bytes); fsig.push_back(PointerType::getUnqual(M->getContext())); argnames.push_back("union_bytes_return"); Type *pair[] = { T_prjlvalue, getInt8Ty(M->getContext()) }; diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index 4c22a289a5367..cd6ee5fe5efea 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -427,12 +427,20 @@ void Optimizer::insertLifetimeEnd(Value *ptr, Constant *sz, Instruction *insert) } break; } +#if JL_LLVM_VERSION >= 200000 CallInst::Create(pass.lifetime_end, {sz, ptr}, "", insert->getIterator()); +#else + CallInst::Create(pass.lifetime_end, {sz, ptr}, "", insert); +#endif } void Optimizer::insertLifetime(Value *ptr, Constant *sz, Instruction *orig) { +#if JL_LLVM_VERSION >= 200000 CallInst::Create(pass.lifetime_start, {sz, ptr}, "", orig->getIterator()); +#else + CallInst::Create(pass.lifetime_start, {sz, ptr}, "", orig); +#endif BasicBlock *def_bb = orig->getParent(); std::set bbs{def_bb}; auto &DT = getDomTree(); @@ -634,7 +642,11 @@ void Optimizer::replaceIntrinsicUseWith(IntrinsicInst *call, Intrinsic::ID ID, #endif assert(newF->getFunctionType() == newfType); newF->setCallingConv(call->getCallingConv()); +#if JL_LLVM_VERSION >= 200000 auto newCall = CallInst::Create(newF, args, "", call->getIterator()); +#else + auto newCall = CallInst::Create(newF, args, "", call); +#endif newCall->setTailCallKind(call->getTailCallKind()); auto old_attrs = call->getAttributes(); newCall->setAttributes(AttributeList::get(pass.getLLVMContext(), getFnAttrs(old_attrs), @@ -799,7 +811,11 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref, AllocF SmallVector IdxOperands(gep->idx_begin(), gep->idx_end()); auto new_gep = GetElementPtrInst::Create(gep->getSourceElementType(), new_i, IdxOperands, +#if JL_LLVM_VERSION >= 200000 gep->getName(), gep->getIterator()); +#else + gep->getName(), gep); +#endif new_gep->setIsInBounds(gep->isInBounds()); new_gep->takeName(gep); new_gep->copyMetadata(*gep); @@ -1242,7 +1258,11 @@ void Optimizer::splitOnStack(CallInst *orig_inst) bundle = OperandBundleDef("jl_roots", std::move(operands)); break; } +#if JL_LLVM_VERSION >= 200000 auto new_call = CallInst::Create(call, bundles, call->getIterator()); +#else + auto new_call = CallInst::Create(call, bundles, call); +#endif new_call->takeName(call); call->replaceAllUsesWith(new_call); call->eraseFromParent(); diff --git a/src/llvm-julia-licm.cpp b/src/llvm-julia-licm.cpp index e09f5cad92102..f971eb0623594 100644 --- a/src/llvm-julia-licm.cpp +++ b/src/llvm-julia-licm.cpp @@ -238,7 +238,11 @@ struct JuliaLICM : public JuliaPassContext { }); for (unsigned i = 1; i < exit_pts.size(); i++) { // Clone exit +#if JL_LLVM_VERSION >= 200000 auto CI = CallInst::Create(call, {}, exit_pts[i]->getIterator()); +#else + auto CI = CallInst::Create(call, {}, "", exit_pts[i]); +#endif exit_pts[i] = CI; createNewInstruction(CI, call, MSSAU); LLVM_DEBUG(dbgs() << "Cloned and sunk gc_preserve_end: " << *CI << "\n"); diff --git a/src/llvm-late-gc-lowering.cpp b/src/llvm-late-gc-lowering.cpp index 60054b994d39a..d378c107f27f7 100644 --- a/src/llvm-late-gc-lowering.cpp +++ b/src/llvm-late-gc-lowering.cpp @@ -348,10 +348,18 @@ void LateLowerGCFrame::LiftSelect(State &S, SelectInst *SI) { if (isa(Cond->getType())) { Cond = ExtractElementInst::Create(Cond, ConstantInt::get(Type::getInt32Ty(Cond->getContext()), i), +#if JL_LLVM_VERSION >= 200000 "", SI->getIterator()); +#else + "", SI); +#endif } assert(FalseElem->getType() == TrueElem->getType()); +#if JL_LLVM_VERSION >= 200000 SelectInst *SelectBase = SelectInst::Create(Cond, TrueElem, FalseElem, "gclift", SI->getIterator()); +#else + SelectInst *SelectBase = SelectInst::Create(Cond, TrueElem, FalseElem, "gclift", SI); +#endif int Number = ++S.MaxPtrNumber; S.AllPtrNumbering[SelectBase] = Number; S.ReversePtrNumbering[Number] = SelectBase; @@ -389,7 +397,11 @@ void LateLowerGCFrame::LiftPhi(State &S, PHINode *Phi) { Numbers.resize(NumRoots); } for (unsigned i = 0; i < NumRoots; ++i) { +#if JL_LLVM_VERSION >= 200000 PHINode *lift = PHINode::Create(T_prjlvalue, Phi->getNumIncomingValues(), "gclift", Phi->getIterator()); +#else + PHINode *lift = PHINode::Create(T_prjlvalue, Phi->getNumIncomingValues(), "gclift", Phi); +#endif int Number = ++S.MaxPtrNumber; S.AllPtrNumbering[lift] = Number; S.ReversePtrNumbering[Number] = lift; @@ -1969,8 +1981,13 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { unsigned allocaAddressSpace = F.getParent()->getDataLayout().getAllocaAddrSpace(); if (T_prjlvalue) { T_pprjlvalue = PointerType::getUnqual(T_prjlvalue->getContext()); - Frame = new AllocaInst(T_prjlvalue, allocaAddressSpace, - ConstantInt::get(T_int32, maxframeargs), "jlcallframe", StartOff->getIterator()); + Frame = new AllocaInst(T_prjlvalue, allocaAddressSpace,ConstantInt::get(T_int32, maxframeargs), "jlcallframe", +#if JL_LLVM_VERSION >= 200000 + StartOff->getIterator() +#else + StartOff +#endif + ); } SmallVector write_barriers; for (BasicBlock &BB : F) { @@ -2011,13 +2028,21 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { /* No replacement */ } else if (pointer_from_objref_func != nullptr && callee == pointer_from_objref_func) { auto *obj = CI->getOperand(0); +#if JL_LLVM_VERSION >= 200000 auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI->getIterator()); +#else + auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI); +#endif ASCI->takeName(CI); CI->replaceAllUsesWith(ASCI); UpdatePtrNumbering(CI, ASCI, S); } else if (gc_loaded_func != nullptr && callee == gc_loaded_func) { auto *obj = CI->getOperand(1); +#if JL_LLVM_VERSION >= 200000 auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI->getIterator()); +#else + auto *ASCI = new AddrSpaceCastInst(obj, CI->getType(), "", CI); +#endif ASCI->takeName(CI); CI->replaceAllUsesWith(ASCI); UpdatePtrNumbering(CI, ASCI, S); @@ -2170,7 +2195,11 @@ bool LateLowerGCFrame::CleanupIR(Function &F, State *S, bool *CFGModified) { FunctionType *FTy = callee == call3_func ? JuliaType::get_jlfunc3_ty(CI->getContext()) : callee == call2_func ? JuliaType::get_jlfunc2_ty(CI->getContext()) : JuliaType::get_jlfunc_ty(CI->getContext()); +#if JL_LLVM_VERSION >= 200000 CallInst *NewCall = CallInst::Create(FTy, new_callee, ReplacementArgs, "", CI->getIterator()); +#else + CallInst *NewCall = CallInst::Create(FTy, new_callee, ReplacementArgs, "", CI); +#endif NewCall->setTailCallKind(CI->getTailCallKind()); auto callattrs = CI->getAttributes(); callattrs = AttributeList::get(CI->getContext(), getFnAttrs(callattrs), getRetAttrs(callattrs), {}); @@ -2287,7 +2316,11 @@ void LateLowerGCFrame::PlaceGCFrameStore(State &S, unsigned R, unsigned MinColor 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 Value *Val = GetPtrForNumber(S, R, InsertBefore); // Pointee types don't have semantics, so the optimizer is diff --git a/src/llvm-multiversioning.cpp b/src/llvm-multiversioning.cpp index 61058f7af08cd..63f9e5b6ef2e4 100644 --- a/src/llvm-multiversioning.cpp +++ b/src/llvm-multiversioning.cpp @@ -767,7 +767,11 @@ std::pair CloneCtx::get_reloc_slot(Function *F) const } template +#if JL_LLVM_VERSION >= 200000 static Value *rewrite_inst_use(const Stack& stack, Type *T_size, Value *replace, InsertPosition& insert_before) +#else +static Value *rewrite_inst_use(const Stack& stack, Type *T_size, Value *replace, Instruction *insert_before) +#endif { SmallVector args; uint32_t nlevel = stack.size(); @@ -828,9 +832,17 @@ static void replaceUsesWithLoad(Function &F, Type *T_size, I2GV should_replace, GlobalVariable *slot = should_replace(*use_i); if (!slot) continue; +#if JL_LLVM_VERSION >= 200000 InsertPosition insert_before = use_i->getIterator(); +#else + Instruction *insert_before = use_i; +#endif if (auto phi = dyn_cast(use_i)) +#if JL_LLVM_VERSION >= 200000 insert_before = phi->getIncomingBlock(*info.use)->getTerminator()->getIterator(); +#else + insert_before = phi->getIncomingBlock(*info.use)->getTerminator(); +#endif Instruction *ptr = new LoadInst(F.getType(), slot, "", false, insert_before); ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const); ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(ptr->getContext(), None)); diff --git a/src/llvm-ptls.cpp b/src/llvm-ptls.cpp index 1bc05c4ce0af8..705742249d3b0 100644 --- a/src/llvm-ptls.cpp +++ b/src/llvm-ptls.cpp @@ -190,7 +190,11 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, phi->addIncoming(pgcstack, fastTerm->getParent()); // emit pre-return cleanup if (CountTrackedPointers(pgcstack->getParent()->getParent()->getReturnType()).count == 0) { +#if JL_LLVM_VERSION >= 200000 auto last_gc_state = PHINode::Create(Type::getInt8Ty(pgcstack->getContext()), 2, "", phi->getIterator()); +#else + auto last_gc_state = PHINode::Create(Type::getInt8Ty(pgcstack->getContext()), 2, "", phi); +#endif // if we called jl_adopt_thread, we must end this cfunction back in the safe-state last_gc_state->addIncoming(ConstantInt::get(Type::getInt8Ty(M->getContext()), JL_GC_STATE_SAFE), slowTerm->getParent()); last_gc_state->addIncoming(prior, fastTerm->getParent()); @@ -282,7 +286,11 @@ void LowerPTLS::fix_pgcstack_use(CallInst *pgcstack, Function *pgcstack_getter, if (TargetTriple.isOSDarwin()) { assert(sizeof(k) == sizeof(uintptr_t)); Constant *key = ConstantInt::get(T_size, (uintptr_t)k); +#if JL_LLVM_VERSION >= 200000 auto new_pgcstack = CallInst::Create(FT_pgcstack_getter, val, {key}, "", pgcstack->getIterator()); +#else + auto new_pgcstack = CallInst::Create(FT_pgcstack_getter, val, {key}, "", pgcstack); +#endif new_pgcstack->takeName(pgcstack); pgcstack->replaceAllUsesWith(new_pgcstack); pgcstack->eraseFromParent(); From bc17490f1fcb765c7dee01180068fd173dae8f7e Mon Sep 17 00:00:00 2001 From: Zentrik Date: Tue, 11 Feb 2025 22:35:04 +0000 Subject: [PATCH 14/16] fixup! Adapt to "CodeGen: Avoid using MachineFunction::getMMI in MachineModuleSlotTracker (#100310)" --- src/codegen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 54db41552966d..fdc7552e733c8 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -10594,7 +10594,7 @@ namespace llvm { void printMIR(raw_ostream &OS, const MachineModuleInfo &MMI, const MachineFunction &MF); #else -void printMIR(raw_ostream &OS, const MachineFunction &MF); + void printMIR(raw_ostream &OS, const MachineFunction &MF); #endif } extern "C" void jl_dump_llvm_mbb(void *v) From a6558896e791c693418bd41218a39142397699bb Mon Sep 17 00:00:00 2001 From: Zentrik Date: Tue, 11 Feb 2025 22:36:19 +0000 Subject: [PATCH 15/16] fixup! Adapt to "[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)" --- src/llvm-alloc-opt.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-alloc-opt.cpp b/src/llvm-alloc-opt.cpp index cd6ee5fe5efea..bfc1b42444cd1 100644 --- a/src/llvm-alloc-opt.cpp +++ b/src/llvm-alloc-opt.cpp @@ -814,7 +814,7 @@ void Optimizer::moveToStack(CallInst *orig_inst, size_t sz, bool has_ref, AllocF #if JL_LLVM_VERSION >= 200000 gep->getName(), gep->getIterator()); #else - gep->getName(), gep); + gep->getName(), gep); #endif new_gep->setIsInBounds(gep->isInBounds()); new_gep->takeName(gep); From b73126e9b7aa465f5c16ecc8914047a9421e0cee Mon Sep 17 00:00:00 2001 From: Zentrik Date: Tue, 11 Feb 2025 22:37:07 +0000 Subject: [PATCH 16/16] fixup! fixup! Adapt to "[DebugInfo] Enable deprecation of iterator-insertion methods (#102608)" --- src/llvm-julia-licm.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/llvm-julia-licm.cpp b/src/llvm-julia-licm.cpp index f971eb0623594..68fe41216bfd4 100644 --- a/src/llvm-julia-licm.cpp +++ b/src/llvm-julia-licm.cpp @@ -241,7 +241,7 @@ struct JuliaLICM : public JuliaPassContext { #if JL_LLVM_VERSION >= 200000 auto CI = CallInst::Create(call, {}, exit_pts[i]->getIterator()); #else - auto CI = CallInst::Create(call, {}, "", exit_pts[i]); + auto CI = CallInst::Create(call, {}, exit_pts[i]); #endif exit_pts[i] = CI; createNewInstruction(CI, call, MSSAU);