# HG changeset patch # User Stefan Mahr # Date 1383561010 -3600 # Node ID efa4572997baf0f490d9d9ce4859d1bf1da6d57c # Parent 21e14380c3ad2cf98cfef8cafe52775fe0f11027 jit compiler: Add counter of jit_fail_exceptions to check if jit compilation fails * libinterp/corefcn/pt-jit.cc (Djit_failure_count): New function * test/jit.tst: Add checks for jit_failure_count diff -r 21e14380c3ad -r efa4572997ba libinterp/corefcn/pt-jit.cc --- a/libinterp/corefcn/pt-jit.cc Fri Nov 01 13:47:33 2013 +0100 +++ b/libinterp/corefcn/pt-jit.cc Mon Nov 04 11:30:10 2013 +0100 @@ -46,6 +46,8 @@ static int Vjit_startcnt = 1000; +static int Vjit_failure_count = 0; + #include #include #include @@ -2129,6 +2131,8 @@ std::cout << "jit fail: " << e.what () << std::endl; } + Vjit_failure_count++; + wrapper.erase (); raw_fn.erase (); } @@ -2285,6 +2289,9 @@ if (e.known ()) std::cout << "jit fail: " << e.what () << std::endl; } + + Vjit_failure_count++; + } if (llvm_function) @@ -2320,6 +2327,29 @@ #endif + +DEFUN (jit_failure_count, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} {@var{val} =} jit_failure_count ()\n\ +@deftypefnx {Built-in Function} {@var{old_val} =} jit_failure_count (@var{new_val})\n\ +@deftypefnx {Built-in Function} {} jit_failure_count (@var{new_val}, \"local\")\n\ +Query or set the internal variable that counts the number of\n\ +JIT fail exceptions for Octave's JIT compiler.\n\ +\n\ +When called from inside a function with the @qcode{\"local\"} option, the\n\ +variable is changed locally for the function and any subroutines it calls. \n\ +The original variable value is restored when exiting the function.\n\ +@seealso{jit_enable, jit_startcnt, debug_jit}\n\ +@end deftypefn") +{ +#if defined (HAVE_LLVM) + return SET_INTERNAL_VARIABLE (jit_failure_count); +#else + warning ("jit_failure_count: JIT compiling not available in this version of Octave"); + return octave_value (); +#endif +} + DEFUN (debug_jit, args, nargout, "-*- texinfo -*-\n\ @deftypefn {Built-in Function} {@var{val} =} debug_jit ()\n\ diff -r 21e14380c3ad -r efa4572997ba test/jit.tst --- a/test/jit.tst Fri Nov 01 13:47:33 2013 +0100 +++ b/test/jit.tst Mon Nov 04 11:30:10 2013 +0100 @@ -28,6 +28,7 @@ ## Test some simple cases that compile. %!testif HAVE_LLVM +%! jit_failure_count (0) %! for i=1:1e6 %! if (i < 5) %! break; @@ -36,8 +37,10 @@ %! endif %! endfor %! assert (i, 1); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! while (1) %! if (1) %! break; @@ -45,33 +48,41 @@ %! break; %! endif %! endwhile +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! for i=1:1e6 %! if (i == 100) %! break; %! endif %! endfor %! assert (i, 100); +%! assert (jit_failure_count, 0); ## Also test parfor keyword %!testif HAVE_LLVM +%! jit_failure_count (0) %! parfor i=1:1e6 %! if (i == 100) %! break; %! endif %! endparfor %! assert (i, 100); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! inc = 1e-5; %! result = 0; %! for ii = 0:inc:1 %! result = result + inc * (1/3 * ii * ii); %! endfor %! assert (abs (result - 1/9) < 1e-5); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! inc = 1e-5; %! result = 0; %! for ii = 0:inc:1 @@ -79,8 +90,10 @@ %! result = result + inc * (1/3 * ii ^ 2); %! endfor %! assert (abs (result - 1/9) < 1e-5); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! temp = 1+1i; %! nan = NaN; %! while (1) @@ -89,8 +102,10 @@ %! break; %! endwhile %! assert (imag (temp), 0); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! temp = 1+1i; %! nan = NaN+1i; %! while (1) @@ -100,24 +115,30 @@ %! break; %! endwhile %! assert (imag (temp), 0); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! temp = 1+1i; %! while (1) %! temp = temp * 5; %! break; %! endwhile %! assert (temp, 5+5i); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! nr = 1001; %! mat = zeros (1, nr); %! for i = 1:nr %! mat(i) = i; %! endfor %! assert (mat == 1:nr); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! nr = 1001; %! mat = 1:nr; %! mat(end) = 0; # force mat to a matrix @@ -126,8 +147,10 @@ %! total = mat(i) + total; %! endfor %! assert (sum (mat) == total); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! nr = 1001; %! mat = [3 1 5]; %! try @@ -141,6 +164,7 @@ %! catch %! end_try_catch %! assert (result == 500); +%! assert (jit_failure_count, 0); %!function result = gen_test (n) %! result = double (rand (1, n) > .01); @@ -176,18 +200,23 @@ %!endfunction %!testif HAVE_LLVM +%! jit_failure_count (0) %! test_set = gen_test (10000); %! assert (all (vectorized (test_set, 3) == loopy (test_set, 3))); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! niter = 1001; %! i = 0; %! while (i < niter) %! i = i + 1; %! endwhile %! assert (i == niter); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! niter = 1001; %! result = 0; %! m = [5 10]; @@ -195,8 +224,10 @@ %! result = result + m(end); %! endfor %! assert (result == m(end) * niter); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! ndim = 100; %! result = 0; %! m = zeros (ndim); @@ -209,8 +240,10 @@ %! i = i + 1; %! endwhile %! assert (result == sum (sum (m))); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! ndim = 100; %! m = zeros (ndim); %! i = 1; @@ -223,8 +256,10 @@ %! m2 = zeros (ndim); %! m2(:) = 1:(ndim^2); %! assert (all (m == m2)); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! ndim = 2; %! m = zeros (ndim, ndim, ndim, ndim); %! result = 0; @@ -244,6 +279,7 @@ %! expected = ones (ndim, ndim, ndim, ndim); %! assert (all (m == expected)); %! assert (result == sum (expected (:))); +%! assert (jit_failure_count, 0); %!function test_divide () %! state = warning ("query", "Octave:divide-by-zero").state; @@ -259,21 +295,26 @@ %!endfunction %!testif HAVE_LLVM +%! jit_failure_count (0) %! lasterr (""); %! try %! test_divide (); %! end_try_catch %! assert (strcmp (lasterr (), "division by zero")); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! while (1) %! a = 0; %! result = a / 1; %! break; %! endwhile %! assert (result, 0); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! m = zeros (2, 1001); %! for i=1:1001 %! m(end, i) = i; @@ -283,38 +324,49 @@ %! m2(1, :) = fliplr (1:1001); %! m2(2, :) = 1:1001; %! assert (m, m2); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! m = [1 2 3]; %! for i=1:1001 %! m = sin (m); %! break; %! endfor %! assert (m == sin ([1 2 3])); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! i = 0; %! while i < 10 %! i += 1; %! endwhile %! assert (i == 10); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! i = 0; %! while i < 10 %! a = ++i; %! endwhile %! assert (i == 10); %! assert (a == 10); +%! jit_failure_count (0) + %!testif HAVE_LLVM +%! jit_failure_count (0) %! i = 0; %! while i < 10 %! a = i++; %! endwhile %! assert (i == 10); %! assert (a == 9); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! num = 2; %! a = zeros (1, num); %! i = 1; @@ -323,6 +375,7 @@ %! ++i; %! endwhile %! assert (a, ones (1, num)); +%! assert (jit_failure_count, 0); %!function test_compute_idom () %! while (li <= length (l1) && si <= length (s1)) @@ -337,11 +390,13 @@ %! endwhile %!testif HAVE_LLVM +%! jit_failure_count (0) %! lasterr (""); %! try %! test_compute_idom (); %! end_try_catch %! assert (! isempty (lasterr ())); +%! assert (jit_failure_count, 0); %!function x = test_overload (a) %! while (1) @@ -351,8 +406,10 @@ %!endfunction %!testif HAVE_LLVM +%! jit_failure_count (0) %! assert (test_overload (1), 1); %! assert (test_overload ([1 2]), [1 2]); +%! assert (jit_failure_count, 0); %!function a = bubble (a = [3 2 1]) %! swapped = 1; @@ -371,9 +428,12 @@ %!endfunction %!testif HAVE_LLVM +%! jit_failure_count (0) %! assert (bubble (), [1 2 3]); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! a = 0; %! b = 1; %! for i=1:1e3 @@ -383,8 +443,10 @@ %! endfor %! assert (a, 2000); %! assert (b, 1); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! a = [1+1i 1+2i]; %! b = 0; %! while (1) @@ -392,6 +454,7 @@ %! break; %! endwhile %! assert (b, a(1)); +%! assert (jit_failure_count, 0); %!function test_undef () %! for i=1:1e7 @@ -400,26 +463,32 @@ %!endfunction %!testif HAVE_LLVM +%! jit_failure_count (0) %! lasterr (""); %! try %! test_undef (); %! end_try_catch %! assert (strncmp (lasterr (), "'XXX' undefined near", 20)); +%! assert (jit_failure_count, 0); %!shared id %! id = @(x) x; %!testif HAVE_LLVM +%! jit_failure_count (0) %! assert (id (1), 1); %! assert (id (1+1i), 1+1i); %! assert (id (1, 2), 1); +%! assert (jit_failure_count, 0); %!testif HAVE_LLVM +%! jit_failure_count (0) %! lasterr (""); %! try %! id (); %! end_try_catch %! assert (strncmp (lasterr (), "'x' undefined near", 18)); +%! assert (jit_failure_count, 0); ## Restore JIT settings %!testif HAVE_LLVM