I'm trying to implement a codegen (I seek for assembler listing only, not a binary code) for custom architecture which doesn't have hardware implementation of integer division. I use clang frontend and get symbols like __divsi3 in my assembler listing. I see an implementation of __divsi3 in compiler_rt library of LLVM. How could I use this?
-
You can adapt the code from this answer.Alexey Frunze– Alexey Frunze2012-09-29 08:38:21 +00:00Commented Sep 29, 2012 at 8:38
-
I don't ask for algorithm of division, but for a way of using standard library function.Artem Pelenitsyn– Artem Pelenitsyn2012-09-29 09:12:08 +00:00Commented Sep 29, 2012 at 9:12
-
Then I don't understand your question. Can you elaborate it or provide an example of what you want?Alexey Frunze– Alexey Frunze2012-09-29 09:14:14 +00:00Commented Sep 29, 2012 at 9:14
-
I suppose you should compile libcompile_rt into bitcode and then substitute calls like __divsi3 with their code.arrowd– arrowd2012-09-30 13:21:14 +00:00Commented Sep 30, 2012 at 13:21
Add a comment
|
1 Answer
You'll use your new compiler to compile the appropriate functions in compiler-rt that your processor is missing. Then include the compiler-rt library at link time so the unresolved symbol can be resolved.
__divsi3 is just a simple C function that uses simpler operations to perform the division that your architecture doesn't support.
3 Comments
Artem Pelenitsyn
Sounds reasonable, thank you. The only gotcha I have, is that I have no control on linkage, my codegen just generates asm. And I'm not sure that the current setting allows for multi-file linkage. I have to elaborate on asm-to-bin tool documentation — whether it can link multiple asm files.
Richard Pennington
No problem. Just compile the compiler-rt files to bitcode, use llvm-link to link the rt objects with your application code bitcode, and then run the result through your code generator.
Artem Pelenitsyn
I found necessary linker option. But I have another problem now: how to told LLVM to add an external declaration for the function which implements integer division…