// Copyright (c) 2023 PaddlePaddle Authors. All Rights Reserved. // // Licensed 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. #pragma once #include #include #include "paddle/cinn/common/macros.h" #include "paddle/ir/core/program.h" #include "paddle/cinn/hlir/framework/graph_compiler.h" #include "paddle/cinn/hlir/framework/op_lowering.h" namespace cinn { namespace hlir { namespace framework { // TODO(Aurelius84): Need abstract this logic to implement Proxy for // the co-existance with GraphCompiler. class NewIRCompiler final { public: NewIRCompiler(const ::ir::Program& prog, const Target& target, const std::shared_ptr& scope) : program_(prog), m_builder_("NewIR", target), target_(target), scope_(scope) {} std::unique_ptr Build(); private: CINN_DISALLOW_COPY_AND_ASSIGN(NewIRCompiler); std::unique_ptr Build(const std::vector& groups); std::vector GetOpFunc(const ::ir::Operation& op, int idx); void ProcessFunction(const std::vector& lowered_funcs); std::vector> BuildInstructions( const std::vector& groups); const ::ir::Program& program_; ir::Module::Builder m_builder_; std::unique_ptr compiler_{nullptr}; Target target_; std::shared_ptr scope_; std::unordered_map func_names_; }; std::shared_ptr BuildScope(const Target&, const ::ir::Program&); } // namespace framework } // namespace hlir } // namespace cinn