diff libinterp/interp-core/pt-jit.cc @ 15603:44272909d926

Stop JIT on interrupt * jit-ir.cc (jit_call::needs_release): Move to cc file and do not release artificial assigns. (jit_error_check::variable_to_strign): New function. (jit_error_check::print): Move to cc file and improve output. * jit-ir.h (jit_call::needs_release): Move to cc file. (jit_error_check::variable): New enum. (jit_error_check::variable_to_string): New declaration. (jit_error_check::jit_error_check): Add variable argument and new overload. (jit_error_check::check_variable, jit_error_check::has_check_for): New function. (jit_error_check::check_for): Ensure has_check_for is true. (jit_error_check::print): Move to cc file. (jit_error_check::check_alive): Always true if has_check_for is false. (jit_error_check::mvariable): New variable. * jit-typeinfo.cc (jit_typeinfo::jit_typeinfo): Initialize loctave_interrupt_state and fix name of cast to any. (jit_typeinfo::do_insert_interrupt_check): New function. * jit-typeinfo.h (jit_typeinfo::insert_interrupt_check): New function. (jit_typeinfo::do_insert_interrupt_check): New declaration. (jit_typeinfo::loctave_interrupt_state): New variable. * pt-jit.cc (jit_convert::visit_simple_for_command, jit_convert::visit_while_command): Check interrupt state. (jit_convert::create_check_impl): Specify var_error_state check. (jit_convert_llvm::visit): Generate var_interrupt error check. (jit_function_info::execute, jit_info::execute): Call octave_quit.
author Max Brister <max@2bass.com>
date Sun, 04 Nov 2012 21:11:33 -0700
parents f3e339aee38f
children 896cf5769537 1f076c40c133
line wrap: on
line diff
--- a/libinterp/interp-core/pt-jit.cc
+++ b/libinterp/interp-core/pt-jit.cc
@@ -403,6 +403,9 @@
   jit_block *check_block = factory.create<jit_block> ("for_check");
   blocks.push_back (check_block);
 
+  jit_block *interrupt_check = factory.create<jit_block> ("for_interrupt");
+  blocks.push_back (interrupt_check);
+
   if (! all_breaking)
     block->append (factory.create<jit_branch> (check_block));
   finish_breaks (check_block, continues);
@@ -415,7 +418,14 @@
   block->append (factory.create<jit_assign> (iterator, iter_inc));
   check = block->append (factory.create<jit_call> (jit_typeinfo::for_check,
                                                    control, iterator));
-  block->append (factory.create<jit_cond_branch> (check, body, tail));
+  block->append (factory.create<jit_cond_branch> (check, interrupt_check,
+                                                  tail));
+
+  block = interrupt_check;
+  jit_error_check *ec
+    = factory.create<jit_error_check> (jit_error_check::var_interrupt,
+                                       body, final_block);
+  block->append (ec);
 
   // breaks will go to our tail
   blocks.push_back (tail);
@@ -834,10 +844,22 @@
     }
 
   finish_breaks (tail, breaks);
-  finish_breaks (cond_check, continues);
-
-  if (! all_breaking)
-    block->append (factory.create<jit_branch> (cond_check));
+
+  if (! all_breaking || continues.size ())
+    {
+      jit_block *interrupt_check
+        = factory.create<jit_block> ("interrupt_check");
+      blocks.push_back (interrupt_check);
+      finish_breaks (interrupt_check, continues);
+      if (! all_breaking)
+        block->append (factory.create<jit_branch> (interrupt_check));
+
+      block = interrupt_check;
+      jit_error_check *ec
+        = factory.create<jit_error_check> (jit_error_check::var_interrupt,
+                                           cond_check, final_block);
+      block->append (ec);
+    }
 
   blocks.push_back (tail);
   block = tail;
@@ -871,8 +893,9 @@
   block->append (ret);
 
   jit_block *normal = factory.create<jit_block> (block->name ());
-  jit_error_check *check = factory.create<jit_error_check> (ret, normal,
-                                                            final_block);
+  jit_error_check *check
+    = factory.create<jit_error_check> (jit_error_check::var_error_state, ret,
+                                       normal, final_block);
   block->append (check);
   blocks.push_back (normal);
   block = normal;
@@ -1365,7 +1388,20 @@
 void
 jit_convert_llvm::visit (jit_error_check& check)
 {
-  llvm::Value *cond = jit_typeinfo::insert_error_check (builder);
+  llvm::Value *cond;
+
+  switch (check.check_variable ())
+    {
+    case jit_error_check::var_error_state:
+      cond = jit_typeinfo::insert_error_check (builder);
+      break;
+    case jit_error_check::var_interrupt:
+      cond = jit_typeinfo::insert_interrupt_check (builder);
+      break;
+    default:
+      panic_impossible ();
+    }
+
   llvm::Value *br = builder.CreateCondBr (cond, check.successor_llvm (0),
                                           check.successor_llvm (1));
   check.stash_llvm (br);
@@ -2080,6 +2116,8 @@
   if (ret)
     retval(0) = octave_value (ret);
 
+  octave_quit ();
+
   return true;
 }
 
@@ -2148,6 +2186,8 @@
         symbol_table::varref (arguments[i].first) = real_arguments[i];
     }
 
+  octave_quit ();
+
   return true;
 }