LCOV - code coverage report
Current view: top level - base_comm/resources/ccu/ccu_representation/reps/translator - ccu_ins_generator_base.h (source / functions) Coverage Total Hit
Test: coverage.info Lines: 88.9 % 18 16
Test Date: 2026-08-04 10:52:23 Functions: 80.0 % 5 4

            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              : #ifndef CCU_INS_GENERATOR_BASE
      11              : #define CCU_INS_GENERATOR_BASE
      12              : 
      13              : #include "ccu_rep_base_v1.h"
      14              : #include "ccu_datatype_v1.h"
      15              : #include "ccu_microcode_v1.h"
      16              : #include "ccu_rep_v1.h"
      17              : #include "ccu_kernel.h"
      18              : #include "ccu_log.h"
      19              : 
      20              : namespace hcomm {
      21              : namespace CcuRep {
      22              : 
      23              : class CcuInsGeneratorBase {
      24              : public:
      25          359 :     CcuInsGeneratorBase() {}
      26              : 
      27              :     // 虚析构函数,确保派生类对象正确析构
      28          359 :     virtual ~CcuInsGeneratorBase() = default;
      29              :     // data
      30              :     virtual HcclResult CcuRepBufLocReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufLocRead* repBufLocRead, const TransDep &dep) = 0;
      31              :     virtual HcclResult CcuRepBufLocWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufLocWrite* repBufLocWrite, const TransDep &dep) = 0;
      32              :     virtual HcclResult CcuRepBufReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufRead* repBufRead, const TransDep &dep) = 0;
      33              :     virtual HcclResult CcuRepBufReduceTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufReduce* ccuRepBufReduce) = 0;
      34              :     virtual HcclResult CcuRepBufWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepBufWrite* ccuRepBufWrite, const TransDep &dep) = 0;
      35              :     virtual HcclResult CcuRepLocCpyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocCpy* ccuRepLocCpy, const TransDep &dep) = 0;
      36              :     virtual HcclResult CcuRepReadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRead* repRemMem) = 0;
      37              :     virtual HcclResult CcuRepRemMemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemMem* repRemMem) = 0;
      38              :     virtual HcclResult CcuRepWriteTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepWrite* repWrite) = 0;
      39              :     
      40              :     // sync
      41              :     virtual HcclResult CcuRepLocRecordEventTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocRecordEvent* ccuRepLocRecordEvent) = 0;
      42              :     virtual HcclResult CcuRepLocWaitEventTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocWaitEvent* ccuRepLocWaitEvent) = 0;
      43              :     virtual HcclResult CcuRepLocWaitNotifyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepLocWaitNotify* ccuRepLocWaitNotify) = 0;
      44              :     virtual HcclResult CcuRepRecordSharedNotifyTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRecordSharedNotify* ccuRepRecordSharedNotify, const TransDep &dep) = 0;
      45              :     virtual HcclResult CcuRepRemWaitSemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemWaitSem* cuRepRemWaitSem) = 0;
      46              :     virtual HcclResult CcuRepRemPostVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemPostVar* ccuRepRemPostVar) = 0;
      47              :     virtual HcclResult CcuRepRemPostSemTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepRemPostSem* ccuRepRemPostSem, const TransDep &dep) = 0;
      48              :     // logical
      49              :     virtual HcclResult CcuRepAndTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAnd* ccuRepAnd, const TransDep &dep) = 0;
      50              :     virtual HcclResult CcuRepNotTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepNot* ccuRepNot, const TransDep &dep) = 0;
      51              :     virtual HcclResult CcuRepOrTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepOr* ccuRepOr, const TransDep &dep) = 0;
      52              :     virtual HcclResult CcuRepXorTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepXor* ccuRepXor, const TransDep &dep) = 0;
      53              : 
      54              :     // shift
      55              :     virtual HcclResult CcuRepShLTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepShL* ccuRepShL, const TransDep &dep) = 0;
      56              :     virtual HcclResult CcuRepShRTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepShR* ccuRepShR, const TransDep &dep) = 0;
      57              : 
      58              :     // arithmetic
      59              :     virtual HcclResult CcuRepAddTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAdd* ccuRepAdd, const TransDep &dep) = 0;;
      60              :     virtual HcclResult CcuRepAssignTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepAssign* ccuRepAssign, const TransDep &dep) = 0;
      61              :     virtual HcclResult CcuRepMulTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepMul* ccuRepMul) = 0;
      62              :     virtual HcclResult CcuRepSubTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, CcuRepSub* ccuRepSub) = 0;
      63              : 
      64              :     // control
      65              :     virtual HcclResult CcuRepFuncBlockTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepFuncBlock* funcBlockPtr,
      66              :         const TransDep &dep, uint32_t step) = 0;
      67              :     virtual HcclResult CcuRepFuncCallTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepFuncCall* funcCallPtr,
      68              :         const TransDep &dep) = 0;
      69              :     virtual HcclResult CcuRepJumpTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJump* jumpPtr,
      70              :         const TransDep &dep) = 0;
      71              :     virtual HcclResult CcuRepJumpNETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpNE* jumpNEPtr,
      72              :         const TransDep &dep) = 0;
      73              :     virtual HcclResult CcuRepJumpEQTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpEQ* jumpEQPtr,
      74              :         const TransDep &dep) = 0;
      75              :     virtual HcclResult CcuRepJumpLETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpLE* jumpLEPtr,
      76              :         const TransDep &dep) = 0;
      77              :     virtual HcclResult CcuRepJumpGETranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpGE* jumpGEPtr,
      78              :         const TransDep &dep) = 0;
      79              :     virtual HcclResult CcuRepJumpGTTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpGT* jumpGTPtr,
      80              :         const TransDep &dep) = 0;
      81              :     virtual HcclResult CcuRepJumpLTTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepJumpLT* jumpLTPtr,
      82              :         const TransDep &dep) = 0;
      83              :     
      84              :     // loop
      85              :     virtual HcclResult CcuRepLoopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoop* loopPtr) = 0;
      86              :     virtual HcclResult CcuRepLoopCallTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoopCall* loopCallPtr,
      87              :         const TransDep &dep) = 0;
      88              :     virtual HcclResult CcuRepSetLoopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepSetLoop* setLoopPtr) = 0;
      89              :     virtual HcclResult CcuRepLoopGroupBundleTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId,
      90              :         CcuRepLoopGroupBundle* bundlePtr, const TransDep &dep) = 0;
      91              :     virtual uint16_t CcuRepLoopGroupBundleInstrCount(CcuRepLoopGroupBundle* bundlePtr) = 0;
      92              :     
      93              :     // common
      94              :     virtual HcclResult CcuRepLoadTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoad* loadPtr, const TransDep &dep) = 0;
      95              :     virtual HcclResult CcuRepLoadVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoadVar* loadVarPtr, const TransDep &dep) = 0;
      96              :     virtual HcclResult CcuRepLoadArgTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepLoadArg* loadArgPtr, const TransDep &dep) = 0;
      97              :     virtual HcclResult CcuRepNopTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepNop* nopPtr, const TransDep &dep) = 0;
      98              :     virtual HcclResult CcuRepStoreTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepStore* storePtr, const TransDep &dep) = 0;
      99              :     virtual HcclResult CcuRepStoreVarTranslate(CcuKernel* ccuKernel, CcuInstr *&instr, uint16_t &curInstrId, CcuRepStoreVar* storeVarPtr, const TransDep &dep) = 0;
     100              : 
     101              :     virtual uint32_t GetInstrCount(CcuRepType repType) = 0;
     102              : 
     103          493 :     virtual HcclResult PrepareConstValue(CcuRepBase* repPtr, const TransDep &dep, CcuKernel *ccuKernel) {
     104              :         // A5使用基类空实现;A6需要根据repType做不同处理
     105              :         (void)repPtr;
     106              :         (void)dep;
     107              :         (void)ccuKernel;
     108          493 :         return HcclResult::HCCL_SUCCESS;
     109              :     }
     110              : 
     111              : protected:
     112              :     struct FuncCallContext {
     113              :         uint32_t inArgCount{0};
     114              :         CcuRepReferenceManager* funcManager{nullptr};
     115              :         std::shared_ptr<CcuRepFuncBlock> funcBlock;
     116              :         CcuInstr* instr{nullptr};
     117              :         std::vector<Variable> formalIns;
     118              :     };
     119              : 
     120            5 :     HcclResult PrepareFuncCallContext(CcuRepFuncCall* funcCallPtr, FuncCallContext& ctx)
     121              :     {
     122            5 :         CHK_PTR_NULL(funcCallPtr);
     123            5 :         ctx.inArgCount = funcCallPtr->GetInArgCount();
     124            5 :         ctx.funcManager = funcCallPtr->GetFuncManager();
     125            5 :         CHK_PTR_NULL(ctx.funcManager);
     126            5 :         ctx.funcBlock = funcCallPtr->GetFuncBlock();
     127            5 :         CHK_PTR_NULL(ctx.funcBlock);
     128            5 :         ctx.instr = funcCallPtr->GetInstr();
     129            5 :         CHK_PTR_NULL(ctx.instr);
     130            5 :         ctx.formalIns = ctx.funcBlock->GetInArgVars();
     131            5 :         if (static_cast<uint32_t>(ctx.formalIns.size()) != ctx.inArgCount) {
     132            0 :             HCCL_ERROR("FuncCall arg count mismatch: caller = %u, callee formal = %u",
     133              :                 ctx.inArgCount, static_cast<uint32_t>(ctx.formalIns.size()));
     134            0 :             return HCCL_E_PARA;
     135              :         }
     136            5 :         return HcclResult::HCCL_SUCCESS;
     137              :     }
     138              : };
     139              : }
     140              : }
     141              : 
     142              : #endif
        

Generated by: LCOV version 2.0-1