Moving the jitdylib storage to the jit engine
This commit is contained in:
parent
a9a8bb9fde
commit
482a410b11
|
@ -96,12 +96,17 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
|||
-fdata-sections
|
||||
|
||||
$<$<CONFIG:DEBUG>:-g3>
|
||||
$<$<CONFIG:DEBUG>:-O1>
|
||||
$<$<CONFIG:DEBUG>:-ggdb>
|
||||
# For the sake of debugging
|
||||
$<$<CONFIG:DEBUG>:-fno-inline>
|
||||
# To make the local ccache happy
|
||||
$<$<CONFIG:DEBUG>:-fdebug-prefix-map=${PROJECT_SOURCE_DIR}=.>
|
||||
|
||||
# No tail call elimination on Debug to let asan provide
|
||||
# better stacktrackes
|
||||
$<$<CONFIG:DEBUG>:-fno-optimize-sibling-calls>
|
||||
|
||||
$<$<CONFIG:DEBUG>:-fno-omit-frame-pointer>
|
||||
$<$<CONFIG:RELEASE>:-fomit-frame-pointer>
|
||||
$<$<CONFIG:DEBUG>:-fsanitize=address>
|
||||
|
|
|
@ -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<types::InternalString> stringStorage;
|
||||
std::vector<std::unique_ptr<types::InternalString>> stringStorage;
|
||||
|
||||
std::vector<types::Namespace> nsStorage;
|
||||
std::vector<std::unique_ptr<types::Namespace>> nsStorage;
|
||||
// /TODO
|
||||
|
||||
// JIT JITDylib related functions ---
|
||||
|
@ -130,6 +130,8 @@ 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);
|
||||
|
||||
public:
|
||||
Halley(std::unique_ptr<SereneContext> ctx,
|
||||
llvm::orc::JITTargetMachineBuilder &&jtmb, llvm::DataLayout &&dl);
|
||||
|
@ -140,9 +142,7 @@ public:
|
|||
SereneContext &getContext() { return *ctx; };
|
||||
|
||||
llvm::Error createEmptyNS(llvm::StringRef name);
|
||||
|
||||
types::InternalString &insertString(types::InternalString &s);
|
||||
types::Namespace &insertNamespace(types::Namespace &n);
|
||||
types::InternalString &getInternalString(llvm::StringRef s);
|
||||
|
||||
/// Return a pointer to the most registered JITDylib of the given \p ns
|
||||
////name
|
||||
|
|
|
@ -19,22 +19,20 @@
|
|||
#ifndef SERENE_TYPES_TYPE_H
|
||||
#define SERENE_TYPES_TYPE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace serene::types {
|
||||
|
||||
struct Expression {
|
||||
const int8_t *data;
|
||||
|
||||
explicit Expression(const int8_t *data) : data(data){};
|
||||
const unsigned char *data;
|
||||
explicit Expression(const unsigned char *data) : data(data){};
|
||||
};
|
||||
|
||||
struct InternalString {
|
||||
// We store the actual string in a "string" data section
|
||||
const char *data;
|
||||
const int64_t len;
|
||||
const unsigned int len;
|
||||
|
||||
InternalString(const char *data, const int64_t len) : data(data), len(len){};
|
||||
InternalString(const char *data, const unsigned int len)
|
||||
: data(data), len(len){};
|
||||
};
|
||||
|
||||
struct Symbol {
|
||||
|
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
#include <system_error> // for error...
|
||||
|
||||
#include <llvm/ADT/StringMapEntry.h> // for Strin...
|
||||
#include <llvm/ADT/StringMapEntry.h> // for Strin...
|
||||
#include <llvm/ADT/StringRef.h>
|
||||
#include <llvm/ADT/Triple.h> // for Triple
|
||||
#include <llvm/ADT/iterator.h> // for itera...
|
||||
#include <llvm/ExecutionEngine/JITEventListener.h> // for JITEv...
|
||||
|
@ -124,11 +125,13 @@ void Halley::pushJITDylib(types::Namespace &ns, llvm::orc::JITDylib *l) {
|
|||
}
|
||||
|
||||
size_t Halley::getNumberOfJITDylibs(types::Namespace &ns) {
|
||||
llvm::outs() << *ns.name->data << "hnt\n";
|
||||
|
||||
if (jitDylibs.count(ns.name->data) == 0) {
|
||||
return 0;
|
||||
}
|
||||
auto vec = jitDylibs[ns.name->data];
|
||||
return vec.size();
|
||||
|
||||
return jitDylibs[ns.name->data].size();
|
||||
};
|
||||
|
||||
Halley::Halley(std::unique_ptr<SereneContext> ctx,
|
||||
|
@ -344,34 +347,40 @@ MaybeEngine Halley::make(std::unique_ptr<SereneContext> sereneCtxPtr,
|
|||
return MaybeEngine(std::move(jitEngine));
|
||||
};
|
||||
|
||||
types::InternalString &Halley::insertString(types::InternalString &s) {
|
||||
stringStorage.push_back(s);
|
||||
auto &sameString = stringStorage.back();
|
||||
return sameString;
|
||||
types::InternalString &Halley::getInternalString(llvm::StringRef 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 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;
|
||||
// /TODO
|
||||
};
|
||||
|
||||
types::Namespace &Halley::insertNamespace(types::Namespace &n) {
|
||||
nsStorage.push_back(n);
|
||||
auto &sameNs = nsStorage.back();
|
||||
return sameNs;
|
||||
types::Namespace &Halley::createNamespace(llvm::StringRef 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;
|
||||
// /TODO
|
||||
};
|
||||
|
||||
llvm::Error Halley::createEmptyNS(llvm::StringRef 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
|
||||
types::InternalString nsName_(name.str().c_str(), name.size());
|
||||
auto &nsName = insertString(nsName_);
|
||||
auto &ns = createNamespace(name);
|
||||
|
||||
types::Namespace ns_(&nsName);
|
||||
auto &ns = insertNamespace(ns_);
|
||||
auto numOfDylibs = getNumberOfJITDylibs(ns) + 1;
|
||||
|
||||
HALLEY_LOG(llvm::formatv("Creating Dylib {0}#{1}", ns.name,
|
||||
getNumberOfJITDylibs(ns) + 1));
|
||||
HALLEY_LOG(llvm::formatv("Creating Dylib {0}#{1}", ns.name, numOfDylibs));
|
||||
|
||||
auto newDylib = engine->createJITDylib(
|
||||
llvm::formatv("{0}#{1}", ns.name, getNumberOfJITDylibs(ns) + 1));
|
||||
auto newDylib =
|
||||
engine->createJITDylib(llvm::formatv("{0}#{1}", ns.name, numOfDylibs));
|
||||
|
||||
if (!newDylib) {
|
||||
llvm::errs() << "Couldn't create the jitDylib\n";
|
||||
|
|
|
@ -269,19 +269,27 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
cl::ParseCommandLineOptions(argc, argv, banner);
|
||||
|
||||
auto engine = makeEngine();
|
||||
auto maybeEngine = makeEngine();
|
||||
|
||||
if (!engine) {
|
||||
if (!maybeEngine) {
|
||||
llvm::errs() << "Error: Couldn't create the engine due to '"
|
||||
<< engine.takeError() << "'\n";
|
||||
<< maybeEngine.takeError() << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
applySereneCLOptions(*(*engine));
|
||||
auto &engine = *maybeEngine;
|
||||
applySereneCLOptions(*engine);
|
||||
|
||||
const std::string forms{"some.ns/sym"};
|
||||
const types::InternalString data(forms.c_str(), forms.size());
|
||||
|
||||
auto err = engine->createEmptyNS("some.ns/sym");
|
||||
|
||||
if (err) {
|
||||
llvm::errs() << "Error: " << err << "'\n";
|
||||
return 1;
|
||||
}
|
||||
|
||||
// // TODO: handle the outputDir by not forcing it. it should be
|
||||
// // default to the current working dir
|
||||
// if (outputDir == "-") {
|
||||
|
|
Loading…
Reference in New Issue