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