Skip to content

Commit 1cf325d

Browse files
committed
Merge remote-tracking branch 'origin/develop'
2 parents 5be14fe + c1f86c9 commit 1cf325d

File tree

17 files changed

+120
-39
lines changed

17 files changed

+120
-39
lines changed

.github/workflows/ci-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ cmake .. \
1515
-DBUILD_TESTS=On \
1616
-DCMAKE_INSTALL_PREFIX=install
1717
make -j$(nproc) install
18+
make test
1819
popd
1920

2021
pushd matching

cmake/FindLLVM.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ find_program(LLDB lldb
2929
PATHS ${LLVM_TOOLS_BINARY_DIR}
3030
NO_DEFAULT_PATH)
3131

32+
find_program(LLVM_DIS llvm-dis
33+
PATHS ${LLVM_TOOLS_BINARY_DIR}
34+
NO_DEFAULT_PATH)
35+
3236
execute_process(
3337
COMMAND "${LLVM_TOOLS_BINARY_DIR}/llvm-config" "--libdir"
3438
OUTPUT_VARIABLE LLVM_LIBRARY_DIR
@@ -41,3 +45,7 @@ endif()
4145
if(NOT LLC)
4246
message(FATAL_ERROR "Could not find an llc binary. Is llvm installed on your PATH?")
4347
endif()
48+
49+
if(NOT LLVM_DIS)
50+
message(FATAL_ERROR "Could not find an llvm-dis binary. Is llvm installed on your PATH?")
51+
endif()

cmake/LLVMKompilePrelude.cmake

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
1+
find_program(CMAKE_C_COMPILER clang-18)
2+
find_program(CMAKE_C_COMPILER clang-17)
13
find_program(CMAKE_C_COMPILER clang-16)
24
find_program(CMAKE_C_COMPILER clang-15)
3-
find_program(CMAKE_C_COMPILER clang-14)
4-
find_program(CMAKE_C_COMPILER clang-13)
5-
find_program(CMAKE_C_COMPILER clang-12)
65
find_program(CMAKE_C_COMPILER clang)
6+
find_program(CMAKE_CXX_COMPILER clang++-18)
7+
find_program(CMAKE_CXX_COMPILER clang++-17)
78
find_program(CMAKE_CXX_COMPILER clang++-16)
89
find_program(CMAKE_CXX_COMPILER clang++-15)
9-
find_program(CMAKE_CXX_COMPILER clang++-14)
10-
find_program(CMAKE_CXX_COMPILER clang++-13)
11-
find_program(CMAKE_CXX_COMPILER clang++-12)
1210
find_program(CMAKE_CXX_COMPILER clang++)
11+
find_program(CMAKE_C_COMPILER_AR llvm-ar-18)
12+
find_program(CMAKE_C_COMPILER_AR llvm-ar-17)
1313
find_program(CMAKE_C_COMPILER_AR llvm-ar-16)
1414
find_program(CMAKE_C_COMPILER_AR llvm-ar-15)
15-
find_program(CMAKE_C_COMPILER_AR llvm-ar-14)
16-
find_program(CMAKE_C_COMPILER_AR llvm-ar-13)
17-
find_program(CMAKE_C_COMPILER_AR llvm-ar-12)
1815
find_program(CMAKE_C_COMPILER_AR llvm-ar)
16+
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-18)
17+
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-17)
1918
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-16)
2019
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-15)
21-
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-14)
22-
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-13)
23-
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib-12)
2420
find_program(CMAKE_C_COMPILER_RANLIB llvm-ranlib)

