LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/translator - ccu_rep_reference_manager.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 78.0 % 50 39
Test Date: 2026-08-04 10:52:23 Functions: 85.7 % 14 12

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

Generated by: LCOV version 2.0-1