[LLVMdev] adding header files to code
adanalis at utk.edu
Wed Apr 1 14:54:36 CDT 2009
You can achieve the result you want, but I don't think you can do it in a "clean" way. For one, clock()'s result should be divided by CLOCKS_PER_SEC which is a macro and therefore it will never going to make it past the preprocessor. In other words, your optimization pass cannot emit code that uses CLOCKS_PER_SEC as a variable. You have to assume that its value (1,000,000) is fixed across all environments you want your pass to be used in, and hardcode the value. If you do that though, you can also assume that "clock_t" will be always "long int" and solve your original problem. If you think of it though, you would have to make an assumption along these lines anyway. If not, what would your optimization pass do with the return value of clock()?
Alternatively, you could follow a "two phases" approach. Write a small program that includes all the appropriate headers and uses the functions and/or macros your opt pass needs to insert in the target code, and distribute that little program with your pass. Then in phase one compile that program with LLVM and have another pass (say p0) look at the types/constants the front end generated based on the local headers. At this point, p0 can save in a configuration file all this info. Then, in phase two, your real optimization pass, p1, can read that configuration file and figure out the real sizes, constants, etc.
I hope this helps,
From: llvmdev-bounces at cs.uiuc.edu on behalf of Kshitiz Garg
Sent: Wed 4/1/2009 4:23 AM
To: LLVM Developers Mailing List
Subject: [LLVMdev] adding header files to code
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.
Department of Computer Science & Engineering
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 4062 bytes
Desc: not available
Url : http://lists.cs.uiuc.edu/pipermail/llvmdev/attachments/20090401/33505e95/attachment.bin
More information about the LLVMdev