Mercurial > hg > octave-lojdl
changeset 15310:b055fc077224
allow jit compiler to be enabled at run-time
* pt-jit.h, pt-jit.cc (Venable_jit_debug, Venable_jit_compiler):
New variables.
(Fenable_jit_debug, Fenable_jit_compiler): New functions.
(jit_info::compile): Make JIT debugging info conditional on
Venable_jit_debug.
* pt-eval.cc (tree_evaluator::visit_simple_for_command,
tree_evaluator::visit_while_command): Make JIT compiling conditional
on Venable_jit_compiler.
* octave.cc (no_jit_compiler_option, jit_debug_option):
New file-scope variables.
(JIT_DEBUG_OPTION, NO_JIT_COMPILER_OPTION): New option macros.
(log_opts): Add --jit_debug and --no-jit-compiler options.
(octave_process_command_line): Handle JIT_DEBUG_OPTION and
NO_JIT_COMPILER_OPTION.
(octave_initialize_interpreter): Handle jit_debug_option and
no_jit_compiler_option.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 06 Sep 2012 01:33:08 -0400 |
parents | c398dde4d409 |
children | de9bfcf637df |
files | libinterp/interp-core/pt-jit.cc libinterp/interp-core/pt-jit.h libinterp/octave.cc libinterp/parse-tree/pt-eval.cc |
diffstat | 4 files changed, 127 insertions(+), 43 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/interp-core/pt-jit.cc +++ b/libinterp/interp-core/pt-jit.cc @@ -27,9 +27,18 @@ #include <config.h> #endif -#ifdef HAVE_LLVM +#include "defun.h" +#include "ov.h" +#include "pt-all.h" +#include "pt-jit.h" +#include "symtab.h" +#include "variables.h" -#include "pt-jit.h" +bool Venable_jit_debug = false; + +bool Venable_jit_compiler = true; + +#ifdef HAVE_LLVM #include <llvm/Analysis/CallGraph.h> #include <llvm/Analysis/Passes.h> @@ -50,9 +59,6 @@ #include <llvm/Bitcode/ReaderWriter.h> #endif -#include "symtab.h" -#include "pt-all.h" - static llvm::IRBuilder<> builder (llvm::getGlobalContext ()); static llvm::LLVMContext& context = llvm::getGlobalContext (); @@ -1710,12 +1716,15 @@ infer.infer (); #ifdef OCTAVE_JIT_DEBUG - jit_block_list& blocks = infer.get_blocks (); - jit_block *entry_block = blocks.front (); - entry_block->label (); - std::cout << "-------------------- Compiling tree --------------------\n"; - std::cout << tee.str_print_code () << std::endl; - blocks.print (std::cout, "octave jit ir"); + if (Venable_jit_debug) + { + jit_block_list& blocks = infer.get_blocks (); + jit_block *entry_block = blocks.front (); + entry_block->label (); + std::cout << "-------------------- Compiling tree --------------------\n"; + std::cout << tee.str_print_code () << std::endl; + blocks.print (std::cout, "octave jit ir"); + } #endif jit_factory& factory = conv.get_factory (); @@ -1728,29 +1737,39 @@ catch (const jit_fail_exception& e) { #ifdef OCTAVE_JIT_DEBUG - if (e.known ()) - std::cout << "jit fail: " << e.what () << std::endl; + if (Venable_jit_debug) + { + if (e.known ()) + std::cout << "jit fail: " << e.what () << std::endl; + } #endif } if (llvm_function) { #ifdef OCTAVE_JIT_DEBUG - std::cout << "-------------------- llvm ir --------------------"; llvm::raw_os_ostream llvm_cout (std::cout); - llvm_function->print (llvm_cout); - std::cout << std::endl; - llvm::verifyFunction (*llvm_function); + + if (Venable_jit_debug) + { + std::cout << "-------------------- llvm ir --------------------"; + llvm_function->print (llvm_cout); + std::cout << std::endl; + llvm::verifyFunction (*llvm_function); + } #endif tjit.optimize (llvm_function); #ifdef OCTAVE_JIT_DEBUG - std::cout << "-------------------- optimized llvm ir " - << "--------------------\n"; - llvm_function->print (llvm_cout); - llvm_cout.flush (); - std::cout << std::endl; + if (Venable_jit_debug) + { + std::cout << "-------------------- optimized llvm ir " + << "--------------------\n"; + llvm_function->print (llvm_cout); + llvm_cout.flush (); + std::cout << std::endl; + } #endif void *void_fn = engine->getPointerToFunction (llvm_function); @@ -1768,6 +1787,34 @@ #endif +DEFUN (enable_jit_debug, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} enable_jit_debug ()\n\ +Query or set the internal variable that determines whether\n\ +debugging/tracing is enabled for Octave's JIT compiler.\n\ +@end deftypefn") +{ +#if defined (HAVE_LLVM) && defined (OCTAVE_JIT_DEBUG) + return SET_INTERNAL_VARIABLE (enable_jit_debug); +#else + warning ("enable_jit_debug: JIT compiling not available in this version of Octave"); + return octave_value (); +#endif +} + +DEFUN (enable_jit_compiler, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {} enable_jit_compiler ()\n\ +Query or set the internal variable that enables Octave's JIT compiler.\n\ +@end deftypefn") +{ +#if defined (HAVE_LLVM) + return SET_INTERNAL_VARIABLE (enable_jit_compiler); +#else + warning ("enable_jit_compiler: JIT compiling not available in this version of Octave"); + return octave_value (); +#endif +} /* Test some simple cases that compile.
--- a/libinterp/interp-core/pt-jit.h +++ b/libinterp/interp-core/pt-jit.h @@ -378,4 +378,11 @@ }; #endif + +// If TRUE, enable JIT compiler debugging/tracing. +extern bool Venable_jit_debug; + +// If TRUE, enable JIT compiler. +extern bool Venable_jit_compiler; + #endif
--- a/libinterp/octave.cc +++ b/libinterp/octave.cc @@ -128,6 +128,14 @@ // (--no-gui) static bool no_gui_option = false; +// If TRUE, disable the JIT compiler. +// (--no-jit-compiler) +static bool no_jit_compiler_option = false; + +// If TRUE, enable JIT compiler debugging/tracing. +// (--jit-debug) +static bool jit_debug_option = false; + // If TRUE, force readline command line editing. // (--line-editing) static bool forced_line_editing = false; @@ -178,10 +186,11 @@ "octave [-HVdfhiqvx] [--debug] [--echo-commands] [--eval CODE]\n\ [--exec-path path] [--force-gui] [--help] [--image-path path]\n\ [--info-file file] [--info-program prog] [--interactive]\n\ - [--line-editing] [--no-gui] [--no-history] [--no-init-file]\n\ - [--no-init-path] [--no-line-editing] [--no-site-file]\n\ - [--no-window-system] [-p path] [--path path] [--silent]\n\ - [--traditional] [--verbose] [--version] [file]"; + [--jit-debug] [--line-editing] [--no-gui] [--no-history]\n\ + [--no-init-file] [--no-init-path] [--no-jit-compiler]\n\ + [--no-line-editing] [--no-site-file] [--no-window-system]\n\ + [-p path] [--path path] [--silent] [--traditional]\n\ + [--verbose] [--version] [file]"; // This is here so that it's more likely that the usage message and // the real set of options will agree. Note: the `+' must come first @@ -203,16 +212,18 @@ #define IMAGE_PATH_OPTION 5 #define INFO_FILE_OPTION 6 #define INFO_PROG_OPTION 7 -#define LINE_EDITING_OPTION 8 -#define NO_GUI_OPTION 9 -#define NO_INIT_FILE_OPTION 10 -#define NO_INIT_PATH_OPTION 11 -#define NO_LINE_EDITING_OPTION 12 -#define NO_SITE_FILE_OPTION 13 -#define NO_WINDOW_SYSTEM_OPTION 14 -#define PERSIST_OPTION 15 -#define TEXI_MACROS_FILE_OPTION 16 -#define TRADITIONAL_OPTION 17 +#define JIT_DEBUG_OPTION 8 +#define LINE_EDITING_OPTION 9 +#define NO_GUI_OPTION 10 +#define NO_INIT_FILE_OPTION 11 +#define NO_INIT_PATH_OPTION 12 +#define NO_JIT_COMPILER_OPTION 13 +#define NO_LINE_EDITING_OPTION 14 +#define NO_SITE_FILE_OPTION 15 +#define NO_WINDOW_SYSTEM_OPTION 16 +#define PERSIST_OPTION 17 +#define TEXI_MACROS_FILE_OPTION 18 +#define TRADITIONAL_OPTION 19 struct option long_opts[] = { { "braindead", no_argument, 0, TRADITIONAL_OPTION }, @@ -227,11 +238,13 @@ { "info-file", required_argument, 0, INFO_FILE_OPTION }, { "info-program", required_argument, 0, INFO_PROG_OPTION }, { "interactive", no_argument, 0, 'i' }, + { "jit-debug", no_argument, 0, JIT_DEBUG_OPTION }, { "line-editing", no_argument, 0, LINE_EDITING_OPTION }, { "no-gui", no_argument, 0, NO_GUI_OPTION }, { "no-history", no_argument, 0, 'H' }, { "no-init-file", no_argument, 0, NO_INIT_FILE_OPTION }, { "no-init-path", no_argument, 0, NO_INIT_PATH_OPTION }, + { "no-jit", no_argument, 0, NO_JIT_COMPILER_OPTION }, { "no-line-editing", no_argument, 0, NO_LINE_EDITING_OPTION }, { "no-site-file", no_argument, 0, NO_SITE_FILE_OPTION }, { "no-window-system", no_argument, 0, NO_WINDOW_SYSTEM_OPTION }, @@ -575,11 +588,13 @@ --info-file FILE Use top-level info file FILE.\n\ --info-program PROGRAM Use PROGRAM for reading info files.\n\ --interactive, -i Force interactive behavior.\n\ + --jit-debug Enable JIT compiler debugging/tracing.\n\ --line-editing Force readline use for command-line editing.\n\ --no-gui Disable the graphical user interface.\n\ --no-history, -H Don't save commands to the history list\n\ --no-init-file Don't read the ~/.octaverc or .octaverc files.\n\ --no-init-path Don't initialize function search path.\n\ + --no-jit-compiler Disable the JIT compiler.\n\ --no-line-editing Don't use readline for command-line editing.\n\ --no-site-file Don't read the site-wide octaverc file.\n\ --no-window-system Disable window system, including graphics.\n\ @@ -801,20 +816,28 @@ info_program = optarg; break; + case JIT_DEBUG_OPTION: + jit_debug_option = true; + break; + case LINE_EDITING_OPTION: forced_line_editing = true; break; + case NO_GUI_OPTION: + no_gui_option = true; + break; + case NO_INIT_FILE_OPTION: read_init_files = false; break; - case NO_GUI_OPTION: - no_gui_option = true; + case NO_INIT_PATH_OPTION: + set_initial_path = false; break; - case NO_INIT_PATH_OPTION: - set_initial_path = false; + case NO_JIT_COMPILER_OPTION: + no_jit_compiler_option = true; break; case NO_LINE_EDITING_OPTION: @@ -944,6 +967,12 @@ if (! texi_macros_file.empty ()) bind_internal_variable ("texi_macros_file", texi_macros_file); + if (jit_debug_option) + bind_internal_variable ("enable_jit_debugging", true); + + if (no_jit_compiler_option) + bind_internal_variable ("enable_jit_compiler", false); + // Make sure we clean up when we exit. Also allow users to register // functions. If we don't have atexit or on_exit, we're going to // leave some junk files around if we exit abnormally.
--- a/libinterp/parse-tree/pt-eval.cc +++ b/libinterp/parse-tree/pt-eval.cc @@ -44,9 +44,10 @@ #include "symtab.h" #include "unwind-prot.h" -#if HAVE_LLVM //FIXME: This should be part of tree_evaluator #include "pt-jit.h" + +#if HAVE_LLVM static tree_jit jiter; #endif @@ -310,7 +311,7 @@ octave_value rhs = expr->rvalue1 (); #if HAVE_LLVM - if (jiter.execute (cmd, rhs)) + if (Venable_jit_compiler && jiter.execute (cmd, rhs)) return; #endif @@ -1047,7 +1048,7 @@ return; #if HAVE_LLVM - if (jiter.execute (cmd)) + if (Venable_jit_compiler && jiter.execute (cmd)) return; #endif