Quiz time
Now that you have completed reading this chapter, try answering the following questions to test your knowledge:
- Would it be correct for a function pass to modify the definition of a global variable?
No, it would not because passes are not supposed to modify elements of the IR that are outside of the scope that was provided to them. It is okay to look at the broader scope, but not modify it.
Modifying a global variable would require a module scope since the variable is visible to the whole module.
More details in the What is a pass? section.
- Draw the CGSCC of the following snippet:
void foo() { bar(); baz(); } void bar() { foo(); baz(); } void baz() { charlie(); }
To draw the CGSCC, first compute the call graph. This gives you the nodes of the call graph and its edges. Then, identify the regions that are strongly connected. The definition of strongly connected is available in the What is a pass? section...