Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
[submodule "external/asmjit"]
path = external/asmjit
path = ThirdParty/asmjit
url = https://github.com/asmjit/asmjit
branch = master
[submodule "external/llvm"]
path = external/llvm
url = https://github.com/llvm/llvm-project
branch = release/7.x
[submodule "external/asmjit-utilities"]
path = external/asmjit-utilities
path = ThirdParty/asmjit-utilities
url = https://github.com/tetzank/asmjit-utilities
192 changes: 108 additions & 84 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,105 +1,129 @@
cmake_minimum_required(VERSION 3.12)

if(NOT DEFINED CMAKE_CXX_FLAGS)
set(CMAKE_CXX_FLAGS "-Wall -Wextra -march=native -fno-rtti" CACHE STRING "Flags used by the compiler during all build types.")
endif()
# build type defaults to release
# Build type defaults to release
if(NOT DEFINED CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None(CMAKE_CXX_FLAGS or CMAKE_C_FLAGS) Debug Release RelWithdebInfo MinSizeRel.")
endif()

project(coat CXX)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include_directories("${CMAKE_SOURCE_DIR}/include/")

option(ENABLE_ASMJIT "enable AsmJit backend" ON)
option(ENABLE_LLVMJIT "enable LLVM JIT backend" ON)

if(ENABLE_ASMJIT)
# find asmjit
find_path(ASMJIT_INCLUDE_DIR
asmjit/asmjit.h
HINTS external/asmjit ENV ASMJIT_ROOT
PATH_SUFFIXES src
)
find_library(ASMJIT_LIBRARIES
asmjit
HINTS external/asmjit ENV ASMJIT_ROOT
PATH_SUFFIXES build build_next
)
include_directories(${ASMJIT_INCLUDE_DIR})

# find asmjit_perf
find_path(ASMJIT_PERF_INCLUDE_DIR
asmjit-utilities/perf/jitdump.h
HINTS external/
)
find_library(ASMJIT_PERF_LIBRARIES
asmjit_perf
HINTS external/asmjit-utilities
PATH_SUFFIXES perf/build
)
include_directories(${ASMJIT_PERF_INCLUDE_DIR})
endif()
enable_testing()

if(ENABLE_LLVMJIT)
# find llvm, quick&dirty
find_path(LLVM_INCLUDE_DIR
llvm/IR/IRBuilder.h
HINTS external/llvm/llvm/install ENV LLVM_ROOT
PATH_SUFFIXES include
)
find_library(LLVM_LIBRARIES
LLVM
HINTS external/llvm/llvm/install ENV LLVM_ROOT
PATH_SUFFIXES lib build/lib
)
include_directories(${LLVM_INCLUDE_DIR})
endif()
macro(coat_add_executable)
set(options TEST)
set(oneValueArgs BACKEND)
set(multiValueArgs NAMES)
cmake_parse_arguments(COAT "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN} )

foreach(NAME ${COAT_NAMES})
if (COAT_TEST)
set(TARGET test_${PROJECT_NAME}_${COAT_BACKEND}_${NAME})
set(SRC src/tests/${NAME}.cpp)
else()
set(TARGET example_${PROJECT_NAME}_${COAT_BACKEND}_${NAME})
set(SRC src/examples/${NAME}.cpp)
endif()
add_executable(${TARGET} ${SRC})
set_target_properties(${TARGET} PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
target_link_libraries(${TARGET} ${PROJECT_NAME}::${COAT_BACKEND})
if (COAT_TEST)
add_test(${TARGET} ${TARGET})
endif()
endforeach()
endmacro()

if (ENABLE_LLVMJIT)
find_package(LLVM CONFIG REQUIRED PATHS "/usr/lib/llvm-12/lib/cmake" NO_DEFAULT_PATH)
find_package(Clang CONFIG REQUIRED PATHS "/usr/lib/llvm-12/lib/cmake" NO_DEFAULT_PATH)

# debugging options
if(NOT DEFINED PROFILING)
set(PROFILING "" CACHE STRING "Choose type of profiling support for perf and AsmJit, options are: None, Assembly, Source")
endif()
if(PROFILING STREQUAL "Assembly")
add_compile_definitions("PROFILING_ASSEMBLY")
elseif(PROFILING STREQUAL "Source")
add_compile_definitions("PROFILING_SOURCE")
endif()
if(MSVC)
set(DISABLE_RTTI_FLAG /GR-)
else()
set(DISABLE_RTTI_FLAG -fno-rtti)
endif()

add_executable(tests tests.cpp)
if(ENABLE_ASMJIT)
target_compile_definitions(tests PRIVATE "ENABLE_ASMJIT")
target_link_libraries(tests ${ASMJIT_LIBRARIES} ${ASMJIT_PERF_LIBRARIES})
endif()
if(ENABLE_LLVMJIT)
target_compile_definitions(tests PRIVATE "ENABLE_LLVMJIT")
target_link_libraries(tests ${LLVM_LIBRARIES})
endif()
add_library(${PROJECT_NAME}_llvmjit INTERFACE)
set_target_properties(${PROJECT_NAME}_llvmjit PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
target_include_directories(${PROJECT_NAME}_llvmjit INTERFACE ${CMAKE_SOURCE_DIR}/include)
add_library(${PROJECT_NAME}::llvmjit ALIAS ${PROJECT_NAME}_llvmjit)

enable_testing()
add_subdirectory(${CMAKE_SOURCE_DIR}/examples)
separate_arguments(LLVM_DEFINITIONS)
target_compile_definitions(${PROJECT_NAME}_llvmjit INTERFACE ${LLVM_DEFINITIONS})

target_include_directories(${PROJECT_NAME}_llvmjit INTERFACE ${LLVM_INCLUDE_DIRS})
if(NOT LLVM_ENABLE_RTTI)
target_compile_options(${PROJECT_NAME}_llvmjit INTERFACE ${DISABLE_RTTI_FLAG})
endif()

target_compile_definitions(${PROJECT_NAME}_llvmjit INTERFACE ENABLE_LLVMJIT)
if ("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
target_compile_definitions(${PROJECT_NAME}_llvmjit INTERFACE LLVMJIT_DEBUG)
endif()
target_link_directories(${PROJECT_NAME}_llvmjit INTERFACE ${LLVM_LIBRARY_DIRS})
target_link_libraries(${PROJECT_NAME}_llvmjit INTERFACE LLVMCore LLVMX86CodeGen LLVMPerfJITEvents LLVMOrcJIT LLVMExecutionEngine)

coat_add_executable(NAMES
tests
calculator
fibonacci
BACKEND llvmjit)

coat_add_executable(NAMES
sum
cast
call
reading_datastruct
# Just trying vector types
vectormean
vectormerge
vectorintersection
BACKEND llvmjit
TEST)

add_executable(calculator calculator.cpp)
if(ENABLE_ASMJIT)
target_compile_definitions(calculator PRIVATE "ENABLE_ASMJIT")
target_link_libraries(calculator ${ASMJIT_LIBRARIES} ${ASMJIT_PERF_LIBRARIES})
endif()
if(ENABLE_LLVMJIT)
target_compile_definitions(calculator PRIVATE "ENABLE_LLVMJIT")
target_link_libraries(calculator ${LLVM_LIBRARIES})
endif()

add_executable(fibonacci fibonacci.cpp)
if(ENABLE_ASMJIT)
target_compile_definitions(fibonacci PRIVATE "ENABLE_ASMJIT")
target_link_libraries(fibonacci ${ASMJIT_LIBRARIES} ${ASMJIT_PERF_LIBRARIES})
endif()
if(ENABLE_LLVMJIT)
target_compile_definitions(fibonacci PRIVATE "ENABLE_LLVMJIT")
target_link_libraries(fibonacci ${LLVM_LIBRARIES})
add_subdirectory(ThirdParty/asmjit)
set(ASMJIT_INCLUDE_DIR ThirdParty/asmjit/src/asmjit)
set(ASMJIT_LIBRARIES asmjit)
add_subdirectory(ThirdParty/asmjit-utilities/perf)

add_library(${PROJECT_NAME}_asmjit INTERFACE)
set_target_properties(${PROJECT_NAME}_asmjit PROPERTIES CXX_STANDARD 17 CXX_STANDARD_REQUIRED ON)
target_include_directories(${PROJECT_NAME}_asmjit INTERFACE ${CMAKE_SOURCE_DIR}/include)
add_library(${PROJECT_NAME}::asmjit ALIAS ${PROJECT_NAME}_asmjit)

target_compile_definitions(${PROJECT_NAME}_asmjit INTERFACE ENABLE_ASMJIT)
target_link_libraries(${PROJECT_NAME}_asmjit INTERFACE asmjit asmjit_perf)

# Debugging options
if(NOT DEFINED PROFILING)
set(PROFILING "" CACHE STRING "Choose type of profiling support for perf and AsmJit, options are: None, Assembly, Source")
endif()
if(PROFILING STREQUAL "Assembly")
target_compile_definitions(${PROJECT_NAME}_asmjit INTERFACE PROFILING_ASSEMBLY)
elseif(PROFILING STREQUAL "Source")
target_compile_definitions(${PROJECT_NAME}_asmjit PROFILING_SOURCE)
endif()

coat_add_executable(NAMES
tests
calculator
fibonacci
BACKEND asmjit)

coat_add_executable(NAMES
sum
cast
call
reading_datastruct
# Just trying vector types
vectormean
BACKEND asmjit
TEST)

endif()

40 changes: 22 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ This library tries to make JIT compilation as easy as possible.
More details are explained in a [blog post](https://tetzank.github.io/posts/coat-edsl-for-codegen/).


## Build Instructions

Ensure submodules are fetched, and build with CMake:

```
git submodule init
git submodule update
mkdir build
cd build
cmake ..
make -j4
make test
```

The library is header-only. Small example programs are included to show how to use the library:

```
cd build
./example_coat_llvmjit_calculator
./example_coat_asmjit_calculator
```

## Example

The following code snippet is a full example program.
Expand Down Expand Up @@ -301,24 +323,6 @@ func_t foo = fn.finalize();
```


## Build Instructions

The library is header-only. Small test programs are included to show how to use the library.

Fetch JIT engines and build them (use `-j` for parallel compilation, LLVM can take a while...):
```
$ ./buildDependencies.sh -j8
```

Then, build with cmake:
```
$ mkdir build
$ cd build
$ cmake ..
$ make
```


## Profiling Instructions

Profiling is currently only supported for the AsmJit backend and perf on Linux.
Expand Down
27 changes: 0 additions & 27 deletions buildDependencies.sh

This file was deleted.

80 changes: 0 additions & 80 deletions examples/CMakeLists.txt

This file was deleted.

1 change: 0 additions & 1 deletion external/llvm
Submodule llvm deleted from 1fdec5
Loading