summaryrefslogtreecommitdiff
path: root/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java
blob: 740b08954004eb9ee83e52898530c6c397253e66 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package com.seaofnodes.simple.node;

import com.seaofnodes.print.ExprPrinter;
import com.seaofnodes.simple.codegen.CodeGen;
import com.seaofnodes.simple.type.*;

// Escapes from calls and unloaded bodies, shared by all compilation units.
// These include paths which never Return. Iter creates this after parsing;
// the outer Start holds it until Unlink. Saved objects contain the resulting
// StopCU types instead. Dependencies wake this node when contributors change;
// Stops need waking only when the combined result changes.
public class GlobalEscapeNode extends Node {
    public GlobalEscapeNode() { super(new Node[0]); _type = TypeMem.BOT; }
    @Override public String label() { return "GlobalEscape"; }
    @Override protected ExprPrinter<Node> _print1(ExprPrinter<Node> p) { return p.p(label()); }
    @Override public Node idealize() { return null; }

    @Override public TypeMem compute() {
        TypeMem xmem = TypeMem.START;
        for( CallNode call : CodeGen.CODE._calls )
            if( !call.isDead() ) {
                xmem = xmem.escapes(call.exposed(this));
            }
        for( FunNode fun : CodeGen.CODE._linker )
            if( fun!=null && fun.summary()!=null && !fun.summary().isDead() ) {
                xmem = xmem.escapes(fun.summary().exposed(this));
                // A reachable unloaded body can call these targets, including
                // private initializers. Its arguments are unavailable here.
                if( fun._type==Type.CONTROL )
                    for( int fidx : fun.summary()._classDependencyFIDXs )
                        if( fidx!=0 ) xmem = xmem.makeFrom(XInt.meet(xmem._escFs,XInt.make(fidx)),xmem._escAs);
            }
        return xmem;
    }
}