On 03/24/2010 12:10 PM, Ajay Kumar wrote: > I am writing a pass in which I need to insert a call to a library > function. Specifically I need to call the function > "pthread_mutex_lock" from the library "pthread". > > Looking around the documentation, what I found is I will have to use > the function gimple_build_call. My question is how do I build the tree > fn, and the arguments which have to be provided to gimple_build_call. > > I also found a function which does something similar, > "build_libfunc_function", but I'm not sure which one can be used for > this purpose. > > Do I have to use build_function_type_list and build_fn_decl for > building tree fn? The original function call "pthread_mutex_lock" > requires an "pthread_mutex_t" type variable as an argument, how can I > declare that in the pass, and use it as an argument in > gimple_build_call? Write a small C program that does what you want. Then, use the tree dumper to look at what trees gcc uses for your C. Then, call builders for each of the trees. You can step through in gdb to see how gcc does it. Andrew.