internal SpecializingVisitor(GraphProcessor graphProcessor, ResidualAssemblyHolder holder, MethodBodyBlock mbbUp, SpecState state, VariablesHashtable varsHash) : base(graphProcessor) { this.holder = holder; this.mbbUp = mbbUp; this.state = state; this.varsHash = varsHash; this.upDownNodes = new Hashtable(); this.exitData = new ArrayList(); }
internal static void SpecializeMethod(ResidualAssemblyHolder holder, ResidualMethod method) { Value[] args = method.Arguments; PointerValue[] ptrs = method.Pointers; MethodBodyBlock mbbDown = holder.AnnotatedHolder[method.AnnotatedMethod]; MethodBodyBlock mbbUp = new MethodBodyBlock(mbbDown.ReturnType); holder.AddMethod(method, mbbUp); SpecState state = new SpecState(mbbDown.Variables.Count); VariablesHashtable varsHash = new VariablesHashtable(); int varCount = 0; int argCount = 0; foreach (Variable varDown in mbbDown.Variables.ParameterMapper) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp; if (Annotation.GetValueBTType(method.AnnotatedMethod.ParamVals[varCount++].Val) == BTType.Static) { state.Pool[varDown].Val = args[argCount++]; varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); } else varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Parameter); varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; } foreach (Variable varDown in mbbDown.Variables) if (! state.Pool.ContainsVar(varDown)) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; } PointerToNode ptrUpNode = new PointerToNode(mbbUp); Node dummyUp = new DummyNode(mbbUp); Node upNode = dummyUp; for (int i = 0; i < ptrs.Length; i++) { Type ptrType = ptrs[i].Type; Type type = ptrType.GetElementType(); Variable newVar1 = mbbUp.Variables.CreateVar(ptrType, VariableKind.Parameter); Variable newVar2 = mbbUp.Variables.CreateVar(type, VariableKind.Local); varsHash[ptrs[i]] = newVar2; ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVar(newVar1)); ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadIndirect(type)); ptrUpNode = new PointerToNode(ptrUpNode.Node = new StoreVar(newVar2)); upNode = upNode.Next = new LoadVar(newVar1); upNode = upNode.Next = new LoadVar(newVar2); upNode = upNode.Next = new StoreIndirect(type); } upNode.Next = new Leave(); upNode = dummyUp.Next; dummyUp.RemoveFromGraph(); GraphProcessor graphProc = new GraphProcessor(); SpecializingVisitor visitor = new SpecializingVisitor(graphProc, holder, mbbUp, state, varsHash); visitor.AddTask(mbbDown.Next, ptrUpNode); graphProc.Process(); visitor.SetLastNode(upNode); }
private void callMethod(Node downNode, AnnotatedMethod method, PointerToNode ptrUpNode, Node upNode, Value[] args) { if (method.SourceMethod.IsDefined(typeof(InlineAttribute), false) && ! (upNode is NewObject)) { MethodBodyBlock mbbDown = this.holder.AnnotatedHolder[method]; SpecState state = new SpecState(mbbDown.Variables.Count); int varCount = 0; int argCount = 0; foreach (Variable varDown in mbbDown.Variables.ParameterMapper) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; if (Annotation.GetValueBTType(method.ParamVals[varCount++].Val) == BTType.Static) { state.Pool[varDown].Val = args[argCount]; state.Stack.Push(args[argCount++]); } else { Node upNext = new StoreVar(varUp); Node upPrevNext = ptrUpNode.Node; ptrUpNode.Node = upNext; upNext.Next = upPrevNext; } } while (ptrUpNode.Node != null) ptrUpNode = new PointerToNode(ptrUpNode.Node); foreach (Variable varDown in mbbDown.Variables) if (! state.Pool.ContainsVar(varDown)) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; ptrUpNode = SpecializingVisitor.initVariable(varUp, ptrUpNode); } int depth = state.Stack.Count + 1; GraphProcessor graphProc = new GraphProcessor(); SpecializingVisitor visitor = new SpecializingVisitor(graphProc, this.holder, this.mbbUp, state, this.varsHash); visitor.AddTask(mbbDown.Next, ptrUpNode); graphProc.Process(); foreach (Data newData in visitor.exitData) { state.Recall(newData.MemoSpecState, newData.ObjectHashtable); if (state.Stack.Count == depth) this.state.Stack.Push(state.Stack.Pop()); this.AddTask(downNode.Next, newData.PointerToNode); } } else { ObjectHashtable objHash = new ObjectHashtable(); MemoState memoArgs = new MemoState(args, objHash); PointerValue[] ptrs = this.varsHash.GetPointers(objHash); for (int i = 0; i < ptrs.Length; i++) ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVarAddr(this.varsHash[ptrs[i]])); ptrUpNode = new PointerToNode(ptrUpNode.Node = upNode); ResidualMethod callMethod = new ResidualMethod(method, memoArgs, args, ptrs); Specialization.SetResidualMethod(upNode, callMethod); this.holder.SpecializeMethod(callMethod); this.AddTask(downNode.Next, ptrUpNode); } }
internal SpecializingVisitor(GraphProcessor graphProcessor, ResidualAssemblyHolder holder, MethodBodyBlock mbbUp, SpecState state, VariablesHashtable varsHash) : base(graphProcessor) { this.holder = holder; this.mbbUp = mbbUp; this.state = state; this.varsHash = varsHash; this.upDownNodes = new Hashtable(); this.exitData = new ArrayList(); }
internal static void SpecializeMethod(ResidualAssemblyHolder holder, ResidualMethod method) { Value[] args = method.Arguments; PointerValue[] ptrs = method.Pointers; MethodBodyBlock mbbDown = holder.AnnotatedHolder[method.AnnotatedMethod]; MethodBodyBlock mbbUp = new MethodBodyBlock(mbbDown.ReturnType); holder.AddMethod(method, mbbUp); SpecState state = new SpecState(mbbDown.Variables.Count); VariablesHashtable varsHash = new VariablesHashtable(); int varCount = 0; int argCount = 0; foreach (Variable varDown in mbbDown.Variables.ParameterMapper) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp; if (Annotation.GetValueBTType(method.AnnotatedMethod.ParamVals[varCount++].Val) == BTType.Static) { state.Pool[varDown].Val = args[argCount++]; varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); } else { varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Parameter); } varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; } foreach (Variable varDown in mbbDown.Variables) { if (!state.Pool.ContainsVar(varDown)) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; } } PointerToNode ptrUpNode = new PointerToNode(mbbUp); Node dummyUp = new DummyNode(mbbUp); Node upNode = dummyUp; for (int i = 0; i < ptrs.Length; i++) { Type ptrType = ptrs[i].Type; Type type = ptrType.GetElementType(); Variable newVar1 = mbbUp.Variables.CreateVar(ptrType, VariableKind.Parameter); Variable newVar2 = mbbUp.Variables.CreateVar(type, VariableKind.Local); varsHash[ptrs[i]] = newVar2; ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVar(newVar1)); ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadIndirect(type)); ptrUpNode = new PointerToNode(ptrUpNode.Node = new StoreVar(newVar2)); upNode = upNode.Next = new LoadVar(newVar1); upNode = upNode.Next = new LoadVar(newVar2); upNode = upNode.Next = new StoreIndirect(type); } upNode.Next = new Leave(); upNode = dummyUp.Next; dummyUp.RemoveFromGraph(); GraphProcessor graphProc = new GraphProcessor(); SpecializingVisitor visitor = new SpecializingVisitor(graphProc, holder, mbbUp, state, varsHash); visitor.AddTask(mbbDown.Next, ptrUpNode); graphProc.Process(); visitor.SetLastNode(upNode); }
private void callMethod(Node downNode, AnnotatedMethod method, PointerToNode ptrUpNode, Node upNode, Value[] args) { if (method.SourceMethod.IsDefined(typeof(InlineAttribute), false) && !(upNode is NewObject)) { MethodBodyBlock mbbDown = this.holder.AnnotatedHolder[method]; SpecState state = new SpecState(mbbDown.Variables.Count); int varCount = 0; int argCount = 0; foreach (Variable varDown in mbbDown.Variables.ParameterMapper) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; if (Annotation.GetValueBTType(method.ParamVals[varCount++].Val) == BTType.Static) { state.Pool[varDown].Val = args[argCount]; state.Stack.Push(args[argCount++]); } else { Node upNext = new StoreVar(varUp); Node upPrevNext = ptrUpNode.Node; ptrUpNode.Node = upNext; upNext.Next = upPrevNext; } } while (ptrUpNode.Node != null) { ptrUpNode = new PointerToNode(ptrUpNode.Node); } foreach (Variable varDown in mbbDown.Variables) { if (!state.Pool.ContainsVar(varDown)) { state.Pool[varDown] = new Location(varDown.Type); Variable varUp = this.mbbUp.Variables.CreateVar(varDown.Type, VariableKind.Local); this.varsHash[new PointerToLocationValue(state.Pool[varDown])] = varUp; ptrUpNode = SpecializingVisitor.initVariable(varUp, ptrUpNode); } } int depth = state.Stack.Count + 1; GraphProcessor graphProc = new GraphProcessor(); SpecializingVisitor visitor = new SpecializingVisitor(graphProc, this.holder, this.mbbUp, state, this.varsHash); visitor.AddTask(mbbDown.Next, ptrUpNode); graphProc.Process(); foreach (Data newData in visitor.exitData) { state.Recall(newData.MemoSpecState, newData.ObjectHashtable); if (state.Stack.Count == depth) { this.state.Stack.Push(state.Stack.Pop()); } this.AddTask(downNode.Next, newData.PointerToNode); } } else { ObjectHashtable objHash = new ObjectHashtable(); MemoState memoArgs = new MemoState(args, objHash); PointerValue[] ptrs = this.varsHash.GetPointers(objHash); for (int i = 0; i < ptrs.Length; i++) { ptrUpNode = new PointerToNode(ptrUpNode.Node = new LoadVarAddr(this.varsHash[ptrs[i]])); } ptrUpNode = new PointerToNode(ptrUpNode.Node = upNode); ResidualMethod callMethod = new ResidualMethod(method, memoArgs, args, ptrs); Specialization.SetResidualMethod(upNode, callMethod); this.holder.SpecializeMethod(callMethod); this.AddTask(downNode.Next, ptrUpNode); } }