open64-compiler / open64

open64 compiler
78 stars 29 forks source link

open64-w2ll/osprey/ir_tools/irbuild.cxx:16:10: fatal error: mir_parser.h: No such file or directory #22

Closed qingw1230 closed 1 year ago

qingw1230 commented 1 year ago

When I use environment variable like below:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HOME=`pwd`
export CLANG_HOME=$HOME/opt/x86_64
export LLVM_HOME=$CLANG_HOME
export PATH=$CLANG_HOME/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/lib/gcc-lib/x84_64-open64-linux/5.0:$PATH

Configure「open64-w2ll/configure」has the following tips:

checking MAPLE_HOME is set ...no
==========================================================
please set MAPLE_HOME which include the maple prebuilt libs
**** js2mpl and mpl2whirl won't be built ****
==========================================================
checking MOZJS_HOME is set ...no
==========================================================
please set MOZJS_HOME which include the mozjs prebuilt libs
**** js2mpl won't be built ****
==========================================================

make no error, make install prompts missing libraries:

osprey/targdir_lib/libacml_mv/libacml_mv.a does not exist
osprey/targdir_lib/libacml_mv/libacml_mv.so.1 does not exist
osprey/targdir_lib2/libmv/libmv.a does not exist
osprey/targdir_lib2/libmv/libmv.so.1 does not exist
osprey/targdir_lib2/libopenmp/libopenmp.a does not exist
osprey/targdir_lib2/libopenmp/libopenmp.so.1 does not exist
osprey/targdir_lib2/libacml_mv/libacml_mv.a does not exist
osprey/targdir_lib2/libacml_mv/libacml_mv.so.1 does not exist

I can't use functions like fastsin, fastcos etc when using opencc。

 undefined reference to `fastsin'
 undefined reference to `fastcos'

When I use environment variable like below:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export HOME=`pwd`
export MOZJS_HOME=/usr/lib
export MAPLE_HOME=$HOME/opt/maple2023/lib
export CLANG_HOME=$HOME/opt/x86_64
export LLVM_HOME=$CLANG_HOME
export PATH=$CLANG_HOME/bin:$PATH
export PATH=$HOME/local/bin:$PATH
export PATH=$HOME/local/lib/gcc-lib/x84_64-open64-linux/5.0:$PATH

It is normal when configuring 「open64-w2ll/configure」, but the following error is reported when executing make:

make[3]: leave directory“/mnt/sdbdata/qgw/open64/build/osprey-gcc-4.2.0”
make[2]: leave directory“/mnt/sdbdata/qgw/open64/build/osprey-gcc-4.2.0”
make[1]: leave directory“/mnt/sdbdata/qgw/open64/build”
make: *** [Makefile:406:build] error 2

Use make -j1 to get the following information:

C++    /mnt/sdbdata/qgw/open64/build/osprey/targdir/ir_tools/../../../../open64-w2ll/osprey/ir_tools/irbuild.cxx
../../../../open64-w2ll/osprey/ir_tools/irbuild.cxx:16:10: fatal error: mir_parser.h: No such file or directory
   16 | #include "mir_parser.h"
      |          ^~~~~~~~~~~~~~
compilation terminated.
make[3]: *** [/mnt/sdbdata/qgw/open64/build/../open64-w2ll/osprey/linux/make/gcommonrules:149:irbuild.o] error 1
make[3]: leave directory“/mnt/sdbdata/qgw/open64/build/osprey/targdir/ir_tools”
make[2]: *** [../../../../open64-w2ll/osprey/ir_tools/Makefile.gbase:232:default] error 2
make[2]: leave directory“/mnt/sdbdata/qgw/open64/build/osprey/targdir/ir_tools”
make[1]: *** [Makefile:360:ir_b2a] error 2
make[1]: leave directory“/mnt/sdbdata/qgw/open64/build”
make: *** [Makefile:406:build] error 2

I did not find the file 「mir_parser.h」. How can I get this file and build the open64 project correctly?

shinmingliu commented 1 year ago

Please do not set the environment variable "MAPLE_HOME". The build error will not happen since irbuild.o will not be the make target without this environment variable. This part of the build is to create maple to whirl or whirl to maple for connecting open64 with maple compiler, aka, ark compiler. We shall talk if you really want to do this.

Those configure errors are harmless and can be ignored.

qingw1230 commented 1 year ago

I don't need MAPLE. However, I want to print WHIRL IR. According to the instructions in osprey/ir_tools/README.md, I need to use the following command to generate .B/.I/.O files before printing WHIRL IR.

