aa
TypeLive.java
Go to the documentation of this file.
1 package com.cliffc.aa.type;
2 
3 import com.cliffc.aa.util.SB;
4 import com.cliffc.aa.util.VBitSet;
5 
6 import java.util.function.Predicate;
7 
8 // Backwards liveness, used to gather forward use types in a reverse flow.
9 
10 // Liveness is passed in TypeMems, because we support precise memory liveness.
11 // - TypeMem.DEAD - Value is dead
12 // - TypeMem.ALIVE - Value is simple, and fully alive
13 // - TypeMem.ESCAPE - Value is simple, and fully alive, and "escapes" into memory or a call argument
14 // - TypeMem[#alias]- Value is complex memory, and partially alive based on alias# and fields.
15 // - TypeMem[#alias]._fld = Type.XSCALAR - This field is dead
16 // - TypeMem[#alias]._fld = Type. SCALAR - This field is fully alive
17 // - TypeMem[#alias]._fld = Type.NSCALR - This field is partially alive: any display is dead, but all else is alive
18 
19 public class TypeLive extends TypeObj<TypeLive> {
20  int _flags;
21  private TypeLive init(boolean any, int flags ) {
22  super.init(TLIVE,"",any,any);
23  _flags = flags;
24  return this;
25  }
26  @Override int compute_hash() { return super.compute_hash() + _flags; }
27  @Override public boolean equals( Object o ) {
28  if( this==o ) return true;
29  if( !(o instanceof TypeLive) || !super.equals(o) ) return false;
30  return _flags==((TypeLive)o)._flags;
31  }
32  @Override public boolean cycle_equals( Type o ) { return equals(o); }
33  @Override public SB str( SB sb, VBitSet dups, TypeMem mem, boolean debug ) {
34  if( this==DEAD ) return sb.p("DEAD");
35  if( _any ) sb.p('~');
36  return sb.p(STRS[_flags]);
37  }
38 
39  static { new Pool(TLIVE,new TypeLive()); }
40  private static TypeLive make( boolean any, int flags ) {
41  TypeLive t1 = POOLS[TLIVE].malloc();
42  return t1.init(any,flags).hashcons_free();
43  }
44 
45  // Value is used as a call-argument, value-stored (address use is ok),
46  // returned, merged at a phi, folded into a funptr, etc.
47  private static final int FLAG_ESCAPE=1;
48  public boolean is_escape() { return (_flags&FLAG_ESCAPE)!=0; }
49  // Keeps all values alive
50  private static final int FLAG_WITH_DISP=2;
51  public boolean is_ret() { return (_flags&FLAG_WITH_DISP)!=0; }
52 
53  static final TypeLive NO_DISP= make(false,0 ); // no escape, no disp
54  static final TypeLive ESC_DISP=make(false,FLAG_ESCAPE); // escape, no disp
55  static final TypeLive LIVE = make(false,FLAG_WITH_DISP); // Basic alive
56  static final TypeLive ESCAPE = make(false,FLAG_ESCAPE+FLAG_WITH_DISP); // Used as a call argument
57 
58  public static final TypeLive LIVE_BOT=make(false,FLAG_ESCAPE+FLAG_WITH_DISP);
59  public static final TypeLive DEAD = LIVE_BOT.dual();
60 
61  @Override protected TypeLive xdual() { return new TypeLive().init(!_any,_flags); }
62  @Override protected Type xmeet( Type t ) {
63  switch( t._type ) {
64  case TLIVE: break;
65  case TARY:
66  case TSTR:
67  case TSTRUCT:return OBJ;
68  case TOBJ: return t.xmeet(this);
69  case TFUNSIG:
70  case TTUPLE:
71  case TFUNPTR:
72  case TMEMPTR:
73  case TFLT:
74  case TINT:
75  case TRPC:
76  case TMEM: return ALL;
77  default: throw typerr(t);
78  }
79  TypeLive ts = (TypeLive)t;
80  boolean any = _any&ts._any;
81  int f0 = _any ? 0 : _flags;
82  int f1 = ts._any ? 0 : ts._flags;
83  int flags = any ? (_flags&ts._flags) : (f0|f1);
84  return make(any,flags);
85  }
86  private static final TypeLive[] LIVES = new TypeLive[]{NO_DISP,ESC_DISP,LIVE,ESCAPE};
87  private static final String[] STRS = new String[]{"!dsp","esc!dsp","live","escp"};
88  public TypeLive lmeet( TypeLive lv ) {
89  if( this.above_center() ) return lv.above_center() ? (TypeLive)xmeet(lv) : lv;
90  if( lv .above_center() ) return this;
91  return LIVES[_flags|lv._flags];
92  }
93  // Widen (loss info), to make it suitable as the default function memory.
94  @Override public TypeObj crush() { return this; }
95 
96  @Override public boolean may_be_con() { return false; }
97  @Override public boolean is_con() { return false; }
98  @Override public Type meet_nil(Type t) { return this; }
99  @Override public void walk( Predicate<Type> p ) { p.test(this); }
100 }
com.cliffc.aa.type.TypeLive.lmeet
TypeLive lmeet(TypeLive lv)
Definition: TypeLive.java:88
com.cliffc.aa.type.TypeObj< TypeLive >::above_center
boolean above_center()
Definition: TypeObj.java:77
com.cliffc.aa.type.TypeLive.may_be_con
boolean may_be_con()
Definition: TypeLive.java:96
com.cliffc.aa.type.TypeLive.str
SB str(SB sb, VBitSet dups, TypeMem mem, boolean debug)
Definition: TypeLive.java:33
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.type.TypeObj< TypeLive >::_any
boolean _any
Definition: TypeObj.java:16
com.cliffc
com.cliffc.aa.util
Definition: AbstractEntry.java:1
com.cliffc.aa.type.TypeLive.FLAG_WITH_DISP
static final int FLAG_WITH_DISP
Definition: TypeLive.java:50
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.type.TypeLive.xmeet
Type xmeet(Type t)
Definition: TypeLive.java:62
com.cliffc.aa.type.TypeLive.LIVE_BOT
static final TypeLive LIVE_BOT
Definition: TypeLive.java:58
com.cliffc.aa.type.Type._type
byte _type
Definition: Type.java:98
com.cliffc.aa.type.TypeLive.xdual
TypeLive xdual()
Definition: TypeLive.java:61
com.cliffc.aa.type.TypeLive.is_escape
boolean is_escape()
Definition: TypeLive.java:48
com.cliffc.aa.type.TypeLive.DEAD
static final TypeLive DEAD
Definition: TypeLive.java:59
com.cliffc.aa.type.TypeLive.is_con
boolean is_con()
Definition: TypeLive.java:97
com.cliffc.aa.type.TypeLive.cycle_equals
boolean cycle_equals(Type o)
Definition: TypeLive.java:32
com.cliffc.aa.type.TypeLive.init
TypeLive init(boolean any, int flags)
Definition: TypeLive.java:21
com.cliffc.aa.type.TypeObj< TypeLive >::OBJ
static final TypeObj OBJ
Definition: TypeObj.java:44
com.cliffc.aa.type.TypeObj
Definition: TypeObj.java:15
com.cliffc.aa.type.TypeLive.meet_nil
Type meet_nil(Type t)
Definition: TypeLive.java:98
com.cliffc.aa.type.TypeLive.NO_DISP
static final TypeLive NO_DISP
Definition: TypeLive.java:53
com.cliffc.aa.type.Type.xmeet
Type xmeet(Type t)
Definition: Type.java:461
com.cliffc.aa.type.TypeLive.ESCAPE
static final TypeLive ESCAPE
Definition: TypeLive.java:56
com.cliffc.aa.type.TypeLive.LIVE
static final TypeLive LIVE
Definition: TypeLive.java:55
com.cliffc.aa.util.VBitSet
Definition: VBitSet.java:5
com.cliffc.aa.type.TypeLive.make
static TypeLive make(boolean any, int flags)
Definition: TypeLive.java:40
com.cliffc.aa.util.SB
Tight/tiny StringBuilder wrapper.
Definition: SB.java:8
com.cliffc.aa.type.TypeLive.crush
TypeObj crush()
Definition: TypeLive.java:94
com.cliffc.aa
Definition: AA.java:1
com.cliffc.aa.type.TypeLive
Definition: TypeLive.java:19
com.cliffc.aa.type.TypeLive.is_ret
boolean is_ret()
Definition: TypeLive.java:51
com.cliffc.aa.util.SB.p
SB p(String s)
Definition: SB.java:13
com.cliffc.aa.type.TypeLive.ESC_DISP
static final TypeLive ESC_DISP
Definition: TypeLive.java:54
com.cliffc.aa.type.TypeLive._flags
int _flags
Definition: TypeLive.java:20
com.cliffc.aa.type.TypeLive.STRS
static final String[] STRS
Definition: TypeLive.java:87
com.cliffc.aa.type.TypeLive.walk
void walk(Predicate< Type > p)
Definition: TypeLive.java:99
com.cliffc.aa.type.TypeLive.LIVES
static final TypeLive[] LIVES
Definition: TypeLive.java:86
com.cliffc.aa.type.TypeLive.FLAG_ESCAPE
static final int FLAG_ESCAPE
Definition: TypeLive.java:47
com.cliffc.aa.type.TypeLive.compute_hash
int compute_hash()
Definition: TypeLive.java:26
com
com.cliffc.aa.type.TypeLive.equals
boolean equals(Object o)
Definition: TypeLive.java:27