Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to link codon LLVM and functions of clang LLVM? #516

Open
iSunfield opened this issue Dec 21, 2023 · 1 comment
Open

How to link codon LLVM and functions of clang LLVM? #516

iSunfield opened this issue Dec 21, 2023 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@iSunfield
Copy link

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'

@inumanag
Copy link
Contributor

Chiming in @arshajii who can help with this.

@inumanag inumanag added the enhancement New feature or request label Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants