Commit 1f6afa86 authored by Georg Neis's avatar Georg Neis Committed by Commit Bot

[turbofan] Brokerize common operator reducer.

R=jarin@chromium.org

Bug: v8:7790
Change-Id: Idca77ca34c06fddfa73f412f20ba72500bbddf9c
Reviewed-on: https://chromium-review.googlesource.com/1128963Reviewed-by: 's avatarJaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Georg Neis <neis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54341}
parent 68621289
......@@ -19,7 +19,7 @@ namespace compiler {
namespace {
Decision DecideCondition(Isolate* isolate, Node* const cond) {
Decision DecideCondition(const JSHeapBroker* broker, Node* const cond) {
switch (cond->opcode()) {
case IrOpcode::kInt32Constant: {
Int32Matcher mcond(cond);
......@@ -27,8 +27,8 @@ Decision DecideCondition(Isolate* isolate, Node* const cond) {
}
case IrOpcode::kHeapConstant: {
HeapObjectMatcher mcond(cond);
return mcond.Value()->BooleanValue(isolate) ? Decision::kTrue
: Decision::kFalse;
ObjectRef object(mcond.Value());
return object.BooleanValue(broker) ? Decision::kTrue : Decision::kFalse;
}
default:
return Decision::kUnknown;
......@@ -37,14 +37,14 @@ Decision DecideCondition(Isolate* isolate, Node* const cond) {
} // namespace
CommonOperatorReducer::CommonOperatorReducer(Isolate* isolate, Editor* editor,
Graph* graph,
CommonOperatorReducer::CommonOperatorReducer(Editor* editor, Graph* graph,
const JSHeapBroker* js_heap_broker,
CommonOperatorBuilder* common,
MachineOperatorBuilder* machine,
Zone* temp_zone)
: AdvancedReducer(editor),
isolate_(isolate),
graph_(graph),
js_heap_broker_(js_heap_broker),
common_(common),
machine_(machine),
dead_(graph->NewNode(common->Dead())),
......@@ -53,6 +53,11 @@ CommonOperatorReducer::CommonOperatorReducer(Isolate* isolate, Editor* editor,
}
Reduction CommonOperatorReducer::Reduce(Node* node) {
DisallowHeapAllocation no_heap_allocation;
DisallowHandleAllocation no_handle_allocation;
DisallowHandleDereference no_handle_dereference;
DisallowCodeDependencyChange no_dependency_change;
switch (node->opcode()) {
case IrOpcode::kBranch:
return ReduceBranch(node);
......@@ -88,8 +93,10 @@ Reduction CommonOperatorReducer::ReduceBranch(Node* node) {
// not (i.e. true being returned in the false case and vice versa).
if (cond->opcode() == IrOpcode::kBooleanNot ||
(cond->opcode() == IrOpcode::kSelect &&
DecideCondition(isolate_, cond->InputAt(1)) == Decision::kFalse &&
DecideCondition(isolate_, cond->InputAt(2)) == Decision::kTrue)) {
DecideCondition(js_heap_broker(), cond->InputAt(1)) ==
Decision::kFalse &&
DecideCondition(js_heap_broker(), cond->InputAt(2)) ==
Decision::kTrue)) {
for (Node* const use : node->uses()) {
switch (use->opcode()) {
case IrOpcode::kIfTrue:
......@@ -111,7 +118,7 @@ Reduction CommonOperatorReducer::ReduceBranch(Node* node) {
node, common()->Branch(NegateBranchHint(BranchHintOf(node->op()))));
return Changed(node);
}
Decision const decision = DecideCondition(isolate_, cond);
Decision const decision = DecideCondition(js_heap_broker(), cond);
if (decision == Decision::kUnknown) return NoChange();
Node* const control = node->InputAt(1);
for (Node* const use : node->uses()) {
......@@ -151,7 +158,7 @@ Reduction CommonOperatorReducer::ReduceDeoptimizeConditional(Node* node) {
: common()->DeoptimizeUnless(p.kind(), p.reason(), p.feedback()));
return Changed(node);
}
Decision const decision = DecideCondition(isolate_, condition);
Decision const decision = DecideCondition(js_heap_broker(), condition);
if (decision == Decision::kUnknown) return NoChange();
if (condition_is_true == (decision == Decision::kTrue)) {
ReplaceWithValue(node, dead(), effect, control);
......@@ -384,7 +391,7 @@ Reduction CommonOperatorReducer::ReduceSelect(Node* node) {
Node* const vtrue = node->InputAt(1);
Node* const vfalse = node->InputAt(2);
if (vtrue == vfalse) return Replace(vtrue);
switch (DecideCondition(isolate_, cond)) {
switch (DecideCondition(js_heap_broker(), cond)) {
case Decision::kTrue:
return Replace(vtrue);
case Decision::kFalse:
......
......@@ -24,7 +24,8 @@ class Operator;
class V8_EXPORT_PRIVATE CommonOperatorReducer final
: public NON_EXPORTED_BASE(AdvancedReducer) {
public:
CommonOperatorReducer(Isolate* isolate, Editor* editor, Graph* graph,
CommonOperatorReducer(Editor* editor, Graph* graph,
const JSHeapBroker* js_heap_broker,
CommonOperatorBuilder* common,
MachineOperatorBuilder* machine, Zone* temp_zone);
~CommonOperatorReducer() final {}
......@@ -47,15 +48,13 @@ class V8_EXPORT_PRIVATE CommonOperatorReducer final
Reduction Change(Node* node, Operator const* op, Node* a, Node* b);
Graph* graph() const { return graph_; }
const JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
CommonOperatorBuilder* common() const { return common_; }
MachineOperatorBuilder* machine() const { return machine_; }
Node* dead() const { return dead_; }
// TODO(mstarzinger): Remove the Isolate field, which is only required for
// HeapObject::BooleanValue. This field should not be used for any other
// purpose.
Isolate* isolate_;
Graph* const graph_;
const JSHeapBroker* const js_heap_broker_;
CommonOperatorBuilder* const common_;
MachineOperatorBuilder* const machine_;
Node* const dead_;
......
......@@ -1023,15 +1023,13 @@ PipelineWasmCompilationJob::ExecuteJobImpl() {
if (FLAG_wasm_opt || asmjs_origin_) {
GraphReducer graph_reducer(scope.zone(), data->graph(),
data->mcgraph()->Dead());
// WASM compilations must *always* be independent of the isolate.
Isolate* isolate = nullptr;
DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(),
data->common(), scope.zone());
ValueNumberingReducer value_numbering(scope.zone(), data->graph()->zone());
MachineOperatorReducer machine_reducer(data->mcgraph(), asmjs_origin_);
CommonOperatorReducer common_reducer(isolate, &graph_reducer, data->graph(),
data->common(), data->machine(),
scope.zone());
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), scope.zone());
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &machine_reducer);
AddReducer(data, &graph_reducer, &common_reducer);
......@@ -1175,9 +1173,9 @@ struct InliningPhase {
DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(),
data->common(), temp_zone);
CheckpointElimination checkpoint_elimination(&graph_reducer);
CommonOperatorReducer common_reducer(isolate, &graph_reducer, data->graph(),
data->common(), data->machine(),
temp_zone);
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
JSCallReducer call_reducer(&graph_reducer, data->jsgraph(),
data->js_heap_broker(),
data->info()->is_bailout_on_uninitialized()
......@@ -1284,8 +1282,8 @@ struct TypedLoweringPhase {
SimplifiedOperatorReducer simple_reducer(&graph_reducer, data->jsgraph(),
data->js_heap_broker());
CheckpointElimination checkpoint_elimination(&graph_reducer);
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
data->graph(), data->common(),
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &create_lowering);
......@@ -1405,8 +1403,8 @@ struct EarlyOptimizationPhase {
RedundancyElimination redundancy_elimination(&graph_reducer, temp_zone);
ValueNumberingReducer value_numbering(temp_zone, data->graph()->zone());
MachineOperatorReducer machine_reducer(data->jsgraph());
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
data->graph(), data->common(),
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &simple_reducer);
......@@ -1476,9 +1474,9 @@ struct EffectControlLinearizationPhase {
data->jsgraph()->Dead());
DeadCodeElimination dead_code_elimination(&graph_reducer, data->graph(),
data->common(), temp_zone);
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
data->graph(), data->common(),
data->machine(), temp_zone);
CommonOperatorReducer common_reducer(
&graph_reducer, data->graph(), data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &common_reducer);
graph_reducer.ReduceGraph();
......@@ -1514,8 +1512,8 @@ struct LoadEliminationPhase {
temp_zone);
CheckpointElimination checkpoint_elimination(&graph_reducer);
ValueNumberingReducer value_numbering(temp_zone, data->graph()->zone());
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
data->graph(), data->common(),
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
ConstantFoldingReducer constant_folding_reducer(
&graph_reducer, data->jsgraph(), data->js_heap_broker());
......@@ -1566,8 +1564,8 @@ struct LateOptimizationPhase {
data->common(), temp_zone);
ValueNumberingReducer value_numbering(temp_zone, data->graph()->zone());
MachineOperatorReducer machine_reducer(data->jsgraph());
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
data->graph(), data->common(),
CommonOperatorReducer common_reducer(&graph_reducer, data->graph(),
data->js_heap_broker(), data->common(),
data->machine(), temp_zone);
SelectLowering select_lowering(data->jsgraph()->graph(),
data->jsgraph()->common());
......
......@@ -29,10 +29,11 @@ class CommonOperatorReducerTest : public GraphTest {
Reduction Reduce(
AdvancedReducer::Editor* editor, Node* node,
MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
JSHeapBroker broker(isolate());
MachineOperatorBuilder machine(zone(), MachineType::PointerRepresentation(),
flags);
CommonOperatorReducer reducer(isolate(), editor, graph(), common(),
&machine, zone());
CommonOperatorReducer reducer(editor, graph(), &broker, common(), &machine,
zone());
return reducer.Reduce(node);
}
......
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