1 /** 2 * Copyright 2020 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef DATASET_ENGINE_OPT_PRE_DEEP_COPY_PASS_H_ 18 #define DATASET_ENGINE_OPT_PRE_DEEP_COPY_PASS_H_ 19 20 #include <memory> 21 #include <vector> 22 #include "minddata/dataset/engine/opt/pass.h" 23 24 namespace mindspore { 25 namespace dataset { 26 27 /// \class DeepCopyPass 28 /// \brief This pass clones a new copy of IR tree. A new copy is used in the compilation to avoid any modification to 29 /// the IR tree associated with the user code. 30 class DeepCopyPass : public IRNodePass { 31 public: 32 /// \brief Constructor 33 DeepCopyPass(); 34 35 /// \brief Destructor 36 ~DeepCopyPass() = default; 37 38 /// \brief Clone a new copy of the node 39 /// \param[in] node The node being visited 40 /// \param[in, out] *modified indicates whether the node has been visited 41 /// \return Status code 42 Status Visit(std::shared_ptr<DatasetNode> node, bool *const modified) override; 43 44 /// \brief Reset parent after walking its sub tree. 45 /// \param[in] node The node being visited 46 /// \param[in, out] *modified indicates whether the node has been visited 47 /// \return Status code 48 Status VisitAfter(std::shared_ptr<DatasetNode> node, bool *const modified) override; 49 50 /// \brief Getter method to retrieve the root node 51 /// \return the root node of the new cloned tree Root()52 std::shared_ptr<RootNode> Root() { return root_; } 53 54 private: 55 std::shared_ptr<RootNode> root_; 56 DatasetNode *parent_; 57 }; 58 } // namespace dataset 59 } // namespace mindspore 60 61 #endif // DATASET_ENGINE_OPT_PRE_DEEP_COPY_PASS_H_ 62