I build a simple (just to try and to learn roughly) LLVM Backend for custom RISC-V.
I simply convert sequential add and multiply to one instruction as in many examples to explain selectionDAG. After I built, I couldn’t compile the code below.
C code:
int a,b,c;
void maddFunc() {
a = 3;
b = 103;
c = 127;
a = a * b +c;
}
ll Code:
.text
.attribute 4, 16
.attribute 5, "rv64i2p0_m2p0_a2p0_f2p0_d2p0_c2p0_v1p0_zvl128b1p0_zvl32b1p0_zvl64b1p0"
.file "madd.c"
.globl maddFunc
.p2align 1
.type maddFunc,@function
maddFunc:
addi sp, sp, -16
sd ra, 8(sp)
sd s0, 0(sp)
addi s0, sp, 16
lui a1, %hi(a)
li a0, 3
sw a0, %lo(a)(a1)
lui a3, %hi(b)
li a0, 103
sw a0, %lo(b)(a3)
lui a2, %hi(c)
li a0, 127
sw a0, %lo(c)(a2)
lw a0, %lo(a)(a1)
lw a3, %lo(b)(a3)
mulw a0, a0, a3
lw a2, %lo(c)(a2)
addw a0, a0, a2
sw a0, %lo(a)(a1)
ld ra, 8(sp)
ld s0, 0(sp)
addi sp, sp, 16
ret
.Lfunc_end0:
.size maddFunc, .Lfunc_end0-maddFunc
.type a,@object
.section .sbss,"aw",@nobits
.globl a
.p2align 2
a:
.word 0
.size a, 4
.type b,@object
.globl b
.p2align 2
b:
.word 0
.size b, 4
.type c,@object
.globl c
.p2align 2
c:
.word 0
.size c, 4
.ident "clang version 14.0.0"
.section ".note.GNU-stack","",@progbits
.addrsig
.addrsig_sym a
.addrsig_sym b
.addrsig_sym c
The command that I used to compile from C to ll file is /home/llvm/Downloads/clang+llvm-14.0.0-x86_64-linux-gnu-ubuntu-18.04/bin/clang-14 -S -emit-llvm -g madd.c
. The command that I used to convert ll to s file is /home/llvm/llvm-project/FirstTrial/bin/llc -mtriple=riscv32 madd.ll
.
However, I am getting an error like that:
'x86-64' is not a recognized processor for this target (ignoring processor)
'generic' is not a recognized processor for this target (ignoring processor)
'+cx8' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'+mmx' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'+x87' is not a recognized feature for this target (ignoring feature)
'generic' is not a recognized processor for this target (ignoring processor)
'x86-64' is not a recognized processor for this target (ignoring processor)
'generic' is not a recognized processor for this target (ignoring processor)
'+cx8' is not a recognized feature for this target (ignoring feature)
'+fxsr' is not a recognized feature for this target (ignoring feature)
'+mmx' is not a recognized feature for this target (ignoring feature)
'+sse' is not a recognized feature for this target (ignoring feature)
'+sse2' is not a recognized feature for this target (ignoring feature)
'+x87' is not a recognized feature for this target (ignoring feature)
'generic' is not a recognized processor for this target (ignoring processor)
Is this mean that I can compile my code successfully ? or there is an error? because it creates s file which seems correct. The problematic part is I cannot see that my new instruction in the final assembly file. It should be about either use of llc or the code that I wrote for selection dag.