Package org.apache.sysds.hops.ipa
Class FunctionCallGraph
- java.lang.Object
- 
- org.apache.sysds.hops.ipa.FunctionCallGraph
 
- 
 public class FunctionCallGraph extends Object 
- 
- 
Constructor SummaryConstructors Constructor Description FunctionCallGraph(DMLProgram prog)Constructs the function call graph for all functions reachable from the main program.FunctionCallGraph(StatementBlock sb)Constructs the function call graph for all functions reachable from the given statement block.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description booleancontainsSecondOrderCall()Indicates if the function call graph, i.e., functions that are transitively reachable from the main program, contains a second-order builtin function call (e.g., eval, paramserv), which prohibits the removal of unused functions.Set<String>getCalledFunctions(String fkey)Returns all functions called from the given function.Set<String>getCalledFunctions(String fnamespace, String fname)Returns all functions called from the given function.List<FunctionOp>getFunctionCalls(String fkey)Returns all function operators calling the given function.List<StatementBlock>getFunctionCallsSB(String fkey)Returns all statement blocks that contain a function operator calling the given function.Set<String>getReachableFunctions()Returns all functions that are reachable either directly or indirectly form the main program, except the main program itself.Set<String>getReachableFunctions(Set<String> excludeList)Returns all functions that are reachable either directly or indirectly form the main program, except the main program itself and the given exclude-list of function names.booleanisReachableFunction(String fkey)Indicates if the given function is reachable either directly or indirectly from the main program.booleanisReachableFunction(String fnamespace, String fname)Indicates if the given function is reachable either directly or indirectly from the main program.booleanisRecursiveFunction(String fkey)Indicates if the given function is either directly or indirectly recursive.booleanisRecursiveFunction(String fnamespace, String fname)Indicates if the given function is either directly or indirectly recursive.booleanisSideEffectFreeFunction(String fkey)Indicates if the given function is side effect free, i.e., has no prints, no persistent write, and includes no or only calls to side-effect-free functions.booleanisSideEffectFreeFunction(String fnamespace, String fname)Indicates if the given function is side effect free, i.e., has no prints, no persistent write, and includes no or only calls to side-effect-free functions.voidremoveFunctionCall(String fkey, FunctionOp fop, StatementBlock sb)Removes a single function call identified by target function name, and source function op and statement block.voidremoveFunctionCalls(String fkey)Removes all calls of the given function.voidreplaceFunctionCalls(String fkeyOld, String fkey)Replaces a function call to fkeyOld with a call to fkey, but using the function op and statement block from the old.
 
- 
- 
- 
Constructor Detail- 
FunctionCallGraphpublic FunctionCallGraph(DMLProgram prog) Constructs the function call graph for all functions reachable from the main program.- Parameters:
- prog- dml program of given script
 
 - 
FunctionCallGraphpublic FunctionCallGraph(StatementBlock sb) Constructs the function call graph for all functions reachable from the given statement block.- Parameters:
- sb- statement block (potentially hierarchical)
 
 
- 
 - 
Method Detail- 
getCalledFunctionspublic Set<String> getCalledFunctions(String fnamespace, String fname) Returns all functions called from the given function.- Parameters:
- fnamespace- function namespace
- fname- function name
- Returns:
- set of function keys (namespace and name)
 
 - 
getCalledFunctionspublic Set<String> getCalledFunctions(String fkey) Returns all functions called from the given function.- Parameters:
- fkey- function key of calling function, null indicates the main program
- Returns:
- set of function keys (namespace and name)
 
 - 
getFunctionCallspublic List<FunctionOp> getFunctionCalls(String fkey) Returns all function operators calling the given function.- Parameters:
- fkey- function key of called function, null indicates the main program and returns an empty list
- Returns:
- list of function call hops
 
 - 
getFunctionCallsSBpublic List<StatementBlock> getFunctionCallsSB(String fkey) Returns all statement blocks that contain a function operator calling the given function.- Parameters:
- fkey- function key of called function, null indicates the main program and returns an empty list
- Returns:
- list of statement blocks
 
 - 
removeFunctionCallspublic void removeFunctionCalls(String fkey) Removes all calls of the given function.- Parameters:
- fkey- function key of called function, null indicates the main program, which has no affect
 
 - 
removeFunctionCallpublic void removeFunctionCall(String fkey, FunctionOp fop, StatementBlock sb) Removes a single function call identified by target function name, and source function op and statement block.- Parameters:
- fkey- function key of called function
- fop- source function call operator
- sb- source statement block
 
 - 
replaceFunctionCallspublic void replaceFunctionCalls(String fkeyOld, String fkey) Replaces a function call to fkeyOld with a call to fkey, but using the function op and statement block from the old.- Parameters:
- fkeyOld- old function key of called function
- fkey- new function key of called function
 
 - 
isRecursiveFunctionpublic boolean isRecursiveFunction(String fnamespace, String fname) Indicates if the given function is either directly or indirectly recursive. An example of an indirect recursive function is foo2 in the following call chain: foo1 -> foo2 -> foo1.- Parameters:
- fnamespace- function namespace
- fname- function name
- Returns:
- true if the given function is recursive, false otherwise
 
 - 
isRecursiveFunctionpublic boolean isRecursiveFunction(String fkey) Indicates if the given function is either directly or indirectly recursive. An example of an indirect recursive function is foo2 in the following call chain: foo1 -> foo2 -> foo1.- Parameters:
- fkey- function key of calling function, null indicates the main program
- Returns:
- true if the given function is recursive, false otherwise
 
 - 
isSideEffectFreeFunctionpublic boolean isSideEffectFreeFunction(String fnamespace, String fname) Indicates if the given function is side effect free, i.e., has no prints, no persistent write, and includes no or only calls to side-effect-free functions.- Parameters:
- fnamespace- function namespace
- fname- function name
- Returns:
- true if the given function is side-effect-free, false otherwise
 
 - 
isSideEffectFreeFunctionpublic boolean isSideEffectFreeFunction(String fkey) Indicates if the given function is side effect free, i.e., has no prints, no persistent write, and includes no or only calls to side-effect-free functions.- Parameters:
- fkey- function key of calling function, null indicates the main program
- Returns:
- true if the given function is side-effect-free, false otherwise
 
 - 
getReachableFunctionspublic Set<String> getReachableFunctions() Returns all functions that are reachable either directly or indirectly form the main program, except the main program itself.- Returns:
- set of function keys (namespace and name)
 
 - 
getReachableFunctionspublic Set<String> getReachableFunctions(Set<String> excludeList) Returns all functions that are reachable either directly or indirectly form the main program, except the main program itself and the given exclude-list of function names.- Parameters:
- excludeList- list of function keys to exclude
- Returns:
- set of function keys (namespace and name)
 
 - 
isReachableFunctionpublic boolean isReachableFunction(String fnamespace, String fname) Indicates if the given function is reachable either directly or indirectly from the main program.- Parameters:
- fnamespace- function namespace
- fname- function name
- Returns:
- true if the given function is reachable, false otherwise
 
 - 
isReachableFunctionpublic boolean isReachableFunction(String fkey) Indicates if the given function is reachable either directly or indirectly from the main program.- Parameters:
- fkey- function key of calling function, null indicates the main program
- Returns:
- true if the given function is reachable, false otherwise
 
 - 
containsSecondOrderCallpublic boolean containsSecondOrderCall() Indicates if the function call graph, i.e., functions that are transitively reachable from the main program, contains a second-order builtin function call (e.g., eval, paramserv), which prohibits the removal of unused functions.- Returns:
- true if the function call graph contains a second-order builtin function call.
 
 
- 
 
-