Skip to content

Commit

Permalink
Merge branch 'master' into stacktrace-filters
Browse files Browse the repository at this point in the history
  • Loading branch information
BioTurboNick authored Dec 6, 2024
2 parents b4fbf93 + fe26173 commit 6db1238
Show file tree
Hide file tree
Showing 34 changed files with 36 additions and 656 deletions.
12 changes: 2 additions & 10 deletions Compiler/extras/CompilerDevTools/src/CompilerDevTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,11 @@ import Core.OptimizedGenerics.CompilerPlugins: typeinf, typeinf_edge
Compiler.typeinf_edge(interp, mi.def, mi.specTypes, Core.svec(), parent_frame, false, false)
end

# TODO: This needs special compiler support to properly case split for multiple
# method matches, etc.
@noinline function mi_for_tt(tt, world=Base.tls_world_age())
interp = SplitCacheInterp(; world)
match, _ = Compiler.findsup(tt, Compiler.method_table(interp))
Base.specialize_method(match)
end

function with_new_compiler(f, args...)
tt = Base.signature_type(f, typeof(args))
mi = @ccall jl_method_lookup(Any[f, args...]::Ptr{Any}, (1+length(args))::Csize_t, Base.tls_world_age()::Csize_t)::Ref{Core.MethodInstance}
world = Base.tls_world_age()
new_compiler_ci = Core.OptimizedGenerics.CompilerPlugins.typeinf(
SplitCacheOwner(), mi_for_tt(tt), Compiler.SOURCE_MODE_ABI
SplitCacheOwner(), mi, Compiler.SOURCE_MODE_ABI
)
invoke(f, new_compiler_ci, args...)
end
Expand Down
9 changes: 5 additions & 4 deletions Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2223,11 +2223,12 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
if isa(method_or_ci, CodeInstance)
our_world = sv.world.this
argtype = argtypes_to_type(pushfirst!(argtype_tail(argtypes, 4), ft))
sig = method_or_ci.def.specTypes
specsig = method_or_ci.def.specTypes
defdef = method_or_ci.def.def
exct = method_or_ci.exctype
if !hasintersect(argtype, sig)
if !hasintersect(argtype, specsig)
return Future(CallMeta(Bottom, TypeError, EFFECTS_THROWS, NoCallInfo()))
elseif !(argtype <: sig)
elseif !(argtype <: specsig) || (isa(defdef, Method) && !(argtype <: defdef.sig))
exct = Union{exct, TypeError}
end
callee_valid_range = WorldRange(method_or_ci.min_world, method_or_ci.max_world)
Expand Down Expand Up @@ -2257,7 +2258,7 @@ function abstract_invoke(interp::AbstractInterpreter, arginfo::ArgInfo, si::Stmt
# Fall through to generic invoke handling
end
else
widenconst(types) >: Union{Method, CodeInstance} && return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
hasintersect(widenconst(types), Union{Method, CodeInstance}) && return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
(types, isexact, isconcrete, istype) = instanceof_tfunc(argtype_by_index(argtypes, 3), false)
isexact || return Future(CallMeta(Any, Any, Effects(), NoCallInfo()))
unwrapped = unwrap_unionall(types)
Expand Down
2 changes: 1 addition & 1 deletion Compiler/src/stmtinfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ struct InvokeCICallInfo <: CallInfo
edge::CodeInstance
end
add_edges_impl(edges::Vector{Any}, info::InvokeCICallInfo) =
add_one_edge!(edges, info.edge)
add_inlining_edge!(edges, info.edge)

"""
info::InvokeCallInfo
Expand Down
4 changes: 2 additions & 2 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2064,8 +2064,8 @@ to `invoke(f, method.sig, args...)`.
The `argtypes` argument may be a `CodeInstance`, bypassing both method lookup and specialization.
The semantics of this invocation are similar to a function pointer call of the `CodeInstance`'s
`invoke` pointer. It is an error to invoke a `CodeInstance` with arguments that do not match its
parent MethodInstance or from a world age not included in the `min_world`/`max_world` range.
It is undefined behavior to invoke a CodeInstance whose behavior does not match the constraints
parent `MethodInstance` or from a world age not included in the `min_world`/`max_world` range.
It is undefined behavior to invoke a `CodeInstance` whose behavior does not match the constraints
specified in its fields. For some code instances with `owner !== nothing` (i.e. those generated
by external compilers), it may be an error to invoke them after passing through precompilation.
This is an advanced interface intended for use with external compiler plugins.
Expand Down
2 changes: 1 addition & 1 deletion base/optimized_generics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ end
Implements a pair of functions `typeinf`/`typeinf_edge`. When the optimizer sees
a call to `typeinf`, it has license to instead call `typeinf_edge`, supplying the
current inference stack in `parent_frame` (but otherwise supplying the arguments
to `typeinf`). typeinf_edge will return the `CodeInstance` that `typeinf` would
to `typeinf`). `typeinf_edge` will return the `CodeInstance` that `typeinf` would
have returned at runtime. The optimizer may perform a non-IPO replacement of
the call to `typeinf` by the result of `typeinf_edge`. In addition, the IPO-safe
fields of the `CodeInstance` may be propagated in IPO mode.
Expand Down
2 changes: 1 addition & 1 deletion doc/src/devdocs/build/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ The most complicated dependency is LLVM, for which we require additional patches
For packaging Julia with LLVM, we recommend either:
- bundling a Julia-only LLVM library inside the Julia package, or
- adding the patches to the LLVM package of the distribution.
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/15.x` branch.
* A complete list of patches is available in on [Github](https://github.com/JuliaLang/llvm-project) see the `julia-release/18.x` branch.
* The only Julia-specific patch is the lib renaming (`llvm7-symver-jlprefix.patch`), which should _not_ be applied to a system LLVM.
* The remaining patches are all upstream bug fixes, and have been contributed into upstream LLVM.

Expand Down
54 changes: 0 additions & 54 deletions src/APInt-C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,6 @@ void LLVMTrunc(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *otys, integerP
memcpy(pr, pa, onumbytes);
}

#if JL_LLVM_VERSION >= 170000
extern "C" JL_DLLEXPORT
unsigned countr_zero_8(uint8_t Val) {
return countr_zero(Val);
Expand All @@ -495,27 +494,6 @@ extern "C" JL_DLLEXPORT
unsigned countr_zero_64(uint64_t Val) {
return countr_zero(Val);
}
#else
extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_8(uint8_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_16(uint16_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_32(uint32_t Val) {
return countTrailingZeros(Val);
}

extern "C" JL_DLLEXPORT
unsigned countTrailingZeros_64(uint64_t Val) {
return countTrailingZeros(Val);
}
#endif

extern "C" JL_DLLEXPORT
void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr) {
Expand Down Expand Up @@ -545,7 +523,6 @@ void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integer
memcpy(pr, pa, numbytes);
}

#if JL_LLVM_VERSION >= 170000
extern "C" JL_DLLEXPORT
unsigned LLVMPopcount(unsigned numbits, integerPart *pa) {
CREATE(a)
Expand Down Expand Up @@ -575,34 +552,3 @@ unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countl_zero();
}
#else
extern "C" JL_DLLEXPORT
unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countPopulation();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countTrailingOnes();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countTrailingZeros();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countLeadingOnes();
}

extern "C" JL_DLLEXPORT
unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa) {
CREATE(a)
return a.countLeadingZeros();
}
#endif
15 changes: 0 additions & 15 deletions src/APInt-C.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,11 @@ JL_DLLEXPORT int LLVMDiv_uov(unsigned numbits, integerPart *pa, integerPart *pb,
JL_DLLEXPORT int LLVMRem_sov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
JL_DLLEXPORT int LLVMRem_uov(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

#if JL_LLVM_VERSION >= 170000
JL_DLLEXPORT unsigned LLVMPopcount(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountr_one(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountr_zero(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountl_one(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountl_zero(unsigned numbits, integerPart *pa);
#else
JL_DLLEXPORT unsigned LLVMCountPopulation(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountTrailingOnes(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountTrailingZeros(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountLeadingOnes(unsigned numbits, integerPart *pa);
JL_DLLEXPORT unsigned LLVMCountLeadingZeros(unsigned numbits, integerPart *pa);
#endif

JL_DLLEXPORT void LLVMFPtoSI(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *oty, integerPart *pr);
JL_DLLEXPORT void LLVMFPtoUI(jl_datatype_t *ty, integerPart *pa, jl_datatype_t *oty, integerPart *pr);
Expand All @@ -82,17 +74,10 @@ JL_DLLEXPORT int LLVMFPtoUI_exact(jl_datatype_t *ty, integerPart *pa, jl_datatyp
JL_DLLEXPORT void jl_LLVMSMod(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);
JL_DLLEXPORT void jl_LLVMFlipSign(unsigned numbits, integerPart *pa, integerPart *pb, integerPart *pr);

#if JL_LLVM_VERSION >= 170000
JL_DLLEXPORT unsigned countr_zero_8(uint8_t Val);
JL_DLLEXPORT unsigned countr_zero_16(uint16_t Val);
JL_DLLEXPORT unsigned countr_zero_32(uint32_t Val);
JL_DLLEXPORT unsigned countr_zero_64(uint64_t Val);
#else
JL_DLLEXPORT unsigned countTrailingZeros_8(uint8_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_16(uint16_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_32(uint32_t Val);
JL_DLLEXPORT unsigned countTrailingZeros_64(uint64_t Val);
#endif

//uint8_t getSwappedBytes_8(uint8_t Value); // no-op
//uint16_t getSwappedBytes_16(uint16_t Value);
Expand Down
6 changes: 1 addition & 5 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,7 @@ else
# JULIACODEGEN != LLVM
endif

RT_LLVM_LIBS := support

ifeq ($(shell test $(LLVM_VER_MAJ) -ge 16 && echo true),true)
RT_LLVM_LIBS += targetparser
endif
RT_LLVM_LIBS := support targetparser

ifeq ($(OS),WINNT)
SRCS += win32_ucontext
Expand Down
30 changes: 2 additions & 28 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
#include "platform.h"

// target support
#if JL_LLVM_VERSION >= 170000
#include <llvm/TargetParser/Triple.h>
#else
#include <llvm/ADT/Triple.h>
#endif
#include "llvm/Support/CodeGen.h"
#include <llvm/ADT/Statistic.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
Expand Down Expand Up @@ -963,11 +959,7 @@ static FunctionInfo getFunctionWeight(const Function &F)
auto val = F.getFnAttribute("julia.mv.clones").getValueAsString();
// base16, so must be at most 4 * length bits long
// popcount gives number of clones
#if JL_LLVM_VERSION >= 170000
info.clones = APInt(val.size() * 4, val, 16).popcount() + 1;
#else
info.clones = APInt(val.size() * 4, val, 16).countPopulation() + 1;
#endif
}
info.weight += info.insts;
// more basic blocks = more complex than just sum of insts,
Expand Down Expand Up @@ -1372,7 +1364,7 @@ static AOTOutputs add_output_impl(Module &M, TargetMachine &SourceTM, ShardTimer
// So for now we inject a definition of these functions that calls our runtime
// functions. We do so after optimization to avoid cloning these functions.
// Float16 conversion routines
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_) && JL_LLVM_VERSION >= 160000
#if defined(_CPU_X86_64_) && defined(_OS_DARWIN_)
// LLVM 16 reverted to soft-float ABI for passing half on x86_64 Darwin
// https://github.com/llvm/llvm-project/commit/2bcf51c7f82ca7752d1bba390a2e0cb5fdd05ca9
injectCRTAlias(M, "__gnu_h2f_ieee", "julia_half_to_float",
Expand Down Expand Up @@ -1721,9 +1713,6 @@ static SmallVector<AOTOutputs, 16> add_output(Module &M, TargetMachine &TM, Stri
std::function<void()> func = [&, i]() {
LLVMContext ctx;
ctx.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(ctx);
#endif
// Lazily deserialize the entire module
timers[i].deserialize.startTimer();
auto EM = getLazyBitcodeModule(MemoryBufferRef(StringRef(serialized.data(), serialized.size()), "Optimized"), ctx);
Expand Down Expand Up @@ -1888,7 +1877,7 @@ void jl_dump_native_impl(void *native_code,
Str += "10.14.0";
TheTriple.setOSName(Str);
}
Optional<Reloc::Model> RelocModel;
std::optional<Reloc::Model> RelocModel;
if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD() || TheTriple.isOSOpenBSD()) {
RelocModel = Reloc::PIC_;
}
Expand Down Expand Up @@ -1933,9 +1922,6 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Sysimg);
LLVMContext Context;
Context.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module sysimgM("sysimg", Context);
sysimgM.setTargetTriple(TheTriple.str());
sysimgM.setDataLayout(DL);
Expand Down Expand Up @@ -2081,9 +2067,6 @@ void jl_dump_native_impl(void *native_code,
JL_TIMING(NATIVE_AOT, NATIVE_Metadata);
LLVMContext Context;
Context.setDiscardValueNames(true);
#if JL_LLVM_VERSION < 170000
SetOpaquePointer(Context);
#endif
Module metadataM("metadata", Context);
metadataM.setTargetTriple(TheTriple.str());
metadataM.setDataLayout(DL);
Expand Down Expand Up @@ -2299,16 +2282,7 @@ void jl_get_llvmf_defn_impl(jl_llvmf_dump_t* dump, jl_method_instance_t *mi, jl_
}
else {
auto p = literal_static_pointer_val(global.first, global.second->getValueType());
#if JL_LLVM_VERSION >= 170000
Type *elty = PointerType::get(output.getContext(), 0);
#else
Type *elty;
if (p->getType()->isOpaquePointerTy()) {
elty = PointerType::get(output.getContext(), 0);
} else {
elty = p->getType()->getNonOpaquePointerElementType();
}
#endif
// For pretty printing, when LLVM inlines the global initializer into its loads
auto alias = GlobalAlias::create(elty, 0, GlobalValue::PrivateLinkage, global.second->getName() + ".jit", p, global.second->getParent());
global.second->setInitializer(ConstantExpr::getBitCast(alias, global.second->getValueType()));
Expand Down
10 changes: 6 additions & 4 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -1590,8 +1590,10 @@ JL_CALLABLE(jl_f_invoke)
} else if (jl_is_code_instance(argtypes)) {
jl_code_instance_t *codeinst = (jl_code_instance_t*)args[1];
jl_callptr_t invoke = jl_atomic_load_acquire(&codeinst->invoke);
if (jl_tuple1_isa(args[0], &args[2], nargs - 2, (jl_datatype_t*)codeinst->def->specTypes)) {
jl_type_error("invoke: argument type error", codeinst->def->specTypes, arg_tuple(args[0], &args[2], nargs - 2));
// N.B.: specTypes need not be a subtype of the method signature. We need to check both.
if (!jl_tuple1_isa(args[0], &args[2], nargs - 1, (jl_datatype_t*)codeinst->def->specTypes) ||
(jl_is_method(codeinst->def->def.value) && !jl_tuple1_isa(args[0], &args[2], nargs - 1, (jl_datatype_t*)codeinst->def->def.method->sig))) {
jl_type_error("invoke: argument type error", codeinst->def->specTypes, arg_tuple(args[0], &args[2], nargs - 1));
}
if (jl_atomic_load_relaxed(&codeinst->min_world) > jl_current_task->world_age ||
jl_current_task->world_age > jl_atomic_load_relaxed(&codeinst->max_world)) {
Expand All @@ -1604,10 +1606,10 @@ JL_CALLABLE(jl_f_invoke)
if (invoke) {
return invoke(args[0], &args[2], nargs - 2, codeinst);
} else {
if (codeinst->owner != jl_nothing || !jl_is_method(codeinst->def->def.value)) {
if (codeinst->owner != jl_nothing) {
jl_error("Failed to invoke or compile external codeinst");
}
return jl_gf_invoke_by_method(codeinst->def->def.method, args[0], &args[2], nargs - 1);
return jl_invoke(args[0], &args[2], nargs - 1, codeinst->def);
}
}
if (!jl_is_tuple_type(jl_unwrap_unionall(argtypes)))
Expand Down
3 changes: 0 additions & 3 deletions src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,6 @@ static GlobalVariable *emit_plt_thunk(
SmallVector<Value*, 16> args;
for (auto &arg : plt->args())
args.push_back(&arg);
#if JL_LLVM_VERSION < 170000
assert(cast<PointerType>(ptr->getType())->isOpaqueOrPointeeTypeMatches(functype));
#endif
CallInst *ret = irbuilder.CreateCall(
functype,
ptr, ArrayRef<Value*>(args));
Expand Down
Loading

0 comments on commit 6db1238

Please sign in to comment.