[LLVMdev] Eliminating redundant loads

Dibyendu Majumdar mobile at majumdar.org.uk
Sun Feb 22 23:02:43 PST 2015


On 23 February 2015 at 01:29, Kamal Sharma <kgs1.rice at gmail.com> wrote:
> Hi  Dibyendu,
>
> It would be very helpful if you could post the original source code or
> snippet.
> That way, one can investigate deeper to understand the problem.
>
> Regards,
> Kamal Sharma
>

Hi Kamal,

Sure. I guess I ought to create a test that one can look in isolation.

I am working on building a JIT compiler for Lua (actually a derivative
of Lua). It is currently work in progress.
The approach is to compile Lua bytecodes into LLVM IR.

The IR generated from my code is here (after optimization I should add):
https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return_ravi.ll

I am using the output from Clang as a guide to generating IR. So I
write small snippets of code in C which are equivalent to Lua
bytecodes - then use Clang to emit the IR. I use this to work out the
IR I need to build.

The C equivalent of the program I am compiling is here:
https://github.com/dibyendumajumdar/ravi/blob/master/clang-output/lua_op_loadk_return.c

The difference between the C version and what I generate is that I put
a load of the "base" pointer at the beginning of every Lua opcode.
This is because some Lua opcodes can reallocate the memory pointed to
by base. I was hoping that the optimizer will get rid of the redundant
stuff.

The code generation is all done here:

https://github.com/dibyendumajumdar/ravi/blob/master/src/ravijit.cpp

I don't expect you to wade through all this - but I will be grateful
for any help / guidance you can provide.

Thanks and Regards
Dibyendu



More information about the llvm-dev mailing list