30{
31
32 std::unordered_map<ir::OperandIndex, ir::OperandIndex> root_map;
36
37
39 return ret;
40
41 auto itr = parent_map.find(ind);
42 if (itr == parent_map.end())
43 {
44
45 return ret = ind;
46 }
47 else
48 {
49 return ret = find_root(itr->second.parent);
50 }
51 };
52
53 ir::OperandIndexMap<bool> first_use_check;
54 ir::OperandIndexMap<bool> last_use_check;
55 LifetimeMap lifetime_map;
56 for (size_t i = 0; i < lifetime_seq.size(); i++)
57 {
58 const auto &[entry_uses_type, entry_idx] = lifetime_seq[i];
59 if (entry_uses_type != UsesType::FIRST)
60 continue;
61 auto root_ind = find_root(entry_idx);
62 if (first_use_check[root_ind])
63 continue;
64 first_use_check[root_ind] = true;
65 lifetime_map[i] = {UsesType::FIRST, root_ind};
66 }
67
68 for (int i = lifetime_seq.size() - 1; i >= 0; i--)
69 {
70 const auto &[entry_uses_type, entry_idx] = lifetime_seq[i];
71 if (entry_uses_type != UsesType::LAST)
72 continue;
73 auto root_ind = find_root(entry_idx);
74 if (last_use_check[root_ind])
75 continue;
76 last_use_check[root_ind] = true;
77 lifetime_map[i] = {UsesType::LAST, root_ind};
78 }
79
80 return lifetime_map;
81}
bool valid() const
Check whether the value is valid or not.