mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 20:51:50 +00:00
Move ConstantPropagator from flow_graph_optimizer.cc/.h into separate files.
flow_graph_optimizer.cc is becoming unnecessarily large, so I'm moving self-contained optimization passes into separate files. In a separate CL I'll also move load/store optimization into separate files. R=srdjan@google.com Review URL: https://codereview.chromium.org//820883004 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@42567 260f80e4-7a28-3924-810f-c04153c831b5
This commit is contained in:
parent
49343faead
commit
009eb5d33c
|
@ -11,6 +11,7 @@
|
|||
#include "vm/cha.h"
|
||||
#include "vm/code_generator.h"
|
||||
#include "vm/code_patcher.h"
|
||||
#include "vm/constant_propagator.h"
|
||||
#include "vm/dart_entry.h"
|
||||
#include "vm/debugger.h"
|
||||
#include "vm/deopt_instructions.h"
|
||||
|
|
1638
runtime/vm/constant_propagator.cc
Normal file
1638
runtime/vm/constant_propagator.cc
Normal file
File diff suppressed because it is too large
Load diff
92
runtime/vm/constant_propagator.h
Normal file
92
runtime/vm/constant_propagator.h
Normal file
|
@ -0,0 +1,92 @@
|
|||
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#ifndef VM_CONSTANT_PROPAGATOR_H_
|
||||
#define VM_CONSTANT_PROPAGATOR_H_
|
||||
|
||||
#include "vm/intermediate_language.h"
|
||||
#include "vm/flow_graph.h"
|
||||
|
||||
namespace dart {
|
||||
|
||||
// Sparse conditional constant propagation and unreachable code elimination.
|
||||
// Assumes that use lists are computed and preserves them.
|
||||
class ConstantPropagator : public FlowGraphVisitor {
|
||||
public:
|
||||
ConstantPropagator(FlowGraph* graph,
|
||||
const GrowableArray<BlockEntryInstr*>& ignored);
|
||||
|
||||
static void Optimize(FlowGraph* graph);
|
||||
|
||||
// (1) Visit branches to optimize away unreachable blocks discovered by range
|
||||
// analysis.
|
||||
// (2) Eliminate branches that have the same true- and false-target: For
|
||||
// example, this occurs after expressions like
|
||||
//
|
||||
// if (a == null || b == null) {
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// where b is known to be null.
|
||||
static void OptimizeBranches(FlowGraph* graph);
|
||||
|
||||
// Used to initialize the abstract value of definitions.
|
||||
static RawObject* Unknown() { return Object::unknown_constant().raw(); }
|
||||
|
||||
private:
|
||||
void Analyze();
|
||||
void Transform();
|
||||
void EliminateRedundantBranches();
|
||||
|
||||
void SetReachable(BlockEntryInstr* block);
|
||||
bool SetValue(Definition* definition, const Object& value);
|
||||
|
||||
Definition* UnwrapPhi(Definition* defn);
|
||||
void MarkPhi(Definition* defn);
|
||||
|
||||
// Assign the join (least upper bound) of a pair of abstract values to the
|
||||
// first one.
|
||||
void Join(Object* left, const Object& right);
|
||||
|
||||
bool IsUnknown(const Object& value) {
|
||||
return value.raw() == unknown_.raw();
|
||||
}
|
||||
bool IsNonConstant(const Object& value) {
|
||||
return value.raw() == non_constant_.raw();
|
||||
}
|
||||
bool IsConstant(const Object& value) {
|
||||
return !IsNonConstant(value) && !IsUnknown(value);
|
||||
}
|
||||
|
||||
void VisitBinaryIntegerOp(BinaryIntegerOpInstr* binary_op);
|
||||
|
||||
virtual void VisitBlocks() { UNREACHABLE(); }
|
||||
|
||||
#define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr);
|
||||
FOR_EACH_INSTRUCTION(DECLARE_VISIT)
|
||||
#undef DECLARE_VISIT
|
||||
|
||||
Isolate* isolate() const { return graph_->isolate(); }
|
||||
|
||||
FlowGraph* graph_;
|
||||
|
||||
// Sentinels for unknown constant and non-constant values.
|
||||
const Object& unknown_;
|
||||
const Object& non_constant_;
|
||||
|
||||
// Analysis results. For each block, a reachability bit. Indexed by
|
||||
// preorder number.
|
||||
BitVector* reachable_;
|
||||
|
||||
BitVector* marked_phis_;
|
||||
|
||||
// Worklists of blocks and definitions.
|
||||
GrowableArray<BlockEntryInstr*> block_worklist_;
|
||||
DefinitionWorklist definition_worklist_;
|
||||
};
|
||||
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif // VM_CONSTANT_PROPAGATOR_H_
|
File diff suppressed because it is too large
Load diff
|
@ -316,83 +316,6 @@ class DeadCodeElimination : public AllStatic {
|
|||
};
|
||||
|
||||
|
||||
// Sparse conditional constant propagation and unreachable code elimination.
|
||||
// Assumes that use lists are computed and preserves them.
|
||||
class ConstantPropagator : public FlowGraphVisitor {
|
||||
public:
|
||||
ConstantPropagator(FlowGraph* graph,
|
||||
const GrowableArray<BlockEntryInstr*>& ignored);
|
||||
|
||||
static void Optimize(FlowGraph* graph);
|
||||
|
||||
// (1) Visit branches to optimize away unreachable blocks discovered by range
|
||||
// analysis.
|
||||
// (2) Eliminate branches that have the same true- and false-target: For
|
||||
// example, this occurs after expressions like
|
||||
//
|
||||
// if (a == null || b == null) {
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// where b is known to be null.
|
||||
static void OptimizeBranches(FlowGraph* graph);
|
||||
|
||||
// Used to initialize the abstract value of definitions.
|
||||
static RawObject* Unknown() { return Object::unknown_constant().raw(); }
|
||||
|
||||
private:
|
||||
void Analyze();
|
||||
void Transform();
|
||||
void EliminateRedundantBranches();
|
||||
|
||||
void SetReachable(BlockEntryInstr* block);
|
||||
bool SetValue(Definition* definition, const Object& value);
|
||||
|
||||
Definition* UnwrapPhi(Definition* defn);
|
||||
void MarkPhi(Definition* defn);
|
||||
|
||||
// Assign the join (least upper bound) of a pair of abstract values to the
|
||||
// first one.
|
||||
void Join(Object* left, const Object& right);
|
||||
|
||||
bool IsUnknown(const Object& value) {
|
||||
return value.raw() == unknown_.raw();
|
||||
}
|
||||
bool IsNonConstant(const Object& value) {
|
||||
return value.raw() == non_constant_.raw();
|
||||
}
|
||||
bool IsConstant(const Object& value) {
|
||||
return !IsNonConstant(value) && !IsUnknown(value);
|
||||
}
|
||||
|
||||
void VisitBinaryIntegerOp(BinaryIntegerOpInstr* binary_op);
|
||||
|
||||
virtual void VisitBlocks() { UNREACHABLE(); }
|
||||
|
||||
#define DECLARE_VISIT(type) virtual void Visit##type(type##Instr* instr);
|
||||
FOR_EACH_INSTRUCTION(DECLARE_VISIT)
|
||||
#undef DECLARE_VISIT
|
||||
|
||||
Isolate* isolate() const { return graph_->isolate(); }
|
||||
|
||||
FlowGraph* graph_;
|
||||
|
||||
// Sentinels for unknown constant and non-constant values.
|
||||
const Object& unknown_;
|
||||
const Object& non_constant_;
|
||||
|
||||
// Analysis results. For each block, a reachability bit. Indexed by
|
||||
// preorder number.
|
||||
BitVector* reachable_;
|
||||
|
||||
BitVector* marked_phis_;
|
||||
|
||||
// Worklists of blocks and definitions.
|
||||
GrowableArray<BlockEntryInstr*> block_worklist_;
|
||||
DefinitionWorklist definition_worklist_;
|
||||
};
|
||||
|
||||
|
||||
// Rewrite branches to eliminate materialization of boolean values after
|
||||
// inlining, and to expose other optimizations (e.g., constant folding of
|
||||
// branches, unreachable code elimination).
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "vm/intermediate_language.h"
|
||||
|
||||
#include "vm/bit_vector.h"
|
||||
#include "vm/constant_propagator.h"
|
||||
#include "vm/cpu.h"
|
||||
#include "vm/dart_entry.h"
|
||||
#include "vm/flow_graph_allocator.h"
|
||||
|
@ -39,7 +40,6 @@ DEFINE_FLAG(bool, unbox_numeric_fields, true,
|
|||
DECLARE_FLAG(bool, enable_type_checks);
|
||||
DECLARE_FLAG(bool, eliminate_type_checks);
|
||||
DECLARE_FLAG(bool, trace_optimization);
|
||||
DECLARE_FLAG(bool, trace_constant_propagation);
|
||||
DECLARE_FLAG(bool, throw_on_javascript_int_overflow);
|
||||
|
||||
Definition::Definition(intptr_t deopt_id)
|
||||
|
|
|
@ -95,6 +95,8 @@
|
|||
'compiler_stats.cc',
|
||||
'compiler_stats.h',
|
||||
'compiler_test.cc',
|
||||
'constant_propagator.h',
|
||||
'constant_propagator.cc',
|
||||
'constants_arm.h',
|
||||
'constants_arm64.h',
|
||||
'constants_ia32.h',
|
||||
|
|
Loading…
Reference in a new issue