next up previous
Next: Analysis of Functions Containing Up: Method/Technique Previous: Analysis of Functions Containing

Analysis of Functions Containing Function Calls but No Stores/Loads

Now we extend our method to consider functions containing calls to other functions. If we computed all the Banning sets and used the results, then function calls were not an issue in our analysis, since the information contained in the Banning sets takes into account side effects that can be generated through function calls. However, since we decide not to use any Banning set computation, we have to develop an alternative to account for function calls.

First, let us consider the case where the current function contains function calls but no store to or load from non-local variables. Let us further assume that there is only one function call in the current function. In this case, any effects that the current function has will depend on any effects that the called function has. So the current function should inherit the class of the called function. With this fact, now we consider that the current function contains multiple function calls. Which class should be assigned to the current function? The effects of the current function will be the union of the effects of all the called functions. If one of the called function is unreusable, then the current function will have effects in the form of modification to non-local variables, and by definition the current function will also be unreusable. Similarly, if none of the called functions are unreusable but there is one or more which is pure, then the current function will have effects in the form of read from non-local variables, which means that it has to be pure. Only if there are no calls to unreusable or pure functions--in other words, all calls are to const functions--will the current function be const. So that is how we determine the class of the current function.

To determine the class of a called function, we apply the same method to it. This will present no problem if the call graph from the current function is in the form of a tree. In this case, the method will traverse the call graph to the functions at the leaves and propagate the results up the tree. However, cycles in the call graph present a problem, because the method described so far might potentially loop through these cycles infinitely when it cannot determine the class of the functions in the cycle. Nevertheless, in the case when all functions in the cycle do not contain any stores or loads, all functions in the cycle can be considered to be const, since there are no stores or loads in the whole cycle. We will consider cases of cycle with functions that may contain stores and loads in the next subsection.


Table 1: Matrix of Aggregate Effects of Stores/Loads and Function Calls
  unreusable pure const
  (function calls) (function calls) (function calls)
unreusable      
(stores/loads) unreusable unreusable unreusable
pure      
(stores/loads) unreusable pure pure
const      
(stores/loads) unreusable pure const



next up previous
Next: Analysis of Functions Containing Up: Method/Technique Previous: Analysis of Functions Containing
Indrayana Rustandi 2003-12-04