private void rebuildProgramTree(GDirectedGraph<CodeBlockVertex, GEdge<CodeBlockVertex>> dg,
			CodeBlockVertex vertex, ProgramModule module) throws CancelledException {

		Collection<CodeBlockVertex> children = dg.getSuccessors(vertex);
		if (children == null || children.isEmpty()) {
			makeFragment(program, module, vertex);
			return;
		}

		ProgramModule currentModule = createModule(module, vertex.getName());
		makeFragment(program, currentModule, vertex);

		for (CodeBlockVertex child : children) {
			monitor.checkCancelled();
			rebuildProgramTree(dg, child, currentModule);
		}
	}
this code will apply the Dominance algorithm to a module or fragment in
a program tree.  First the code generates a call graph and from there a
dominance graph and finally a dominance structure in the program tree.
Ghidra/Features/Base/src/main/java/ghidra/app/cmd/module/DominanceModularizationCmd.java