Go to the documentation of this file. 1 package com.cliffc.aa.node;
7 import org.jetbrains.annotations.
NotNull;
9 import java.util.HashSet;
10 import java.util.concurrent.ConcurrentHashMap;
11 import java.util.function.Predicate;
54 private static final String[]
STRS =
new String[] {
null,
"Call",
"CallEpi",
"Cast",
"Con",
"ConType",
"CProj",
"DefMem",
"Err",
"Fresh",
"FP2Disp",
"Fun",
"FunPtr",
"If",
"Join",
"Load",
"Loop",
"Name",
"NewObj",
"NewAry",
"NewStr",
"Parm",
"Phi",
"Prim",
"Proj",
"Region",
"Return",
"Scope",
"Split",
"Start",
"StartMem",
"Store",
"Thret",
"Thunk",
"Type",
"Unresolved" };
59 private static int CNT=1;
62 assert
CNT < 100000 :
"infinite node create loop";
107 for(
int i=0; i<
_defs._len; i++ )
if(
_defs._es[i] !=
null ) sum ^=
_defs._es[i]._uid;
112 @Override
public boolean equals(Object o) {
113 if(
this==o )
return true;
114 if( !(o instanceof
Node) )
return false;
116 if(
_op != n.
_op )
return false;
119 for(
int i=0; i<
_defs._len; i++ )
if(
_defs._es[i] != n.
_defs._es[i] )
return false;
145 if( x ==
this ) old=
this;
147 else for(
Node o :
VALS.keySet() )
if( o._uid ==
_uid ) { old=o;
break; }
148 return (old!=
null) ==
_elock;
159 if( (
_defs._es[idx] = n) !=
null ) n.
_uses.add(
this);
169 public void del(
int idx ) {
172 if( n !=
null ) n.
_uses.del(
this);
179 if( old ==
null )
return this;
193 while(
_uses._len > 0 ) {
228 public <N extends Node> N
keep() {
return keep(1); }
229 @SuppressWarnings(
"unchecked")
233 @SuppressWarnings(
"unchecked")
253 for(
Node def : defs )
if( def !=
null ) def._uses.add(
this);
278 }
catch( CloneNotSupportedException cns ) {
throw new RuntimeException(cns); }
288 public String
dump(
int max,
boolean prims,
boolean plive ) {
return dump(0,
new SB(),max,
new VBitSet(),prims,plive).toString(); }
291 String xs = String.format(
"%s%4d: %-7.7s ",plive ?
_live :
"",
_uid,
xstr());
293 if(
is_dead() )
return sb.
p(
"DEAD");
294 for(
Node n :
_defs ) sb.
p(n ==
null ?
"____ " : String.format(
"%4d ",n._uid));
296 for(
Node n :
_uses ) sb.
p(String.format(
"%4d ",n._uid));
299 if(
_val==
null ) sb.
p(
"----");
307 dump(d,sb,plive).nl();
316 for(
Node n :
_defs )
if( n instanceof
ConNode ) n.dump(d+1,sb,max,bs,prims,plive);
319 for(
Node n :
_defs )
if( n !=
null && (!prims && n.is_prim() && n._defs._len > 3) ) bs.set(n._uid);
323 if( n !=
null && !n.is_multi_head() && !n.is_multi_tail() &&
325 n.dump(d+1,sb,max,bs,prims,plive);
329 n.dump(d+1,sb,max,bs,prims,plive);
331 for(
Node n :
_defs )
if( n !=
null && !n.is_multi_head() ) n.dump(d+1,sb,max,bs,prims,plive);
332 for(
Node n :
_defs )
if( n !=
null ) n.dump(d+1,sb,max,bs,prims,plive);
338 int dx = d+(x==
this?0:1);
343 if( dx<max) m.
dump(dx+1,sb,max,bs,prims,plive);
344 if( x==
this ) bs.clear(
_uid);
345 x.dump(dx,sb,bs,plive);
347 if( x!=
this ) bs.clear(
_uid);
351 return dump(d,sb,plive).nl();
358 public String
dumprpo(
boolean prims,
boolean plive ) {
364 for(
int i=nodes.
_len-1; i>=0; i-- ) {
374 n.
dump(0,sb,plive).nl();
381 sb.
p(
"============ ").
p(fun==
null?
"null":fun.
name()).
p(
" ============").
nl();
391 use.postorder(nodes,bs);
394 if( !(use instanceof
CallEpiNode) && use.is_CFG() )
395 use.postorder(nodes,bs);
398 use.postorder(nodes,bs);
409 use.postorder(nodes,bs);
413 p1.postorder(nodes,bs);
421 if( use.is_multi_tail() )
429 if(
_uid==uid )
return this;
432 for(
Node n :
_defs )
if( n!=
null && (m=n.
find(uid,bs)) !=
null )
return m;
433 for(
Node n :
_uses )
if( (m=n.
find(uid,bs)) !=
null )
return m;
483 if( use.live_uses() ) {
484 TypeMem ulive = use.live_use(opt_mode,
this);
523 public boolean unify(
boolean test) {
return false; }
537 public static final ConcurrentHashMap<Node,Node>
VALS =
new ConcurrentHashMap<>();
601 assert nliv.
isa(oliv);
615 assert nval.
isa(oval);
634 if( x==
null )
return null;
641 if( nnn==
null || nnn==
this ||
is_dead() )
return nnn;
663 if(
err(
true) !=
null )
697 for(
Node use :
_uses ) use.walk_initype(gvn,bs);
698 for(
Node def :
_defs )
if( def !=
null ) def.walk_initype(gvn,bs);
740 for(
Node def :
_defs )
if( def !=
null && def.more_ideal(bs) )
return true;
741 for(
Node use :
_uses )
if( use !=
null && use.more_ideal(bs) )
return true;
755 if( nval != oval || nliv != oliv || hm ) {
757 ? nval.isa(oval) && nliv.isa(oliv)
758 : oval.
isa(nval) && oliv.
isa(nliv);
761 System.err.println(
dump(0,
new SB(),
true));
765 for(
Node def :
_defs )
if( def !=
null ) errs = def.more_flow(lifting,errs);
766 for(
Node use :
_uses )
if( use !=
null ) errs = use.more_flow(lifting,errs);
773 for(
int i=0; i<
_defs._len; i++ ) {
784 if( def !=
null && def._val ==
Type.
ALL )
789 private void adderr( HashSet<ErrMsg> errs ) {
791 if( msg==
null )
return;
817 for(
Node use :
_uses ) use.walk_opt(visit);
838 public boolean is_mem() {
return false; }
841 for(
Node use :
_uses )
if( use.is_mem() )
return use;
849 if( use == memw ) found=
true;
850 else if( use.is_mem() )
return false;
864 assert
in(0) !=
null;
866 if( n !=
null )
return n;
867 return P.test(
this) ? this :
null;
910 SB sb = actual.
str(
new SB(),vb, tmem,
false).
p(
" is not a ");
912 expected.
str(sb,vb,
null,
false);
919 SB sb = actual.
str(
new SB(),vb, tmem,
false);
920 sb.
p( expecteds.length==1 ?
" is not a " :
" is none of (");
922 for(
Type expect : expecteds ) expect.str(sb,vb,
null,
false).
p(
',');
923 sb.
unchar().
p(expecteds.length==1 ?
"" :
")");
930 SB sb =
new SB().
p(msg).
p(closure ?
" val '" :
" field '.").
p(fld).
p(
"'");
931 if( to !=
null && !closure ) to.
str(sb.
p(
" in "),
new VBitSet(),
null,
false);
935 String f = fld==
null ? msg : msg+
" field '."+fld+
"'";
950 if( cmp != 0 )
return cmp;
956 @Override
public boolean equals(Object obj) {
957 if(
this==obj )
return true;
958 if( !(obj instanceof
ErrMsg) )
return false;
int compareTo(ErrMsg msg)
static final byte OP_PROJ
static void roll_back_CNT()
static final Type NO_DISP
static final byte OP_NEWARY
boolean equals(Object obj)
static final TypeMem DEAD
E push(E e)
Add element in amortized constant time.
static final byte OP_START
Node walk_dom_last(Predicate< Node > P)
TypeMem live(GVNGCM.Mode opt_mode)
Memory type; the state of all of memory; memory edges order memory ops.
public< N extends Node > N add_mono(N n)
void dump(int d, SB sb, VBitSet bs, boolean plive)
static final byte OP_LOOP
void add_flow_uses(Node n)
static final TypeMem LIVE_BOT
void add_flow_use_extra(Node chg)
static final ConcurrentHashMap< Node, Node > VALS
static final byte OP_SPLIT
Node add_work_all(Node n)
static final byte OP_FUNPTR
final boolean more_ideal(VBitSet bs)
an implementation of language AA
String dump(int max, boolean prims, boolean plive)
static final byte OP_CALLEPI
void add_flow_def_extra(Node chg)
static ErrMsg typerr(Parse loc, Type actual, Type t0mem, Type expected)
Node find(int uid, VBitSet bs)
public< N extends Node > N keep()
static final byte OP_THUNK
static final byte OP_CONTYPE
SB dump(int d, SB sb, int max, VBitSet bs, boolean prims, boolean plive)
static ErrMsg niladr(Parse loc, String msg, String fld)
static final byte OP_JOIN
static final byte OP_FRESH
static RuntimeException unimpl()
static final byte OP_THRET
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
static final byte OP_CALL
void postorder(Ary< Node > nodes, VBitSet bs)
boolean check_solo_mem_writer(Node memw)
static ErrMsg typerr(Parse loc, Type actual, Type t0mem, Type expected, Level lvl)
static String name(int fidx, boolean debug)
public< N extends Node > N unkeep()
public< N extends Node > N unhook()
static final byte OP_CAST
static final VBitSet FLOW_VISIT
static ErrMsg syntax(Parse loc, String msg)
boolean should_con(Type t)
abstract Type value(GVNGCM.Mode opt_mode)
static final byte OP_DEFMEM
String dumprpo(boolean prims, boolean plive)
void adderr(HashSet< ErrMsg > errs)
static ErrMsg forward_ref(Parse loc, String name)
boolean equals(Object loc)
static final String[] STRS
static ErrMsg trailingjunk(Parse loc)
static FunNode find_fidx(int fidx)
String errLocMsg(String s)
static final byte OP_SCOPE
static TV2 make_leaf(Node n, @NotNull String alloc_site)
static final byte OP_LOAD
static final byte OP_NEWOBJ
TypeFunPtr make_no_disp()
static ErrMsg asserterr(Parse loc, Type actual, Type t0mem, Type expected)
final void walk_initype(GVNGCM gvn, VBitSet bs)
final int more_flow(boolean lifting)
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Node insert(int idx, Node n)
Tight/tiny StringBuilder wrapper.
static final byte OP_NEWSTR
Node(byte op, Node... defs)
an implementation of language AA
static void _header(FunNode fun, SB sb)
static final byte OP_CPROJ
static final byte OP_STORE
static final VBitSet LIVE
Node copy(boolean copy_edges)
static final byte OP_PRIM
Node set_def(int idx, Node n)
static final byte OP_TYPE
ErrMsg(Parse loc, String msg, Level lvl)
public< N extends Node > N add_reduce(N n)
static void reset_to_init0()
void walkerr_def(HashSet< ErrMsg > errs, VBitSet bs)
static final byte OP_FP2DISP
void add_flow_defs(Node n)
static final byte OP_PARM
static ErrMsg unresolved(Parse loc, String msg)
boolean unify(boolean test)
public< N extends Node > N add_flow(N n)
TypeMem live_use(GVNGCM.Mode opt_mode, Node def)
int more_flow(boolean lifting, int errs)
static final byte OP_NAME
static ErrMsg forward_ref(Parse loc, FunPtrNode fun)
void replace(Node old, Node nnn)
SB dump(int d, SB sb, boolean plive)
TV2 new_tvar(String alloc_site)
static final byte OP_STMEM
static final ErrMsg BADARGS
static ErrMsg typerr(Parse loc, Type actual, Type t0mem, Type[] expecteds)
void walk_opt(VBitSet visit)
void add_flow_extra(Type old)
static final byte OP_REGION
an implementation of language AA
static ErrMsg field(Parse loc, String msg, String fld, boolean closure, TypeObj to)
Node xliv(GVNGCM.Mode opt_mode)
static ErrMsg badGC(Parse loc)