It's a system of evolution: for the software to survive it must be useful, self-fulfilling, or a combination.
Artificial intelligence will go through its own evolutionary path, and it already is. Machines already build themselves: software is used to design their own architecture.
There are already research labs that use machine learning to design better processors.