26 #if ! defined (octave_pt_jit_h)
27 #define octave_pt_jit_h 1
29 #include "octave-config.h"
31 #if defined (HAVE_LLVM)
64 template <
typename ...Args>
68 return create_checked_impl (ret);
204 jit_variable * find_variable (
const std::string& vname)
const;
218 {
return next_name (
"#iter", m_iterator_count, inc); }
221 {
return next_name (
"#for_bounds", m_for_bounds_count, inc); }
224 {
return next_name (
"#shortcircut_result", m_short_count, inc); }
226 std::string next_name (
const char *prefix,
size_t& count,
bool inc);
229 jit_value *extra_arg =
nullptr,
bool lhs =
false);
232 bool artificial =
false);
235 bool artificial =
false);
254 llvm::Function * convert_loop (
const jit_module& module,
256 const std::list<jit_value *>& constants,
257 const std::string& llvm_function_name);
261 const std::list<jit_value *>& constants,
263 const std::vector<jit_type *>& args);
267 {
return m_argument_vec; }
269 #define JIT_METH(clname) \
270 virtual void visit (jit_ ## clname&);
295 const std::list<jit_value *>& constants);
297 void finish_phi (
jit_phi *phi);
301 return visit (*jvalue);
338 void construct_ssa (
void);
340 void do_construct_ssa (
jit_block& block,
size_t avisit_count);
346 void place_releases (
void);
352 void release_dead_phi (
jit_block& ablock);
354 void release_temp (
jit_block& ablock, std::set<jit_value *>& temp);
356 void simplify_phi (
void);
358 void simplify_phi (
jit_phi& phi);
383 bool do_initialize (
void);
407 open_new_module (
const std::string& module_name = generate_unique_module_name ());
415 do_open_new_module (
const std::string& module_name)
const;
432 void do_unregister_jit_module (
jit_module* jm);
447 void* do_getPointerToNamedFunction (
const std::string &Name)
const;
449 uint64_t do_getSymbolAddress (
const std::string &
name)
const;
457 return std::string (
"jittedForLoop")
458 + std::to_string (next_forloop_number ++);
464 return std::string (
"jittedFunction")
465 + std::to_string (next_function_number ++);
471 return std::string (
"octaveJITModule")
472 + std::to_string (next_module_number ++);
488 {
return instance ().
do_execute (cmd, bounds); }
537 create_llvm_function (llvm::FunctionType *ftype,
538 const llvm::Twine &
name)
const;
541 llvm::GlobalVariable*
542 create_global_variable (llvm::Type *
type,
bool is_constant,
543 const llvm::Twine&
name)
const;
548 get_intrinsic_declaration (
size_t id,
549 std::vector<llvm::Type*> types)
const;
556 template <
typename ptr_type>
559 do_add_global_mapping (gv,
reinterpret_cast<void *
> (p));
563 uint64_t getFunctionAddress (
const std::string &
name)
const;
566 void optimize (llvm::Function *fn)
const;
570 void finalizeObject (
void);
574 void do_add_global_mapping (
const llvm::GlobalValue* gv,
void* p)
const;
587 typedef std::map<std::string, const octave_value *>
vmap;
595 bool execute (
const vmap& extra_vars =
vmap ())
const;
597 bool match (
const vmap& extra_vars =
vmap ())
const;
jit_block * front(void) const
jit_block * back(void) const
llvm::Function * m_function
std::map< std::string, llvm::Value * > m_arguments
void visit(jit_value *jvalue)
const std::vector< std::pair< std::string, bool > > & get_arguments(void) const
llvm::BasicBlock * m_prelude
bool m_converting_function
std::vector< std::pair< std::string, bool > > m_argument_vec
void visit(jit_value &jvalue)
std::map< std::string, int > m_argument_index
llvm::Function * m_function
bool m_converting_function
std::string next_for_bounds(bool inc=true)
void visit_if_command(tree_if_command &)
void visit_statement_list(tree_statement_list &)
jit_factory & get_factory(void)
jit_block_list & get_blocks(void)
llvm::Function * get_function(void) const
std::vector< type_bound > type_bound_vector
jit_block * m_entry_block
jit_block * m_final_block
std::vector< std::pair< std::string, bool > > m_arguments
jit_value * visit(tree *tee)
const variable_map & get_variable_map(void) const
std::string next_shortcircut_result(bool inc=true)
std::pair< jit_type *, std::string > type_bound
std::vector< jit_magic_end::context > m_end_context
size_t m_for_bounds_count
std::string next_iterator(bool inc=true)
type_bound_vector m_bounds
std::list< jit_block * > block_list
jit_call * create_checked(const Args &... args)
std::map< std::string, jit_variable * > variable_map
const type_bound_vector & get_bounds(void) const
jited_function m_function
std::string m_llvm_function_name
std::vector< jit_type * > m_argument_types
std::list< jit_instruction * > m_worklist
jit_block_list & get_blocks(void) const
jit_block_list & m_blocks
jit_convert::variable_map variable_map
jit_factory & get_factory(void) const
jit_block & entry_block(void)
const variable_map & m_vmap
jit_block & final_block(void)
type_bound_vector m_bounds
std::vector< std::pair< std::string, bool > > m_arguments
jited_function m_function
jit_convert::type_bound type_bound
std::map< std::string, const octave_value * > vmap
std::string m_llvm_function_name
jit_convert::type_bound_vector type_bound_vector
llvm::ExecutionEngine * m_engine
void add_global_mapping(const llvm::GlobalValue *gv, ptr_type p) const
virtual void accept(jit_ir_walker &walker)=0
static int next_module_number
void * do_getPointerToNamedFunction(const std::string &Name) const
uint64_t do_getSymbolAddress(const std::string &name) const
static const llvm::TargetMachine * get_target_machine(void)
void do_register_jit_module(jit_module *jm)
static llvm::LLVMContext llvm_context
void do_unregister_jit_module(jit_module *jm)
static void * getPointerToNamedFunction(const std::string &name)
std::list< jit_module * > jm_list
static uint64_t getSymbolAddress(const std::string &name)
static bool execute(tree_while_command &cmd)
static int next_function_number
static void unregister_jit_module(jit_module *jm)
static bool execute(tree_simple_for_command &cmd, const octave_value &bounds)
static void register_jit_module(jit_module *jm)
static int next_forloop_number
llvm::TargetMachine * target_machine
static std::string generate_unique_module_name(void)
static std::string generate_unique_forloop_name(void)
bool do_execute(tree_simple_for_command &cmd, const octave_value &bounds)
static bool execute(octave_user_function &fcn, const octave_value_list &args, octave_value_list &retval)
void do_dump_all_modules(void) const
static std::string generate_unique_function_name(void)
static octave_idx_type find(octave_idx_type i, octave_idx_type *pp)
static int convert(int x, int ibase, int obase)
#define JIT_VISIT_IR_CLASSES
static void initialize(void)
static std::string get_variable(const char *name, const std::string &defval)
std::unique_ptr< llvm::ExecutionEngine > EngineOwner
std::unique_ptr< llvm::Module > ModuleOwner
octave_value::octave_value(const Array< char > &chm, char type) return retval