codon
codon copied to clipboard
How to link codon LLVM and functions of clang LLVM?
I've been trying to link C or C++ function assets at the LLVM level with codon code to see if LLVM optimizations can be applied to these C/C++ functions. However, I encounter errors when using llvm-link. Below is the small example that generates the error. How can I successfully link codon's LLVM code with LLVM functions codecompiled by Clang? Any advice would be greatly appreciated.
//--- C abs function(File name:LlvmAbsWrapper.c)
#include <math.h>
double abs_wrapper(double val) {
return fabsf(val);
}
//--- Codon code(File name:LlvmAbs.codon)
@llvm
def abs_w(val: float) -> float:
declare double @abs_wrapper(double)
%0 = call double @abs_wrapper(double %val)
ret double %0
A=-20
print(abs_w(A))
#-- Compile c code to LLVM
clang -S -emit-llvm LlvmAbsWrapper.c -o LlvmAbsWrapper.ll
#-- Compile code code to LLVM
codon build -llvm LlvmAbs.codon
#-- Link both LLVM
llvm-link LlvmAbs.ll LlvmAbsWrapper.ll -o LlvmAbs.bc
LlvmAbs.ll:6:57: warning: ptr type is only supported in -opaque-pointers mode
%"__magic__.iter:0[Tuple.N1[float]].170.Frame" = type { ptr, ptr, double, { double }, i2, i8 }
^
llvm-link: LlvmAbs.ll:6:57: error: expected type
%"__magic__.iter:0[Tuple.N1[float]].170.Frame" = type { ptr, ptr, double, { double }, i2, i8 }
^
llvm-link: error: loading file 'LlvmAbs.ll'
Chiming in @arshajii who can help with this.