LCOV - code coverage report
Current view: top level - legacy/ascend950/unified_platform/ccu/ccu_representation/reps/control - ccu_rep_jump.cpp (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 69 69
Test Date: 2026-08-18 17:47:01 Functions: 100.0 % 11 11

            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              : 
      15              : namespace Hccl {
      16              : namespace CcuRep {
      17              : 
      18          101 :     CcuRepJumpBase::CcuRepJumpBase(const std::string& label, const Variable& targetInstrId)
      19          101 :         : label(label),
      20          101 :           targetInstrId(targetInstrId)
      21          101 :     {}
      22              : 
      23          100 :     void CcuRepJumpBase::Reference(std::shared_ptr<CcuRepJumpLabel> refRep) { jumpLabel = refRep; }
      24              : 
      25           41 :     CcuRepJump::CcuRepJump(const std::string& label, const Variable& targetInstrId)
      26           41 :         : CcuRepJumpBase(label, targetInstrId)
      27              :     {
      28           41 :         type = CcuRepType::JUMP;
      29           41 :         instrCount = 2; // jump翻译需要2条指令
      30           41 :     }
      31              : 
      32           23 :     bool CcuRepJump::Translate(CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
      33              :     {
      34           23 :         if (this->instr == nullptr) {
      35           12 :             this->instrId = instrId;
      36           12 :             this->instr = instr;
      37           12 :             instr += instrCount;
      38           12 :             instrId += instrCount;
      39              :         }
      40              : 
      41           23 :         if (jumpLabel->Translated()) {
      42           12 :             LoadImdToXnInstr(this->instr + 0, targetInstrId.Id(), jumpLabel->StartInstrId());
      43           12 :             JumpInstr(this->instr + 1, targetInstrId.Id(), dep.reserveXnId, 1);
      44              : 
      45           12 :             translated = true;
      46              :         }
      47              : 
      48           23 :         return translated;
      49              :     }
      50              : 
      51           15 :     std::string CcuRepJump::Describe() { return StringFormat("Jump To Label[%s]", label.c_str()); }
      52              : 
      53           16 :     CcuRepJumpNE::CcuRepJumpNE(
      54           16 :         const std::string& label, const Variable& targetInstrId, const Variable& condition, uint64_t expected)
      55              :         : CcuRepJumpBase(label, targetInstrId),
      56           16 :           condition(condition),
      57           16 :           expected(expected)
      58              :     {
      59           16 :         type = CcuRepType::JUMP_NE;
      60           16 :         instrCount = 2; // jumpNE翻译需要2条指令
      61           16 :     }
      62              : 
      63           28 :     bool CcuRepJumpNE::Translate(CcuInstr*& instr, uint16_t& instrId, [[maybe_unused]] const TransDep& dep)
      64              :     {
      65           28 :         if (this->instr == nullptr) {
      66           16 :             this->instrId = instrId;
      67           16 :             this->instr = instr;
      68           16 :             instr += instrCount;
      69           16 :             instrId += instrCount;
      70              :         }
      71              : 
      72           28 :         if (jumpLabel->Translated()) {
      73           16 :             LoadImdToXnInstr(this->instr + 0, targetInstrId.Id(), jumpLabel->StartInstrId());
      74           16 :             JumpInstr(this->instr + 1, targetInstrId.Id(), condition.Id(), expected);
      75              : 
      76           16 :             translated = true;
      77              :         }
      78              : 
      79           28 :         return translated;
      80              :     }
      81              : 
      82           15 :     std::string CcuRepJumpNE::Describe()
      83              :     {
      84              :         return StringFormat(
      85           30 :             "Jump To Label[%s], When Condition[%u] Not equal to Expected[%lu]", label.c_str(), condition.Id(),
      86           15 :             expected);
      87              :     }
      88              : 
      89           44 :     CcuRepJumpEQ::CcuRepJumpEQ(
      90           44 :         const std::string& label, const Variable& targetInstrId, const Variable& condition, uint64_t expected)
      91              :         : CcuRepJumpBase(label, targetInstrId),
      92           44 :           condition(condition),
      93           44 :           expected(expected)
      94              :     {
      95           44 :         type = CcuRepType::JUMP_EQ;
      96           44 :         instrCount = 5; // jumpEQ翻译需要5条指令
      97           44 :     }
      98              : 
      99           29 :     bool CcuRepJumpEQ::Translate(CcuInstr*& instr, uint16_t& instrId, const TransDep& dep)
     100              :     {
     101           29 :         if (this->instr == nullptr) {
     102           16 :             this->instrId = instrId;
     103           16 :             this->instr = instr;
     104           16 :             instr += instrCount;
     105           16 :             instrId += instrCount;
     106              :         }
     107              : 
     108           29 :         if (jumpLabel->Translated()) {
     109           16 :             uint32_t localInstrIndex = 0;
     110           32 :             LoadImdToXnInstr(
     111           16 :                 this->instr + localInstrIndex++, targetInstrId.Id(),
     112           16 :                 this->instrId + 4); // 需要指向NOP位置,为输入指令Id + 4
     113           16 :             JumpInstr(this->instr + localInstrIndex++, targetInstrId.Id(), condition.Id(), expected);
     114           16 :             LoadImdToXnInstr(this->instr + localInstrIndex++, targetInstrId.Id(), jumpLabel->StartInstrId());
     115           16 :             JumpInstr(this->instr + localInstrIndex++, targetInstrId.Id(), dep.reserveXnId, 1);
     116           16 :             LoadImdToXnInstr(this->instr + localInstrIndex++, dep.reserveXnId, 0);
     117              : 
     118           16 :             translated = true;
     119              :         }
     120              : 
     121           29 :         return translated;
     122              :     }
     123              : 
     124           19 :     std::string CcuRepJumpEQ::Describe()
     125              :     {
     126              :         return StringFormat(
     127           19 :             "Jump To Label[%s], When Condition[%u] Be equal to Expected[%lu]", label.c_str(), condition.Id(), expected);
     128              :     }
     129              : 
     130              : }; // namespace CcuRep
     131              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1