aa
FreshNode.java
Go to the documentation of this file.
1 package com.cliffc.aa.node;
2 
3 import com.cliffc.aa.Env;
4 import com.cliffc.aa.GVNGCM;
5 import com.cliffc.aa.tvar.TV2;
6 import com.cliffc.aa.type.*;
7 
8 import java.util.Arrays;
9 
10 // "fresh" the incoming TVar: make a fresh instance.
11 public class FreshNode extends UnOrFunPtrNode {
13  public FreshNode( Env.VStack vs, Node ctrl, Node ld ) { super(OP_FRESH, ctrl, ld); _tv2s = vs.compact(); }
14 
15  Node id() { return in(1); }
16  @Override public Node ideal_reduce() {
17  if( id()==this ) return null; // Dead self-cycle
18  // Remove Fresh of base type values: things that can never have structure.
19  if( no_tvar_structure(_val) )
20  return id();
21  // Remove if TVar has already unified with the input.
22  // TODO: TURN BACK ON. Removes many FreshNodes but requires non-local info to put on worklist.
23  // i.e. a remote unification can suddenly enable this.
24  //if( !tvar().unify(id().tvar(),true) )
25  // return id();
26 
27  // Unwind ctrl-copy
28  Node cc = in(0).is_copy(0);
29  if( cc!=null ) return set_def(0,cc);
30 
31  return null;
32  }
33 
34  @Override public Type value(GVNGCM.Mode opt_mode) { return val(1); }
35  @Override public void add_flow_extra(Type old) {
36  // Types changed, now might collapse
38  Env.GVN.add_reduce(this);
39  }
40 
41  @Override public TypeMem all_live() { return TypeMem.LIVE_BOT; }
42 
43  @Override public TypeMem live_use(GVNGCM.Mode opt_mode, Node def ) {
44  if( def==id() ) return _live; // Pass full liveness along
45  return TypeMem.ALIVE; // Basic aliveness for control
46  }
47 
48  // Things that can never have type-variable internal structure.
49  private static boolean no_tvar_structure(Type t) {
50  return t.isa(TypeInt.INT64) || t.isa(TypeFlt.FLT64) || t.isa(TypeMemPtr.ISUSED0);
51  }
52 
53  @Override public boolean unify( boolean test ) { return tvar(1).fresh_unify(tvar(),_tv2s,test); }
54 
55  @Override public byte op_prec() { return id().op_prec(); }
56  @Override Node is_pure_call() { return id().is_pure_call(); }
57 
58  @Override public UnresolvedNode unk() { return id() instanceof UnresolvedNode ? (UnresolvedNode)id() : null; }
59  @Override int nargs() { return ((UnOrFunPtrNode)id()).nargs(); }
60  @Override public UnOrFunPtrNode filter(int nargs) { return ((UnOrFunPtrNode)id()).filter(nargs); }
61  @Override public FunPtrNode funptr() {
62  return id() instanceof UnOrFunPtrNode ? ((UnOrFunPtrNode)id()).funptr() : null;
63  }
64 
65  @Override public int hashCode() { return super.hashCode()+Arrays.hashCode(_tv2s); }
66  @Override public boolean equals(Object o) {
67  if( this==o ) return true;
68  if( !super.equals(o) ) return false;
69  return (o instanceof FreshNode) && Arrays.equals(_tv2s,((FreshNode)o)._tv2s);
70  }
71 
72 }
com.cliffc.aa.node.FreshNode.all_live
TypeMem all_live()
Definition: FreshNode.java:41
com.cliffc.aa.type.Type.isa
boolean isa(Type t)
Definition: Type.java:623
com.cliffc.aa.type.TypeMem
Memory type; the state of all of memory; memory edges order memory ops.
Definition: TypeMem.java:53
com.cliffc.aa.node.FreshNode.add_flow_extra
void add_flow_extra(Type old)
Definition: FreshNode.java:35
com.cliffc.aa.node.Node._live
TypeMem _live
Definition: Node.java:89
com.cliffc
com.cliffc.aa.node.FreshNode.op_prec
byte op_prec()
Definition: FreshNode.java:55
com.cliffc.aa.type.TypeMem.LIVE_BOT
static final TypeMem LIVE_BOT
Definition: TypeMem.java:226
com.cliffc.aa.node.Node
Definition: Node.java:16
com.cliffc.aa.type.TypeInt
Definition: TypeInt.java:9
com.cliffc.aa.node.UnOrFunPtrNode
Definition: UnOrFunPtrNode.java:6
com.cliffc.aa.tvar
Definition: TV2.java:1
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.node.FreshNode.no_tvar_structure
static boolean no_tvar_structure(Type t)
Definition: FreshNode.java:49
com.cliffc.aa.type.TypeFlt
Definition: TypeFlt.java:9
Arrays
com.cliffc.aa.node.Node.is_pure_call
Node is_pure_call()
Definition: Node.java:834
com.cliffc.aa.node.FreshNode.unk
UnresolvedNode unk()
Definition: FreshNode.java:58
com.cliffc.aa.node.Node._val
Type _val
Definition: Node.java:88
com.cliffc.aa.node.Node.OP_FRESH
static final byte OP_FRESH
Definition: Node.java:25
com.cliffc.aa.node.FunPtrNode
Definition: FunPtrNode.java:40
com.cliffc.aa.node.FreshNode.hashCode
int hashCode()
Definition: FreshNode.java:65
com.cliffc.aa.node.FreshNode._tv2s
TV2[] _tv2s
Definition: FreshNode.java:12
com.cliffc.aa.node.FreshNode.FreshNode
FreshNode(Env.VStack vs, Node ctrl, Node ld)
Definition: FreshNode.java:13
com.cliffc.aa.Env.GVN
static final GVNGCM GVN
Definition: Env.java:13
com.cliffc.aa.type.TypeInt.INT64
static final TypeInt INT64
Definition: TypeInt.java:39
com.cliffc.aa.node.UnOrFunPtrNode.UnOrFunPtrNode
UnOrFunPtrNode(byte op, Node... funs)
Definition: UnOrFunPtrNode.java:7
com.cliffc.aa.node.FreshNode.filter
UnOrFunPtrNode filter(int nargs)
Definition: FreshNode.java:60
com.cliffc.aa.node.Node.is_copy
Node is_copy(int idx)
Definition: Node.java:827
com.cliffc.aa.node.Node.in
Node in(int i)
Definition: Node.java:126
com.cliffc.aa.type.TypeMem.ALIVE
static final TypeMem ALIVE
Definition: TypeMem.java:226
com.cliffc.aa.GVNGCM
Definition: GVNGCM.java:12
com.cliffc.aa.node.FreshNode.funptr
FunPtrNode funptr()
Definition: FreshNode.java:61
com.cliffc.aa.node.FreshNode
Definition: FreshNode.java:11
com.cliffc.aa.node.UnOrFunPtrNode.filter
abstract UnOrFunPtrNode filter(int nargs)
com.cliffc.aa.node.FreshNode.equals
boolean equals(Object o)
Definition: FreshNode.java:66
com.cliffc.aa.Env.VStack
Definition: Env.java:256
com.cliffc.aa.node.Node.val
Type val(int idx)
Definition: Node.java:470
com.cliffc.aa
Definition: AA.java:1
com.cliffc.aa.node.UnresolvedNode
Definition: UnresolvedNode.java:13
com.cliffc.aa.node.FreshNode.id
Node id()
Definition: FreshNode.java:15
com.cliffc.aa.node.Node.set_def
Node set_def(int idx, Node n)
Definition: Node.java:154
com.cliffc.aa.GVNGCM.add_reduce
public< N extends Node > N add_reduce(N n)
Definition: GVNGCM.java:49
com.cliffc.aa.node.FreshNode.nargs
int nargs()
Definition: FreshNode.java:59
com.cliffc.aa.node.FreshNode.unify
boolean unify(boolean test)
Definition: FreshNode.java:53
com.cliffc.aa.node.FreshNode.live_use
TypeMem live_use(GVNGCM.Mode opt_mode, Node def)
Definition: FreshNode.java:43
com.cliffc.aa.tvar.TV2
Definition: TV2.java:23
com.cliffc.aa.node.FreshNode.value
Type value(GVNGCM.Mode opt_mode)
Definition: FreshNode.java:34
com.cliffc.aa.node.FreshNode.is_pure_call
Node is_pure_call()
Definition: FreshNode.java:56
com.cliffc.aa.node.FreshNode.ideal_reduce
Node ideal_reduce()
Definition: FreshNode.java:16
com.cliffc.aa.tvar.TV2.fresh_unify
boolean fresh_unify(TV2 that, TV2[] vs, boolean test)
Definition: TV2.java:374
com.cliffc.aa.node.Node.tvar
TV2 tvar()
Definition: Node.java:96
com
com.cliffc.aa.node.Node.op_prec
byte op_prec()
Definition: Node.java:533
com.cliffc.aa.Env
Definition: Env.java:12
com.cliffc.aa.type
Definition: Bits.java:1
com.cliffc.aa.type.TypeMemPtr
Definition: TypeMemPtr.java:14
com.cliffc.aa.type.TypeFlt.FLT64
static final TypeFlt FLT64
Definition: TypeFlt.java:38
com.cliffc.aa.GVNGCM.Mode
Definition: GVNGCM.java:14
com.cliffc.aa.type.TypeMemPtr.ISUSED0
static final TypeMemPtr ISUSED0
Definition: TypeMemPtr.java:91