我正在尝试在 LLVM 中编写一个 5 元素向量加法程序,但不知道如何返回整个结果向量。我的代码在下面,错误是
LLVM 错误:提供的 main() 的返回类型无效
@veca = global [5 x i32] [i32 1, i32 2, i32 3, i32 4, i32 5]
@vecb = global [5 x i32] [i32 4, i32 6, i32 9, i32 2, i32 4]
define [5 x i32]* @vector_add([5 x i32]* %vec1, [5 x i32]* %vec2)
{
entry:
%vecc = alloca [5 x i32]
br label %loop
loop:
%i = phi i32 [0, %entry], [%nexti, %loop]
%nexti = add i32 %i, 1
%ptra = getelementptr [5 x i32]* %vec1, i64 0, i32 %i
%loada = load i32* %ptra
%ptrb = getelementptr [5 x i32]* %vec2, i64 0, i32 %i
%loadb = load i32* %ptrb
%added = add i32 %loada, %loadb
%ptr = getelementptr [5 x i32]* %vecc, i32 0, i32 %i
store i32 %added, i32* %ptr
%eq = icmp eq i32 %i, 4
br i1 %eq, label %loop, label %exit
exit:
ret [5 x i32]* %vecc
}
define [5 x i32] @main()
{
%answer = call [5 x i32]* @vector_add([5 x i32]* @veca, [5 x i32]* @vecb)
%ans = load [5 x i32]* %answer
ret [5 x i32] %ans
}