[LLVMdev] How to replace a global variable to one with a different type?

Duncan Sands baldrick at free.fr
Fri Feb 4 02:38:23 PST 2011


Hi Talin,

> I'm experimenting with "replaceAllUsesWith" and I see that it requires that the
> replacement be the same type.
>
> Here's what I am trying to do: Say I have a global variable A whose type is [10
> x Foo]. The only references to A are via GEPs which get a pointer to the first
> element: GEP(A, 0, 0), so in other words no user of A knows the length of the
> array from the type.
>
> Now I want to replace A with A', which is exactly the same except that it has a
> different array length. I want to remove all references to the original A. I
> can't use replaceAllUsesWith, because A and A' have different types.

first generate a (constexpr) bitcast of A' to [10 x Foo]*, then do RAUW of A
with the bitcast.

Ciao, Duncan.



More information about the llvm-dev mailing list