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

Unified Diff: runtime/vm/intermediate_language_mips.cc

Issue 62133002: Cleanup of branch code generation (no change in functionality). (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: rebased Created 7 years, 1 month 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
« no previous file with comments | « runtime/vm/intermediate_language_ia32.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intermediate_language_mips.cc
===================================================================
--- runtime/vm/intermediate_language_mips.cc (revision 30039)
+++ runtime/vm/intermediate_language_mips.cc (working copy)
@@ -127,21 +127,6 @@
}
-static bool BindsToSmiConstant(Value* val, intptr_t* smi_value) {
- if (!val->BindsToConstant()) {
- return false;
- }
-
- const Object& bound_constant = val->BoundConstant();
- if (!bound_constant.IsSmi()) {
- return false;
- }
-
- *smi_value = Smi::Cast(bound_constant).Value();
- return true;
-}
-
-
// Detect pattern when one value is zero and another is a power of 2.
static bool IsPowerOfTwoKind(intptr_t v1, intptr_t v2) {
return (Utils::IsPowerOfTwo(v1) && (v2 == 0)) ||
@@ -149,27 +134,6 @@
}
-bool IfThenElseInstr::Supports(ComparisonInstr* comparison,
- Value* v1,
- Value* v2) {
- if (!(comparison->IsStrictCompare() &&
- !comparison->AsStrictCompare()->needs_number_check()) &&
- !(comparison->IsEqualityCompare() &&
- (comparison->AsEqualityCompare()->operation_cid() == kSmiCid))) {
- return false;
- }
-
- intptr_t v1_value, v2_value;
-
- if (!BindsToSmiConstant(v1, &v1_value) ||
- !BindsToSmiConstant(v2, &v2_value)) {
- return false;
- }
-
- return true;
-}
-
-
LocationSummary* IfThenElseInstr::MakeLocationSummary() const {
const intptr_t kNumInputs = 2;
const intptr_t kNumTemps = 0;
@@ -505,6 +469,42 @@
}
+static void EmitBranchOnValue(FlowGraphCompiler* compiler,
+ TargetEntryInstr* true_successor,
+ TargetEntryInstr* false_successor,
+ bool value) {
+ __ TraceSimMsg("ControlInstruction::EmitBranchOnValue");
+ if (value && !compiler->CanFallThroughTo(true_successor)) {
+ __ b(compiler->GetJumpLabel(true_successor));
+ } else if (!value && !compiler->CanFallThroughTo(false_successor)) {
+ __ b(compiler->GetJumpLabel(false_successor));
+ }
+}
+
+
+// The comparison result is in CMPRES1.
+static void EmitBranchOnCondition(FlowGraphCompiler* compiler,
+ TargetEntryInstr* true_successor,
+ TargetEntryInstr* false_successor,
+ Condition true_condition) {
+ __ TraceSimMsg("ControlInstruction::EmitBranchOnCondition");
+ if (compiler->CanFallThroughTo(false_successor)) {
+ // If the next block is the false successor, fall through to it.
+ Label* label = compiler->GetJumpLabel(true_successor);
+ EmitBranchAfterCompare(compiler, true_condition, label);
+ } else {
+ // If the next block is not the false successor, branch to it.
+ Condition false_condition = NegateCondition(true_condition);
+ Label* label = compiler->GetJumpLabel(false_successor);
+ EmitBranchAfterCompare(compiler, false_condition, label);
+ // Fall through or jump to the true successor.
+ if (!compiler->CanFallThroughTo(true_successor)) {
+ __ b(compiler->GetJumpLabel(true_successor));
+ }
+ }
+}
+
+
static void EmitSmiComparisonOp(FlowGraphCompiler* compiler,
const LocationSummary& locs,
Token::Kind kind,
@@ -528,7 +528,10 @@
}
if (branch != NULL) {
- branch->EmitBranchOnCondition(compiler, true_condition);
+ EmitBranchOnCondition(compiler,
+ branch->true_successor(),
+ branch->false_successor(),
+ true_condition);
} else {
Register result = locs.out().reg();
Label done, is_true;
@@ -573,6 +576,87 @@
}
+static void EmitDoubleCompareBranch(FlowGraphCompiler* compiler,
+ Condition true_condition,
+ FpuRegister left,
+ FpuRegister right,
+ BranchInstr* branch) {
+ ASSERT(branch != NULL);
+ __ Comment("DoubleCompareBranch");
+ __ cund(left, right);
+ BlockEntryInstr* nan_result = (true_condition == NE) ?
+ branch->true_successor() : branch->false_successor();
+ __ bc1t(compiler->GetJumpLabel(nan_result));
+
+ switch (true_condition) {
+ case EQ: __ ceqd(left, right); break;
+ case NE: __ ceqd(left, right); break;
+ case LT: __ coltd(left, right); break;
+ case LE: __ coled(left, right); break;
+ case GT: __ coltd(right, left); break;
+ case GE: __ coled(right, left); break;
+ default: {
+ // Should only passing the above conditions to this function.
+ UNREACHABLE();
+ break;
+ }
+ }
+
+ __ LoadImmediate(TMP, 1);
+ if (true_condition == NE) {
+ __ movf(CMPRES1, ZR);
+ __ movt(CMPRES1, TMP);
+ } else {
+ __ movf(CMPRES1, TMP);
+ __ movt(CMPRES1, ZR);
+ }
+ __ mov(CMPRES2, ZR);
+
+ // EmitBranchOnCondition expects ordering to be described by CMPRES1, CMPRES2.
+ EmitBranchOnCondition(compiler,
+ branch->true_successor(),
+ branch->false_successor(),
+ EQ);
+}
+
+
+static void EmitDoubleCompareBool(FlowGraphCompiler* compiler,
+ Condition true_condition,
+ FpuRegister left,
+ FpuRegister right,
+ Register result) {
+ Label done, is_true;
+ Label* nan_label = (true_condition == NE) ? &is_true : &done;
+ __ Comment("DoubleCompareBool");
+ __ LoadObject(result, Bool::False());
+ __ cund(left, right);
+ __ bc1t(nan_label);
+
+ switch (true_condition) {
+ case EQ: __ ceqd(left, right); break;
+ case NE: __ ceqd(left, right); break;
+ case LT: __ coltd(left, right); break;
+ case LE: __ coled(left, right); break;
+ case GT: __ coltd(right, left); break;
+ case GE: __ coled(right, left); break;
+ default: {
+ // Should only passing the above conditions to this function.
+ UNREACHABLE();
+ break;
+ }
+ }
+
+ if (true_condition == NE) {
+ __ bc1t(&done); // False is already in result.
+ } else {
+ __ bc1f(&done);
+ }
+ __ Bind(&is_true);
+ __ LoadObject(result, Bool::True());
+ __ Bind(&done);
+}
+
+
static void EmitDoubleComparisonOp(FlowGraphCompiler* compiler,
const LocationSummary& locs,
Token::Kind kind,
@@ -584,11 +668,10 @@
Condition true_condition = TokenKindToDoubleCondition(kind);
if (branch != NULL) {
- compiler->EmitDoubleCompareBranch(
- true_condition, left, right, branch);
+ EmitDoubleCompareBranch(compiler, true_condition, left, right, branch);
} else {
- compiler->EmitDoubleCompareBool(
- true_condition, left, right, locs.out().reg());
+ EmitDoubleCompareBool(compiler, true_condition,
+ left, right, locs.out().reg());
}
}
@@ -668,7 +751,10 @@
__ and_(CMPRES1, left, right.reg());
}
__ mov(CMPRES2, ZR);
- branch->EmitBranchOnCondition(compiler, branch_condition);
+ EmitBranchOnCondition(compiler,
+ branch->true_successor(),
+ branch->false_successor(),
+ branch_condition);
}
@@ -3710,38 +3796,6 @@
}
-void ControlInstruction::EmitBranchOnValue(FlowGraphCompiler* compiler,
- bool value) {
- __ TraceSimMsg("ControlInstruction::EmitBranchOnValue");
- if (value && !compiler->CanFallThroughTo(true_successor())) {
- __ b(compiler->GetJumpLabel(true_successor()));
- } else if (!value && !compiler->CanFallThroughTo(false_successor())) {
- __ b(compiler->GetJumpLabel(false_successor()));
- }
-}
-
-
-// The comparison result is in CMPRES1.
-void ControlInstruction::EmitBranchOnCondition(FlowGraphCompiler* compiler,
- Condition true_condition) {
- __ TraceSimMsg("ControlInstruction::EmitBranchOnCondition");
- if (compiler->CanFallThroughTo(false_successor())) {
- // If the next block is the false successor, fall through to it.
- Label* label = compiler->GetJumpLabel(true_successor());
- EmitBranchAfterCompare(compiler, true_condition, label);
- } else {
- // If the next block is not the false successor, branch to it.
- Condition false_condition = NegateCondition(true_condition);
- Label* label = compiler->GetJumpLabel(false_successor());
- EmitBranchAfterCompare(compiler, false_condition, label);
- // Fall through or jump to the true successor.
- if (!compiler->CanFallThroughTo(true_successor())) {
- __ b(compiler->GetJumpLabel(true_successor()));
- }
- }
-}
-
-
LocationSummary* CurrentContextInstr::MakeLocationSummary() const {
return LocationSummary::Make(0,
Location::RequiresRegister(),
@@ -3825,7 +3879,10 @@
const bool result = (kind() == Token::kEQ_STRICT) ?
left.constant().raw() == right.constant().raw() :
left.constant().raw() != right.constant().raw();
- branch->EmitBranchOnValue(compiler, result);
+ EmitBranchOnValue(compiler,
+ branch->true_successor(),
+ branch->false_successor(),
+ result);
return;
}
if (left.IsConstant()) {
@@ -3846,7 +3903,10 @@
}
Condition true_condition = (kind() == Token::kEQ_STRICT) ? EQ : NE;
- branch->EmitBranchOnCondition(compiler, true_condition);
+ EmitBranchOnCondition(compiler,
+ branch->true_successor(),
+ branch->false_successor(),
+ true_condition);
}
« no previous file with comments | « runtime/vm/intermediate_language_ia32.cc ('k') | runtime/vm/intermediate_language_x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698