On 10/14/11 11:20 AM, pablo barrio lópez-cortijo wrote:> Hi,
>
> I want to duplicate a function and transfer it from one module to another.
I found "CloneFunction()" but it needs an "vMap". I found
that "vMap" is used to map the original values to the new values. So,
hypothetically, if the original function uses a global variable from the
previous module and I want that use in the new function to be mapped to a global
variable in the new module... how can I add this map to the vMap so that
CloneFunction does it for me?
The value map specifies that, in the new function, the uses of an old
value should be replaced with a use of the new value. The index is the
old value, and the value that the index is mapped to is the new value.
For example:
GlobalValue * Old = ... // Old value in function
GlobalVaue * New = ... // New value in function
DenseMap<const Value *, Value *> ValueMap;
ValueMap[Old] = New; // This is what tells cloneFunction to replace
uses of Old with New in the cloned function
cloneFunction (..., ValueMap, ...);
Having said that, I don't know if cloneFunction() was designed to clone
a function and put the clone into a different module. I've always seen
it used to clone a function and place the clone within the same module
as the original function.
-- John T.
>
> If you have in mind any LLVM piece of code that does anything like that,
please let me know.
>
> Thanks ahead,
> Pablo
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev