aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorKushal Pal <kushalpal109@gmail.com>2024-08-28 06:16:11 +0000
committerP-E-P <32375388+P-E-P@users.noreply.github.com>2024-09-09 08:33:02 +0000
commit4a6cccfbf18b4bd0594a9d50c508f0e139c7558c (patch)
tree2ccd995c1e925b1c36808243e999797a67cc11a2 /gcc
parent170223717e8af57f18e632a8547e5d1b18525aaf (diff)
downloadgcc-4a6cccfbf18b4bd0594a9d50c508f0e139c7558c.zip
gcc-4a6cccfbf18b4bd0594a9d50c508f0e139c7558c.tar.gz
gcc-4a6cccfbf18b4bd0594a9d50c508f0e139c7558c.tar.bz2
Use `IndexVec` for bb_fold_map
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Used `IndexVec` for bb_fold_map. (Dump::go): Use strong type as index instead of value as now we are using `IndexVec`. (Dump::visit): Likewise. * checks/errors/borrowck/rust-bir-dump.h (class Dump): Use `IndexVec` for bb_fold_map. * checks/errors/borrowck/rust-bir-place.h: Add constructor for `IndexVec` that can reserve size. Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-dump.cc27
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-dump.h2
-rw-r--r--gcc/rust/checks/errors/borrowck/rust-bir-place.h3
3 files changed, 17 insertions, 15 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
index 5bcf224..080029a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.cc
@@ -71,7 +71,7 @@ renumber_places (const Function &func, std::vector<PlaceId> &place_map)
}
void
-simplify_cfg (Function &func, std::vector<BasicBlockId> &bb_fold_map)
+simplify_cfg (Function &func, IndexVec<BasicBlockId, BasicBlockId> &bb_fold_map)
{
// The BIR builder can generate many useless basic blocks, which contain only
// a goto.
@@ -84,11 +84,11 @@ simplify_cfg (Function &func, std::vector<BasicBlockId> &bb_fold_map)
// BB0 cannot be folded as it is an entry block.
for (BasicBlockId i = {1}; i.value < func.basic_blocks.size (); ++i.value)
{
- const BasicBlock &bb = func.basic_blocks[bb_fold_map[i.value]];
+ const BasicBlock &bb = func.basic_blocks[bb_fold_map[i]];
if (bb.statements.empty () && bb.is_goto_terminated ())
{
auto dst = bb.successors.at (0);
- if (bb_fold_map[dst.value] != dst)
+ if (bb_fold_map[dst] != dst)
{
rust_error_at (
UNKNOWN_LOCATION,
@@ -100,12 +100,12 @@ simplify_cfg (Function &func, std::vector<BasicBlockId> &bb_fold_map)
for (BasicBlockId i = ENTRY_BASIC_BLOCK;
i.value < bb_fold_map.size (); ++i.value)
{
- bb_fold_map[i.value] = i;
+ bb_fold_map[i] = i;
}
stabilized = true;
break;
}
- bb_fold_map[i.value] = dst;
+ bb_fold_map[i] = dst;
stabilized = false;
}
}
@@ -119,7 +119,7 @@ Dump::go (bool enable_simplify_cfg)
for (BasicBlockId i = ENTRY_BASIC_BLOCK; i.value < bb_fold_map.size ();
++i.value)
{
- bb_fold_map[i.value] = i;
+ bb_fold_map[i] = i;
}
for (size_t i = 0; i < place_map.size (); ++i)
{
@@ -146,7 +146,7 @@ Dump::go (bool enable_simplify_cfg)
for (statement_bb = ENTRY_BASIC_BLOCK;
statement_bb.value < func.basic_blocks.size (); ++statement_bb.value)
{
- if (bb_fold_map[statement_bb.value] != statement_bb)
+ if (bb_fold_map[statement_bb] != statement_bb)
continue; // This BB was folded.
if (func.basic_blocks[statement_bb].statements.empty ()
@@ -157,7 +157,7 @@ Dump::go (bool enable_simplify_cfg)
BasicBlock &bb = func.basic_blocks[statement_bb];
stream << "\n";
- stream << indentation << "bb" << bb_fold_map[statement_bb.value].value
+ stream << indentation << "bb" << bb_fold_map[statement_bb].value
<< ": {\n";
size_t i = 0;
for (auto &stmt : bb.statements)
@@ -168,8 +168,8 @@ Dump::go (bool enable_simplify_cfg)
}
if (!bb_terminated)
stream << indentation << indentation << "goto -> bb"
- << bb_fold_map[bb.successors.at (0).value].value << ";\t\t"
- << i++ << "\n";
+ << bb_fold_map[bb.successors.at (0)].value << ";\t\t" << i++
+ << "\n";
stream << indentation << "}\n";
}
@@ -194,7 +194,7 @@ Dump::visit (const Statement &stmt)
stream << ") -> [";
print_comma_separated (stream, func.basic_blocks[statement_bb].successors,
[this] (BasicBlockId succ) {
- stream << "bb" << bb_fold_map[succ.value].value;
+ stream << "bb" << bb_fold_map[succ].value;
});
stream << "]";
bb_terminated = true;
@@ -206,8 +206,7 @@ Dump::visit (const Statement &stmt)
case Statement::Kind::GOTO:
stream
<< "goto -> bb"
- << bb_fold_map[func.basic_blocks[statement_bb].successors.at (0).value]
- .value;
+ << bb_fold_map[func.basic_blocks[statement_bb].successors.at (0)].value;
bb_terminated = true;
break;
case Statement::Kind::STORAGE_DEAD:
@@ -329,7 +328,7 @@ Dump::visit (const CallExpr &expr)
stream << ") -> [";
print_comma_separated (stream, func.basic_blocks[statement_bb].successors,
[this] (BasicBlockId succ) {
- stream << "bb" << bb_fold_map[succ.value].value;
+ stream << "bb" << bb_fold_map[succ].value;
});
stream << "]";
bb_terminated = true;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
index 9d6babd..4f2bb2a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-dump.h
@@ -34,7 +34,7 @@ class Dump : public Visitor
Function &func;
const std::string &name;
- std::vector<BasicBlockId> bb_fold_map;
+ IndexVec<BasicBlockId, BasicBlockId> bb_fold_map;
std::vector<PlaceId> place_map;
PlaceId statement_place = INVALID_PLACE;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index 23f8c7d..1706ace 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -205,6 +205,9 @@ template <typename I, typename T> class IndexVec
std::vector<T> internal_vector;
public:
+ IndexVec () = default;
+ IndexVec (size_t size) { internal_vector.reserve (size); }
+
T &at (I pid) { return internal_vector[pid.value]; }
const T &at (I pid) const { return internal_vector[pid.value]; }
T &operator[] (I pid) { return internal_vector[pid.value]; }