Hi everyone, I am doing some work with LLVM IR, I need to use LLVM IR to do operation on C variables. Code emission is done by LLVM JIT. That variable is C thread local , for example __thread int* gvar; I think some methods to convert that variable to LLVM IR, (1) use external function I know LLVM IR is able to call an external function, so I can write codes that look like: int* load() { return gvar; } %x = call load(); // LLVM IR so gvar is converted to %x This method takes a lot of work and slow down the performance. Method 2 use LLVM InlineAsm to load that gvar so It may look like %x = call InlineAsm(... ); but I am not really sure how to write LLVM InlineAsm. The reason why I take such indirect method is that as I know, JIT is not able to do with LLVM GlobalVariable with ThreadLocal type. I would be grateful to you for any idea on handling this problem Have A Nice Day Chia Lun Liu -- View this message in context: http://llvm.1065342.n5.nabble.com/Convert-C-variable-to-LLVM-IR-Variable-tp55680.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
> Method 2 > > use LLVM InlineAsm to load that gvar > so It may look like > %x = call InlineAsm(... ); > > but I am not really sure how to write LLVM InlineAsm.Are you looking for this? http://llvm.org/docs/LangRef.html#inline-assembler-expressions HTH, chenwj -- Wei-Ren Chen (陳韋任) Computer Systems Lab, Institute of Information Science, Academia Sinica, Taiwan (R.O.C.) Tel:886-2-2788-3799 #1667 Homepage: http://people.cs.nctu.edu.tw/~chenwj
Hi Chia Lun Liu, > The reason why I take such indirect method is that as I know, JIT is not> able to > > do with LLVM GlobalVariable with ThreadLocal type.did you try mcjit? Run lli with -use-mcjit Ciao, Duncan.
Hi Wei-Ren Chen, Thanks for your information, I also find a method to write LLVM InlineAsm First, write a c program which contain gcc asm ( I know how to write gcc asm ) then use clang -S -emit-llvm $prog next do llc -march=cpp $prog.s You will see how to write LLVM InlineAsm in the output file by llc Chia Lun Liu -- View this message in context: http://llvm.1065342.n5.nabble.com/Convert-C-variable-to-LLVM-IR-Variable-tp55680p55692.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Hi Ciao, Duncan I had tested your method before but fail. I did it today but fail again. I write a simple c program #include<stdio.h> __thread int g[128]; int main() { int i; for(i = 0 ; i< 128 ; i++) { g[i] = 2*i; printf("%d\n",g[i]); } return 0; } ------------- I turn it to LLVM IR by clang -S -emit-llvm $file then use lli -use-mcjit $file.s the following is my output :~/Desktop/program$ lli threadLocal.s -use-mcjit Cannot allocate thread local storage on this arch! UNREACHABLE executed at /home/bendog/Desktop/llvm-3.2.src/lib/Target/X86/X86JITInfo.cpp:585! 0 lli 0x0000000000d14acf 1 lli 0x0000000000d14fe9 2 libpthread.so.0 0x00007fae25fc9cb0 3 libc.so.6 0x00007fae25218425 gsignal + 53 4 libc.so.6 0x00007fae2521bb8b abort + 379 5 lli 0x0000000000d00fbc 6 lli 0x00000000006176ec 7 lli 0x0000000000845747 llvm::JIT::getMemoryForGV(llvm::GlobalVariable const*) + 343 8 lli 0x00000000008471ed llvm::JIT::getOrEmitGlobalVariable(llvm::GlobalVariable const*) + 333 9 lli 0x0000000000850739 10 lli 0x000000000085222b 11 lli 0x000000000057c151 12 lli 0x0000000000cadd1f llvm::FPPassManager::runOnFunction(llvm::Function&) + 607 13 lli 0x0000000000cb134b llvm::FunctionPassManagerImpl::run(llvm::Function&) + 139 14 lli 0x0000000000cb14c9 llvm::FunctionPassManager::run(llvm::Function&) + 105 15 lli 0x0000000000847647 llvm::JIT::jitTheFunction(llvm::Function*, llvm::MutexGuard const&) + 39 16 lli 0x0000000000847cac llvm::JIT::runJITOnFunctionUnlocked(llvm::Function*, llvm::MutexGuard const&) + 28 17 lli 0x0000000000847e69 llvm::JIT::getPointerToFunction(llvm::Function*) + 265 18 lli 0x000000000050b71a main + 3210 19 libc.so.6 0x00007fae2520376d __libc_start_main + 237 20 lli 0x0000000000512d09 Stack dump: 0. Program arguments: lli threadLocal.s -use-mcjit 1. Running pass 'X86 Machine Code Emitter' on function '@main' Aborted (core dumped) As can seen from the result, I use llvm 3.2, and my machine is x86_64 , OS : Ubuntu 12.xx Chia Lun Liu -- View this message in context: http://llvm.1065342.n5.nabble.com/Convert-C-variable-to-LLVM-IR-Variable-tp55680p55694.html Sent from the LLVM - Dev mailing list archive at Nabble.com.
Apparently Analagous Threads
- [LLVMdev] Convert C variable to LLVM IR Variable
- [LLVMdev] LLVM-GCC generating too much code from inline assembly
- [LLVMdev] LLVM-GCC generating too much code from inline assembly
- [LLVMdev] Inserting Instructions (pass)
- [LLVMdev] Inserting Instructions (pass)