Mian M. Hamayun
2011-Aug-31 17:54 UTC
[LLVMdev] How to place call(s) to functions found in other llvm modules ???
Hi,
I tried this as well, using the following line to add function
declaration to the caller module.
Function::Create(FT, Function::ExternalLinkage, "gcd", mod);
Where "FT" is the same as before. And the output produced by the
PrintModulePass becomes:
; ModuleID = 'GCDMain'
declare i32 @gcd(i32, i32)
define i32 @main() {
EntryBlock:
%tmp = call i32 @gcd(i32 30, i32 50)
ret i32 %tmp
}
But it still fails to WriteBitcodeToFile, and produces the same error as
before.
I guess I might be missing some attribute, like "extern" in C ...
Any Comments?
Thanks again for your help,
Hamayun
On 08/31/2011 07:18 PM, Eli Friedman wrote:> On Wed, Aug 31, 2011 at 10:00 AM, Mian M. Hamayun
> <mian-muhammad.hamayun at imag.fr> wrote:
>> Hello Everyone,
>>
>> I am trying to create two modules in LLVM, where first module contains
the
>> definition of a function, gcd in this example and another module
contains a
>> call to this function.
>
> You can't reference a global in one module in another module. Either
> stick with one module, or add a declaration of the function in the
> second module and call that.
>
> -Eli
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3781 bytes
Desc: S/MIME Cryptographic Signature
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20110831/88b5b64c/attachment.bin>
Eli Friedman
2011-Aug-31 18:11 UTC
[LLVMdev] How to place call(s) to functions found in other llvm modules ???
On Wed, Aug 31, 2011 at 10:54 AM, Mian M. Hamayun <mian-muhammad.hamayun at imag.fr> wrote:> Hi, > > I tried this as well, using the following line to add function declaration > to the caller module. > > Function::Create(FT, Function::ExternalLinkage, "gcd", mod); > > Where "FT" is the same as before. And the output produced by the > PrintModulePass becomes: > > ; ModuleID = 'GCDMain' > > declare i32 @gcd(i32, i32) > > define i32 @main() { > EntryBlock: > %tmp = call i32 @gcd(i32 30, i32 50) > ret i32 %tmp > } > > But it still fails to WriteBitcodeToFile, and produces the same error as > before.If you're still getting the "Referencing function in another module" error, the call isn't referring to a declaration in the same module. -Eli
Mian M. Hamayun
2011-Sep-01 13:04 UTC
[LLVMdev] How to place call(s) to functions found in other llvm modules ???
Hi Eli,
Yes, you were right. I was doing something like this ... (which doesn't
work :()
Function* gcd = inMod.getFunction("gcd"); // Get gcd function from the
input module
...
Function *F_GCD = Function::Create(FT, Function::ExternalLinkage,
"gcd", mod); // Add a prototype of the gcd function
...
Value *gcd_val = builder.CreateCall(gcd, args.begin(), args.end(),
"tmp"); // Add a call to the gcd function.
In fact we don't need to getFunction from the other module.
Just adding a prototype and calling this prototype is sufficient.
Like this ... (this works :))
Function *F_GCD = Function::Create(FT, Function::ExternalLinkage,
"gcd", mod); // Add a prototype of the gcd function
...
Value *gcd_val = builder.CreateCall(F_GCD, args.begin(), args.end(),
"tmp"); // Add a call to the gcd function.
Thanks for you help,
Have a Nice Day !!!
Hamayun
On 08/31/2011 08:11 PM, Eli Friedman wrote:> On Wed, Aug 31, 2011 at 10:54 AM, Mian M. Hamayun
> <mian-muhammad.hamayun at imag.fr> wrote:
>> Hi,
>>
>> I tried this as well, using the following line to add function
declaration
>> to the caller module.
>>
>> Function::Create(FT, Function::ExternalLinkage, "gcd", mod);
>>
>> Where "FT" is the same as before. And the output produced by
the
>> PrintModulePass becomes:
>>
>> ; ModuleID = 'GCDMain'
>>
>> declare i32 @gcd(i32, i32)
>>
>> define i32 @main() {
>> EntryBlock:
>> %tmp = call i32 @gcd(i32 30, i32 50)
>> ret i32 %tmp
>> }
>>
>> But it still fails to WriteBitcodeToFile, and produces the same error
as
>> before.
>
> If you're still getting the "Referencing function in another
module"
> error, the call isn't referring to a declaration in the same module.
>
> -Eli
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3781 bytes
Desc: S/MIME Cryptographic Signature
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20110901/25a2f2cc/attachment.bin>
Seemingly Similar Threads
- [LLVMdev] How to place call(s) to functions found in other llvm modules ???
- [LLVMdev] How to place call(s) to functions found in other llvm modules ???
- [LLVMdev] How to place call(s) to functions found in other llvm modules ???
- [LLVMdev] LLVM JIT on a Baremetal x86 Machine !!!
- [LLVMdev] LLVM JIT on a Baremetal x86 Machine !!!