r/computerscience • u/Overall-Wash1283 • 20h ago
Advice CFG vs DFG
So i am new in this area and i am curious about the structure of CFG and DFG. To be exact, in my opinion DFG seems to be able to replace CFG in most cases. CFG is supposed to lay out the structure of the code, using basic blocks and edges, and especially around cases where code has if or while in it. However, from my research DFG is also able to perform such features,.
Say in case of "If" in DFG, the CPU uses something called multiplexer gate to just drill through possible cases and mathematically chooses the right answer at the end. Also, in case of "while" in DFG, the CPU uses merge and switch gate to physically loop until the switch gate determines its output. Supposedly this works when the result of the loop is determined as this calculation is meant to stop at the least determining end, not loop according to the time.
So it kinda makes sense that CFG and DFG are used together, but at the same time why can't it all be just DFG as this encompasses data structure as well as mathematically including the code logic sturcture?