public override bool Equals(object stateObj) { MemoState state = stateObj as MemoState; if (state == null) { return(false); } if (GetHashCode() != state.GetHashCode()) { return(false); } if (this == state) { return(true); } if (memo.Length != state.memo.Length) { return(false); } int length = memo.Length; for (int i = 0; i < length; i++) { if (!memo[i].Equals(state.memo[i])) { return(false); } } return(true); }
public void Recall(MemoState memo, ObjectHashtable hash) { StateDecomposition dec = memo.Recall(hash) as StateDecomposition; this.stack.Clear(); for (int i = dec.Stack.Length - 1; i >= 0; i--) { this.stack.Push(dec.Stack[i]); } int j = 0; foreach (Variable v in this.pool.GetVariables()) { this.pool[v].Val = dec.Pool[j++].Val; } }
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 MemoSpecState(MemoState memo, Variable[] vars) { this.MemoState = memo; this.Variables = vars; }