Skip to content
Merged
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
1 change: 0 additions & 1 deletion Compiler/extras/CompilerDevTools/test/testpkg.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Pkg

Pkg.activate(dirname(@__DIR__)) do
Pkg.instantiate()
include("runtests.jl")
end
16 changes: 16 additions & 0 deletions JuliaLowering/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.14.0-DEV"
manifest_format = "2.1"
project_hash = "16f6f8d58c46fe20d68a941bfaddb4590471548a"

[[deps.JuliaLowering]]
deps = ["JuliaSyntax"]
path = "."
uuid = "f3c80556-a63f-4383-b822-37d64f81a311"
version = "1.0.0-DEV"

[[deps.JuliaSyntax]]
path = "../JuliaSyntax"
uuid = "70703baa-626e-46a2-a12c-08ffd08c73b4"
version = "2.0.0-DEV"
3 changes: 3 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ function locate_package_env(pkg::PkgId, stopenv::Union{String, Nothing}=nothing)
path = manifest_uuid_path(env, pkg)
# missing is used as a sentinel to stop looking further down in envs
if path === missing
# Before stopping, try stdlib fallback
is_stdlib(pkg) && @goto stdlib_fallback
path = nothing
@goto done
end
Expand All @@ -481,6 +483,7 @@ function locate_package_env(pkg::PkgId, stopenv::Union{String, Nothing}=nothing)
stopenv == env && break
end
end
@label stdlib_fallback
# Allow loading of stdlibs if the name/uuid are given
# e.g. if they have been explicitly added to the project/manifest
mbypath = manifest_uuid_path(Sys.STDLIB, pkg)
Expand Down
4 changes: 2 additions & 2 deletions contrib/generate_precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,8 +348,8 @@ generate_precompile_statements() = try # Make sure `ansi_enablecursor` is printe
uuid = "$pkguuid"
""")
touch(joinpath(pkgpath, "Manifest.toml"))
tmp_prec = tempname(prec_path)
tmp_proc = tempname(prec_path)
tmp_prec = tempname(prec_path; cleanup=false)
tmp_proc = tempname(prec_path; cleanup=false)
s = """
pushfirst!(DEPOT_PATH, $(repr(joinpath(prec_path,"depot"))));
Base.PRECOMPILE_TRACE_COMPILE[] = $(repr(tmp_prec));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cb635b45a66cab302b34bf56367e69d7
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
40a0495141d6b220bbc6b4119369cdc86b22498ca6a9c83eba47aec397c4c92afa5776e9043b1545a3111ace0317ca0c2412d0ba51731a7505742f47545a5530

This file was deleted.

This file was deleted.

