public inbox for jit@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: First bytecode compiled in Ravi/Lua
  2015-01-01  0:00 First bytecode compiled in Ravi/Lua Dibyendu Majumdar
@ 2015-01-01  0:00 ` David Malcolm
  0 siblings, 0 replies; 4+ messages in thread
From: David Malcolm @ 2015-01-01  0:00 UTC (permalink / raw)
  To: Dibyendu Majumdar; +Cc: jit

On Sun, 2015-06-14 at 23:38 +0100, Dibyendu Majumdar wrote:
> I am pleased to report that I can JIT compile the following minimal
> Lua function:
> 
> x=function() return; end

Excellent!

> I faced following problems that I had to work around:
> 
> 1. libgccjit fails when there are unreachable blocks - I had to patch
> libgccjit to disable this validation. As explained in my previous post
> this is a show stopper issue.

(noted; we'll keep that discussion in the other thread)

> 2. I had to make the compiled function exported - I didn't think this
> should be necessary given that the function is JIT compiled, but I
> suspect it is the result of the JITed function being part of a
> temporary shared library?

Yes, it has to be GCC_JIT_FUNCTION_EXPORTED to be accessible via
gcc_jit_result_get_code(), and this is indeed because internally we're
going through a shared library:
https://gcc.gnu.org/onlinedocs/jit/topics/functions.html#gcc_jit_function_kind


> ------------
> 
> The compiled output looks like this:
> 
> extern int
> ravif1 (struct ravi_lua_State * L)
> {
>   struct ravi_TValue * base;
>   struct ravi_LClosure * cl;
> 
> entry:
>   cl = (struct ravi_LClosure *)L->ci->func->value_.gc;
>   base = L->ci->u.l.base;
>   base = L->ci->u.l.base;
>   L->top = &base[(int)0];
>   if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x10109f0>; else goto
> <UNNAMED BLOCK 0x100bee0>;
> 
> <UNNAMED BLOCK 0x10109f0>:
>   (void)luaF_close (L, base);
>   goto <UNNAMED BLOCK 0x100bee0>;
> 
> <UNNAMED BLOCK 0x100bee0>:
>   (void)luaD_poscall (L, &base[(int)0]);
>   return (int)1;
> 
> <UNNAMED BLOCK 0x100bb20>:
>   base = L->ci->u.l.base;
>   L->top = &base[(int)0];
>   if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x100edc0>; else goto
> <UNNAMED BLOCK 0x100ef20>;
> 
> <UNNAMED BLOCK 0x100edc0>:
>   (void)luaF_close (L, base);
>   goto <UNNAMED BLOCK 0x100ef20>;
> 
> <UNNAMED BLOCK 0x100ef20>:
>   (void)luaD_poscall (L, &base[(int)0]);
>   return (int)1;
> }

Does it run? :)

Note that if you're running under gdb, you ought to be able to:

  (gdb) breakpoint ravif1

and gdb ought to notice when the shared library is loaded and set the
breakpoint on the generated code (one advantage of doing it as a shared
library internally); the notes on faking debuginfo here:
https://gcc.gnu.org/onlinedocs/jit/topics/locations.html#faking-it
may be pertinent; you'll also need:

gcc_jit_context_set_bool_option (
  ctxt,
  GCC_JIT_BOOL_OPTION_DEBUGINFO,
  1);

Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

* First bytecode compiled in Ravi/Lua
@ 2015-01-01  0:00 Dibyendu Majumdar
  2015-01-01  0:00 ` David Malcolm
  0 siblings, 1 reply; 4+ messages in thread
From: Dibyendu Majumdar @ 2015-01-01  0:00 UTC (permalink / raw)
  To: jit, David Malcolm

I am pleased to report that I can JIT compile the following minimal
Lua function:

x=function() return; end

I faced following problems that I had to work around:

1. libgccjit fails when there are unreachable blocks - I had to patch
libgccjit to disable this validation. As explained in my previous post
this is a show stopper issue.

2. I had to make the compiled function exported - I didn't think this
should be necessary given that the function is JIT compiled, but I
suspect it is the result of the JITed function being part of a
temporary shared library?

------------

The compiled output looks like this:

