private static void GenerateCandidateForEnablednessWhenAccessingSharedArrays(GPUVerifier verifier, Implementation impl, IRegion region)
        {
            Block header = region.Header();

            if (verifier.UniformityAnalyser.IsUniform(impl.Name, header))
            {
                return;
            }

            var cfg = Program.GraphFromImpl(impl);
            Dictionary <Block, HashSet <Block> > controlDependence = cfg.ControlDependence();

            controlDependence.TransitiveClosure();
            cfg.ComputeLoops();

            List <Expr> guards = new List <Expr>();

            foreach (var b in controlDependence.Keys.Where(item => controlDependence[item].Contains(region.Header())))
            {
                foreach (var succ in cfg.Successors(b).Where(item => cfg.DominatorMap.DominatedBy(header, item)))
                {
                    var guard = MaybeExtractGuard(verifier, impl, succ);
                    if (guard != null)
                    {
                        guards.Add(guard);
                        break;
                    }
                }
            }

            if (guards.Count == 0)
            {
                return;
            }

            IEnumerable <Variable> readVariables;
            IEnumerable <Variable> writtenVariables;

            GetReadAndWrittenVariables(region, out readVariables, out writtenVariables);

            foreach (var v in readVariables.Where(item => verifier.KernelArrayInfo.GetGlobalAndGroupSharedArrays(false).Contains(item) &&
                                                  !verifier.KernelArrayInfo.GetReadOnlyGlobalAndGroupSharedArrays(true).Contains(item)))
            {
                foreach (var g in guards)
                {
                    verifier.AddCandidateInvariant(
                        region,
                        Expr.Imp(Expr.Ident(verifier.FindOrCreateAccessHasOccurredVariable(v.Name, AccessType.READ)), g),
                        "accessOnlyIfEnabledInEnclosingScopes",
                        "do_not_predicate");
                }
            }

            foreach (var v in writtenVariables.Where(item => verifier.KernelArrayInfo.GetGlobalAndGroupSharedArrays(false).Contains(item)))
            {
                foreach (var g in guards)
                {
                    verifier.AddCandidateInvariant(
                        region,
                        Expr.Imp(Expr.Ident(verifier.FindOrCreateAccessHasOccurredVariable(v.Name, AccessType.WRITE)), g),
                        "accessOnlyIfEnabledInEnclosingScopes",
                        "do_not_predicate");
                }
            }
        }