LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_ins_generator_v1.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_V1
      12              : #define CCU_INS_GENERATOR_V1
      13              : 
      14              : #include "ccu_ins_generator_base.h"
      15              : namespace hcomm {
      16              : namespace CcuRep {
      17              : 
      18              :     class CcuInsGeneratorV1 : public CcuInsGeneratorBase {
      19              :     public:
      20          918 :         CcuInsGeneratorV1() {}
      21              : 
      22              :         // 虚析构函数,确保派生类对象正确析构
      23          306 :         virtual ~CcuInsGeneratorV1() = default;
      24              : 
      25              :         // data
      26              :         HcclResult CcuRepLocCpyTranslate(
      27              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocCpy* ccuRepLocCpy, const TransDep& dep) override;
      28              :         HcclResult CcuRepReadTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRead* repRemMem) override;
      29              :         HcclResult CcuRepRemMemTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemMem* repRemMem) override;
      30              :         HcclResult CcuRepWriteTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepWrite* repWrite) override;
      31              :         HcclResult CcuRepBufLocReadTranslate(
      32              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufLocRead* repBufLocRead, const TransDep& dep) override;
      33              :         HcclResult CcuRepBufLocWriteTranslate(
      34              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufLocWrite* repBufLocWrite, const TransDep& dep) override;
      35              :         HcclResult CcuRepBufWriteTranslate(
      36              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufWrite* ccuRepBufWrite, const TransDep& dep) override;
      37              :         HcclResult CcuRepBufReadTranslate(
      38              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufRead* repBufRead, const TransDep& dep) override;
      39              :         HcclResult
      40              :         CcuRepBufReduceTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepBufReduce* ccuRepBufReduce) override;
      41              : 
      42              :         // sync
      43              :         HcclResult CcuRepRecordSharedNotifyTranslate(
      44              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRecordSharedNotify* ccuRepRecordSharedNotify,
      45              :             const TransDep& dep) override;
      46              :         HcclResult
      47              :         CcuRepRemPostVarTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemPostVar* ccuRepRemPostVar) override;
      48              :         HcclResult CcuRepRemPostSemTranslate(
      49              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemPostSem* ccuRepRemPostSem, const TransDep& dep) override;
      50              :         HcclResult
      51              :         CcuRepRemWaitSemTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepRemWaitSem* cuRepRemWaitSem) override;
      52              :         HcclResult CcuRepLocRecordEventTranslate(
      53              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocRecordEvent* ccuRepLocRecordEvent) override;
      54              :         HcclResult CcuRepLocWaitEventTranslate(
      55              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocWaitEvent* ccuRepLocWaitEvent) override;
      56              :         HcclResult CcuRepLocWaitNotifyTranslate(
      57              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepLocWaitNotify* ccuRepLocWaitNotify) override;
      58              : 
      59              :         // logical
      60              :         HcclResult
      61              :         CcuRepOrTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepOr* ccuRepOr, const TransDep& dep) override;
      62              :         HcclResult
      63              :         CcuRepXorTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepXor* ccuRepXor, const TransDep& dep) override;
      64              :         HcclResult
      65              :         CcuRepAndTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAnd* ccuRepAnd, const TransDep& dep) override;
      66              :         HcclResult
      67              :         CcuRepNotTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepNot* ccuRepNot, const TransDep& dep) override;
      68              : 
      69              :         // arithmetic
      70              :         HcclResult
      71              :         CcuRepAddTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAdd* ccuRepAdd, const TransDep& dep) override;
      72              :         HcclResult CcuRepAssignTranslate(
      73              :             CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepAssign* ccuRepAssign, const TransDep& dep) override;
      74              :         HcclResult CcuRepMulTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepMul* ccuRepMul) override;
      75              :         HcclResult CcuRepSubTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepSub* ccuRepSub) override;
      76              : 
      77              :         // shift
      78              :         HcclResult
      79              :         CcuRepShLTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepShL* ccuRepShL, const TransDep& dep) override;
      80              :         HcclResult
      81              :         CcuRepShRTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, CcuRepShR* ccuRepShR, const TransDep& dep) override;
      82              : 
      83              :         // loop
      84              :         HcclResult
      85              :         CcuRepLoopTranslate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoop* loopPtr) override;
      86              :         HcclResult CcuRepLoopCallTranslate(
      87              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopCall* loopCallPtr,
      88              :             const TransDep& dep) override;
      89              :         HcclResult CcuRepSetLoopTranslate(
      90              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepSetLoop* setLoopPtr) override;
      91              :         HcclResult CcuRepLoopGroupBundleTranslate(
      92              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoopGroupBundle* bundlePtr,
      93              :             const TransDep& dep) override;
      94              :         uint16_t CcuRepLoopGroupBundleInstrCount(CcuRepLoopGroupBundle* bundlePtr) override;
      95              : 
      96              :         // control
      97              :         HcclResult CcuRepFuncBlockTranslate(
      98              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& instrId, CcuRepFuncBlock* funcBlockPtr,
      99              :             const TransDep& dep, uint32_t step) override;
     100              :         HcclResult CcuRepFuncCallTranslate(
     101              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepFuncCall* funcCallPtr,
     102              :             const TransDep& dep) override;
     103              :         HcclResult CcuRepJumpTranslate(
     104              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJump* jumpPtr,
     105              :             const TransDep& dep) override;
     106              :         HcclResult CcuRepJumpEQTranslate(
     107              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpEQ* jumpEQPtr,
     108              :             const TransDep& dep) override;
     109              :         HcclResult CcuRepJumpNETranslate(
     110              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpNE* jumpNEPtr,
     111              :             const TransDep& dep) override;
     112              :         HcclResult CcuRepJumpGETranslate(
     113              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpGE* jumpGEPtr,
     114              :             const TransDep& dep) override;
     115              :         HcclResult CcuRepJumpLETranslate(
     116              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpLE* jumpLEPtr,
     117              :             const TransDep& dep) override;
     118              :         HcclResult CcuRepJumpLTTranslate(
     119              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpLT* jumpLTPtr,
     120              :             const TransDep& dep) override;
     121              :         HcclResult CcuRepJumpGTTranslate(
     122              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepJumpGT* jumpGTPtr,
     123              :             const TransDep& dep) override;
     124              : 
     125              :         // common
     126              :         HcclResult CcuRepLoadTranslate(
     127              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoad* loadPtr,
     128              :             const TransDep& dep) override;
     129              :         HcclResult CcuRepLoadVarTranslate(
     130              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoadVar* loadVarPtr,
     131              :             const TransDep& dep) override;
     132              :         HcclResult CcuRepLoadArgTranslate(
     133              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepLoadArg* loadArgPtr,
     134              :             const TransDep& dep) override;
     135              :         HcclResult CcuRepStoreTranslate(
     136              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepStore* storePtr,
     137              :             const TransDep& dep) override;
     138              :         HcclResult CcuRepStoreVarTranslate(
     139              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepStoreVar* storeVarPtr,
     140              :             const TransDep& dep) override;
     141              :         HcclResult CcuRepNopTranslate(
     142              :             CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, CcuRepNop* nopPtr,
     143              :             const TransDep& dep) override;
     144              : 
     145              :         uint32_t GetInstrCount(CcuRepType repType) override;
     146              : 
     147              :     private:
     148              :         void LoadFuncCallInArgs(
     149              :             CcuInstr* instr, std::vector<CcuRepArg>& inArgs, std::vector<Variable>& formalIns, uint16_t reserveXnId);
     150              :         void LoadFuncCallOutArgs(
     151              :             CcuInstr* instr, uint32_t offset, std::vector<CcuRepArg>& outArgs, CcuRepReferenceManager* funcManager,
     152              :             uint16_t reserveXnId);
     153              :         HcclResult
     154              :         LoadLoopCallArg(CcuInstr*& instr, const CcuRepArg& inArg, const CcuRepArg& blkArg, const TransDep& dep);
     155              : 
     156              :         std::unordered_map<CcuRepType, uint32_t> repTypeInstrCount
     157              :             = {{CcuRepType::READ, 1},
     158              :                {CcuRepType::WRITE, 1},
     159              :                {CcuRepType::REM_MEM, 2},
     160              :                {CcuRepType::BUF_READ, 1},
     161              :                {CcuRepType::BUF_WRITE, 1},
     162              :                {CcuRepType::BUF_REDUCE, 1},
     163              :                {CcuRepType::BUF_LOC_READ, 1},
     164              :                {CcuRepType::BUF_LOC_WRITE, 1},
     165              :                {CcuRepType::LOCAL_CPY, 1},
     166              :                {CcuRepType::LOCAL_REDUCE, 1},
     167              : 
     168              :                {CcuRepType::LOC_RECORD_EVENT, 1},
     169              :                {CcuRepType::LOC_WAIT_EVENT, 1},
     170              :                {CcuRepType::LOC_WAIT_NOTIFY, 1},
     171              :                {CcuRepType::RECORD_SHARED_NOTIFY, 1},
     172              :                {CcuRepType::REM_POST_SEM, 1},
     173              :                {CcuRepType::REM_POST_VAR, 1},
     174              :                {CcuRepType::REM_WAIT_SEM, 1},
     175              : 
     176              :                {CcuRepType::ASSIGN, 1},
     177              :                {CcuRepType::ADD, 1},
     178              : 
     179              :                {CcuRepType::FUNC_BLOCK, 2},
     180              :                {CcuRepType::FUNC_CALL, 4},
     181              :                {CcuRepType::JUMP, 2},
     182              :                {CcuRepType::JUMP_NE, 2},
     183              :                {CcuRepType::JUMP_EQ, 5},
     184              :                {CcuRepType::LOOP, 1},
     185              :                {CcuRepType::LOOPGROUP, 1},
     186              :                {CcuRepType::SET_LOOP, 2},
     187              :                {CcuRepType::LOAD, 7},
     188              :                {CcuRepType::LOAD_VAR, 7},
     189              :                {CcuRepType::LOAD_ARG, 1},
     190              :                {CcuRepType::STORE, 7},
     191              :                {CcuRepType::STORE_VAR, 7},
     192              : 
     193              :                {CcuRepType::NOP, 1}};
     194              :     };
     195              : 
     196              : } // namespace CcuRep
     197              : } // namespace hcomm
     198              : 
     199              : #endif
        

Generated by: LCOV version 2.0-1