Exemple #1
0
        private void Analyse(Implementation impl, List <Cmd> cs)
        {
            foreach (var c in cs)
            {
                if (c is AssignCmd)
                {
                    AssignCmd assignCmd = c as AssignCmd;
                    for (int i = 0; i != assignCmd.Lhss.Count; i++)
                    {
                        if (assignCmd.Lhss[i] is SimpleAssignLhs)
                        {
                            SimpleAssignLhs lhs = assignCmd.Lhss[i] as SimpleAssignLhs;
                            Expr            rhs = assignCmd.Rhss[i];

                            VariablesOccurringInExpressionVisitor visitor = new VariablesOccurringInExpressionVisitor();
                            visitor.VisitExpr(rhs);

                            foreach (Variable v in visitor.GetVariables())
                            {
                                if (!mayBeDerivedFrom[impl.Name].ContainsKey(v.Name))
                                {
                                    continue;
                                }
                                foreach (string s in mayBeDerivedFrom[impl.Name][v.Name])
                                {
                                    if (mayBeDerivedFrom[impl.Name].ContainsKey(lhs.AssignedVariable.Name) && !mayBeDerivedFrom[impl.Name][lhs.AssignedVariable.Name].Contains(s))
                                    {
                                        SetMayBeDerivedFrom(impl.Name, lhs.AssignedVariable.Name, s);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (c is CallCmd)
                {
                    CallCmd callCmd = c as CallCmd;

                    if (QKeyValue.FindBoolAttribute(callCmd.Proc.Attributes, "barrier_invariant") ||
                        QKeyValue.FindBoolAttribute(callCmd.Proc.Attributes, "binary_barrier_invariant"))
                    {
                        foreach (Expr param in callCmd.Ins)
                        {
                            ExprMayAffectControlFlow(impl.Name, param);
                        }
                    }
                    else if (!GPUVerifier.IsBarrier(callCmd.Proc))
                    {
                        Implementation CalleeImplementation = verifier.GetImplementation(callCmd.callee);
                        if (CalleeImplementation != null)
                        {
                            for (int i = 0; i < CalleeImplementation.InParams.Count(); i++)
                            {
                                VariablesOccurringInExpressionVisitor visitor = new VariablesOccurringInExpressionVisitor();
                                visitor.VisitExpr(callCmd.Ins[i]);

                                foreach (Variable v in visitor.GetVariables())
                                {
                                    if (!mayBeDerivedFrom[impl.Name].ContainsKey(v.Name))
                                    {
                                        continue;
                                    }


                                    foreach (string s in mayBeDerivedFrom[impl.Name][v.Name])
                                    {
                                        if (!mayBeDerivedFrom[callCmd.callee][CalleeImplementation.InParams[i].Name].Contains(s))
                                        {
                                            SetMayBeDerivedFrom(callCmd.callee, CalleeImplementation.InParams[i].Name, s);
                                        }
                                    }
                                }
                            }

                            for (int i = 0; i < CalleeImplementation.OutParams.Count(); i++)
                            {
                                foreach (string s in mayBeDerivedFrom[callCmd.callee][CalleeImplementation.OutParams[i].Name])
                                {
                                    if (!mayBeDerivedFrom[impl.Name][callCmd.Outs[i].Name].Contains(s))
                                    {
                                        SetMayBeDerivedFrom(impl.Name, callCmd.Outs[i].Name, s);
                                    }
                                }
                            }
                        }
                    }
                }
                else if (c is AssumeCmd)
                {
                    var assumeCmd = c as AssumeCmd;
                    ExprMayAffectControlFlow(impl.Name, assumeCmd.Expr);
                }
                else if (c is AssertCmd)
                {
                    var assertCmd = c as AssertCmd;
                    ExprMayAffectControlFlow(impl.Name, assertCmd.Expr);
                }
            }
        }