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