[llvm-dev] Strange error after doing transformation on IR level

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[llvm-dev] Strange error after doing transformation on IR level

Sam McCall via llvm-dev
Hello,

I met a very strange error after transforming IR code.

What I did is that I create a function and insert it into the original program's IR code.

I use following command to load my pass and generate the transformed bytecode (the "result").
opt -load ~/mypass/libLLVMMYPASS.so -insert < mytestcode.ll > result

Then, I try to compile it to assembly code via llc
llc result

After that, the error occurs:
llc: result:1:1: error: expected top-level entity

It seems like the error is about the IR code.
Thus, I dump the module during my pass, it turns out that there is only one line different:
1. when I just open the IR code - mytestcode.ll, the first line is:
; ModuleID = './mytestcode.c'

2. when I dump it during my pass, the first line is:
; ModuleID = '<stdin>'

The strange thing is, after transformation by my pass, I also dump the transformed module, and copy all the dumped content to a file, and then, perform "llc" on it. Surprisingly, I found It works well. I also compile it to an executable and run it. The result is correct for my transformation.

Thus, I'm so confused about:
1. what the different between "; ModuleID = './mytestcode.c'" and "; ModuleID = '<stdin>'". Will it impact the "llc" and trigger the error?

2. when I read the module during my pass, why the ModuleID has been changed from './mytestcode.c' to '<stdin>'

3. why does the error "llc: result:1:1: error: expected top-level entity" happen, and why does the IR code dumped during my pass work well?

Thanks in advance!

Best,
Yin

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev
Reply | Threaded
Open this post in threaded view
|

Re: [llvm-dev] Strange error after doing transformation on IR level

Sam McCall via llvm-dev
The reason the module name is <stdin> is because you used input redirection via "< mytestcode.ll" on your command line. This means the shell opened the file and sent it through stdin. Opt never saw your file name. I'm not sure, but the output redirection "> result" may also be keep llc from reading the file. Try this to read and write your file

opt -load ~/mypass/libLLVMMYPASS.so -insert mytestcode.ll -o result.bc
llc result.bc

~Craig


On Tue, Jun 12, 2018 at 2:24 PM Yin Liu via llvm-dev <[hidden email]> wrote:
Hello,

I met a very strange error after transforming IR code.

What I did is that I create a function and insert it into the original program's IR code.

I use following command to load my pass and generate the transformed bytecode (the "result").
opt -load ~/mypass/libLLVMMYPASS.so -insert < mytestcode.ll > result

Then, I try to compile it to assembly code via llc
llc result

After that, the error occurs:
llc: result:1:1: error: expected top-level entity

It seems like the error is about the IR code.
Thus, I dump the module during my pass, it turns out that there is only one line different:
1. when I just open the IR code - mytestcode.ll, the first line is:
; ModuleID = './mytestcode.c'

2. when I dump it during my pass, the first line is:
; ModuleID = '<stdin>'

The strange thing is, after transformation by my pass, I also dump the transformed module, and copy all the dumped content to a file, and then, perform "llc" on it. Surprisingly, I found It works well. I also compile it to an executable and run it. The result is correct for my transformation.

Thus, I'm so confused about:
1. what the different between "; ModuleID = './mytestcode.c'" and "; ModuleID = '<stdin>'". Will it impact the "llc" and trigger the error?

2. when I read the module during my pass, why the ModuleID has been changed from './mytestcode.c' to '<stdin>'

3. why does the error "llc: result:1:1: error: expected top-level entity" happen, and why does the IR code dumped during my pass work well?

Thanks in advance!

Best,
Yin
_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev

_______________________________________________
LLVM Developers mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev