CFG of a function

How could I keep the function CFG in another memory space.

I want to be able to change one of the old CFG , but keeping the original one in another space.

Thanks

Why you don’t map the basic blocks to integers and apply algorithms on the integer graph? And construct your new CFG.

What do you mean by mapping to integers?

Map every basic block from the CFG to a set of integers. The successors from the CFG can be used to make the edges in your simplified graph. The pair (Callee,Caller) can link the CFG-s between them in a larger CFG-like.

I think I understood that, but what I mean is what is the function responsible to do mapping is it MapValue() in ValueMapper.h?

Thanks for your help

I don’t use a function for do the mapping, it may be MapValue(). If it does not work, alias an int identifier for each basic block. Be aware because basic block cannot have the same name (getName) in the same function, but they might have the same name being in different functions. Therefore, take into account the function name as well.

Good luck

But I don’t want to map only basic blocks, I need too to map the edges “the whole CFG of the function”

Save the CFG of the function in another memory address and call it for example orgCFG and change the CFG by referencing to the orgCFG

Thank you for help and patience

But I don’t want to map only basic blocks, I need too to map the edges “the whole CFG of the function”

Yes. First you create simple methods to create an integer graph and to addEdge. Then, two types of edges: between basic blocks inside a function (you can use LLVM succesors) and between functions (use Call/Return/ and identify the pairs (Callee/Caller), so you can add edges between the correspondent basic blocks from different functions.

Save the CFG of the function in another memory address and call it for example orgCFG and change the CFG by referencing to the orgCFG

So first make all the changes on orgCFG (the integers CFG) and then, in another transformation pass: modify your old CFG (by removing./adding, which I don’t recommand) or add metadata (keeps information about the changes you want to make, but you don’t actually make)

Thank you for help and patience

Good luck !

Hi Rasha,

First, you should not erase that cloned function XD the idea is that your pass should create that new function, add it to a module (that could be the same one where the original function is, or another one that you could be creating if that is the case), and then just let it be: the pass manager should identify this new function (after your pass returned) and all the other analysis and transformations should be called for this new function you created (even your own pass could be called again for this new function, depending on the type of you pass). If you call eraseFromParent, then all the instruction, BB’s, arguments, and everything you cloned will be deleted from memory, and it’ll just seem like nothing was cloned.

Ok, now in order to identify all the values between the two copies of the functions you need to use that ValueToValueMap that you created and used as an argument for cloneFunction. This VMap can be seen as a hash of values, and everything in the cloned function is mapped to something in the original function inside this map. So, if you need to identify an equivalent BB between them, for example, you could use VMap[BBfromOrigFunc] to access the pointer to the equivalent BB in you clone.

You can address any value using this map, but only using a original function’s value as the key for VMap. So, you must be careful and not applying any transformations on your original function, unless you don’t need the VMap anymore.

Also, you will probably need to use llvm::cast or llvm::dyn_cast to get the right type for your references, since every reference in a ValueToValueMap is a Value :wink:

PS: I’m adding the llvm-dev list back into the recipients, since someone else could also find this informations useful.

Cheers,