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: 98.0 % 50 49
Test Date: 2026-08-04 10:52:23 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         2485 : CcuRepReferenceManager::CcuRepReferenceManager(uint8_t deiId) : dieId(deiId)
      19              : {
      20         2485 :     funcInVar.resize(FUNC_ARG_MAX);
      21         2485 :     funcOutVar.resize(FUNC_ARG_MAX);
      22         2485 :     funcCallVar.resize(1 + FUNC_NEST_MAX + 1); // FUNC_NEST_MAX个xn存放返回地址,1个xn存放block的起始地址和1个xn存放函数地址调用时返回地址
      23         2485 : }
      24              : 
      25         2466 : CcuResReq CcuRepReferenceManager::GetResReq(uint8_t reqDieId)
      26              : {
      27              :     // 申请离散 xn 资源
      28         2466 :     CcuResReq resReq;
      29         2466 :     resReq.xnReq[reqDieId] = FUNC_ARG_MAX + FUNC_ARG_MAX + 1 + FUNC_NEST_MAX + 1;
      30         2466 :     return resReq;
      31              : }
      32              : 
      33         2465 : void CcuRepReferenceManager::GetRes(CcuRepResource &res)
      34              : {
      35         2465 :     res.variable[dieId].insert(res.variable[dieId].end(),
      36              :         funcInVar.begin(), funcInVar.end());
      37         2465 :     res.variable[dieId].insert(res.variable[dieId].end(),
      38              :         funcOutVar.begin(), funcOutVar.end());
      39         2465 :     res.variable[dieId].insert(res.variable[dieId].end(),
      40              :         funcCallVar.begin(), funcCallVar.end());
      41         2465 : }
      42              : 
      43           13 : bool CcuRepReferenceManager::CheckValid(const std::string &label)
      44              : {
      45           13 :     return (referenceMap.find(label) != referenceMap.end());
      46              : }
      47              : 
      48           56 : bool CcuRepReferenceManager::CheckUnique(const std::string &label)
      49              : {
      50           56 :     return (referenceMap.find(label) == referenceMap.end());
      51              : }
      52              : 
      53           11 : std::shared_ptr<CcuRepBlock> CcuRepReferenceManager::GetRefBlock(const std::string &label)
      54              : {
      55           11 :     if (!CheckValid(label)) {
      56            2 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      57              :     }
      58            9 :     return referenceMap[label];
      59              : }
      60              : 
      61           56 : void CcuRepReferenceManager::SetRefBlock(const std::string &label, std::shared_ptr<CcuRepBlock> refBlock)
      62              : {
      63           56 :     if (!CheckUnique(label)) {
      64            1 :         Hccl::THROW<Hccl::CcuApiException>("Duplicate Definition: %s", label.c_str());
      65              :     }
      66           55 :     referenceMap[label] = refBlock;
      67           55 : }
      68              : 
      69            2 : uint16_t CcuRepReferenceManager::GetFuncAddr(const std::string &label)
      70              : {
      71            2 :     if (!CheckValid(label)) {
      72            1 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Reference: %s", label.c_str());
      73              :     }
      74              : 
      75            1 :     if (referenceMap[label]->Type() != CcuRepType::FUNC_BLOCK) {
      76            1 :         Hccl::THROW<Hccl::CcuApiException>("Invalid Type, %s Must be FuncBlock", label.c_str());
      77              :     }
      78              : 
      79            0 :     return referenceMap[label]->StartInstrId();
      80              : }
      81              : 
      82           11 : const Variable &CcuRepReferenceManager::GetFuncCall()
      83              : {
      84           11 :     return funcCallVar[0];
      85              : }
      86              : 
      87           12 : const Variable &CcuRepReferenceManager::GetFuncRet(uint16_t callLayer)
      88              : {
      89           12 :     if (callLayer > FUNC_NEST_MAX) {
      90            1 :         Hccl::THROW<Hccl::CcuApiException>("Max Func Call Nest Num is %u, callLayer = %u", FUNC_NEST_MAX, callLayer);
      91              :     }
      92           11 :     return funcCallVar[callLayer + 1];
      93              : }
      94              : 
      95          137 : const std::vector<Variable> &CcuRepReferenceManager::GetFuncIn()
      96              : {
      97          137 :     return funcInVar;
      98              : }
      99              : 
     100            1 : const std::vector<Variable> &CcuRepReferenceManager::GetFuncOut()
     101              : {
     102            1 :     return funcOutVar;
     103              : }
     104              : 
     105            1 : void CcuRepReferenceManager::Dump() const
     106              : {
     107            2 :     for (const auto &kv : referenceMap) {
     108            1 :         HCCL_INFO("refBlock[%s]:", kv.first.c_str());
     109              :     }
     110            1 : }
     111              : 
     112         1026 : void CcuRepReferenceManager::ClearRepReference()
     113              : {
     114         1026 :     referenceMap.clear();
     115         1026 : }
     116              : 
     117              : }; // namespace CcuRep
     118              : }; // namespace hcomm
        

Generated by: LCOV version 2.0-1