LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/loop - ccu_rep_loop.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 79.4 % 34 27
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 6 6

            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.h"
      12              : #include <climits>
      13              : 
      14              : #include "string_util.h"
      15              : #include "exception_util.h"
      16              : #include "ccu_api_exception.h"
      17              : 
      18              : namespace Hccl {
      19              : namespace CcuRep {
      20              : 
      21           59 : CcuRepLoop::CcuRepLoop(const std::string &label, const Variable &loopParam) : label(label), loopParam(loopParam)
      22              : {
      23           59 :     type       = CcuRepType::LOOP;
      24           59 :     instrCount = 1; // loop翻译需要1条指令
      25           59 : }
      26              : 
      27           16 : const std::string &CcuRepLoop::GetLabel() const
      28              : {
      29           16 :     return label;
      30              : }
      31              : 
      32           17 : void CcuRepLoop::Reference(std::shared_ptr<CcuRepLoopBlock> refRep)
      33              : {
      34           17 :     loopBlock = refRep;
      35           17 : }
      36              : 
      37           57 : std::shared_ptr<CcuRepBase> CcuRepLoop::SetLoopParam(Executor executor, Variable var)
      38              : {
      39           57 :     return std::make_shared<CcuRepSetLoop>(loopParam, executor, var);
      40              : }
      41              : 
      42           15 : bool CcuRepLoop::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      43              : {
      44           15 :     this->instrId = instrId;
      45           15 :     translated    = true;
      46              : 
      47           15 :     Hccl::CHECK_NULLPTR(loopBlock, "[CcuRepLoop::Translate] LoopBlock is nullptr!");
      48              : 
      49           15 :     if (!loopBlock->Translated()) {
      50            0 :         THROW<CcuApiException>("Reference To Invalid LoopBlock");
      51              :     }
      52              : 
      53           15 :     uint16_t startInstrId = loopBlock->StartInstrId();
      54           15 :     uint16_t loopInstrCount = loopBlock->InstrCount();
      55           15 :     if (loopInstrCount == 0) {
      56            0 :         HCCL_ERROR("[CcuRepLoop][Translate] loopInstrCount[%u] is 0, which causes underflow in endInstrId calculation.",
      57              :                     loopInstrCount);
      58            0 :         return false;
      59              :     }
      60           15 :     if (startInstrId > USHRT_MAX - loopInstrCount) {
      61            0 :         HCCL_ERROR("[CcuRepLoop][Translate] startInstrId[%u] + loopInstrCount[%u] exceeds the maximum value of unsigned short int.",
      62              :                     startInstrId, loopInstrCount);
      63            0 :         return false;
      64              :     }
      65           15 :     if (instrId > USHRT_MAX - instrCount) {
      66            0 :         HCCL_ERROR("[CcuRepLoop][Translate] instrId[%u] + instrCount[%u] exceeds the maximum value of unsigned short int.",
      67              :                     instrId, instrCount);
      68            0 :         return false;
      69              :     }
      70           15 :     uint16_t endInstrId = startInstrId + loopInstrCount - 1;
      71              : 
      72           15 :     LoopInstr(instr++, startInstrId, endInstrId, loopParam.Id());
      73              : 
      74           15 :     instrId += instrCount;
      75              : 
      76           15 :     return translated;
      77              : }
      78              : 
      79           24 : std::string CcuRepLoop::Describe()
      80              : {
      81           24 :     return StringFormat("Loop reference to [%s]", label.c_str());
      82              : }
      83              : 
      84              : }; // namespace CcuRep
      85              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1