include/kllvm/codegen/ApplyPasses.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
namespace kllvm {
88

9+
void do_bitcode_linking(llvm::Module &);
10+
911
void apply_kllvm_opt_passes(llvm::Module &, bool hidden_visibility);
1012

1113
void generate_object_file(llvm::Module &, llvm::raw_ostream &);

include/runtime/alloc_cpp.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#ifndef ALLOC_CPP_H
2+
#define ALLOC_CPP_H
3+
4+
/* This header file declares a string containing the textual bitcode of
5+
* runtime/lto/alloc.cpp. The cpp file that defines these symbols is generated
6+
* from that library by the lto library. The reason we do this is to ensure
7+
* that code generation can inline the bump allocator fully into the functions
8+
* that it is called from, which is quite important for performance.
9+
*/
10+
extern unsigned char alloc_cpp_o_ll[];
11+
extern unsigned int alloc_cpp_o_ll_len;
12+
13+
#endif

include/runtime/arena.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
#include <cstddef>
55
#include <sys/types.h>
66

7+
#include "runtime/alloc.h"
8+
79
extern "C" {
810

911
// An arena can be used to allocate objects that can then be deallocated all at
@@ -51,11 +53,24 @@ char get_arena_collection_semispace_id(const struct arena *);
5153
// allocated within an arena.
5254
char get_arena_semispace_id_of_object(void *);
5355

56+
// helper function for `kore_arena_alloc`. Do not call directly.
57+
void *do_alloc_slow(size_t, struct arena *);
58+
5459
// Allocates the requested number of bytes as a contiguous region and returns a
5560
// pointer to the first allocated byte.
5661
// If called with requested size greater than the maximun single allocation
5762
// size, the space is allocated in a general (not garbage collected pool).
58-
void *kore_arena_alloc(struct arena *, size_t);
63+
inline void *kore_arena_alloc(struct arena *arena, size_t requested) {
64+
if (arena->block + requested > arena->block_end) {
65+
return do_alloc_slow(requested, arena);
66+
}
67+
void *result = arena->block;
68+
arena->block += requested;
69+
MEM_LOG(
70+
"Allocation at %p (size %zd), next alloc at %p (if it fits)\n", result,
71+
requested, arena->block);
72+
return result;
73+
}
5974

6075
// Resizes the last allocation as long as the resize does not require a new
6176
// block allocation.

lib/codegen/ApplyPasses.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <kllvm/codegen/Options.h>
33
#include <kllvm/codegen/SetVisibilityHidden.h>
44

5+
#include "runtime/alloc_cpp.h"
56
#include "runtime/header.h"
67

78
#if LLVM_VERSION_MAJOR >= 17
@@ -12,7 +13,10 @@
1213
#include <llvm/Support/Host.h>
1314
#endif
1415

16+
#include "llvm/IRReader/IRReader.h"
17+
#include <llvm/Bitcode/BitcodeReader.h>
1518
#include <llvm/IR/LegacyPassManager.h>
19+
#include <llvm/Linker/Linker.h>
1620
#include <llvm/MC/TargetRegistry.h>
1721
#include <llvm/Pass.h>
1822
#include <llvm/Support/CommandLine.h>
@@ -145,4 +149,24 @@ void generate_object_file(llvm::Module &mod, llvm::raw_ostream &os) {
145149
pm.run(mod);
146150
}
147151

152+
/* This function links the code generated module generated by
153+
* llvm-kompile-codegen with any llvm bitcode modules we wish to place in the
154+
* same translation unit as the code generated code during optimization. This
155+
* is done currently with only a single file: runtime/lto/alloc.cpp. We do this
156+
* so that inlining can occur across the functions in each file.
157+
*/
158+
void do_bitcode_linking(llvm::Module &mod) {
159+
Linker linker(mod);
160+
llvm::SMDiagnostic err;
161+
auto alloc_cpp_mod = llvm::parseIR(
162+
*llvm::MemoryBuffer::getMemBuffer(
163+
std::string((char *)alloc_cpp_o_ll, alloc_cpp_o_ll_len)),
164+
err, mod.getContext());
165+
bool error = linker.linkInModule(std::move(alloc_cpp_mod));
166+
if (error) {
167+
throw std::runtime_error(
168+
"Bitcode linking failed. Please report this as a bug.");
169+
}
170+
}
171+
148172
} // namespace kllvm

lib/codegen/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ add_library(Codegen
1313
)
1414

1515
target_link_libraries(Codegen
16-
PUBLIC AST fmt::fmt-header-only
16+
PUBLIC AST fmt::fmt-header-only alloc-cpp
1717
PRIVATE base64)

runtime/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ install(
99
DESTINATION lib/kllvm/llvm/main
1010
)
1111

12-
add_subdirectory(arithmetic)
13-
add_subdirectory(util)
14-
add_subdirectory(strings)
15-
add_subdirectory(meta)
1612
add_subdirectory(alloc)
13+
add_subdirectory(arithmetic)
1714
add_subdirectory(collect)
18-
add_subdirectory(io)
1915
add_subdirectory(collections)
16+
add_subdirectory(io)
2017
add_subdirectory(json)
18+
add_subdirectory(lto)
19+
add_subdirectory(meta)
20+
add_subdirectory(strings)
21+
add_subdirectory(util)

runtime/alloc/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_library(alloc STATIC
2-
alloc.cpp
32
arena.cpp
43
register_gc_roots_enum.cpp
54
)

0 commit comments

Comments
 (0)