LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/arithmetic - ccu_rep_assign.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 93.8 % 64 60
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 7 7

            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              : 
      13              : #include "string_util.h"
      14              : #include "exception_util.h"
      15              : #include "ccu_api_exception.h"
      16              : 
      17              : namespace Hccl {
      18              : namespace CcuRep {
      19              : 
      20          201 : CcuRepAssign::CcuRepAssign(const Variable &varA, uint64_t immediate)
      21          201 :     : subType(AssignSubType::IMD_TO_VARIABLE), immediate(immediate), varA(varA)
      22              : {
      23          201 :     type       = CcuRepType::ASSIGN;
      24          201 :     instrCount = 1;
      25          201 : }
      26              : 
      27            1 : CcuRepAssign::CcuRepAssign(const Address &addrA, uint64_t immediate)
      28            1 :     : subType(AssignSubType::IMD_TO_ADDR), immediate(immediate), addrA(addrA)
      29              : {
      30            1 :     type       = CcuRepType::ASSIGN;
      31            1 :     instrCount = 1;
      32            1 : }
      33              : 
      34          171 : CcuRepAssign::CcuRepAssign(const Address &addrA, const Variable &varA)
      35          171 :     : subType(AssignSubType::VAR_TO_ADDR), immediate(0), varA(varA), addrA(addrA)
      36              : {
      37          171 :     type       = CcuRepType::ASSIGN;
      38          171 :     instrCount = 1;
      39          171 : }
      40              : 
      41            8 : CcuRepAssign::CcuRepAssign(const Address &addrB, const Address &addrA)
      42            8 :     : subType(AssignSubType::ADDR_TO_ADDR), immediate(0), addrA(addrA), addrB(addrB)
      43              : {
      44            8 :     type       = CcuRepType::ASSIGN;
      45            8 :     instrCount = 1;
      46            8 : }
      47              : 
      48          257 : CcuRepAssign::CcuRepAssign(const Variable &varB, const Variable &varA)
      49          257 :     : subType(AssignSubType::VAR_TO_VAR), immediate(0), varA(varA), varB(varB)
      50              : {
      51          257 :     type       = CcuRepType::ASSIGN;
      52          257 :     instrCount = 1;
      53          257 : }
      54              : 
      55          215 : bool CcuRepAssign::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      56              : {
      57          215 :     CHECK_NULLPTR(instr, "[CcuRepAssign::Translate] instr is nullptr!");
      58          215 :     this->instrId = instrId;
      59          215 :     translated    = true;
      60              : 
      61          215 :     switch (subType) {
      62           86 :         case AssignSubType::IMD_TO_VARIABLE: {
      63           86 :             LoadImdToXnInstr(instr++, varA.Id(), immediate);
      64           86 :             break;
      65              :         }
      66            1 :         case AssignSubType::IMD_TO_ADDR: {
      67            1 :             LoadImdToGSAInstr(instr++, addrA.Id(), immediate);
      68            1 :             break;
      69              :         }
      70           45 :         case AssignSubType::VAR_TO_ADDR: {
      71           45 :             LoadGSAXnInstr(instr++, addrA.Id(), dep.reserveGsaId, varA.Id());
      72           45 :             break;
      73              :         }
      74            8 :         case AssignSubType::ADDR_TO_ADDR: {
      75            8 :             LoadGSAGSAInstr(instr++, addrB.Id(), addrA.Id(), dep.reserveGsaId);
      76            8 :             break;
      77              :         }
      78           75 :         case AssignSubType::VAR_TO_VAR: {
      79           75 :             LoadXXInstr(instr++, varB.Id(), varA.Id(), dep.reserveXnId);
      80           75 :             break;
      81              :         }
      82            0 :         default: {
      83            0 :             THROW<CcuApiException>("Invalid Assign");
      84              :         }
      85              :     }
      86              :     
      87          215 :     CHK_PRT_THROW((instrId > UINT16_MAX - instrCount),
      88              :                         HCCL_ERROR("[CcuRepAssign::Translate]uint16 integer overflow occurs, instrId = [%hu], instrCount = [%hu]", instrId, instrCount),
      89              :                           InternalException, "integer overflow");
      90          215 :     instrId += instrCount;
      91              : 
      92          215 :     return translated;
      93              : }
      94              : 
      95          296 : std::string CcuRepAssign::Describe()
      96              : {
      97          296 :     switch (subType) {
      98          110 :         case AssignSubType::IMD_TO_VARIABLE: {
      99          110 :             return StringFormat("Variable[%u] = Value[%lu]", varA.Id(), immediate);
     100              :         }
     101            2 :         case AssignSubType::IMD_TO_ADDR: {
     102            2 :             return StringFormat("Address[%u] = Value[%lu]", addrA.Id(), immediate);
     103              :         }
     104           63 :         case AssignSubType::VAR_TO_ADDR: {
     105           63 :             return StringFormat("Address[%u] = Variable[%u]", addrA.Id(), varA.Id());
     106              :         }
     107           12 :         case AssignSubType::ADDR_TO_ADDR: {
     108           12 :             return StringFormat("Address[%u] = Address[%u]", addrB.Id(), addrA.Id());
     109              :         }
     110          109 :         case AssignSubType::VAR_TO_VAR: {
     111          109 :             return StringFormat("Var[%u] = Var[%u]", varB.Id(), varA.Id());
     112              :         }
     113            0 :         default: {
     114            0 :             return StringFormat("Invalid Assign");
     115              :         }
     116              :     }
     117              : }
     118              : 
     119              : }; // namespace CcuRep
     120              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1