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 : #include "string_util.h"
12 : #include "exception_util.h"
13 : #include "ccu_api_exception.h"
14 : #include "ccu_rep_v1.h"
15 : #include "ccu_ins_generator_v1.h"
16 : #include "ccu_kernel.h"
17 : namespace hcomm {
18 : namespace CcuRep {
19 :
20 6 : CcuRepShL::CcuRepShL(
21 6 : CcuInsGeneratorBase* insGenPtr, const Variable& varD, const Variable& varN, const Variable& varM)
22 6 : : subType(ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR),
23 6 : shiftType(ShiftType::LOGICAL_SHIFT),
24 6 : varN(varN),
25 6 : varM(varM),
26 6 : varD(varD),
27 12 : insGenPtr(insGenPtr)
28 : {
29 6 : type = CcuRepType::SHL;
30 6 : instrCount = insGenPtr->GetInstrCount(type);
31 10 : }
32 :
33 3 : CcuRepShL::CcuRepShL(CcuInsGeneratorBase* insGenPtr, const Variable& varD, const Variable& varM)
34 3 : : subType(ShiftSubType::VAR_SHIFT_ASSIGN_VAR),
35 3 : shiftType(ShiftType::LOGICAL_SHIFT),
36 3 : varM(varM),
37 3 : varD(varD),
38 6 : insGenPtr(insGenPtr)
39 : {
40 3 : type = CcuRepType::SHL;
41 3 : instrCount = insGenPtr->GetInstrCount(type);
42 3 : }
43 :
44 3 : CcuRepShL::CcuRepShL(
45 3 : CcuInsGeneratorBase* insGenPtr, const Address& addrD, const Variable& varN, const Variable& varM)
46 3 : : subType(ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR),
47 3 : shiftType(ShiftType::LOGICAL_SHIFT),
48 3 : varN(varN),
49 3 : varM(varM),
50 3 : addrD(addrD),
51 6 : insGenPtr(insGenPtr)
52 : {
53 3 : type = CcuRepType::SHL;
54 3 : instrCount = insGenPtr->GetInstrCount(type);
55 3 : }
56 :
57 3 : CcuRepShL::CcuRepShL(CcuInsGeneratorBase* insGenPtr, const Address& addrD, const Variable& varM)
58 3 : : subType(ShiftSubType::ADDR_SHIFT_ASSIGN_VAR),
59 3 : shiftType(ShiftType::LOGICAL_SHIFT),
60 3 : varM(varM),
61 3 : addrD(addrD),
62 6 : insGenPtr(insGenPtr)
63 : {
64 3 : type = CcuRepType::SHL;
65 3 : instrCount = insGenPtr->GetInstrCount(type);
66 3 : }
67 :
68 6 : bool CcuRepShL::Translate(CcuKernel* ccuKernel, CcuInstr*& instr, uint16_t& curInstrId, const TransDep& dep)
69 : {
70 6 : Hccl::CHECK_NULLPTR(instr, "[CcuRepShL::Translate] instr is nullptr!");
71 6 : this->instrId = curInstrId;
72 6 : translated = true;
73 6 : instrCount = insGenPtr->GetInstrCount(type);
74 6 : CHK_PRT_THROW(
75 : insGenPtr->CcuRepShLTranslate(ccuKernel, instr, this, dep) != HcclResult::HCCL_SUCCESS,
76 : HCCL_ERROR("[CcuRepShL][Translate] failed to translate for instrId[%u]", instrId), Hccl::CcuApiException,
77 : "CcuRepShL translate failed");
78 6 : CHK_PRT_THROW(
79 : (curInstrId > UINT16_MAX - instrCount),
80 : HCCL_ERROR(
81 : "[CcuRepShL::Translate]uint16 integer overflow occurs, curInstrId = [%hu], instrCount = [%hu]",
82 : curInstrId, instrCount),
83 : Hccl::InternalException, "integer overflow");
84 6 : curInstrId += instrCount;
85 6 : return translated;
86 : }
87 :
88 6 : std::string CcuRepShL::Describe()
89 : {
90 6 : switch (subType) {
91 3 : case ShiftSubType::VAR_EQUALS_VAR_SHIFT_VAR: {
92 : return Hccl::StringFormat(
93 3 : "Variable[%u] = Variable[%u] << Variable[%u]", varD.Id(), varN.Id(), varM.Id());
94 : }
95 1 : case ShiftSubType::VAR_SHIFT_ASSIGN_VAR: {
96 1 : return Hccl::StringFormat("Variable[%u] <<= Variable[%u]", varD.Id(), varM.Id());
97 : }
98 1 : case ShiftSubType::ADDR_EQUALS_VAR_SHIFT_VAR: {
99 : return Hccl::StringFormat(
100 1 : "Address[%u] = Variable[%u] << Variable[%u]", addrD.Id(), varN.Id(), varM.Id());
101 : }
102 1 : case ShiftSubType::ADDR_SHIFT_ASSIGN_VAR: {
103 1 : return Hccl::StringFormat("Address[%u] <<= Variable[%u]", addrD.Id(), varM.Id());
104 : }
105 0 : default: {
106 0 : return Hccl::StringFormat("Invalid Shift");
107 : }
108 : }
109 : return Hccl::StringFormat("Invalid Shift");
110 : }
111 :
112 : }; // namespace CcuRep
113 : }; // namespace hcomm
|