From 628209c1f2f746e3fc21ccd7cb34e67289403d44 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 5 Oct 2021 16:14:00 -0400 Subject: [PATCH] separate codegen/LLVM from julia runtime (#41936) separate libjulia-internal and libjulia-codegen makes codegen optional via a plugin interface Add special `@` character to `LOADER_BUILD_DEP_LIBS` and friends This allows us to mark a library as `"special"` so that the loader doesn't attempt to open it blindly, but rather interprets it as a list of positional arguments, that it knows how to interpret. We strictly require exactly the number of special libraries, to help avoid errors in the future as we add to this list. Strip windows runtime symbols from the windows import library Without stripping these symbols out of the import library, we end up with duplicate symbol definition errors. Co-authored-by: Julian Samaroo Co-authored-by: Elliot Saba --- Make.inc | 20 +- Makefile | 4 +- NEWS.md | 4 + cli/jl_exports.h | 40 ++- cli/list_strip_symbols.h | 4 +- cli/loader.h | 5 +- cli/loader_lib.c | 68 +++- cli/trampolines/trampolines_aarch64.S | 5 +- cli/trampolines/trampolines_arm.S | 5 +- cli/trampolines/trampolines_i686.S | 5 +- cli/trampolines/trampolines_powerpc64le.S | 3 +- cli/trampolines/trampolines_x86_64.S | 5 +- src/Makefile | 94 +++-- src/anticodegen.c | 65 ---- src/aotcompile.cpp | 34 +- src/ast.c | 402 ++++++++++++---------- src/builtin_proto.h | 11 +- src/builtins.c | 18 +- src/ccall.cpp | 6 +- src/cgutils.cpp | 2 +- src/codegen-stubs.c | 104 ++++++ src/codegen.cpp | 288 ++++++++++------ src/datatype.c | 2 +- src/debuginfo.cpp | 17 +- src/disasm.cpp | 14 +- src/dlload.c | 8 +- src/dump.c | 2 +- src/gc-debug.c | 22 +- src/gc.c | 12 +- src/gc.h | 10 +- src/gf.c | 16 +- src/init.c | 63 +--- src/interpreter.c | 68 ++-- src/intrinsics.cpp | 199 +---------- src/ircode.c | 6 +- src/jitlayers.cpp | 75 ++-- src/jitlayers.h | 2 + src/jl_exported_data.inc | 2 +- src/jl_exported_funcs.inc | 56 ++- src/jlapi.c | 14 + src/jloptions.c | 1 - src/julia.expmap | 2 +- src/julia.h | 15 +- src/julia_internal.h | 247 +++++++------ src/method.c | 76 ++-- src/precompile.c | 2 +- src/processor.cpp | 2 +- src/processor.h | 9 +- src/processor_fallback.cpp | 2 +- src/processor_x86.cpp | 6 +- src/rtutils.c | 14 +- src/runtime_intrinsics.c | 196 +++++++++++ src/safepoint.c | 2 +- src/signal-handling.c | 4 +- src/signals-win.c | 2 +- src/stackwalk.c | 6 +- src/support/Makefile | 2 +- src/support/arraylist.c | 2 +- src/support/arraylist.h | 2 +- src/sys.c | 29 -- src/task.c | 5 +- src/threading.c | 14 +- src/toplevel.c | 98 +++--- src/{support => }/win32_ucontext.c | 0 src/{support => }/win32_ucontext.h | 0 test/compiler/codegen.jl | 7 + 66 files changed, 1411 insertions(+), 1114 deletions(-) delete mode 100644 src/anticodegen.c create mode 100644 src/codegen-stubs.c rename src/{support => }/win32_ucontext.c (100%) rename src/{support => }/win32_ucontext.h (100%) diff --git a/Make.inc b/Make.inc index e7fdc03718bfe..bc7bb7aae64bc 100644 --- a/Make.inc +++ b/Make.inc @@ -935,6 +935,7 @@ OPENBLAS_DYNAMIC_ARCH:=0 OPENBLAS_TARGET_ARCH:=ARMV8 USE_BLAS64:=1 BINARY:=64 +HAVE_SSP:=1 ifeq ($(OS),Darwin) # Apple Chips are all at least A12Z MCPU:=apple-a12 @@ -1500,6 +1501,12 @@ LIBJULIAINTERNAL_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlib LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT)) LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT)) +LIBJULIACODEGEN_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/libjulia-codegen.$(JL_MAJOR_SHLIB_EXT)) +LIBJULIACODEGEN_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/libjulia-codegen.$(JL_MAJOR_SHLIB_EXT)) + +LIBJULIACODEGEN_DEBUG_BUILD_DEPLIB := $(call dep_lib_path,$(build_libdir),$(build_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT)) +LIBJULIACODEGEN_DEBUG_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT)) + ifeq ($(OS),WINNT) ifeq ($(BINARY),32) LIBGCC_NAME := libgcc_s_sjlj-1.$(SHLIB_EXT) @@ -1539,16 +1546,19 @@ LIBM_INSTALL_DEPLIB := $(call dep_lib_path,$(libdir),$(private_shlibdir)/$(LIBMN # We list: # * libgcc_s, because FreeBSD needs to load ours, not the system one. # * libopenlibm, because Windows has an untrustworthy libm, and we want to use ours more than theirs -# * libjulia, which must always come last. +# * libjulia-internal, which must always come second-to-last. +# * libjulia-codegen, which must always come last # # We need these four separate variables because: # * debug builds must link against libjuliadebug, not libjulia # * install time relative paths are not equal to build time relative paths (../lib vs. ../lib/julia) # That second point will no longer be true for most deps once they are placed within Artifacts directories. -LOADER_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBM_BUILD_DEPLIB):$(LIBJULIAINTERNAL_BUILD_DEPLIB) -LOADER_DEBUG_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBM_BUILD_DEPLIB):$(LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB) -LOADER_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBM_INSTALL_DEPLIB):$(LIBJULIAINTERNAL_INSTALL_DEPLIB) -LOADER_DEBUG_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBM_INSTALL_DEPLIB):$(LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB) +# Note that we prefix `libjulia-codegen` and `libjulia-internal` with `@` to signify to the loader that it +# should not automatically dlopen() it in its loading loop. +LOADER_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBM_BUILD_DEPLIB):@$(LIBJULIAINTERNAL_BUILD_DEPLIB):@$(LIBJULIACODEGEN_BUILD_DEPLIB): +LOADER_DEBUG_BUILD_DEP_LIBS = $(LIBGCC_BUILD_DEPLIB):$(LIBM_BUILD_DEPLIB):@$(LIBJULIAINTERNAL_DEBUG_BUILD_DEPLIB):@$(LIBJULIACODEGEN_DEBUG_BUILD_DEPLIB): +LOADER_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBM_INSTALL_DEPLIB):@$(LIBJULIAINTERNAL_INSTALL_DEPLIB):@$(LIBJULIACODEGEN_INSTALL_DEPLIB): +LOADER_DEBUG_INSTALL_DEP_LIBS = $(LIBGCC_INSTALL_DEPLIB):$(LIBM_INSTALL_DEPLIB):@$(LIBJULIAINTERNAL_DEBUG_INSTALL_DEPLIB):@$(LIBJULIACODEGEN_DEBUG_INSTALL_DEPLIB): # Colors for make ifndef VERBOSE diff --git a/Makefile b/Makefile index d2cc6f93c9b81..d0a906e392488 100644 --- a/Makefile +++ b/Makefile @@ -165,9 +165,9 @@ JL_TARGETS += julia-debug endif # private libraries, that are installed in $(prefix)/lib/julia -JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal libblastrampoline +JL_PRIVATE_LIBS-0 := libccalltest libllvmcalltest libjulia-internal libjulia-codegen libblastrampoline ifeq ($(BUNDLE_DEBUG_LIBS),1) -JL_PRIVATE_LIBS-0 += libjulia-internal-debug +JL_PRIVATE_LIBS-0 += libjulia-internal-debug libjulia-codegen-debug endif ifeq ($(USE_GPL_LIBS), 1) JL_PRIVATE_LIBS-$(USE_SYSTEM_LIBSUITESPARSE) += libamd libbtf libcamd libccolamd libcholmod libcolamd libklu libldl librbio libspqr libsuitesparseconfig libumfpack diff --git a/NEWS.md b/NEWS.md index a8473aa026675..48ba0e9d4cb5a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -24,6 +24,10 @@ Language changes Compiler/Runtime improvements ----------------------------- +* The LLVM-based compiler has been separated from the run-time library into a new library, + `libjulia-codegen`. It is loaded by default, so normal usage should see no changes. + In deployments that do not need the compiler (e.g. system images where all needed code + is precompiled), this library (and its LLVM dependency) can simply be excluded ([#41936]). Command-line option changes --------------------------- diff --git a/cli/jl_exports.h b/cli/jl_exports.h index 1221c97c1d676..e9be7c6f2f819 100644 --- a/cli/jl_exports.h +++ b/cli/jl_exports.h @@ -19,37 +19,57 @@ JL_EXPORTED_DATA_SYMBOLS(XX) // Declare list of exported functions (sans type) #define XX(name) JL_DLLEXPORT void name(void); typedef void (anonfunc)(void); -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX // Define holder locations for function addresses as `const void * $(name)_addr = NULL; #define XX(name) JL_HIDDEN anonfunc * name##_addr = NULL; -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX // Generate lists of function names and addresses #define XX(name) "i" #name, -static const char *const jl_exported_func_names[] = { - JL_EXPORTED_FUNCS(XX) +static const char *const jl_runtime_exported_func_names[] = { + JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ - JL_EXPORTED_FUNCS_WIN(XX) + JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif NULL }; #undef XX +#define XX(name) #name"_impl", +static const char *const jl_codegen_exported_func_names[] = { + JL_CODEGEN_EXPORTED_FUNCS(XX) + NULL +}; +#undef XX + +#define XX(name) #name"_fallback", +static const char *const jl_codegen_fallback_func_names[] = { + JL_CODEGEN_EXPORTED_FUNCS(XX) + NULL +}; +#undef XX + #define XX(name) &name##_addr, -static anonfunc **const jl_exported_func_addrs[] = { - JL_EXPORTED_FUNCS(XX) +static anonfunc **const jl_runtime_exported_func_addrs[] = { + JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ - JL_EXPORTED_FUNCS_WIN(XX) + JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif NULL }; +static anonfunc **const jl_codegen_exported_func_addrs[] = { + JL_CODEGEN_EXPORTED_FUNCS(XX) + NULL +}; #undef XX diff --git a/cli/list_strip_symbols.h b/cli/list_strip_symbols.h index 0ea0f7ac9f6ac..5d534616e132b 100644 --- a/cli/list_strip_symbols.h +++ b/cli/list_strip_symbols.h @@ -3,8 +3,8 @@ #include "jl_exported_funcs.inc" #include "trampolines/common.h" #define XX(x) --strip-symbol=CNAME(x) -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif #undef XX diff --git a/cli/loader.h b/cli/loader.h index a69e1ec3e5c5b..70ae8750a6c0a 100644 --- a/cli/loader.h +++ b/cli/loader.h @@ -25,9 +25,12 @@ #include #ifdef _OS_WINDOWS_ + #define WIN32_LEAN_AND_MEAN #include + #else + #ifdef _OS_DARWIN_ #include #endif @@ -35,7 +38,6 @@ #include #include #endif - #define _GNU_SOURCE // Need this for `dladdr()` #include #include @@ -44,6 +46,7 @@ #include #include #include + #endif // Borrow definition from `support/dtypes.h` diff --git a/cli/loader_lib.c b/cli/loader_lib.c index a920c752cc55a..abc144c41c159 100644 --- a/cli/loader_lib.c +++ b/cli/loader_lib.c @@ -16,7 +16,7 @@ extern "C" { #endif // Save DEP_LIBS to a variable that is explicitly sized for expansion -static char dep_libs[512] = DEP_LIBS; +static char dep_libs[1024] = DEP_LIBS; JL_DLLEXPORT void jl_loader_print_stderr(const char * msg) { @@ -31,7 +31,7 @@ void jl_loader_print_stderr3(const char * msg1, const char * msg2, const char * } /* Wrapper around dlopen(), with extra relative pathing thrown in*/ -static void * load_library(const char * rel_path, const char * src_dir) { +static void * load_library(const char * rel_path, const char * src_dir, int err) { void * handle = NULL; // See if a handle is already open to the basename @@ -65,6 +65,8 @@ static void * load_library(const char * rel_path, const char * src_dir) { #endif if (handle == NULL) { + if (!err) + return NULL; jl_loader_print_stderr3("ERROR: Unable to load dependent library ", path, "\n"); #if defined(_OS_WINDOWS_) LPWSTR wmsg = TEXT(""); @@ -157,31 +159,75 @@ __attribute__((constructor)) void jl_load_libjulia_internal(void) { // Pre-load libraries that libjulia-internal needs. int deps_len = strlen(dep_libs); char * curr_dep = &dep_libs[0]; + + // We keep track of "special" libraries names (ones whose name is prefixed with `@`) + // which are libraries that we want to load in some special, custom way, such as + // `libjulia-internal` or `libjulia-codegen`. + int special_idx = 0; + char * special_library_names[2] = {NULL}; while (1) { - // try to find next colon character, if we can't, escape out. + // try to find next colon character; if we can't, break out char * colon = strchr(curr_dep, ':'); if (colon == NULL) break; - // Chop the string at the colon, load this library. + // Chop the string at the colon so it's a valid-ending-string *colon = '\0'; - load_library(curr_dep, lib_dir); + + // If this library name starts with `@`, don't open it here (but mark it as special) + if (curr_dep[0] == '@') { + if (special_idx > sizeof(special_library_names)/sizeof(char *)) { + jl_loader_print_stderr("ERROR: Too many special library names specified, check LOADER_BUILD_DEP_LIBS and friends!\n"); + exit(1); + } + special_library_names[special_idx] = curr_dep + 1; + special_idx += 1; + } else { + load_library(curr_dep, lib_dir, 1); + } // Skip ahead to next dependency curr_dep = colon + 1; } - // Last dependency is `libjulia-internal`, so load that and we're done with `dep_libs`! - libjulia_internal = load_library(curr_dep, lib_dir); + if (special_idx != sizeof(special_library_names)/sizeof(char *)) { + jl_loader_print_stderr("ERROR: Too few special library names specified, check LOADER_BUILD_DEP_LIBS and friends!\n"); + exit(1); + } + + // Unpack our special library names. This is why ordering of library names matters. + libjulia_internal = load_library(special_library_names[0], lib_dir, 1); + void *libjulia_codegen = load_library(special_library_names[1], lib_dir, 0); + const char * const * codegen_func_names; + if (libjulia_codegen == NULL) { + // if codegen is not available, use fallback implementation in libjulia-internal + libjulia_codegen = libjulia_internal; + codegen_func_names = jl_codegen_fallback_func_names; + } + else { + codegen_func_names = jl_codegen_exported_func_names; + } // Once we have libjulia-internal loaded, re-export its symbols: - for (unsigned int symbol_idx=0; jl_exported_func_names[symbol_idx] != NULL; ++symbol_idx) { - void *addr = lookup_symbol(libjulia_internal, jl_exported_func_names[symbol_idx]); + for (unsigned int symbol_idx=0; jl_runtime_exported_func_names[symbol_idx] != NULL; ++symbol_idx) { + void *addr = lookup_symbol(libjulia_internal, jl_runtime_exported_func_names[symbol_idx]); + if (addr == NULL) { + jl_loader_print_stderr3("ERROR: Unable to load ", jl_runtime_exported_func_names[symbol_idx], " from libjulia-internal\n"); + exit(1); + } + (*jl_runtime_exported_func_addrs[symbol_idx]) = addr; + } + // jl_options must be initialized very early, in case an embedder sets some + // values there before calling jl_init + ((void (*)())jl_init_options_addr)(); + + for (unsigned int symbol_idx=0; codegen_func_names[symbol_idx] != NULL; ++symbol_idx) { + void *addr = lookup_symbol(libjulia_codegen, codegen_func_names[symbol_idx]); if (addr == NULL) { - jl_loader_print_stderr3("ERROR: Unable to load ", jl_exported_func_names[symbol_idx], " from libjulia-internal\n"); + jl_loader_print_stderr3("ERROR: Unable to load ", codegen_func_names[symbol_idx], " from libjulia-codegen\n"); exit(1); } - (*jl_exported_func_addrs[symbol_idx]) = addr; + (*jl_codegen_exported_func_addrs[symbol_idx]) = addr; } // jl_options must be initialized very early, in case an embedder sets some diff --git a/cli/trampolines/trampolines_aarch64.S b/cli/trampolines/trampolines_aarch64.S index 0e5aaf397c8fa..2d87ae6dcdb1c 100644 --- a/cli/trampolines/trampolines_aarch64.S +++ b/cli/trampolines/trampolines_aarch64.S @@ -13,8 +13,9 @@ CNAME(name)##: SEP \ br x16 SEP \ .cfi_endproc SEP \ -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX diff --git a/cli/trampolines/trampolines_arm.S b/cli/trampolines/trampolines_arm.S index 11ae17a1a75d1..5ce6617f3f04e 100644 --- a/cli/trampolines/trampolines_arm.S +++ b/cli/trampolines/trampolines_arm.S @@ -16,8 +16,9 @@ CONCAT(.L,CNAMEADDR(name))##: ; \ .word CNAMEADDR(name)##-(CONCAT(.L,CNAME(name)) + 8); \ .cfi_endproc; \ -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX diff --git a/cli/trampolines/trampolines_i686.S b/cli/trampolines/trampolines_i686.S index e0bb0ff513922..3d9cacf0ce652 100644 --- a/cli/trampolines/trampolines_i686.S +++ b/cli/trampolines/trampolines_i686.S @@ -14,8 +14,9 @@ CNAME(name)##:; \ .cfi_endproc; \ EXPORT(name); \ -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX diff --git a/cli/trampolines/trampolines_powerpc64le.S b/cli/trampolines/trampolines_powerpc64le.S index ccf40d857b787..8b32ef91d2464 100644 --- a/cli/trampolines/trampolines_powerpc64le.S +++ b/cli/trampolines/trampolines_powerpc64le.S @@ -24,5 +24,6 @@ CNAME(name)##: ; \ .cfi_endproc; \ .size CNAME(name)##,.-CNAME(name)##; \ -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX diff --git a/cli/trampolines/trampolines_x86_64.S b/cli/trampolines/trampolines_x86_64.S index c00b7c764f699..3b800da56eee1 100644 --- a/cli/trampolines/trampolines_x86_64.S +++ b/cli/trampolines/trampolines_x86_64.S @@ -18,8 +18,9 @@ SEH_END(); \ .cfi_endproc; \ EXPORT(name); \ -JL_EXPORTED_FUNCS(XX) +JL_RUNTIME_EXPORTED_FUNCS(XX) #ifdef _OS_WINDOWS_ -JL_EXPORTED_FUNCS_WIN(XX) +JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) #endif +JL_CODEGEN_EXPORTED_FUNCS(XX) #undef XX diff --git a/src/Makefile b/src/Makefile index bb9064029e8eb..f91e8ae10c70c 100644 --- a/src/Makefile +++ b/src/Makefile @@ -28,6 +28,10 @@ endif JCFLAGS += -Wold-style-definition -Wstrict-prototypes -Wc++-compat endif +ifeq ($(USECLANG),1) +FLAGS += -Wno-return-type-c-linkage +endif + FLAGS += -DJL_BUILD_ARCH='"$(ARCH)"' ifeq ($(OS),WINNT) FLAGS += -DJL_BUILD_UNAME='"NT"' @@ -45,22 +49,26 @@ RUNTIME_SRCS := \ simplevector runtime_intrinsics precompile \ threading partr stackwalk gc gc-debug gc-pages gc-stacks method \ jlapi signal-handling safepoint timing subtype \ - crc32c APInt-C processor ircode opaque_closure + crc32c APInt-C processor ircode opaque_closure codegen-stubs SRCS := jloptions runtime_ccall rtutils +ifeq ($(OS),WINNT) +SRCS += win32_ucontext +endif -LLVMLINK := +RT_LLVMLINK := +CG_LLVMLINK := ifeq ($(JULIACODEGEN),LLVM) -SRCS += codegen llvm-ptls -RUNTIME_SRCS += jitlayers aotcompile debuginfo disasm llvm-simdloop llvm-muladd \ +CODEGEN_SRCS := codegen llvm-ptls +RUNTIME_CODEGEN_SRCS := jitlayers aotcompile debuginfo disasm llvm-simdloop llvm-muladd \ llvm-final-gc-lowering llvm-pass-helpers llvm-late-gc-lowering \ llvm-lower-handlers llvm-gc-invariant-verifier llvm-propagate-addrspaces \ llvm-multiversioning llvm-alloc-opt cgmemmgr llvm-remove-addrspaces \ llvm-remove-ni llvm-julia-licm llvm-demote-float16 FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --includedir) -LLVM_LIBS := all +CG_LLVM_LIBS := all ifeq ($(USE_POLLY),1) -LLVMLINK += -lPolly -lPollyISL +CG_LLVMLINK += -lPolly -lPollyISL FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --src-root)/tools/polly/include FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --obj-root)/tools/polly/include FLAGS += -DUSE_POLLY @@ -68,22 +76,25 @@ ifeq ($(USE_POLLY_OPENMP),1) FLAGS += -fopenmp endif ifeq ($(USE_POLLY_ACC),1) -LLVMLINK += -lPollyPPCG -lGPURuntime +CG_LLVMLINK += -lPollyPPCG -lGPURuntime FLAGS += -DUSE_POLLY_ACC FLAGS += -I$(shell $(LLVM_CONFIG_HOST) --src-root)/tools/polly/tools # Required to find GPURuntime/GPUJIT.h endif endif else -RUNTIME_SRCS += anticodegen -LLVM_LIBS := support +# JULIACODEGEN != LLVM endif +RT_LLVM_LIBS := support + ifeq ($(USEMSVC), 1) SRCS += getopt endif SRCS += $(RUNTIME_SRCS) +CODEGEN_SRCS += $(RUNTIME_CODEGEN_SRCS) + ifeq ($(WITH_DTRACE),1) DTRACE_HEADERS := uprobes.h.gen ifneq ($(OS),Darwin) @@ -109,14 +120,14 @@ LLVM_CXXFLAGS := $(shell $(LLVM_CONFIG_HOST) --cxxflags) ifeq ($(JULIACODEGEN),LLVM) ifneq ($(USE_SYSTEM_LLVM),0) -LLVMLINK += $(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --libs --system-libs) +CG_LLVMLINK += $(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --libs --system-libs) # HACK: llvm-config doesn't correctly point to shared libs on all platforms # https://github.com/JuliaLang/julia/issues/29981 else ifneq ($(USE_LLVM_SHLIB),1) -LLVMLINK += $(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --libs $(LLVM_LIBS) --link-static) $($(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null) +CG_LLVMLINK += $(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --libs $(CG_LLVM_LIBS) --link-static) $($(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null) else -LLVMLINK += $(LLVM_LDFLAGS) -lLLVM +CG_LLVMLINK += $(LLVM_LDFLAGS) -lLLVM endif endif ifeq ($(USE_LLVM_SHLIB),1) @@ -124,18 +135,31 @@ FLAGS += -DLLVM_SHLIB endif # USE_LLVM_SHLIB == 1 endif +RT_LLVM_LINK_ARGS := $(shell $(LLVM_CONFIG_HOST) --libs $(RT_LLVM_LIBS) --link-static) +RT_LLVMLINK += $(LLVM_LDFLAGS) $(RT_LLVM_LINK_ARGS) $($(LLVM_LDFLAGS) $(shell $(LLVM_CONFIG_HOST) --system-libs 2> /dev/null) +ifeq ($(OS), WINNT) +RT_LLVMLINK += -luuid -lole32 +endif + CLANG_LDFLAGS := $(LLVM_LDFLAGS) ifeq ($(OS), Darwin) CLANG_LDFLAGS += -Wl,-undefined,dynamic_lookup endif COMMON_LIBPATHS := -L$(build_libdir) -L$(build_shlibdir) -COMMON_LIBS := $(LIBUV) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(LIBUNWIND) $(LLVMLINK) $(OSLIBS) -DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a -ljulia-debug $(COMMON_LIBS) -RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a -ljulia $(COMMON_LIBS) +RT_LIBS := $(LIBUV) $(LIBUTF8PROC) $(NO_WHOLE_ARCHIVE) $(RT_LLVMLINK) $(LIBUNWIND) $(OSLIBS) +CG_LIBS := $(NO_WHOLE_ARCHIVE) $(LIBUV) $(LIBUNWIND) $(CG_LLVMLINK) $(OSLIBS) +RT_DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp-debug.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport-debug.a -ljulia-debug $(RT_LIBS) +CG_DEBUG_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(WHOLE_ARCHIVE) $(CG_LIBS) -ljulia-debug -ljulia-internal-debug +RT_RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(BUILDDIR)/flisp/libflisp.a $(WHOLE_ARCHIVE) $(BUILDDIR)/support/libsupport.a -ljulia $(RT_LIBS) +CG_RELEASE_LIBS := $(COMMON_LIBPATHS) $(WHOLE_ARCHIVE) $(WHOLE_ARCHIVE) $(CG_LIBS) -ljulia -ljulia-internal OBJS := $(SRCS:%=$(BUILDDIR)/%.o) DOBJS := $(SRCS:%=$(BUILDDIR)/%.dbg.obj) + +CODEGEN_OBJS := $(CODEGEN_SRCS:%=$(BUILDDIR)/%.o) +CODEGEN_DOBJS := $(CODEGEN_SRCS:%=$(BUILDDIR)/%.dbg.obj) + DEBUGFLAGS += $(FLAGS) -DLIBRARY_EXPORTS SHIPFLAGS += $(FLAGS) -DLIBRARY_EXPORTS @@ -165,7 +189,7 @@ endif default: $(JULIA_BUILD_MODE) # contains either "debug" or "release" all: debug release -release debug: %: libjulia-internal-% +release debug: %: libjulia-internal-% libjulia-codegen-% $(BUILDDIR): mkdir -p $(BUILDDIR) @@ -238,7 +262,7 @@ endif $(INSTALL_NAME_CMD)libccalltest.$(SHLIB_EXT) $@ $(build_shlibdir)/libllvmcalltest.$(SHLIB_EXT): $(SRCDIR)/llvmcalltest.cpp $(LLVM_CONFIG_ABSOLUTE) - @$(call PRINT_CC, $(CXX) $(LLVM_CXXFLAGS) $(FLAGS) $(CPPFLAGS) $(CXXFLAGS) -O3 $< $(fPIC) -shared -o $@ $(LDFLAGS) $(COMMON_LIBPATHS) $(NO_WHOLE_ARCHIVE) $(LLVMLINK)) -lpthread + @$(call PRINT_CC, $(CXX) $(LLVM_CXXFLAGS) $(FLAGS) $(CPPFLAGS) $(CXXFLAGS) -O3 $< $(fPIC) -shared -o $@ $(LDFLAGS) $(COMMON_LIBPATHS) $(NO_WHOLE_ARCHIVE) $(CG_LLVMLINK)) -lpthread julia_flisp.boot.inc.phony: $(BUILDDIR)/julia_flisp.boot.inc @@ -252,7 +276,7 @@ $(BUILDDIR)/julia_flisp.boot: $(addprefix $(SRCDIR)/,jlfrontend.scm flisp/aliase $(call cygpath_w,$(SRCDIR)/mk_julia_flisp_boot.scm) $(call cygpath_w,$(dir $<)) $(notdir $<) $(call cygpath_w,$@)) # additional dependency links -$(BUILDDIR)/anticodegen.o $(BUILDDIR)/anticodegen.dbg.obj: $(SRCDIR)/intrinsics.h +$(BUILDDIR)/codegen-stubs.o $(BUILDDIR)/codegen-stubs.dbg.obj: $(SRCDIR)/intrinsics.h $(BUILDDIR)/aotcompile.o $(BUILDDIR)/aotcompile.dbg.obj: $(SRCDIR)/jitlayers.h $(SRCDIR)/codegen_shared.h $(BUILDDIR)/ast.o $(BUILDDIR)/ast.dbg.obj: $(BUILDDIR)/julia_flisp.boot.inc $(SRCDIR)/flisp/*.h $(BUILDDIR)/builtins.o $(BUILDDIR)/builtins.dbg.obj: $(SRCDIR)/iddict.c $(SRCDIR)/builtin_proto.h @@ -274,7 +298,7 @@ $(BUILDDIR)/llvm-final-gc-lowering.o $(BUILDDIR)/llvm-final-gc-lowering.dbg.obj: $(BUILDDIR)/llvm-gc-invariant-verifier.o $(BUILDDIR)/llvm-gc-invariant-verifier.dbg.obj: $(SRCDIR)/codegen_shared.h $(BUILDDIR)/llvm-late-gc-lowering.o $(BUILDDIR)/llvm-late-gc-lowering.dbg.obj: $(SRCDIR)/llvm-pass-helpers.h $(BUILDDIR)/llvm-lower-handlers.o $(BUILDDIR)/llvm-lower-handlers.dbg.obj: $(SRCDIR)/codegen_shared.h -$(BUILDDIR)/llvm-multiversioning.o $(BUILDDIR)/llvm-multiversioning.dbg.obj: $(SRCDIR)/codegen_shared.h +$(BUILDDIR)/llvm-multiversioning.o $(BUILDDIR)/llvm-multiversioning.dbg.obj: $(SRCDIR)/codegen_shared.h $(SRCDIR)/processor.h $(BUILDDIR)/llvm-pass-helpers.o $(BUILDDIR)/llvm-pass-helpers.dbg.obj: $(SRCDIR)/llvm-pass-helpers.h $(SRCDIR)/codegen_shared.h $(BUILDDIR)/llvm-ptls.o $(BUILDDIR)/llvm-ptls.dbg.obj: $(SRCDIR)/codegen_shared.h $(BUILDDIR)/processor.o $(BUILDDIR)/processor.dbg.obj: $(addprefix $(SRCDIR)/,processor_*.cpp processor.h features_*.h) @@ -326,13 +350,13 @@ endif $(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT): $(SRCDIR)/julia.expmap $(OBJS) $(BUILDDIR)/flisp/libflisp.a $(BUILDDIR)/support/libsupport.a $(LIBUV) @$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(CXXLDFLAGS) $(SHIPFLAGS) $(OBJS) $(RPATH_LIB) -o $@ \ - $(JLDFLAGS) $(JLIBLDFLAGS) $(RELEASE_LIBS) $(call SONAME_FLAGS,libjulia-internal.$(JL_MAJOR_SHLIB_EXT))) + $(JLDFLAGS) $(JLIBLDFLAGS) $(RT_RELEASE_LIBS) $(call SONAME_FLAGS,libjulia-internal.$(JL_MAJOR_SHLIB_EXT))) @$(INSTALL_NAME_CMD)libjulia-internal.$(SHLIB_EXT) $@ $(DSYMUTIL) $@ $(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(SRCDIR)/julia.expmap $(DOBJS) $(BUILDDIR)/flisp/libflisp-debug.a $(BUILDDIR)/support/libsupport-debug.a $(LIBUV) @$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(CXXLDFLAGS) $(DEBUGFLAGS) $(DOBJS) $(RPATH_LIB) -o $@ \ - $(JLDFLAGS) $(JLIBLDFLAGS) $(DEBUG_LIBS) $(call SONAME_FLAGS,libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT))) + $(JLDFLAGS) $(JLIBLDFLAGS) $(RT_DEBUG_LIBS) $(call SONAME_FLAGS,libjulia-internal-debug.$(JL_MAJOR_SHLIB_EXT))) @$(INSTALL_NAME_CMD)libjulia-internal-debug.$(SHLIB_EXT) $@ $(DSYMUTIL) $@ @@ -350,8 +374,34 @@ libjulia-internal-release: $(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_ libjulia-internal-debug: $(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_MINOR_SHLIB_EXT) libjulia-internal-debug libjulia-internal-release: $(PUBLIC_HEADER_TARGETS) +$(build_shlibdir)/libjulia-codegen.$(JL_MAJOR_MINOR_SHLIB_EXT): $(SRCDIR)/julia.expmap $(CODEGEN_OBJS) $(BUILDDIR)/support/libsupport.a $(build_shlibdir)/libjulia-internal.$(JL_MAJOR_MINOR_SHLIB_EXT) + @$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(CXXLDFLAGS) $(SHIPFLAGS) $(CODEGEN_OBJS) $(RPATH_LIB) -o $@ \ + $(JLDFLAGS) $(JLIBLDFLAGS) $(CG_RELEASE_LIBS) $(call SONAME_FLAGS,libjulia-codegen.$(JL_MAJOR_SHLIB_EXT))) + @$(INSTALL_NAME_CMD)libjulia-codegen.$(SHLIB_EXT) $@ + $(DSYMUTIL) $@ + +$(build_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_MINOR_SHLIB_EXT): $(SRCDIR)/julia.expmap $(CODEGEN_DOBJS) $(BUILDDIR)/support/libsupport-debug.a $(build_shlibdir)/libjulia-internal-debug.$(JL_MAJOR_MINOR_SHLIB_EXT) + @$(call PRINT_LINK, $(CXXLD) $(call IMPLIB_FLAGS,$@) $(JCXXFLAGS) $(CXXLDFLAGS) $(DEBUGFLAGS) $(CODEGEN_DOBJS) $(RPATH_LIB) -o $@ \ + $(JLDFLAGS) $(JLIBLDFLAGS) $(CG_DEBUG_LIBS) $(call SONAME_FLAGS,libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT))) + @$(INSTALL_NAME_CMD)libjulia-codegen-debug.$(SHLIB_EXT) $@ + $(DSYMUTIL) $@ + +ifneq ($(OS), WINNT) +$(build_shlibdir)/libjulia-codegen.$(JL_MAJOR_SHLIB_EXT) $(build_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT): $(build_shlibdir)/libjulia-codegen%.$(JL_MAJOR_SHLIB_EXT): \ + $(build_shlibdir)/libjulia-codegen%.$(JL_MAJOR_MINOR_SHLIB_EXT) + @$(call PRINT_LINK, ln -sf $(notdir $<) $@) +$(build_shlibdir)/libjulia-codegen.$(SHLIB_EXT) $(build_shlibdir)/libjulia-codegen-debug.$(SHLIB_EXT): $(build_shlibdir)/libjulia-codegen%.$(SHLIB_EXT): \ + $(build_shlibdir)/libjulia-codegen%.$(JL_MAJOR_MINOR_SHLIB_EXT) + @$(call PRINT_LINK, ln -sf $(notdir $<) $@) +libjulia-codegen-release: $(build_shlibdir)/libjulia-codegen.$(JL_MAJOR_SHLIB_EXT) $(build_shlibdir)/libjulia-codegen.$(SHLIB_EXT) +libjulia-codegen-debug: $(build_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_SHLIB_EXT) $(build_shlibdir)/libjulia-codegen-debug.$(SHLIB_EXT) +endif +libjulia-codegen-release: $(build_shlibdir)/libjulia-codegen.$(JL_MAJOR_MINOR_SHLIB_EXT) +libjulia-codegen-debug: $(build_shlibdir)/libjulia-codegen-debug.$(JL_MAJOR_MINOR_SHLIB_EXT) +libjulia-codegen-debug libjulia-codegen-release: $(PUBLIC_HEADER_TARGETS) + clean: - -rm -fr $(build_shlibdir)/libjulia-internal* $(build_shlibdir)/libccalltest* $(build_shlibdir)/libllvmcalltest* + -rm -fr $(build_shlibdir)/libjulia-internal* $(build_shlibdir)/libjulia-codegen* $(build_shlibdir)/libccalltest* $(build_shlibdir)/libllvmcalltest* -rm -f $(BUILDDIR)/julia_flisp.boot $(BUILDDIR)/julia_flisp.boot.inc -rm -f $(BUILDDIR)/*.dbg.obj $(BUILDDIR)/*.o $(BUILDDIR)/*.dwo $(BUILDDIR)/*.$(SHLIB_EXT) $(BUILDDIR)/*.a -rm -f $(BUILDDIR)/julia_version.h diff --git a/src/anticodegen.c b/src/anticodegen.c deleted file mode 100644 index df2738b0f67d5..0000000000000 --- a/src/anticodegen.c +++ /dev/null @@ -1,65 +0,0 @@ -// This file is a part of Julia. License is MIT: https://julialang.org/license - -#include "julia.h" -#include "julia_internal.h" - -#include "intrinsics.h" - -#define UNAVAILABLE { jl_errorf("%s: not available in this build of Julia", __func__); } - -void jl_dump_native(const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname, const char *asm_fname, const char *sysimg_data, size_t sysimg_len) UNAVAILABLE -int32_t jl_get_llvm_gv(jl_value_t *p) UNAVAILABLE -void jl_write_malloc_log(void) UNAVAILABLE -void jl_write_coverage_data(void) UNAVAILABLE - -JL_DLLEXPORT void jl_clear_malloc_data(void) UNAVAILABLE -JL_DLLEXPORT int jl_extern_c(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE -JL_DLLEXPORT void *jl_function_ptr(jl_function_t *f, jl_value_t *rt, jl_value_t *argt) UNAVAILABLE -JL_DLLEXPORT jl_value_t *jl_dump_method_asm(jl_method_instance_t *linfo, size_t world, int raw_mc, char getwrapper, const char* asm_variant, const char *debuginfo) UNAVAILABLE -JL_DLLEXPORT const jl_value_t *jl_dump_function_ir(void *f, uint8_t strip_ir_metadata, uint8_t dump_module, const char *debuginfo) UNAVAILABLE -JL_DLLEXPORT void *jl_get_llvmf_defn(jl_method_instance_t *linfo, size_t world, char getwrapper, char optimize, const jl_cgparams_t params) UNAVAILABLE - -JL_DLLEXPORT void *jl_LLVMCreateDisasm(const char *TripleName, void *DisInfo, int TagType, void *GetOpInfo, void *SymbolLookUp) UNAVAILABLE -JL_DLLEXPORT size_t jl_LLVMDisasmInstruction(void *DC, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize) UNAVAILABLE - -int32_t jl_assign_functionID(const char *fname) UNAVAILABLE - -void jl_init_codegen(void) { } - -int jl_getFunctionInfo(jl_frame_t **frames, uintptr_t pointer, int skipC, int noInline) -{ - return 0; -} - -void jl_register_fptrs(uint64_t sysimage_base, const struct _jl_sysimg_fptrs_t *fptrs, - jl_method_instance_t **linfos, size_t n) -{ - (void)sysimage_base; (void)fptrs; (void)linfos; (void)n; -} - -jl_llvm_functions_t jl_compile_linfo(jl_method_instance_t **pli, jl_code_info_t *src, size_t world, const jl_cgparams_t *params) -{ - jl_method_instance_t *li = *pli; - jl_llvm_functions_t decls = {}; - - if (jl_is_method(li->def.method)) { - jl_printf(JL_STDERR, "code missing for "); - jl_static_show(JL_STDERR, (jl_value_t*)li); - jl_printf(JL_STDERR, " : sysimg may not have been built with --compile=all\n"); - } - else { - jl_printf(JL_STDERR, "top level expression cannot be compiled in this build of Julia"); - } - return decls; -} - -jl_value_t *jl_fptr_interpret_call(jl_method_instance_t *lam, jl_value_t **args, uint32_t nargs); -jl_callptr_t jl_generate_fptr(jl_method_instance_t **pli, jl_llvm_functions_t decls, size_t world) -{ - return (jl_callptr_t)&jl_fptr_interpret_call; -} - -JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION(void) -{ - return 0; -} diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index cfe3c562c7a59..425a073def58d 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -96,7 +96,7 @@ typedef struct { } jl_native_code_desc_t; extern "C" JL_DLLEXPORT -void jl_get_function_id(void *native_code, jl_code_instance_t *codeinst, +void jl_get_function_id_impl(void *native_code, jl_code_instance_t *codeinst, int32_t *func_idx, int32_t *specfunc_idx) { jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code; @@ -109,8 +109,8 @@ void jl_get_function_id(void *native_code, jl_code_instance_t *codeinst, } } -extern "C" -int32_t jl_get_llvm_gv(void *native_code, jl_value_t *p) +extern "C" JL_DLLEXPORT +int32_t jl_get_llvm_gv_impl(void *native_code, jl_value_t *p) { // map a jl_value_t memory location to a GlobalVariable jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code; @@ -124,7 +124,7 @@ int32_t jl_get_llvm_gv(void *native_code, jl_value_t *p) } extern "C" JL_DLLEXPORT -Module* jl_get_llvm_module(void *native_code) +Module* jl_get_llvm_module_impl(void *native_code) { jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code; if (data) @@ -134,7 +134,7 @@ Module* jl_get_llvm_module(void *native_code) } extern "C" JL_DLLEXPORT -GlobalValue* jl_get_llvm_function(void *native_code, uint32_t idx) +GlobalValue* jl_get_llvm_function_impl(void *native_code, uint32_t idx) { jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code; if (data) @@ -144,7 +144,7 @@ GlobalValue* jl_get_llvm_function(void *native_code, uint32_t idx) } extern "C" JL_DLLEXPORT -LLVMContext* jl_get_llvm_context(void *native_code) +LLVMContext* jl_get_llvm_context_impl(void *native_code) { jl_native_code_desc_t *data = (jl_native_code_desc_t*)native_code; if (data) @@ -267,16 +267,18 @@ static void jl_ci_cache_lookup(const jl_cgparams_t &cgparams, jl_method_instance // all reachable & inferrrable functions. The `policy` flag switches between the default // mode `0`, the extern mode `1`, and imaging mode `2`. extern "C" JL_DLLEXPORT -void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _policy) +void *jl_create_native_impl(jl_array_t *methods, const jl_cgparams_t *cgparams, int _policy) { + if (cgparams == NULL) + cgparams = &jl_default_cgparams; jl_native_code_desc_t *data = new jl_native_code_desc_t; jl_codegen_params_t params; - params.params = &cgparams; + params.params = cgparams; std::map emitted; jl_method_instance_t *mi = NULL; jl_code_info_t *src = NULL; JL_GC_PUSH1(&src); - JL_LOCK(&codegen_lock); + JL_LOCK(&jl_codegen_lock); uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -314,7 +316,7 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _p if (mi->def.method->primary_world <= params.world && params.world <= mi->def.method->deleted_world) { // find and prepare the source code to compile jl_code_instance_t *codeinst = NULL; - jl_ci_cache_lookup(cgparams, mi, params.world, &codeinst, &src); + jl_ci_cache_lookup(*cgparams, mi, params.world, &codeinst, &src); if (src && !emitted.count(codeinst)) { // now add it to our compilation results JL_GC_PROMISE_ROOTED(codeinst->rettype); @@ -411,7 +413,7 @@ void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int _p jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); if (policy == CompilationPolicy::ImagingMode) imaging_mode = 0; - JL_UNLOCK(&codegen_lock); // Might GC + JL_UNLOCK(&jl_codegen_lock); // Might GC return (void*)data; } @@ -441,8 +443,8 @@ static void reportWriterError(const ErrorInfoBase &E) // takes the running content that has collected in the shadow module and dump it to disk // this builds the object file portion of the sysimage files for fast startup -extern "C" -void jl_dump_native(void *native_code, +extern "C" JL_DLLEXPORT +void jl_dump_native_impl(void *native_code, const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname, const char *asm_fname, const char *sysimg_data, size_t sysimg_len) @@ -859,7 +861,7 @@ void jl_add_optimization_passes(LLVMPassManagerRef PM, int opt_level, int lower_ // this is paired with jl_dump_function_ir, jl_dump_function_asm, jl_dump_method_asm in particular ways: // misuse will leak memory or cause read-after-free extern "C" JL_DLLEXPORT -void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper, char optimize, const jl_cgparams_t params) +void *jl_get_llvmf_defn_impl(jl_method_instance_t *mi, size_t world, char getwrapper, char optimize, const jl_cgparams_t params) { if (jl_is_method(mi->def.method) && mi->def.method->source == NULL && mi->def.method->generator == NULL) { @@ -906,7 +908,7 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper, output.params = ¶ms; std::unique_ptr m; jl_llvm_functions_t decls; - JL_LOCK(&codegen_lock); + JL_LOCK(&jl_codegen_lock); uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -936,7 +938,7 @@ void *jl_get_llvmf_defn(jl_method_instance_t *mi, size_t world, char getwrapper, JL_GC_POP(); if (measure_compile_time_enabled) jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); - JL_UNLOCK(&codegen_lock); // Might GC + JL_UNLOCK(&jl_codegen_lock); // Might GC if (F) return F; } diff --git a/src/ast.c b/src/ast.c index 7f720b80cf90f..e52a3d8e80143 100644 --- a/src/ast.c +++ b/src/ast.c @@ -27,57 +27,95 @@ extern "C" { // head symbols for each expression type -jl_sym_t *call_sym; jl_sym_t *invoke_sym; -jl_sym_t *invoke_modify_sym; -jl_sym_t *empty_sym; jl_sym_t *top_sym; -jl_sym_t *module_sym; jl_sym_t *slot_sym; -jl_sym_t *export_sym; jl_sym_t *import_sym; -jl_sym_t *toplevel_sym; jl_sym_t *quote_sym; -jl_sym_t *line_sym; jl_sym_t *incomplete_sym; -jl_sym_t *goto_sym; jl_sym_t *goto_ifnot_sym; -jl_sym_t *return_sym; jl_sym_t *lineinfo_sym; -jl_sym_t *lambda_sym; jl_sym_t *assign_sym; -jl_sym_t *globalref_sym; jl_sym_t *do_sym; -jl_sym_t *method_sym; jl_sym_t *core_sym; -jl_sym_t *enter_sym; jl_sym_t *leave_sym; -jl_sym_t *pop_exception_sym; -jl_sym_t *exc_sym; jl_sym_t *error_sym; -jl_sym_t *new_sym; jl_sym_t *using_sym; -jl_sym_t *splatnew_sym; jl_sym_t *block_sym; -jl_sym_t *new_opaque_closure_sym; -jl_sym_t *opaque_closure_method_sym; -jl_sym_t *const_sym; jl_sym_t *thunk_sym; -jl_sym_t *foreigncall_sym; jl_sym_t *as_sym; -jl_sym_t *global_sym; jl_sym_t *list_sym; -jl_sym_t *dot_sym; jl_sym_t *newvar_sym; -jl_sym_t *boundscheck_sym; jl_sym_t *inbounds_sym; -jl_sym_t *copyast_sym; jl_sym_t *cfunction_sym; -jl_sym_t *pure_sym; jl_sym_t *loopinfo_sym; -jl_sym_t *meta_sym; jl_sym_t *inert_sym; -jl_sym_t *polly_sym; jl_sym_t *unused_sym; -jl_sym_t *static_parameter_sym; jl_sym_t *inline_sym; -jl_sym_t *noinline_sym; jl_sym_t *generated_sym; -jl_sym_t *generated_only_sym; jl_sym_t *isdefined_sym; -jl_sym_t *propagate_inbounds_sym; jl_sym_t *specialize_sym; -jl_sym_t *aggressive_constprop_sym; jl_sym_t *no_constprop_sym; -jl_sym_t *nospecialize_sym; jl_sym_t *macrocall_sym; -jl_sym_t *colon_sym; jl_sym_t *hygienicscope_sym; -jl_sym_t *throw_undef_if_not_sym; jl_sym_t *getfield_undefref_sym; -jl_sym_t *gc_preserve_begin_sym; jl_sym_t *gc_preserve_end_sym; -jl_sym_t *coverageeffect_sym; jl_sym_t *escape_sym; -jl_sym_t *aliasscope_sym; jl_sym_t *popaliasscope_sym; -jl_sym_t *optlevel_sym; jl_sym_t *thismodule_sym; -jl_sym_t *atom_sym; jl_sym_t *statement_sym; jl_sym_t *all_sym; -jl_sym_t *compile_sym; jl_sym_t *infer_sym; - -jl_sym_t *atomic_sym; -jl_sym_t *not_atomic_sym; -jl_sym_t *unordered_sym; -jl_sym_t *monotonic_sym; -jl_sym_t *acquire_sym; -jl_sym_t *release_sym; -jl_sym_t *acquire_release_sym; -jl_sym_t *sequentially_consistent_sym; +JL_DLLEXPORT jl_sym_t *jl_call_sym; +JL_DLLEXPORT jl_sym_t *jl_invoke_sym; +JL_DLLEXPORT jl_sym_t *jl_invoke_modify_sym; +JL_DLLEXPORT jl_sym_t *jl_empty_sym; +JL_DLLEXPORT jl_sym_t *jl_top_sym; +JL_DLLEXPORT jl_sym_t *jl_module_sym; +JL_DLLEXPORT jl_sym_t *jl_slot_sym; +JL_DLLEXPORT jl_sym_t *jl_export_sym; +JL_DLLEXPORT jl_sym_t *jl_import_sym; +JL_DLLEXPORT jl_sym_t *jl_toplevel_sym; +JL_DLLEXPORT jl_sym_t *jl_quote_sym; +JL_DLLEXPORT jl_sym_t *jl_line_sym; +JL_DLLEXPORT jl_sym_t *jl_incomplete_sym; +JL_DLLEXPORT jl_sym_t *jl_goto_sym; +JL_DLLEXPORT jl_sym_t *jl_goto_ifnot_sym; +JL_DLLEXPORT jl_sym_t *jl_return_sym; +JL_DLLEXPORT jl_sym_t *jl_lineinfo_sym; +JL_DLLEXPORT jl_sym_t *jl_lambda_sym; +JL_DLLEXPORT jl_sym_t *jl_assign_sym; +JL_DLLEXPORT jl_sym_t *jl_globalref_sym; +JL_DLLEXPORT jl_sym_t *jl_do_sym; +JL_DLLEXPORT jl_sym_t *jl_method_sym; +JL_DLLEXPORT jl_sym_t *jl_core_sym; +JL_DLLEXPORT jl_sym_t *jl_enter_sym; +JL_DLLEXPORT jl_sym_t *jl_leave_sym; +JL_DLLEXPORT jl_sym_t *jl_pop_exception_sym; +JL_DLLEXPORT jl_sym_t *jl_exc_sym; +JL_DLLEXPORT jl_sym_t *jl_error_sym; +JL_DLLEXPORT jl_sym_t *jl_new_sym; +JL_DLLEXPORT jl_sym_t *jl_using_sym; +JL_DLLEXPORT jl_sym_t *jl_splatnew_sym; +JL_DLLEXPORT jl_sym_t *jl_block_sym; +JL_DLLEXPORT jl_sym_t *jl_new_opaque_closure_sym; +JL_DLLEXPORT jl_sym_t *jl_opaque_closure_method_sym; +JL_DLLEXPORT jl_sym_t *jl_const_sym; +JL_DLLEXPORT jl_sym_t *jl_thunk_sym; +JL_DLLEXPORT jl_sym_t *jl_foreigncall_sym; +JL_DLLEXPORT jl_sym_t *jl_as_sym; +JL_DLLEXPORT jl_sym_t *jl_global_sym; +JL_DLLEXPORT jl_sym_t *jl_list_sym; +JL_DLLEXPORT jl_sym_t *jl_dot_sym; +JL_DLLEXPORT jl_sym_t *jl_newvar_sym; +JL_DLLEXPORT jl_sym_t *jl_boundscheck_sym; +JL_DLLEXPORT jl_sym_t *jl_inbounds_sym; +JL_DLLEXPORT jl_sym_t *jl_copyast_sym; +JL_DLLEXPORT jl_sym_t *jl_cfunction_sym; +JL_DLLEXPORT jl_sym_t *jl_pure_sym; +JL_DLLEXPORT jl_sym_t *jl_loopinfo_sym; +JL_DLLEXPORT jl_sym_t *jl_meta_sym; +JL_DLLEXPORT jl_sym_t *jl_inert_sym; +JL_DLLEXPORT jl_sym_t *jl_polly_sym; +JL_DLLEXPORT jl_sym_t *jl_unused_sym; +JL_DLLEXPORT jl_sym_t *jl_static_parameter_sym; +JL_DLLEXPORT jl_sym_t *jl_inline_sym; +JL_DLLEXPORT jl_sym_t *jl_noinline_sym; +JL_DLLEXPORT jl_sym_t *jl_generated_sym; +JL_DLLEXPORT jl_sym_t *jl_generated_only_sym; +JL_DLLEXPORT jl_sym_t *jl_isdefined_sym; +JL_DLLEXPORT jl_sym_t *jl_propagate_inbounds_sym; +JL_DLLEXPORT jl_sym_t *jl_specialize_sym; +JL_DLLEXPORT jl_sym_t *jl_aggressive_constprop_sym; +JL_DLLEXPORT jl_sym_t *jl_no_constprop_sym; +JL_DLLEXPORT jl_sym_t *jl_nospecialize_sym; +JL_DLLEXPORT jl_sym_t *jl_macrocall_sym; +JL_DLLEXPORT jl_sym_t *jl_colon_sym; +JL_DLLEXPORT jl_sym_t *jl_hygienicscope_sym; +JL_DLLEXPORT jl_sym_t *jl_throw_undef_if_not_sym; +JL_DLLEXPORT jl_sym_t *jl_getfield_undefref_sym; +JL_DLLEXPORT jl_sym_t *jl_gc_preserve_begin_sym; +JL_DLLEXPORT jl_sym_t *jl_gc_preserve_end_sym; +JL_DLLEXPORT jl_sym_t *jl_coverageeffect_sym; +JL_DLLEXPORT jl_sym_t *jl_escape_sym; +JL_DLLEXPORT jl_sym_t *jl_aliasscope_sym; +JL_DLLEXPORT jl_sym_t *jl_popaliasscope_sym; +JL_DLLEXPORT jl_sym_t *jl_optlevel_sym; +JL_DLLEXPORT jl_sym_t *jl_thismodule_sym; +JL_DLLEXPORT jl_sym_t *jl_atom_sym; +JL_DLLEXPORT jl_sym_t *jl_statement_sym; +JL_DLLEXPORT jl_sym_t *jl_all_sym; +JL_DLLEXPORT jl_sym_t *jl_compile_sym; +JL_DLLEXPORT jl_sym_t *jl_infer_sym; +JL_DLLEXPORT jl_sym_t *jl_atomic_sym; +JL_DLLEXPORT jl_sym_t *jl_not_atomic_sym; +JL_DLLEXPORT jl_sym_t *jl_unordered_sym; +JL_DLLEXPORT jl_sym_t *jl_monotonic_sym; +JL_DLLEXPORT jl_sym_t *jl_acquire_sym; +JL_DLLEXPORT jl_sym_t *jl_release_sym; +JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; +JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; static uint8_t flisp_system_image[] = { @@ -343,95 +381,95 @@ void jl_init_flisp(void) void jl_init_common_symbols(void) { - empty_sym = jl_symbol(""); - call_sym = jl_symbol("call"); - invoke_sym = jl_symbol("invoke"); - invoke_modify_sym = jl_symbol("invoke_modify"); - foreigncall_sym = jl_symbol("foreigncall"); - cfunction_sym = jl_symbol("cfunction"); - quote_sym = jl_symbol("quote"); - inert_sym = jl_symbol("inert"); - top_sym = jl_symbol("top"); - core_sym = jl_symbol("core"); - globalref_sym = jl_symbol("globalref"); - line_sym = jl_symbol("line"); - lineinfo_sym = jl_symbol("lineinfo"); - incomplete_sym = jl_symbol("incomplete"); - error_sym = jl_symbol("error"); - goto_sym = jl_symbol("goto"); - goto_ifnot_sym = jl_symbol("gotoifnot"); - return_sym = jl_symbol("return"); - lambda_sym = jl_symbol("lambda"); - module_sym = jl_symbol("module"); - export_sym = jl_symbol("export"); - import_sym = jl_symbol("import"); - using_sym = jl_symbol("using"); - assign_sym = jl_symbol("="); - method_sym = jl_symbol("method"); - exc_sym = jl_symbol("the_exception"); - enter_sym = jl_symbol("enter"); - leave_sym = jl_symbol("leave"); - pop_exception_sym = jl_symbol("pop_exception"); - new_sym = jl_symbol("new"); - splatnew_sym = jl_symbol("splatnew"); - new_opaque_closure_sym = jl_symbol("new_opaque_closure"); - opaque_closure_method_sym = jl_symbol("opaque_closure_method"); - const_sym = jl_symbol("const"); - global_sym = jl_symbol("global"); - thunk_sym = jl_symbol("thunk"); - toplevel_sym = jl_symbol("toplevel"); - dot_sym = jl_symbol("."); - as_sym = jl_symbol("as"); - colon_sym = jl_symbol(":"); - boundscheck_sym = jl_symbol("boundscheck"); - inbounds_sym = jl_symbol("inbounds"); - newvar_sym = jl_symbol("newvar"); - copyast_sym = jl_symbol("copyast"); - loopinfo_sym = jl_symbol("loopinfo"); - pure_sym = jl_symbol("pure"); - meta_sym = jl_symbol("meta"); - list_sym = jl_symbol("list"); - unused_sym = jl_symbol("#unused#"); - slot_sym = jl_symbol("slot"); - static_parameter_sym = jl_symbol("static_parameter"); - inline_sym = jl_symbol("inline"); - noinline_sym = jl_symbol("noinline"); - polly_sym = jl_symbol("polly"); - propagate_inbounds_sym = jl_symbol("propagate_inbounds"); - aggressive_constprop_sym = jl_symbol("aggressive_constprop"); - no_constprop_sym = jl_symbol("no_constprop"); - isdefined_sym = jl_symbol("isdefined"); - nospecialize_sym = jl_symbol("nospecialize"); - specialize_sym = jl_symbol("specialize"); - optlevel_sym = jl_symbol("optlevel"); - compile_sym = jl_symbol("compile"); - infer_sym = jl_symbol("infer"); - macrocall_sym = jl_symbol("macrocall"); - escape_sym = jl_symbol("escape"); - hygienicscope_sym = jl_symbol("hygienic-scope"); - gc_preserve_begin_sym = jl_symbol("gc_preserve_begin"); - gc_preserve_end_sym = jl_symbol("gc_preserve_end"); - generated_sym = jl_symbol("generated"); - generated_only_sym = jl_symbol("generated_only"); - throw_undef_if_not_sym = jl_symbol("throw_undef_if_not"); - getfield_undefref_sym = jl_symbol("##getfield##"); - do_sym = jl_symbol("do"); - coverageeffect_sym = jl_symbol("code_coverage_effect"); - aliasscope_sym = jl_symbol("aliasscope"); - popaliasscope_sym = jl_symbol("popaliasscope"); - thismodule_sym = jl_symbol("thismodule"); - block_sym = jl_symbol("block"); - atom_sym = jl_symbol("atom"); - statement_sym = jl_symbol("statement"); - all_sym = jl_symbol("all"); - atomic_sym = jl_symbol("atomic"); - not_atomic_sym = jl_symbol("not_atomic"); - unordered_sym = jl_symbol("unordered"); - monotonic_sym = jl_symbol("monotonic"); - acquire_sym = jl_symbol("acquire"); - release_sym = jl_symbol("release"); - acquire_release_sym = jl_symbol("acquire_release"); - sequentially_consistent_sym = jl_symbol("sequentially_consistent"); + jl_empty_sym = jl_symbol(""); + jl_call_sym = jl_symbol("call"); + jl_invoke_sym = jl_symbol("invoke"); + jl_invoke_modify_sym = jl_symbol("invoke_modify"); + jl_foreigncall_sym = jl_symbol("foreigncall"); + jl_cfunction_sym = jl_symbol("cfunction"); + jl_quote_sym = jl_symbol("quote"); + jl_inert_sym = jl_symbol("inert"); + jl_top_sym = jl_symbol("top"); + jl_core_sym = jl_symbol("core"); + jl_globalref_sym = jl_symbol("globalref"); + jl_line_sym = jl_symbol("line"); + jl_lineinfo_sym = jl_symbol("lineinfo"); + jl_incomplete_sym = jl_symbol("incomplete"); + jl_error_sym = jl_symbol("error"); + jl_goto_sym = jl_symbol("goto"); + jl_goto_ifnot_sym = jl_symbol("gotoifnot"); + jl_return_sym = jl_symbol("return"); + jl_lambda_sym = jl_symbol("lambda"); + jl_module_sym = jl_symbol("module"); + jl_export_sym = jl_symbol("export"); + jl_import_sym = jl_symbol("import"); + jl_using_sym = jl_symbol("using"); + jl_assign_sym = jl_symbol("="); + jl_method_sym = jl_symbol("method"); + jl_exc_sym = jl_symbol("the_exception"); + jl_enter_sym = jl_symbol("enter"); + jl_leave_sym = jl_symbol("leave"); + jl_pop_exception_sym = jl_symbol("pop_exception"); + jl_new_sym = jl_symbol("new"); + jl_splatnew_sym = jl_symbol("splatnew"); + jl_new_opaque_closure_sym = jl_symbol("new_opaque_closure"); + jl_opaque_closure_method_sym = jl_symbol("opaque_closure_method"); + jl_const_sym = jl_symbol("const"); + jl_global_sym = jl_symbol("global"); + jl_thunk_sym = jl_symbol("thunk"); + jl_toplevel_sym = jl_symbol("toplevel"); + jl_dot_sym = jl_symbol("."); + jl_as_sym = jl_symbol("as"); + jl_colon_sym = jl_symbol(":"); + jl_boundscheck_sym = jl_symbol("boundscheck"); + jl_inbounds_sym = jl_symbol("inbounds"); + jl_newvar_sym = jl_symbol("newvar"); + jl_copyast_sym = jl_symbol("copyast"); + jl_loopinfo_sym = jl_symbol("loopinfo"); + jl_pure_sym = jl_symbol("pure"); + jl_meta_sym = jl_symbol("meta"); + jl_list_sym = jl_symbol("list"); + jl_unused_sym = jl_symbol("#unused#"); + jl_slot_sym = jl_symbol("slot"); + jl_static_parameter_sym = jl_symbol("static_parameter"); + jl_inline_sym = jl_symbol("inline"); + jl_noinline_sym = jl_symbol("noinline"); + jl_polly_sym = jl_symbol("polly"); + jl_propagate_inbounds_sym = jl_symbol("propagate_inbounds"); + jl_aggressive_constprop_sym = jl_symbol("aggressive_constprop"); + jl_no_constprop_sym = jl_symbol("no_constprop"); + jl_isdefined_sym = jl_symbol("isdefined"); + jl_nospecialize_sym = jl_symbol("nospecialize"); + jl_specialize_sym = jl_symbol("specialize"); + jl_optlevel_sym = jl_symbol("optlevel"); + jl_compile_sym = jl_symbol("compile"); + jl_infer_sym = jl_symbol("infer"); + jl_macrocall_sym = jl_symbol("macrocall"); + jl_escape_sym = jl_symbol("escape"); + jl_hygienicscope_sym = jl_symbol("hygienic-scope"); + jl_gc_preserve_begin_sym = jl_symbol("gc_preserve_begin"); + jl_gc_preserve_end_sym = jl_symbol("gc_preserve_end"); + jl_generated_sym = jl_symbol("generated"); + jl_generated_only_sym = jl_symbol("generated_only"); + jl_throw_undef_if_not_sym = jl_symbol("throw_undef_if_not"); + jl_getfield_undefref_sym = jl_symbol("##getfield##"); + jl_do_sym = jl_symbol("do"); + jl_coverageeffect_sym = jl_symbol("code_coverage_effect"); + jl_aliasscope_sym = jl_symbol("aliasscope"); + jl_popaliasscope_sym = jl_symbol("popaliasscope"); + jl_thismodule_sym = jl_symbol("thismodule"); + jl_block_sym = jl_symbol("block"); + jl_atom_sym = jl_symbol("atom"); + jl_statement_sym = jl_symbol("statement"); + jl_all_sym = jl_symbol("all"); + jl_atomic_sym = jl_symbol("atomic"); + jl_not_atomic_sym = jl_symbol("not_atomic"); + jl_unordered_sym = jl_symbol("unordered"); + jl_monotonic_sym = jl_symbol("monotonic"); + jl_acquire_sym = jl_symbol("acquire"); + jl_release_sym = jl_symbol("release"); + jl_acquire_release_sym = jl_symbol("acquire_release"); + jl_sequentially_consistent_sym = jl_symbol("sequentially_consistent"); } JL_DLLEXPORT void jl_lisp_prompt(void) @@ -495,7 +533,7 @@ static jl_value_t *scm_to_julia(fl_context_t *fl_ctx, value_t e, jl_module_t *mo } JL_CATCH { // if expression cannot be converted, replace with error expr - jl_expr_t *ex = jl_exprn(error_sym, 1); + jl_expr_t *ex = jl_exprn(jl_error_sym, 1); v = (jl_value_t*)ex; jl_array_ptr_set(ex->args, 0, jl_cstr_to_string("invalid AST")); } @@ -569,7 +607,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m if (issymbol(hd)) sym = scmsym_to_julia(fl_ctx, hd); else - sym = list_sym; + sym = jl_list_sym; size_t n = llength(e)-1; if (issymbol(hd)) e = cdr_(e); @@ -577,7 +615,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m n++; // nodes with special representations jl_value_t *ex = NULL, *temp = NULL; - if (sym == line_sym && (n == 1 || n == 2)) { + if (sym == jl_line_sym && (n == 1 || n == 2)) { jl_value_t *linenum = scm_to_julia_(fl_ctx, car_(e), mod); jl_value_t *file = jl_nothing; JL_GC_PUSH2(&linenum, &file); @@ -587,7 +625,7 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m JL_GC_POP(); return temp; } - else if (sym == lineinfo_sym && n == 5) { + else if (sym == jl_lineinfo_sym && n == 5) { jl_value_t *modu=NULL, *name=NULL, *file=NULL, *linenum=NULL, *inlinedat=NULL; JL_GC_PUSH5(&modu, &name, &file, &linenum, &inlinedat); value_t lst = e; @@ -605,41 +643,41 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m return temp; } JL_GC_PUSH2(&ex, &temp); - if (sym == goto_sym) { + if (sym == jl_goto_sym) { ex = scm_to_julia_(fl_ctx, car_(e), mod); temp = jl_new_struct(jl_gotonode_type, ex); } - else if (sym == goto_ifnot_sym) { + else if (sym == jl_goto_ifnot_sym) { ex = scm_to_julia_(fl_ctx, car_(e), mod); temp = scm_to_julia(fl_ctx, car_(cdr_(e)), mod); temp = jl_new_struct(jl_gotoifnot_type, ex, temp); } - else if (sym == newvar_sym) { + else if (sym == jl_newvar_sym) { ex = scm_to_julia_(fl_ctx, car_(e), mod); temp = jl_new_struct(jl_newvarnode_type, ex); } - else if (sym == globalref_sym) { + else if (sym == jl_globalref_sym) { ex = scm_to_julia_(fl_ctx, car_(e), mod); temp = scm_to_julia_(fl_ctx, car_(cdr_(e)), mod); assert(jl_is_module(ex)); assert(jl_is_symbol(temp)); temp = jl_module_globalref((jl_module_t*)ex, (jl_sym_t*)temp); } - else if (sym == top_sym) { + else if (sym == jl_top_sym) { assert(mod && "top should not be generated by the parser"); ex = scm_to_julia_(fl_ctx, car_(e), mod); assert(jl_is_symbol(ex)); temp = jl_module_globalref(jl_base_relative_to(mod), (jl_sym_t*)ex); } - else if (sym == core_sym) { + else if (sym == jl_core_sym) { ex = scm_to_julia_(fl_ctx, car_(e), mod); assert(jl_is_symbol(ex)); temp = jl_module_globalref(jl_core_module, (jl_sym_t*)ex); } - else if (sym == thismodule_sym) { + else if (sym == jl_thismodule_sym) { temp = (jl_value_t*)mod; } - else if (iscons(e) && (sym == inert_sym || (sym == quote_sym && (!iscons(car_(e)))))) { + else if (iscons(e) && (sym == jl_inert_sym || (sym == jl_quote_sym && (!iscons(car_(e)))))) { ex = scm_to_julia_(fl_ctx, car_(e), mod); temp = jl_new_struct(jl_quotenode_type, ex); } @@ -654,10 +692,10 @@ static jl_value_t *scm_to_julia_(fl_context_t *fl_ctx, value_t e, jl_module_t *m jl_array_ptr_set(((jl_expr_t*)ex)->args, i, scm_to_julia_(fl_ctx, car_(e), mod)); e = cdr_(e); } - if (sym == lambda_sym) + if (sym == jl_lambda_sym) ex = (jl_value_t*)jl_new_code_info_from_ir((jl_expr_t*)ex); JL_GC_POP(); - if (sym == list_sym) + if (sym == jl_list_sym) return (jl_value_t*)((jl_expr_t*)ex)->args; return (jl_value_t*)ex; } @@ -781,11 +819,11 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_vali jl_expr_t *ex = (jl_expr_t*)v; value_t args = fl_ctx->NIL; fl_gc_handle(fl_ctx, &args); - if (jl_expr_nargs(ex) > 520000 && ex->head != block_sym) + if (jl_expr_nargs(ex) > 520000 && ex->head != jl_block_sym) lerror(fl_ctx, symbol(fl_ctx, "error"), "expression too large"); array_to_list(fl_ctx, ex->args, &args, check_valid); value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)ex->head, check_valid); - if (ex->head == lambda_sym && jl_expr_nargs(ex)>0 && jl_is_array(jl_exprarg(ex,0))) { + if (ex->head == jl_lambda_sym && jl_expr_nargs(ex)>0 && jl_is_array(jl_exprarg(ex,0))) { value_t llist = fl_ctx->NIL; fl_gc_handle(fl_ctx, &llist); array_to_list(fl_ctx, (jl_array_t*)jl_exprarg(ex,0), &llist, check_valid); @@ -804,26 +842,26 @@ static value_t julia_to_scm_(fl_context_t *fl_ctx, jl_value_t *v, int check_vali jl_value_t *line = jl_fieldref(v,0); value_t args = julia_to_list2_noalloc(fl_ctx, line, file, check_valid); fl_gc_handle(fl_ctx, &args); - value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)line_sym, check_valid); + value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)jl_line_sym, check_valid); value_t scmv = fl_cons(fl_ctx, hd, args); fl_free_gc_handles(fl_ctx, 1); return scmv; } if (jl_typeis(v, jl_gotonode_type)) - return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)goto_sym, jl_fieldref(v,0), check_valid); + return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)jl_goto_sym, jl_fieldref(v,0), check_valid); if (jl_typeis(v, jl_quotenode_type)) - return julia_to_list2(fl_ctx, (jl_value_t*)inert_sym, jl_fieldref_noalloc(v,0), 0); + return julia_to_list2(fl_ctx, (jl_value_t*)jl_inert_sym, jl_fieldref_noalloc(v,0), 0); if (jl_typeis(v, jl_newvarnode_type)) - return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)newvar_sym, jl_fieldref(v,0), check_valid); + return julia_to_list2_noalloc(fl_ctx, (jl_value_t*)jl_newvar_sym, jl_fieldref(v,0), check_valid); if (jl_typeis(v, jl_globalref_type)) { jl_module_t *m = jl_globalref_mod(v); jl_sym_t *sym = jl_globalref_name(v); if (m == jl_core_module) - return julia_to_list2(fl_ctx, (jl_value_t*)core_sym, + return julia_to_list2(fl_ctx, (jl_value_t*)jl_core_sym, (jl_value_t*)sym, check_valid); value_t args = julia_to_list2(fl_ctx, (jl_value_t*)m, (jl_value_t*)sym, check_valid); fl_gc_handle(fl_ctx, &args); - value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)globalref_sym, check_valid); + value_t hd = julia_to_scm_(fl_ctx, (jl_value_t*)jl_globalref_sym, check_valid); value_t scmv = fl_cons(fl_ctx, hd, args); fl_free_gc_handles(fl_ctx, 1); return scmv; @@ -844,10 +882,10 @@ JL_DLLEXPORT jl_value_t *jl_fl_parse(const char *text, size_t text_len, jl_bounds_error(textstr, jl_box_long(offset+1)); } jl_sym_t *rule = (jl_sym_t*)options; - if (rule != atom_sym && rule != statement_sym && rule != all_sym) { + if (rule != jl_atom_sym && rule != jl_statement_sym && rule != jl_all_sym) { jl_error("jl_fl_parse: unrecognized parse options"); } - if (offset != 0 && rule == all_sym) { + if (offset != 0 && rule == jl_all_sym) { jl_error("Parse `all`: offset not supported"); } @@ -860,14 +898,14 @@ JL_DLLEXPORT jl_value_t *jl_fl_parse(const char *text, size_t text_len, fl_gc_handle(fl_ctx, &fl_filename); value_t fl_expr; size_t offset1 = 0; - if (rule == all_sym) { + if (rule == jl_all_sym) { value_t e = fl_applyn(fl_ctx, 2, symbol_value(symbol(fl_ctx, "jl-parse-all")), fl_text, fl_filename); fl_expr = e; offset1 = e == fl_ctx->FL_EOF ? text_len : 0; } else { - value_t greedy = rule == statement_sym ? fl_ctx->T : fl_ctx->F; + value_t greedy = rule == jl_statement_sym ? fl_ctx->T : fl_ctx->F; value_t p = fl_applyn(fl_ctx, 4, symbol_value(symbol(fl_ctx, "jl-parse-one")), fl_text, fl_filename, fixnum(offset), greedy); fl_expr = car_(p); @@ -1045,7 +1083,7 @@ int jl_has_meta(jl_array_t *body, jl_sym_t *sym) JL_NOTSAFEPOINT size_t i, l = jl_array_len(body); for (i = 0; i < l; i++) { jl_expr_t *stmt = (jl_expr_t*)jl_array_ptr_ref(body, i); - if (jl_is_expr((jl_value_t*)stmt) && stmt->head == meta_sym) { + if (jl_is_expr((jl_value_t*)stmt) && stmt->head == jl_meta_sym) { size_t i, l = jl_array_len(stmt->args); for (i = 0; i < l; i++) if (jl_array_ptr_ref(stmt->args, i) == (jl_value_t*)sym) @@ -1115,20 +1153,20 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str if (!expr || !jl_is_expr(expr)) return expr; jl_expr_t *e = (jl_expr_t*)expr; - if (e->head == inert_sym || - e->head == module_sym || - //e->head == toplevel_sym || // TODO: enable this once julia-expand-macroscope is fixed / removed - e->head == meta_sym) { + if (e->head == jl_inert_sym || + e->head == jl_module_sym || + //e->head == jl_toplevel_sym || // TODO: enable this once julia-expand-macroscope is fixed / removed + e->head == jl_meta_sym) { return expr; } - if (e->head == quote_sym && jl_expr_nargs(e) == 1) { + if (e->head == jl_quote_sym && jl_expr_nargs(e) == 1) { expr = jl_call_scm_on_ast("julia-bq-macro", jl_exprarg(e, 0), inmodule); JL_GC_PUSH1(&expr); expr = jl_expand_macros(expr, inmodule, macroctx, onelevel, world, throw_load_error); JL_GC_POP(); return expr; } - if (e->head == hygienicscope_sym && jl_expr_nargs(e) == 2) { + if (e->head == jl_hygienicscope_sym && jl_expr_nargs(e) == 2) { struct macroctx_stack newctx; newctx.m = (jl_module_t*)jl_exprarg(e, 1); JL_TYPECHK(hygienic-scope, module, (jl_value_t*)newctx.m); @@ -1139,7 +1177,7 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str jl_array_ptr_set(e->args, 0, a2); return expr; } - if (e->head == macrocall_sym) { + if (e->head == jl_macrocall_sym) { struct macroctx_stack newctx; newctx.m = macroctx ? macroctx->m : inmodule; newctx.parent = macroctx; @@ -1147,10 +1185,10 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str jl_value_t *wrap = NULL; JL_GC_PUSH3(&result, &wrap, &newctx.m); // copy and wrap the result in `(hygienic-scope ,result ,newctx) - if (jl_is_expr(result) && ((jl_expr_t*)result)->head == escape_sym) + if (jl_is_expr(result) && ((jl_expr_t*)result)->head == jl_escape_sym) result = jl_exprarg(result, 0); else - wrap = (jl_value_t*)jl_exprn(hygienicscope_sym, 2); + wrap = (jl_value_t*)jl_exprn(jl_hygienicscope_sym, 2); result = jl_copy_ast(result); if (!onelevel) result = jl_expand_macros(result, inmodule, wrap ? &newctx : macroctx, onelevel, world, throw_load_error); @@ -1162,11 +1200,11 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str JL_GC_POP(); return result; } - if (e->head == do_sym && jl_expr_nargs(e) == 2 && jl_is_expr(jl_exprarg(e, 0)) && - ((jl_expr_t*)jl_exprarg(e, 0))->head == macrocall_sym) { + if (e->head == jl_do_sym && jl_expr_nargs(e) == 2 && jl_is_expr(jl_exprarg(e, 0)) && + ((jl_expr_t*)jl_exprarg(e, 0))->head == jl_macrocall_sym) { jl_expr_t *mc = (jl_expr_t*)jl_exprarg(e, 0); size_t nm = jl_expr_nargs(mc); - jl_expr_t *mc2 = jl_exprn(macrocall_sym, nm+1); + jl_expr_t *mc2 = jl_exprn(jl_macrocall_sym, nm+1); JL_GC_PUSH1(&mc2); jl_exprargset(mc2, 0, jl_exprarg(mc, 0)); // macro name jl_exprargset(mc2, 1, jl_exprarg(mc, 1)); // location @@ -1179,7 +1217,7 @@ static jl_value_t *jl_expand_macros(jl_value_t *expr, jl_module_t *inmodule, str JL_GC_POP(); return ret; } - if (e->head == escape_sym && macroctx) { + if (e->head == jl_escape_sym && macroctx) { macroctx = macroctx->parent; } @@ -1329,7 +1367,7 @@ JL_DLLEXPORT jl_value_t *jl_parse_all(const char *text, size_t text_len, { jl_value_t *fname = jl_pchar_to_string(filename, filename_len); JL_GC_PUSH1(&fname); - jl_value_t *p = jl_parse(text, text_len, fname, 0, (jl_value_t*)all_sym); + jl_value_t *p = jl_parse(text, text_len, fname, 0, (jl_value_t*)jl_all_sym); JL_GC_POP(); return jl_svecref(p, 0); } @@ -1342,7 +1380,7 @@ JL_DLLEXPORT jl_value_t *jl_parse_string(const char *text, size_t text_len, jl_value_t *fname = jl_cstr_to_string("none"); JL_GC_PUSH1(&fname); jl_value_t *result = jl_parse(text, text_len, fname, offset, - (jl_value_t*)(greedy ? statement_sym : atom_sym)); + (jl_value_t*)(greedy ? jl_statement_sym : jl_atom_sym)); JL_GC_POP(); return result; } diff --git a/src/builtin_proto.h b/src/builtin_proto.h index 49d3cd7fe87e1..e0b328e664d6c 100644 --- a/src/builtin_proto.h +++ b/src/builtin_proto.h @@ -12,11 +12,13 @@ extern "C" { #ifdef DEFINE_BUILTIN_GLOBALS #define DECLARE_BUILTIN(name) \ JL_CALLABLE(jl_f_##name); \ - jl_value_t *jl_builtin_##name + JL_DLLEXPORT jl_value_t *jl_builtin_##name; \ + JL_DLLEXPORT jl_fptr_args_t jl_f_##name##_addr = &jl_f_##name #else #define DECLARE_BUILTIN(name) \ JL_CALLABLE(jl_f_##name); \ - extern jl_value_t *jl_builtin_##name + JL_DLLEXPORT extern jl_value_t *jl_builtin_##name; \ + JL_DLLEXPORT extern jl_fptr_args_t jl_f_##name##_addr #endif DECLARE_BUILTIN(applicable); @@ -53,6 +55,11 @@ DECLARE_BUILTIN(typeof); DECLARE_BUILTIN(_typevar); JL_CALLABLE(jl_f_invoke_kwsorter); +#ifdef DEFINE_BUILTIN_GLOBALS +JL_DLLEXPORT jl_fptr_args_t jl_f_invoke_kwsorter_addr = &jl_f_invoke_kwsorter; +#else +JL_DLLEXPORT extern jl_fptr_args_t jl_f_invoke_kwsorter_addr; +#endif JL_CALLABLE(jl_f__structtype); JL_CALLABLE(jl_f__abstracttype); JL_CALLABLE(jl_f__primitivetype); diff --git a/src/builtins.c b/src/builtins.c index bdc6fb94ae9b8..b7f9a6153ff88 100644 --- a/src/builtins.c +++ b/src/builtins.c @@ -810,19 +810,19 @@ JL_CALLABLE(jl_f_svec) enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing) { - if (order == not_atomic_sym) + if (order == jl_not_atomic_sym) return jl_memory_order_notatomic; - if (order == unordered_sym && (loading ^ storing)) + if (order == jl_unordered_sym && (loading ^ storing)) return jl_memory_order_unordered; - if (order == monotonic_sym && (loading || storing)) + if (order == jl_monotonic_sym && (loading || storing)) return jl_memory_order_monotonic; - if (order == acquire_sym && loading) + if (order == jl_acquire_sym && loading) return jl_memory_order_acquire; - if (order == release_sym && storing) + if (order == jl_release_sym && storing) return jl_memory_order_release; - if (order == acquire_release_sym && loading && storing) + if (order == jl_acquire_release_sym && loading && storing) return jl_memory_order_acq_rel; - if (order == sequentially_consistent_sym) + if (order == jl_sequentially_consistent_sym) return jl_memory_order_seq_cst; return jl_memory_order_invalid; } @@ -1658,7 +1658,7 @@ JL_CALLABLE(jl_f_intrinsic_call) f = cglobal_auto; unsigned fargs = intrinsic_nargs[f]; if (!fargs) - jl_error("this intrinsic must be compiled to be called"); + jl_errorf("`%s` must be compiled to be called", jl_intrinsic_name(f)); JL_NARGS(intrinsic_call, fargs, fargs); union { @@ -1684,7 +1684,7 @@ JL_CALLABLE(jl_f_intrinsic_call) default: assert(0 && "unexpected number of arguments to an intrinsic function"); } - gc_debug_critical_error(); + jl_gc_debug_critical_error(); abort(); } diff --git a/src/ccall.cpp b/src/ccall.cpp index 53f6f6a50ec15..426abf6b7dcb1 100644 --- a/src/ccall.cpp +++ b/src/ccall.cpp @@ -2,10 +2,6 @@ // --- the ccall, cglobal, and llvm intrinsics --- -#ifdef _OS_WINDOWS_ -extern const char jl_crtdll_basename[]; -#endif - // somewhat unusual variable, in that aotcompile wants to get the address of this for a sanity check GlobalVariable *jl_emit_RTLD_DEFAULT_var(Module *M) { @@ -531,7 +527,7 @@ static void interpret_symbol_arg(jl_codectx_t &ctx, native_sym_arg_t &out, jl_va jl_value_t *ptr = static_eval(ctx, arg); if (ptr == NULL) { - if (jl_is_expr(arg) && ((jl_expr_t*)arg)->head == call_sym && jl_expr_nargs(arg) == 3 && + if (jl_is_expr(arg) && ((jl_expr_t*)arg)->head == jl_call_sym && jl_expr_nargs(arg) == 3 && jl_is_globalref(jl_exprarg(arg,0)) && jl_globalref_mod(jl_exprarg(arg,0)) == jl_core_module && jl_globalref_name(jl_exprarg(arg,0)) == jl_symbol("tuple")) { // attempt to interpret a non-constant 2-tuple expression as (func_name, lib_name()), where diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 7afd276edc31d..cba1f9111b46f 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -517,7 +517,7 @@ static Type *julia_type_to_llvm(jl_codectx_t &ctx, jl_value_t *jt, bool *isboxed } extern "C" JL_DLLEXPORT -Type *jl_type_to_llvm(jl_value_t *jt, bool *isboxed) +Type *jl_type_to_llvm_impl(jl_value_t *jt, bool *isboxed) { return _julia_type_to_llvm(NULL, jt, isboxed); } diff --git a/src/codegen-stubs.c b/src/codegen-stubs.c new file mode 100644 index 0000000000000..70bd2ee2f7af7 --- /dev/null +++ b/src/codegen-stubs.c @@ -0,0 +1,104 @@ +// This file is a part of Julia. License is MIT: https://julialang.org/license + +// This file provides a fallback implementation of the codegen plugin interface, +// used when libjulia-codegen is not available. + +#include "julia.h" +#include "julia_internal.h" + +#include "intrinsics.h" + +#define UNAVAILABLE { jl_errorf("%s: not available in this build of Julia", __func__); } + +JL_DLLEXPORT void jl_dump_native_fallback(void *native_code, + const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname, const char *asm_fname, + const char *sysimg_data, size_t sysimg_len) UNAVAILABLE +JL_DLLEXPORT int32_t jl_get_llvm_gv_fallback(void *native_code, jl_value_t *p) UNAVAILABLE +JL_DLLEXPORT void jl_write_malloc_log_fallback(void) UNAVAILABLE +JL_DLLEXPORT void jl_write_coverage_data_fallback(const char *output) UNAVAILABLE + +JL_DLLEXPORT void jl_clear_malloc_data_fallback(void) UNAVAILABLE +JL_DLLEXPORT int jl_extern_c_fallback(jl_function_t *f, jl_value_t *rt, jl_value_t *argt, char *name) UNAVAILABLE +JL_DLLEXPORT jl_value_t *jl_dump_method_asm_fallback(jl_method_instance_t *linfo, size_t world, + char raw_mc, char getwrapper, const char* asm_variant, const char *debuginfo, char binary) UNAVAILABLE +JL_DLLEXPORT jl_value_t *jl_dump_function_ir_fallback(void *f, char strip_ir_metadata, char dump_module, const char *debuginfo) UNAVAILABLE +JL_DLLEXPORT void *jl_get_llvmf_defn_fallback(jl_method_instance_t *linfo, size_t world, char getwrapper, char optimize, const jl_cgparams_t params) UNAVAILABLE + +JL_DLLEXPORT void *jl_LLVMCreateDisasm_fallback(const char *TripleName, void *DisInfo, int TagType, void *GetOpInfo, void *SymbolLookUp) UNAVAILABLE +JL_DLLEXPORT size_t jl_LLVMDisasmInstruction_fallback(void *DC, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize) UNAVAILABLE + +JL_DLLEXPORT void jl_init_codegen_fallback(void) { } + +JL_DLLEXPORT int jl_getFunctionInfo_fallback(jl_frame_t **frames, uintptr_t pointer, int skipC, int noInline) +{ + return 0; +} + +JL_DLLEXPORT void jl_register_fptrs_fallback(uint64_t sysimage_base, const struct _jl_sysimg_fptrs_t *fptrs, + jl_method_instance_t **linfos, size_t n) +{ + (void)sysimage_base; (void)fptrs; (void)linfos; (void)n; +} + +JL_DLLEXPORT jl_code_instance_t *jl_generate_fptr_fallback(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world) +{ + return NULL; +} + +JL_DLLEXPORT void jl_generate_fptr_for_unspecialized_fallback(jl_code_instance_t *unspec) +{ + jl_atomic_store_release(&unspec->invoke, &jl_fptr_interpret_call); +} + +JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION_fallback(void) +{ + return 0; +} + +JL_DLLEXPORT int jl_compile_extern_c_fallback(void *llvmmod, void *params, void *sysimg, jl_value_t *declrt, jl_value_t *sigt) +{ + return 0; +} + +JL_DLLEXPORT void jl_teardown_codegen_fallback(void) +{ +} + +JL_DLLEXPORT void jl_lock_profile_fallback(void) +{ +} + +JL_DLLEXPORT void jl_unlock_profile_fallback(void) +{ +} + +JL_DLLEXPORT void *jl_create_native_fallback(jl_array_t *methods, const jl_cgparams_t *cgparams, int _policy) UNAVAILABLE + +JL_DLLEXPORT void jl_dump_compiles_fallback(void *s) +{ +} + +JL_DLLEXPORT jl_value_t *jl_dump_fptr_asm_fallback(uint64_t fptr, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) UNAVAILABLE + +JL_DLLEXPORT jl_value_t *jl_dump_function_asm_fallback(void *F, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) UNAVAILABLE + +JL_DLLEXPORT void jl_get_function_id_fallback(void *native_code, jl_code_instance_t *ncode, + int32_t *func_idx, int32_t *specfunc_idx) UNAVAILABLE + +JL_DLLEXPORT void *jl_get_llvm_context_fallback(void *native_code) UNAVAILABLE + +JL_DLLEXPORT void *jl_get_llvm_function_fallback(void *native_code, uint32_t idx) UNAVAILABLE + +JL_DLLEXPORT void *jl_get_llvm_module_fallback(void *native_code) UNAVAILABLE + +JL_DLLEXPORT void *jl_type_to_llvm_fallback(jl_value_t *jt, bool_t *isboxed) UNAVAILABLE + +JL_DLLEXPORT jl_value_t *jl_get_libllvm_fallback(void) JL_NOTSAFEPOINT +{ + return jl_nothing; +} + +JL_DLLEXPORT uint64_t jl_getUnwindInfo_fallback(uint64_t dwAddr) +{ + return 0; +} diff --git a/src/codegen.cpp b/src/codegen.cpp index af01b54a9352f..754499d5020f0 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -114,19 +114,7 @@ extern "C" { #include "builtin_proto.h" -#ifdef HAVE_SSP -extern uintptr_t __stack_chk_guard; extern void __stack_chk_fail(); -#else -JL_DLLEXPORT uintptr_t __stack_chk_guard = (uintptr_t)0xBAD57ACCBAD67ACC; // 0xBADSTACKBADSTACK -JL_DLLEXPORT void __stack_chk_fail() -{ - /* put your panic function or similar in here */ - fprintf(stderr, "fatal error: stack corruption detected\n"); - gc_debug_critical_error(); - abort(); // end with abort, since the compiler destroyed the stack upon entry to this function, there's no going back now -} -#endif #ifdef _OS_WINDOWS_ #if defined(_CPU_X86_64_) @@ -867,39 +855,7 @@ static const auto pointer_from_objref_func = new JuliaFunction{ }; static const auto jltuple_func = new JuliaFunction{XSTR(jl_f_tuple), get_func_sig, get_func_attrs}; -static const std::map builtin_func_map = { - { &jl_f_is, new JuliaFunction{XSTR(jl_f_is), get_func_sig, get_func_attrs} }, - { &jl_f_typeof, new JuliaFunction{XSTR(jl_f_typeof), get_func_sig, get_func_attrs} }, - { &jl_f_sizeof, new JuliaFunction{XSTR(jl_f_sizeof), get_func_sig, get_func_attrs} }, - { &jl_f_issubtype, new JuliaFunction{XSTR(jl_f_issubtype), get_func_sig, get_func_attrs} }, - { &jl_f_isa, new JuliaFunction{XSTR(jl_f_isa), get_func_sig, get_func_attrs} }, - { &jl_f_typeassert, new JuliaFunction{XSTR(jl_f_typeassert), get_func_sig, get_func_attrs} }, - { &jl_f_ifelse, new JuliaFunction{XSTR(jl_f_ifelse), get_func_sig, get_func_attrs} }, - { &jl_f__apply_iterate, new JuliaFunction{XSTR(jl_f__apply_iterate), get_func_sig, get_func_attrs} }, - { &jl_f__apply_pure, new JuliaFunction{XSTR(jl_f__apply_pure), get_func_sig, get_func_attrs} }, - { &jl_f__call_latest, new JuliaFunction{XSTR(jl_f__call_latest), get_func_sig, get_func_attrs} }, - { &jl_f__call_in_world, new JuliaFunction{XSTR(jl_f__call_in_world), get_func_sig, get_func_attrs} }, - { &jl_f_throw, new JuliaFunction{XSTR(jl_f_throw), get_func_sig, get_func_attrs} }, - { &jl_f_tuple, jltuple_func }, - { &jl_f_svec, new JuliaFunction{XSTR(jl_f_svec), get_func_sig, get_func_attrs} }, - { &jl_f_applicable, new JuliaFunction{XSTR(jl_f_applicable), get_func_sig, get_func_attrs} }, - { &jl_f_invoke, new JuliaFunction{XSTR(jl_f_invoke), get_func_sig, get_func_attrs} }, - { &jl_f_invoke_kwsorter, new JuliaFunction{XSTR(jl_f_invoke_kwsorter), get_func_sig, get_func_attrs} }, - { &jl_f_isdefined, new JuliaFunction{XSTR(jl_f_isdefined), get_func_sig, get_func_attrs} }, - { &jl_f_getfield, new JuliaFunction{XSTR(jl_f_getfield), get_func_sig, get_func_attrs} }, - { &jl_f_setfield, new JuliaFunction{XSTR(jl_f_setfield), get_func_sig, get_func_attrs} }, - { &jl_f_swapfield, new JuliaFunction{XSTR(jl_f_swapfield), get_func_sig, get_func_attrs} }, - { &jl_f_modifyfield, new JuliaFunction{XSTR(jl_f_modifyfield), get_func_sig, get_func_attrs} }, - { &jl_f_fieldtype, new JuliaFunction{XSTR(jl_f_fieldtype), get_func_sig, get_func_attrs} }, - { &jl_f_nfields, new JuliaFunction{XSTR(jl_f_nfields), get_func_sig, get_func_attrs} }, - { &jl_f__expr, new JuliaFunction{XSTR(jl_f__expr), get_func_sig, get_func_attrs} }, - { &jl_f__typevar, new JuliaFunction{XSTR(jl_f__typevar), get_func_sig, get_func_attrs} }, - { &jl_f_arrayref, new JuliaFunction{XSTR(jl_f_arrayref), get_func_sig, get_func_attrs} }, - { &jl_f_const_arrayref, new JuliaFunction{XSTR(jl_f_const_arrayref), get_func_sig, get_func_attrs} }, - { &jl_f_arrayset, new JuliaFunction{XSTR(jl_f_arrayset), get_func_sig, get_func_attrs} }, - { &jl_f_arraysize, new JuliaFunction{XSTR(jl_f_arraysize), get_func_sig, get_func_attrs} }, - { &jl_f_apply_type, new JuliaFunction{XSTR(jl_f_apply_type), get_func_sig, get_func_attrs} }, -}; +static std::map builtin_func_map; static const auto jl_new_opaque_closure_jlcall_func = new JuliaFunction{XSTR(jl_new_opaque_closure_jlcall), get_func_sig, get_func_attrs}; @@ -907,14 +863,13 @@ static int globalUnique = 0; // --- code generation --- extern "C" { - int jl_default_debug_info_kind = (int) DICompileUnit::DebugEmissionKind::FullDebug; jl_cgparams_t jl_default_cgparams = {1, 1, 0, #ifdef _OS_WINDOWS_ 0, #else 1, #endif - jl_default_debug_info_kind, + (int) DICompileUnit::DebugEmissionKind::FullDebug, jl_rettype_inferred, NULL }; } @@ -1929,7 +1884,7 @@ static void mallocVisitLine(jl_codectx_t &ctx, StringRef filename, int line, Val } // Resets the malloc counts. -extern "C" JL_DLLEXPORT void jl_clear_malloc_data(void) +extern "C" JL_DLLEXPORT void jl_clear_malloc_data_impl(void) { logdata_t::iterator it = mallocData.begin(); for (; it != mallocData.end(); it++) { @@ -1957,7 +1912,7 @@ static void write_log_data(logdata_t &logData, const char *extension) std::string filename(it->first()); std::vector &values = it->second; if (!values.empty()) { - if (!isabspath(filename.c_str())) + if (!jl_isabspath(filename.c_str())) filename = base + filename; std::ifstream inf(filename.c_str()); if (!inf.is_open()) @@ -2043,12 +1998,12 @@ static void write_lcov_data(logdata_t &logData, const std::string &outfile) outf.close(); } -extern "C" void jl_write_coverage_data(const char *output) +extern "C" JL_DLLEXPORT void jl_write_coverage_data_impl(const char *output) { if (output) { StringRef output_pattern(output); if (output_pattern.endswith(".info")) - write_lcov_data(coverageData, jl_format_filename(output_pattern)); + write_lcov_data(coverageData, jl_format_filename(output_pattern.str().c_str())); } else { std::string stm; @@ -2057,7 +2012,7 @@ extern "C" void jl_write_coverage_data(const char *output) } } -extern "C" void jl_write_malloc_log(void) +extern "C" JL_DLLEXPORT void jl_write_malloc_log_impl(void) { std::string stm; raw_string_ostream(stm) << "." << jl_getpid() << ".mem"; @@ -2142,7 +2097,7 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex) } if (jl_is_expr(ex)) { jl_expr_t *e = (jl_expr_t*)ex; - if (e->head == call_sym) { + if (e->head == jl_call_sym) { jl_value_t *f = static_eval(ctx, jl_exprarg(e, 0)); if (f) { if (jl_array_dim0(e->args) == 3 && f == jl_builtin_getfield) { @@ -2192,7 +2147,7 @@ static jl_value_t *static_eval(jl_codectx_t &ctx, jl_value_t *ex) } } } - else if (e->head == static_parameter_sym) { + else if (e->head == jl_static_parameter_sym) { size_t idx = jl_unbox_long(jl_exprarg(e, 0)); if (idx <= jl_svec_len(ctx.linfo->sparam_vals)) { jl_value_t *e = jl_svecref(ctx.linfo->sparam_vals, idx - 1); @@ -2249,7 +2204,7 @@ static std::set assigned_in_try(jl_array_t *stmts, int s, long l) for(int i=s; i <= l; i++) { jl_value_t *st = jl_array_ptr_ref(stmts,i); if (jl_is_expr(st)) { - if (((jl_expr_t*)st)->head == assign_sym) { + if (((jl_expr_t*)st)->head == jl_assign_sym) { jl_value_t *ar = jl_exprarg(st, 0); if (jl_is_slot(ar)) { av.insert(jl_slot_number(ar)-1); @@ -2266,7 +2221,7 @@ static void mark_volatile_vars(jl_array_t *stmts, std::vector &slo for (int i = 0; i < (int)slength; i++) { jl_value_t *st = jl_array_ptr_ref(stmts, i); if (jl_is_expr(st)) { - if (((jl_expr_t*)st)->head == enter_sym) { + if (((jl_expr_t*)st)->head == jl_enter_sym) { int last = jl_unbox_long(jl_exprarg(st, 0)); std::set as = assigned_in_try(stmts, i + 1, last); for (int j = 0; j < (int)slength; j++) { @@ -2297,14 +2252,14 @@ static void simple_use_analysis(jl_codectx_t &ctx, jl_value_t *expr) } else if (jl_is_expr(expr)) { jl_expr_t *e = (jl_expr_t*)expr; - if (e->head == method_sym) { + if (e->head == jl_method_sym) { simple_use_analysis(ctx, jl_exprarg(e, 0)); if (jl_expr_nargs(e) > 1) { simple_use_analysis(ctx, jl_exprarg(e, 1)); simple_use_analysis(ctx, jl_exprarg(e, 2)); } } - else if (e->head == assign_sym) { + else if (e->head == jl_assign_sym) { // don't consider assignment LHS as a variable "use" simple_use_analysis(ctx, jl_exprarg(e, 1)); } @@ -3683,11 +3638,11 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, const if (ci != jl_nothing) { auto invoke = jl_atomic_load_relaxed(&codeinst->invoke); // check if we know how to handle this specptr - if (invoke == jl_fptr_const_return) { + if (invoke == jl_fptr_const_return_addr) { result = mark_julia_const(codeinst->rettype_const); handled = true; } - else if (invoke != jl_fptr_sparam) { + else if (invoke != jl_fptr_sparam_addr) { bool specsig, needsparams; std::tie(specsig, needsparams) = uses_specsig(mi, codeinst->rettype, ctx.params->prefer_specsig); std::string name; @@ -3699,7 +3654,7 @@ static jl_cgval_t emit_invoke(jl_codectx_t &ctx, const jl_cgval_t &lival, const auto invoke = jl_atomic_load_relaxed(&codeinst->invoke); auto fptr = jl_atomic_load_relaxed(&codeinst->specptr.fptr); if (fptr) { - if (specsig ? codeinst->isspecsig : invoke == jl_fptr_args) { + if (specsig ? codeinst->isspecsig : invoke == jl_fptr_args_addr) { protoname = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)fptr, codeinst); need_to_emit = false; } @@ -3751,7 +3706,7 @@ static jl_cgval_t emit_invoke_modify(jl_codectx_t &ctx, jl_expr_t *ex, jl_value_ if (f.constant && f.constant == jl_builtin_modifyfield) { if (emit_f_opfield(ctx, &ret, jl_builtin_modifyfield, argv, nargs - 1, &lival)) return ret; - auto it = builtin_func_map.find(&jl_f_modifyfield); + auto it = builtin_func_map.find(jl_f_modifyfield_addr); assert(it != builtin_func_map.end()); Value *oldnew = emit_jlcall(ctx, it->second, V_rnull, &argv[1], nargs - 1, JLCALL_F_CC); return mark_julia_type(ctx, oldnew, true, rt); @@ -3971,7 +3926,7 @@ static jl_cgval_t emit_isdefined(jl_codectx_t &ctx, jl_value_t *sym) } } else if (jl_is_expr(sym)) { - assert(((jl_expr_t*)sym)->head == static_parameter_sym && "malformed isdefined expression"); + assert(((jl_expr_t*)sym)->head == jl_static_parameter_sym && "malformed isdefined expression"); size_t i = jl_unbox_long(jl_exprarg(sym, 0)) - 1; if (jl_svec_len(ctx.linfo->sparam_vals) > 0) { jl_value_t *e = jl_svecref(ctx.linfo->sparam_vals, i); @@ -4488,18 +4443,18 @@ static void emit_stmtpos(jl_codectx_t &ctx, jl_value_t *expr, int ssaval_result) jl_expr_t *ex = (jl_expr_t*)expr; jl_value_t **args = (jl_value_t**)jl_array_data(ex->args); jl_sym_t *head = ex->head; - if (head == meta_sym || head == inbounds_sym || head == coverageeffect_sym - || head == aliasscope_sym || head == popaliasscope_sym || head == inline_sym || head == noinline_sym) { + if (head == jl_meta_sym || head == jl_inbounds_sym || head == jl_coverageeffect_sym + || head == jl_aliasscope_sym || head == jl_popaliasscope_sym || head == jl_inline_sym || head == jl_noinline_sym) { // some expression types are metadata and can be ignored // in statement position return; } - else if (head == leave_sym) { + else if (head == jl_leave_sym) { assert(jl_is_long(args[0])); ctx.builder.CreateCall(prepare_call(jlleave_func), ConstantInt::get(T_int32, jl_unbox_long(args[0]))); } - else if (head == pop_exception_sym) { + else if (head == jl_pop_exception_sym) { jl_cgval_t excstack_state = emit_expr(ctx, jl_exprarg(expr, 0)); assert(excstack_state.V && excstack_state.V->getType() == T_size); ctx.builder.CreateCall(prepare_call(jl_restore_excstack_func), excstack_state.V); @@ -4593,15 +4548,15 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) // this is object-disoriented. // however, this is a good way to do it because it should *not* be easy // to add new node types. - if (head == isdefined_sym) { + if (head == jl_isdefined_sym) { assert(nargs == 1); return emit_isdefined(ctx, args[0]); } - else if (head == throw_undef_if_not_sym) { + else if (head == jl_throw_undef_if_not_sym) { assert(nargs == 2); jl_sym_t *var = (jl_sym_t*)args[0]; Value *cond = ctx.builder.CreateTrunc(emit_unbox(ctx, T_int8, emit_expr(ctx, args[1]), (jl_value_t*)jl_bool_type), T_int1); - if (var == getfield_undefref_sym) { + if (var == jl_getfield_undefref_sym) { raise_exception_unless(ctx, cond, literal_pointer_val(ctx, jl_undefref_exception)); } @@ -4610,19 +4565,19 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) } return ghostValue(jl_nothing_type); } - else if (head == invoke_sym) { + else if (head == jl_invoke_sym) { assert(ssaval >= 0); jl_value_t *expr_t = jl_is_long(ctx.source->ssavaluetypes) ? (jl_value_t*)jl_any_type : jl_array_ptr_ref(ctx.source->ssavaluetypes, ssaval); return emit_invoke(ctx, ex, expr_t); } - else if (head == invoke_modify_sym) { + else if (head == jl_invoke_modify_sym) { assert(ssaval >= 0); jl_value_t *expr_t = jl_is_long(ctx.source->ssavaluetypes) ? (jl_value_t*)jl_any_type : jl_array_ptr_ref(ctx.source->ssavaluetypes, ssaval); return emit_invoke_modify(ctx, ex, expr_t); } - else if (head == call_sym) { + else if (head == jl_call_sym) { jl_value_t *expr_t; if (ssaval < 0) // TODO: this case is needed for the call to emit_expr in emit_llvmcall @@ -4638,24 +4593,24 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) } return res; } - else if (head == foreigncall_sym) { + else if (head == jl_foreigncall_sym) { return emit_ccall(ctx, args, jl_array_dim0(ex->args)); } - else if (head == cfunction_sym) { + else if (head == jl_cfunction_sym) { assert(nargs == 5); jl_cgval_t fexpr_rt = emit_expr(ctx, args[1]); return emit_cfunction(ctx, args[0], fexpr_rt, args[2], (jl_svec_t*)args[3]); } - else if (head == assign_sym) { + else if (head == jl_assign_sym) { assert(nargs == 2); emit_assignment(ctx, args[0], args[1], ssaval); return ghostValue(jl_nothing_type); } - else if (head == static_parameter_sym) { + else if (head == jl_static_parameter_sym) { assert(nargs == 1); return emit_sparam(ctx, jl_unbox_long(args[0]) - 1); } - else if (head == method_sym) { + else if (head == jl_method_sym) { if (nargs == 1) { jl_value_t *mn = args[0]; assert(jl_is_symbol(mn) || jl_is_slot(mn)); @@ -4723,7 +4678,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) jl_method_type); return meth; } - else if (head == const_sym) { + else if (head == jl_const_sym) { assert(nargs == 1); jl_sym_t *sym = (jl_sym_t*)args[0]; jl_module_t *mod = ctx.module; @@ -4738,7 +4693,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) literal_pointer_val(ctx, bnd)); } } - else if (head == new_sym) { + else if (head == jl_new_sym) { assert(nargs > 0); jl_cgval_t *argv = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * nargs); for (size_t i = 0; i < nargs; ++i) { @@ -4756,7 +4711,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) // it to the inferred type. return mark_julia_type(ctx, val, true, (jl_value_t*)jl_any_type); } - else if (head == splatnew_sym) { + else if (head == jl_splatnew_sym) { jl_cgval_t argv[2]; assert(nargs == 2); argv[0] = emit_expr(ctx, args[0]); @@ -4768,7 +4723,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) // it to the inferred type. return mark_julia_type(ctx, val, true, (jl_value_t*)jl_any_type); } - else if (head == new_opaque_closure_sym) { + else if (head == jl_new_opaque_closure_sym) { assert(nargs >= 5 && "Not enough arguments in new_opaque_closure"); SmallVector argv(nargs); for (size_t i = 0; i < nargs; ++i) { @@ -4907,13 +4862,13 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) emit_jlcall(ctx, jl_new_opaque_closure_jlcall_func, V_rnull, argv.data(), nargs, JLCALL_F_CC), true, jl_any_type); } - else if (head == exc_sym) { + else if (head == jl_exc_sym) { assert(nargs == 0); return mark_julia_type(ctx, ctx.builder.CreateCall(prepare_call(jl_current_exception_func)), true, jl_any_type); } - else if (head == copyast_sym) { + else if (head == jl_copyast_sym) { assert(nargs == 1); jl_cgval_t ast = emit_expr(ctx, args[0]); if (ast.typ != (jl_value_t*)jl_expr_type && ast.typ != (jl_value_t*)jl_any_type) { @@ -4924,7 +4879,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) ctx.builder.CreateCall(prepare_call(jlcopyast_func), boxed(ctx, ast)), true, jl_expr_type); } - else if (head == loopinfo_sym) { + else if (head == jl_loopinfo_sym) { // parse Expr(:loopinfo, "julia.simdloop", ("llvm.loop.vectorize.width", 4)) SmallVector MDs; for (int i = 0, ie = nargs; i < ie; ++i) { @@ -4938,15 +4893,15 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) I->setMetadata("julia.loopinfo", MD); return jl_cgval_t(); } - else if (head == leave_sym || head == coverageeffect_sym - || head == pop_exception_sym || head == enter_sym || head == inbounds_sym - || head == aliasscope_sym || head == popaliasscope_sym || head == inline_sym || head == noinline_sym) { + else if (head == jl_leave_sym || head == jl_coverageeffect_sym + || head == jl_pop_exception_sym || head == jl_enter_sym || head == jl_inbounds_sym + || head == jl_aliasscope_sym || head == jl_popaliasscope_sym || head == jl_inline_sym || head == jl_noinline_sym) { jl_errorf("Expr(:%s) in value position", jl_symbol_name(head)); } - else if (head == boundscheck_sym) { + else if (head == jl_boundscheck_sym) { return mark_julia_const(bounds_check_enabled(ctx, jl_true) ? jl_true : jl_false); } - else if (head == gc_preserve_begin_sym) { + else if (head == jl_gc_preserve_begin_sym) { jl_cgval_t *argv = (jl_cgval_t*)alloca(sizeof(jl_cgval_t) * nargs); for (size_t i = 0; i < nargs; ++i) { argv[i] = emit_expr(ctx, args[i]); @@ -4970,7 +4925,7 @@ static jl_cgval_t emit_expr(jl_codectx_t &ctx, jl_value_t *expr, ssize_t ssaval) jl_cgval_t tok(token, NULL, false, (jl_value_t*)jl_nothing_type, NULL); return tok; } - else if (head == gc_preserve_end_sym) { + else if (head == jl_gc_preserve_end_sym) { // We only support ssa values as the argument. Everything else will // fall back to the default behavior of preserving the argument value // until the end of the scope, which is correct, but not optimal. @@ -5228,11 +5183,11 @@ static Function* gen_cfun_wrapper( // TODO: this isn't ideal to be unconditionally calling type inference (and compile) from here codeinst = jl_compile_method_internal(lam, world); assert(codeinst->invoke); - if (codeinst->invoke == jl_fptr_args) { + if (codeinst->invoke == jl_fptr_args_addr) { callptr = codeinst->specptr.fptr; calltype = 1; } - else if (codeinst->invoke == jl_fptr_const_return) { + else if (codeinst->invoke == jl_fptr_const_return_addr) { // don't need the fptr callptr = (void*)codeinst->rettype_const; calltype = 2; @@ -6275,7 +6230,7 @@ static std::pair, jl_llvm_functions_t> ctx.nReqArgs = nreq; if (va) { jl_sym_t *vn = (jl_sym_t*)jl_array_ptr_ref(src->slotnames, ctx.nargs - 1); - if (vn != unused_sym) + if (vn != jl_unused_sym) ctx.vaSlot = ctx.nargs - 1; } toplevel = !jl_is_method(lam->def.method); @@ -6338,7 +6293,7 @@ static std::pair, jl_llvm_functions_t> jl_varinfo_t &varinfo = ctx.slots[i]; varinfo.isArgument = true; jl_sym_t *argname = (jl_sym_t*)jl_array_ptr_ref(src->slotnames, i); - if (argname == unused_sym) + if (argname == jl_unused_sym) continue; jl_value_t *ty = jl_nth_slot_type(lam->specTypes, i); // OpaqueClosure implicitly loads the env @@ -6456,12 +6411,12 @@ static std::pair, jl_llvm_functions_t> f->setDoesNotReturn(); #ifdef USE_POLLY - if (!jl_has_meta(stmts, polly_sym) || jl_options.polly == JL_OPTIONS_POLLY_OFF) { + if (!jl_has_meta(stmts, jl_polly_sym) || jl_options.polly == JL_OPTIONS_POLLY_OFF) { f->addFnAttr(polly::PollySkipFnAttr); } #endif - if (jl_has_meta(stmts, noinline_sym)) { + if (jl_has_meta(stmts, jl_noinline_sym)) { f->addFnAttr(Attribute::NoInline); } @@ -6550,7 +6505,7 @@ static std::pair, jl_llvm_functions_t> // Go over all arguments and local variables and initialize their debug information for (i = 0; i < nreq; i++) { jl_sym_t *argname = (jl_sym_t*)jl_array_ptr_ref(src->slotnames, i); - if (argname == unused_sym) + if (argname == jl_unused_sym) continue; jl_varinfo_t &varinfo = ctx.slots[i]; varinfo.dinfo = dbuilder.createParameterVariable( @@ -6578,7 +6533,7 @@ static std::pair, jl_llvm_functions_t> for (i = 0; i < vinfoslen; i++) { jl_sym_t *s = (jl_sym_t*)jl_array_ptr_ref(src->slotnames, i); jl_varinfo_t &varinfo = ctx.slots[i]; - if (varinfo.isArgument || s == empty_sym || s == unused_sym) + if (varinfo.isArgument || s == jl_empty_sym || s == jl_unused_sym) continue; // LLVM 4.0: Assume the variable has default alignment varinfo.dinfo = dbuilder.createAutoVariable( @@ -6707,7 +6662,7 @@ static std::pair, jl_llvm_functions_t> // get pointers for locals stored in the gc frame array (argTemp) for (i = 0; i < vinfoslen; i++) { jl_sym_t *s = slot_symbol(ctx, i); - if (s == unused_sym) + if (s == jl_unused_sym) continue; jl_varinfo_t &varinfo = ctx.slots[i]; if (!varinfo.used) { @@ -6779,14 +6734,14 @@ static std::pair, jl_llvm_functions_t> jl_nth_slot_type(lam->specTypes, i); bool isboxed = deserves_argbox(argType); Type *llvmArgType = isboxed ? T_prjlvalue : julia_type_to_llvm(ctx, argType); - if (s == unused_sym) { + if (s == jl_unused_sym) { if (specsig && !type_is_ghost(llvmArgType) && !is_uniquerep_Type(argType)) ++AI; continue; } jl_varinfo_t &vi = ctx.slots[i]; jl_cgval_t theArg; - if (s == unused_sym || vi.value.constant) { + if (s == jl_unused_sym || vi.value.constant) { assert(vi.boxroot == NULL); if (specsig && !type_is_ghost(llvmArgType) && !is_uniquerep_Type(argType)) ++AI; @@ -7013,13 +6968,13 @@ static std::pair, jl_llvm_functions_t> jl_value_t *stmt = jl_array_ptr_ref(stmts, i); jl_expr_t *expr = jl_is_expr(stmt) ? (jl_expr_t*)stmt : nullptr; if (expr) { - if (expr->head == aliasscope_sym) { + if (expr->head == jl_aliasscope_sym) { MDNode *scope = mbuilder.createAliasScope("aliasscope", alias_domain); scope_stack.push_back(scope); MDNode *scope_list = MDNode::get(jl_LLVMContext, ArrayRef(scope_stack)); scope_list_stack.push_back(scope_list); current_aliasscope = scope_list; - } else if (expr->head == popaliasscope_sym) { + } else if (expr->head == jl_popaliasscope_sym) { scope_stack.pop_back(); scope_list_stack.pop_back(); if (scope_list_stack.empty()) { @@ -7144,7 +7099,7 @@ static std::pair, jl_llvm_functions_t> if (i + 2 <= stmtslen) branch_targets.insert(i + 2); } else if (jl_is_expr(stmt)) { - if (((jl_expr_t*)stmt)->head == enter_sym) { + if (((jl_expr_t*)stmt)->head == jl_enter_sym) { branch_targets.insert(i + 1); if (i + 2 <= stmtslen) branch_targets.insert(i + 2); @@ -7331,7 +7286,7 @@ static std::pair, jl_llvm_functions_t> find_next_stmt(cursor + 1); continue; } - else if (expr && expr->head == enter_sym) { + else if (expr && expr->head == jl_enter_sym) { jl_value_t **args = (jl_value_t**)jl_array_data(expr->args); assert(jl_is_long(args[0])); @@ -7807,7 +7762,7 @@ jl_compile_result_t jl_emit_codeinst( // and there is something to delete (test this before calling jl_ir_flag_inlineable) codeinst->inferred != jl_nothing && // don't delete inlineable code, unless it is constant - (codeinst->invoke == jl_fptr_const_return || !jl_ir_flag_inlineable((jl_array_t*)codeinst->inferred)) && + (codeinst->invoke == jl_fptr_const_return_addr || !jl_ir_flag_inlineable((jl_array_t*)codeinst->inferred)) && // don't delete code when generating a precompile file !imaging_mode) { // if not inlineable, code won't be needed again @@ -7843,7 +7798,7 @@ void jl_compile_workqueue( auto invoke = jl_atomic_load_relaxed(&codeinst->invoke); if (params.cache && invoke != NULL) { auto fptr = jl_atomic_load_relaxed(&codeinst->specptr.fptr); - if (invoke == jl_fptr_args) { + if (invoke == jl_fptr_args_addr) { preal_decl = jl_ExecutionEngine->getFunctionAtAddress((uintptr_t)fptr, codeinst); } else if (codeinst->isspecsig) { @@ -8186,9 +8141,59 @@ static void init_jit_functions(void) #undef BOX_F } +char jl_using_gdb_jitevents = 0; + +#ifdef JL_USE_INTEL_JITEVENTS +char jl_using_intel_jitevents; // Non-zero if running under Intel VTune Amplifier +#endif + +#ifdef JL_USE_OPROFILE_JITEVENTS +char jl_using_oprofile_jitevents = 0; // Non-zero if running under OProfile +#endif + +#ifdef JL_USE_PERF_JITEVENTS +char jl_using_perf_jitevents = 0; +#endif + +void jl_init_debuginfo(void); + extern "C" void jl_init_llvm(void) { - jl_page_size = jl_getpagesize(); + builtin_func_map = + { { jl_f_is_addr, new JuliaFunction{XSTR(jl_f_is), get_func_sig, get_func_attrs} }, + { jl_f_typeof_addr, new JuliaFunction{XSTR(jl_f_typeof), get_func_sig, get_func_attrs} }, + { jl_f_sizeof_addr, new JuliaFunction{XSTR(jl_f_sizeof), get_func_sig, get_func_attrs} }, + { jl_f_issubtype_addr, new JuliaFunction{XSTR(jl_f_issubtype), get_func_sig, get_func_attrs} }, + { jl_f_isa_addr, new JuliaFunction{XSTR(jl_f_isa), get_func_sig, get_func_attrs} }, + { jl_f_typeassert_addr, new JuliaFunction{XSTR(jl_f_typeassert), get_func_sig, get_func_attrs} }, + { jl_f_ifelse_addr, new JuliaFunction{XSTR(jl_f_ifelse), get_func_sig, get_func_attrs} }, + { jl_f__apply_iterate_addr, new JuliaFunction{XSTR(jl_f__apply_iterate), get_func_sig, get_func_attrs} }, + { jl_f__apply_pure_addr, new JuliaFunction{XSTR(jl_f__apply_pure), get_func_sig, get_func_attrs} }, + { jl_f__call_latest_addr, new JuliaFunction{XSTR(jl_f__call_latest), get_func_sig, get_func_attrs} }, + { jl_f__call_in_world_addr, new JuliaFunction{XSTR(jl_f__call_in_world), get_func_sig, get_func_attrs} }, + { jl_f_throw_addr, new JuliaFunction{XSTR(jl_f_throw), get_func_sig, get_func_attrs} }, + { jl_f_tuple_addr, jltuple_func }, + { jl_f_svec_addr, new JuliaFunction{XSTR(jl_f_svec), get_func_sig, get_func_attrs} }, + { jl_f_applicable_addr, new JuliaFunction{XSTR(jl_f_applicable), get_func_sig, get_func_attrs} }, + { jl_f_invoke_addr, new JuliaFunction{XSTR(jl_f_invoke), get_func_sig, get_func_attrs} }, + { jl_f_invoke_kwsorter_addr, new JuliaFunction{XSTR(jl_f_invoke_kwsorter), get_func_sig, get_func_attrs} }, + { jl_f_isdefined_addr, new JuliaFunction{XSTR(jl_f_isdefined), get_func_sig, get_func_attrs} }, + { jl_f_getfield_addr, new JuliaFunction{XSTR(jl_f_getfield), get_func_sig, get_func_attrs} }, + { jl_f_setfield_addr, new JuliaFunction{XSTR(jl_f_setfield), get_func_sig, get_func_attrs} }, + { jl_f_swapfield_addr, new JuliaFunction{XSTR(jl_f_swapfield), get_func_sig, get_func_attrs} }, + { jl_f_modifyfield_addr, new JuliaFunction{XSTR(jl_f_modifyfield), get_func_sig, get_func_attrs} }, + { jl_f_fieldtype_addr, new JuliaFunction{XSTR(jl_f_fieldtype), get_func_sig, get_func_attrs} }, + { jl_f_nfields_addr, new JuliaFunction{XSTR(jl_f_nfields), get_func_sig, get_func_attrs} }, + { jl_f__expr_addr, new JuliaFunction{XSTR(jl_f__expr), get_func_sig, get_func_attrs} }, + { jl_f__typevar_addr, new JuliaFunction{XSTR(jl_f__typevar), get_func_sig, get_func_attrs} }, + { jl_f_arrayref_addr, new JuliaFunction{XSTR(jl_f_arrayref), get_func_sig, get_func_attrs} }, + { jl_f_const_arrayref_addr, new JuliaFunction{XSTR(jl_f_const_arrayref), get_func_sig, get_func_attrs} }, + { jl_f_arrayset_addr, new JuliaFunction{XSTR(jl_f_arrayset), get_func_sig, get_func_attrs} }, + { jl_f_arraysize_addr, new JuliaFunction{XSTR(jl_f_arraysize), get_func_sig, get_func_attrs} }, + { jl_f_apply_type_addr, new JuliaFunction{XSTR(jl_f_apply_type), get_func_sig, get_func_attrs} }, + }; + + jl_default_debug_info_kind = (int) DICompileUnit::DebugEmissionKind::FullDebug; imaging_mode = jl_options.image_codegen || (jl_generating_output() && !jl_options.incremental); jl_default_cgparams.generic_context = jl_nothing; jl_init_debuginfo(); @@ -8313,9 +8318,41 @@ extern "C" void jl_init_llvm(void) jl_data_layout.reset(DL); // Register GDB event listener - if(jl_using_gdb_jitevents) +#if defined(JL_DEBUG_BUILD) + jl_using_gdb_jitevents = 1; +# else + const char *jit_gdb = getenv("ENABLE_GDBLISTENER"); + if (jit_gdb && atoi(jit_gdb)) { + jl_using_gdb_jitevents = 1; + } +#endif + if (jl_using_gdb_jitevents) jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createGDBRegistrationListener()); +#if defined(JL_USE_INTEL_JITEVENTS) || \ + defined(JL_USE_OPROFILE_JITEVENTS) || \ + defined(JL_USE_PERF_JITEVENTS) + const char *jit_profiling = getenv("ENABLE_JITPROFILING"); +#endif + +#if defined(JL_USE_INTEL_JITEVENTS) + if (jit_profiling && atoi(jit_profiling)) { + jl_using_intel_jitevents = 1; + } +#endif + +#if defined(JL_USE_OPROFILE_JITEVENTS) + if (jit_profiling && atoi(jit_profiling)) { + jl_using_oprofile_jitevents = 1; + } +#endif + +#if defined(JL_USE_PERF_JITEVENTS) + if (jit_profiling && atoi(jit_profiling)) { + jl_using_perf_jitevents= 1; + } +#endif + #ifdef JL_USE_INTEL_JITEVENTS if (jl_using_intel_jitevents) jl_ExecutionEngine->RegisterJITEventListener(JITEventListener::createIntelJITEventListener()); @@ -8334,7 +8371,7 @@ extern "C" void jl_init_llvm(void) cl::PrintOptionValues(); } -extern "C" void jl_init_codegen(void) +extern "C" JL_DLLEXPORT void jl_init_codegen_impl(void) { jl_init_llvm(); // Now that the execution engine exists, initialize all modules @@ -8348,7 +8385,7 @@ extern "C" void jl_init_codegen(void) jl_init_intrinsic_functions_codegen(); } -extern "C" void jl_teardown_codegen() +extern "C" JL_DLLEXPORT void jl_teardown_codegen_impl() { // output LLVM timings and statistics reportAndResetTimings(); @@ -8414,3 +8451,30 @@ extern void jl_write_bitcode_module(void *M, char *fname) { raw_fd_ostream OS(fname, EC, sys::fs::OF_None); llvm::WriteBitcodeToFile(*(llvm::Module*)M, OS); } + +#ifdef _OS_WINDOWS_ +#include +#else +#include +#endif + +#include + +extern "C" JL_DLLEXPORT jl_value_t *jl_get_libllvm_impl(void) JL_NOTSAFEPOINT +{ +#if defined(_OS_WINDOWS_) + HMODULE mod; + if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS, (LPCSTR)&llvm::DebugFlag, &mod)) + return jl_nothing; + + char path[MAX_PATH]; + if (!GetModuleFileNameA(mod, path, sizeof(path))) + return jl_nothing; + return (jl_value_t*) jl_symbol(path); +#else + Dl_info dli; + if (!dladdr((void*)LLVMContextCreate, &dli)) + return jl_nothing; + return (jl_value_t*) jl_symbol(dli.dli_fname); +#endif +} diff --git a/src/datatype.c b/src/datatype.c index c49c74a8dd91c..2a0c9a29c9019 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -628,7 +628,7 @@ JL_DLLEXPORT jl_datatype_t *jl_new_datatype( if (fldn < 1 || fldn > jl_svec_len(fnames)) jl_errorf("invalid field attribute %lld", (long long)fldn); fldn--; - if (attr == atomic_sym) { + if (attr == jl_atomic_sym) { if (!mutabl) jl_errorf("invalid field attribute atomic for immutable struct"); if (atomicfields == NULL) { diff --git a/src/debuginfo.cpp b/src/debuginfo.cpp index ed0f09b96220e..6a2f3b9c2ab06 100644 --- a/src/debuginfo.cpp +++ b/src/debuginfo.cpp @@ -50,17 +50,17 @@ typedef object::SymbolRef SymRef; // and cannot have any interaction with the julia runtime static uv_rwlock_t threadsafe; -extern "C" void jl_init_debuginfo(void) +void jl_init_debuginfo(void) { uv_rwlock_init(&threadsafe); } -extern "C" void jl_lock_profile(void) +extern "C" JL_DLLEXPORT void jl_lock_profile_impl(void) { uv_rwlock_rdlock(&threadsafe); } -extern "C" void jl_unlock_profile(void) +extern "C" JL_DLLEXPORT void jl_unlock_profile_impl(void) { uv_rwlock_rdunlock(&threadsafe); } @@ -710,8 +710,9 @@ static uint64_t jl_sysimage_base; static jl_sysimg_fptrs_t sysimg_fptrs; static jl_method_instance_t **sysimg_fvars_linfo; static size_t sysimg_fvars_n; -void jl_register_fptrs(uint64_t sysimage_base, const jl_sysimg_fptrs_t *fptrs, - jl_method_instance_t **linfos, size_t n) +extern "C" JL_DLLEXPORT +void jl_register_fptrs_impl(uint64_t sysimage_base, const jl_sysimg_fptrs_t *fptrs, + jl_method_instance_t **linfos, size_t n) { jl_sysimage_base = (uintptr_t)sysimage_base; sysimg_fptrs = *fptrs; @@ -1210,7 +1211,7 @@ int jl_DI_for_fptr(uint64_t fptr, uint64_t *symsize, int64_t *slide, } // Set *name and *filename to either NULL or malloc'd string -int jl_getFunctionInfo(jl_frame_t **frames_out, size_t pointer, int skipC, int noInline) JL_NOTSAFEPOINT +extern "C" JL_DLLEXPORT int jl_getFunctionInfo_impl(jl_frame_t **frames_out, size_t pointer, int skipC, int noInline) JL_NOTSAFEPOINT { // This function is not allowed to reference any TLS variables if noInline // since it can be called from an unmanaged thread on OSX. @@ -1650,8 +1651,8 @@ void deregister_eh_frames(uint8_t *Addr, size_t Size) #endif -extern "C" -uint64_t jl_getUnwindInfo(uint64_t dwAddr) +extern "C" JL_DLLEXPORT +uint64_t jl_getUnwindInfo_impl(uint64_t dwAddr) { // Might be called from unmanaged thread uv_rwlock_rdlock(&threadsafe); diff --git a/src/disasm.cpp b/src/disasm.cpp index f94459c8a6063..73b394b77d0b2 100644 --- a/src/disasm.cpp +++ b/src/disasm.cpp @@ -484,7 +484,7 @@ void jl_strip_llvm_addrspaces(Module *m) // print an llvm IR acquired from jl_get_llvmf // warning: this takes ownership of, and destroys, f->getParent() extern "C" JL_DLLEXPORT -jl_value_t *jl_dump_function_ir(void *f, char strip_ir_metadata, char dump_module, const char *debuginfo) +jl_value_t *jl_dump_function_ir_impl(void *f, char strip_ir_metadata, char dump_module, const char *debuginfo) { std::string code; raw_string_ostream stream(code); @@ -494,7 +494,7 @@ jl_value_t *jl_dump_function_ir(void *f, char strip_ir_metadata, char dump_modul if (!llvmf || (!llvmf->isDeclaration() && !llvmf->getParent())) jl_error("jl_dump_function_ir: Expected Function* in a temporary Module"); - JL_LOCK(&codegen_lock); // Might GC + JL_LOCK(&jl_codegen_lock); // Might GC LineNumberAnnotatedWriter AAW{"; ", false, debuginfo}; if (!llvmf->getParent()) { // print the function declaration as-is @@ -518,7 +518,7 @@ jl_value_t *jl_dump_function_ir(void *f, char strip_ir_metadata, char dump_modul } delete m; } - JL_UNLOCK(&codegen_lock); // Might GC + JL_UNLOCK(&jl_codegen_lock); // Might GC } return jl_pchar_to_string(stream.str().data(), stream.str().size()); @@ -567,7 +567,7 @@ static uint64_t compute_obj_symsize(object::SectionRef Section, uint64_t offset) // print a native disassembly for the function starting at fptr extern "C" JL_DLLEXPORT -jl_value_t *jl_dump_fptr_asm(uint64_t fptr, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) +jl_value_t *jl_dump_fptr_asm_impl(uint64_t fptr, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) { assert(fptr != 0); std::string code; @@ -1181,7 +1181,7 @@ class LineNumberPrinterHandler : public AsmPrinterHandler { // get a native assembly for llvm::Function extern "C" JL_DLLEXPORT -jl_value_t *jl_dump_function_asm(void *F, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) +jl_value_t *jl_dump_function_asm_impl(void *F, char raw_mc, const char* asm_variant, const char *debuginfo, char binary) { // precise printing via IR assembler SmallVector ObjBufferSV; @@ -1247,7 +1247,7 @@ jl_value_t *jl_dump_function_asm(void *F, char raw_mc, const char* asm_variant, } extern "C" JL_DLLEXPORT -LLVMDisasmContextRef jl_LLVMCreateDisasm( +LLVMDisasmContextRef jl_LLVMCreateDisasm_impl( const char *TripleName, void *DisInfo, int TagType, LLVMOpInfoCallback GetOpInfo, LLVMSymbolLookupCallback SymbolLookUp) { @@ -1255,7 +1255,7 @@ LLVMDisasmContextRef jl_LLVMCreateDisasm( } extern "C" JL_DLLEXPORT -JL_DLLEXPORT size_t jl_LLVMDisasmInstruction( +JL_DLLEXPORT size_t jl_LLVMDisasmInstruction_impl( LLVMDisasmContextRef DC, uint8_t *Bytes, uint64_t BytesSize, uint64_t PC, char *OutString, size_t OutStringSize) { diff --git a/src/dlload.c b/src/dlload.c index bb4d0a68e7dd9..f9e4ba857b1f8 100644 --- a/src/dlload.c +++ b/src/dlload.c @@ -70,8 +70,8 @@ static int endswith_extension(const char *path) JL_NOTSAFEPOINT #define CRTDLL_BASENAME "msvcrt" #endif -const char jl_crtdll_basename[] = CRTDLL_BASENAME; -const char jl_crtdll_name[] = CRTDLL_BASENAME ".dll"; +JL_DLLEXPORT const char *jl_crtdll_basename = CRTDLL_BASENAME; +const char *jl_crtdll_name = CRTDLL_BASENAME ".dll"; #undef CRTDLL_BASENAME #endif @@ -190,7 +190,7 @@ JL_DLLEXPORT void *jl_load_dynamic_library(const char *modname, unsigned flags, goto done; } - abspath = isabspath(modname); + abspath = jl_isabspath(modname); /* this branch permutes all base paths in DL_LOAD_PATH with all extensions @@ -320,7 +320,7 @@ JL_DLLEXPORT int jl_dlsym(void *handle, const char *symbol, void ** value, int t #ifdef _OS_WINDOWS_ //Look for symbols in win32 libraries -const char *jl_dlfind_win32(const char *f_name) +JL_DLLEXPORT const char *jl_dlfind_win32(const char *f_name) { void * dummy; if (jl_dlsym(jl_exe_handle, f_name, &dummy, 0)) diff --git a/src/dump.c b/src/dump.c index 0290d90ed94db..17d5ff3b58f66 100644 --- a/src/dump.c +++ b/src/dump.c @@ -2753,7 +2753,7 @@ void jl_init_serializer(void) htable_new(&backref_table, 0); void *vals[] = { jl_emptysvec, jl_emptytuple, jl_false, jl_true, jl_nothing, jl_any_type, - call_sym, invoke_sym, invoke_modify_sym, goto_ifnot_sym, return_sym, jl_symbol("tuple"), + jl_call_sym, jl_invoke_sym, jl_invoke_modify_sym, jl_goto_ifnot_sym, jl_return_sym, jl_symbol("tuple"), jl_an_empty_string, jl_an_empty_vec_any, // empirical list of very common symbols diff --git a/src/gc-debug.c b/src/gc-debug.c index ed09cff212ff8..712ccc31a195a 100644 --- a/src/gc-debug.c +++ b/src/gc-debug.c @@ -282,8 +282,8 @@ void gc_verify(jl_ptls_t ptls) } restore(); gc_verify_track(ptls); - gc_debug_print_status(); - gc_debug_critical_error(); + jl_gc_debug_print_status(); + jl_gc_debug_critical_error(); abort(); } #endif @@ -496,12 +496,12 @@ int gc_debug_check_pool(void) return gc_debug_alloc_check(&jl_gc_debug_env.pool); } -int gc_debug_check_other(void) +int jl_gc_debug_check_other(void) { return gc_debug_alloc_check(&jl_gc_debug_env.other); } -void gc_debug_print_status(void) +void jl_gc_debug_print_status(void) { uint64_t pool_count = jl_gc_debug_env.pool.num; uint64_t other_count = jl_gc_debug_env.other.num; @@ -510,9 +510,9 @@ void gc_debug_print_status(void) pool_count + other_count, pool_count, other_count, gc_num.pause); } -void gc_debug_critical_error(void) +void jl_gc_debug_critical_error(void) { - gc_debug_print_status(); + jl_gc_debug_print_status(); if (!jl_gc_debug_env.wait_for_debugger) return; jl_safe_printf("Waiting for debugger to attach\n"); @@ -521,11 +521,11 @@ void gc_debug_critical_error(void) } } -void gc_debug_print(void) +void jl_gc_debug_print(void) { if (!gc_debug_alloc_check(&jl_gc_debug_env.print)) return; - gc_debug_print_status(); + jl_gc_debug_print_status(); } // a list of tasks for conservative stack scan during gc_scrub @@ -607,11 +607,11 @@ void gc_scrub(void) jl_gc_debug_tasks.len = 0; } #else -void gc_debug_critical_error(void) +void jl_gc_debug_critical_error(void) { } -void gc_debug_print_status(void) +void jl_gc_debug_print_status(void) { // May not be accurate but should be helpful enough uint64_t pool_count = gc_num.poolalloc; @@ -979,7 +979,7 @@ void gc_time_sweep_pause(uint64_t gc_end_t, int64_t actual_allocd, } #endif -void gc_debug_init(void) +void jl_gc_debug_init(void) { #ifdef GC_DEBUG_ENV char *env = getenv("JULIA_GC_NO_GENERATIONAL"); diff --git a/src/gc.c b/src/gc.c index e92b96fa289ee..8df054c9b54d1 100644 --- a/src/gc.c +++ b/src/gc.c @@ -181,7 +181,7 @@ bigval_t *big_objects_marked = NULL; // `to_finalize` should not have tagged pointers. arraylist_t finalizer_list_marked; arraylist_t to_finalize; -int jl_gc_have_pending_finalizers = 0; +JL_DLLEXPORT int jl_gc_have_pending_finalizers = 0; NOINLINE uintptr_t gc_get_stack_ptr(void) { @@ -878,7 +878,7 @@ void jl_gc_force_mark_old(jl_ptls_t ptls, jl_value_t *v) JL_NOTSAFEPOINT static inline void maybe_collect(jl_ptls_t ptls) { - if (jl_atomic_load_relaxed(&ptls->gc_num.allocd) >= 0 || gc_debug_check_other()) { + if (jl_atomic_load_relaxed(&ptls->gc_num.allocd) >= 0 || jl_gc_debug_check_other()) { jl_gc_collect(JL_GC_AUTO); } else { @@ -1650,9 +1650,9 @@ JL_NORETURN NOINLINE void gc_assert_datatype_fail(jl_ptls_t ptls, jl_datatype_t jl_gc_mark_sp_t sp) { jl_safe_printf("GC error (probable corruption) :\n"); - gc_debug_print_status(); + jl_gc_debug_print_status(); jl_(vt); - gc_debug_critical_error(); + jl_gc_debug_critical_error(); gc_mark_loop_unwind(ptls, sp, 0); abort(); } @@ -3229,7 +3229,7 @@ JL_DLLEXPORT void jl_gc_collect(jl_gc_collection_t collection) jl_atomic_fetch_add((_Atomic(uint64_t)*)&gc_num.deferred_alloc, localbytes); return; } - gc_debug_print(); + jl_gc_debug_print(); int8_t old_state = jl_atomic_load_relaxed(&ptls->gc_state); jl_atomic_store_release(&ptls->gc_state, JL_GC_STATE_WAITING); @@ -3349,7 +3349,7 @@ void jl_init_thread_heap(jl_ptls_t ptls) void jl_gc_init(void) { jl_gc_init_page(); - gc_debug_init(); + jl_gc_debug_init(); arraylist_new(&finalizer_list_marked, 0); arraylist_new(&to_finalize, 0); diff --git a/src/gc.h b/src/gc.h index 19fe3401665d1..74eaf483f8451 100644 --- a/src/gc.h +++ b/src/gc.h @@ -517,7 +517,7 @@ void gc_mark_queue_finlist(jl_gc_mark_cache_t *gc_cache, jl_gc_mark_sp_t *sp, arraylist_t *list, size_t start); void gc_mark_loop(jl_ptls_t ptls, jl_gc_mark_sp_t sp); void sweep_stack_pools(void); -void gc_debug_init(void); +void jl_gc_debug_init(void); extern void *gc_mark_label_addrs[_GC_MARK_L_MAX]; @@ -646,14 +646,14 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, jl_gc_mark_sp_t sp, int pc_off #ifdef GC_DEBUG_ENV JL_DLLEXPORT extern jl_gc_debug_env_t jl_gc_debug_env; #define gc_sweep_always_full jl_gc_debug_env.always_full -int gc_debug_check_other(void); +int jl_gc_debug_check_other(void); int gc_debug_check_pool(void); -void gc_debug_print(void); +void jl_gc_debug_print(void); void gc_scrub_record_task(jl_task_t *ta) JL_NOTSAFEPOINT; void gc_scrub(void); #else #define gc_sweep_always_full 0 -static inline int gc_debug_check_other(void) +static inline int jl_gc_debug_check_other(void) { return 0; } @@ -661,7 +661,7 @@ static inline int gc_debug_check_pool(void) { return 0; } -static inline void gc_debug_print(void) +static inline void jl_gc_debug_print(void) { } static inline void gc_scrub_record_task(jl_task_t *ta) JL_NOTSAFEPOINT diff --git a/src/gf.c b/src/gf.c index ad6378cf2827c..ad50c8efc0e10 100644 --- a/src/gf.c +++ b/src/gf.c @@ -494,7 +494,7 @@ static void reset_mt_caches(jl_methtable_t *mt, void *env) jl_function_t *jl_typeinf_func = NULL; -size_t jl_typeinf_world = 1; +JL_DLLEXPORT size_t jl_typeinf_world = 1; JL_DLLEXPORT void jl_set_typeinf_func(jl_value_t *f) { @@ -2003,12 +2003,12 @@ jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *mi, size_t } -JL_DLLEXPORT jl_value_t *jl_fptr_const_return(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) +jl_value_t *jl_fptr_const_return(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) { return m->rettype_const; } -JL_DLLEXPORT jl_value_t *jl_fptr_args(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) +jl_value_t *jl_fptr_args(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) { while (1) { jl_fptr_args_t invoke = jl_atomic_load_relaxed(&m->specptr.fptr1); @@ -2017,7 +2017,7 @@ JL_DLLEXPORT jl_value_t *jl_fptr_args(jl_value_t *f, jl_value_t **args, uint32_t } } -JL_DLLEXPORT jl_value_t *jl_fptr_sparam(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) +jl_value_t *jl_fptr_sparam(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *m) { jl_svec_t *sparams = m->def->sparam_vals; assert(sparams != jl_emptysvec); @@ -2028,6 +2028,12 @@ JL_DLLEXPORT jl_value_t *jl_fptr_sparam(jl_value_t *f, jl_value_t **args, uint32 } } +JL_DLLEXPORT jl_callptr_t jl_fptr_args_addr = &jl_fptr_args; + +JL_DLLEXPORT jl_callptr_t jl_fptr_const_return_addr = &jl_fptr_const_return; + +JL_DLLEXPORT jl_callptr_t jl_fptr_sparam_addr = &jl_fptr_sparam; + // Return the index of the invoke api, if known JL_DLLEXPORT int32_t jl_invoke_api(jl_code_instance_t *codeinst) { @@ -3161,7 +3167,7 @@ int jl_has_concrete_subtype(jl_value_t *typ) // the best way to avoid acquisition priority // ordering violations //static jl_mutex_t typeinf_lock; -#define typeinf_lock codegen_lock +#define typeinf_lock jl_codegen_lock static uint64_t inference_start_time = 0; static uint8_t inference_is_measuring_compile_time = 0; diff --git a/src/init.c b/src/init.c index 49e61935100f8..6267cecb0d027 100644 --- a/src/init.c +++ b/src/init.c @@ -51,7 +51,7 @@ extern BOOL (WINAPI *hSymRefreshModuleList)(HANDLE); // list of modules being deserialized with __init__ methods jl_array_t *jl_module_init_order; -size_t jl_page_size; +JL_DLLEXPORT size_t jl_page_size; void jl_init_stack_limits(int ismaster, void **stack_lo, void **stack_hi) { @@ -295,14 +295,14 @@ static void post_boot_hooks(void); JL_DLLEXPORT void *jl_libjulia_internal_handle; JL_DLLEXPORT void *jl_libjulia_handle; -void *jl_RTLD_DEFAULT_handle; +JL_DLLEXPORT void *jl_RTLD_DEFAULT_handle; JL_DLLEXPORT void *jl_exe_handle; #ifdef _OS_WINDOWS_ void *jl_ntdll_handle; void *jl_kernel32_handle; void *jl_crtdll_handle; void *jl_winsock_handle; -extern const char jl_crtdll_name[]; +extern const char *jl_crtdll_name; #endif uv_loop_t *jl_io_loop; @@ -431,21 +431,7 @@ static void init_stdio(void) jl_flush_cstdio(); } -#ifdef JL_USE_INTEL_JITEVENTS -char jl_using_intel_jitevents; // Non-zero if running under Intel VTune Amplifier -#endif - -#ifdef JL_USE_OPROFILE_JITEVENTS -char jl_using_oprofile_jitevents = 0; // Non-zero if running under OProfile -#endif - -#ifdef JL_USE_PERF_JITEVENTS -char jl_using_perf_jitevents = 0; -#endif - -char jl_using_gdb_jitevents = 0; - -int isabspath(const char *in) JL_NOTSAFEPOINT +int jl_isabspath(const char *in) JL_NOTSAFEPOINT { #ifdef _OS_WINDOWS_ char c0 = in[0]; @@ -517,7 +503,7 @@ static char *abspath(const char *in, int nprefix) // unless `in` starts with `%` static const char *absformat(const char *in) { - if (in[0] == '%' || isabspath(in)) + if (in[0] == '%' || jl_isabspath(in)) return in; // get an escaped copy of cwd size_t path_size = PATH_MAX; @@ -572,7 +558,7 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel) free(free_path); free_path = NULL; if (jl_options.image_file) { - if (rel == JL_IMAGE_JULIA_HOME && !isabspath(jl_options.image_file)) { + if (rel == JL_IMAGE_JULIA_HOME && !jl_isabspath(jl_options.image_file)) { // build time path, relative to JULIA_BINDIR free_path = (char*)malloc_s(PATH_MAX); int n = snprintf(free_path, PATH_MAX, "%s" PATHSEPSTRING "%s", @@ -630,8 +616,12 @@ static void restore_fp_env(void) static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct); +JL_DLLEXPORT int jl_default_debug_info_kind; + JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel) { + jl_default_debug_info_kind = 0; + jl_init_timing(); // Make sure we finalize the tls callback before starting any threads. (void)jl_get_pgcstack(); @@ -684,39 +674,6 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel) #endif #endif -#if defined(JL_USE_INTEL_JITEVENTS) || \ - defined(JL_USE_OPROFILE_JITEVENTS) || \ - defined(JL_USE_PERF_JITEVENTS) - const char *jit_profiling = getenv("ENABLE_JITPROFILING"); -#endif - -#if defined(JL_USE_INTEL_JITEVENTS) - if (jit_profiling && atoi(jit_profiling)) { - jl_using_intel_jitevents = 1; - } -#endif - -#if defined(JL_USE_OPROFILE_JITEVENTS) - if (jit_profiling && atoi(jit_profiling)) { - jl_using_oprofile_jitevents = 1; - } -#endif - -#if defined(JL_USE_PERF_JITEVENTS) - if (jit_profiling && atoi(jit_profiling)) { - jl_using_perf_jitevents= 1; - } -#endif - -#if defined(JL_DEBUG_BUILD) - jl_using_gdb_jitevents = 1; -# else - const char *jit_gdb = getenv("ENABLE_GDBLISTENER"); - if (jit_gdb && atoi(jit_gdb)) { - jl_using_gdb_jitevents = 1; - } -#endif - if ((jl_options.outputo || jl_options.outputbc || jl_options.outputasm) && (jl_options.code_coverage || jl_options.malloc_log)) { jl_error("cannot generate code-coverage or track allocation information while generating a .o, .bc, or .s output file"); diff --git a/src/interpreter.c b/src/interpreter.c index 50946a666ab0c..a7afc996f6ca4 100644 --- a/src/interpreter.c +++ b/src/interpreter.c @@ -211,16 +211,16 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) jl_value_t **args = jl_array_ptr_data(ex->args); size_t nargs = jl_array_len(ex->args); jl_sym_t *head = ex->head; - if (head == call_sym) { + if (head == jl_call_sym) { return do_call(args, nargs, s); } - else if (head == invoke_sym) { + else if (head == jl_invoke_sym) { return do_invoke(args, nargs, s); } - else if (head == invoke_modify_sym) { + else if (head == jl_invoke_modify_sym) { return do_call(args + 1, nargs - 1, s); } - else if (head == isdefined_sym) { + else if (head == jl_isdefined_sym) { jl_value_t *sym = args[0]; int defined = 0; if (jl_is_slot(sym) || jl_is_argument(sym)) { @@ -235,7 +235,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) else if (jl_is_symbol(sym)) { defined = jl_boundp(s->module, (jl_sym_t*)sym); } - else if (jl_is_expr(sym) && ((jl_expr_t*)sym)->head == static_parameter_sym) { + else if (jl_is_expr(sym) && ((jl_expr_t*)sym)->head == jl_static_parameter_sym) { ssize_t n = jl_unbox_long(jl_exprarg(sym, 0)); assert(n > 0); if (s->sparam_vals && n <= jl_svec_len(s->sparam_vals)) { @@ -252,19 +252,19 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) } return defined ? jl_true : jl_false; } - else if (head == throw_undef_if_not_sym) { + else if (head == jl_throw_undef_if_not_sym) { jl_value_t *cond = eval_value(args[1], s); assert(jl_is_bool(cond)); if (cond == jl_false) { jl_sym_t *var = (jl_sym_t*)args[0]; - if (var == getfield_undefref_sym) + if (var == jl_getfield_undefref_sym) jl_throw(jl_undefref_exception); else jl_undefined_var_error(var); } return jl_nothing; } - else if (head == new_sym) { + else if (head == jl_new_sym) { jl_value_t **argv; JL_GC_PUSHARGS(argv, nargs); for (size_t i = 0; i < nargs; i++) @@ -273,7 +273,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) JL_GC_POP(); return v; } - else if (head == splatnew_sym) { + else if (head == jl_splatnew_sym) { jl_value_t **argv; JL_GC_PUSHARGS(argv, 2); argv[0] = eval_value(args[0], s); @@ -282,7 +282,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) JL_GC_POP(); return v; } - else if (head == new_opaque_closure_sym) { + else if (head == jl_new_opaque_closure_sym) { jl_value_t **argv; JL_GC_PUSHARGS(argv, nargs); for (size_t i = 0; i < nargs; i++) @@ -293,7 +293,7 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) JL_GC_POP(); return ret; } - else if (head == static_parameter_sym) { + else if (head == jl_static_parameter_sym) { ssize_t n = jl_unbox_long(args[0]); assert(n > 0); if (s->sparam_vals && n <= jl_svec_len(s->sparam_vals)) { @@ -305,28 +305,34 @@ static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s) // static parameter val unknown needs to be an error for ccall jl_error("could not determine static parameter value"); } - else if (head == copyast_sym) { + else if (head == jl_copyast_sym) { return jl_copy_ast(eval_value(args[0], s)); } - else if (head == exc_sym) { + else if (head == jl_exc_sym) { return jl_current_exception(); } - else if (head == boundscheck_sym) { + else if (head == jl_boundscheck_sym) { return jl_true; } - else if (head == meta_sym || head == coverageeffect_sym || head == inbounds_sym || head == loopinfo_sym || - head == aliasscope_sym || head == popaliasscope_sym || head == inline_sym || head == noinline_sym) { + else if (head == jl_meta_sym || head == jl_coverageeffect_sym || head == jl_inbounds_sym || head == jl_loopinfo_sym || + head == jl_aliasscope_sym || head == jl_popaliasscope_sym || head == jl_inline_sym || head == jl_noinline_sym) { return jl_nothing; } - else if (head == gc_preserve_begin_sym || head == gc_preserve_end_sym) { + else if (head == jl_gc_preserve_begin_sym || head == jl_gc_preserve_end_sym) { // The interpreter generally keeps values that were assigned in this scope // rooted. If the interpreter learns to be more aggressive here, we may // want to explicitly root these values. return jl_nothing; } - else if (head == method_sym && nargs == 1) { + else if (head == jl_method_sym && nargs == 1) { return eval_methoddef(ex, s); } + else if (head == jl_foreigncall_sym) { + jl_error("`ccall` requires the compiler"); + } + else if (head == jl_cfunction_sym) { + jl_error("`cfunction` requires the compiler"); + } jl_errorf("unsupported or misplaced expression %s", jl_symbol_name(head)); abort(); } @@ -456,7 +462,7 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, else if (jl_is_expr(stmt)) { // Most exprs are allowed to end a BB by fall through jl_sym_t *head = ((jl_expr_t*)stmt)->head; - if (head == assign_sym) { + if (head == jl_assign_sym) { jl_value_t *lhs = jl_exprarg(stmt, 0); jl_value_t *rhs = eval_value(jl_exprarg(stmt, 1), s); if (jl_is_slot(lhs)) { @@ -482,7 +488,7 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, JL_GC_POP(); } } - else if (head == enter_sym) { + else if (head == jl_enter_sym) { jl_enter_handler(&__eh); // This is a bit tricky, but supports the implementation of PhiC nodes. // They are conceptually slots, but the slot to store to doesn't get explicitly @@ -525,7 +531,7 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, continue; } } - else if (head == leave_sym) { + else if (head == jl_leave_sym) { int hand_n_leave = jl_unbox_long(jl_exprarg(stmt, 0)); assert(hand_n_leave > 0); // equivalent to jl_pop_handler(hand_n_leave), but retaining eh for longjmp: @@ -538,41 +544,41 @@ static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, s->continue_at = next_ip; jl_longjmp(eh->eh_ctx, 1); } - else if (head == pop_exception_sym) { + else if (head == jl_pop_exception_sym) { size_t prev_state = jl_unbox_ulong(eval_value(jl_exprarg(stmt, 0), s)); jl_restore_excstack(prev_state); } else if (toplevel) { - if (head == method_sym && jl_expr_nargs(stmt) > 1) { + if (head == jl_method_sym && jl_expr_nargs(stmt) > 1) { eval_methoddef((jl_expr_t*)stmt, s); } - else if (head == toplevel_sym) { + else if (head == jl_toplevel_sym) { jl_value_t *res = jl_toplevel_eval(s->module, stmt); s->locals[jl_source_nslots(s->src) + s->ip] = res; } else if (jl_is_toplevel_only_expr(stmt)) { jl_toplevel_eval(s->module, stmt); } - else if (head == meta_sym) { - if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)nospecialize_sym) { + else if (head == jl_meta_sym) { + if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)jl_nospecialize_sym) { jl_set_module_nospecialize(s->module, 1); } - if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)specialize_sym) { + if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)jl_specialize_sym) { jl_set_module_nospecialize(s->module, 0); } if (jl_expr_nargs(stmt) == 2) { - if (jl_exprarg(stmt, 0) == (jl_value_t*)optlevel_sym) { + if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_optlevel_sym) { if (jl_is_long(jl_exprarg(stmt, 1))) { int n = jl_unbox_long(jl_exprarg(stmt, 1)); jl_set_module_optlevel(s->module, n); } } - else if (jl_exprarg(stmt, 0) == (jl_value_t*)compile_sym) { + else if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_compile_sym) { if (jl_is_long(jl_exprarg(stmt, 1))) { jl_set_module_compile(s->module, jl_unbox_long(jl_exprarg(stmt, 1))); } } - else if (jl_exprarg(stmt, 0) == (jl_value_t*)infer_sym) { + else if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_infer_sym) { if (jl_is_long(jl_exprarg(stmt, 1))) { jl_set_module_infer(s->module, jl_unbox_long(jl_exprarg(stmt, 1))); } @@ -677,6 +683,8 @@ jl_value_t *NOINLINE jl_fptr_interpret_call(jl_value_t *f, jl_value_t **args, ui return r; } +JL_DLLEXPORT jl_callptr_t jl_fptr_interpret_call_addr = &jl_fptr_interpret_call; + jl_value_t *jl_interpret_opaque_closure(jl_opaque_closure_t *oc, jl_value_t **args, size_t nargs) { jl_method_t *source = oc->source; diff --git a/src/intrinsics.cpp b/src/intrinsics.cpp index 1f74f0059b4d1..6ac02c79f7bf4 100644 --- a/src/intrinsics.cpp +++ b/src/intrinsics.cpp @@ -70,7 +70,7 @@ static void jl_init_intrinsic_functions_codegen(void) } extern "C" -JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION(void) +JL_DLLEXPORT uint32_t jl_get_LLVM_VERSION_impl(void) { return 10000 * LLVM_VERSION_MAJOR + 100 * LLVM_VERSION_MINOR #ifdef LLVM_VERSION_PATCH @@ -1477,200 +1477,3 @@ static Value *emit_untyped_intrinsic(jl_codectx_t &ctx, intrinsic f, Value **arg } assert(0 && "unreachable"); } - - -// float16 intrinsics -// TODO: use LLVM's compiler-rt - -static inline float half_to_float(uint16_t ival) -{ - uint32_t sign = (ival & 0x8000) >> 15; - uint32_t exp = (ival & 0x7c00) >> 10; - uint32_t sig = (ival & 0x3ff) >> 0; - uint32_t ret; - - if (exp == 0) { - if (sig == 0) { - sign = sign << 31; - ret = sign | exp | sig; - } - else { - int n_bit = 1; - uint16_t bit = 0x0200; - while ((bit & sig) == 0) { - n_bit = n_bit + 1; - bit = bit >> 1; - } - sign = sign << 31; - exp = ((-14 - n_bit + 127) << 23); - sig = ((sig & (~bit)) << n_bit) << (23 - 10); - ret = sign | exp | sig; - } - } - else if (exp == 0x1f) { - if (sig == 0) { // Inf - if (sign == 0) - ret = 0x7f800000; - else - ret = 0xff800000; - } - else // NaN - ret = 0x7fc00000 | (sign << 31) | (sig << (23 - 10)); - } - else { - sign = sign << 31; - exp = ((exp - 15 + 127) << 23); - sig = sig << (23 - 10); - ret = sign | exp | sig; - } - - float fret; - memcpy(&fret, &ret, sizeof(float)); - return fret; -} - -// float to half algorithm from: -// "Fast Half Float Conversion" by Jeroen van der Zijp -// ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf -// -// With adjustments for round-to-nearest, ties to even. - -static uint16_t basetable[512] = { - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, - 0x0000, 0x0000, 0x0000, 0x0400, 0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00, 0x2000, - 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00, 0x4000, 0x4400, 0x4800, 0x4c00, - 0x5000, 0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00, 0x7000, 0x7400, 0x7800, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, - 0x7c00, 0x7c00, 0x7c00, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, - 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8400, 0x8800, 0x8c00, 0x9000, 0x9400, - 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00, 0xb000, 0xb400, 0xb800, 0xbc00, 0xc000, - 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400, 0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, - 0xf000, 0xf400, 0xf800, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, - 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00}; - -static uint8_t shifttable[512] = { - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, - 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, - 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, - 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x0d, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, - 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, - 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, - 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, - 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, - 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0d}; - -static inline uint16_t float_to_half(float param) -{ - uint32_t f; - memcpy(&f, ¶m, sizeof(float)); - if (isnan(param)) { - uint32_t t = 0x8000 ^ (0x8000 & ((uint16_t)(f >> 0x10))); - return t ^ ((uint16_t)(f >> 0xd)); - } - int i = ((f & ~0x007fffff) >> 23); - uint8_t sh = shifttable[i]; - f &= 0x007fffff; - // If `val` is subnormal, the tables are set up to force the - // result to 0, so the significand has an implicit `1` in the - // cases we care about. - f |= 0x007fffff + 0x1; - uint16_t h = (uint16_t)(basetable[i] + ((f >> sh) & 0x03ff)); - // round - // NOTE: we maybe should ignore NaNs here, but the payload is - // getting truncated anyway so "rounding" it might not matter - int nextbit = (f >> (sh - 1)) & 1; - if (nextbit != 0 && (h & 0x7C00) != 0x7C00) { - // Round halfway to even or check lower bits - if ((h & 1) == 1 || (f & ((1 << (sh - 1)) - 1)) != 0) - h += UINT16_C(1); - } - return h; -} - -#if !defined(_OS_DARWIN_) // xcode already links compiler-rt - -extern "C" JL_DLLEXPORT float __gnu_h2f_ieee(uint16_t param) -{ - return half_to_float(param); -} - -extern "C" JL_DLLEXPORT float __extendhfsf2(uint16_t param) -{ - return half_to_float(param); -} - -extern "C" JL_DLLEXPORT uint16_t __gnu_f2h_ieee(float param) -{ - return float_to_half(param); -} - -extern "C" JL_DLLEXPORT uint16_t __truncdfhf2(double param) -{ - return float_to_half((float)param); -} - -#endif diff --git a/src/ircode.c b/src/ircode.c index 414c80213d5a4..408301734b576 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -151,7 +151,7 @@ static void jl_encode_value_(jl_ircode_state *s, jl_value_t *v, int as_literal) else if (jl_is_expr(v)) { jl_expr_t *e = (jl_expr_t*)v; size_t l = jl_array_len(e->args); - if (e->head == call_sym) { + if (e->head == jl_call_sym) { if (l == 2) { write_uint8(s->s, TAG_CALL1); jl_encode_value(s, jl_exprarg(e, 0)); @@ -486,11 +486,11 @@ static jl_value_t *jl_decode_value_expr(jl_ircode_state *s, uint8_t tag) JL_GC_D } else if (tag == TAG_CALL1) { len = 2; - head = call_sym; + head = jl_call_sym; } else if (tag == TAG_CALL2) { len = 3; - head = call_sym; + head = jl_call_sym; } else { len = read_int32(s->s); diff --git a/src/jitlayers.cpp b/src/jitlayers.cpp index c0283fce21dac..1708fe50115f2 100644 --- a/src/jitlayers.cpp +++ b/src/jitlayers.cpp @@ -37,7 +37,7 @@ void jl_init_jit(void) { } // Snooping on which functions are being compiled, and how long it takes JL_STREAM *dump_compiles_stream = NULL; extern "C" JL_DLLEXPORT -void jl_dump_compiles(void *s) +void jl_dump_compiles_impl(void *s) { dump_compiles_stream = (JL_STREAM*)s; } @@ -76,21 +76,6 @@ void jl_jit_globals(std::map &globals) } } -extern "C" JL_DLLEXPORT -uint64_t jl_cumulative_compile_time_ns_before() -{ - // Increment the flag to allow reentrant callers to `@time`. - jl_atomic_fetch_add(&jl_measure_compile_time_enabled, 1); - return jl_atomic_load_relaxed(&jl_cumulative_compile_time); -} -extern "C" JL_DLLEXPORT -uint64_t jl_cumulative_compile_time_ns_after() -{ - // Decrement the flag when done measuring, allowing other callers to continue measuring. - jl_atomic_fetch_add(&jl_measure_compile_time_enabled, -1); - return jl_atomic_load_relaxed(&jl_cumulative_compile_time); -} - // this generates llvm code for the lambda info // and adds the result to the jitlayers // (and the shadow module), @@ -163,10 +148,10 @@ static jl_callptr_t _jl_compile_codeinst( jl_callptr_t addr; bool isspecsig = false; if (decls.functionObject == "jl_fptr_args") { - addr = &jl_fptr_args; + addr = jl_fptr_args_addr; } else if (decls.functionObject == "jl_fptr_sparam") { - addr = &jl_fptr_sparam; + addr = jl_fptr_sparam_addr; } else { addr = (jl_callptr_t)getAddressForFunction(decls.functionObject); @@ -181,7 +166,7 @@ static jl_callptr_t _jl_compile_codeinst( } jl_atomic_store_release(&this_code->invoke, addr); } - else if (this_code->invoke == jl_fptr_const_return && !decls.specFunctionObject.empty()) { + else if (this_code->invoke == jl_fptr_const_return_addr && !decls.specFunctionObject.empty()) { // hack to export this pointer value to jl_dump_method_disasm jl_atomic_store_release(&this_code->specptr.fptr, (void*)getAddressForFunction(decls.specFunctionObject)); } @@ -229,10 +214,10 @@ static jl_callptr_t _jl_compile_codeinst( const char *jl_generate_ccallable(void *llvmmod, void *sysimg_handle, jl_value_t *declrt, jl_value_t *sigt, jl_codegen_params_t ¶ms); // compile a C-callable alias -extern "C" -int jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt, jl_value_t *sigt) +extern "C" JL_DLLEXPORT +int jl_compile_extern_c_impl(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt, jl_value_t *sigt) { - JL_LOCK(&codegen_lock); + JL_LOCK(&jl_codegen_lock); uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -259,15 +244,15 @@ int jl_compile_extern_c(void *llvmmod, void *p, void *sysimg, jl_value_t *declrt if (success && llvmmod == NULL) jl_add_to_ee(std::unique_ptr(into)); } - if (codegen_lock.count == 1 && measure_compile_time_enabled) + if (jl_codegen_lock.count == 1 && measure_compile_time_enabled) jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); - JL_UNLOCK(&codegen_lock); + JL_UNLOCK(&jl_codegen_lock); return success; } // declare a C-callable entry point; called during code loading from the toplevel extern "C" JL_DLLEXPORT -void jl_extern_c(jl_value_t *declrt, jl_tupletype_t *sigt) +void jl_extern_c_impl(jl_value_t *declrt, jl_tupletype_t *sigt) { // validate arguments. try to do as many checks as possible here to avoid // throwing errors later during codegen. @@ -282,10 +267,10 @@ void jl_extern_c(jl_value_t *declrt, jl_tupletype_t *sigt) // compute / validate return type if (!jl_is_concrete_type(declrt) || jl_is_kind(declrt)) jl_error("@ccallable: return type must be concrete and correspond to a C type"); - JL_LOCK(&codegen_lock); + JL_LOCK(&jl_codegen_lock); if (!jl_type_mappable_to_c(declrt)) jl_error("@ccallable: return type doesn't correspond to a C type"); - JL_UNLOCK(&codegen_lock); + JL_UNLOCK(&jl_codegen_lock); // validate method signature size_t i, nargs = jl_nparams(sigt); @@ -311,10 +296,10 @@ void jl_extern_c(jl_value_t *declrt, jl_tupletype_t *sigt) } // this compiles li and emits fptr -extern "C" -jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world) +extern "C" JL_DLLEXPORT +jl_code_instance_t *jl_generate_fptr_impl(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world) { - JL_LOCK(&codegen_lock); // also disables finalizers, to prevent any unexpected recursion + JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -355,20 +340,20 @@ jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT else { codeinst = NULL; } - if (codegen_lock.count == 1 && measure_compile_time_enabled) + if (jl_codegen_lock.count == 1 && measure_compile_time_enabled) jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); - JL_UNLOCK(&codegen_lock); + JL_UNLOCK(&jl_codegen_lock); JL_GC_POP(); return codeinst; } -extern "C" -void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec) +extern "C" JL_DLLEXPORT +void jl_generate_fptr_for_unspecialized_impl(jl_code_instance_t *unspec) { if (jl_atomic_load_relaxed(&unspec->invoke) != NULL) { return; } - JL_LOCK(&codegen_lock); + JL_LOCK(&jl_codegen_lock); uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -395,19 +380,19 @@ void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec) _jl_compile_codeinst(unspec, src, unspec->min_world); if (unspec->invoke == NULL) { // if we hit a codegen bug (or ran into a broken generated function or llvmcall), fall back to the interpreter as a last resort - jl_atomic_store_release(&unspec->invoke, &jl_fptr_interpret_call); + jl_atomic_store_release(&unspec->invoke, jl_fptr_interpret_call_addr); } JL_GC_POP(); } - if (codegen_lock.count == 1 && measure_compile_time_enabled) + if (jl_codegen_lock.count == 1 && measure_compile_time_enabled) jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); - JL_UNLOCK(&codegen_lock); // Might GC + JL_UNLOCK(&jl_codegen_lock); // Might GC } // get a native disassembly for a compiled method extern "C" JL_DLLEXPORT -jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world, +jl_value_t *jl_dump_method_asm_impl(jl_method_instance_t *mi, size_t world, char raw_mc, char getwrapper, const char* asm_variant, const char *debuginfo, char binary) { // printing via disassembly @@ -417,11 +402,11 @@ jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world, if (getwrapper) return jl_dump_fptr_asm(fptr, raw_mc, asm_variant, debuginfo, binary); uintptr_t specfptr = (uintptr_t)jl_atomic_load_relaxed(&codeinst->specptr.fptr); - if (fptr == (uintptr_t)&jl_fptr_const_return && specfptr == 0) { + if (fptr == (uintptr_t)jl_fptr_const_return_addr && specfptr == 0) { // normally we prevent native code from being generated for these functions, // (using sentinel value `1` instead) // so create an exception here so we can print pretty our lies - JL_LOCK(&codegen_lock); // also disables finalizers, to prevent any unexpected recursion + JL_LOCK(&jl_codegen_lock); // also disables finalizers, to prevent any unexpected recursion uint64_t compiler_start_time = 0; uint8_t measure_compile_time_enabled = jl_atomic_load_relaxed(&jl_measure_compile_time_enabled); if (measure_compile_time_enabled) @@ -442,7 +427,7 @@ jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world, fptr = (uintptr_t)jl_atomic_load_relaxed(&codeinst->invoke); specfptr = (uintptr_t)jl_atomic_load_relaxed(&codeinst->specptr.fptr); if (src && jl_is_code_info(src)) { - if (fptr == (uintptr_t)&jl_fptr_const_return && specfptr == 0) { + if (fptr == (uintptr_t)jl_fptr_const_return_addr && specfptr == 0) { fptr = (uintptr_t)_jl_compile_codeinst(codeinst, src, world); specfptr = (uintptr_t)jl_atomic_load_relaxed(&codeinst->specptr.fptr); } @@ -451,7 +436,7 @@ jl_value_t *jl_dump_method_asm(jl_method_instance_t *mi, size_t world, } if (measure_compile_time_enabled) jl_atomic_fetch_add_relaxed(&jl_cumulative_compile_time, (jl_hrtime() - compiler_start_time)); - JL_UNLOCK(&codegen_lock); + JL_UNLOCK(&jl_codegen_lock); } if (specfptr != 0) return jl_dump_fptr_asm(specfptr, raw_mc, asm_variant, debuginfo, binary); @@ -840,10 +825,10 @@ StringRef JuliaOJIT::getFunctionAtAddress(uint64_t Addr, jl_code_instance_t *cod if (Addr == (uintptr_t)invoke) { stream_fname << "jsysw_"; } - else if (invoke == &jl_fptr_args) { + else if (invoke == jl_fptr_args_addr) { stream_fname << "jsys1_"; } - else if (invoke == &jl_fptr_sparam) { + else if (invoke == jl_fptr_sparam_addr) { stream_fname << "jsys3_"; } else { diff --git a/src/jitlayers.h b/src/jitlayers.h index 89aaa7c94fec1..4922c08538f45 100644 --- a/src/jitlayers.h +++ b/src/jitlayers.h @@ -16,6 +16,8 @@ using namespace llvm; +extern "C" jl_cgparams_t jl_default_cgparams; + extern TargetMachine *jl_TargetMachine; extern bool imaging_mode; diff --git a/src/jl_exported_data.inc b/src/jl_exported_data.inc index 83860a50a8ce3..588d2a831e225 100644 --- a/src/jl_exported_data.inc +++ b/src/jl_exported_data.inc @@ -123,7 +123,7 @@ XX(jl_vecelement_typename) \ XX(jl_voidpointer_type) \ XX(jl_void_type) \ - XX(jl_weakref_type) \ + XX(jl_weakref_type) // Data symbols that are defined inside the public libjulia #define JL_EXPORTED_DATA_SYMBOLS(XX) \ diff --git a/src/jl_exported_funcs.inc b/src/jl_exported_funcs.inc index f343df4291a4b..38a3da08f0b28 100644 --- a/src/jl_exported_funcs.inc +++ b/src/jl_exported_funcs.inc @@ -1,8 +1,7 @@ // This file is a part of Julia. License is MIT: https://julialang.org/license -#define JL_EXPORTED_FUNCS(XX) \ +#define JL_RUNTIME_EXPORTED_FUNCS(XX) \ XX(jl_active_task_stack) \ - XX(jl_add_optimization_passes) \ XX(jl_add_standard_imports) \ XX(jl_alignment) \ XX(jl_alloc_array_1d) \ @@ -94,7 +93,6 @@ XX(jl_cglobal_auto) \ XX(jl_checked_assignment) \ XX(jl_clear_implicit_imports) \ - XX(jl_clear_malloc_data) \ XX(jl_close_uv) \ XX(jl_code_for_staged) \ XX(jl_compile_hint) \ @@ -105,7 +103,6 @@ XX(jl_copy_code_info) \ XX(jl_cpu_threads) \ XX(jl_crc32c_sw) \ - XX(jl_create_native) \ XX(jl_create_system_image) \ XX(jl_cstr_to_string) \ XX(jl_current_exception) \ @@ -116,12 +113,7 @@ XX(jl_dlclose) \ XX(jl_dlopen) \ XX(jl_dlsym) \ - XX(jl_dump_compiles) \ - XX(jl_dump_fptr_asm) \ - XX(jl_dump_function_asm) \ - XX(jl_dump_function_ir) \ XX(jl_dump_host_cpu) \ - XX(jl_dump_method_asm) \ XX(jl_egal__bits) \ XX(jl_egal__special) \ XX(jl_eh_restore_state) \ @@ -152,7 +144,6 @@ XX(jl_expand_stmt_with_loc) \ XX(jl_expand_with_loc) \ XX(jl_expand_with_loc_warn) \ - XX(jl_extern_c) \ XX(jl_field_index) \ XX(jl_gc_add_finalizer) \ XX(jl_gc_add_finalizer_th) \ @@ -218,7 +209,6 @@ XX(jl_get_fenv_consts) \ XX(jl_get_field) \ XX(jl_get_field_offset) \ - XX(jl_get_function_id) \ XX(jl_get_global) \ XX(jl_get_image_file) \ XX(jl_get_JIT) \ @@ -226,11 +216,6 @@ XX(jl_get_julia_bindir) \ XX(jl_get_keyword_sorter) \ XX(jl_get_kwsorter) \ - XX(jl_get_llvm_context) \ - XX(jl_get_llvmf_defn) \ - XX(jl_get_llvm_function) \ - XX(jl_get_llvm_module) \ - XX(jl_get_LLVM_VERSION) \ XX(jl_get_method_inferred) \ XX(jl_get_module_binding) \ XX(jl_get_module_compile) \ @@ -498,7 +483,6 @@ XX(jl_typename_str) \ XX(jl_typeof_str) \ XX(jl_types_equal) \ - XX(jl_type_to_llvm) \ XX(jl_type_union) \ XX(jl_type_unionall) \ XX(jl_unbox_bool) \ @@ -529,5 +513,41 @@ XX(jl_wakeup_thread) \ XX(jl_yield) \ -#define JL_EXPORTED_FUNCS_WIN(XX) \ +#define JL_RUNTIME_EXPORTED_FUNCS_WIN(XX) \ XX(jl_setjmp) + +// use YY instead of XX to avoid jl -> ijl renaming in libjulia-codegen +#define JL_CODEGEN_EXPORTED_FUNCS(YY) \ + YY(jl_clear_malloc_data) \ + YY(jl_dump_function_ir) \ + YY(jl_dump_method_asm) \ + YY(jl_extern_c) \ + YY(jl_get_llvm_context) \ + YY(jl_get_llvmf_defn) \ + YY(jl_get_llvm_function) \ + YY(jl_get_llvm_module) \ + YY(jl_get_LLVM_VERSION) \ + YY(jl_dump_native) \ + YY(jl_get_llvm_gv) \ + YY(jl_write_malloc_log) \ + YY(jl_write_coverage_data) \ + YY(jl_dump_function_asm) \ + YY(jl_LLVMCreateDisasm) \ + YY(jl_LLVMDisasmInstruction) \ + YY(jl_init_codegen) \ + YY(jl_getFunctionInfo) \ + YY(jl_register_fptrs) \ + YY(jl_generate_fptr) \ + YY(jl_generate_fptr_for_unspecialized) \ + YY(jl_compile_extern_c) \ + YY(jl_teardown_codegen) \ + YY(jl_lock_profile) \ + YY(jl_unlock_profile) \ + YY(jl_create_native) \ + YY(jl_dump_compiles) \ + YY(jl_dump_fptr_asm) \ + YY(jl_get_function_id) \ + YY(jl_type_to_llvm) \ + YY(jl_getUnwindInfo) \ + YY(jl_get_libllvm) \ + diff --git a/src/jlapi.c b/src/jlapi.c index e3c5938d30abf..65d1feab6b4e3 100644 --- a/src/jlapi.c +++ b/src/jlapi.c @@ -475,6 +475,20 @@ JL_DLLEXPORT void (jl_cpu_wake)(void) jl_cpu_wake(); } +JL_DLLEXPORT uint64_t jl_cumulative_compile_time_ns_before(void) +{ + // Increment the flag to allow reentrant callers to `@time`. + jl_atomic_fetch_add(&jl_measure_compile_time_enabled, 1); + return jl_atomic_load_relaxed(&jl_cumulative_compile_time); +} + +JL_DLLEXPORT uint64_t jl_cumulative_compile_time_ns_after(void) +{ + // Decrement the flag when done measuring, allowing other callers to continue measuring. + jl_atomic_fetch_add(&jl_measure_compile_time_enabled, -1); + return jl_atomic_load_relaxed(&jl_cumulative_compile_time); +} + JL_DLLEXPORT void jl_get_fenv_consts(int *ret) { ret[0] = FE_INEXACT; diff --git a/src/jloptions.c b/src/jloptions.c index 5226da2884750..294fb7dd39aef 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -27,7 +27,6 @@ JL_DLLEXPORT const char *jl_get_default_sysimg_path(void) return &system_image_path[1]; } - static int jl_options_initialized = 0; JL_DLLEXPORT void jl_init_options(void) diff --git a/src/julia.expmap b/src/julia.expmap index ddf09cf6e474b..9c21fff9963f7 100644 --- a/src/julia.expmap +++ b/src/julia.expmap @@ -13,6 +13,7 @@ int64hash; int64to32hash; ios_*; + small_arraylist_grow; iswprint; jl_*; ijl_*; @@ -34,7 +35,6 @@ utf8proc_*; jlbacktrace; jlbacktracet; - julia_type_to_llvm; _IO_stdin_used; __ZN4llvm23createLowerSimdLoopPassEv; LLVMExtra*; diff --git a/src/julia.h b/src/julia.h index 0dec28f9b22df..1651b236c82a6 100644 --- a/src/julia.h +++ b/src/julia.h @@ -225,15 +225,19 @@ typedef jl_call_t *jl_callptr_t; // "speccall" calling convention signatures. // This describes some of the special ABI used by compiled julia functions. -JL_DLLEXPORT extern jl_call_t jl_fptr_args; +extern jl_call_t jl_fptr_args; +JL_DLLEXPORT extern jl_callptr_t jl_fptr_args_addr; typedef jl_value_t *(*jl_fptr_args_t)(jl_value_t*, jl_value_t**, uint32_t); -JL_DLLEXPORT extern jl_call_t jl_fptr_const_return; +extern jl_call_t jl_fptr_const_return; +JL_DLLEXPORT extern jl_callptr_t jl_fptr_const_return_addr; -JL_DLLEXPORT extern jl_call_t jl_fptr_sparam; +extern jl_call_t jl_fptr_sparam; +JL_DLLEXPORT extern jl_callptr_t jl_fptr_sparam_addr; typedef jl_value_t *(*jl_fptr_sparam_t)(jl_value_t*, jl_value_t**, uint32_t, jl_svec_t*); -JL_DLLEXPORT extern jl_call_t jl_fptr_interpret_call; +extern jl_call_t jl_fptr_interpret_call; +JL_DLLEXPORT extern jl_callptr_t jl_fptr_interpret_call_addr; typedef struct _jl_method_instance_t jl_method_instance_t; @@ -674,7 +678,7 @@ extern JL_DLLIMPORT jl_datatype_t *jl_initerror_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_typeerror_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_methoderror_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_undefvarerror_type JL_GLOBALLY_ROOTED; -extern JL_DLLEXPORT jl_datatype_t *jl_atomicerror_type JL_GLOBALLY_ROOTED; +extern JL_DLLIMPORT jl_datatype_t *jl_atomicerror_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_datatype_t *jl_lineinfonode_type JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_value_t *jl_stackovf_exception JL_GLOBALLY_ROOTED; extern JL_DLLIMPORT jl_value_t *jl_memory_exception JL_GLOBALLY_ROOTED; @@ -2134,7 +2138,6 @@ typedef struct { // generic_context(f, args...) instead of f(args...). jl_value_t *generic_context; } jl_cgparams_t; -extern JL_DLLEXPORT jl_cgparams_t jl_default_cgparams; extern JL_DLLEXPORT int jl_default_debug_info_kind; #ifdef __cplusplus diff --git a/src/julia_internal.h b/src/julia_internal.h index 6153f3e48820f..96fb6cc276bdd 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -99,6 +99,8 @@ void __tsan_switch_to_fiber(void *fiber, unsigned flags); #endif #endif +extern JL_DLLEXPORT uintptr_t __stack_chk_guard; + // If this is detected in a backtrace of segfault, it means the functions // that use this value must be reworked into their async form with cb arg // provided and with JL_UV_LOCK used around the calls @@ -155,8 +157,8 @@ static inline uint64_t cycleclock(void) #include "timing.h" // Global *atomic* integers controlling *process-wide* measurement of compilation time. -extern _Atomic(uint8_t) jl_measure_compile_time_enabled; -extern _Atomic(uint64_t) jl_cumulative_compile_time; +extern JL_DLLEXPORT _Atomic(uint8_t) jl_measure_compile_time_enabled; +extern JL_DLLEXPORT _Atomic(uint64_t) jl_cumulative_compile_time; #ifdef _COMPILER_MICROSOFT_ # define jl_return_address() ((uintptr_t)_ReturnAddress()) @@ -208,7 +210,7 @@ static inline void memmove_refs(void **dstp, void *const *srcp, size_t n) JL_NOT // useful constants extern jl_methtable_t *jl_type_type_mt JL_GLOBALLY_ROOTED; extern jl_methtable_t *jl_nonfunction_mt JL_GLOBALLY_ROOTED; -extern size_t jl_world_counter; +extern JL_DLLEXPORT size_t jl_world_counter; typedef void (*tracer_cb)(jl_value_t *tracee); extern tracer_cb jl_newmeth_tracer; @@ -216,9 +218,9 @@ void jl_call_tracer(tracer_cb callback, jl_value_t *tracee); void print_func_loc(JL_STREAM *s, jl_method_t *m); extern jl_array_t *_jl_debug_method_invalidation JL_GLOBALLY_ROOTED; -extern size_t jl_page_size; +extern JL_DLLEXPORT size_t jl_page_size; extern jl_function_t *jl_typeinf_func; -extern size_t jl_typeinf_world; +extern JL_DLLEXPORT size_t jl_typeinf_world; extern _Atomic(jl_typemap_entry_t*) call_cache[N_CALL_CACHE] JL_GLOBALLY_ROOTED; extern jl_array_t *jl_all_methods JL_GLOBALLY_ROOTED; @@ -228,7 +230,7 @@ JL_DLLEXPORT extern const char *jl_filename; JL_DLLEXPORT jl_value_t *jl_gc_pool_alloc(jl_ptls_t ptls, int pool_offset, int osize); JL_DLLEXPORT jl_value_t *jl_gc_big_alloc(jl_ptls_t ptls, size_t allocsz); -int jl_gc_classify_pools(size_t sz, int *osize); +JL_DLLEXPORT int jl_gc_classify_pools(size_t sz, int *osize); extern jl_mutex_t gc_perm_lock; void *jl_gc_perm_alloc_nolock(size_t sz, int zero, unsigned align, unsigned offset) JL_NOTSAFEPOINT; @@ -471,8 +473,8 @@ STATIC_INLINE void jl_gc_wb_buf(void *parent, void *bufptr, size_t minsz) JL_NOT } } -void gc_debug_print_status(void); -void gc_debug_critical_error(void); +void jl_gc_debug_print_status(void); +JL_DLLEXPORT void jl_gc_debug_critical_error(void); void jl_print_gc_stats(JL_STREAM *s); void jl_gc_reset_alloc_count(void); uint32_t jl_get_gs_ctr(void); @@ -506,8 +508,8 @@ typedef union { // -- functions -- // // jl_code_info_flag_t code_info_flags(uint8_t pure, uint8_t propagate_inbounds, uint8_t inlineable, uint8_t inferred, uint8_t constprop); -jl_code_info_t *jl_type_infer(jl_method_instance_t *li, size_t world, int force); -jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *meth JL_PROPAGATES_ROOT, size_t world); +JL_DLLEXPORT jl_code_info_t *jl_type_infer(jl_method_instance_t *li, size_t world, int force); +JL_DLLEXPORT jl_code_instance_t *jl_compile_method_internal(jl_method_instance_t *meth JL_PROPAGATES_ROOT, size_t world); jl_code_instance_t *jl_generate_fptr(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world); void jl_generate_fptr_for_unspecialized(jl_code_instance_t *unspec); JL_DLLEXPORT jl_code_instance_t *jl_get_method_inferred( @@ -528,7 +530,7 @@ int jl_valid_type_param(jl_value_t *v); JL_DLLEXPORT jl_value_t *jl_apply_2va(jl_value_t *f, jl_value_t **args, uint32_t nargs); void JL_NORETURN jl_method_error(jl_function_t *f, jl_value_t **args, size_t na, size_t world); -jl_value_t *jl_get_exceptionf(jl_datatype_t *exception_type, const char *fmt, ...); +JL_DLLEXPORT jl_value_t *jl_get_exceptionf(jl_datatype_t *exception_type, const char *fmt, ...); JL_DLLEXPORT jl_value_t *jl_get_keyword_sorter(jl_value_t *f); JL_DLLEXPORT void jl_typeassert(jl_value_t *x, jl_value_t *t); @@ -543,7 +545,7 @@ void jl_install_default_signal_handlers(void); void restore_signals(void); void jl_install_thread_signal_handler(jl_ptls_t ptls); -jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b); +JL_DLLEXPORT jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b); extern uv_loop_t *jl_io_loop; void jl_uv_flush(uv_stream_t *stream); @@ -558,7 +560,7 @@ typedef struct jl_typeenv_t { int jl_tuple_isa(jl_value_t **child, size_t cl, jl_datatype_t *pdt); int jl_tuple1_isa(jl_value_t *child1, jl_value_t **child, size_t cl, jl_datatype_t *pdt); -int jl_has_intersect_type_not_kind(jl_value_t *t); +JL_DLLEXPORT int jl_has_intersect_type_not_kind(jl_value_t *t); int jl_subtype_invariant(jl_value_t *a, jl_value_t *b, int ta); int jl_has_concrete_subtype(jl_value_t *typ); jl_tupletype_t *jl_inst_arg_tuple_type(jl_value_t *arg1, jl_value_t **args, size_t nargs, int leaf); @@ -568,8 +570,8 @@ jl_datatype_t *jl_mk_builtin_func(jl_datatype_t *dt, const char *name, jl_fptr_a int jl_obviously_unequal(jl_value_t *a, jl_value_t *b); JL_DLLEXPORT jl_array_t *jl_find_free_typevars(jl_value_t *v); int jl_has_fixed_layout(jl_datatype_t *t); -int jl_struct_try_layout(jl_datatype_t *dt); -int jl_type_mappable_to_c(jl_value_t *ty); +JL_DLLEXPORT int jl_struct_try_layout(jl_datatype_t *dt); +JL_DLLEXPORT int jl_type_mappable_to_c(jl_value_t *ty); jl_svec_t *jl_outer_unionall_vars(jl_value_t *u); jl_value_t *jl_type_intersection_env_s(jl_value_t *a, jl_value_t *b, jl_svec_t **penv, int *issubty); jl_value_t *jl_type_intersection_env(jl_value_t *a, jl_value_t *b, jl_svec_t **penv); @@ -580,16 +582,16 @@ JL_DLLEXPORT int jl_type_morespecific_no_subtype(jl_value_t *a, jl_value_t *b); jl_value_t *jl_instantiate_type_with(jl_value_t *t, jl_value_t **env, size_t n); JL_DLLEXPORT jl_value_t *jl_instantiate_type_in_env(jl_value_t *ty, jl_unionall_t *env, jl_value_t **vals); jl_value_t *jl_substitute_var(jl_value_t *t, jl_tvar_t *var, jl_value_t *val); -jl_value_t *jl_unwrap_unionall(jl_value_t *v JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; -jl_value_t *jl_rewrap_unionall(jl_value_t *t, jl_value_t *u); +JL_DLLEXPORT jl_value_t *jl_unwrap_unionall(jl_value_t *v JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_value_t *jl_rewrap_unionall(jl_value_t *t, jl_value_t *u); int jl_count_union_components(jl_value_t *v); -jl_value_t *jl_nth_union_component(jl_value_t *v JL_PROPAGATES_ROOT, int i) JL_NOTSAFEPOINT; +JL_DLLEXPORT jl_value_t *jl_nth_union_component(jl_value_t *v JL_PROPAGATES_ROOT, int i) JL_NOTSAFEPOINT; int jl_find_union_component(jl_value_t *haystack, jl_value_t *needle, unsigned *nth) JL_NOTSAFEPOINT; jl_datatype_t *jl_new_abstracttype(jl_value_t *name, jl_module_t *module, jl_datatype_t *super, jl_svec_t *parameters); jl_datatype_t *jl_new_uninitialized_datatype(void); void jl_precompute_memoized_dt(jl_datatype_t *dt, int cacheable); -jl_datatype_t *jl_wrap_Type(jl_value_t *t); // x -> Type{x} +JL_DLLEXPORT jl_datatype_t *jl_wrap_Type(jl_value_t *t); // x -> Type{x} jl_vararg_t *jl_wrap_vararg(jl_value_t *t, jl_value_t *n); void jl_reinstantiate_inner_types(jl_datatype_t *t); jl_datatype_t *jl_lookup_cache_type_(jl_datatype_t *type); @@ -603,9 +605,9 @@ jl_function_t *jl_new_generic_function(jl_sym_t *name, jl_module_t *module); jl_function_t *jl_new_generic_function_with_supertype(jl_sym_t *name, jl_module_t *module, jl_datatype_t *st); void jl_foreach_reachable_mtable(void (*visit)(jl_methtable_t *mt, void *env), void *env); void jl_init_main_module(void); -int jl_is_submodule(jl_module_t *child, jl_module_t *parent) JL_NOTSAFEPOINT; +JL_DLLEXPORT int jl_is_submodule(jl_module_t *child, jl_module_t *parent) JL_NOTSAFEPOINT; jl_array_t *jl_get_loaded_modules(void); -int jl_datatype_isinlinealloc(jl_datatype_t *ty, int pointerfree); +JL_DLLEXPORT int jl_datatype_isinlinealloc(jl_datatype_t *ty, int pointerfree); jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int expanded); @@ -615,7 +617,7 @@ jl_value_t *jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t *src); jl_value_t *jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, jl_code_info_t *src, jl_svec_t *sparam_vals); -int jl_is_toplevel_only_expr(jl_value_t *e) JL_NOTSAFEPOINT; +JL_DLLEXPORT int jl_is_toplevel_only_expr(jl_value_t *e) JL_NOTSAFEPOINT; jl_value_t *jl_call_scm_on_ast(const char *funcname, jl_value_t *expr, jl_module_t *inmodule); jl_method_instance_t *jl_method_lookup(jl_value_t **args, size_t nargs, size_t world); @@ -633,14 +635,14 @@ JL_DLLEXPORT jl_methtable_t *jl_method_get_table( jl_method_t *method) JL_NOTSAFEPOINT; jl_methtable_t *jl_argument_method_table(jl_value_t *argt JL_PROPAGATES_ROOT); -int jl_pointer_egal(jl_value_t *t); -jl_value_t *jl_nth_slot_type(jl_value_t *sig JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT; +JL_DLLEXPORT int jl_pointer_egal(jl_value_t *t); +JL_DLLEXPORT jl_value_t *jl_nth_slot_type(jl_value_t *sig JL_PROPAGATES_ROOT, size_t i) JL_NOTSAFEPOINT; void jl_compute_field_offsets(jl_datatype_t *st); jl_array_t *jl_new_array_for_deserialization(jl_value_t *atype, uint32_t ndims, size_t *dims, int isunboxed, int hasptr, int isunion, int elsz); void jl_module_run_initializer(jl_module_t *m); jl_binding_t *jl_get_module_binding(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *var); -void jl_binding_deprecation_warning(jl_module_t *m, jl_binding_t *b); +JL_DLLEXPORT void jl_binding_deprecation_warning(jl_module_t *m, jl_binding_t *b); extern jl_array_t *jl_module_init_order JL_GLOBALLY_ROOTED; extern htable_t jl_current_modules JL_GLOBALLY_ROOTED; int jl_compile_extern_c(void *llvmmod, void *params, void *sysimg, jl_value_t *declrt, jl_value_t *sigt); @@ -717,17 +719,6 @@ STATIC_INLINE jl_vararg_kind_t jl_va_tuple_kind(jl_datatype_t *t) JL_NOTSAFEPOIN return jl_vararg_kind(jl_tparam(t,l-1)); } -#ifdef JL_USE_INTEL_JITEVENTS -extern char jl_using_intel_jitevents; -#endif -#ifdef JL_USE_OPROFILE_JITEVENTS -extern char jl_using_oprofile_jitevents; -#endif -#ifdef JL_USE_PERF_JITEVENTS -extern char jl_using_perf_jitevents; -#endif -extern char jl_using_gdb_jitevents; - // -- init.c -- // void jl_init_types(void) JL_GC_DISABLED; @@ -745,16 +736,16 @@ jl_task_t *jl_init_root_task(jl_ptls_t ptls, void *stack_lo, void *stack_hi); void jl_init_serializer(void); void jl_gc_init(void); void jl_init_uv(void); -void jl_init_debuginfo(void); void jl_init_thread_heap(jl_ptls_t ptls); void jl_init_int32_int64_cache(void); +JL_DLLEXPORT void jl_init_options(void); void jl_teardown_codegen(void); void jl_set_base_ctx(char *__stk); -extern ssize_t jl_tls_offset; -extern const int jl_tls_elf_support; +extern JL_DLLEXPORT ssize_t jl_tls_offset; +extern JL_DLLEXPORT const int jl_tls_elf_support; void jl_init_threading(void); void jl_start_threads(void); @@ -810,7 +801,7 @@ typedef DWORD jl_pgcstack_key_t; #else typedef jl_gcframe_t ***(*jl_pgcstack_key_t)(void) JL_NOTSAFEPOINT; #endif -void jl_pgcstack_getkey(jl_get_pgcstack_func **f, jl_pgcstack_key_t *k); +JL_DLLEXPORT void jl_pgcstack_getkey(jl_get_pgcstack_func **f, jl_pgcstack_key_t *k); #if !defined(__clang_gcanalyzer__) static inline void jl_set_gc_and_wait(void) @@ -833,12 +824,12 @@ JL_DLLEXPORT jl_value_t *jl_dump_fptr_asm(uint64_t fptr, char raw_mc, const char JL_DLLEXPORT jl_value_t *jl_dump_function_ir(void *f, char strip_ir_metadata, char dump_module, const char *debuginfo); JL_DLLEXPORT jl_value_t *jl_dump_function_asm(void *F, char raw_mc, const char* asm_variant, const char *debuginfo, char binary); -void *jl_create_native(jl_array_t *methods, const jl_cgparams_t cgparams, int policy); +void *jl_create_native(jl_array_t *methods, const jl_cgparams_t *cgparams, int policy); void jl_dump_native(void *native_code, const char *bc_fname, const char *unopt_bc_fname, const char *obj_fname, const char *asm_fname, const char *sysimg_data, size_t sysimg_len); int32_t jl_get_llvm_gv(void *native_code, jl_value_t *p) JL_NOTSAFEPOINT; -void jl_get_function_id(void *native_code, jl_code_instance_t *ncode, +JL_DLLEXPORT void jl_get_function_id(void *native_code, jl_code_instance_t *ncode, int32_t *func_idx, int32_t *specfunc_idx); // the first argument to jl_idtable_rehash is used to return a value @@ -849,10 +840,10 @@ _Atomic(jl_value_t*) *jl_table_peek_bp(jl_array_t *a, jl_value_t *key) JL_NOTSAF JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t*); JL_DLLEXPORT jl_methtable_t *jl_new_method_table(jl_sym_t *name, jl_module_t *module); -jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world, size_t *min_valid, size_t *max_valid, int mt_cache); +JL_DLLEXPORT jl_method_instance_t *jl_get_specialization1(jl_tupletype_t *types, size_t world, size_t *min_valid, size_t *max_valid, int mt_cache); jl_method_instance_t *jl_get_specialized(jl_method_t *m, jl_value_t *types, jl_svec_t *sp); JL_DLLEXPORT jl_value_t *jl_rettype_inferred(jl_method_instance_t *li JL_PROPAGATES_ROOT, size_t min_world, size_t max_world); -jl_code_instance_t *jl_method_compiled(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world); +JL_DLLEXPORT jl_code_instance_t *jl_method_compiled(jl_method_instance_t *mi JL_PROPAGATES_ROOT, size_t world); JL_DLLEXPORT jl_value_t *jl_methtable_lookup(jl_methtable_t *mt, jl_value_t *type, size_t world); JL_DLLEXPORT jl_method_instance_t *jl_specializations_get_linfo( jl_method_t *m JL_PROPAGATES_ROOT, jl_value_t *type, jl_svec_t *sparams); @@ -862,7 +853,7 @@ JL_DLLEXPORT void jl_method_table_add_backedge(jl_methtable_t *mt, jl_value_t *t uint32_t jl_module_next_counter(jl_module_t *m); jl_tupletype_t *arg_type_tuple(jl_value_t *arg1, jl_value_t **args, size_t nargs); -int jl_has_meta(jl_array_t *body, jl_sym_t *sym) JL_NOTSAFEPOINT; +JL_DLLEXPORT int jl_has_meta(jl_array_t *body, jl_sym_t *sym) JL_NOTSAFEPOINT; jl_value_t *jl_parse(const char *text, size_t text_len, jl_value_t *filename, size_t offset, jl_value_t *options); @@ -986,7 +977,7 @@ typedef struct { uint64_t jl_getUnwindInfo(uint64_t dwBase); #ifdef _OS_WINDOWS_ #include -JL_DLLEXPORT EXCEPTION_DISPOSITION __julia_personality( +JL_DLLEXPORT EXCEPTION_DISPOSITION NTAPI __julia_personality( PEXCEPTION_RECORD ExceptionRecord, void *EstablisherFrame, PCONTEXT ContextRecord, void *DispatcherContext); extern HANDLE hMainThread; typedef CONTEXT bt_context_t; @@ -998,7 +989,7 @@ typedef struct { CONTEXT context; } bt_cursor_t; #endif -extern jl_mutex_t jl_in_stackwalk; +extern JL_DLLEXPORT jl_mutex_t jl_in_stackwalk; #elif !defined(JL_DISABLE_LIBUNWIND) // This gives unwind only local unwinding options ==> faster code # define UNW_LOCAL_ONLY @@ -1032,7 +1023,7 @@ JL_DLLEXPORT void jl_gdblookup(void* ip) JL_NOTSAFEPOINT; void jl_print_native_codeloc(uintptr_t ip) JL_NOTSAFEPOINT; void jl_print_bt_entry_codeloc(jl_bt_element_t *bt_data) JL_NOTSAFEPOINT; #ifdef _OS_WINDOWS_ -void jl_refresh_dbg_module_list(void); +JL_DLLEXPORT void jl_refresh_dbg_module_list(void); #endif // *to is NULL or malloc'd pointer, from is allowed to be NULL STATIC_INLINE char *jl_copy_str(char **to, const char *from) JL_NOTSAFEPOINT @@ -1118,13 +1109,14 @@ JL_DLLEXPORT extern void *jl_RTLD_DEFAULT_handle; #if defined(_OS_WINDOWS_) JL_DLLEXPORT extern void *jl_exe_handle; JL_DLLEXPORT extern void *jl_libjulia_handle; +JL_DLLEXPORT extern const char *jl_crtdll_basename; extern void *jl_ntdll_handle; extern void *jl_kernel32_handle; extern void *jl_crtdll_handle; extern void *jl_winsock_handle; #endif -void *jl_get_library_(const char *f_lib, int throw_err); +JL_DLLEXPORT void *jl_get_library_(const char *f_lib, int throw_err); #define jl_get_library(f_lib) jl_get_library_(f_lib, 1) JL_DLLEXPORT void *jl_load_and_lookup(const char *f_lib, const char *f_name, _Atomic(void*) *hnd); JL_DLLEXPORT void *jl_lazy_load_and_lookup(jl_value_t *lib_val, const char *f_name); @@ -1138,7 +1130,7 @@ JL_DLLEXPORT jl_value_t *jl_get_cfunction_trampoline( #define JL_EXE_LIBNAME ((const char*)1) #define JL_LIBJULIA_DL_LIBNAME ((const char*)2) #define JL_LIBJULIA_INTERNAL_DL_LIBNAME ((const char*)3) -const char *jl_dlfind_win32(const char *name); +JL_DLLEXPORT const char *jl_dlfind_win32(const char *name); // libuv wrappers: JL_DLLEXPORT int jl_fs_rename(const char *src_path, const char *dst_path); @@ -1150,7 +1142,7 @@ extern JL_DLLEXPORT jl_value_t *jl_segv_exception; // -- Runtime intrinsics -- // JL_DLLEXPORT const char *jl_intrinsic_name(int f) JL_NOTSAFEPOINT; -unsigned jl_intrinsic_nargs(int f) JL_NOTSAFEPOINT; +JL_DLLEXPORT unsigned jl_intrinsic_nargs(int f) JL_NOTSAFEPOINT; STATIC_INLINE int is_valid_intrinsic_elptr(jl_value_t *ety) { @@ -1258,7 +1250,7 @@ JL_DLLEXPORT void jl_set_next_task(jl_task_t *task) JL_NOTSAFEPOINT; // -- synchronization utilities -- // extern jl_mutex_t typecache_lock; -extern jl_mutex_t codegen_lock; +extern JL_DLLEXPORT jl_mutex_t jl_codegen_lock; extern jl_mutex_t safepoint_lock; #if defined(__APPLE__) @@ -1337,7 +1329,7 @@ JL_DLLEXPORT int8_t jl_svec_isassigned(jl_svec_t *t JL_PROPAGATES_ROOT, ssize_t JL_DLLEXPORT jl_value_t *jl_svec_ref(jl_svec_t *t JL_PROPAGATES_ROOT, ssize_t i); -unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *field_type); +JL_DLLEXPORT unsigned jl_special_vector_alignment(size_t nfields, jl_value_t *field_type); void register_eh_frames(uint8_t *Addr, size_t Size); void deregister_eh_frames(uint8_t *Addr, size_t Size); @@ -1364,61 +1356,100 @@ void jl_log(int level, jl_value_t *module, jl_value_t *group, jl_value_t *id, jl_value_t *file, jl_value_t *line, jl_value_t *kwargs, jl_value_t *msg); -int isabspath(const char *in) JL_NOTSAFEPOINT; - -extern jl_sym_t *call_sym; extern jl_sym_t *invoke_sym; -extern jl_sym_t *invoke_modify_sym; -extern jl_sym_t *empty_sym; extern jl_sym_t *top_sym; -extern jl_sym_t *module_sym; extern jl_sym_t *slot_sym; -extern jl_sym_t *export_sym; extern jl_sym_t *import_sym; -extern jl_sym_t *toplevel_sym; extern jl_sym_t *quote_sym; -extern jl_sym_t *line_sym; extern jl_sym_t *incomplete_sym; -extern jl_sym_t *goto_sym; extern jl_sym_t *goto_ifnot_sym; -extern jl_sym_t *return_sym; -extern jl_sym_t *lambda_sym; extern jl_sym_t *assign_sym; -extern jl_sym_t *globalref_sym; extern jl_sym_t *do_sym; -extern jl_sym_t *method_sym; extern jl_sym_t *core_sym; -extern jl_sym_t *enter_sym; extern jl_sym_t *leave_sym; -extern jl_sym_t *exc_sym; extern jl_sym_t *error_sym; -extern jl_sym_t *new_sym; extern jl_sym_t *using_sym; -extern jl_sym_t *splatnew_sym; -extern jl_sym_t *new_opaque_closure_sym; -extern jl_sym_t *opaque_closure_method_sym; -extern jl_sym_t *pop_exception_sym; -extern jl_sym_t *const_sym; extern jl_sym_t *thunk_sym; -extern jl_sym_t *foreigncall_sym; extern jl_sym_t *as_sym; -extern jl_sym_t *global_sym; extern jl_sym_t *list_sym; -extern jl_sym_t *dot_sym; extern jl_sym_t *newvar_sym; -extern jl_sym_t *boundscheck_sym; extern jl_sym_t *inbounds_sym; -extern jl_sym_t *aliasscope_sym; extern jl_sym_t *popaliasscope_sym; -extern jl_sym_t *copyast_sym; extern jl_sym_t *cfunction_sym; -extern jl_sym_t *pure_sym; extern jl_sym_t *loopinfo_sym; -extern jl_sym_t *meta_sym; extern jl_sym_t *inert_sym; -extern jl_sym_t *polly_sym; extern jl_sym_t *unused_sym; -extern jl_sym_t *static_parameter_sym; extern jl_sym_t *inline_sym; -extern jl_sym_t *noinline_sym; extern jl_sym_t *generated_sym; -extern jl_sym_t *generated_only_sym; extern jl_sym_t *isdefined_sym; -extern jl_sym_t *propagate_inbounds_sym; extern jl_sym_t *specialize_sym; -extern jl_sym_t *aggressive_constprop_sym; extern jl_sym_t *no_constprop_sym; -extern jl_sym_t *nospecialize_sym; extern jl_sym_t *macrocall_sym; -extern jl_sym_t *colon_sym; extern jl_sym_t *hygienicscope_sym; -extern jl_sym_t *throw_undef_if_not_sym; extern jl_sym_t *getfield_undefref_sym; -extern jl_sym_t *gc_preserve_begin_sym; extern jl_sym_t *gc_preserve_end_sym; -extern jl_sym_t *coverageeffect_sym; extern jl_sym_t *escape_sym; -extern jl_sym_t *optlevel_sym; extern jl_sym_t *compile_sym; -extern jl_sym_t *infer_sym; -extern jl_sym_t *atom_sym; extern jl_sym_t *statement_sym; extern jl_sym_t *all_sym; - -extern jl_sym_t *atomic_sym; -extern jl_sym_t *not_atomic_sym; -extern jl_sym_t *unordered_sym; -extern jl_sym_t *monotonic_sym; // or relaxed_sym? -extern jl_sym_t *acquire_sym; -extern jl_sym_t *release_sym; -extern jl_sym_t *acquire_release_sym; -extern jl_sym_t *sequentially_consistent_sym; // or strong_sym? -enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing); -enum jl_memory_order jl_get_atomic_order_checked(jl_sym_t *order, char loading, char storing); +JL_DLLEXPORT int jl_isabspath(const char *in) JL_NOTSAFEPOINT; + +extern JL_DLLEXPORT jl_sym_t *jl_call_sym; +extern JL_DLLEXPORT jl_sym_t *jl_invoke_sym; +extern JL_DLLEXPORT jl_sym_t *jl_invoke_modify_sym; +extern JL_DLLEXPORT jl_sym_t *jl_empty_sym; +extern JL_DLLEXPORT jl_sym_t *jl_top_sym; +extern JL_DLLEXPORT jl_sym_t *jl_module_sym; +extern JL_DLLEXPORT jl_sym_t *jl_slot_sym; +extern JL_DLLEXPORT jl_sym_t *jl_export_sym; +extern JL_DLLEXPORT jl_sym_t *jl_import_sym; +extern JL_DLLEXPORT jl_sym_t *jl_toplevel_sym; +extern JL_DLLEXPORT jl_sym_t *jl_quote_sym; +extern JL_DLLEXPORT jl_sym_t *jl_line_sym; +extern JL_DLLEXPORT jl_sym_t *jl_incomplete_sym; +extern JL_DLLEXPORT jl_sym_t *jl_goto_sym; +extern JL_DLLEXPORT jl_sym_t *jl_goto_ifnot_sym; +extern JL_DLLEXPORT jl_sym_t *jl_return_sym; +extern JL_DLLEXPORT jl_sym_t *jl_lineinfo_sym; +extern JL_DLLEXPORT jl_sym_t *jl_lambda_sym; +extern JL_DLLEXPORT jl_sym_t *jl_assign_sym; +extern JL_DLLEXPORT jl_sym_t *jl_globalref_sym; +extern JL_DLLEXPORT jl_sym_t *jl_do_sym; +extern JL_DLLEXPORT jl_sym_t *jl_method_sym; +extern JL_DLLEXPORT jl_sym_t *jl_core_sym; +extern JL_DLLEXPORT jl_sym_t *jl_enter_sym; +extern JL_DLLEXPORT jl_sym_t *jl_leave_sym; +extern JL_DLLEXPORT jl_sym_t *jl_pop_exception_sym; +extern JL_DLLEXPORT jl_sym_t *jl_exc_sym; +extern JL_DLLEXPORT jl_sym_t *jl_error_sym; +extern JL_DLLEXPORT jl_sym_t *jl_new_sym; +extern JL_DLLEXPORT jl_sym_t *jl_using_sym; +extern JL_DLLEXPORT jl_sym_t *jl_splatnew_sym; +extern JL_DLLEXPORT jl_sym_t *jl_block_sym; +extern JL_DLLEXPORT jl_sym_t *jl_new_opaque_closure_sym; +extern JL_DLLEXPORT jl_sym_t *jl_opaque_closure_method_sym; +extern JL_DLLEXPORT jl_sym_t *jl_const_sym; +extern JL_DLLEXPORT jl_sym_t *jl_thunk_sym; +extern JL_DLLEXPORT jl_sym_t *jl_foreigncall_sym; +extern JL_DLLEXPORT jl_sym_t *jl_as_sym; +extern JL_DLLEXPORT jl_sym_t *jl_global_sym; +extern JL_DLLEXPORT jl_sym_t *jl_list_sym; +extern JL_DLLEXPORT jl_sym_t *jl_dot_sym; +extern JL_DLLEXPORT jl_sym_t *jl_newvar_sym; +extern JL_DLLEXPORT jl_sym_t *jl_boundscheck_sym; +extern JL_DLLEXPORT jl_sym_t *jl_inbounds_sym; +extern JL_DLLEXPORT jl_sym_t *jl_copyast_sym; +extern JL_DLLEXPORT jl_sym_t *jl_cfunction_sym; +extern JL_DLLEXPORT jl_sym_t *jl_pure_sym; +extern JL_DLLEXPORT jl_sym_t *jl_loopinfo_sym; +extern JL_DLLEXPORT jl_sym_t *jl_meta_sym; +extern JL_DLLEXPORT jl_sym_t *jl_inert_sym; +extern JL_DLLEXPORT jl_sym_t *jl_polly_sym; +extern JL_DLLEXPORT jl_sym_t *jl_unused_sym; +extern JL_DLLEXPORT jl_sym_t *jl_static_parameter_sym; +extern JL_DLLEXPORT jl_sym_t *jl_inline_sym; +extern JL_DLLEXPORT jl_sym_t *jl_noinline_sym; +extern JL_DLLEXPORT jl_sym_t *jl_generated_sym; +extern JL_DLLEXPORT jl_sym_t *jl_generated_only_sym; +extern JL_DLLEXPORT jl_sym_t *jl_isdefined_sym; +extern JL_DLLEXPORT jl_sym_t *jl_propagate_inbounds_sym; +extern JL_DLLEXPORT jl_sym_t *jl_specialize_sym; +extern JL_DLLEXPORT jl_sym_t *jl_aggressive_constprop_sym; +extern JL_DLLEXPORT jl_sym_t *jl_no_constprop_sym; +extern JL_DLLEXPORT jl_sym_t *jl_nospecialize_sym; +extern JL_DLLEXPORT jl_sym_t *jl_macrocall_sym; +extern JL_DLLEXPORT jl_sym_t *jl_colon_sym; +extern JL_DLLEXPORT jl_sym_t *jl_hygienicscope_sym; +extern JL_DLLEXPORT jl_sym_t *jl_throw_undef_if_not_sym; +extern JL_DLLEXPORT jl_sym_t *jl_getfield_undefref_sym; +extern JL_DLLEXPORT jl_sym_t *jl_gc_preserve_begin_sym; +extern JL_DLLEXPORT jl_sym_t *jl_gc_preserve_end_sym; +extern JL_DLLEXPORT jl_sym_t *jl_coverageeffect_sym; +extern JL_DLLEXPORT jl_sym_t *jl_escape_sym; +extern JL_DLLEXPORT jl_sym_t *jl_aliasscope_sym; +extern JL_DLLEXPORT jl_sym_t *jl_popaliasscope_sym; +extern JL_DLLEXPORT jl_sym_t *jl_optlevel_sym; +extern JL_DLLEXPORT jl_sym_t *jl_thismodule_sym; +extern JL_DLLEXPORT jl_sym_t *jl_atom_sym; +extern JL_DLLEXPORT jl_sym_t *jl_statement_sym; +extern JL_DLLEXPORT jl_sym_t *jl_all_sym; +extern JL_DLLEXPORT jl_sym_t *jl_compile_sym; +extern JL_DLLEXPORT jl_sym_t *jl_infer_sym; +extern JL_DLLEXPORT jl_sym_t *jl_atomic_sym; +extern JL_DLLEXPORT jl_sym_t *jl_not_atomic_sym; +extern JL_DLLEXPORT jl_sym_t *jl_unordered_sym; +extern JL_DLLEXPORT jl_sym_t *jl_monotonic_sym; +extern JL_DLLEXPORT jl_sym_t *jl_acquire_sym; +extern JL_DLLEXPORT jl_sym_t *jl_release_sym; +extern JL_DLLEXPORT jl_sym_t *jl_acquire_release_sym; +extern JL_DLLEXPORT jl_sym_t *jl_sequentially_consistent_sym; + +JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing); +JL_DLLEXPORT enum jl_memory_order jl_get_atomic_order_checked(jl_sym_t *order, char loading, char storing); struct _jl_sysimg_fptrs_t; diff --git a/src/method.c b/src/method.c index 5899ccffc8a71..d8cd1c30a94e1 100644 --- a/src/method.c +++ b/src/method.c @@ -73,24 +73,24 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve } else if (jl_is_expr(expr)) { jl_expr_t *e = (jl_expr_t*)expr; - if (e->head == global_sym && binding_effects) { + if (e->head == jl_global_sym && binding_effects) { // execute the side-effects of "global x" decl immediately: // creates uninitialized mutable binding in module for each global jl_toplevel_eval_flex(module, expr, 0, 1); expr = jl_nothing; } - if (jl_is_toplevel_only_expr(expr) || e->head == const_sym || - e->head == coverageeffect_sym || e->head == copyast_sym || - e->head == quote_sym || e->head == inert_sym || - e->head == meta_sym || e->head == inbounds_sym || - e->head == boundscheck_sym || e->head == loopinfo_sym || - e->head == aliasscope_sym || e->head == popaliasscope_sym || - e->head == inline_sym || e->head == noinline_sym) { + if (jl_is_toplevel_only_expr(expr) || e->head == jl_const_sym || + e->head == jl_coverageeffect_sym || e->head == jl_copyast_sym || + e->head == jl_quote_sym || e->head == jl_inert_sym || + e->head == jl_meta_sym || e->head == jl_inbounds_sym || + e->head == jl_boundscheck_sym || e->head == jl_loopinfo_sym || + e->head == jl_aliasscope_sym || e->head == jl_popaliasscope_sym || + e->head == jl_inline_sym || e->head == jl_noinline_sym) { // ignore these } else { size_t i = 0, nargs = jl_array_len(e->args); - if (e->head == opaque_closure_method_sym) { + if (e->head == jl_opaque_closure_method_sym) { if (nargs != 4) { jl_error("opaque_closure_method: invalid syntax"); } @@ -103,7 +103,7 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve } return (jl_value_t*)jl_make_opaque_closure_method(module, name, nargs, functionloc, (jl_code_info_t*)ci); } - if (e->head == cfunction_sym) { + if (e->head == jl_cfunction_sym) { JL_NARGS(cfunction method definition, 5, 5); // (type, func, rt, at, cc) jl_value_t *typ = jl_exprarg(e, 0); if (!jl_is_type(typ)) @@ -145,7 +145,7 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve JL_TYPECHK(cfunction method definition, symbol, *(jl_value_t**)jl_exprarg(e, 4)); return expr; } - if (e->head == foreigncall_sym) { + if (e->head == jl_foreigncall_sym) { JL_NARGSV(ccall method definition, 5); // (fptr, rt, at, cc, narg) jl_value_t *rt = jl_exprarg(e, 1); jl_value_t *at = jl_exprarg(e, 2); @@ -180,14 +180,14 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve jl_exprargset(e, 0, resolve_globals(jl_exprarg(e, 0), module, sparam_vals, binding_effects, 1)); i++; } - if (e->head == method_sym || e->head == module_sym) { + if (e->head == jl_method_sym || e->head == jl_module_sym) { i++; } for (; i < nargs; i++) { // TODO: this should be making a copy, not mutating the source jl_exprargset(e, i, resolve_globals(jl_exprarg(e, i), module, sparam_vals, binding_effects, eager_resolve)); } - if (e->head == call_sym && jl_expr_nargs(e) == 3 && + if (e->head == jl_call_sym && jl_expr_nargs(e) == 3 && jl_is_globalref(jl_exprarg(e, 0)) && jl_is_globalref(jl_exprarg(e, 1)) && jl_is_quotenode(jl_exprarg(e, 2))) { @@ -213,7 +213,7 @@ static jl_value_t *resolve_globals(jl_value_t *expr, jl_module_t *module, jl_sve } } } - if (e->head == call_sym && nargs > 0 && + if (e->head == jl_call_sym && nargs > 0 && jl_is_globalref(jl_exprarg(e, 0))) { // TODO: this hack should be deleted once llvmcall is fixed jl_value_t *fe = jl_exprarg(e, 0); @@ -293,20 +293,20 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) jl_value_t *st = bd[j]; int is_flag_stmt = 0; // check :meta expression - if (jl_is_expr(st) && ((jl_expr_t*)st)->head == meta_sym) { + if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_meta_sym) { size_t k, ins = 0, na = jl_expr_nargs(st); jl_array_t *meta = ((jl_expr_t*)st)->args; for (k = 0; k < na; k++) { jl_value_t *ma = jl_array_ptr_ref(meta, k); - if (ma == (jl_value_t*)pure_sym) + if (ma == (jl_value_t*)jl_pure_sym) li->pure = 1; - else if (ma == (jl_value_t*)inline_sym) + else if (ma == (jl_value_t*)jl_inline_sym) li->inlineable = 1; - else if (ma == (jl_value_t*)propagate_inbounds_sym) + else if (ma == (jl_value_t*)jl_propagate_inbounds_sym) li->propagate_inbounds = 1; - else if (ma == (jl_value_t*)aggressive_constprop_sym) + else if (ma == (jl_value_t*)jl_aggressive_constprop_sym) li->constprop = 1; - else if (ma == (jl_value_t*)no_constprop_sym) + else if (ma == (jl_value_t*)jl_no_constprop_sym) li->constprop = 2; else jl_array_ptr_set(meta, ins++, ma); @@ -317,7 +317,7 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) jl_array_del_end(meta, na - ins); } // check other flag expressions - else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == inbounds_sym) { + else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_inbounds_sym) { is_flag_stmt = 1; jl_value_t *arg1 = expr_arg1(st); if (arg1 == (jl_value_t*)jl_true) // push @@ -328,7 +328,7 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) inbounds_depth -= 1; bd[j] = jl_nothing; } - else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == inline_sym) { + else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_inline_sym) { is_flag_stmt = 1; jl_value_t *arg1 = expr_arg1(st); if (arg1 == (jl_value_t*)jl_true) // enter inline region @@ -339,7 +339,7 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) } bd[j] = jl_nothing; } - else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == noinline_sym) { + else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_noinline_sym) { is_flag_stmt = 1; jl_value_t *arg1 = expr_arg1(st); if (arg1 == (jl_value_t*)jl_true) // enter noinline region @@ -350,7 +350,7 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) } bd[j] = jl_nothing; } - else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == return_sym) { + else if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_return_sym) { jl_array_ptr_set(body, j, jl_new_struct(jl_returnnode_type, jl_exprarg(st, 0))); } @@ -391,14 +391,14 @@ static void jl_code_info_set_ir(jl_code_info_t *li, jl_expr_t *ir) jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(vi, 0); assert(jl_is_symbol(name)); char *str = jl_symbol_name(name); - if (i > 0 && name != unused_sym) { + if (i > 0 && name != jl_unused_sym) { if (str[0] == '#') { // convention for renamed variables: #...#original_name char *nxt = strchr(str + 1, '#'); if (nxt) name = jl_symbol(nxt+1); else if (str[1] == 's') // compiler-generated temporaries, #sXXX - name = empty_sym; + name = jl_empty_sym; } } jl_array_ptr_set(li->slotnames, i, name); @@ -559,7 +559,7 @@ JL_DLLEXPORT jl_code_info_t *jl_code_for_staged(jl_method_instance_t *linfo) func = jl_expand_and_resolve(ex, def->module, linfo->sparam_vals); if (!jl_is_code_info(func)) { - if (jl_is_expr(func) && ((jl_expr_t*)func)->head == error_sym) { + if (jl_is_expr(func) && ((jl_expr_t*)func)->head == jl_error_sym) { ct->ptls->in_pure_callback = 0; jl_toplevel_eval(def->module, (jl_value_t*)func); } @@ -571,7 +571,7 @@ JL_DLLEXPORT jl_code_info_t *jl_code_for_staged(jl_method_instance_t *linfo) // correctness of method identity for (int i = 0; i < jl_array_len(func->code); ++i) { jl_value_t *stmt = jl_array_ptr_ref(func->code, i); - if (jl_is_expr(stmt) && ((jl_expr_t*)stmt)->head == new_opaque_closure_sym) { + if (jl_is_expr(stmt) && ((jl_expr_t*)stmt)->head == jl_new_opaque_closure_sym) { linfo->uninferred = jl_copy_ast((jl_value_t*)func); jl_gc_wb(linfo, linfo->uninferred); break; @@ -620,7 +620,7 @@ static void jl_method_set_source(jl_method_t *m, jl_code_info_t *src) int gen_only = 0; for (j = 1; j < m->nargs && j <= sizeof(m->nospecialize) * 8; j++) { jl_value_t *ai = jl_array_ptr_ref(src->slotnames, j); - if (ai == (jl_value_t*)unused_sym) { + if (ai == (jl_value_t*)jl_unused_sym) { // TODO: enable this. currently it triggers a bug on arguments like // ::Type{>:Missing} //int sn = j-1; @@ -646,9 +646,9 @@ static void jl_method_set_source(jl_method_t *m, jl_code_info_t *src) copy = jl_alloc_vec_any(n); for (i = 0; i < n; i++) { jl_value_t *st = jl_array_ptr_ref(stmts, i); - if (jl_is_expr(st) && ((jl_expr_t*)st)->head == meta_sym) { + if (jl_is_expr(st) && ((jl_expr_t*)st)->head == jl_meta_sym) { size_t nargs = jl_expr_nargs(st); - if (nargs >= 1 && jl_exprarg(st, 0) == (jl_value_t*)nospecialize_sym) { + if (nargs >= 1 && jl_exprarg(st, 0) == (jl_value_t*)jl_nospecialize_sym) { if (nargs == 1) // bare `@nospecialize` is special: it prevents specialization on all args m->nospecialize = -1; size_t j; @@ -672,12 +672,12 @@ static void jl_method_set_source(jl_method_t *m, jl_code_info_t *src) } st = jl_nothing; } - else if (nargs >= 1 && jl_exprarg(st, 0) == (jl_value_t*)specialize_sym) { + else if (nargs >= 1 && jl_exprarg(st, 0) == (jl_value_t*)jl_specialize_sym) { if (nargs == 1) // bare `@specialize` is special: it causes specialization on all args m->nospecialize = 0; st = jl_nothing; } - else if (nargs == 2 && jl_exprarg(st, 0) == (jl_value_t*)generated_sym) { + else if (nargs == 2 && jl_exprarg(st, 0) == (jl_value_t*)jl_generated_sym) { m->generator = NULL; jl_value_t *gexpr = jl_exprarg(st, 1); if (jl_expr_nargs(gexpr) == 7) { @@ -694,7 +694,7 @@ static void jl_method_set_source(jl_method_t *m, jl_code_info_t *src) } st = jl_nothing; } - else if (nargs == 1 && jl_exprarg(st, 0) == (jl_value_t*)generated_only_sym) { + else if (nargs == 1 && jl_exprarg(st, 0) == (jl_value_t*)jl_generated_only_sym) { gen_only = 1; st = jl_nothing; } @@ -738,7 +738,7 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module) jl_atomic_store_relaxed(&m->unspecialized, NULL); m->generator = NULL; m->name = NULL; - m->file = empty_sym; + m->file = jl_empty_sym; m->line = 0; m->called = 0xff; m->nospecialize = module->nospecialize; @@ -776,7 +776,7 @@ jl_method_t *jl_make_opaque_closure_method(jl_module_t *module, jl_value_t *name m->nargs = jl_unbox_long(nargs) + 1; assert(jl_is_linenode(functionloc)); jl_value_t *file = jl_linenode_file(functionloc); - m->file = jl_is_symbol(file) ? (jl_sym_t*)file : empty_sym; + m->file = jl_is_symbol(file) ? (jl_sym_t*)file : jl_empty_sym; m->line = jl_linenode_line(functionloc); jl_method_set_source(m, ci); JL_GC_POP(); @@ -930,7 +930,7 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata, m->nargs = nargs; assert(jl_is_linenode(functionloc)); jl_value_t *file = jl_linenode_file(functionloc); - m->file = jl_is_symbol(file) ? (jl_sym_t*)file : empty_sym; + m->file = jl_is_symbol(file) ? (jl_sym_t*)file : jl_empty_sym; m->line = jl_linenode_line(functionloc); jl_method_set_source(m, f); @@ -946,7 +946,7 @@ JL_DLLEXPORT jl_method_t* jl_method_def(jl_svec_t *argdata, jl_value_t *elt = jl_svecref(atypes, i); if (!jl_is_type(elt) && !jl_is_typevar(elt) && !jl_is_vararg(elt)) { jl_sym_t *argname = (jl_sym_t*)jl_array_ptr_ref(f->slotnames, i); - if (argname == unused_sym) + if (argname == jl_unused_sym) jl_exceptionf(jl_argumenterror_type, "invalid type for argument number %d in method definition for %s at %s:%d", i, diff --git a/src/precompile.c b/src/precompile.c index 0c5f1fa368a9d..5d39405045c9e 100644 --- a/src/precompile.c +++ b/src/precompile.c @@ -398,7 +398,7 @@ static void *jl_precompile(int all) } } m = NULL; - void *native_code = jl_create_native(m2, jl_default_cgparams, 0); + void *native_code = jl_create_native(m2, NULL, 0); JL_GC_POP(); return native_code; } diff --git a/src/processor.cpp b/src/processor.cpp index c5e42368412e8..b9dfc2b7f0b4e 100644 --- a/src/processor.cpp +++ b/src/processor.cpp @@ -73,7 +73,7 @@ // // Optimize only for size. Clang's `-Oz`. -bool jl_processor_print_help = false; +JL_DLLEXPORT bool jl_processor_print_help = false; namespace { diff --git a/src/processor.h b/src/processor.h index a1509180ba24a..895a2c2b96786 100644 --- a/src/processor.h +++ b/src/processor.h @@ -177,7 +177,7 @@ JL_DLLEXPORT int32_t jl_get_default_nans(void); #include #include -extern bool jl_processor_print_help; +extern JL_DLLEXPORT bool jl_processor_print_help; /** * Returns the CPU name and feature string to be used by LLVM JIT. @@ -185,14 +185,14 @@ extern bool jl_processor_print_help; * If the detected/specified CPU name is not available on the LLVM version specified, * a fallback CPU name will be used. Unsupported features will be ignored. */ -std::pair> jl_get_llvm_target(bool imaging, uint32_t &flags); +extern "C" JL_DLLEXPORT std::pair> jl_get_llvm_target(bool imaging, uint32_t &flags); /** * Returns the CPU name and feature string to be used by LLVM disassembler. * * This will return a generic CPU name and a full feature string. */ -const std::pair &jl_get_llvm_disasm_target(void); +extern "C" JL_DLLEXPORT const std::pair &jl_get_llvm_disasm_target(void); struct jl_target_spec_t { // LLVM target name @@ -209,8 +209,7 @@ struct jl_target_spec_t { /** * Return the list of targets to clone */ -std::vector jl_get_llvm_clone_targets(void); +extern "C" JL_DLLEXPORT std::vector jl_get_llvm_clone_targets(void); std::string jl_get_cpu_name_llvm(void); std::string jl_get_cpu_features_llvm(void); -std::string jl_format_filename(llvm::StringRef output_pattern); #endif diff --git a/src/processor_fallback.cpp b/src/processor_fallback.cpp index 564562f971f4a..1f314eb460f0f 100644 --- a/src/processor_fallback.cpp +++ b/src/processor_fallback.cpp @@ -117,7 +117,7 @@ const std::pair &jl_get_llvm_disasm_target(void) return res; } -std::vector jl_get_llvm_clone_targets(void) +extern "C" std::vector jl_get_llvm_clone_targets(void) { if (jit_targets.empty()) jl_error("JIT targets not initialized"); diff --git a/src/processor_x86.cpp b/src/processor_x86.cpp index eab2c77ad91dc..8d3c7df091510 100644 --- a/src/processor_x86.cpp +++ b/src/processor_x86.cpp @@ -1011,21 +1011,21 @@ jl_sysimg_fptrs_t jl_init_processor_sysimg(void *hdl) return parse_sysimg(hdl, sysimg_init_cb); } -std::pair> jl_get_llvm_target(bool imaging, uint32_t &flags) +extern "C" JL_DLLEXPORT std::pair> jl_get_llvm_target(bool imaging, uint32_t &flags) { ensure_jit_target(imaging); flags = jit_targets[0].en.flags; return get_llvm_target_vec(jit_targets[0]); } -const std::pair &jl_get_llvm_disasm_target(void) +extern "C" JL_DLLEXPORT const std::pair &jl_get_llvm_disasm_target(void) { static const auto res = get_llvm_target_str(TargetData{"generic", "", {feature_masks, 0}, {{}, 0}, 0}); return res; } -std::vector jl_get_llvm_clone_targets(void) +extern "C" JL_DLLEXPORT std::vector jl_get_llvm_clone_targets(void) { if (jit_targets.empty()) jl_error("JIT targets not initialized"); diff --git a/src/rtutils.c b/src/rtutils.c index 99af741993c44..453406d856778 100644 --- a/src/rtutils.c +++ b/src/rtutils.c @@ -214,6 +214,18 @@ JL_DLLEXPORT void jl_typeassert(jl_value_t *x, jl_value_t *t) jl_type_error("typeassert", t, x); } +#ifndef HAVE_SSP +JL_DLLEXPORT uintptr_t __stack_chk_guard = (uintptr_t)0xBAD57ACCBAD67ACC; // 0xBADSTACKBADSTACK + +JL_DLLEXPORT void __stack_chk_fail(void) +{ + /* put your panic function or similar in here */ + fprintf(stderr, "fatal error: stack corruption detected\n"); + jl_gc_debug_critical_error(); + abort(); // end with abort, since the compiler destroyed the stack upon entry to this function, there's no going back now +} +#endif + // exceptions ----------------------------------------------------------------- JL_DLLEXPORT void jl_enter_handler(jl_handler_t *eh) @@ -972,7 +984,7 @@ static size_t jl_static_show_x_(JL_STREAM *out, jl_value_t *v, jl_datatype_t *vt } else if (vt == jl_expr_type) { jl_expr_t *e = (jl_expr_t*)v; - if (e->head == assign_sym && jl_array_len(e->args) == 2) { + if (e->head == jl_assign_sym && jl_array_len(e->args) == 2) { n += jl_static_show_x(out, jl_exprarg(e,0), depth); n += jl_printf(out, " = "); n += jl_static_show_x(out, jl_exprarg(e,1), depth); diff --git a/src/runtime_intrinsics.c b/src/runtime_intrinsics.c index 00c110f7ce1c5..657c750ee76d6 100644 --- a/src/runtime_intrinsics.c +++ b/src/runtime_intrinsics.c @@ -14,6 +14,202 @@ const unsigned int host_char_bit = 8; +// float16 intrinsics +// TODO: use LLVM's compiler-rt + +static inline float half_to_float(uint16_t ival) JL_NOTSAFEPOINT +{ + uint32_t sign = (ival & 0x8000) >> 15; + uint32_t exp = (ival & 0x7c00) >> 10; + uint32_t sig = (ival & 0x3ff) >> 0; + uint32_t ret; + + if (exp == 0) { + if (sig == 0) { + sign = sign << 31; + ret = sign | exp | sig; + } + else { + int n_bit = 1; + uint16_t bit = 0x0200; + while ((bit & sig) == 0) { + n_bit = n_bit + 1; + bit = bit >> 1; + } + sign = sign << 31; + exp = ((-14 - n_bit + 127) << 23); + sig = ((sig & (~bit)) << n_bit) << (23 - 10); + ret = sign | exp | sig; + } + } + else if (exp == 0x1f) { + if (sig == 0) { // Inf + if (sign == 0) + ret = 0x7f800000; + else + ret = 0xff800000; + } + else // NaN + ret = 0x7fc00000 | (sign << 31) | (sig << (23 - 10)); + } + else { + sign = sign << 31; + exp = ((exp - 15 + 127) << 23); + sig = sig << (23 - 10); + ret = sign | exp | sig; + } + + float fret; + memcpy(&fret, &ret, sizeof(float)); + return fret; +} + +// float to half algorithm from: +// "Fast Half Float Conversion" by Jeroen van der Zijp +// ftp://ftp.fox-toolkit.org/pub/fasthalffloatconversion.pdf +// +// With adjustments for round-to-nearest, ties to even. + +static uint16_t basetable[512] = { + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, + 0x0000, 0x0000, 0x0000, 0x0400, 0x0800, 0x0c00, 0x1000, 0x1400, 0x1800, 0x1c00, 0x2000, + 0x2400, 0x2800, 0x2c00, 0x3000, 0x3400, 0x3800, 0x3c00, 0x4000, 0x4400, 0x4800, 0x4c00, + 0x5000, 0x5400, 0x5800, 0x5c00, 0x6000, 0x6400, 0x6800, 0x6c00, 0x7000, 0x7400, 0x7800, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, 0x7c00, + 0x7c00, 0x7c00, 0x7c00, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, + 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8000, 0x8400, 0x8800, 0x8c00, 0x9000, 0x9400, + 0x9800, 0x9c00, 0xa000, 0xa400, 0xa800, 0xac00, 0xb000, 0xb400, 0xb800, 0xbc00, 0xc000, + 0xc400, 0xc800, 0xcc00, 0xd000, 0xd400, 0xd800, 0xdc00, 0xe000, 0xe400, 0xe800, 0xec00, + 0xf000, 0xf400, 0xf800, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, + 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00, 0xfc00}; + +static uint8_t shifttable[512] = { + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, 0x12, 0x11, 0x10, 0x0f, + 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, + 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, + 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x0d, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, + 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x19, 0x18, 0x17, 0x16, 0x15, 0x14, 0x13, + 0x12, 0x11, 0x10, 0x0f, 0x0e, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, + 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, + 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x0d, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, + 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x0d}; + +static inline uint16_t float_to_half(float param) JL_NOTSAFEPOINT +{ + uint32_t f; + memcpy(&f, ¶m, sizeof(float)); + if (isnan(param)) { + uint32_t t = 0x8000 ^ (0x8000 & ((uint16_t)(f >> 0x10))); + return t ^ ((uint16_t)(f >> 0xd)); + } + int i = ((f & ~0x007fffff) >> 23); + uint8_t sh = shifttable[i]; + f &= 0x007fffff; + // If `val` is subnormal, the tables are set up to force the + // result to 0, so the significand has an implicit `1` in the + // cases we care about. + f |= 0x007fffff + 0x1; + uint16_t h = (uint16_t)(basetable[i] + ((f >> sh) & 0x03ff)); + // round + // NOTE: we maybe should ignore NaNs here, but the payload is + // getting truncated anyway so "rounding" it might not matter + int nextbit = (f >> (sh - 1)) & 1; + if (nextbit != 0 && (h & 0x7C00) != 0x7C00) { + // Round halfway to even or check lower bits + if ((h & 1) == 1 || (f & ((1 << (sh - 1)) - 1)) != 0) + h += UINT16_C(1); + } + return h; +} + +#if !defined(_OS_DARWIN_) // xcode already links compiler-rt + +JL_DLLEXPORT float __gnu_h2f_ieee(uint16_t param) +{ + return half_to_float(param); +} + +JL_DLLEXPORT float __extendhfsf2(uint16_t param) +{ + return half_to_float(param); +} + +JL_DLLEXPORT uint16_t __gnu_f2h_ieee(float param) +{ + return float_to_half(param); +} + +JL_DLLEXPORT uint16_t __truncdfhf2(double param) +{ + return float_to_half((float)param); +} + +#endif + // run time version of bitcast intrinsic JL_DLLEXPORT jl_value_t *jl_bitcast(jl_value_t *ty, jl_value_t *v) { diff --git a/src/safepoint.c b/src/safepoint.c index bf88ecff6b320..8e035f9704f78 100644 --- a/src/safepoint.c +++ b/src/safepoint.c @@ -100,7 +100,7 @@ void jl_safepoint_init(void) #endif if (addr == NULL) { jl_printf(JL_STDERR, "could not allocate GC synchronization page\n"); - gc_debug_critical_error(); + jl_gc_debug_critical_error(); abort(); } // The signal page is for the gc safepoint. diff --git a/src/signal-handling.c b/src/signal-handling.c index d4641065ec2c6..f61588ded0489 100644 --- a/src/signal-handling.c +++ b/src/signal-handling.c @@ -285,8 +285,8 @@ void jl_critical_error(int sig, bt_context_t *context) for (i = 0; i < n; i += jl_bt_entry_size(bt_data + i)) { jl_print_bt_entry_codeloc(bt_data + i); } - gc_debug_print_status(); - gc_debug_critical_error(); + jl_gc_debug_print_status(); + jl_gc_debug_critical_error(); } /////////////////////// diff --git a/src/signals-win.c b/src/signals-win.c index dd8dca959cabf..c43fe67f15113 100644 --- a/src/signals-win.c +++ b/src/signals-win.c @@ -384,7 +384,7 @@ static DWORD WINAPI profile_bt( LPVOID lparam ) if ((DWORD)-1 == ResumeThread(hMainThread)) { jl_profile_stop_timer(); fputs("failed to resume main thread! aborting.", stderr); - gc_debug_critical_error(); + jl_gc_debug_critical_error(); abort(); } } diff --git a/src/stackwalk.c b/src/stackwalk.c index 9436926903682..291db257e36c7 100644 --- a/src/stackwalk.c +++ b/src/stackwalk.c @@ -431,7 +431,7 @@ static DWORD64 WINAPI JuliaGetModuleBase64( volatile int needsSymRefreshModuleList; BOOL (WINAPI *hSymRefreshModuleList)(HANDLE); -void jl_refresh_dbg_module_list(void) +JL_DLLEXPORT void jl_refresh_dbg_module_list(void) { if (needsSymRefreshModuleList && hSymRefreshModuleList != NULL) { hSymRefreshModuleList(GetCurrentProcess()); @@ -595,12 +595,12 @@ JL_DLLEXPORT jl_value_t *jl_lookup_code_address(void *ip, int skipC) if (frame.func_name) jl_svecset(r, 0, jl_symbol(frame.func_name)); else - jl_svecset(r, 0, empty_sym); + jl_svecset(r, 0, jl_empty_sym); free(frame.func_name); if (frame.file_name) jl_svecset(r, 1, jl_symbol(frame.file_name)); else - jl_svecset(r, 1, empty_sym); + jl_svecset(r, 1, jl_empty_sym); free(frame.file_name); jl_svecset(r, 2, jl_box_long(frame.line)); jl_svecset(r, 3, frame.linfo != NULL ? (jl_value_t*)frame.linfo : jl_nothing); diff --git a/src/support/Makefile b/src/support/Makefile index 1ccfdeed3f3da..f123d26886ff7 100644 --- a/src/support/Makefile +++ b/src/support/Makefile @@ -11,7 +11,7 @@ JLDFLAGS += $(LDFLAGS) SRCS := hashing timefuncs ptrhash operators utf8 ios htable bitvector \ int2str libsupportinit arraylist strtod ifeq ($(OS),WINNT) -SRCS += asprintf strptime win32_ucontext +SRCS += asprintf strptime ifeq ($(ARCH),i686) SRCS += _setjmp.win32 else ifeq ($(ARCH),x86_64) diff --git a/src/support/arraylist.c b/src/support/arraylist.c index 343ee59ab6540..230c4ed3a16f5 100644 --- a/src/support/arraylist.c +++ b/src/support/arraylist.c @@ -104,7 +104,7 @@ void small_arraylist_free(small_arraylist_t *a) a->items = &a->_space[0]; } -void small_arraylist_grow(small_arraylist_t *a, uint32_t n) +JL_DLLEXPORT void small_arraylist_grow(small_arraylist_t *a, uint32_t n) { size_t len = a->len; size_t newlen = len + n; diff --git a/src/support/arraylist.h b/src/support/arraylist.h index f996fb397c6e0..03bfd45f8f525 100644 --- a/src/support/arraylist.h +++ b/src/support/arraylist.h @@ -39,7 +39,7 @@ void small_arraylist_free(small_arraylist_t *a) JL_NOTSAFEPOINT; void small_arraylist_push(small_arraylist_t *a, void *elt) JL_NOTSAFEPOINT; void *small_arraylist_pop(small_arraylist_t *a) JL_NOTSAFEPOINT; -void small_arraylist_grow(small_arraylist_t *a, uint32_t n) JL_NOTSAFEPOINT; +JL_DLLEXPORT void small_arraylist_grow(small_arraylist_t *a, uint32_t n) JL_NOTSAFEPOINT; #ifdef __cplusplus } diff --git a/src/sys.c b/src/sys.c index 5080c361494dc..1b7d83f7d7f69 100644 --- a/src/sys.c +++ b/src/sys.c @@ -13,7 +13,6 @@ #include "julia.h" #include "julia_internal.h" -#include "llvm-version.h" #ifdef _OS_WINDOWS_ #include @@ -60,8 +59,6 @@ #include "julia_assert.h" -#include - #ifdef __cplusplus extern "C" { #endif @@ -912,32 +909,6 @@ JL_DLLEXPORT int jl_threading_enabled(void) return 1; } -JL_DLLEXPORT jl_value_t *jl_get_libllvm(void) JL_NOTSAFEPOINT { -#if defined(_OS_WINDOWS_) - HMODULE mod; - // FIXME: GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS on LLVMContextCreate, - // but that just points to libjulia.dll -#if JL_LLVM_VERSION <= 110000 - const char* libLLVM = "LLVM"; -#else - const char* libLLVM = "libLLVM"; -#endif - - if (!GetModuleHandleEx(GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, libLLVM, &mod)) - return jl_nothing; - - char path[MAX_PATH]; - if (!GetModuleFileNameA(mod, path, sizeof(path))) - return jl_nothing; - return (jl_value_t*) jl_symbol(path); -#else - Dl_info dli; - if (!dladdr(LLVMContextCreate, &dli)) - return jl_nothing; - return (jl_value_t*) jl_symbol(dli.dli_fname); -#endif -} - #ifdef __cplusplus } #endif diff --git a/src/task.c b/src/task.c index dd276a9b046c7..796a0825d36d1 100644 --- a/src/task.c +++ b/src/task.c @@ -83,7 +83,6 @@ static inline void tsan_switch_to_ctx(void *state) { #define STATIC_OR_JS static #endif -extern size_t jl_page_size; static char *jl_alloc_fiber(jl_ucontext_t *t, size_t *ssize, jl_task_t *owner) JL_NOTSAFEPOINT; STATIC_OR_JS void jl_set_fiber(jl_ucontext_t *t); STATIC_OR_JS void jl_swap_fiber(jl_ucontext_t *lastt, jl_ucontext_t *t); @@ -221,7 +220,7 @@ void JL_NORETURN jl_finish_task(jl_task_t *t) jl_no_exc_handler(jl_current_exception()); } } - gc_debug_critical_error(); + jl_gc_debug_critical_error(); abort(); } @@ -886,7 +885,7 @@ skip_pop_exception:; ct->result = res; jl_gc_wb(ct, ct->result); jl_finish_task(ct); - gc_debug_critical_error(); + jl_gc_debug_critical_error(); abort(); } diff --git a/src/threading.c b/src/threading.c index 5a9d660329412..acee64fbcd4c4 100644 --- a/src/threading.c +++ b/src/threading.c @@ -287,8 +287,8 @@ void jl_pgcstack_getkey(jl_get_pgcstack_func **f, jl_pgcstack_key_t *k) #endif jl_ptls_t *jl_all_tls_states JL_GLOBALLY_ROOTED; -_Atomic(uint8_t) jl_measure_compile_time_enabled = 0; -_Atomic(uint64_t) jl_cumulative_compile_time = 0; +JL_DLLEXPORT _Atomic(uint8_t) jl_measure_compile_time_enabled = 0; +JL_DLLEXPORT _Atomic(uint64_t) jl_cumulative_compile_time = 0; // return calling thread's ID // Also update the suspended_threads list in signals-mach when changing the @@ -336,14 +336,13 @@ jl_ptls_t jl_init_threadtls(int16_t tid) return ptls; } -// lock for code generation -jl_mutex_t codegen_lock; +JL_DLLEXPORT jl_mutex_t jl_codegen_lock; jl_mutex_t typecache_lock; -ssize_t jl_tls_offset = -1; +JL_DLLEXPORT ssize_t jl_tls_offset = -1; #ifdef JL_ELF_TLS_VARIANT -const int jl_tls_elf_support = 1; +JL_DLLEXPORT const int jl_tls_elf_support = 1; // Optimize TLS access in codegen if the TLS buffer is using a IE or LE model. // To detect such case, we find the size of the TLS segment in the main // executable and the thread pointer (TP) and then see if the TLS pointer on the @@ -439,7 +438,8 @@ static void jl_check_tls(void) jl_tls_offset = offset; } #else -const int jl_tls_elf_support = 0; +// !JL_ELF_TLS_VARIANT +JL_DLLEXPORT const int jl_tls_elf_support = 0; #endif // interface to Julia; sets up to make the runtime thread-safe diff --git a/src/toplevel.c b/src/toplevel.c index 4973d09ab832c..a903063b6d9ec 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -117,7 +117,7 @@ static int jl_is__toplevel__mod(jl_module_t *mod) static jl_value_t *jl_eval_module_expr(jl_module_t *parent_module, jl_expr_t *ex) { jl_task_t *ct = jl_current_task; - assert(ex->head == module_sym); + assert(ex->head == jl_module_sym); if (jl_array_len(ex->args) != 3 || !jl_is_expr(jl_exprarg(ex, 2))) { jl_error("syntax: malformed module expression"); } @@ -310,36 +310,36 @@ static void expr_attributes(jl_value_t *v, int *has_intrinsics, int *has_defs, i return; jl_expr_t *e = (jl_expr_t*)v; jl_sym_t *head = e->head; - if (head == toplevel_sym || head == thunk_sym) { + if (head == jl_toplevel_sym || head == jl_thunk_sym) { return; } - else if (head == global_sym) { + else if (head == jl_global_sym) { // this could be considered has_defs, but loops that assign to globals // might still need to be optimized. return; } - else if (head == const_sym || head == copyast_sym) { + else if (head == jl_const_sym || head == jl_copyast_sym) { // Note: `copyast` is included here since it indicates the presence of // `quote` and probably `eval`. *has_defs = 1; return; } - else if (head == method_sym || jl_is_toplevel_only_expr(v)) { + else if (head == jl_method_sym || jl_is_toplevel_only_expr(v)) { *has_defs = 1; } - else if (head == cfunction_sym) { + else if (head == jl_cfunction_sym) { *has_intrinsics = 1; return; } - else if (head == foreigncall_sym) { + else if (head == jl_foreigncall_sym) { *has_intrinsics = 1; return; } - else if (head == new_opaque_closure_sym) { + else if (head == jl_new_opaque_closure_sym) { *has_opaque = 1; return; } - else if (head == call_sym && jl_expr_nargs(e) > 0) { + else if (head == jl_call_sym && jl_expr_nargs(e) > 0) { jl_value_t *called = NULL; jl_value_t *f = jl_exprarg(e, 0); if (jl_is_globalref(f)) { @@ -378,7 +378,7 @@ int jl_code_requires_compiler(jl_code_info_t *src) assert(jl_typeis(body, jl_array_any_type)); size_t i; int has_intrinsics = 0, has_defs = 0, has_opaque = 0; - if (jl_has_meta(body, compile_sym)) + if (jl_has_meta(body, jl_compile_sym)) return 1; for(i=0; i < jl_array_len(body); i++) { jl_value_t *stmt = jl_array_ptr_ref(body,i); @@ -407,7 +407,7 @@ static void body_attributes(jl_array_t *body, int *has_intrinsics, int *has_defs } expr_attributes(stmt, has_intrinsics, has_defs, has_opaque); } - *has_compile = jl_has_meta(body, compile_sym); + *has_compile = jl_has_meta(body, jl_compile_sym); } static jl_module_t *call_require(jl_module_t *mod, jl_sym_t *var) JL_GLOBALLY_ROOTED @@ -454,7 +454,7 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR m = from; i = 0; } - else if (var != dot_sym) { + else if (var != jl_dot_sym) { // `A.B`: call the loader to obtain the root A in the current environment. if (jl_core_module && var == jl_core_module->name) { m = jl_core_module; @@ -475,7 +475,7 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR if (i >= jl_array_len(args)) jl_error("invalid module path"); var = (jl_sym_t*)jl_array_ptr_ref(args, i); - if (var != dot_sym) + if (var != jl_dot_sym) break; i++; assert(m); @@ -487,7 +487,7 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR var = (jl_sym_t*)jl_array_ptr_ref(args, i); if (!jl_is_symbol(var)) jl_type_error(keyword, (jl_value_t*)jl_symbol_type, (jl_value_t*)var); - if (var == dot_sym) + if (var == jl_dot_sym) jl_errorf("invalid %s path: \".\" in identifier path", keyword); if (i == jl_array_len(args)-1) break; @@ -504,16 +504,16 @@ static jl_module_t *eval_import_path(jl_module_t *where, jl_module_t *from JL_PR int jl_is_toplevel_only_expr(jl_value_t *e) JL_NOTSAFEPOINT { return jl_is_expr(e) && - (((jl_expr_t*)e)->head == module_sym || - ((jl_expr_t*)e)->head == import_sym || - ((jl_expr_t*)e)->head == using_sym || - ((jl_expr_t*)e)->head == export_sym || - ((jl_expr_t*)e)->head == thunk_sym || - ((jl_expr_t*)e)->head == global_sym || - ((jl_expr_t*)e)->head == const_sym || - ((jl_expr_t*)e)->head == toplevel_sym || - ((jl_expr_t*)e)->head == error_sym || - ((jl_expr_t*)e)->head == incomplete_sym); + (((jl_expr_t*)e)->head == jl_module_sym || + ((jl_expr_t*)e)->head == jl_import_sym || + ((jl_expr_t*)e)->head == jl_using_sym || + ((jl_expr_t*)e)->head == jl_export_sym || + ((jl_expr_t*)e)->head == jl_thunk_sym || + ((jl_expr_t*)e)->head == jl_global_sym || + ((jl_expr_t*)e)->head == jl_const_sym || + ((jl_expr_t*)e)->head == jl_toplevel_sym || + ((jl_expr_t*)e)->head == jl_error_sym || + ((jl_expr_t*)e)->head == jl_incomplete_sym); } int jl_needs_lowering(jl_value_t *e) JL_NOTSAFEPOINT @@ -522,12 +522,12 @@ int jl_needs_lowering(jl_value_t *e) JL_NOTSAFEPOINT return 0; jl_expr_t *ex = (jl_expr_t*)e; jl_sym_t *head = ex->head; - if (head == module_sym || head == import_sym || head == using_sym || - head == export_sym || head == thunk_sym || head == toplevel_sym || - head == error_sym || head == incomplete_sym || head == method_sym) { + if (head == jl_module_sym || head == jl_import_sym || head == jl_using_sym || + head == jl_export_sym || head == jl_thunk_sym || head == jl_toplevel_sym || + head == jl_error_sym || head == jl_incomplete_sym || head == jl_method_sym) { return 0; } - if (head == global_sym || head == const_sym) { + if (head == jl_global_sym || head == jl_const_sym) { size_t i, l = jl_array_len(ex->args); for (i = 0; i < l; i++) { jl_value_t *a = jl_exprarg(ex, i); @@ -576,10 +576,10 @@ static jl_module_t *eval_import_from(jl_module_t *m JL_PROPAGATES_ROOT, jl_expr_ { if (jl_expr_nargs(ex) == 1 && jl_is_expr(jl_exprarg(ex, 0))) { jl_expr_t *fr = (jl_expr_t*)jl_exprarg(ex, 0); - if (fr->head == colon_sym) { + if (fr->head == jl_colon_sym) { if (jl_expr_nargs(fr) > 0 && jl_is_expr(jl_exprarg(fr, 0))) { jl_expr_t *path = (jl_expr_t*)jl_exprarg(fr, 0); - if (((jl_expr_t*)path)->head == dot_sym) { + if (((jl_expr_t*)path)->head == jl_dot_sym) { jl_sym_t *name = NULL; jl_module_t *from = eval_import_path(m, NULL, path->args, &name, keyword); if (name != NULL) { @@ -610,7 +610,7 @@ static void check_macro_rename(jl_sym_t *from, jl_sym_t *to, const char *keyword // location in julia code gets into the backtrace. static void jl_eval_errorf(jl_module_t *m, const char* fmt, ...) { - jl_value_t *throw_ex = (jl_value_t*)jl_exprn(call_sym, 2); + jl_value_t *throw_ex = (jl_value_t*)jl_exprn(jl_call_sym, 2); JL_GC_PUSH1(&throw_ex); jl_exprargset(throw_ex, 0, jl_builtin_throw); va_list args; @@ -645,7 +645,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int jl_expr_t *ex = (jl_expr_t*)e; - if (ex->head == dot_sym && jl_expr_nargs(ex) != 1) { + if (ex->head == jl_dot_sym && jl_expr_nargs(ex) != 1) { if (jl_expr_nargs(ex) != 2) jl_eval_errorf(m, "syntax: malformed \".\" expression"); jl_value_t *lhs = jl_exprarg(ex, 0); @@ -672,12 +672,12 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } jl_sym_t *head = jl_is_expr(ex) ? ex->head : NULL; - if (head == module_sym) { + if (head == jl_module_sym) { jl_value_t *val = jl_eval_module_expr(m, ex); JL_GC_POP(); return val; } - else if (head == using_sym) { + else if (head == jl_using_sym) { jl_sym_t *name = NULL; jl_module_t *from = eval_import_from(m, ex, "using"); size_t i = 0; @@ -687,7 +687,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } for (; i < jl_expr_nargs(ex); i++) { jl_value_t *a = jl_exprarg(ex, i); - if (jl_is_expr(a) && ((jl_expr_t*)a)->head == dot_sym) { + if (jl_is_expr(a) && ((jl_expr_t*)a)->head == jl_dot_sym) { name = NULL; jl_module_t *import = eval_import_path(m, from, ((jl_expr_t*)a)->args, &name, "using"); jl_module_t *u = import; @@ -711,8 +711,8 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } continue; } - else if (from && jl_is_expr(a) && ((jl_expr_t*)a)->head == as_sym && jl_expr_nargs(a) == 2 && - jl_is_expr(jl_exprarg(a, 0)) && ((jl_expr_t*)jl_exprarg(a, 0))->head == dot_sym) { + else if (from && jl_is_expr(a) && ((jl_expr_t*)a)->head == jl_as_sym && jl_expr_nargs(a) == 2 && + jl_is_expr(jl_exprarg(a, 0)) && ((jl_expr_t*)jl_exprarg(a, 0))->head == jl_dot_sym) { jl_sym_t *asname = (jl_sym_t*)jl_exprarg(a, 1); if (jl_is_symbol(asname)) { jl_expr_t *path = (jl_expr_t*)jl_exprarg(a, 0); @@ -730,7 +730,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return jl_nothing; } - else if (head == import_sym) { + else if (head == jl_import_sym) { jl_sym_t *name = NULL; jl_module_t *from = eval_import_from(m, ex, "import"); size_t i = 0; @@ -740,7 +740,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } for (; i < jl_expr_nargs(ex); i++) { jl_value_t *a = jl_exprarg(ex, i); - if (jl_is_expr(a) && ((jl_expr_t*)a)->head == dot_sym) { + if (jl_is_expr(a) && ((jl_expr_t*)a)->head == jl_dot_sym) { name = NULL; jl_module_t *import = eval_import_path(m, from, ((jl_expr_t*)a)->args, &name, "import"); if (name == NULL) { @@ -753,8 +753,8 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } continue; } - else if (jl_is_expr(a) && ((jl_expr_t*)a)->head == as_sym && jl_expr_nargs(a) == 2 && - jl_is_expr(jl_exprarg(a, 0)) && ((jl_expr_t*)jl_exprarg(a, 0))->head == dot_sym) { + else if (jl_is_expr(a) && ((jl_expr_t*)a)->head == jl_as_sym && jl_expr_nargs(a) == 2 && + jl_is_expr(jl_exprarg(a, 0)) && ((jl_expr_t*)jl_exprarg(a, 0))->head == jl_dot_sym) { jl_sym_t *asname = (jl_sym_t*)jl_exprarg(a, 1); if (jl_is_symbol(asname)) { jl_expr_t *path = (jl_expr_t*)jl_exprarg(a, 0); @@ -777,7 +777,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return jl_nothing; } - else if (head == export_sym) { + else if (head == jl_export_sym) { for (size_t i = 0; i < jl_array_len(ex->args); i++) { jl_sym_t *name = (jl_sym_t*)jl_array_ptr_ref(ex->args, i); if (!jl_is_symbol(name)) @@ -787,7 +787,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return jl_nothing; } - else if (head == global_sym) { + else if (head == jl_global_sym) { // create uninitialized mutable binding for "global x" decl size_t i, l = jl_array_len(ex->args); for (i = 0; i < l; i++) { @@ -808,7 +808,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return jl_nothing; } - else if (head == const_sym) { + else if (head == jl_const_sym) { jl_sym_t *arg = (jl_sym_t*)jl_exprarg(ex, 0); jl_module_t *gm; jl_sym_t *gs; @@ -826,7 +826,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return jl_nothing; } - else if (head == toplevel_sym) { + else if (head == jl_toplevel_sym) { jl_value_t *res = jl_nothing; int i; for (i = 0; i < jl_array_len(ex->args); i++) { @@ -835,7 +835,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int JL_GC_POP(); return res; } - else if (head == error_sym || head == incomplete_sym) { + else if (head == jl_error_sym || head == jl_incomplete_sym) { if (jl_expr_nargs(ex) == 0) jl_eval_errorf(m, "malformed \"%s\" expression", jl_symbol_name(head)); if (jl_is_string(jl_exprarg(ex, 0))) @@ -852,7 +852,7 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *JL_NONNULL m, jl_value_t *e, int } int has_intrinsics = 0, has_defs = 0, has_loops = 0, has_opaque = 0, has_compile = 0; - assert(head == thunk_sym); + assert(head == jl_thunk_sym); thk = (jl_code_info_t*)jl_exprarg(ex, 0); assert(jl_is_code_info(thk)); assert(jl_typeis(thk->code, jl_array_any_type)); @@ -995,8 +995,8 @@ static jl_value_t *jl_parse_eval_all(jl_module_t *module, jl_value_t *text, JL_GC_PUSH3(&ast, &result, &expression); ast = jl_svecref(jl_parse(jl_string_data(text), jl_string_len(text), - filename, 0, (jl_value_t*)all_sym), 0); - if (!jl_is_expr(ast) || ((jl_expr_t*)ast)->head != toplevel_sym) { + filename, 0, (jl_value_t*)jl_all_sym), 0); + if (!jl_is_expr(ast) || ((jl_expr_t*)ast)->head != jl_toplevel_sym) { jl_errorf("jl_parse_all() must generate a top level expression"); } diff --git a/src/support/win32_ucontext.c b/src/win32_ucontext.c similarity index 100% rename from src/support/win32_ucontext.c rename to src/win32_ucontext.c diff --git a/src/support/win32_ucontext.h b/src/win32_ucontext.h similarity index 100% rename from src/support/win32_ucontext.h rename to src/win32_ucontext.h diff --git a/test/compiler/codegen.jl b/test/compiler/codegen.jl index fbba027cd9f91..17185d0706458 100644 --- a/test/compiler/codegen.jl +++ b/test/compiler/codegen.jl @@ -637,3 +637,10 @@ t41096 = Term41096{:t}(Modulate41096(:t, false)) U41096 = Term41096{:U}(Modulate41096(:U, false)) @test !newexpand41096((t=t41096, μ=μ41096, U=U41096), :U) + +# test that we can start julia with libjulia-codegen removed; PR #41936 +mktempdir() do pfx + run(`cp -r $(Sys.BINDIR)/.. $pfx`) + run(`rm -rf $pfx/lib/julia/libjulia-codegen\*`) + @test readchomp(`$pfx/bin/$(Base.julia_exename()) -e 'println("no codegen!")'`) == "no codegen!" +end