openCC -clang -emit-llvm -fno-exceptions -O3 -OPT:malloc_alg=off -PHASE:c=off -c -sw -kp hello.c

Then, use the following command to convert it to ASCII format:

ir_b2a a.O

However, when I was using the command openCC -clang -emit-llvm -fno-exceptions -O3 -OPT:malloc_alg=off -PHASE:c=off -c -sw -kp hello.c, I encountered the problem 'stddef.h' file not found when run openCC, and the link to this issue is:open64/issues/16

Furthermore, after using the -I option to specify the header file path, I encountered the error use of undeclared identifier 'printf', which is the same as the issue mentioned above. I would like to know how to correctly print WHIRL IR.

I also want to use math library functions such as sin and cos, but opencc replaces them with fastsin. I found its declaration in the file below:

./osprey/libacml_mv/inc/acml_mv.h:double fastsin(double);
./osprey/libacml_mv/inc/acml_mv.h:void fastsincos(double , double *, double *);
./osprey/libacml_mv/inc/acml_mv.h:float fastsinf(float );

However, I encountered the following error during make install:

osprey/targdir_lib2/libacml_mv/libacml_mv.a does not exist
osprey/targdir_lib2/libacml_mv/libacml_mv.so.1 does not exist

Therefore, I get linking errors when using sin and cos.

/usr/bin/ld: /tmp/cco.Y35h6C: in function `main':
/test/TSVC/test_opencc/test.c:8: undefined reference to `fastsin' 
collect2: ld returned 1 exit status

I found an environment for open64 on DockerHub.

docker pull opencc/open64:llvm15.w2ll

However, it did not solve the two issues mentioned above.

Yvan-xy commented 1 year ago

The files stddef.h and stdarg.h are no longer in /usr/include/ in the late Ubuntu like 22.04. Mine are located in /usr/lib/gcc/x86_64-linux-gnu/11/include/

So I would add the option -I/usr/lib/gcc/x86_64-linux-gnu/11/include/

Open64 would support the libc in llvm in the future.

Screen Shot 2023-08-01 at 18 47 25

Yvan-xy commented 1 year ago

Meanwhile, the libacml_mv is deprecated now. It's too old to use.

qingw1230 commented 1 year ago

Thank you, now I can print WHIRL IR.

Previously, I specified the path for stddef.h as -I/usr/include/linux, but it was not successful.

Now the specified path is -I/usr/lib/gcc/x86_64-linux-gnu/9/include and there is no problem.

qingw1230 commented 1 year ago

Is there any way to prevent open64 from converting sin to fastsin? Or how can I use the functions in math.h?

Assuming we have the following C code:

#include <stdio.h>
#include <math.h>

int main() {
    for (int i = 0; i < 2; i++) {
        int result = sin(i);
        printf("%f\n", result);
    }
    return 0;
}

Using the following compilation options:

openCC -S test.c

Opening test.s will reveal the following contents:

cvtsi2sd %ebx,%xmm0             # [0]
.globl  fastsin
call fastsin                    # [0] fastsin

It replaced the sin function with fastsin. Manually changing fastsin to sin allows the code to run properly. How can I prevent the substitution from happening?

Yvan-xy commented 1 year ago

Did you make any changes related to the libacml_mv in the Makefile? We have removed it from the toolchain. The sin function in my a.s file seems correct. Screen Shot 2023-08-02 at 11 36 00

qingw1230 commented 1 year ago

I didn't modify the Makefile file and I'm not sure what happened. Now I have installed open64 on two machines, one is working fine, but the other one has problems. This is a normal screenshot: image This is the problematic one: image Both machines have Ubuntu 20.04 operating system. The CPU of the problematic machine is: Intel(R) Xeon(R) CPU E5-2630 v4 @ 2.20GHz

Yvan-xy commented 1 year ago

Have you checked out the develop branch?

qingw1230 commented 1 year ago

I installed the w2ll branch on both machines. Just now, I reinstalled it on the problematic machine, but 'sin' was still replaced with 'fastsin'.

Yvan-xy commented 1 year ago

Try to add this option: -OPT:fast_math=0

I have no idea why the OPT_Fast_Math is turned on. https://github.com/open64-compiler/open64/blob/7e934651214049860141269bbadb457056745d51/osprey/be/com/emulate.cxx#L4646

qingw1230 commented 1 year ago

After adding this option, it works fine. image

qingw1230 commented 1 year ago

The problematic machine did not report this warning. Is it related to this issue?

openCC WARNING: cannot deduce a supported CPU name from /proc/cpuinfo, defaulting to basic 64-bit x86.

Yvan-xy commented 1 year ago

Sounds possible.