Skip to content

Commit

Permalink
[vm/compiler] Canonicalize more intermediate constants in IL.
Browse files Browse the repository at this point in the history
* when building IL from Kernel use canonical double representation
instead of allocating new double objects;
* in constant propagation canonicalize immutable primitive constants
(strings, mints and doubles) before replacing instruction with its
constant value;

This relands 5909932 with the part
that was causing timeouts on flutter_test reverted.

See #32904 for more details.

TBR=aam@google.com

Change-Id: I0c128e44dd6c9689c4b7e9dd91832408214847f3
Reviewed-on: https://dart-review.googlesource.com/51460
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
  • Loading branch information
mraleph authored and commit-bot@chromium.org committed Apr 20, 2018
1 parent 9d7e35b commit 375b32d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 10 additions & 1 deletion runtime/vm/compiler/backend/constant_propagator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ DEFINE_FLAG(bool,
// Quick access to the current zone and isolate.
#define I (isolate())
#define Z (graph_->zone())
#define T (graph_->thread())

ConstantPropagator::ConstantPropagator(
FlowGraph* graph,
Expand Down Expand Up @@ -1321,6 +1322,7 @@ void ConstantPropagator::Transform() {
// instructions, previous pointers, predecessors, etc. after eliminating
// unreachable code. We do not maintain those properties during the
// transformation.
auto& value = Object::Handle(Z);
for (BlockIterator b = graph_->reverse_postorder_iterator(); !b.Done();
b.Advance()) {
BlockEntryInstr* block = b.Current();
Expand Down Expand Up @@ -1398,7 +1400,14 @@ void ConstantPropagator::Transform() {
THR_Print("Constant v%" Pd " = %s\n", defn->ssa_temp_index(),
defn->constant_value().ToCString());
}
ConstantInstr* constant = graph_->GetConstant(defn->constant_value());
value = defn->constant_value().raw();
if ((value.IsString() || value.IsMint() || value.IsDouble()) &&
!value.IsCanonical()) {
const char* error_str = nullptr;
value = Instance::Cast(value).CheckAndCanonicalize(T, &error_str);
ASSERT(!value.IsNull() && (error_str == nullptr));
}
ConstantInstr* constant = graph_->GetConstant(value);
defn->ReplaceUsesWith(constant);
i.RemoveCurrentFromGraph();
}
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8985,9 +8985,9 @@ Fragment StreamingFlowGraphBuilder::BuildDoubleLiteral(
TokenPosition* position) {
if (position != NULL) *position = TokenPosition::kNoSource;

Double& constant =
Double::ZoneHandle(Z, Double::New(H.DartString(ReadStringReference()),
Heap::kOld)); // read string reference.
Double& constant = Double::ZoneHandle(
Z, Double::NewCanonical(
H.DartString(ReadStringReference()))); // read string reference.
return Constant(constant);
}

Expand Down

0 comments on commit 375b32d

Please sign in to comment.