[LLVMdev] whether these transformations are doable and how?

Zheng Wang jason.wangz at gmail.com
Fri Apr 9 08:12:31 PDT 2010


Hi Ning,

The easy way is to check some examples in lib/Transformation or lib/Analysis.

You may also write some simple c programs, then you can use "llc
-march=cpp x.bc" to see how you can declare variables using LLVM APIs.

For example, you can simply write a c program named test.c as:

#include <stdio.h>

int global_1;
float global_2;

int main()
{
  int stack_1, stack_2;

  ...
  return 0;
}

You can translate it to LLVM Bytecode by:
llvm-gcc -emit-llvm -c test.c
opt -mem2reg -f < test.o > test.new.o

then, convert it c++ formation by:
llc -march=cpp test.new.o

You should be able to get some hints about how to declare global
variables from generated file --- test.new.o.cpp.

On 9 April 2010 12:29, Ning Wang <neal.wang at gmail.com> wrote:
> Hi folk,
>
> I'm a newbie to llvm, please first forgive my naive questions. I want to
> instrument llvm code to do some run-time monitoring work.  After reading
> some of the llvm documentation, it begins clear to me that I can do the
> instrumentation in a transformation pass.   There are several things I want
> to do in the transformation pass, but I'm not sure whether they are doable
> and how to do them even after I read the documentation.  I would be very
> appreciate if anyone can answer my questions or give me hints of how to do
> them.
>
> 1.  can I add more global memory objects to a module?  any hint how to do
> it?  do I need to derive a pass from ModulePass?
> 2.  can I add more stack allocated memory objects to a function?  the answer
> seems yes, any hint how to do it?
> 3.  can I modify a function to take extra formal parameters? can I update
> all calls of the original function to take extra actual paramters?  The
> function might be called across multiple modules.   It seems this has to be
> done at both ModulePass and FunctionPass levels.
>
> Thanks,
> Neal
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>
>

Cheers,
Zheng




More information about the llvm-dev mailing list