Add BDW gc and change the JIT interface to use raw pointers

This commit is contained in:
Sameer Rahmani 2022-07-01 18:17:50 +01:00
parent 482a410b11
commit 5bec18b327
8 changed files with 56 additions and 29 deletions

View File

@ -15,6 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
cmake_minimum_required(VERSION 3.19)
# Project name and a few useful settings. Other commands can pick up the results
project(Serene
VERSION 1.0.0
@ -139,6 +140,8 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
set(BUILD_SHARED_LIBS "${SERENE_SHARED_LIB}")
endif()
find_package(BDWgc 8.2.0 REQUIRED)
find_program(LLD_PROGRAM REQUIRED NAMES lld)
find_program(MLIRTBLGEN_PROGRAM REQUIRED NAMES mlir-tblgen)

11
builder
View File

@ -31,6 +31,13 @@
# Make sure to provid one line of DESCRIPTION for the subcommand and use two "#"
# characters to start the description following by a space. Otherwise, your
# subcommand won't be registered
#
## Verbos Mode
# In order to turn on the verbose mode for your build just invoke the builder script
# like:
#
# $ VERBOSE=ON ./builder build/
#
set -e
@ -66,8 +73,8 @@ BUILD_DIR=$ROOT_DIR/build
ME=$(cd "$(dirname "$0")/." >/dev/null 2>&1 ; pwd -P)
CMAKEARGS_DEBUG=("-DCMAKE_BUILD_TYPE=Debug")
# Verbose -DCMAKE_VERBOSE_MAKEFILE:BOOL=ON
CMAKEARGS=("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON" "-DSERENE_CCACHE_DIR=$HOME/.ccache")
CMAKEARGS=("-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
"-DSERENE_CCACHE_DIR=$HOME/.ccache")
# -----------------------------------------------------------------------------
# Helper functions

View File

@ -116,9 +116,9 @@ class SERENE_EXPORT Halley {
// the strings. A lockless algorithm would be even better
/// Owns all the internal strings used in the compilation process
std::vector<std::unique_ptr<types::InternalString>> stringStorage;
std::vector<types::InternalString *> stringStorage;
std::vector<std::unique_ptr<types::Namespace>> nsStorage;
std::vector<types::Namespace *> nsStorage;
// /TODO
// JIT JITDylib related functions ---
@ -130,7 +130,7 @@ class SERENE_EXPORT Halley {
// /// Returns the number of registered `JITDylib` for the given \p ns.
size_t getNumberOfJITDylibs(types::Namespace &ns);
types::Namespace &createNamespace(llvm::StringRef name);
types::Namespace &createNamespace(const char *name);
public:
Halley(std::unique_ptr<SereneContext> ctx,
@ -141,8 +141,8 @@ public:
SereneContext &getContext() { return *ctx; };
llvm::Error createEmptyNS(llvm::StringRef name);
types::InternalString &getInternalString(llvm::StringRef s);
llvm::Error createEmptyNS(const char *name);
const types::InternalString &getInternalString(const char *s);
/// Return a pointer to the most registered JITDylib of the given \p ns
////name

View File

@ -18,11 +18,16 @@
#ifndef SERENE_SERENE_H
#define SERENE_SERENE_H
#include "serene/export.h" // for SERENE_EXPORT
#include "serene/jit/halley.h" // for Engine, MaybeEngine
#include "serene/options.h" // for Options
#include <gc.h>
#define SERENE_INIT() \
GC_INIT(); \
initSerene();
namespace serene {
/// Clinet applications have to call this function before any interaction

View File

@ -29,7 +29,7 @@ struct Expression {
struct InternalString {
// We store the actual string in a "string" data section
const char *data;
const unsigned int len;
unsigned int len;
InternalString(const char *data, const unsigned int len)
: data(data), len(len){};

View File

@ -87,5 +87,5 @@ target_compile_definitions(
serene PUBLIC "$<$<NOT:$<BOOL:${BUILD_SHARED_LIBS}>>:SERENE_STATIC_DEFINE>")
target_link_libraries(serene PRIVATE ${llvm_libs})
target_link_libraries(serene PRIVATE ${llvm_libs} BDWgc::gc)
llvm_update_compile_flags(serene)

View File

@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "serene/jit/halley.h"
#include "serene/context.h" // for Seren...
@ -49,9 +50,11 @@
#include <algorithm> // for max
#include <assert.h> // for assert
#include <memory> // for uniqu...
#include <string> // for opera...
#include <utility> // for move
#include <cstring>
#include <gc.h>
#include <memory> // for uniqu...
#include <string> // for opera...
#include <utility> // for move
#define COMMON_ARGS_COUNT 8
@ -347,40 +350,48 @@ MaybeEngine Halley::make(std::unique_ptr<SereneContext> sereneCtxPtr,
return MaybeEngine(std::move(jitEngine));
};
types::InternalString &Halley::getInternalString(llvm::StringRef s) {
const types::InternalString &Halley::getInternalString(const char *s) {
// TODO: [serene.core] We need to provide some functions on llvm level to
// build instances from these type in a functional way. We need to avoid
// randomly build instances here and there that causes unsafe memory
auto len = std::strlen(s);
auto str = std::make_unique<types::InternalString>(s.str().c_str(), s.size());
stringStorage.push_back(std::move(str));
const auto &sameString = stringStorage.back();
return *sameString;
auto *str =
(types::InternalString *)GC_MALLOC_ATOMIC(sizeof(types::InternalString));
str->data = (char *)GC_MALLOC_ATOMIC(len);
memcpy((void *)str->data, (void *)s, len);
str->len = len;
stringStorage.push_back(str);
return *str;
// /TODO
};
types::Namespace &Halley::createNamespace(llvm::StringRef name) {
types::Namespace &Halley::createNamespace(const char *name) {
// TODO: [serene.core] We need to provide some functions on llvm level to
// build instances from these type in a functional way. We need to avoid
// randomly build instances here and there that causes unsafe memory
auto nsName = getInternalString(name);
auto ns = std::make_unique<types::Namespace>(&nsName);
nsStorage.push_back(std::move(ns));
const auto &sameNs = nsStorage.back();
return *sameNs;
const auto &nsName = getInternalString(name);
auto *ns = (types::Namespace *)GC_MALLOC(sizeof(types::Namespace));
ns->name = &nsName;
nsStorage.push_back(ns);
return *ns;
// /TODO
};
llvm::Error Halley::createEmptyNS(llvm::StringRef name) {
llvm::Error Halley::createEmptyNS(const char *name) {
auto &ns = createNamespace(name);
auto numOfDylibs = getNumberOfJITDylibs(ns) + 1;
HALLEY_LOG(llvm::formatv("Creating Dylib {0}#{1}", ns.name, numOfDylibs));
HALLEY_LOG(
llvm::formatv("Creating Dylib {0}#{1}", ns.name->data, numOfDylibs));
auto newDylib =
engine->createJITDylib(llvm::formatv("{0}#{1}", ns.name, numOfDylibs));
auto newDylib = engine->createJITDylib(
llvm::formatv("{0}#{1}", ns.name->data, numOfDylibs));
if (!newDylib) {
llvm::errs() << "Couldn't create the jitDylib\n";

View File

@ -264,7 +264,8 @@ static std::string banner =
// };
int main(int argc, char *argv[]) {
initSerene();
SERENE_INIT();
registerSereneCLOptions();
cl::ParseCommandLineOptions(argc, argv, banner);