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

Generated by: LCOV version 2.0-1