vinx13 commented on code in PR #14690: URL: https://github.com/apache/tvm/pull/14690#discussion_r1195077741
########## src/arith/presburger_set.h: ########## @@ -0,0 +1,199 @@ +/* + * 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 presburger_set.h + * \brief Integer set based on MLIR Presburger set + */ +#ifndef TVM_ARITH_PRESBURGER_SET_H_ +#define TVM_ARITH_PRESBURGER_SET_H_ + +#if TVM_MLIR_VERSION >= 150 +#include <mlir/Analysis/Presburger/IntegerRelation.h> +#include <mlir/Analysis/Presburger/PresburgerRelation.h> +#include <mlir/Analysis/Presburger/Simplex.h> +#endif + +#include <tvm/arith/analyzer.h> +#include <tvm/tir/op.h> + +#include <limits> +#include <vector> + +#include "const_fold.h" + +namespace tvm { +namespace arith { + +#if TVM_MLIR_VERSION >= 150 +using namespace mlir; +using namespace presburger; + +// Acknowledgement: PresburgerSet is based on Presburger set of MLIR. +/*! + * \brief Symbolic integer set. + * + * \note PresburgerSet aims to provide compatible APIs with IntSet, + * and some additional APIs that analyze and solve + * multi-dimension interger set problems + */ +class PresburgerSetNode : public IntSetNode { + public: + PresburgerSetNode() : space(PresburgerSpace::getRelationSpace()) {} + explicit PresburgerSetNode(const PresburgerSpace& space, const Array<Var>& vars) + : disjuncts({}), space(space), vars(vars) {} + explicit PresburgerSetNode(const std::vector<IntegerRelation>& disjuncts, + const PresburgerSpace& space, const Array<Var>& vars) + : disjuncts(disjuncts), space(space), vars(vars) {} + + /*! \brief Represent the union of multiple IntegerRelation */ + std::vector<IntegerRelation> disjuncts; + /*! \brief The space of all the disjuncts */ + PresburgerSpace space; + + // visitor overload. + void VisitAttrs(tvm::AttrVisitor* v) { + v->Visit("vars", &vars); + if (auto* p = dynamic_cast<NodeAttrSetter*>(v)) { Review Comment: if the goal is to provide a way to get / set / update constraints via python FFI, we can explicitly register APIs so that we can avoid the special handling here and changes to reflection.h -- 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]
