how to build a StructType incrementally


StructType has no method for adding elements, but I'd like to build
a type incrementally, i.e. it starts empty and a global of the type exists.
then load instructions are added to a basic block and for each load
instruction an element to the type has to be added. Is there a way to do this?
For example I could first use UndefValues instead of load and then
do a replaceAllUsesWith when the type is finally known. Does this work
or is there a better solution?