Hi All, I'm having a bit of trouble with ConstantExprs currently. In particular, a global variable A is bitcasted and used in the initializer of another global variable B (as a struct element). B is unused, so it gets whacked and its initializer gets set to NULL. This succesfully reduces the usecount of the bitcast to 0, but the bitcast itself does not get removed then. This means that further on, other transformations fail because A is still used by the bitcast. Now I know that there is GlobalValue::removeDeadConstantUsers which the transformation could be calling, but shouldn't that be arranged automatically? Also, in this case I'm using a bitcast of A, but what if this was a bitcast of a gep of a A? In this case, removeDeadConstantUsers on A would not remove anything, since the GEP is still used by the bitcast. AFAICS this kind of thing should be triggered when the use is removed (ie, when the initializer is set to 0). I was however unable to find the implementation of Use::set(), which seems to be closely related. Does anyone know where it is (grepping for "set" didn't prove so fruitful...)? Gr. Matthijs -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080624/dd752a99/attachment.sig>
On Tue, 24 Jun 2008, Matthijs Kooijman wrote:> I'm having a bit of trouble with ConstantExprs currently. In particular, a > global variable A is bitcasted and used in the initializer of another global > variable B (as a struct element). > > B is unused, so it gets whacked and its initializer gets set to NULL. This > succesfully reduces the usecount of the bitcast to 0, but the bitcast itself > does not get removed then. This means that further on, other transformations > fail because A is still used by the bitcast.ok.> Now I know that there is GlobalValue::removeDeadConstantUsers which the > transformation could be calling, but shouldn't that be arranged automatically?We can't "garbage collect" ConstantExprs at arbitrary points: they may exist in maps, in local variables etc. There is no good way to know they are dead.> Also, in this case I'm using a bitcast of A, but what if this was a bitcast of > a gep of a A? In this case, removeDeadConstantUsers on A would not remove > anything, since the GEP is still used by the bitcast.removeDeadConstantUsers removes both of them. Existing clients call removeDeadConstantUsers and then recheck to see if the use count is zero. If not, there was some real user that can't be removed.> AFAICS this kind of thing should be triggered when the use is removed (ie, > when the initializer is set to 0). I was however unable to find the > implementation of Use::set(), which seems to be closely related. Does anyone > know where it is (grepping for "set" didn't prove so fruitful...)?I'm not sure what you mean here -Chris -- http://nondot.org/sabre/ http://llvm.org/
> We can't "garbage collect" ConstantExprs at arbitrary points: they may > exist in maps, in local variables etc. There is no good way to know they > are dead.Ah, makes sense.> > Also, in this case I'm using a bitcast of A, but what if this was a bitcast of > > a gep of a A? In this case, removeDeadConstantUsers on A would not remove > > anything, since the GEP is still used by the bitcast. > removeDeadConstantUsers removes both of them. Existing clients call > removeDeadConstantUsers and then recheck to see if the use count is zero. > If not, there was some real user that can't be removed.Ah, in that case, I should just modify my pass to call removeDeadConstantUsers before inspecting the global.> > AFAICS this kind of thing should be triggered when the use is removed (ie, > > when the initializer is set to 0). I was however unable to find the > > implementation of Use::set(), which seems to be closely related. Does anyone > > know where it is (grepping for "set" didn't prove so fruitful...)? > I'm not sure what you mean hereI was just following the code that is related to this stuff, and couldn't find the implementation of Use::set(). It's declared in Use.h but not implemented there, nor in Use.cpp. Anyway, considering the above, this is no longer relevant. Thanks! Matthijs -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 189 bytes Desc: Digital signature URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20080624/398dcdff/attachment.sig>