Jobin, Gaël
2015-Mar-23 15:31 UTC
[LLVMdev] LLVM 3.6 and ConstantExpr::replaceUsesOfWithOnConstant(...) strange behavior
Le 20.03.2015 15:33, Duncan Exon Smith a écrit :> AFK right now, but IIRC, this function is supposed to be internal to replaceAllUsesWith() and it's not really supposed to be called directly. Constants aren't supposed to change. > > Why can't you just call replaceAllUsesWith()? > > -- dpnesBecause it does not do what I want. Basically, my algorithm is interested in some GlobalVariable that are used by constant expression. My goal is to replace the GlobalVariable reference inside the constant expression by another GlobalVariable. If I use REPLACEALLUSESWITH(...) on the constant expression, I should pass as argument a constant expression recreated from scratch. In the other hand, if I call REPLACEALLUSESWITH(...) on the GlobalVariable "a" with the new GlobalVariable "b", it will replace all variables "a" with "b" in the whole module and I still need the "a" for my algorithm. The best solution would be the first but, during my research, I found the function REPLACEUSESOFWITHONCONSTANT(...) that does exactly the job (with some improvment like the "in-place" replacement) and started using it. But now, it doesn't work anymore in LLVM 3.6... So, I was interested in the change made between the two versions. And, apart for my algorithm, I think that maybe the new implementation was not very logical. Like I said, the REPLACEOPERANDSINPLACE(...) seems designed to work with and without a given Use/NumUpdated argument (using an improvment for the first case). So, for me, it makes no sense to force using an Use argument for REPLACEUSESOFWITHONCONSTANT(...) because it can handle both cases with minor changes. Gael -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150323/537a9a39/attachment.html>
Duncan P. N. Exon Smith
2015-Mar-23 18:58 UTC
[LLVMdev] LLVM 3.6 and ConstantExpr::replaceUsesOfWithOnConstant(...) strange behavior
> On 2015-Mar-23, at 08:31, Jobin, Gaël <gael.jobin at switzerlandmail.ch> wrote: > > Le 20.03.2015 15:33, Duncan Exon Smith a écrit : > > AFK right now, but IIRC, this function is supposed to be internal to replaceAllUsesWith() and it's not really supposed to be called directly. Constants aren't supposed to change. > > Why can't you just call replaceAllUsesWith()? > > -- dpnes > Because it does not do what I want. Basically, my algorithm is interested in some GlobalVariable that are used by constant expression. My goal is to replace the GlobalVariable reference inside the constant expression by another GlobalVariable. If I use replaceAllUsesWith(...) on the constant expression, I should pass as argument a constant expression recreated from scratch. In the other hand, if I call replaceAllUsesWith(...) on the GlobalVariable "a" with the new GlobalVariable "b", it will replace all variables "a" with "b" in the whole module and I still need the "a" for my algorithm.It seems strange to me that you need to replace constant expressions but not other uses. For example, you'd be translating this code: ; This will not change. %ptr = getelementptr [2 x i8]* @a, i32 0, i32 0 store i8 7, i8* %ptr ; This will change. store i8 7, i8* getelementptr ([2 x i8]* @a, i32 0, i32 0) into: ; This still points at @a. %ptr = getelementptr [2 x i8]* @a, i32 0, i32 0 store i8 7, i8* %ptr ; This points at @b now. store i8 7, i8* getelementptr ([2 x i8]* @b, i32 0, i32 0) I don't understand how this is useful.> it will replace all variables "a" with "b" in the whole module and I still need the "a" for my algorithm.Just to be sure: you know that this function affects the whole module too, right?> > The best solution would be the first but, during my research, I found the function replaceUsesOfWithOnConstant(...) that does exactly the job (with some improvment like the "in-place" replacement) and started using it. > > But now, it doesn't work anymore in LLVM 3.6... So, I was interested in the change made between the two versions. And, apart for my algorithm, I think that maybe the new implementation was not very logical. Like I said, the replaceOperandsInPlace(...) seems designed to work with and without a given Use/NumUpdated argument (using an improvment for the first case). So, for me, it makes no sense to force using an Use argument for replaceUsesOfWithOnConstant(...) because it can handle both cases with minor changes.I'm still skeptical that this functionality is generally useful. I think you should find a valid `Use` to send in here (it's surprising you don't have one already; how do you know `@a` is an operand?). If we were to add this in-tree, I suppose the right place would be a non-virtual overload of `Constant::replaceUsesOfWithOnConstant()` that takes two arguments, searches operands for a `Use`, and then calls the `virtual` 3-arg version that already exists.