nico
nico

Reputation: 1406

In LLVM, how can I get a Value's ValuetoValueMapTy (VMap)? What its purpose?

On the context of cloning functions, one of the used objects is the ValueToValueMapTy &VMap which is a typedef ofValueMap<const Value *, WeakVH>.

For example, it is used during cloneFunctionInto(...) in llvm/lib/Transforms/Utils/CloneFunction.cpp

Thus I have questions that will help me clarify its purpose:

  1. Does every llvm::Value has its on VMap? Or this only belongs to Functions or Modules or what?
  2. How do I get this ValueMap for a specific function?
  3. Is it correct that its purpose is to hold information of llvm::Values of the function?

ps.:

I have already checked those links that may be helpful to others asking questions on Vmap, but none of them could completely answer my questions.

What to pass for the vmap argument of CloneFunction in llvm?

Filling the LLVM CloneFunction VMAP

LLVM CloneFunction.cpp

Upvotes: 2

Views: 1698

Answers (1)

Yishen Chen
Yishen Chen

Reputation: 589

Purpose of the ValueMap in CloneFunction is to record the mapping from values in the source function to values in the cloned function.

Example:

Function *F;
Value *V = /* some register in F */;
ValueToValueMapTy VMap;
auto *Clone = CloneFunction(F, VMap);
// V2 represents essentially the same register as V,
// except it's in Clone instead of F
Value *V2 = VMap[V];

Upvotes: 5

Related Questions