aa
ParmNode.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.Parse;
6 import com.cliffc.aa.type.Type;
7 
8 import static com.cliffc.aa.AA.ARG_IDX;
9 import static com.cliffc.aa.AA.MEM_IDX;
10 
11 // Function parameter node; almost just a Phi with a name. There is a dense
12 // numbering matching function arguments, with -1 reserved for the RPC and 0
13 // for memory.
14 public class ParmNode extends PhiNode {
15  public final int _idx; // Parameter index, MEM_IDX, FUN_IDX is display, ARGIDX+ normal args
16  final String _name; // Parameter name
17  public ParmNode( int idx, String name, Node fun, ConNode defalt, Parse badgc) {
18  this(idx,name,fun,defalt._t,defalt,badgc);
19  }
20  public ParmNode( int idx, String name, Node fun, Type tdef, Node defalt, Parse badgc) {
21  super(OP_PARM,fun,tdef,defalt,badgc);
22  assert idx>=0;
23  _idx=idx;
24  _name=name;
25  }
26  FunNode fun() { return (FunNode) in(0); }
27  @Override public String xstr() { return "Parm:"+_name; }
28  @Override public int hashCode() { return super.hashCode()+_idx; }
29  @Override public boolean equals(Object o) {
30  if( this==o ) return true;
31  if( !super.equals(o) ) return false;
32  if( !(o instanceof ParmNode) ) return false;
33  ParmNode parm = (ParmNode)o;
34  return _idx==parm._idx;
35  }
36 
37  @Override public Node ideal_reduce() {
38  if( !(in(0) instanceof FunNode) )
39  return in(0).is_copy(_idx); // Dying, or thunks
40  FunNode fun = fun();
41  if( fun._val == Type.XCTRL ) return null; // All dead, c-prop will fold up
42  assert fun._defs._len==_defs._len;
43  if( fun.in(0)!=null && in(1) != this) // FunNode is a Copy
44  return in(1); // So return the copy
45  // Do not otherwise fold away, as this lets Nodes in *this* function depend
46  // on values in some other function... which, if code-split, gets confused
47  // (would have to re-insert the Parm).
48  return null;
49  }
50 
51  private boolean valid_args( FunNode fun, int i, Node mem ) {
52  if( fun._thunk_rhs ) return true; // Always allow folding of Thunks
53  // Check arg type, after sharpening
54  Type actual = mem==null ? val(i) : in(i).sharptr(mem.in(i));
55  Type formal = fun.formal(_idx);
56  return actual.isa(formal);
57  }
58 
59  @Override public Type value(GVNGCM.Mode opt_mode) {
60  // Not executing?
61  Type ctl = val(0);
62  if( ctl != Type.CTRL ) return ctl.oob();
63  Node in0 = in(0);
64  if( in0 instanceof ThunkNode ) return val(1);
65  if( !(in0 instanceof FunNode) ) return ctl.oob();
66  // If unknown callers, then always the default value because some unknown
67  // caller can be that bad. During & after GCP all unknown callers are
68  // accounted for.
69  FunNode fun = (FunNode)in0;
70  if( !opt_mode._CG && fun.has_unknown_callers() )
71  return val(1);
72  Node mem = fun.parm(MEM_IDX);
73  // All callers known; merge the wired & flowing ones
74  Type t = Type.ANY;
75  for( int i=1; i<_defs._len; i++ ) {
76  if( fun.val(i)==Type.XCTRL || fun.val(i)==Type.ANY ) continue; // Only meet alive paths
77  // Check arg type, after sharpening
78  Type ta = mem == null ? val(i) : in(i).sharptr(mem.in(i));
79  t = t.meet(ta);
80  }
81 
82  if( _idx <= 0 ) return t;
83  if( fun.in(0)==fun ) return t.simple_ptr(); // Function is collapsing, memory not available to check formals
84  // High, but valid, values like choice-functions need to pass thru,
85  // so following Calls agree that SOME function will be called.
86  // Check against formals; if OOB, always produce an error.
87  Type formal = fun.formal(_idx);
88  // Good case:
89  if( t.isa(formal) ) return t.simple_ptr();
90  return Type.ALL;
91  }
92 
93  // If an input to a Mem Parm changes, the flow results of other Parms can change
94  @Override public void add_flow_use_extra(Node chg) {
95  if( is_mem() )
96  for( Node parm : in(0)._uses )
97  if( parm instanceof ParmNode && parm != this )
98  Env.GVN.add_flow(parm);
99  }
100 
101  //@Override public TV2 new_tvar(String alloc_site) {
102  // if( _name==null ) return null; // Wait till initialized
103  // return _idx==MEM_IDX ? TV2.make_mem(this,alloc_site) : TV2.make_leaf(this,alloc_site);
104  //}
105  //
109  //@Override public boolean unify( boolean test ) { return false; }
110 
111  @Override public ErrMsg err( boolean fast ) {
112  if( !(in(0) instanceof FunNode) ) return null; // Dead, report elsewhere
113  FunNode fun = fun();
114  if( fun.in(0)== fun ) return null; // Dead, being inlined
115  assert fun._defs._len==_defs._len;
116  if( _idx <= MEM_IDX ) return null; // No arg check on RPC or memory
117  Node mem = fun.parm(MEM_IDX);
118  Type formal = fun.formal(_idx);
119  for( int i=1; i<_defs._len; i++ ) {
120  if( fun.val(i)==Type.XCTRL ) continue;// Ignore dead paths
121  Type argt = mem == null ? in(i)._val : in(i).sharptr(mem.in(i)); // Arg type for this incoming path
122  if( argt!=Type.ALL && !argt.isa(formal) ) { // Argument is legal? ALL args are in-error elsewhere
123  // The merge of all incoming calls for this argument is not legal.
124  // Find the call bringing the broken args, and use it for error
125  // reporting - it MUST exist, or we have a really weird situation
126  for( Node def : fun._defs ) {
127  if( def instanceof CProjNode ) {
128  CallNode call = (CallNode)def.in(0);
129  if( call.nargs() != fun.nargs() )
130  return null; // #args errors reported before bad-args
131  Type argc = call.arg(_idx).sharptr(call.mem()); // Call arg type
132  if( argc!=Type.ALL && !argc.isa(formal) ) // Check this call
133  return fast ? ErrMsg.FAST : ErrMsg.typerr(call._badargs[_idx-ARG_IDX+1],argc, call.mem()._val,formal);
134  // Must be a different call that is in-error
135  }
136  }
137  // meet of args is not the formal, but no single arg is not the formal?
138  return fast ? ErrMsg.FAST : ErrMsg.typerr(_badgc,argt,mem.val(i),formal); // Can be the default
139  }
140  }
141  return null;
142  }
143 }
com.cliffc.aa.node.ParmNode.xstr
String xstr()
Definition: ParmNode.java:27
com.cliffc.aa.node.ParmNode.ParmNode
ParmNode(int idx, String name, Node fun, ConNode defalt, Parse badgc)
Definition: ParmNode.java:17
com.cliffc.aa.type.Type.isa
boolean isa(Type t)
Definition: Type.java:623
com.cliffc.aa.node.CallNode.mem
Node mem()
Definition: CallNode.java:119
com.cliffc
com.cliffc.aa.node.Node
Definition: Node.java:16
com.cliffc.aa.node.FunNode.has_unknown_callers
boolean has_unknown_callers()
Definition: FunNode.java:185
com.cliffc.aa.node.PhiNode._badgc
final Parse _badgc
Definition: PhiNode.java:10
com.cliffc.aa.type.Type
an implementation of language AA
Definition: Type.java:94
com.cliffc.aa.node.PhiNode
Definition: PhiNode.java:9
com.cliffc.aa.AA.MEM_IDX
static final int MEM_IDX
Definition: AA.java:14
com.cliffc.aa.node.CProjNode
Definition: CProjNode.java:10
com.cliffc.aa.node.ConNode._t
T _t
Definition: ConNode.java:10
com.cliffc.aa.node.Node.ErrMsg.typerr
static ErrMsg typerr(Parse loc, Type actual, Type t0mem, Type expected)
Definition: Node.java:906
com.cliffc.aa.node.ParmNode.valid_args
boolean valid_args(FunNode fun, int i, Node mem)
Definition: ParmNode.java:51
com.cliffc.aa.AA.ARG_IDX
static final int ARG_IDX
Definition: AA.java:17
com.cliffc.aa.node.Node._val
Type _val
Definition: Node.java:88
com.cliffc.aa.type.Type.ANY
static final Type ANY
Definition: Type.java:325
com.cliffc.aa.node.Node.ErrMsg
Definition: Node.java:888
com.cliffc.aa.node.ConNode
Definition: ConNode.java:9
com.cliffc.aa.type.Type.meet
final Type meet(Type t)
Definition: Type.java:412
com.cliffc.aa.node.FunNode.formal
Type formal(int idx)
Definition: FunNode.java:187
com.cliffc.aa.node.CallNode
Definition: CallNode.java:86
com.cliffc.aa.type.Type.ALL
static final Type ALL
Definition: Type.java:324
com.cliffc.aa.Env.GVN
static final GVNGCM GVN
Definition: Env.java:13
com.cliffc.aa.node.ParmNode.value
Type value(GVNGCM.Mode opt_mode)
Definition: ParmNode.java:59
com.cliffc.aa.node.CallNode.nargs
int nargs()
Definition: CallNode.java:125
com.cliffc.aa.type.Type.CTRL
static final Type CTRL
Definition: Type.java:326
com.cliffc.aa.node.Node.is_copy
Node is_copy(int idx)
Definition: Node.java:827
com.cliffc.aa.node.Node.ErrMsg.FAST
static final ErrMsg FAST
Definition: Node.java:893
com.cliffc.aa.node.Node.in
Node in(int i)
Definition: Node.java:126
com.cliffc.aa.node.ParmNode.ParmNode
ParmNode(int idx, String name, Node fun, Type tdef, Node defalt, Parse badgc)
Definition: ParmNode.java:20
com.cliffc.aa.type.Type.XCTRL
static final Type XCTRL
Definition: Type.java:327
com.cliffc.aa.GVNGCM
Definition: GVNGCM.java:12
com.cliffc.aa.type.Type.simple_ptr
Type simple_ptr()
Definition: Type.java:358
com.cliffc.aa.node.PhiNode.is_mem
boolean is_mem()
Definition: PhiNode.java:24
com.cliffc.aa.node.Node._uses
Ary< Node > _uses
Definition: Node.java:245
com.cliffc.aa.node.FunNode.nargs
int nargs()
Definition: FunNode.java:190
com.cliffc.aa.AA
an implementation of language AA
Definition: AA.java:9
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.ParmNode.hashCode
int hashCode()
Definition: ParmNode.java:28
com.cliffc.aa.node.ParmNode.equals
boolean equals(Object o)
Definition: ParmNode.java:29
com.cliffc.aa.node.ParmNode.add_flow_use_extra
void add_flow_use_extra(Node chg)
Definition: ParmNode.java:94
com.cliffc.aa.node.ThunkNode
Definition: ThunkNode.java:16
com.cliffc.aa.node.Node.sharptr
Type sharptr(Node mem)
Definition: Node.java:855
com.cliffc.aa.node.FunNode.parm
ParmNode parm(int idx)
Definition: FunNode.java:887
com.cliffc.aa.node.ParmNode
Definition: ParmNode.java:14
com.cliffc.aa.node.Node.OP_PARM
static final byte OP_PARM
Definition: Node.java:37
com.cliffc.aa.type.Type.oob
Type oob()
Definition: Type.java:635
com.cliffc.aa.GVNGCM.add_flow
public< N extends Node > N add_flow(N n)
Definition: GVNGCM.java:50
com.cliffc.aa.node.CallNode.arg
Node arg(int x)
Definition: CallNode.java:127
com.cliffc.aa.node.FunNode
Definition: FunNode.java:58
com.cliffc.aa.node.CallNode._badargs
Parse[] _badargs
Definition: CallNode.java:94
com.cliffc.aa.node.ParmNode.ideal_reduce
Node ideal_reduce()
Definition: ParmNode.java:37
com
com.cliffc.aa.node.ParmNode.fun
FunNode fun()
Definition: ParmNode.java:26
com.cliffc.aa.node.ParmNode.err
ErrMsg err(boolean fast)
Definition: ParmNode.java:111
com.cliffc.aa.Env
Definition: Env.java:12
com.cliffc.aa.type
Definition: Bits.java:1
com.cliffc.aa.node.ParmNode._name
final String _name
Definition: ParmNode.java:16
com.cliffc.aa.node.Node._defs
Ary< Node > _defs
Definition: Node.java:124
com.cliffc.aa.node.FunNode._thunk_rhs
final boolean _thunk_rhs
Definition: FunNode.java:68
com.cliffc.aa.Parse
an implementation of language AA
Definition: Parse.java:68
com.cliffc.aa.GVNGCM.Mode
Definition: GVNGCM.java:14
com.cliffc.aa.node.ParmNode._idx
final int _idx
Definition: ParmNode.java:15