LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_ins_generator_v2.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 2 2
Test Date: 2026-08-18 17:47:01 Functions: 66.7 % 3 2

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2026 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              : #ifndef CCU_INS_GENERATOR_V2
      12              : #define CCU_INS_GENERATOR_V2
      13              : 
      14              : #include "ccu_ins_generator_base.h"
      15              : 
      16              : namespace hcomm {
      17              : 
      18              : namespace CcuRep {
      19              : 
      20              :     class CcuInsGeneratorV2 : public CcuInsGeneratorBase {
      21              :     public:
      22          204 :         CcuInsGeneratorV2() {}
      23              : 
      24              :         // 虚析构函数,确保派生类对象正确析构
      25           68 :         virtual ~CcuInsGeneratorV2() = default;
      26              : 
      27              :         // data
      28              :         HcclResult CcuRepBufLocReadTranslate(
      29              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufLocRead* repBufLocRead, const TransDep& dep) override;
      30              :         HcclResult CcuRepBufLocWriteTranslate(
      31              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufLocWrite* repBufLocWrite, const TransDep& dep) override;
      32              :         HcclResult CcuRepBufReadTranslate(
      33              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufRead* repBufRead, const TransDep& dep) override;
      34              :         HcclResult
      35              :         CcuRepBufReduceTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufReduce* ccuRepBufReduce) override;
      36              :         HcclResult CcuRepBufWriteTranslate(
      37              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufWrite* ccuRepBufWrite, const TransDep& dep) override;
      38              :         HcclResult CcuRepLocCpyTranslate(
      39              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocCpy* ccuRepLocCpy, const TransDep& dep) override;
      40              :         HcclResult CcuRepReadTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRead* repRemMem) override;
      41              :         HcclResult CcuRepRemMemTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemMem* repRemMem) override;
      42              :         HcclResult CcuRepWriteTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepWrite* repWrite) override;
      43              : 
      44              :         // sync
      45              :         HcclResult CcuRepLocRecordEventTranslate(
      46              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocRecordEvent* ccuRepLocRecordEvent) override;
      47              :         HcclResult CcuRepLocWaitEventTranslate(
      48              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocWaitEvent* ccuRepLocWaitEvent) override;
      49              :         HcclResult CcuRepLocWaitNotifyTranslate(
      50              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocWaitNotify* ccuRepLocWaitNotify) override;
      51              :         HcclResult CcuRepRecordSharedNotifyTranslate(
      52              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRecordSharedNotify* ccuRepRecordSharedNotify,
      53              :             const TransDep& dep) override;
      54              :         HcclResult
      55              :         CcuRepRemWaitSemTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemWaitSem* cuRepRemWaitSem) override;
      56              :         HcclResult
      57              :         CcuRepRemPostVarTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemPostVar* ccuRepRemPostVar) override;
      58              :         HcclResult CcuRepRemPostSemTranslate(
      59              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemPostSem* ccuRepRemPostSem, const TransDep& dep) override;
      60              : 
      61              :         // logical
      62              :         HcclResult
      63              :         CcuRepAndTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAnd* ccuRepAnd, const TransDep& dep) override;
      64              :         HcclResult
      65              :         CcuRepNotTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepNot* ccuRepNot, const TransDep& dep) override;
      66              :         HcclResult
      67              :         CcuRepOrTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepOr* ccuRepOr, const TransDep& dep) override;
      68              :         HcclResult
      69              :         CcuRepXorTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepXor* ccuRepXor, const TransDep& dep) override;
      70              : 
      71              :         // shift
      72              :         HcclResult
      73              :         CcuRepShLTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepShL* ccuRepShL, const TransDep& dep) override;
      74              :         HcclResult
      75              :         CcuRepShRTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepShR* ccuRepShR, const TransDep& dep) override;
      76              : 
      77              :         // arithmetic
      78              :         HcclResult
      79              :         CcuRepAddTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAdd* ccuRepAdd, const TransDep& dep) override;
      80              :         HcclResult CcuRepAssignTranslate(
      81              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAssign* ccuRepAssign, const TransDep& dep) override;
      82              :         HcclResult CcuRepMulTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepMul* ccuRepMul) override;
      83              :         HcclResult CcuRepSubTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepSub* ccuRepSub) override;
      84              : 
      85              :         // control
      86              :         HcclResult CcuRepFuncBlockTranslate(
      87              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, CcuRepFuncBlock* funcBlockPtr,
      88              :             const TransDep& dep, uint32_t step) override;
      89              :         HcclResult CcuRepFuncCallTranslate(
      90              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepFuncCall* funcCallPtr,
      91              :             const TransDep& dep) override;
      92              :         HcclResult CcuRepJumpTranslate(
      93              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJump* jumpPtr,
      94              :             const TransDep& dep) override;
      95              :         HcclResult CcuRepJumpNETranslate(
      96              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpNE* jumpNEPtr,
      97              :             const TransDep& dep) override;
      98              :         HcclResult CcuRepJumpEQTranslate(
      99              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpEQ* jumpEQPtr,
     100              :             const TransDep& dep) override;
     101              :         HcclResult CcuRepJumpLETranslate(
     102              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpLE* jumpLEPtr,
     103              :             const TransDep& dep) override;
     104              :         HcclResult CcuRepJumpGETranslate(
     105              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpGE* jumpGEPtr,
     106              :             const TransDep& dep) override;
     107              :         HcclResult CcuRepJumpGTTranslate(
     108              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpGT* jumpGTPtr,
     109              :             const TransDep& dep) override;
     110              :         HcclResult CcuRepJumpLTTranslate(
     111              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpLT* jumpLTPtr,
     112              :             const TransDep& dep) override;
     113              : 
     114              :         // loop
     115              :         HcclResult
     116              :         CcuRepLoopTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoop* loopPtr) override;
     117              :         HcclResult CcuRepLoopCallTranslate(
     118              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopCall* loopCallPtr,
     119              :             const TransDep& dep) override;
     120              :         HcclResult CcuRepSetLoopTranslate(
     121              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepSetLoop* setLoopPtr) override;
     122              :         HcclResult CcuRepLoopGroupBundleTranslate(
     123              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopGroupBundle* bundlePtr,
     124              :             const TransDep& dep) override;
     125              :         uint16_t CcuRepLoopGroupBundleInstrCount(CcuRepLoopGroupBundle* bundlePtr) override;
     126              : 
     127              :         // common
     128              :         HcclResult CcuRepLoadTranslate(
     129              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoad* loadPtr,
     130              :             const TransDep& dep) override;
     131              :         HcclResult CcuRepLoadVarTranslate(
     132              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoadVar* loadVarPtr,
     133              :             const TransDep& dep) override;
     134              :         HcclResult CcuRepLoadArgTranslate(
     135              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoadArg* loadArgPtr,
     136              :             const TransDep& dep) override;
     137              :         HcclResult CcuRepNopTranslate(
     138              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepNop* nopPtr,
     139              :             const TransDep& dep) override;
     140              :         HcclResult CcuRepStoreTranslate(
     141              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepStore* storePtr,
     142              :             const TransDep& dep) override;
     143              :         HcclResult CcuRepStoreVarTranslate(
     144              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepStoreVar* storeVarPtr,
     145              :             const TransDep& dep) override;
     146              : 
     147              :         uint32_t GetInstrCount(CcuRepType repType) override;
     148              : 
     149              :         HcclResult PrepareConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel) override;
     150              : 
     151              :     private:
     152              :         HcclResult CcuRepJumpTranslateV2Base(
     153              :             CcuInstr*& curInstr, uint16_t& curInstrId, CcuRepJumpBase* jumpBasePtr, uint64_t expected,
     154              :             const Variable& condition, const Variable& expectedVar, ConditionType condType);
     155              : 
     156              :         void LoadFuncCallInArgs(
     157              :             CcuInstr* instr, std::vector<CcuRepArg>& inArgs, std::vector<Variable>& formalIns, uint16_t reserveXnId);
     158              :         void LoadFuncCallOutArgs(
     159              :             CcuInstr* instr, uint32_t offset, std::vector<CcuRepArg>& outArgs, CcuRepReferenceManager* funcManager,
     160              :             uint16_t reserveXnId);
     161              :         HcclResult LoadLoopCallArg(CcuInstr*& instr, const CcuRepArg& inArg, const CcuRepArg& blkArg);
     162              :         HcclResult PrepareLoadConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     163              :         HcclResult PrepareLoadVarConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     164              :         HcclResult PrepareStoreConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     165              :         HcclResult PrepareStoreVarConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     166              :         HcclResult PrepareRemPostSemConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     167              :         HcclResult PrepareRemPostVarConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     168              :         HcclResult PrepareWriteConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     169              :         HcclResult PrepareReadConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     170              :         HcclResult PrepareBufWriteConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     171              :         HcclResult PrepareBufReadConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     172              :         HcclResult PrepareLocCpyConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     173              :         HcclResult PrepareRecordSharedNotifyConstValue(CcuRepBase* repPtr, const TransDep& dep, CcuKernel* ccuKernel);
     174              :         HcclResult LoopConfigTranslate(
     175              :             CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopGroupBundle* bundlePtr, const TransDep& dep);
     176              :         HcclResult LoopGroupConfigTranslate(
     177              :             CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopGroupBundle* bundlePtr, const TransDep& dep,
     178              :             bool isConfig, bool isCompat, uint16_t& loopGroupConfigId);
     179              : 
     180              :         static constexpr uint32_t V2_FUNC_BLOCK_INSTR_NUM = 11; // FuncBlock: RelJmp(9)+Jump(1)+Nop(1)
     181              :         static constexpr uint32_t V2_FUNC_CALL_INSTR_NUM = 13;  // FuncCall: FuncBlock(11)+Call(2)
     182              : 
     183              :         std::unordered_map<CcuRepType, uint32_t> repTypeInstrCount
     184              :             = {{CcuRepType::READ, 1},
     185              :                {CcuRepType::WRITE, 1},
     186              :                {CcuRepType::REM_MEM, 2},
     187              :                {CcuRepType::BUF_READ, 1},
     188              :                {CcuRepType::LOCAL_CPY, 1},
     189              :                {CcuRepType::LOCAL_REDUCE, 1},
     190              :                {CcuRepType::BUF_WRITE, 1},
     191              :                {CcuRepType::BUF_REDUCE, 1},
     192              :                {CcuRepType::BUF_LOC_READ, 1},
     193              :                {CcuRepType::BUF_LOC_WRITE, 1},
     194              : 
     195              :                {CcuRepType::ASSIGN, 1},
     196              :                {CcuRepType::ADD, 1},
     197              :                {CcuRepType::MUL, 1},
     198              :                {CcuRepType::SUB, 1},
     199              : 
     200              :                {CcuRepType::LOC_RECORD_EVENT, 1},
     201              :                {CcuRepType::LOC_WAIT_EVENT, 1},
     202              :                {CcuRepType::LOC_WAIT_NOTIFY, 1},
     203              :                {CcuRepType::RECORD_SHARED_NOTIFY, 1},
     204              :                {CcuRepType::REM_POST_SEM, 1},
     205              :                {CcuRepType::REM_POST_VAR, 1},
     206              :                {CcuRepType::REM_WAIT_SEM, 1},
     207              : 
     208              :                {CcuRepType::FUNC_BLOCK, V2_FUNC_BLOCK_INSTR_NUM},
     209              :                {CcuRepType::FUNC_CALL, V2_FUNC_CALL_INSTR_NUM},
     210              :                {CcuRepType::JUMP, 2},
     211              :                {CcuRepType::JUMP_NE, 3},
     212              :                {CcuRepType::JUMP_EQ, 3},
     213              :                {CcuRepType::LOOP, 1},
     214              :                {CcuRepType::LOOPGROUP, 1},
     215              :                {CcuRepType::SET_LOOP, 1},
     216              : 
     217              :                {CcuRepType::LOAD, 3},
     218              :                {CcuRepType::LOAD_VAR, 3},
     219              :                {CcuRepType::LOAD_ARG, 1},
     220              :                {CcuRepType::STORE, 3},
     221              :                {CcuRepType::STORE_VAR, 3},
     222              : 
     223              :                {CcuRepType::WRITE_WITH_ARRIVE_NOTIFY, 1},
     224              :                {CcuRepType::CLEAR_ALL_ARRIVE_NOTIFY, 1},
     225              :                {CcuRepType::RECORD_EXPECT_COUNT, 1},
     226              :                {CcuRepType::WAIT_ALL_PEERS_ARRIVE_NOTIFY, 1},
     227              : 
     228              :                {CcuRepType::AND, 1},
     229              :                {CcuRepType::NOT, 1},
     230              :                {CcuRepType::OR, 1},
     231              :                {CcuRepType::XOR, 1},
     232              :                {CcuRepType::SHL, 1},
     233              :                {CcuRepType::SHR, 1},
     234              : 
     235              :                {CcuRepType::NOP, 1}};
     236              :     };
     237              : 
     238              :     uint32_t GetRelativeInstrId(uint32_t currentInstrId, uint32_t targetInstrId);
     239              : 
     240              : } // namespace CcuRep
     241              : } // namespace hcomm
     242              : 
     243              : #endif
        

Generated by: LCOV version 2.0-1