extern int
ravif1 (struct ravi_lua_State * L)
{
  struct ravi_TValue * base;
  struct ravi_LClosure * cl;

entry:
  cl = (struct ravi_LClosure *)L->ci->func->value_.gc;
  base = L->ci->u.l.base;
  base = L->ci->u.l.base;
  L->top = &base[(int)0];
  if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x10109f0>; else goto
<UNNAMED BLOCK 0x100bee0>;

<UNNAMED BLOCK 0x10109f0>:
  (void)luaF_close (L, base);
  goto <UNNAMED BLOCK 0x100bee0>;

<UNNAMED BLOCK 0x100bee0>:
  (void)luaD_poscall (L, &base[(int)0]);
  return (int)1;

<UNNAMED BLOCK 0x100bb20>:
  base = L->ci->u.l.base;
  L->top = &base[(int)0];
  if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x100edc0>; else goto
<UNNAMED BLOCK 0x100ef20>;

<UNNAMED BLOCK 0x100edc0>:
  (void)luaF_close (L, base);
  goto <UNNAMED BLOCK 0x100ef20>;

<UNNAMED BLOCK 0x100ef20>:
  (void)luaD_poscall (L, &base[(int)0]);
  return (int)1;
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: First bytecode compiled in Ravi/Lua
  2015-01-01  0:00 Dibyendu Majumdar
@ 2015-01-01  0:00 ` Dibyendu Majumdar
  0 siblings, 0 replies; 4+ messages in thread
From: Dibyendu Majumdar @ 2015-01-01  0:00 UTC (permalink / raw)
  To: David Malcolm; +Cc: jit

Now we can compile/run:

function x() return 1; end

That's two Lua op codes.

I won't post each op code but hopefully I can start running some of my
benchmarks soon (need to get for loop implemented).

Regards

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: First bytecode compiled in Ravi/Lua
@ 2015-01-01  0:00 Dibyendu Majumdar
  2015-01-01  0:00 ` Dibyendu Majumdar
  0 siblings, 1 reply; 4+ messages in thread
From: Dibyendu Majumdar @ 2015-01-01  0:00 UTC (permalink / raw)
  To: David Malcolm; +Cc: jit

Yes it runs! Took couple of hours of bug fixing (my code) to get from
compiles to runs. Will respond to other points later tonight.
From: David Malcolm
Sent: ‎15/‎06/‎2015 04:57
To: Dibyendu Majumdar
Cc: jit@gcc.gnu.org
Subject: Re: First bytecode compiled in Ravi/Lua
On Sun, 2015-06-14 at 23:38 +0100, Dibyendu Majumdar wrote:
> I am pleased to report that I can JIT compile the following minimal
> Lua function:
>
> x=function() return; end

Excellent!

> I faced following problems that I had to work around:
>
> 1. libgccjit fails when there are unreachable blocks - I had to patch
> libgccjit to disable this validation. As explained in my previous post
> this is a show stopper issue.

(noted; we'll keep that discussion in the other thread)

> 2. I had to make the compiled function exported - I didn't think this
> should be necessary given that the function is JIT compiled, but I
> suspect it is the result of the JITed function being part of a
> temporary shared library?

Yes, it has to be GCC_JIT_FUNCTION_EXPORTED to be accessible via
gcc_jit_result_get_code(), and this is indeed because internally we're
going through a shared library:
https://gcc.gnu.org/onlinedocs/jit/topics/functions.html#gcc_jit_function_kind


> ------------
>
> The compiled output looks like this:
>
> extern int
> ravif1 (struct ravi_lua_State * L)
> {
>   struct ravi_TValue * base;
>   struct ravi_LClosure * cl;
>
> entry:
>   cl = (struct ravi_LClosure *)L->ci->func->value_.gc;
>   base = L->ci->u.l.base;
>   base = L->ci->u.l.base;
>   L->top = &base[(int)0];
>   if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x10109f0>; else goto
> <UNNAMED BLOCK 0x100bee0>;
>
> <UNNAMED BLOCK 0x10109f0>:
>   (void)luaF_close (L, base);
>   goto <UNNAMED BLOCK 0x100bee0>;
>
> <UNNAMED BLOCK 0x100bee0>:
>   (void)luaD_poscall (L, &base[(int)0]);
>   return (int)1;
>
> <UNNAMED BLOCK 0x100bb20>:
>   base = L->ci->u.l.base;
>   L->top = &base[(int)0];
>   if (cl->p->sizep > (int)0) goto <UNNAMED BLOCK 0x100edc0>; else goto
> <UNNAMED BLOCK 0x100ef20>;
>
> <UNNAMED BLOCK 0x100edc0>:
>   (void)luaF_close (L, base);
>   goto <UNNAMED BLOCK 0x100ef20>;
>
> <UNNAMED BLOCK 0x100ef20>:
>   (void)luaD_poscall (L, &base[(int)0]);
>   return (int)1;
> }

Does it run? :)

Note that if you're running under gdb, you ought to be able to:

  (gdb) breakpoint ravif1

and gdb ought to notice when the shared library is loaded and set the
breakpoint on the generated code (one advantage of doing it as a shared
library internally); the notes on faking debuginfo here:
https://gcc.gnu.org/onlinedocs/jit/topics/locations.html#faking-it
may be pertinent; you'll also need:

gcc_jit_context_set_bool_option (
  ctxt,
  GCC_JIT_BOOL_OPTION_DEBUGINFO,
  1);

Dave

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-06-15 22:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-01-01  0:00 First bytecode compiled in Ravi/Lua Dibyendu Majumdar
2015-01-01  0:00 ` David Malcolm
  -- strict thread matches above, loose matches on Subject: below --
2015-01-01  0:00 Dibyendu Majumdar
2015-01-01  0:00 ` Dibyendu Majumdar

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).