Esempio n. 1
0
        private static bool IsDisjunctionOfPredicates(Expr guard)
        {
            if (!(guard is NAryExpr))
            {
                return(false);
            }
            NAryExpr nary = (NAryExpr)guard;

            if (nary.Args.Count() != 2)
            {
                return(false);
            }
            if (!(nary.Fun is BinaryOperator))
            {
                return(false);
            }
            BinaryOperator binOp = (BinaryOperator)nary.Fun;

            if (binOp.Op != BinaryOperator.Opcode.Or)
            {
                return(false);
            }
            if (!(nary.Args[0] is IdentifierExpr && nary.Args[1] is IdentifierExpr))
            {
                return(false);
            }
            return(GPUVerifier.IsPredicate(GVUtil.StripThreadIdentifier(
                                               ((IdentifierExpr)nary.Args[0]).Name)) &&
                   GPUVerifier.IsPredicate(GVUtil.StripThreadIdentifier(
                                               ((IdentifierExpr)nary.Args[1]).Name)));
        }
        private static bool IsDisjunctionOfPredicates(Expr guard)
        {
            NAryExpr nary = guard as NAryExpr;

            if (nary == null || nary.Args.Count() != 2)
            {
                return(false);
            }

            BinaryOperator binOp = nary.Fun as BinaryOperator;

            if (binOp == null || binOp.Op != BinaryOperator.Opcode.Or)
            {
                return(false);
            }

            if (!(nary.Args[0] is IdentifierExpr && nary.Args[1] is IdentifierExpr))
            {
                return(false);
            }

            return(GPUVerifier.IsPredicate(Utilities.StripThreadIdentifier(((IdentifierExpr)nary.Args[0]).Name)) &&
                   GPUVerifier.IsPredicate(Utilities.StripThreadIdentifier(((IdentifierExpr)nary.Args[1]).Name)));
        }
        private void AddBarrierDivergenceCandidates(HashSet <Variable> localVars, Implementation impl, IRegion region)
        {
            if (!verifier.ContainsBarrierCall(region) && !GPUVerifyVCGenCommandLineOptions.WarpSync)
            {
                return;
            }

            Expr guard = region.Guard();

            if (guard != null && verifier.UniformityAnalyser.IsUniform(impl.Name, guard))
            {
                return;
            }

            if (IsDisjunctionOfPredicates(guard))
            {
                string loopPredicate = ((guard as NAryExpr).Args[0] as IdentifierExpr).Name;
                loopPredicate = loopPredicate.Substring(0, loopPredicate.IndexOf('$'));

                // Int type used here, but it doesn't matter as we will print and then re-parse the program
                var uniformEnabledPredicate = Expr.Eq(
                    new IdentifierExpr(Token.NoToken, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, loopPredicate + "$1", Type.Int))),
                    new IdentifierExpr(Token.NoToken, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, loopPredicate + "$2", Type.Int))));

                verifier.AddCandidateInvariant(region, uniformEnabledPredicate, "loopPredicateEquality");

                verifier.AddCandidateInvariant(region, Expr.Imp(verifier.ThreadsInSameGroup(), uniformEnabledPredicate), "loopPredicateEquality");

                Dictionary <string, int> assignmentCounts = GetAssignmentCounts(impl);

                HashSet <string> alreadyConsidered = new HashSet <string>();

                foreach (var v in localVars)
                {
                    string lv = Utilities.StripThreadIdentifier(v.Name);
                    if (alreadyConsidered.Contains(lv))
                    {
                        continue;
                    }

                    alreadyConsidered.Add(lv);

                    if (verifier.UniformityAnalyser.IsUniform(impl.Name, v.Name))
                    {
                        continue;
                    }

                    if (GPUVerifier.IsPredicate(lv))
                    {
                        continue;
                    }

                    if (!assignmentCounts.ContainsKey(lv) || assignmentCounts[lv] <= 1)
                    {
                        continue;
                    }

                    if (!verifier.ContainsNamedVariable(region.GetModifiedVariables(), lv))
                    {
                        continue;
                    }

                    AddPredicatedEqualityCandidateInvariant(region, loopPredicate, new LocalVariable(Token.NoToken, new TypedIdent(Token.NoToken, lv, Type.Int)));
                }
            }
        }