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 #include "me_ssa_update.h"
17
18 // Create or update HSSA representation for variables given by *updateCands;
19 // for each variable, the mapped bb set gives the bbs that have newly inserted
20 // dassign's to the variable.
21 // If some assignments have been deleted, the current implementation does not
22 // delete useless phi's, and these useless phi's may end up having identical
23 // phi operands.
24 namespace maple {
GetRenameStack(OStIdx idx)25 std::stack<ScalarMeExpr *> *VectorVersionStacks::GetRenameStack(OStIdx idx)
26 {
27 return renameWithVectorStacks.at(idx).get();
28 }
29
GetRenameStack(OStIdx idx)30 std::stack<ScalarMeExpr *> *MapVersionStacks::GetRenameStack(OStIdx idx)
31 {
32 auto it = renameWithMapStacks.find(idx);
33 if (it == renameWithMapStacks.end()) {
34 return nullptr;
35 }
36 return it->second.get();
37 }
38
InitRenameStack(OStIdx idx)39 void VectorVersionStacks::InitRenameStack(OStIdx idx)
40 {
41 renameWithVectorStacks[idx] = std::make_unique<std::stack<ScalarMeExpr *>>();
42 }
43
InitRenameStack(OStIdx idx)44 void MapVersionStacks::InitRenameStack(OStIdx idx)
45 {
46 renameWithMapStacks[idx] = std::make_unique<std::stack<ScalarMeExpr *>>();
47 }
48
RecordCurrentStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)49 void VectorVersionStacks::RecordCurrentStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
50 {
51 origStackSize.resize(renameWithVectorStacks.size());
52 for (size_t i = 0; i < renameWithVectorStacks.size(); ++i) {
53 if (renameWithVectorStacks.at(i) == nullptr) {
54 continue;
55 }
56 origStackSize[i] = std::make_pair(renameWithVectorStacks.at(i)->size(), OStIdx(i));
57 }
58 }
59
RecordCurrentStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)60 void MapVersionStacks::RecordCurrentStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
61 {
62 origStackSize.resize(renameWithMapStacks.size());
63 uint32 stackId = 0;
64 for (const auto &ost2stack : renameWithMapStacks) {
65 origStackSize[stackId] = std::make_pair(ost2stack.second->size(), ost2stack.first);
66 ++stackId;
67 }
68 }
69
RecoverStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)70 void VectorVersionStacks::RecoverStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
71 {
72 for (size_t i = 1; i < renameWithVectorStacks.size(); ++i) {
73 if (renameWithVectorStacks.at(i) == nullptr) {
74 continue;
75 }
76 while (renameWithVectorStacks.at(i)->size() > origStackSize[i].first) {
77 renameWithVectorStacks.at(i)->pop();
78 }
79 }
80 }
81
RecoverStackSize(std::vector<std::pair<uint32,OStIdx>> & origStackSize)82 void MapVersionStacks::RecoverStackSize(std::vector<std::pair<uint32, OStIdx>> &origStackSize)
83 {
84 uint32 stackId = 0;
85 for (const auto &ost2stack : renameWithMapStacks) {
86 DEBUG_ASSERT(ost2stack.first == origStackSize[stackId].second,
87 "OStIdx must be equal, element of renameWithMapStacks should not be changed");
88 while (ost2stack.second->size() > origStackSize[stackId].first) {
89 ost2stack.second->pop();
90 }
91 ++stackId;
92 }
93 }
94 } // namespace maple
95