[LLVMdev] adding header files to code

Mattias Holm holm at liacs.nl
Wed Apr 1 02:09:13 PDT 2009

You have to add time.h when you compile the original C-code to LLVM IR. 
LLVM has no notion of C-header files, so you cannot add a C header file 
to a module. If you then want the type for clock_t you can lookup the 
clock function declaration in the LLVM module and ask for its type.


Kshitiz Garg wrote:
> Hi,
>    I was wondering how to add header files to code in LLVM. I am trying 
> to create a small profiler to track the actual time spent in functions.
> For this i am adding call to clock() in the C code of the given program. 
> However this will require adding the file time.h to C code. Can some  
> tell me a way to do so.
> I have tried using Module.addLibrary("time.h"); but this doesn't seem to 
> address the problem because I am not able to get the type clock_t by 
> using Module.getType() .Moreover only adding just the module.addlibrary 
> does not add the header file in the generated c code.
>  It would be a great help if someone could shed light as to how to 
> introduce header files by a transformation pass and able to use the 
> types defined in the header file in the pass itself.
> A similar scenario can arise in a parallelizing transformation where one 
> is trying to create threads but this requires inclusion of pthread.h to 
> access the types like pthread_t. etc.
> -- 
> Kshitiz Garg
> Graduate Student
> Department of Computer Science & Engineering
> IIT Kanpur
> ------------------------------------------------------------------------
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev

More information about the llvm-dev mailing list