sifive / riscv-llvm

SiFive's LLVM working tree
83 stars 14 forks source link

Question about llvm intrinsic::vsetvl #9

Closed WilliamWangPeng closed 4 years ago

WilliamWangPeng commented 4 years ago

Hi everyone      Iwant to ask some llvm intrinsic::vsetvl questions here, which may not proper to open an issue here? but can't find other places.      Nowadays I'm building EPI project, one things confused me is that test-epi-max.o can't link to test-epi-max ELF, I used riscv64-unknown-elf-ld to link but errors occured.

     test-epi-max.c is one part of epi/clang/test/CodeGen/epi-builtins.c

unsigned long test_vsetvlmax__epi_e64__epi_m1()
{
    unsigned long vlmax = __builtin_epi_vsetvlmax(__epi_e64, __epi_m1);
    return vlmax;
}  

clang --target=riscv64-unknown-linux-gnu -mepi -S test-epi-max.c -emit-llvm -O2 -o test-epi-max.bc
 llc test-epi-max.bc  
clang --target=riscv64-unknown-linux-gnu -mepi -c test-epi-max.s -o test-epi-max.o  
riscv64-unknown-elf-gcc test-epi-max.o -o test-epi-max  

errors

/home/u/tools/rv64/lib/gcc/riscv64-unknown-elf/10.0.0/../../../../riscv64-unknown-elf/bin/ld: /home/u/tools/rv64/lib/gcc/riscv64-unknown-elf/10.0.0/../../../../riscv64-unknown-elf/lib/crt0.o: in function `.L0 ':
(.text+0x38): undefined reference to `main'
collect2: error: ld returned 1 exit status

Best Regards William

ebahapo commented 4 years ago

Hi, William.

     Iwant to ask some llvm intrinsic::vsetvl questions here, which may not proper to open an issue here? but can't find other places.      Nowadays I'm building EPI project, one things confused me is that test-epi-max.o can't link to test-epi-max ELF, I used riscv64-unknown-elf-ld to link but errors occured.

     test-epi-max.c is one part of epi/clang/test/CodeGen/epi-builtins.c

unsigned long test_vsetvlmaxepi_e64__epi_m1() { unsigned long vlmax = builtin_epi_vsetvlmax(__epi_e64, __epi_m1); return vlmax; }

clang --target=riscv64-unknown-linux-gnu -mepi -S test-epi-max.c -emit-llvm -O2 -o test-epi-max.bc llc test-epi-max.bc
clang --target=riscv64-unknown-linux-gnu -mepi -c test-epi-max.s -o test-epi-max.o Any reason why you want the IR and assembly files? Otherwise, just invoke clang once with:

clang --target=riscv64-unknown-linux-gnu -mepi -c test-epi-max.c

riscv64-unknown-elf-gcc test-epi-max.o -o test-epi-max
errors

/home/u/tools/rv64/lib/gcc/riscv64-unknown-elf/10.0.0/../../../../riscv64-unknown-elf/bin/ld: /home/u/tools/rv64/lib/gcc/riscv64-unknown-elf/10.0.0/../../../../riscv64-unknown-elf/lib/crt0.o: in function .L0 ': (.text+0x38): undefined reference tomain' collect2: error: ld returned 1 exit status This command line is trying to link a C program, which starts at main() and should be included by the programmer. Did you include one?

HTH

__ Evandro Menezes ◊ SiFive ◊ Austin, TX

WilliamWangPeng commented 4 years ago

Thank you for your guidance Evandro Menezes.      I have try a main test function like this:

#include<stdio.h>
unsigned long test_vsetvlmax__epi_e64__epi_m1()
{
    unsigned long vlmax = __builtin_epi_vsetvlmax(__epi_e64, __epi_m1);
    return vlmax;
}
int main()
{
    test_vsetvlmax__epi_e64__epi_m1();
    return 0;
}    
    riscv64-unknown-elf-gcc test.o -o test    
    spike pk test    

    nowadays the RISC-V ELF test can be linked, but the spike pk has errors here:

readelf -a f
spike pk f
f is also a RISC-V ELF, just the different naming with test here.

rofirrim commented 4 years ago

Hi @WilliamWangPeng do you mind if we continue the discussion by email?

I don't think we should bother SiFive folks with questions about the EPI compiler.

WilliamWangPeng commented 4 years ago

ok, thank you dear Roger, I'll send you the e-mail now