• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 MAPLE_ME_INCLUDE_ME_SSA_UPDATE_H
17 #define MAPLE_ME_INCLUDE_ME_SSA_UPDATE_H
18 #include "me_function.h"
19 #include "dominance.h"
20 #include "me_irmap.h"
21 
22 namespace maple {
23 // When the number of osts is greater than kOstLimitSize, use RenameWithVectorStack object to update ssa, otherwise,
24 // use RenameWithMapStack object to update ssa
25 constexpr size_t kOstLimitSize = 5000;
26 
27 class VersionStacks {
28 public:
29     VersionStacks() = default;
30     virtual ~VersionStacks() = default;
31 
GetRenameStack(OStIdx idx)32     virtual std::stack<ScalarMeExpr *> *GetRenameStack(OStIdx idx)
33     {
34         (void)idx;
35         DEBUG_ASSERT(false, "can not be here");
36         return nullptr;
37     }
38 
InitRenameStack(OStIdx idx)39     virtual void InitRenameStack(OStIdx idx)
40     {
41         (void)idx;
42         DEBUG_ASSERT(false, "can not be here");
43     }
44 
RecordCurrentStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)45     virtual void RecordCurrentStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
46     {
47         (void)origStackSize;
48         DEBUG_ASSERT(false, "can not be here");
49     }
50 
RecoverStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)51     virtual void RecoverStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
52     {
53         (void)origStackSize;
54         DEBUG_ASSERT(false, "can not be here");
55     }
56 };
57 
58 class VectorVersionStacks : public VersionStacks {
59 public:
60     VectorVersionStacks() = default;
61     virtual ~VectorVersionStacks() = default;
62 
63     std::stack<ScalarMeExpr *> *GetRenameStack(OStIdx idx) override;
64     void InitRenameStack(OStIdx idx) override;
65     void RecordCurrentStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize) override;
66     void RecoverStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize) override;
67 
ResizeRenameStack(size_t size)68     void ResizeRenameStack(size_t size)
69     {
70         renameWithVectorStacks.resize(size);
71     }
72 
73 private:
74     std::vector<std::unique_ptr<std::stack<ScalarMeExpr *>>> renameWithVectorStacks;
75 };
76 
77 class MapVersionStacks : public VersionStacks {
78 public:
MapVersionStacks()79     MapVersionStacks() : renameWithMapStacks(std::less<OStIdx>()) {}
80     virtual ~MapVersionStacks() = default;
81 
82     std::stack<ScalarMeExpr *> *GetRenameStack(OStIdx idx) override;
83     void InitRenameStack(OStIdx idx) override;
84     void RecordCurrentStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize) override;
85     void RecoverStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize) override;
86 
87 private:
88     std::map<OStIdx, std::unique_ptr<std::stack<ScalarMeExpr *>>> renameWithMapStacks;
89 };
90 }  // namespace maple
91 #endif  // MAPLE_ME_INCLUDE_ME_SSA_UPDATE_H
92