Skip to content

Commit c123419

Browse files
yoneyfacebook-github-bot
authored andcommitted
Modernize loops
Summary: Convert some of to loops to range-based loops. Reviewed By: alexmalyshev Differential Revision: D83292507 fbshipit-source-id: f43a79b7c56c726c33dbe2b3471b06a5ac913842
1 parent a24c053 commit c123419

4 files changed

Lines changed: 9 additions & 14 deletions

File tree

cinderx/Jit/hir/printer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -885,11 +885,10 @@ void HIRPrinter::Print(std::ostream& os, const FrameState& state) {
885885
}
886886

887887
auto& bs = state.block_stack;
888-
if (bs.size() > 0) {
888+
if (!bs.isEmpty()) {
889889
Indented(os) << "BlockStack {" << std::endl;
890890
Indent();
891-
for (std::size_t i = 0; i < bs.size(); i++) {
892-
auto& entry = bs.at(i);
891+
for (const auto& entry : bs) {
893892
Indented(os) << fmt::format(
894893
"Opcode {} HandlerOff {} StackLevel {}\n",
895894
entry.opcode,

cinderx/Jit/hir/simplify.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,10 +1816,7 @@ void Simplify::Run(Function& irfunc) {
18161816
changed && i < iteration_limit && env.new_blocks < new_block_limit;
18171817
++i) {
18181818
changed = false;
1819-
for (auto cfg_it = irfunc.cfg.blocks.begin();
1820-
cfg_it != irfunc.cfg.blocks.end();
1821-
++cfg_it) {
1822-
BasicBlock& block = *cfg_it;
1819+
for (auto& block : irfunc.cfg.blocks) {
18231820
env.block = &block;
18241821

18251822
for (auto blk_it = block.begin(); blk_it != block.end();) {

cinderx/Jit/jit_time_log.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -111,25 +111,22 @@ void CompilationPhaseTimer::dumpPhaseTimingsAndTidy() {
111111
int ts_digits = 0;
112112
int unattributed_time_digitls = 0;
113113
double leaf_total_time = 0;
114-
for (auto it = flat_rows.begin(); it != flat_rows.end(); ++it) {
115-
auto& [indent, phase, time_span, is_leaf, unattributed_time] = *it;
116-
114+
for (auto& [indent, phase, time_span, is_leaf, unattributed_time] :
115+
flat_rows) {
117116
longest_phase =
118117
std::max(longest_phase, int(phase->sub_phase_name.size() + 1 + indent));
119118
ts_digits = std::max(ts_digits, int(log10(time_span) + 1));
120119
unattributed_time_digitls =
121120
std::max(unattributed_time_digitls, int(log10(unattributed_time) + 1));
122121

123122
if (is_leaf) {
124-
int time_span = std::get<2>(*it);
125123
leaf_total_time += time_span;
126124
}
127125
}
128126

129127
std::string phase_info;
130-
for (auto it = flat_rows.begin(); it != flat_rows.end(); ++it) {
131-
auto& [indent, phase, time_span, is_leaf, unattributed_time] = *it;
132-
128+
for (auto& [indent, phase, time_span, is_leaf, unattributed_time] :
129+
flat_rows) {
133130
phase_info += fmt::format(
134131
"{:<{}}",
135132
fmt::format("{}>{}", std::string(indent, ' '), phase->sub_phase_name),

cinderx/Jit/lir/inliner.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ bool LIRInliner::inlineCalls(Function* func) {
1717
bool changed = false;
1818
std::vector<BasicBlock*>& blocks = func->basicblocks();
1919

20+
// Do not convert to a range-based for loop because 'blocks' is updated
21+
// inside the loop.
2022
for (size_t i = 0; i < blocks.size(); ++i) {
2123
BasicBlock* bb = blocks[i];
2224

0 commit comments

Comments
 (0)