2 changes: 1 addition & 1 deletion deps/jlutilities/documenter/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ version = "1.0.0"
[[deps.LibCURL_jll]]
deps = ["Artifacts", "CompilerSupportLibraries_jll", "LibSSH2_jll", "Libdl", "OpenSSL_jll", "Zlib_jll", "Zstd_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "8.16.0+0"
version = "8.17.0+0"

[[deps.LibGit2]]
deps = ["LibGit2_jll", "NetworkOptions", "Printf", "SHA"]
Expand Down
28 changes: 28 additions & 0 deletions deps/jlutilities/objectfile/Manifest.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.14.0-DEV"
manifest_format = "2.1"
project_hash = "23b8253b8eadb7ba5d7489bb56f38819b7150654"

[[deps.ObjectFile]]
deps = ["Reexport", "StructIO"]
git-tree-sha1 = "22faba70c22d2f03e60fbc61da99c4ebfc3eb9ba"
registries = "General"
uuid = "d8793406-e978-5875-9003-1fc021f44a92"
version = "0.5.0"

[[deps.Reexport]]
git-tree-sha1 = "45e428421666073eab6f2da5c9d310d99bb12f9b"
registries = "General"
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
version = "1.2.2"

[[deps.StructIO]]
git-tree-sha1 = "c581be48ae1cbf83e899b14c07a807e1787512cc"
registries = "General"
uuid = "53d494c1-5632-5724-8f4c-31dff12d585f"
version = "0.3.1"

[registries.General]
url = "https://github.com/JuliaRegistries/General.git"
uuid = "23338594-aafe-5451-b93e-139f81909106"
2 changes: 2 additions & 0 deletions deps/jlutilities/objectfile/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[deps]
ObjectFile = "d8793406-e978-5875-9003-1fc021f44a92"
9 changes: 9 additions & 0 deletions doc/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,15 @@ BaseDocs = [

StdlibDocs = [stdlib.targetfile for stdlib in STDLIB_DOCS]

# HACK: get nicer sorting here, even though we don't have the header
# of the .md files at hand.
sort!(StdlibDocs, by=function(x)
x = replace(x, "stdlib/" => "")
startswith(x, "Libdl") && return lowercase("Dynamic Linker")
startswith(x, "Test") && return lowercase("Unit Testing")
return lowercase(x)
end)

DevDocs = [
"Documentation of Julia's Internals" => [
"devdocs/init.md",
Expand Down
54 changes: 8 additions & 46 deletions doc/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ Markdown.parse("""
""")
```

## [Important Links](@id man-important-links)

Below is a non-exhaustive list of links that will be useful as you learn and use the Julia programming language.

- [Julia Homepage](https://julialang.org)
- [Install Julia](https://julialang.org/install/)
- [Discussion forum](https://discourse.julialang.org)
- [Julia YouTube](https://www.youtube.com/user/JuliaLanguage)
- [Find Julia Packages](https://julialang.org/packages/)
- [Learning Resources](https://julialang.org/learning/)
- [Read and write blogs on Julia](https://forem.julialang.org)

## [Introduction](@id man-introduction)

Scientific computing has traditionally required the highest performance, yet domain experts have
Expand Down Expand Up @@ -127,39 +115,13 @@ language. In addition to the above, some advantages of Julia over comparable sys
* Powerful shell-like capabilities for managing other processes
* Lisp-like macros and other metaprogramming facilities

## [Julia Standard Modules and the Standard Library](@id man-standard-modules-stdlib)

The Julia runtime comes with [standard modules](@ref standard-modules),
which are essential namespaces that are usually loaded automatically.

```@docs; canonical=false
Core
Base
```

Julia's `Base` module contains various [useful submodules](@ref base-submodules).

### [The Standard Library](@id man-stdlib)

The Julia standard library contains additional, commonly used packages that are installed alongside the Julia runtime by default.
To use a standard library package, it is first necessary to load the package with a [`using`](@ref) or [`import`](@ref) statement.
Links to available standard library packages are provided below,
and may also be found in the website sidebar.
Their source code is available in the `Sys.STDLIB` directory of a Julia installation.

```@eval
import Markdown
list = sort(filter(x -> match(r"_jll$", x) === nothing, readdir(Sys.STDLIB)))
Markdown.parse(join("- [`" .* list .* "`](stdlib/" .* list .* ".html)", "\n"))
```
## [Important Links](@id man-important-links)

Julia also provides various standard, pre-built binary libraries
of established software that is written in other languages.
By convention, these packages have names that end with `_jll`.
The [`using`](@ref) statement can load symbol names from these binary libraries:
A non-exhaustive list of links that will be useful as you learn and use the Julia programming language:

```@eval
import Markdown
list = sort(filter(x -> match(r"_jll$", x) !== nothing, readdir(Sys.STDLIB)))
Markdown.parse(join("- [`" .* list .* "`](stdlib/" .* list .* ".html)", "\n"))
```
- [Julia Homepage](https://julialang.org)
- [Install Julia](https://julialang.org/install/)
- [Discussion forum](https://discourse.julialang.org)
- [Julia YouTube](https://www.youtube.com/user/JuliaLanguage)
- [Find Julia Packages](https://julialang.org/packages/)
- [Learning Resources](https://julialang.org/learning/)
98 changes: 64 additions & 34 deletions src/llvm-multiversioning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ struct CloneCtx {
void clone_partial(Group &grp, Target &tgt);
uint32_t get_func_id(Function *F) const;
std::pair<uint32_t,GlobalVariable*> get_reloc_slot(Function *F) const;

Function *create_trampoline(Function *F, GlobalVariable *slot, bool autoinit=false);
void rewrite_alias(GlobalAlias *alias, Function* F);

MDNode *tbaa_const;
Expand Down Expand Up @@ -493,6 +495,53 @@ void CloneCtx::prepare_vmap(ValueToValueMapTy &vmap)
}
}

Function *CloneCtx::create_trampoline(Function *F, GlobalVariable *slot, bool autoinit)
{
Function *trampoline =
Function::Create(F->getFunctionType(), GlobalValue::ExternalLinkage, "", &M);

trampoline->copyAttributesFrom(F);
trampoline->setVisibility(GlobalValue::HiddenVisibility);
trampoline->setDSOLocal(true);

// drop multiversioning attributes
trampoline->removeFnAttr("julia.mv.reloc");
trampoline->removeFnAttr("julia.mv.clones");

auto BB = BasicBlock::Create(F->getContext(), "top", trampoline);
IRBuilder<> irbuilder(BB);

if (autoinit) {
irbuilder.CreateCall(F->getParent()->getOrInsertFunction(
XSTR(jl_autoinit_and_adopt_thread),
PointerType::get(F->getContext(), 0)
));
}

auto ptr = irbuilder.CreateLoad(F->getType(), slot);
ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const);
ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(F->getContext(), None));

SmallVector<Value *, 0> Args;
for (auto &arg : trampoline->args())
Args.push_back(&arg);
auto call = irbuilder.CreateCall(F->getFunctionType(), ptr, ArrayRef<Value *>(Args));
if (F->isVarArg()) {
assert(!TT.isARM() && !TT.isPPC() && "musttail not supported on ARM/PPC!");
call->setTailCallKind(CallInst::TCK_MustTail);
} else {
call->setTailCallKind(CallInst::TCK_Tail);

}

if (F->getReturnType() == Type::getVoidTy(F->getContext()))
irbuilder.CreateRetVoid();
else
irbuilder.CreateRet(call);

return trampoline;
}

void CloneCtx::prepare_slots()
{
for (auto &F : orig_funcs) {
Expand All @@ -507,7 +556,12 @@ void CloneCtx::prepare_slots()
else {
auto id = get_func_id(F);
const_relocs[id] = GV;
GV->setInitializer(Constant::getNullValue(F->getType()));

// Initialize with a single-use trampoline that calls `jl_autoinit_and_adopt_thread`,
// so that auto-initialization works with multi-versioned entrypoints.
Function *trampoline = create_trampoline(F, GV, /* autoinit */ true);
trampoline->setName(F->getName() + ".autoinit_trampoline");
GV->setInitializer(trampoline);
}
}
}
Expand Down Expand Up @@ -665,45 +719,21 @@ void CloneCtx::rewrite_alias(GlobalAlias *alias, Function *F)
{
assert(!is_vector(F->getFunctionType()));

Function *trampoline =
Function::Create(F->getFunctionType(), alias->getLinkage(), "", &M);
trampoline->copyAttributesFrom(F);
trampoline->takeName(alias);
trampoline->setVisibility(alias->getVisibility());
trampoline->setDSOLocal(alias->isDSOLocal());
// drop multiversioning attributes, add alias attribute for testing purposes
trampoline->removeFnAttr("julia.mv.reloc");
trampoline->removeFnAttr("julia.mv.clones");
trampoline->addFnAttr("julia.mv.alias");
trampoline->setDLLStorageClass(alias->getDLLStorageClass());
alias->eraseFromParent();

uint32_t id;
GlobalVariable *slot;
std::tie(id, slot) = get_reloc_slot(F);
assert(slot);

auto BB = BasicBlock::Create(F->getContext(), "top", trampoline);
IRBuilder<> irbuilder(BB);
Function *trampoline = create_trampoline(F, slot, /* autoinit */ false);
trampoline->addFnAttr("julia.mv.alias"); // add alias attribute for testing purposes

auto ptr = irbuilder.CreateLoad(F->getType(), slot);
ptr->setMetadata(llvm::LLVMContext::MD_tbaa, tbaa_const);
ptr->setMetadata(llvm::LLVMContext::MD_invariant_load, MDNode::get(F->getContext(), None));

SmallVector<Value *, 0> Args;
for (auto &arg : trampoline->args())
Args.push_back(&arg);
auto call = irbuilder.CreateCall(F->getFunctionType(), ptr, ArrayRef<Value *>(Args));
if (F->isVarArg()) {
assert(!TT.isARM() && !TT.isPPC() && "musttail not supported on ARM/PPC!");
call->setTailCallKind(CallInst::TCK_MustTail);
} else {
call->setTailCallKind(CallInst::TCK_Tail);
}
trampoline->takeName(alias);
trampoline->setLinkage(alias->getLinkage());
trampoline->setVisibility(alias->getVisibility());
trampoline->setDSOLocal(alias->isDSOLocal());
trampoline->setDLLStorageClass(alias->getDLLStorageClass());

if (F->getReturnType() == Type::getVoidTy(F->getContext()))
irbuilder.CreateRetVoid();
else
irbuilder.CreateRet(call);
alias->eraseFromParent();
}

void CloneCtx::fix_gv_uses()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg.version
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
PKG_BRANCH = release-1.13
PKG_SHA1 = d0be1daf22f15da346e83429b323a82554ef241c
PKG_SHA1 = 4f9884fdb867f2c928ba43dc41da5f150aaec4ab
PKG_GIT_URL := https://github.com/JuliaLang/Pkg.jl.git
PKG_TAR_URL = https://api.github.com/repos/JuliaLang/Pkg.jl/tarball/$1
20 changes: 15 additions & 5 deletions test/llvmpasses/multiversioning-clone-only.ll
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
; CHECK: @jl_fvar_idxs = hidden constant [1 x i32] zeroinitializer
; CHECK: @jl_gvar_idxs = hidden constant [0 x i32] zeroinitializer
; OPAQUE: @subtarget_cloned_gv = hidden global ptr null
; OPAQUE: @subtarget_cloned.reloc_slot = hidden global ptr null
; OPAQUE: @subtarget_cloned.reloc_slot = hidden global ptr @subtarget_cloned.autoinit_trampoline
; CHECK: @jl_fvar_count = hidden constant i64 1
; OPAQUE: @jl_fvar_ptrs = hidden global [1 x ptr] [ptr @subtarget_cloned]
; CHECK: @jl_clone_slots = hidden constant [5 x i32]
Expand Down Expand Up @@ -57,7 +57,7 @@ define noundef i32 @subtarget_cloned(i32 noundef %0) #2 {
; COM: should fixup this callsite since 2 is cloned for a subtarget
; CHECK: define{{.*}}@call_subtarget_cloned({{.*}}#[[CALL_SUBTARGET_CLONED_DEFAULT_ATTRS:[0-9]+]]
; CHECK-NEXT: [[FUNC_PTR:%[0-9]+]] = load{{.*}}@subtarget_cloned.reloc_slot{{.*}}!tbaa ![[TBAA_CONST_METADATA:[0-9]+]], !invariant.load
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]({{.*}})
; CHECK: ret i32
define noundef i32 @call_subtarget_cloned(i32 noundef %0) #3 {
%2 = call noundef i32 @subtarget_cloned(i32 noundef %0)
Expand All @@ -66,13 +66,23 @@ define noundef i32 @call_subtarget_cloned(i32 noundef %0) #3 {

; CHECK: define{{.*}}@call_subtarget_cloned_but_not_cloned({{.*}}#[[BORING_DEFAULT_ATTRS]]
; CHECK-NEXT: [[FUNC_PTR:%[0-9]+]] = load{{.*}}@subtarget_cloned.reloc_slot{{.*}}!tbaa ![[TBAA_CONST_METADATA]], !invariant.load
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]({{.*}})
; CHECK: ret i32
define noundef i32 @call_subtarget_cloned_but_not_cloned(i32 noundef %0) #0 {
%2 = call noundef i32 @subtarget_cloned(i32 noundef %0)
ret i32 %2
}

; COM: check that the autoinit trampoline is generated correctly
; CHECK: define{{.*}}@subtarget_cloned.autoinit_trampoline({{.*}}
; CHECK-NEXT: top:
; CHECK-NEXT: call ptr @ijl_autoinit_and_adopt_thread()
; CHECK-NEXT: [[FUNC_PTR:%[0-9]+]] = load ptr, ptr @subtarget_cloned.reloc_slot{{.*}}!tbaa ![[TBAA_CONST_METADATA]], !invariant.load
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]({{.*}})
; CHECK: ret i32

declare ptr @ijl_autoinit_and_adopt_thread()

; CHECK: define{{.*}}@boring.1({{.*}}#[[BORING_CLONEALL_ATTRS:[0-9]+]]
; CHECK-NEXT: ret i32 %0

Expand Down Expand Up @@ -106,10 +116,10 @@ define noundef i32 @call_subtarget_cloned_but_not_cloned(i32 noundef %0) #0 {
; CHECK-NOT: @subtarget_cloned_but_not_cloned.2

; COM: check for alias being rewritten to a function trampoline
; CHECK: define{{.*}}@subtarget_cloned_aliased{{.*}}#[[SUBTARGET_ALIASED_ATTRS:[0-9]+]]
; CHECK: define{{.*}}@subtarget_cloned_aliased{{[^.]*}}#[[SUBTARGET_ALIASED_ATTRS:[0-9]+]]
; CHECK-NOT: }
; CHECK: [[FUNC_PTR:%[0-9]+]] = load{{.*}}@subtarget_cloned.reloc_slot{{.*}}!tbaa ![[TBAA_CONST_METADATA]], !invariant.load
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]
; CHECK-NEXT: call{{.*}}[[FUNC_PTR]]({{.*}})
; CHECK: ret i32

; CHECK: attributes #[[BORING_DEFAULT_ATTRS]]
Expand Down
2 changes: 1 addition & 1 deletion test/llvmpasses/multiversioning-x86.ll
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
; OPAQUE: @jl_gvar_ptrs = global [0 x ptr] zeroinitializer, align 8
; CHECK: @jl_fvar_idxs = hidden constant [5 x i32] [i32 0, i32 1, i32 2, i32 3, i32 4], align 8
; CHECK: @jl_gvar_idxs = hidden constant [0 x i32] zeroinitializer, align 8
; OPAQUE: @simd_test.reloc_slot = hidden global ptr null
; OPAQUE: @simd_test.reloc_slot = hidden global ptr @simd_test.autoinit_trampoline
; OPAQUE: @jl_fvar_ptrs = hidden global [5 x ptr] [ptr @boring, ptr @fastmath_test, ptr @loop_test, ptr @simd_test, ptr @simd_test_call]
; OPAQUE: @jl_clone_slots = hidden constant [3 x i32] [i32 1, i32 3, i32 trunc (i64 sub (i64 ptrtoint (ptr @simd_test.reloc_slot to i64), i64 ptrtoint (ptr @jl_clone_slots to i64)) to i32)]
; CHECK: @jl_clone_idxs = hidden constant [10 x i32] [i32 -2147483647, i32 3, i32 -2147483647, i32 3, i32 4, i32 1, i32 1, i32 2, i32 -2147483645, i32 4]
Expand Down
Loading