Commit 3a5b4ae9 authored by ritesht's avatar ritesht Committed by Commit bot

[wasm] Cleaning up code

Cleaning up the code to replace all instances of "i++" in for loops with the more efficient "++i".
The latter foregoes an extra intermediate variable.

BUG=v8:5044

Review-Url: https://codereview.chromium.org/2094573002
Cr-Commit-Position: refs/heads/master@{#37230}
parent 8c0ee440
......@@ -2362,7 +2362,7 @@ void WasmGraphBuilder::BuildJSToWasmWrapper(Handle<Code> wasm_code,
args[pos++] = HeapConstant(wasm_code);
// Convert JS parameters to WASM numbers.
for (int i = 0; i < wasm_count; i++) {
for (int i = 0; i < wasm_count; ++i) {
Node* param =
graph()->NewNode(jsgraph()->common()->Parameter(i + 1), start);
Node* wasm_param = FromJS(param, context, sig->GetParam(i));
......@@ -2451,7 +2451,7 @@ void WasmGraphBuilder::BuildWasmToJSWrapper(Handle<JSFunction> function,
// Convert WASM numbers to JS values.
int param_index = 0;
for (int i = 0; i < wasm_count; i++) {
for (int i = 0; i < wasm_count; ++i) {
Node* param =
graph()->NewNode(jsgraph()->common()->Parameter(param_index++), start);
args[pos++] = ToJS(param, context, sig->GetParam(i));
......
......@@ -385,7 +385,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
current_function_builder_->EmitVarInt(default_block);
}
}
for (int i = 0; i < case_count; i++) {
for (int i = 0; i < case_count; ++i) {
CaseClause* clause = clauses->at(i);
RECURSE(VisitStatements(clause->statements()));
BlockVisitor* v = blocks.at(case_count - i - 1);
......@@ -468,7 +468,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
FunctionSig::Builder b(zone(), return_type == kAstStmt ? 0 : 1,
func_type->Arity());
if (return_type != kAstStmt) b.AddReturn(return_type);
for (int i = 0; i < expr->parameter_count(); i++) {
for (int i = 0; i < expr->parameter_count(); ++i) {
LocalType type = TypeFrom(func_type->Parameter(i));
DCHECK_NE(kAstStmt, type);
b.AddParam(type);
......@@ -645,13 +645,13 @@ class AsmWasmBuilderImpl : public AstVisitor {
if (return_type != kAstStmt) {
sig.AddReturn(static_cast<LocalType>(return_type));
}
for (int i = 0; i < func_type->Arity(); i++) {
for (int i = 0; i < func_type->Arity(); ++i) {
sig.AddParam(TypeFrom(func_type->Parameter(i)));
}
uint32_t signature_index = builder_->AddSignature(sig.Build());
InsertFunctionTable(table->var(), next_table_index_, signature_index);
next_table_index_ += funcs->values()->length();
for (int i = 0; i < funcs->values()->length(); i++) {
for (int i = 0; i < funcs->values()->length(); ++i) {
VariableProxy* func = funcs->values()->at(i)->AsVariableProxy();
DCHECK_NOT_NULL(func);
builder_->AddIndirectFunction(LookupOrInsertFunction(func->var()));
......@@ -1286,7 +1286,7 @@ class AsmWasmBuilderImpl : public AstVisitor {
if (return_type != kAstStmt) {
sig.AddReturn(return_type);
}
for (int i = 0; i < args->length(); i++) {
for (int i = 0; i < args->length(); ++i) {
sig.AddParam(TypeOf(args->at(i)));
}
index =
......
......@@ -249,7 +249,7 @@ class WasmDecoder : public Decoder {
return false;
}
// Verify table.
for (uint32_t i = 0; i < operand.table_count + 1; i++) {
for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
uint32_t target = operand.read_entry(this, i);
if (target >= block_depth) {
error(operand.table + i * 2, "improper branch in br_table");
......@@ -565,7 +565,7 @@ class SR_WasmDecoder : public WasmDecoder {
char* indentation() {
static const int kMaxIndent = 64;
static char bytes[kMaxIndent + 1];
for (int i = 0; i < kMaxIndent; i++) bytes[i] = ' ';
for (int i = 0; i < kMaxIndent; ++i) bytes[i] = ' ';
bytes[kMaxIndent] = 0;
if (stack_.size() < kMaxIndent / 2) {
bytes[stack_.size() * 2] = 0;
......@@ -579,7 +579,7 @@ class SR_WasmDecoder : public WasmDecoder {
// Initialize {local_type_vec} from signature.
if (sig_) {
local_type_vec_.reserve(sig_->parameter_count());
for (size_t i = 0; i < sig_->parameter_count(); i++) {
for (size_t i = 0; i < sig_->parameter_count(); ++i) {
local_type_vec_.push_back(sig_->GetParam(i));
}
}
......@@ -814,7 +814,7 @@ class SR_WasmDecoder : public WasmDecoder {
SsaEnv* copy = Steal(break_env);
ssa_env_ = copy;
for (uint32_t i = 0; i < operand.table_count + 1; i++) {
for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
uint16_t target = operand.read_entry(this, i);
ssa_env_ = Split(copy);
ssa_env_->control = (i == operand.table_count)
......@@ -1045,7 +1045,7 @@ class SR_WasmDecoder : public WasmDecoder {
#if DEBUG
if (FLAG_trace_wasm_decoder) {
for (size_t i = 0; i < stack_.size(); i++) {
for (size_t i = 0; i < stack_.size(); ++i) {
Value& val = stack_[i];
WasmOpcode opcode = static_cast<WasmOpcode>(*val.pc);
PrintF(" %c@%d:%s", WasmOpcodes::ShortNameOf(val.type),
......@@ -1528,7 +1528,7 @@ std::ostream& operator<<(std::ostream& os, const Tree& tree) {
}
PrintF("%s", WasmOpcodes::OpcodeName(tree.opcode()));
if (tree.count > 0) os << "(";
for (uint32_t i = 0; i < tree.count; i++) {
for (uint32_t i = 0; i < tree.count; ++i) {
if (i > 0) os << ", ";
os << *tree.children[i];
}
......@@ -1606,7 +1606,7 @@ bool PrintAst(base::AccountingAllocator* allocator, const FunctionBody& body,
os.write(padding, num_whitespaces);
os << "k" << WasmOpcodes::OpcodeName(opcode) << ",";
for (size_t i = 1; i < length; i++) {
for (size_t i = 1; i < length; ++i) {
os << " " << AsHex(pc[i], 2) << ",";
}
......
......@@ -87,7 +87,7 @@ void WasmFunctionBuilder::EmitSetLocal(uint32_t local_index) {
}
void WasmFunctionBuilder::EmitCode(const byte* code, uint32_t code_size) {
for (size_t i = 0; i < code_size; i++) {
for (size_t i = 0; i < code_size; ++i) {
body_.push_back(code[i]);
}
}
......@@ -129,7 +129,7 @@ void WasmFunctionBuilder::SetExported() { exported_ = true; }
void WasmFunctionBuilder::SetName(const char* name, int name_length) {
name_.clear();
if (name_length > 0) {
for (int i = 0; i < name_length; i++) {
for (int i = 0; i < name_length; ++i) {
name_.push_back(*(name + i));
}
}
......@@ -165,7 +165,7 @@ void WasmFunctionBuilder::WriteBody(ZoneBuffer& buffer) const {
WasmDataSegmentEncoder::WasmDataSegmentEncoder(Zone* zone, const byte* data,
uint32_t size, uint32_t dest)
: data_(zone), dest_(dest) {
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < size; ++i) {
data_.push_back(data[i]);
}
}
......
......@@ -157,7 +157,7 @@ class ModuleDecoder : public Decoder {
uint32_t signatures_count = consume_u32v(&length, "signatures count");
module->signatures.reserve(SafeReserve(signatures_count));
// Decode signatures.
for (uint32_t i = 0; i < signatures_count; i++) {
for (uint32_t i = 0; i < signatures_count; ++i) {
if (failed()) break;
TRACE("DecodeSignature[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -170,7 +170,7 @@ class ModuleDecoder : public Decoder {
int length;
uint32_t functions_count = consume_u32v(&length, "functions count");
module->functions.reserve(SafeReserve(functions_count));
for (uint32_t i = 0; i < functions_count; i++) {
for (uint32_t i = 0; i < functions_count; ++i) {
module->functions.push_back({nullptr, // sig
i, // func_index
0, // sig_index
......@@ -193,7 +193,7 @@ class ModuleDecoder : public Decoder {
static_cast<uint32_t>(module->functions.size()));
break;
}
for (uint32_t i = 0; i < functions_count; i++) {
for (uint32_t i = 0; i < functions_count; ++i) {
WasmFunction* function = &module->functions[i];
int length;
uint32_t size = consume_u32v(&length, "body size");
......@@ -220,7 +220,7 @@ class ModuleDecoder : public Decoder {
break;
}
for (uint32_t i = 0; i < functions_count; i++) {
for (uint32_t i = 0; i < functions_count; ++i) {
WasmFunction* function = &module->functions[i];
function->name_offset =
consume_string(&function->name_length, false);
......@@ -241,7 +241,7 @@ class ModuleDecoder : public Decoder {
uint32_t globals_count = consume_u32v(&length, "globals count");
module->globals.reserve(SafeReserve(globals_count));
// Decode globals.
for (uint32_t i = 0; i < globals_count; i++) {
for (uint32_t i = 0; i < globals_count; ++i) {
if (failed()) break;
TRACE("DecodeGlobal[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -257,7 +257,7 @@ class ModuleDecoder : public Decoder {
consume_u32v(&length, "data segments count");
module->data_segments.reserve(SafeReserve(data_segments_count));
// Decode data segments.
for (uint32_t i = 0; i < data_segments_count; i++) {
for (uint32_t i = 0; i < data_segments_count; ++i) {
if (failed()) break;
TRACE("DecodeDataSegment[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -292,7 +292,7 @@ class ModuleDecoder : public Decoder {
consume_u32v(&length, "function table count");
module->function_table.reserve(SafeReserve(function_table_count));
// Decode function table.
for (uint32_t i = 0; i < function_table_count; i++) {
for (uint32_t i = 0; i < function_table_count; ++i) {
if (failed()) break;
TRACE("DecodeFunctionTable[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -331,7 +331,7 @@ class ModuleDecoder : public Decoder {
consume_u32v(&length, "import table count");
module->import_table.reserve(SafeReserve(import_table_count));
// Decode import table.
for (uint32_t i = 0; i < import_table_count; i++) {
for (uint32_t i = 0; i < import_table_count; ++i) {
if (failed()) break;
TRACE("DecodeImportTable[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -364,7 +364,7 @@ class ModuleDecoder : public Decoder {
consume_u32v(&length, "export table count");
module->export_table.reserve(SafeReserve(export_table_count));
// Decode export table.
for (uint32_t i = 0; i < export_table_count; i++) {
for (uint32_t i = 0; i < export_table_count; ++i) {
if (failed()) break;
TRACE("DecodeExportTable[%d] module+%d\n", i,
static_cast<int>(pc_ - start_));
......@@ -409,7 +409,7 @@ class ModuleDecoder : public Decoder {
case WasmSection::Code::Max:
// Skip unknown sections.
TRACE("Unknown section: '");
for (uint32_t i = 0; i != string_length; i++) {
for (uint32_t i = 0; i != string_length; ++i) {
TRACE("%c", *(section_name_start + i));
}
TRACE("'\n");
......@@ -707,7 +707,7 @@ class ModuleDecoder : public Decoder {
// parse parameter types
uint32_t param_count = consume_u32v(&length, "param count");
std::vector<LocalType> params;
for (uint32_t i = 0; i < param_count; i++) {
for (uint32_t i = 0; i < param_count; ++i) {
LocalType param = consume_local_type();
if (param == kAstStmt) error(pc_ - 1, "invalid void parameter type");
params.push_back(param);
......@@ -722,7 +722,7 @@ class ModuleDecoder : public Decoder {
return nullptr;
}
std::vector<LocalType> returns;
for (uint32_t i = 0; i < return_count; i++) {
for (uint32_t i = 0; i < return_count; ++i) {
LocalType ret = consume_local_type();
if (ret == kAstStmt) error(pc_ - 1, "invalid void return type");
returns.push_back(ret);
......@@ -732,8 +732,8 @@ class ModuleDecoder : public Decoder {
LocalType* buffer =
module_zone->NewArray<LocalType>(param_count + return_count);
uint32_t b = 0;
for (uint32_t i = 0; i < return_count; i++) buffer[b++] = returns[i];
for (uint32_t i = 0; i < param_count; i++) buffer[b++] = params[i];
for (uint32_t i = 0; i < return_count; ++i) buffer[b++] = returns[i];
for (uint32_t i = 0; i < param_count; ++i) buffer[b++] = params[i];
return new (module_zone) FunctionSig(return_count, param_count, buffer);
}
......@@ -863,7 +863,7 @@ FunctionOffsetsResult DecodeWasmFunctionOffsets(const byte* module_start,
table.reserve(functions_count);
int section_offset = static_cast<int>(code_section.start() - module_start);
DCHECK_LE(0, section_offset);
for (uint32_t i = 0; i < functions_count && decoder.ok(); i++) {
for (uint32_t i = 0; i < functions_count && decoder.ok(); ++i) {
uint32_t size = decoder.consume_u32v(&length, "body size");
int offset = static_cast<int>(section_offset + decoder.pc_offset());
table.push_back(std::make_pair(offset, static_cast<int>(size)));
......
......@@ -34,7 +34,7 @@ CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
}
std::sort(cases->begin(), cases->end());
ZoneVector<size_t> table_breaks(zone);
for (size_t i = 1; i < cases->size(); i++) {
for (size_t i = 1; i < cases->size(); ++i) {
if (cases->at(i) - cases->at(i - 1) > max_distance) {
table_breaks.push_back(i);
}
......@@ -42,7 +42,7 @@ CaseNode* OrderCases(ZoneVector<int>* cases, Zone* zone) {
table_breaks.push_back(cases->size());
ZoneVector<CaseNode*> nodes(zone);
size_t curr_pos = 0;
for (size_t i = 0; i < table_breaks.size(); i++) {
for (size_t i = 0; i < table_breaks.size(); ++i) {
size_t break_pos = table_breaks[i];
if (break_pos - curr_pos >= min_size) {
int begin = cases->at(curr_pos);
......
......@@ -822,7 +822,7 @@ class ControlTransfers : public ZoneObject {
TRACE("control @%td $%zu: BrTable[arity=%u count=%u]\n", (pc - start),
value_depth, operand.arity, operand.table_count);
value_depth -= (operand.arity + 1);
for (uint32_t i = 0; i < operand.table_count + 1; i++) {
for (uint32_t i = 0; i < operand.table_count + 1; ++i) {
uint32_t target = operand.read_entry(&decoder, i);
control_stack[control_stack.size() - target - 1].Ref(
&map_, start, pc + i, value_depth, operand.arity > 0);
......@@ -873,7 +873,7 @@ class CodeMap {
CodeMap(const WasmModule* module, Zone* zone)
: zone_(zone), module_(module), interpreter_code_(zone) {
if (module == nullptr) return;
for (size_t i = 0; i < module->functions.size(); i++) {
for (size_t i = 0; i < module->functions.size(); ++i) {
const WasmFunction* function = &module->functions[i];
const byte* code_start =
module->module_start + function->code_start_offset;
......@@ -964,7 +964,7 @@ class ThreadImpl : public WasmInterpreter::Thread {
InterpreterCode* code = codemap()->FindCode(function);
CHECK_NOT_NULL(code);
frames_.push_back({code, 0, 0, stack_.size()});
for (size_t i = 0; i < function->sig->parameter_count(); i++) {
for (size_t i = 0; i < function->sig->parameter_count(); ++i) {
stack_.push_back(args[i]);
}
frames_.back().ret_pc = InitLocals(code);
......@@ -1657,7 +1657,7 @@ class ThreadImpl : public WasmInterpreter::Thread {
sp_t plimit = top ? top->plimit() : 0;
sp_t llimit = top ? top->llimit() : 0;
if (FLAG_trace_wasm_interpreter) {
for (size_t i = sp; i < stack_.size(); i++) {
for (size_t i = sp; i < stack_.size(); ++i) {
if (i < plimit)
PrintF(" p%zu:", i);
else if (i < llimit)
......
......@@ -153,7 +153,7 @@ class LocalDeclEncoder {
size_t Emit(byte* buffer) const {
size_t pos = 0;
pos = WriteUint32v(buffer, pos, static_cast<uint32_t>(local_decls.size()));
for (size_t i = 0; i < local_decls.size(); i++) {
for (size_t i = 0; i < local_decls.size(); ++i) {
pos = WriteUint32v(buffer, pos, local_decls[i].first);
buffer[pos++] = WasmOpcodes::LocalTypeCodeFor(local_decls[i].second);
}
......
......@@ -178,7 +178,7 @@ Handle<JSArrayBuffer> NewArrayBuffer(Isolate* isolate, size_t size,
#if DEBUG
// Double check the API allocator actually zero-initialized the memory.
byte* bytes = reinterpret_cast<byte*>(*backing_store);
for (size_t i = 0; i < size; i++) {
for (size_t i = 0; i < size; ++i) {
DCHECK_EQ(0, bytes[i]);
}
#endif
......@@ -314,7 +314,7 @@ bool LinkFunction(Handle<Code> unlinked,
void LinkModuleFunctions(Isolate* isolate,
std::vector<Handle<Code>>& functions) {
for (size_t i = 0; i < functions.size(); i++) {
for (size_t i = 0; i < functions.size(); ++i) {
Handle<Code> code = functions[i];
bool modified = LinkFunction(code, functions, Code::WASM_FUNCTION);
if (modified) {
......@@ -521,7 +521,7 @@ void InitializeParallelCompilation(
Isolate* isolate, const std::vector<WasmFunction>& functions,
std::vector<compiler::WasmCompilationUnit*>& compilation_units,
ModuleEnv& module_env, ErrorThrower& thrower) {
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); i++) {
for (uint32_t i = FLAG_skip_compiling_wasm_funcs; i < functions.size(); ++i) {
compilation_units[i] = new compiler::WasmCompilationUnit(
&thrower, isolate, &module_env, &functions[i], i);
}
......@@ -537,7 +537,7 @@ uint32_t* StartCompilationTasks(
Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks),
V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads());
uint32_t* task_ids = new uint32_t[num_tasks];
for (size_t i = 0; i < num_tasks; i++) {
for (size_t i = 0; i < num_tasks; ++i) {
WasmCompilationTask* task =
new WasmCompilationTask(isolate, &compilation_units, &executed_units,
pending_tasks, &result_mutex, &next_unit);
......@@ -553,7 +553,7 @@ void WaitForCompilationTasks(Isolate* isolate, uint32_t* task_ids,
const size_t num_tasks =
Min(static_cast<size_t>(FLAG_wasm_num_compilation_tasks),
V8::GetCurrentPlatform()->NumberOfAvailableBackgroundThreads());
for (size_t i = 0; i < num_tasks; i++) {
for (size_t i = 0; i < num_tasks; ++i) {
// If the task has not started yet, then we abort it. Otherwise we wait for
// it to finish.
if (!isolate->cancelable_task_manager()->TryAbort(task_ids[i])) {
......@@ -651,7 +651,7 @@ void CompileSequentially(Isolate* isolate, const WasmModule* module,
DCHECK(!thrower->error());
for (uint32_t i = FLAG_skip_compiling_wasm_funcs;
i < module->functions.size(); i++) {
i < module->functions.size(); ++i) {
const WasmFunction& func = module->functions[i];
DCHECK_EQ(i, func.func_index);
......
......@@ -40,12 +40,12 @@ const char* WasmOpcodes::ShortOpcodeName(WasmOpcode opcode) {
std::ostream& operator<<(std::ostream& os, const FunctionSig& sig) {
if (sig.return_count() == 0) os << "v";
for (size_t i = 0; i < sig.return_count(); i++) {
for (size_t i = 0; i < sig.return_count(); ++i) {
os << WasmOpcodes::ShortNameOf(sig.GetReturn(i));
}
os << "_";
if (sig.parameter_count() == 0) os << "v";
for (size_t i = 0; i < sig.parameter_count(); i++) {
for (size_t i = 0; i < sig.parameter_count(); ++i) {
os << WasmOpcodes::ShortNameOf(sig.GetParam(i));
}
return os;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment