Skip to content

Commit

Permalink
Added Mimalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
Brugarolas committed Jan 16, 2024
1 parent 584868b commit 401f7b8
Show file tree
Hide file tree
Showing 614 changed files with 186,471 additions and 122 deletions.
15 changes: 10 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
## Set ccompiler and force system options
option(USE_FORCE_GCC "Use GCC compiler" OFF)
option(USE_FORCE_CLANG "Use Clang compiler" OFF)
option(USE_DEBUG_MODE "Enable debug mode" OFF)

if (USE_FORCE_GCC)
message(STATUS "Using GCC compiler")
Expand All @@ -53,7 +54,7 @@ if (USE_FORCE_GCC)
endif()

if (USE_FORCE_CLANG)
messagge(STATUS "Using Clang compiler")
message(STATUS "Using Clang compiler")

# Find if Clang is installed
find_program(CLANG_COMPILER clang)
Expand All @@ -67,7 +68,11 @@ if (USE_FORCE_CLANG)
endif()
endif()

include(cmake/OptimizeCompilerFlags.cmake)
if (USE_DEBUG_MODE)
include(cmake/DebugCompilerFlags.cmake)
else()
include(cmake/OptimizeCompilerFlags.cmake)
endif()

##### ------------- #####

Expand Down Expand Up @@ -561,7 +566,6 @@ if(IOS)
COMPILE_FLAGS "-arch ${ARCHS} -isysroot ${CMAKE_OSX_SYSROOT} ${BITCODE}")
endif()


set(LJ_VM_S_PATH ${CMAKE_CURRENT_BINARY_DIR}/${LJ_VM_NAME})
add_custom_command(OUTPUT ${LJ_VM_S_PATH}
COMMAND ${HOST_WINE} ${BUILDVM_PATH} -m ${LJVM_MODE} -o ${LJ_VM_S_PATH}
Expand Down Expand Up @@ -621,12 +625,13 @@ add_custom_target(lj_gen_folddef ALL
)

file(GLOB_RECURSE SRC_LJCORE "${LJ_DIR}/lj_*.c")
file(GLOB MIMALLOC_SOURCES "${LJ_DIR}/mimalloc/**/*.c")
file(GLOB_RECURSE SRC_LIBCORE "${LJ_DIR}/lib_*.c")

if(LUAJIT_BUILD_ALAMG)
set(luajit_sources ${LJ_DIR}/ljamalg.c ${LJ_VM_NAME})
else()
set(luajit_sources ${SRC_LIBCORE} ${SRC_LJCORE} ${LJ_VM_NAME})
set(luajit_sources ${SRC_LIBCORE} ${SRC_LJCORE} ${LJ_VM_NAME} ${MIMALLOC_SOURCES})
endif()

# Build the luajit static library
Expand Down Expand Up @@ -711,7 +716,7 @@ install(TARGETS libluajit

# Build the luajit binary
if (LUAJIT_BUILD_EXE)
add_executable(luajit ${LJ_DIR}/luajit.c)
add_executable(luajit ${LJ_DIR}/luajit.c ${MIMALLOC_SOURCES})
target_link_libraries(luajit libluajit)
target_include_directories(luajit PRIVATE
${CMAKE_CURRENT_BINARY_DIR}
Expand Down
27 changes: 27 additions & 0 deletions build-clang-debug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/bash

# Find Clang
CLANG=$(which clang)
CLANGXX=$(which clang++)

if [ -z "$CLANG" ] || [ -z "$CLANGXX" ]; then
echo "Clang not found."
exit 1
fi

# Set Clang as the compiler
export CC=$CLANG
export CXX=$CLANGXX

# Create a build directory
mkdir -p build
cd build

# Configure the project with CMake using Ninja
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Debug -DUSE_FORCE_CLANG=ON -DUSE_DEBUG_MODE=ON

# Build the project
ninja

# Return to the original directory
cd ..
2 changes: 1 addition & 1 deletion build-gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ mkdir -p build
cd build

# Configure the project with CMake using Ninja
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -USE_FORCE_GCC=ON
cmake -G Ninja .. -DCMAKE_BUILD_TYPE=Release -DUSE_FORCE_GCC=ON

# Build the project
ninja
Expand Down
19 changes: 19 additions & 0 deletions cmake/DebugCompilerFlags.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
message(STATUS "Debug mode enabled")
set(CMAKE_BUILD_TYPE Debug)
set(BUILD_TYPE "Debug")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbmi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")

set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -g")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -O0")
set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall -Wextra")
#set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fsanitize=address")
#set(CMAKE_EXE_LINKER_FLAGS_DEBUG "${CMAKE_EXE_LINKER_FLAGS_DEBUG} -fsanitize=address")
set(CMAKE_VERBOSE_MAKEFILE ON)

export const urlAlphabet = 'ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW';
161 changes: 47 additions & 114 deletions cmake/OptimizeCompilerFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,28 @@ message(STATUS "Build type: ${BUILD_TYPE}")

## Set build type
option(NATIVE_OPTIMIZATIONS "Enable native optimizations" ON)
option(AGGRESSIVE_OPTIMIZATIONS "Enable aggresive optimizations" ON)
option(UNSAFE_OPTIMIZATIONS "Enable aggresive optimizations" OFF)
option(AGGRESSIVE_OPTIMIZATIONS "Enable aggresive optimizations" OFF)

message(STATUS "Native optimizations: ${NATIVE_OPTIMIZATIONS}")
message(STATUS "Aggressive optimizations: ${AGGRESSIVE_OPTIMIZATIONS}")
message(STATUS "Unsafe optimizations: ${UNSAFE_OPTIMIZATIONS}")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbmi")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mbmi2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mbmi2")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mavx2")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")

## Set GCC optimization flags
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

## Aggressive optimizations
if (AGGRESSIVE_OPTIMIZATIONS)
## Unsafe optimizations
if (UNSAFE_OPTIMIZATIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Ofast")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Ofast")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -funsafe-math-optimizations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsafe-math-optimizations")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
else()
## Safe optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")
endif()

## LTO optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")
Expand All @@ -61,40 +46,26 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
## Inline optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-functions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-functions")

## Native optimizations
if (NATIVE_OPTIMIZATIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
else ()
## Safe optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O3")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3")

## LTO optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto")

## Loop optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -funroll-loops")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops")

## Vectorization optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-vectorize")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-vectorize")

## Inline optimizations (small functions only)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -finline-small-functions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -finline-small-functions")

## Native optimizations
if (NATIVE_OPTIMIZATIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
endif()

## Native optimizations
if (NATIVE_OPTIMIZATIONS)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()

# Some extra optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flive-range-shrinkage")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flive-range-shrinkage")
Expand All @@ -111,62 +82,45 @@ if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fipa-icf")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fipa-icf")

# Sample test source file to test ISL support
set(TEST_SOURCE "${CMAKE_BINARY_DIR}/test_isl_support.c")
file(WRITE ${TEST_SOURCE} "int main() { return 0; }")
if (AGGRESSIVE_OPTIMIZATIONS)
# Sample test source file to test ISL support
set(TEST_SOURCE "${CMAKE_BINARY_DIR}/test_isl_support.c")
file(WRITE ${TEST_SOURCE} "int main() { return 0; }")

# Try to compile with ISL-specific flags
include(CheckCCompilerFlag)
check_c_compiler_flag("-floop-nest-optimize" COMPILER_SUPPORTS_ISL)
# Try to compile with ISL-specific flags
include(CheckCCompilerFlag)
check_c_compiler_flag("-floop-nest-optimize" COMPILER_SUPPORTS_ISL)

if(COMPILER_SUPPORTS_ISL)
message(STATUS "GCC is built with ISL support.")
if(COMPILER_SUPPORTS_ISL)
message(STATUS "GCC is built with ISL support.")

# Add the ISL-dependent flags to your project
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -floop-nest-optimize -ftree-loop-linear -floop-strip-mine -floop-block")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -floop-nest-optimize -ftree-loop-linear -floop-strip-mine -floop-block")
# Add the ISL-dependent flags to your project
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -floop-nest-optimize -ftree-loop-linear -floop-strip-mine -floop-block")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -floop-nest-optimize -ftree-loop-linear -floop-strip-mine -floop-block")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgraphite-identity")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fgraphite-identity")
else()
message(STATUS "GCC is not built with ISL support. Skipping certain optimizations.")
endif()

