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