Add a flow flattening util

Instead of recursively executing subflows which causes
dead locks when they parent and subflows share the same
executor we can instead flatten the parent and subflows
into a single graph, composed with only tasks and run
this instead, which will not have the issue of subflows
dead locking, since after flattening there is no concept
of a subflow.

Fixes bug: 1225759

Change-Id: I79b9b194cd81e36ce75ba34a673e3e9d3e96c4cd