[LLVMdev] copy Value object?
John Criswell
criswell at illinois.edu
Mon Sep 19 11:02:20 PDT 2011
On 9/19/11 12:53 PM, ret val wrote:
> Is there a easy way to copy a Value object, so it can be used in
> multiple instructions without a dominance issue?
A value object can be used multiple times with no problem.
The dominance problem stems from the fact that the program must be in
SSA form. When the program uses a value, it must have been defined
dynamically for all possible executions of the program. This is why the
definition of a value must dominate all of its uses.
If you're instrumenting code and having trouble meeting the dominance
requirement, what you should do is add the "variable" as an alloca'ed
stack variable that is read/written by loads/stores instead of as an SSA
value that is defined only once.
For example, instead of adding code that does this:
%y = add %x, 5
...
%z = sub %y, 2
... you add this:
entry_block:
%yp = alloca <type of y>
...
%y1 = add %x, 5
store %y1, %yp
...
%y2 = load %yp
%z = sub %y2, 2
The second version of the code allows the "variable" stored into the
alloca'ed memory to never have been initialized or to be written
multiple times. You are freed from trying to keep %y in valid SSA form
at all times.
After your pass is run, you can run the -mem2reg pass. This pass will
convert your instrumented code into SSA form (i.e., it will change the
second version of the code into the first version of the code).
-- John T.
> _______________________________________________
> 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