public override void Optimize() { var fixups = new List <CodeBlock>(); var refmap = new Dictionary <Variable, int>(); var callsites = new Dictionary <Variable, int>(); Pass0 p0 = new Pass0(refmap, callsites); p0.WalkNode(Root); Pass1 p1 = new Pass1(fixups, refmap, callsites); p1.WalkNode(Root); Pass2 p2 = new Pass2(); p2.WalkNode(Root); foreach (var cb in Distinct(fixups)) { cb.Bind(); } Root.Bind(); }
public override void Optimize() { int total = 0, fc = 0; do { var vartypes = new Dictionary <Variable, Dictionary <Type, List <Expression> > >(); var p0 = new Pass0 { vartypes = vartypes }; p0.WalkNode(Root); var p1 = new Pass1 { vartypes = vartypes }; p1.WalkNode(Root); fc = p1.Count; total += fc; }while (fc > 0); //if (total > 0) //{ // Console.WriteLine("Typed {0} variables", total); //} }
public override void Optimize() { Pass0 p0 = new Pass0(references); p0.WalkNode(Root); foreach (var v in references.Keys) { foreach (var t in references[v].Keys) { var c = references[v][t]; if (t != typeof(object) && c > 1 && t.IsValueType) { var n = SymbolTable.StringToId(t.Name + "___" + SymbolTable.IdToString(v.Name)); var tv = v.Block.CreateVariable(n, Variable.VariableKind.Local, t); v.SetTypedVariable(t, tv); var vv = v; if (vv.Kind == Variable.VariableKind.Local && vv.AssumedValue is BoundExpression) { var assbe = vv.AssumedValue as BoundExpression; if (assbe.Variable.Kind == Variable.VariableKind.Parameter) { vv = assbe.Variable; } } var inittv = Ast.Write(tv, Ast.SimpleCallHelper(typeof(IronScheme.Runtime.Helpers).GetMethod("UnsafeConvert").MakeGenericMethod(tv.Type), Ast.Read(vv))); var bs = v.Block.Body as BlockStatement; if (bs != null) { Statement[] newbody = new Statement[bs.Statements.Count + 1]; newbody[0] = inittv; bs.Statements.CopyTo(newbody, 1); v.Block.Body = Ast.Block(newbody); } else { v.Block.Body = Ast.Block(inittv, v.Block.Body); } } } v.Block.Bind(); } Pass1 p1 = new Pass1(references); p1.WalkNode(Root); foreach (var v in references.Keys) { v.Block.Bind(); } }
public override void Optimize() { Pass0 p0 = new Pass0(); p0.WalkNode(Root); //Pass1 p1 = new Pass1(); //p1.WalkNode(Root); Pass2 p2 = new Pass2(references); p2.WalkNode(Root); Pass3 p3 = new Pass3(references); p3.WalkNode(Root); }
public override void Optimize() { var fixups = new List<CodeBlock>(); Pass0 p0 = new Pass0(fixups); p0.WalkNode(Root); foreach (var cb in Distinct(fixups)) { cb.Bind(); } Root.Bind(); }
public override void Optimize() { var fixups = new List <CodeBlock>(); Pass0 p0 = new Pass0(fixups); p0.WalkNode(Root); foreach (var cb in Distinct(fixups)) { cb.Bind(); } Root.Bind(); }
public override void Optimize() { var returns = new Dictionary <CodeBlock, List <ReturnStatement> >(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; foreach (var ret in retlist) { var expr = ret.Expression; if (expr is MethodCallExpression) { var mce = (MethodCallExpression)expr; if (mce.TailCall) { var ass = mce.Method.DeclaringType.Assembly; if (ass == typeof(Optimizer).Assembly || ass == typeof(Oyster.Math.IntX).Assembly || ass == typeof(CodeBlock).Assembly || ass.GlobalAssemblyCache) { if (mce.Method.DeclaringType.BaseType != typeof(MulticastDelegate)) { mce.TailCall = false; } } else { // what here? // look for method decorated with [Recursive] or [NonRecursive] attribute //Console.WriteLine(mce.Method); } } } } } }
public override void Optimize() { var fixups = new List<CodeBlock>(); var refmap = new Dictionary<Variable, int>(); var callsites = new Dictionary<Variable, int>(); Pass0 p0 = new Pass0(refmap, callsites); p0.WalkNode(Root); Pass1 p1 = new Pass1(fixups, refmap, callsites); p1.WalkNode(Root); Pass2 p2 = new Pass2(); p2.WalkNode(Root); foreach (var cb in Distinct(fixups)) { cb.Bind(); } Root.Bind(); }
public override void Optimize() { int total = 0, fc = 0; do { var vartypes = new Dictionary<Variable, Dictionary<Type, List<Expression>>>(); var p0 = new Pass0 { vartypes = vartypes }; p0.WalkNode(Root); var p1 = new Pass1 { vartypes = vartypes }; p1.WalkNode(Root); fc = p1.Count; total += fc; } while (fc > 0); //if (total > 0) //{ // Console.WriteLine("Typed {0} variables", total); //} }
public override void Optimize() { int changes = 0; do { changes = 0; var returns = new Dictionary<CodeBlock, List<ReturnStatement>>(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; if (cb.DecorateWithUnspecifiedReturn) { continue; } var allgood = false; foreach (var ret in retlist) { if (ret.Expression is MethodCallExpression) { var mce = (MethodCallExpression)ret.Expression; if (mce.Instance is CodeBlockExpression && mce.Method.Name == "Invoke") { var ii = mce.Instance as CodeBlockExpression; if (ii.Block.DecorateWithUnspecifiedReturn) { allgood = true; continue; } } if (!(mce.Method is MethodBuilder) && Attribute.IsDefined(mce.Method, typeof(UnspecifiedReturnAttribute))) { allgood = true; continue; } } if (!(ret.Expression is MemberExpression)) { allgood = false; break; } var expr = ret.Expression; if (expr is MemberExpression) { var me = (MemberExpression)expr; if (me.Member == Generator.Unspecified) { allgood = true; } else { allgood = false; break; } } } if (allgood && !cb.DecorateWithUnspecifiedReturn) { changes++; cb.DecorateWithUnspecifiedReturn = true; } } } while (changes > 0); }
public override void Optimize() { Pass0 p0 = new Pass0(); p0.WalkNode(Root); }
public override void Optimize() { int changes = 0; var returns = new Dictionary<CodeBlock, List<ReturnStatement>>(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); do { changes = 0; foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; if (cb.DecorateWithNonRecursive) { continue; } var allgood = true; foreach (var ret in retlist) { if (ret.Expression is MethodCallExpression) { var mce = (MethodCallExpression)ret.Expression; if (mce.Instance is CodeBlockExpression && mce.Method.Name == "Invoke") { var ii = mce.Instance as CodeBlockExpression; if (ii.Block.DecorateWithNonRecursive) { continue; } } if (mce.TailCall) { allgood = false; break; } if (!(mce.Method is MethodBuilder) && Attribute.IsDefined(mce.Method, typeof(IronScheme.Runtime.NonRecursiveAttribute))) { continue; } } } if (allgood && !cb.DecorateWithNonRecursive) { changes++; cb.DecorateWithNonRecursive = true; } } } while (changes > 0); }
public override void Optimize() { var returns = new Dictionary<CodeBlock, List<ReturnStatement>>(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; foreach (var ret in retlist) { var expr = ret.Expression; var ue = expr as UnaryExpression; if (ue != null && ue.NodeType == AstNodeType.Convert) { if (ue.Type == typeof(object) && !ue.Operand.Type.IsValueType) { expr = ue.Operand; ret.Expression = expr; } } if (expr is MethodCallExpression) { var mce = (MethodCallExpression)expr; if (mce.TailCall) { var type = mce.Method.DeclaringType; var ass = type.Assembly; // check for proc attribute class and defy if found, all will be tail called if (ass.GlobalAssemblyCache || (!Attribute.IsDefined(type, typeof(ProcedureAttribute)) && !typeof(IModuleDictionaryInitialization).IsAssignableFrom(type))) { // alway tail call delegates if (type.BaseType != typeof(MulticastDelegate)) { var pa = (ProcedureAttribute) Attribute.GetCustomAttribute(mce.Method, typeof(ProcedureAttribute)); // either must not allow it if (pa != null) { mce.TailCall = pa.AllowTailCall; } else { bool tc = false; foreach (BuiltinAttribute ba in Attribute.GetCustomAttributes(mce.Method, typeof(BuiltinAttribute))) { if (ba.AllowTailCall) { tc = true; } } mce.TailCall = tc; } } } //else if (!mce.Method.DeclaringType.IsAssignableFrom(typeof(Callable))) { // what here? // Callable should be excluded, match with known list // The problem here is that direct calls are only resolved at link time // We need to make a list to use at LTO time too // Perhaps all we need, is to take care of it at LTO //Console.WriteLine("In {0} => {1}", cb.Name, mce.Method.Name); } } } } } }
public override void Optimize() { var returns = new Dictionary <CodeBlock, List <ReturnStatement> >(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; foreach (var ret in retlist) { var expr = ret.Expression; var ue = expr as UnaryExpression; if (ue != null && ue.NodeType == AstNodeType.Convert) { if (ue.Type == typeof(object) && !ue.Operand.Type.IsValueType) { expr = ue.Operand; ret.Expression = expr; } } if (expr is MethodCallExpression) { var mce = (MethodCallExpression)expr; if (mce.TailCall) { var type = mce.Method.DeclaringType; var ass = type.Assembly; // check for proc attribute class and defy if found, all will be tail called if (ass.GlobalAssemblyCache || (!Attribute.IsDefined(type, typeof(ProcedureAttribute)) && !typeof(IModuleDictionaryInitialization).IsAssignableFrom(type))) { // alway tail call delegates if (type.BaseType != typeof(MulticastDelegate)) { var pa = (ProcedureAttribute)Attribute.GetCustomAttribute(mce.Method, typeof(ProcedureAttribute)); // either must not allow it if (pa != null) { mce.TailCall = pa.AllowTailCall; } else { bool tc = false; foreach (BuiltinAttribute ba in Attribute.GetCustomAttributes(mce.Method, typeof(BuiltinAttribute))) { if (ba.AllowTailCall) { tc = true; } } mce.TailCall = tc; } } } //else if (!mce.Method.DeclaringType.IsAssignableFrom(typeof(Callable))) { // what here? // Callable should be excluded, match with known list // The problem here is that direct calls are only resolved at link time // We need to make a list to use at LTO time too // Perhaps all we need, is to take care of it at LTO //Console.WriteLine("In {0} => {1}", cb.Name, mce.Method.Name); } } } } } }
public override void Optimize() { int changes = 0; do { changes = 0; var returns = new Dictionary <CodeBlock, List <ReturnStatement> >(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; if (cb.DecorateWithUnspecifiedReturn) { continue; } var allgood = false; foreach (var ret in retlist) { if (ret.Expression is MethodCallExpression) { var mce = (MethodCallExpression)ret.Expression; if (mce.Instance is CodeBlockExpression && mce.Method.Name == "Invoke") { var ii = mce.Instance as CodeBlockExpression; if (ii.Block.DecorateWithUnspecifiedReturn) { allgood = true; continue; } } if (!(mce.Method is MethodBuilder) && Attribute.IsDefined(mce.Method, typeof(UnspecifiedReturnAttribute))) { allgood = true; continue; } } if (!(ret.Expression is MemberExpression)) { allgood = false; break; } var expr = ret.Expression; if (expr is MemberExpression) { var me = (MemberExpression)expr; if (me.Member == Generator.Unspecified) { allgood = true; } else { allgood = false; break; } } } if (allgood && !cb.DecorateWithUnspecifiedReturn) { changes++; cb.DecorateWithUnspecifiedReturn = true; } } }while (changes > 0); }
public override void Optimize() { int changes = 0; var returns = new Dictionary <CodeBlock, List <ReturnStatement> >(); Pass0 p0 = new Pass0 { Returns = returns }; p0.WalkNode(Root); do { changes = 0; foreach (var kv in returns) { var cb = kv.Key; var retlist = kv.Value; if (cb.DecorateWithNonRecursive) { continue; } var allgood = true; foreach (var ret in retlist) { if (ret.Expression is MethodCallExpression) { var mce = (MethodCallExpression)ret.Expression; if (mce.Instance is CodeBlockExpression && mce.Method.Name == "Invoke") { var ii = mce.Instance as CodeBlockExpression; if (ii.Block.DecorateWithNonRecursive) { continue; } } if (mce.TailCall) { allgood = false; break; } if (!(mce.Method is MethodBuilder) && Attribute.IsDefined(mce.Method, typeof(IronScheme.Runtime.NonRecursiveAttribute))) { continue; } } } if (allgood && !cb.DecorateWithNonRecursive) { changes++; cb.DecorateWithNonRecursive = true; } } }while (changes > 0); }