Lunderberg commented on code in PR #12863: URL: https://github.com/apache/tvm/pull/12863#discussion_r989415776
########## src/arith/transitive_comparison_analyzer.cc: ########## @@ -0,0 +1,683 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +/*! + * \file tvm/arith/transitive_comparison_analyzer.cc + */ + +#include <tvm/arith/analyzer.h> +#include <tvm/tir/analysis.h> +#include <tvm/tir/expr.h> + +#include <optional> +#include <vector> + +#include "constraint_extract.h" +#include "pattern_match.h" + +namespace tvm { +namespace arith { + +using namespace tir; + +class TransitiveComparisonAnalyzer::Impl { + public: + /* \brief Using previously specified knowns, compare the expressions provided + * + * \param lhs The left-hand side of the comparison + * + * \param rhs The right-hand side of the comparison + * + * \return The most specific result that can be proven about the + * comparison. If nothing can be proven, returns kUnknown. + */ + CompareResult TryCompare(const PrimExpr& lhs, const PrimExpr& rhs) const; + + /*! \brief Bind a variable as being equal to a known expression + * + * \param var The variable of interest. + * \param expr The bound expression + * \param allow_override Whether to allow override of existing information. + */ + void Bind(const tir::Var& var, const PrimExpr& expr, bool allow_override = false); + + /*! \brief Bind a variable as being within a specified range + * + * \param var The variable of interest. + * \param range The known range + * \param allow_override Whether to allow override of existing information. + */ + void Bind(const tir::Var& var, const Range& expr, bool allow_override = false); + + /*! + * \brief Update the internal state to enter constraint. + * \param constraint A constraint expression. + * + * \return An exit function that must be called to cleanup. May be + * `nullptr`, if no cleanup is required. + */ + std::function<void()> EnterConstraint(const PrimExpr& expr); + + private: + // Utility class to avoid needing to repeatedly call ExprDeepEqual + enum class Key : size_t {}; Review Comment: That's exactly correct. A `size_t` could have been used directly without introducing the `enum class Key`, but that would introduce the possibility of a `size_t` being erroneously used as a key (e.g. accidentally treating a loop iterator as a lookup key). Since it required reading into it to discern the intent, I'm updating the docstrings for `Key`, `ExprToPreviousKey`, and `ExprToKey` to make the intended usage explicit. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
