我正在尝试在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
}
答案 0 :(得分:1)
这个IR本身没有任何问题 - 它与llc
编译得很好。您的问题可能是尝试JIT或解释它,因为LLVM ExecutionEngine
期望main
具有标准签名:
int main()