aa
ProjNode.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.Type;
7 import com.cliffc.aa.type.TypeMem;
8 import com.cliffc.aa.type.TypeTuple;
9 
10 // Proj data
11 public class ProjNode extends Node {
12  public int _idx;
13  public ProjNode( Node head, int idx ) { this(OP_PROJ,head,idx); }
14  public ProjNode( int idx, Node... ns ) { super(OP_PROJ,ns); _idx=idx; }
15  ProjNode( byte op, Node ifn, int idx ) { super(op,ifn); _idx=idx; }
16  @Override public String xstr() { return "DProj"+_idx; }
17 
18  // Strictly reducing
19  @Override public Node ideal_reduce() {
20  Node c = in(0).is_copy(_idx);
21  if( c != null ) return c==this ? Env.ANY : c; // Happens in dying loops
22  return null;
23  }
24  @Override public Type value(GVNGCM.Mode opt_mode) {
25  Type c = val(0);
26  if( c instanceof TypeTuple ) {
27  TypeTuple ct = (TypeTuple)c;
28  if( _idx < ct._ts.length )
29  return ct._ts[_idx];
30  }
31  return c.oob();
32  }
33  // Only called here if alive, and input is more-than-basic-alive
34  @Override public TypeMem live_use(GVNGCM.Mode opt_mode, Node def ) {
35  return def.all_live().basic_live() ? TypeMem.ALIVE : TypeMem.ANYMEM;
36  }
37 
38  // Unify with the parent TVar sub-part
39  @Override public boolean unify( boolean test ) {
40  if( in(0) instanceof NewNode ) { // TODO: Not really a proper use of Proj
41  NewNode nnn = (NewNode)in(0);
42  TV2 tv = tvar();
43  if( tv.is_base() && tv._type==nnn._tptr ) return false; // No progress
44  return tv.unify(TV2.make("Ptr",this,"DProj_NewNode",nnn),test);
45  }
46  TV2 tv0 = tvar(0);
47  return tv0._args!=null && tv0.unify_at(_idx,tvar(),test);
48  }
49 
50  public static ProjNode proj( Node head, int idx ) {
51  for( Node use : head._uses )
52  if( use instanceof ProjNode && ((ProjNode)use)._idx==idx )
53  return (ProjNode)use;
54  return null;
55  }
56 
57  void set_idx( int idx ) { unelock(); _idx=idx; } // Unlock before changing hash
58  @Override public int hashCode() { return super.hashCode()+_idx; }
59  @Override public boolean equals(Object o) {
60  if( this==o ) return true;
61  if( !super.equals(o) ) return false;
62  if( !(o instanceof ProjNode) ) return false;
63  ProjNode proj = (ProjNode)o;
64  return _idx==proj._idx;
65  }
66  @Override public byte op_prec() { return in(0).op_prec(); }
67 }
com.cliffc.aa.tvar.TV2._args
NonBlockingHashMap< Comparable, TV2 > _args
Definition: TV2.java:42
com.cliffc.aa.node.Node.OP_PROJ
static final byte OP_PROJ
Definition: Node.java:40
com.cliffc.aa.tvar.TV2.unify_at
boolean unify_at(Comparable key, TV2 tv2, boolean test)
Definition: TV2.java:105
com.cliffc.aa.tvar.TV2.unify
boolean unify(TV2 that, boolean test)
Definition: TV2.java:288
com.cliffc.aa.type.TypeMem
Memory type; the state of all of memory; memory edges order memory ops.
Definition: TypeMem.java:53
com.cliffc
com.cliffc.aa.node.Node
Definition: Node.java:16
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.ProjNode.ProjNode
ProjNode(Node head, int idx)
Definition: ProjNode.java:13
com.cliffc.aa.type.TypeTuple
Definition: TypeTuple.java:11
com.cliffc.aa.node.Node.unelock
void unelock()
Definition: Node.java:128
com.cliffc.aa.type.TypeMem.ANYMEM
static final TypeMem ANYMEM
Definition: TypeMem.java:228
com.cliffc.aa.tvar.TV2._type
Type _type
Definition: TV2.java:49
com.cliffc.aa.node.ProjNode.op_prec
byte op_prec()
Definition: ProjNode.java:66
com.cliffc.aa.node.ProjNode.hashCode
int hashCode()
Definition: ProjNode.java:58
com.cliffc.aa.tvar.TV2.make
static TV2 make(@NotNull String name, Node n, @NotNull String alloc_site)
Definition: TV2.java:154
com.cliffc.aa.node.NewNode._tptr
TypeMemPtr _tptr
Definition: NewNode.java:34
com.cliffc.aa.node.ProjNode.unify
boolean unify(boolean test)
Definition: ProjNode.java:39
com.cliffc.aa.node.ProjNode._idx
int _idx
Definition: ProjNode.java:12
com.cliffc.aa.node.ProjNode.proj
static ProjNode proj(Node head, int idx)
Definition: ProjNode.java:50
com.cliffc.aa.node.Node.is_copy
Node is_copy(int idx)
Definition: Node.java:827
com.cliffc.aa.type.TypeMem.basic_live
boolean basic_live()
Definition: TypeMem.java:561
com.cliffc.aa.node.ProjNode.equals
boolean equals(Object o)
Definition: ProjNode.java:59
com.cliffc.aa.node.ProjNode.xstr
String xstr()
Definition: ProjNode.java:16
com.cliffc.aa.node.Node.in
Node in(int i)
Definition: Node.java:126
com.cliffc.aa.node.ProjNode.ProjNode
ProjNode(int idx, Node... ns)
Definition: ProjNode.java:14
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.tvar.TV2.is_base
boolean is_base()
Definition: TV2.java:79
com.cliffc.aa.node.ProjNode.set_idx
void set_idx(int idx)
Definition: ProjNode.java:57
com.cliffc.aa.node.ProjNode
Definition: ProjNode.java:11
com.cliffc.aa.node.ProjNode.ProjNode
ProjNode(byte op, Node ifn, int idx)
Definition: ProjNode.java:15
com.cliffc.aa.node.Node._uses
Ary< Node > _uses
Definition: Node.java:245
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.Node.all_live
TypeMem all_live()
Definition: Node.java:509
com.cliffc.aa.node.NewNode
Definition: NewNode.java:17
com.cliffc.aa.node.ProjNode.live_use
TypeMem live_use(GVNGCM.Mode opt_mode, Node def)
Definition: ProjNode.java:34
com.cliffc.aa.tvar.TV2
Definition: TV2.java:23
com.cliffc.aa.type.Type.oob
Type oob()
Definition: Type.java:635
com.cliffc.aa.node.ProjNode.value
Type value(GVNGCM.Mode opt_mode)
Definition: ProjNode.java:24
com.cliffc.aa.type.TypeTuple._ts
Type[] _ts
Definition: TypeTuple.java:13
com.cliffc.aa.node.Node.tvar
TV2 tvar()
Definition: Node.java:96
com.cliffc.aa.Env.ANY
static ConNode ANY
Definition: Env.java:24
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.GVNGCM.Mode
Definition: GVNGCM.java:14
com.cliffc.aa.node.ProjNode.ideal_reduce
Node ideal_reduce()
Definition: ProjNode.java:19