Ejemplo n.º 1
0
 internal void addUsage(StoreVar storer, LoadVar loader)
 {
     usageHash.Add(storer,loader);
 }
Ejemplo n.º 2
0
        private bool performPatternReplacing()
        {
            bool result = false;

            foreach (BasicBlock block in blockList)
            {
                NodeArray body = block.Body;

                bool flag = true;
                while (flag)
                {
                    flag = false;
                    for (int i = 0; i < body.Count-1 && ! flag; i++)
                    {
                        Node n1 = body[i];

                        if (n1 is Branch && (n1 as Branch).Next == (n1 as Branch).Alt)
                        {
                            result = flag = true;
                            Node n = newRemoveStackTop(block);
                            body[i] = n;
                            n1.ReplaceByNode(n);
                            n.Next = n1.Next;
                            n1.RemoveFromGraph();
                        }
                        else
                        {
                            Node n2 = body[i+1];

                            if (n1 is StoreVar && n2 is LoadVar &&
                                (n1 as ManageVar).Var == (n2 as ManageVar).Var)
                            {
                                result = flag = true;
                                Node n = newDuplicateStackTop(block);
                                body[i] = n;
                                body[i+1] = n1;
                                n1.ReplaceByNode(n);
                                n.Next = n1;
                                n1.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (detectedDoubleLoading(n1,n2))
                            {
                                result = flag = true;
                                Node n = newDuplicateStackTop(block);
                                body[i+1] = n;
                                n2.ReplaceByNode(n);
                                n.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (detectedDoubleCasting(n1,n2))
                            {
                                result = flag = true;
                                body.RemoveAt(i+1);
                                n1.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (n1 is StoreVar && n2 is Leave &&
                                n2.Parent is MethodBodyBlock)
                            {
                                result = flag = true;
                                Node n = newRemoveStackTop(block);
                                body[i] = n;
                                n1.ReplaceByNode(n);
                                n1.RemoveFromGraph();
                                n.Next = n2;
                            }
                            else if (detectedReplacementByPop(n1,n2))
                            {
                                result = flag = true;
                                Node n = newRemoveStackTop(block);
                                body.RemoveAt(i+1);
                                body[i] = n;
                                n1.ReplaceByNode(n);
                                n1.RemoveFromGraph();
                                n.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (detectedReplacementByDoublePop(n1,n2))
                            {
                                result = flag = true;
                                Node new1 = newRemoveStackTop(block),
                                    new2 = newRemoveStackTop(block);
                                body[i] = new1;
                                body[i+1] = new2;
                                n1.ReplaceByNode(new1);
                                n1.RemoveFromGraph();
                                new1.Next = new2;
                                new2.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (detectedRemoval(n1,n2))
                            {
                                result = flag = true;
                                body.RemoveAt(i+1);
                                body.RemoveAt(i);
                                n1.ReplaceByNode(n2.Next);
                                n1.RemoveFromGraph();
                                n2.RemoveFromGraph();
                            }
                            else if (detectedInitValueReplacement(n1,n2))
                            {
                                result = flag = true;
                                Variable var = (n1 as LoadVarAddr).Var;
                                Type type = (n2 as InitValue).Type;

                                object constant = null;
                                if (type == typeof(Int64))
                                    constant = (Int64)0;
                                else if (type == typeof(Single) || type == typeof(Double))
                                    constant = (Double)0;
                                else
                                    constant = (Int32)0;

                                Node new1 = new LoadConst(constant),
                                    new2 = new StoreVar(var);
                                new1.Options[BasicBlock.BASIC_BLOCK_OPTION] = block;
                                new2.Options[BasicBlock.BASIC_BLOCK_OPTION] = block;

                                body[i] = new1;
                                body[i+1] = new2;
                                n1.ReplaceByNode(new1);
                                n1.RemoveFromGraph();
                                new1.Next = new2;
                                new2.Next = n2.Next;
                                n2.RemoveFromGraph();
                            }
                            else if (i < body.Count-2)
                            {
                                Node n3 = body[i+2];

                                if (i < body.Count-3)
                                {
                                    Node n4 = body[i+3];

                                    if (detectedOperandExchange(n1,n2,n3,n4))
                                    {
                                        result = flag = true;
                                        Node n = newDuplicateStackTop(block);
                                        body[i] = n;
                                        body[i+1] = n1;
                                        body[i+2] = n2;
                                        body[i+3] = n4;
                                        n3.RemoveFromGraph();
                                        n1.ReplaceByNode(n);
                                        n.Next = n1;
                                        n2.Next = n4;
                                    }
                                    else if (detectedQuadruple1(n1,n2,n3,n4))
                                    {
                                        result = flag = true;
                                        Node n = newDuplicateStackTop(block);
                                        body[i] = n;
                                        body[i+1] = n1;
                                        body[i+2] = n2;
                                        body[i+3] = n3;
                                        n1.ReplaceByNode(n);
                                        n.Next = n1;
                                        n3.Next = n4.Next;
                                        n4.RemoveFromGraph();
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return result;
        }
Ejemplo n.º 3
0
 public LoadVar this[StoreVar storer]
 {
     get { return usageHash[storer] as LoadVar; }
 }
Ejemplo n.º 4
0
 public bool IsUsed(StoreVar storer)
 {
     return usageHash.ContainsKey(storer);
 }
Ejemplo n.º 5
0
 protected internal virtual void VisitStoreVar(StoreVar node, object data)
 {
     throw new NodeNotSupportedException(node);
 }
Ejemplo n.º 6
0
 protected internal override void VisitStoreVar(StoreVar node, object data)
 {
     StackTypes stack = data as StackTypes;
     Verifier.ProcessSt(new TypeEx(node.Var.Type), stack);
     AddTask(node.Next,stack);
 }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
 protected override void VisitStoreVar(StoreVar downNode, object o)
 {
     PointerValue ptr = new PointerToLocationValue(this.state.Pool[downNode.Var]);
     this.storeVar(downNode, ptr, o);
 }
Ejemplo n.º 9
0
        protected override void VisitStoreVar(StoreVar upNode, object o)
        {
            State state = o as State;
            BTValue val = state.Stack.Pop() as BTValue;
            state.Pool[upNode.Var].Val = val;

            BTType btType;
            if (val.BTType == BTType.Dynamic)
                btType = BTType.eXclusive;
            else
                btType = BTType.Static;
            Annotation.SetNodeBTType(upNode, btType);
        }
Ejemplo n.º 10
0
 protected override void VisitStoreVar(StoreVar upNode, object o)
 {
     DepthContainer cnt = o as DepthContainer;
     cnt.Depth += 1;
 }
Ejemplo n.º 11
0
 protected internal override void VisitStoreVar(StoreVar node, object data)
 {
     switch(node.Var.Kind)
     {
         case VariableKind.Local:
         {
             generator.Emit(OpCodes.Stloc, GetLocal(node.Var));
         } break;
         case VariableKind.Parameter:
         {
             int index = GetArgIndex(node.Var);
             if(index <= 255)
                 generator.Emit(OpCodes.Starg_S, (byte)index);
             else
                 generator.Emit(OpCodes.Starg, index);
         } break;
         case VariableKind.ArgList:
             throw new EmissionException(); //Impossible!
     }
     AddTask(node.Next,null);
 }