[LLVMdev] Removal of ConstantExprs
sabre at nondot.org
Tue Jun 24 10:00:08 PDT 2008
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.
> 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
> 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
More information about the llvm-dev