Mercurial > hg > octave-nkf
diff libinterp/corefcn/pt-jit.h @ 20830:b65888ec820e draft default tip gccjit
dmalcom gcc jit import
author | Stefan Mahr <dac922@gmx.de> |
---|---|
date | Fri, 27 Feb 2015 16:59:36 +0100 |
parents | 4197fc428c7d |
children |
line wrap: on
line diff
--- a/libinterp/corefcn/pt-jit.h +++ b/libinterp/corefcn/pt-jit.h @@ -25,12 +25,13 @@ #if !defined (octave_pt_jit_h) #define octave_pt_jit_h 1 -#ifdef HAVE_LLVM +#ifdef HAVE_JIT #include "jit-ir.h" #include "pt-walk.h" #include "symtab.h" + class octave_value_list; // Convert from the parse tree (AST) to the low level Octave IR. @@ -69,7 +70,9 @@ jit_factory& get_factory (void) { return factory; } +#ifdef HAVE_LLVM llvm::Function *get_function (void) const { return function; } +#endif const variable_map &get_variable_map (void) const { return vmap; } @@ -180,7 +183,9 @@ jit_block *block; +#ifdef HAVE_LLVM llvm::Function *function; +#endif jit_block_list blocks; @@ -242,7 +247,81 @@ void finish_breaks (jit_block *dest, const block_list& lst); }; +// Convert from the low level Octave IR to libgccjit +#ifdef HAVE_GCCJIT +class +jit_convert_gcc : public jit_ir_walker +{ +public: + jit_convert_gcc (); + ~jit_convert_gcc (); + + gcc_jit_result *convert_loop (const jit_block_list& blocks, + const std::list<jit_value *>& constants); + +#define JIT_METH(clname) \ + virtual void visit (jit_ ## clname&); + + JIT_VISIT_IR_CLASSES; + +private: + void visit (jit_value *jvalue) + { + return visit (*jvalue); + } + + void visit (jit_value &jvalue) + { + jvalue.accept (*this); + } + +#if 0 + gccjit::lvalue as_lvalue (jit_value *); +#endif + gccjit::rvalue as_rvalue (jit_value *); + + void add_assignment_for_insn (jit_instruction &insn, + gccjit::rvalue val); + + gccjit::block get_block_for_edge (jit_block *src, jit_block *dest); + + gccjit::block get_current_block (); + void push_block (gccjit::block block); + void pop_block (); + + bool converting_function; + + // Inputs (used internally by callback): + const jit_block_list *m_blocks; + const std::list<jit_value *> *m_constants; + + // Internal state: + gccjit::context m_ctxt; + gccjit::function m_func; + + /* We have a single param, confusingly named "params" (an array). */ + gccjit::param params; + + // name -> argument index (used for compiling functions) + std::map<std::string, int> m_argument_index; + std::vector<std::pair<std::string, bool> > m_argument_vec; + + std::vector<gccjit::lvalue> m_extracted_params; + std::map<jit_block *, gccjit::block> m_block_map; + std::map<std::pair<jit_block *, jit_block *>, gccjit::block> m_blocks_for_edges; + std::map<jit_instruction *, gccjit::lvalue> m_locals_for_insns; + + std::map<jit_value *, gccjit::rvalue> m_rvalues; + + std::stack<gccjit::block> m_block_stack; + + bool m_with_comments; + bool m_log_visits; +}; +#endif // #ifdef HAVE_GCCJIT + // Convert from the low level Octave IR to LLVM +#if HAVE_LLVM class jit_convert_llvm : public jit_ir_walker { @@ -299,6 +378,7 @@ jvalue.accept (*this); } }; +#endif /* HAVE_LLVM */ // type inference and SSA construction on the low level Octave IR class @@ -362,11 +442,13 @@ static bool execute (octave_user_function& fcn, const octave_value_list& args, octave_value_list& retval); +#ifdef HAVE_LLVM llvm::ExecutionEngine *get_engine (void) const { return engine; } llvm::Module *get_module (void) const { return module; } void optimize (llvm::Function *fn); +#endif private: tree_jit (void); @@ -385,6 +467,7 @@ size_t trip_count (const octave_value& bounds) const; +#ifdef HAVE_LLVM llvm::Module *module; #ifdef LEGACY_PASSMANAGER llvm::legacy::PassManager *module_pass_manager; @@ -394,6 +477,7 @@ llvm::FunctionPassManager *pass_manager; #endif llvm::ExecutionEngine *engine; +#endif }; class @@ -439,13 +523,19 @@ octave_value find (const vmap& extra_vars, const std::string& vname) const; +#ifdef HAVE_LLVM llvm::ExecutionEngine *engine; +#endif jited_function function; +#ifdef HAVE_LLVM llvm::Function *llvm_function; - +#endif +#ifdef HAVE_GCCJIT + gcc_jit_result *gccjit_result; +#endif std::vector<std::pair<std::string, bool> > arguments; type_bound_vector bounds; }; +#endif /* ifdef HAVE_JIT */ #endif -#endif