Talin
2011-Feb-04 09:10 UTC
[LLVMdev] How to replace a global variable to one with a different type?
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. -- -- Talin -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20110204/5ce9b6b7/attachment.html>
Duncan Sands
2011-Feb-04 10:38 UTC
[LLVMdev] How to replace a global variable to one with a different type?
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.
Seemingly Similar Threads
- [LLVMdev] Replacing uses within a function
- [LLVMdev] Replacing uses within a function
- InstCombine doesn't delete instructions with token
- [LLVMdev] Assertion: replaceAllUses of value with new value of different type! being thrown all of a sudden
- [LLVMdev] Pointers in Load and Store