Package org.apache.sysds.hops.ipa

## Class FunctionCallGraph

- java.lang.Object
- - org.apache.sysds.hops.ipa.FunctionCallGraph

    public class FunctionCallGraph
    extends Object

### Constructor Summary

Constructors
`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 Summary

All Methods Instance Methods Concrete Methods
`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.
`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.
`boolean` `isReachableFunction​(String fkey)` Indicates if the given function is reachable either directly or indirectly from the main program.
`boolean` `isReachableFunction​(String fnamespace, String fname)` Indicates if the given function is reachable either directly or indirectly from the main program.
`boolean` `isRecursiveFunction​(String fkey)` Indicates if the given function is either directly or indirectly recursive.
`boolean` `isRecursiveFunction​(String fnamespace, String fname)` Indicates if the given function is either directly or indirectly recursive.
`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.
`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.
`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.
`void` `removeFunctionCalls​(String fkey)` Removes all calls of the given function.
`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.

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### FunctionCallGraph

    public FunctionCallGraph​(DMLProgram prog)

Constructs the function call graph for all functions reachable from the main program.

Parameters:
  `prog` - dml program of given script

#### FunctionCallGraph

    public 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

#### getCalledFunctions

    public 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)

#### getCalledFunctions

    public 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)

#### getFunctionCalls

    public 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

#### getFunctionCallsSB

    public 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

#### removeFunctionCalls

    public 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

#### removeFunctionCall

    public 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

#### replaceFunctionCalls

    public 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

#### isRecursiveFunction

    public 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

#### isRecursiveFunction

    public 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

#### isSideEffectFreeFunction

    public 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

#### isSideEffectFreeFunction

    public 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

#### getReachableFunctions

    public 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)

#### getReachableFunctions

    public 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)

#### isReachableFunction

    public 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

#### isReachableFunction

    public 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

#### containsSecondOrderCall

    public 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.