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-08-04 10:52:23 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) : label(label), targetInstrId(targetInstrId)
      19              : {
      20          101 : }
      21              : 
      22          100 : void CcuRepJumpBase::Reference(std::shared_ptr<CcuRepJumpLabel> refRep)
      23              : {
      24          100 :     jumpLabel = refRep;
      25          100 : }
      26              : 
      27           41 : CcuRepJump::CcuRepJump(const std::string &label, const Variable &targetInstrId) : CcuRepJumpBase(label, targetInstrId)
      28              : {
      29           41 :     type       = CcuRepType::JUMP;
      30           41 :     instrCount = 2; // jump翻译需要2条指令
      31           41 : }
      32              : 
      33           23 : bool CcuRepJump::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      34              : {
      35           23 :     if (this->instr == nullptr) {
      36           12 :         this->instrId = instrId;
      37           12 :         this->instr   = instr;
      38           12 :         instr += instrCount;
      39           12 :         instrId += instrCount;
      40              :     }
      41              : 
      42           23 :     if (jumpLabel->Translated()) {
      43           12 :         LoadImdToXnInstr(this->instr + 0, targetInstrId.Id(), jumpLabel->StartInstrId());
      44           12 :         JumpInstr(this->instr + 1, targetInstrId.Id(), dep.reserveXnId, 1);
      45              : 
      46           12 :         translated = true;
      47              :     }
      48              : 
      49           23 :     return translated;
      50              : }
      51              : 
      52           15 : std::string CcuRepJump::Describe()
      53              : {
      54           15 :     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           44 : CcuRepJumpEQ::CcuRepJumpEQ(const std::string &label, const Variable &targetInstrId, const Variable &condition, uint64_t expected)
      90           44 :     : CcuRepJumpBase(label, targetInstrId), condition(condition), expected(expected)
      91              : {
      92           44 :     type       = CcuRepType::JUMP_EQ;
      93           44 :     instrCount = 5; // jumpEQ翻译需要5条指令
      94           44 : }
      95              : 
      96           29 : bool CcuRepJumpEQ::Translate(CcuInstr *&instr, uint16_t &instrId, const TransDep &dep)
      97              : {
      98           29 :     if (this->instr == nullptr) {
      99           16 :         this->instrId = instrId;
     100           16 :         this->instr   = instr;
     101           16 :         instr += instrCount;
     102           16 :         instrId += instrCount;
     103              :     }
     104              : 
     105           29 :     if (jumpLabel->Translated()) {
     106           16 :         uint32_t localInstrIndex = 0;
     107           16 :         LoadImdToXnInstr(this->instr + localInstrIndex++, targetInstrId.Id(),
     108           16 :                          this->instrId + 4); // 需要指向NOP位置,为输入指令Id + 4
     109           16 :         JumpInstr(this->instr + localInstrIndex++, targetInstrId.Id(), condition.Id(), expected);
     110           16 :         LoadImdToXnInstr(this->instr + localInstrIndex++, targetInstrId.Id(), jumpLabel->StartInstrId());
     111           16 :         JumpInstr(this->instr + localInstrIndex++, targetInstrId.Id(), dep.reserveXnId, 1);
     112           16 :         LoadImdToXnInstr(this->instr + localInstrIndex++, dep.reserveXnId, 0);
     113              : 
     114           16 :         translated = true;
     115              :     }
     116              : 
     117           29 :     return translated;
     118              : }
     119              : 
     120           19 : std::string CcuRepJumpEQ::Describe()
     121              : {
     122           38 :     return StringFormat("Jump To Label[%s], When Condition[%u] Be equal to Expected[%lu]", label.c_str(), condition.Id(),
     123           19 :                         expected);
     124              : }
     125              : 
     126              : }; // namespace CcuRep
     127              : }; // namespace Hccl
        

Generated by: LCOV version 2.0-1