• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LIBABCKIT_SRC_CODEGEN_IC_SLOT_ALLOCATOR_H
17 #define LIBABCKIT_SRC_CODEGEN_IC_SLOT_ALLOCATOR_H
18 
19 #include "compiler/optimizer/ir/basicblock.h"
20 #include "compiler/optimizer/ir/graph.h"
21 #include "compiler/optimizer/ir/graph_visitor.h"
22 #include "compiler/optimizer/ir/constants.h"
23 #include "compiler/optimizer/ir/inst.h"
24 #include "compiler/optimizer/pass.h"
25 
26 namespace libabckit {
27 
28 using ark::compiler::BasicBlock;
29 using ark::compiler::Inst;
30 using ark::compiler::Opcode;
31 
32 class ICSlotAllocator final : public ark::compiler::Optimization {
33 public:
ICSlotAllocator(ark::compiler::Graph * graph,uint16_t * icSlotNumber)34     explicit ICSlotAllocator(ark::compiler::Graph *graph, uint16_t *icSlotNumber)
35         : ark::compiler::Optimization(graph), icSlotNumber_(icSlotNumber)
36     {
37     }
38 
39     bool RunImpl() override;
40 
GetPassName()41     const char *GetPassName() const override
42     {
43         return "ICSlotAllocator";
44     }
45 
46 private:
47     template <typename Callback>
48     void VisitInstructions(const Callback &callback);
49 
50     bool Allocate8BitIcSlots();
51     bool Allocate8Or16BitIcSlots();
52     bool Allocate16BitIcSlots();
53 
54     uint8_t nextFree8BitSlot_ = 0x0;
55     uint16_t nextFree16BitSlot_ = INIT_16BIT_SLOT_VALE;
56     uint16_t *icSlotNumber_ = nullptr;
57 
58     static constexpr uint16_t INIT_16BIT_SLOT_VALE = 0x100;
59     static constexpr uint8_t INVALID_8_BIT_SLOT = 0xFF;
60     static constexpr uint16_t INVALID_16_BIT_SLOT = 0xFFFF;
61 };
62 
63 }  // namespace libabckit
64 
65 #endif  // LIBABCKIT_SRC_CODEGEN_IC_SLOT_ALLOCATOR_H
66