LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_rep_reference_manager.cc (source / functions) Coverage Total Hit
Test: coverage.info Lines: 97.8 % 45 44
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 14 14

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "ccu_rep_reference_manager_v1.h"
      12              : #include "exception_util.h"
      13              : #include "ccu_api_exception.h"
      14              : 
      15              : namespace hcomm {
      16              : namespace CcuRep {
      17              : 
      18         2965 :     CcuRepReferenceManager::CcuRepReferenceManager(uint8_t deiId) : dieId(deiId)
      19              :     {
      20         2965 :         funcInVar.resize(FUNC_ARG_MAX);
      21         2965 :         funcOutVar.resize(FUNC_ARG_MAX);
      22         2965 :         funcCallVar.resize(
      23              :             1 + FUNC_NEST_MAX
      24              :             + 1); // FUNC_NEST_MAX个xn存放返回地址,1个xn存放block的起始地址和1个xn存放函数地址调用时返回地址
      25         2965 :     }
      26              : 
      27         2946 :     CcuResReq CcuRepReferenceManager::GetResReq(uint8_t reqDieId)
      28              :     {
      29              :         // 申请离散 xn 资源
      30         2946 :         CcuResReq resReq;
      31         2946 :         resReq.xnReq[reqDieId] = FUNC_ARG_MAX + FUNC_ARG_MAX + 1 + FUNC_NEST_MAX + 1;
      32         2946 :         return resReq;
      33              :     }
      34              : 
      35         2945 :     void CcuRepReferenceManager::GetRes(CcuRepResource& res)
      36              :     {
      37         2945 :         res.variable[dieId].insert(res.variable[dieId].end(), funcInVar.begin(), funcInVar.end());
      38         2945 :         res.variable[dieId].insert(res.variable[dieId].end(), funcOutVar.begin(), funcOutVar.end());
      39         2945 :         res.variable[dieId].insert(res.variable[dieId].end(), funcCallVar.begin(), funcCallVar.end());
      40         2945 :     }
      41              : 
      42           13 :     bool CcuRepReferenceManager::CheckValid(const std::string& label)
      43              :     {
      44           13 :         return (referenceMap.find(label) != referenceMap.end());
      45              :     }
      46              : 
      47           56 :     bool CcuRepReferenceManager::CheckUnique(const std::string& label)
      48              :     {
      49           56 :         return (referenceMap.find(label) == referenceMap.end());
      50              :     }
      51              : 
      52           11 :     std::shared_ptr<CcuRepBlock> CcuRepReferenceManager::GetRefBlock(const std::string& label)
      53              :     {
      54           11 :         if (!CheckValid(label)) {
      55            2 :             Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      56              :         }
      57            9 :         return referenceMap[label];
      58              :     }
      59              : 
      60           56 :     void CcuRepReferenceManager::SetRefBlock(const std::string& label, std::shared_ptr<CcuRepBlock> refBlock)
      61              :     {
      62           56 :         if (!CheckUnique(label)) {
      63            1 :             Hccl::THROW<Hccl::CcuApiException>("Duplicate Definition: %s", label.c_str());
      64              :         }
      65           55 :         referenceMap[label] = refBlock;
      66           55 :     }
      67              : 
      68            2 :     uint16_t CcuRepReferenceManager::GetFuncAddr(const std::string& label)
      69              :     {
      70            2 :         if (!CheckValid(label)) {
      71            1 :             Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      72              :         }
      73              : 
      74            1 :         if (referenceMap[label]->Type() != CcuRepType::FUNC_BLOCK) {
      75            1 :             Hccl::THROW<Hccl::CcuApiException>("Invalid Type, %s Must be FuncBlock", label.c_str());
      76              :         }
      77              : 
      78            0 :         return referenceMap[label]->StartInstrId();
      79              :     }
      80              : 
      81           11 :     const Variable& CcuRepReferenceManager::GetFuncCall() { return funcCallVar[0]; }
      82              : 
      83           12 :     const Variable& CcuRepReferenceManager::GetFuncRet(uint16_t callLayer)
      84              :     {
      85           12 :         if (callLayer > FUNC_NEST_MAX) {
      86            1 :             Hccl::THROW<Hccl::CcuApiException>(
      87              :                 "Max Func Call Nest Num is %u, callLayer = %u", FUNC_NEST_MAX, callLayer);
      88              :         }
      89           11 :         return funcCallVar[callLayer + 1];
      90              :     }
      91              : 
      92          181 :     const std::vector<Variable>& CcuRepReferenceManager::GetFuncIn() { return funcInVar; }
      93              : 
      94            1 :     const std::vector<Variable>& CcuRepReferenceManager::GetFuncOut() { return funcOutVar; }
      95              : 
      96            1 :     void CcuRepReferenceManager::Dump() const
      97              :     {
      98            2 :         for (const auto& kv : referenceMap) {
      99            1 :             HCCL_INFO("refBlock[%s]:", kv.first.c_str());
     100              :         }
     101            1 :     }
     102              : 
     103         1378 :     void CcuRepReferenceManager::ClearRepReference() { referenceMap.clear(); }
     104              : 
     105              : }; // namespace CcuRep
     106              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1