# More extra optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-loop-if-convert -ftree-loop-distribution -ftree-loop-distribute-patterns -floop-interchange")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-loop-if-convert -ftree-loop-distribution -ftree-loop-distribute-patterns -floop-interchange")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-loop-ivcanon -fivopts")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-loop-ivcanon -fivopts")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fgraphite-identity")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fgraphite-identity")
else()
message(STATUS "GCC is not built with ISL support. Skipping certain optimizations.")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt")
# More extra optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ftree-loop-if-convert -ftree-loop-distribution -ftree-loop-distribute-patterns -floop-interchange -ftree-loop-ivcanon")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ftree-loop-if-convert -ftree-loop-distribution -ftree-loop-distribute-patterns -floop-interchange -ftree-loop-ivcanon")
endif()

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt")
# Final Optimizations
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt -fivopts")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fweb -fuse-linker-plugin -fstdarg-opt -fivopts")
endif()

## Set Clang optimization flags
if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# Use -Ofast or -O3 optimization
if (AGGRESSIVE_OPTIMIZATION)
if(UNSAFE_OPTIMIZATIONS)
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -Ofast")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Ofast")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fstrict-aliasing")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fstrict-aliasing")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -funsafe-math-optimizations")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funsafe-math-optimizations")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -ffast-math")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffast-math")
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
endif()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")

# Aggressive optimizations
if (AGGRESSIVE_OPTIMIZATION)
## These optimizations depends on wether if LLVM is built with Polly support or Polly support is installed per separate
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvectorize -fslp-vectorize -finline-functions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvectorize -fslp-vectorize -finline-functions")
Expand All @@ -191,46 +145,25 @@ if ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly-vectorizer=stripmine")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly-parallel")

# Native optimization
if (NATIVE_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
else()
set(CMAKE_C_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3")

## These optimizations depends on wether if LLVM is built with Polly support or Polly support is installed per separate
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fvectorize -fslp-vectorize -finline-functions")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fvectorize -fslp-vectorize -finline-functions")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -floop-parallelize-all -floop-unroll-and-jam -fvectorize -fslp-vectorize -finline-functions")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -floop-parallelize-all -floop-unroll-and-jam -fvectorize -fslp-vectorize -finline-functions")

## FLTO optimizations
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -funroll-loops -flto=thin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops -flto=thin")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -flto=thin")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -flto=thin")

## These optimizations depends on wether if LLVM is built with Polly support or Polly support is installed per separate
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Xclang -load -Xclang LLVMPolly.so -mllvm -polly")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mllvm -polly-vectorizer=stripmine")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mllvm -polly")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mllvm -polly-vectorizer=stripmine")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -mllvm -polly-parallel")

## These optimizations depends on wether if LLVM is built with Polly support or Polly support is installed per separate
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Xclang -load -Xclang LLVMPolly.so -mllvm -polly")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly-vectorizer=stripmine")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly-vectorizer=stripmine")
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mllvm -polly-parallel")
endif()

# Native optimization
if (NATIVE_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()
# Native optimization
if (NATIVE_OPTIMIZATION)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -march=native")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
endif()

if(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/default.profraw")
Expand Down
1 change: 1 addition & 0 deletions lib/libuv/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test/fixtures/lorem_ipsum.txt text eol=lf
13 changes: 13 additions & 0 deletions lib/libuv/.github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!--
If you want to report a bug, you are in the right place!
If you need help or have a question, go here:
https://github.com/libuv/libuv/discussions
If you are reporting a libuv test failure, please ensure that you are not
running the test as root.
Please include code that demonstrates the bug and keep it short and simple.
-->
* **Version**: <!-- libuv version -->
* **Platform**: <!-- `uname -a` (UNIX), or Windows version and machine type -->
Loading

0 comments on commit 401f7b8

Please sign in to comment.