Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(383)

Unified Diff: runtime/vm/flow_graph_optimizer.cc

Issue 12178019: Add a use list iterator that allows mutation of current. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/vm/flow_graph_optimizer.cc
diff --git a/runtime/vm/flow_graph_optimizer.cc b/runtime/vm/flow_graph_optimizer.cc
index f0355837f6e06eeb6a0fcc683254b3d3482415f4..82871667a4db7aac21418bf1ddd8b7739b8c2a5b 100644
--- a/runtime/vm/flow_graph_optimizer.cc
+++ b/runtime/vm/flow_graph_optimizer.cc
@@ -224,46 +224,47 @@ void FlowGraphOptimizer::Canonicalize() {
void FlowGraphOptimizer::InsertConversion(Representation from,
Representation to,
- Instruction* instr,
Value* use,
- Definition* def,
+ Instruction* insert_before,
Instruction* deopt_target) {
Definition* converted = NULL;
if ((from == kTagged) && (to == kUnboxedMint)) {
+ ASSERT((deopt_target != NULL) ||
+ (use->definition()->GetPropagatedCid() == kDoubleCid));
const intptr_t deopt_id = (deopt_target != NULL) ?
deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId;
- ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid));
- converted = new UnboxIntegerInstr(new Value(def), deopt_id);
+ converted = new UnboxIntegerInstr(new Value(use->definition()), deopt_id);
} else if ((from == kUnboxedMint) && (to == kTagged)) {
- converted = new BoxIntegerInstr(new Value(def));
+ converted = new BoxIntegerInstr(new Value(use->definition()));
} else if (from == kUnboxedMint && to == kUnboxedDouble) {
// Convert by boxing/unboxing.
// TODO(fschneider): Implement direct unboxed mint-to-double conversion.
- BoxIntegerInstr* boxed = new BoxIntegerInstr(new Value(def));
- InsertBefore(instr, boxed, NULL, Definition::kValue);
+ BoxIntegerInstr* boxed = new BoxIntegerInstr(new Value(use->definition()));
+ InsertBefore(insert_before, boxed, NULL, Definition::kValue);
const intptr_t deopt_id = (deopt_target != NULL) ?
deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId;
converted = new UnboxDoubleInstr(new Value(boxed), deopt_id);
} else if ((from == kUnboxedDouble) && (to == kTagged)) {
- converted = new BoxDoubleInstr(new Value(def), NULL);
+ converted = new BoxDoubleInstr(new Value(use->definition()), NULL);
} else if ((from == kTagged) && (to == kUnboxedDouble)) {
const intptr_t deopt_id = (deopt_target != NULL) ?
deopt_target->DeoptimizationTarget() : Isolate::kNoDeoptId;
- ASSERT((deopt_target != NULL) || (def->GetPropagatedCid() == kDoubleCid));
- if (def->IsConstant() && def->AsConstant()->value().IsSmi()) {
- const double dbl_val =
- Smi::Cast(def->AsConstant()->value()).AsDoubleValue();
+ ASSERT((deopt_target != NULL) ||
+ (use->definition()->GetPropagatedCid() == kDoubleCid));
+ ConstantInstr* constant = use->definition()->AsConstant();
+ if ((constant != NULL) && constant->value().IsSmi()) {
+ const double dbl_val = Smi::Cast(constant->value()).AsDoubleValue();
const Double& dbl_obj =
Double::ZoneHandle(Double::New(dbl_val, Heap::kOld));
ConstantInstr* double_const = new ConstantInstr(dbl_obj);
- InsertBefore(instr, double_const, NULL, Definition::kValue);
+ InsertBefore(insert_before, double_const, NULL, Definition::kValue);
converted = new UnboxDoubleInstr(new Value(double_const), deopt_id);
} else {
- converted = new UnboxDoubleInstr(new Value(def), deopt_id);
+ converted = new UnboxDoubleInstr(new Value(use->definition()), deopt_id);
}
}
ASSERT(converted != NULL);
- InsertBefore(instr, converted, use->instruction()->env(),
+ InsertBefore(insert_before, converted, use->instruction()->env(),
Definition::kValue);
use->set_definition(converted);
}
@@ -272,29 +273,31 @@ void FlowGraphOptimizer::InsertConversion(Representation from,
void FlowGraphOptimizer::InsertConversionsFor(Definition* def) {
const Representation from_rep = def->representation();
- for (Value* use = def->input_use_list();
- use != NULL;
- use = use->next_use()) {
+ for (Value::Iterator it(def->input_use_list());
+ !it.Done();
+ it.Advance()) {
+ Value* use = it.Current();
const Representation to_rep =
use->instruction()->RequiredInputRepresentation(use->use_index());
if (from_rep == to_rep) {
continue;
}
- Instruction* deopt_target = NULL;
- Instruction* instr = use->instruction();
- if (instr->IsPhi()) {
- if (!instr->AsPhi()->is_alive()) continue;
+ Instruction* insert_before;
+ Instruction* deopt_target;
+ PhiInstr* phi = use->instruction()->AsPhi();
+ if (phi != NULL) {
+ if (!phi->is_alive()) continue;
// For phis conversions have to be inserted in the predecessor.
- const BlockEntryInstr* pred =
- instr->AsPhi()->block()->PredecessorAt(use->use_index());
- instr = pred->last_instruction();
+ insert_before =
+ phi->block()->PredecessorAt(use->use_index())->last_instruction();
+ deopt_target = NULL;
} else {
- deopt_target = instr;
+ deopt_target = insert_before = use->instruction();
}
- InsertConversion(from_rep, to_rep, instr, use, def, deopt_target);
+ InsertConversion(from_rep, to_rep, use, insert_before, deopt_target);
}
}
@@ -2199,11 +2202,10 @@ static bool IsDominatedUse(Instruction* dom, Value* use) {
void RangeAnalysis::RenameDominatedUses(Definition* def,
Instruction* dom,
Definition* other) {
- Value* next_use = NULL;
- for (Value* use = def->input_use_list();
- use != NULL;
- use = next_use) {
- next_use = use->next_use();
+ for (Value::Iterator it(def->input_use_list());
+ !it.Done();
+ it.Advance()) {
+ Value* use = it.Current();
// Skip dead phis.
PhiInstr* phi = use->instruction()->AsPhi();

Powered by Google App Engine
This is Rietveld 408576698