mbs-octoml commented on code in PR #11474: URL: https://github.com/apache/tvm/pull/11474#discussion_r888505472
########## src/relay/transforms/compiler_function_utils.cc: ########## @@ -0,0 +1,201 @@ +/* + * 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 src/relay/transforms/compiler_function_utils.cc + * \brief Helper passes for working with functions with the "Compiler" attribute. + */ + +#include "./compiler_function_utils.h" + +#include "../op/call/call.h" +#include "tvm/relay/analysis.h" +#include "tvm/relay/expr_functor.h" + +namespace tvm { +namespace relay { +namespace transforms { +namespace { + +/*! + * \brief Rewrite calls to inlined "Compiler" functions to global functions. The given + * module will be extended with the newly outlined functions. + */ +class Outliner : public MixedModeMutator { + public: + Outliner(GlobalSymbolCache* cache, std::string compiler_filter, IRModule mod) + : cache_(cache), compiler_filter_(std::move(compiler_filter)), mod_(std::move(mod)) {} + + Expr Rewrite_(const CallNode* pre, const Expr& post) final { + Call new_call = Downcast<Call>(post); + if (const auto* function_node = new_call->op.as<FunctionNode>()) { + Optional<String> opt_compiler = function_node->GetAttr<String>(attr::kCompiler); + if (opt_compiler.defined() && + (compiler_filter_.empty() || opt_compiler.value() == compiler_filter_)) { + auto function = GetRef<Function>(function_node); + ICHECK(FreeVars(function).empty()) << "Function marked with '" << attr::kCompiler Review Comment: Ok I'll change to a DCHECK since technically execution could continue even with this invariant broken (not like a null-deref or anything), however the codebase is full of ICHECKS which probably should be DCHECKs. -- 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]
