chromium/third_party/angle/src/compiler/translator/tree_ops/PruneInfiniteLoops.cpp

//
// Copyright 2024 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// PruneInfiniteLoops.cpp: The PruneInfiniteLoops function prunes:
//
// 1. while (true) { ... }
//
// 2. bool variable = true; /* variable is never accessed */
//    while (variable) { ... }
//
// In all cases, the loop must not have EOpBreak or EOpReturn inside to be allowed to prune.
//
// In all cases, for (...; condition; ...) is treated the same as while (condition).
//
// It quickly gets error-prone when trying to detect more complicated cases.  For example, it's
// temping to reject any |while (expression involving variable with no side effects)| because that's
// either while(true) or while(false), which is prune-able either way.  That detects loops like
// while(variable == false), while(variable + 2 != 4).  But for example
// while(coherent_buffer[variable]) may indeed not result in an infinite loop.  For now, we stick to
// the basic case.

#include "compiler/translator/tree_ops/PruneInfiniteLoops.h"

#include "compiler/translator/Symbol.h"
#include "compiler/translator/tree_util/IntermTraverse.h"

#include <stack>

namespace sh
{

namespace
{
VariableSet;

class FindConstantVariablesTraverser : public TIntermTraverser
{};

struct LoopStats
{};

class PruneInfiniteLoopsTraverser : public TIntermTraverser
{};

bool PruneInfiniteLoopsTraverser::visitLoop(Visit visit, TIntermLoop *loop)
{}

bool PruneInfiniteLoopsTraverser::visitSwitch(Visit visit, TIntermSwitch *node)
{}

bool PruneInfiniteLoopsTraverser::visitBranch(Visit visit, TIntermBranch *node)
{}
}  // namespace

bool PruneInfiniteLoops(TCompiler *compiler,
                        TIntermBlock *root,
                        TSymbolTable *symbolTable,
                        bool *anyLoopsPruned)
{}

}  // namespace sh