xo-jit: + LlvmContext to keepalive native LLVMContext
This commit is contained in:
parent
f3af5d27bf
commit
a927d44e0e
7 changed files with 94 additions and 17 deletions
|
|
@ -6,6 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "xo/refcnt/Refcounted.hpp"
|
||||
#include "LlvmContext.hpp"
|
||||
|
||||
/* stuff from kaleidoscope.cpp */
|
||||
#include "llvm/ADT/APFloat.h"
|
||||
|
|
@ -46,13 +47,16 @@ namespace xo {
|
|||
**/
|
||||
class IrPipeline : public ref::Refcount {
|
||||
public:
|
||||
explicit IrPipeline(llvm::LLVMContext & llvm_cx);
|
||||
explicit IrPipeline(ref::rp<LlvmContext> llvm_cx);
|
||||
|
||||
void run_pipeline(llvm::Function & fn);
|
||||
|
||||
private:
|
||||
// ----- transforms (also adapted from kaleidescope.cpp) ------
|
||||
|
||||
/** keepalive for contained llvm::LLVMContext **/
|
||||
ref::rp<LlvmContext> llvm_cx_;
|
||||
|
||||
/** manages all the passes+analaysis (?) **/
|
||||
std::unique_ptr<llvm::FunctionPassManager> llvm_fpmgr_;
|
||||
/** loop analysis (?) **/
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "xo/refcnt/Refcounted.hpp"
|
||||
#include "IrPipeline.hpp"
|
||||
#include "LlvmContext.hpp"
|
||||
#include "xo/expression/Expression.hpp"
|
||||
#include "xo/expression/ConstantInterface.hpp"
|
||||
#include "xo/expression/PrimitiveInterface.hpp"
|
||||
|
|
@ -31,7 +32,6 @@
|
|||
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
|
||||
#include "llvm/ExecutionEngine/SectionMemoryManager.h"
|
||||
#include "llvm/IR/DataLayout.h"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
#include <memory>
|
||||
#endif
|
||||
|
||||
|
|
@ -159,7 +159,8 @@ namespace xo {
|
|||
* Not threadsafe, but ok to have multiple threads,
|
||||
* each with its own LLVMContext
|
||||
**/
|
||||
std::unique_ptr<llvm::LLVMContext> llvm_cx_;
|
||||
ref::rp<LlvmContext> llvm_cx_;
|
||||
//std::unique_ptr<llvm::LLVMContext> llvm_cx_;
|
||||
/** builder for intermediate-representation objects **/
|
||||
std::unique_ptr<llvm::IRBuilder<>> llvm_ir_builder_;
|
||||
/** a module (1:1 with library) being prepared by llvm.
|
||||
|
|
|
|||
40
include/xo/jit/LlvmContext.hpp
Normal file
40
include/xo/jit/LlvmContext.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** @file LlvmContext.hpp
|
||||
*
|
||||
* Author: Roland Conybeare
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "xo/refcnt/Refcounted.hpp"
|
||||
#include "llvm/IR/LLVMContext.h"
|
||||
//#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace jit {
|
||||
/** @class LlvmContext
|
||||
* @brief Keepalive for a llvm::LLVMContext instance.
|
||||
*
|
||||
* For example IrPipeline holds an rp<LlvmContext>
|
||||
* to help ensure validity of embedded llvm::LLVMContext reference
|
||||
**/
|
||||
class LlvmContext : public ref::Refcount {
|
||||
public:
|
||||
static xo::ref::rp<LlvmContext> make();
|
||||
|
||||
llvm::LLVMContext & llvm_cx_ref() { return *llvm_cx_; }
|
||||
std::unique_ptr<llvm::LLVMContext> & llvm_cx() { return llvm_cx_; }
|
||||
|
||||
private:
|
||||
LlvmContext();
|
||||
|
||||
private:
|
||||
/** Llvm context. Ties together fragments of code generation
|
||||
* for AST subtrees that go into the same module.
|
||||
**/
|
||||
std::unique_ptr<llvm::LLVMContext> llvm_cx_;
|
||||
}; /*LlvmContext*/
|
||||
} /*namespace jit*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/** end LlvmContext.hpp **/
|
||||
Loading…
Add table
Add a link
Reference in a new issue