• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * Copyright (c) 2021-2022 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 "reg_alloc_stat.h"
17 #include "optimizer/ir/datatype.h"
18 
19 namespace panda::compiler {
RegAllocStat(const ArenaVector<LifeIntervals * > & intervals)20 RegAllocStat::RegAllocStat(const ArenaVector<LifeIntervals *> &intervals)
21 {
22     std::vector<bool> used_regs(INVALID_REG);
23     std::vector<bool> used_vregs(INVALID_REG);
24     std::vector<bool> used_slots(INVALID_REG);
25     std::vector<bool> used_vslots(INVALID_REG);
26 
27     for (const auto &interv : intervals) {
28         if (interv->IsPhysical() || interv->NoDest()) {
29             continue;
30         }
31         auto location = interv->GetLocation();
32         if (location.IsRegister()) {
33             used_regs[location.GetValue()] = true;
34         } else if (location.IsFpRegister()) {
35             used_vregs[location.GetValue()] = true;
36         } else if (location.IsStack()) {
37             auto slot = location.GetValue();
38             DataType::IsFloatType(interv->GetType()) ? (used_slots[slot] = true) : (used_vslots[slot] = true);
39         }
40     }
41 
42     regs_ = static_cast<size_t>(std::count(used_regs.begin(), used_regs.end(), true));
43     vregs_ = static_cast<size_t>(std::count(used_vregs.begin(), used_vregs.end(), true));
44     slots_ = static_cast<size_t>(std::count(used_slots.begin(), used_slots.end(), true));
45     vslots_ = static_cast<size_t>(std::count(used_vslots.begin(), used_vslots.end(), true));
46 }
47 }  // namespace panda::compiler
48