mirror of
https://github.com/irmen/prog8.git
synced 2025-02-16 22:30:46 +00:00
performance todo's
This commit is contained in:
parent
534b5ced8f
commit
a94bc40ab0
@ -54,6 +54,7 @@ interface INameScope {
|
||||
fun linkParents(parent: Node)
|
||||
|
||||
fun subScopes(): Map<String, INameScope> {
|
||||
// TODO PERFORMANCE: this is called very often and is relatively expensive. Optimize this.
|
||||
val subscopes = mutableMapOf<String, INameScope>()
|
||||
for(stmt in statements) {
|
||||
when(stmt) {
|
||||
@ -126,7 +127,7 @@ interface INameScope {
|
||||
for(module in localContext.definingModule().program.modules) {
|
||||
var scope: INameScope? = module
|
||||
for(name in scopedName.dropLast(1)) {
|
||||
scope = scope?.subScopes()?.get(name)
|
||||
scope = scope?.subScopes()?.get(name) // TODO PERFORMANCE: EXPENSIVE! (creates new map every call) OPTIMIZE.
|
||||
if(scope==null)
|
||||
break
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ class CallGraph(private val program: Program) : IAstVisitor {
|
||||
val subroutinesCalling = mutableMapOf<INameScope, List<Subroutine>>().withDefault { mutableListOf() }
|
||||
val subroutinesCalledBy = mutableMapOf<Subroutine, List<Node>>().withDefault { mutableListOf() }
|
||||
|
||||
// TODO add dataflow graph: what statements use what variables
|
||||
// TODO add dataflow graph: what statements use what variables - can be used to eliminate unused vars
|
||||
val usedSymbols = mutableSetOf<Statement>()
|
||||
|
||||
init {
|
||||
|
@ -24,7 +24,7 @@ internal class StatementOptimizer(private val program: Program,
|
||||
private set
|
||||
|
||||
private val pureBuiltinFunctions = BuiltinFunctions.filter { it.value.pure }
|
||||
private val callgraph = CallGraph(program)
|
||||
private val callgraph = CallGraph(program) // TODO PERFORMANCE: it is expensive to create this every round
|
||||
private val vardeclsToRemove = mutableListOf<VarDecl>()
|
||||
|
||||
override fun visit(program: Program) {
|
||||
@ -37,6 +37,7 @@ internal class StatementOptimizer(private val program: Program,
|
||||
}
|
||||
|
||||
private fun removeUnusedCode(callgraph: CallGraph) {
|
||||
// TODO PERFORMANCE: expensive code (because of callgraph) OPTIMIZE THIS: only run once separately ?
|
||||
// remove all subroutines that aren't called, or are empty
|
||||
val removeSubroutines = mutableSetOf<Subroutine>()
|
||||
val entrypoint = program.entrypoint()
|
||||
|
Loading…
x
Reference in New Issue
Block a user