What have you found for these years?


LLVM & Rubinius (2)

Hi godfat,

From the english translation, it looks like you didn't have much luck getting my examples running. I'd love to help, I still have the code I used from the original experiment around somewhere.

Please contact me and we'll try again!

Greetings Evan,

I am very, very surprised that you have left this message for me.
Although I was talking about your examples and LLVM and Rubinius,
most of contents were written in Chinese. I didn't expect there
would be any reader who's first language wasn't Chinese.

So, I am very surprised and glad to see your message.
If you were interested in some content of that blog post,
I could translate some of them to English for you,
if you don't mind my poor, strange English sentence.


Let's get back to your examples. At first, I couldn't find a way to
compile the examples. After searching header files and llvm-config,
the examples ran fine. I was glad to reach here.

But I thought it's a bit strange that your "create" function which
creates JIT module, was skipping "function label", lacking a switch
case to find out which function it should call this time.

By talking about "function label", I mean the 0, 1, 2 in our source
program. 0 stands for set, 1 stands for add, and 2 stands for show.

Then I started to add the switch case in your create function,
thinking it should let me rewrite our source program to such as:

int program[] = {
0, 0, 5, // res[0] = 5
2, 0, // puts res[0]
1, 0, 0, 4, // res[0] = res[0] + 4
2, 0, // puts res[0]
1, 1, 0, 7, // res[1] = res[0] + 7
2, 1 // puts res[1]

Problems occurred here.
Segmentation fault, or strange result, e.g. -2153546.

blah blah blah... time passed.

I started to think perhaps there would be a bug in your examples.
The body bytecode (or bitcode?) emitted by llvm, i.e.,

define void @body(i32* %ops, i32* %registers) {
call void @set( i32* %ops, i32* %registers )
%tmp3 = getelementptr i32* %ops, i32 3 ; [#uses=1]
call void @add( i32* %tmp3, i32* %registers )
%tmp31 = getelementptr i32* %ops, i32 4 ; [#uses=1]
call void @show( i32* %tmp31, i32* %registers )
ret void

I thought it's very strange that the second getelementptr told
%ops to step 4, just like "ops + 4" in C. Then it passed %tmp31,
i.e. "ops + 4" to show. Shouldn't it be "ops + 3 + 4" ?

Then I took out the line:

GetElementPtrInst* ptr2 = GetElementPtrInst::Create(ops, const_4, "tmp3", bb);

and changed it to:

GetElementPtrInst* ptr2 = GetElementPtrInst::Create(ptr1, const_4, "tmp3", bb);

save, compile, and it runs fine. Of course it's not the exactly
modification I made, because I built a loop and a switch case to
create many CallInst(s). The exactly lines were:

const_n = ConstantInt::get(APInt(32, lexical_cast<std::string>(step), 10));
ptr = GetElementPtrInst::Create(params.back(), const_n, "tmp", bb);

You can find the source code at the bottom of previous post.
[LLVM & Rubinius]

Many thanks for your listening and kindness!

Lin Jen-Shin (a.k.a. godfat 真常)

4 retries:

chen kai said...


godfat 真常 said...

沒有哩,不知道他心裡是怎麼想 XD

Plumm said...


Lin Jen-Shin (aka godfat 真常) said...


Post a Comment

All texts are licensed under CC Attribution 3.0