From 7d98d8e01d66031bacdf4634703d41ce69cb6dfb Mon Sep 17 00:00:00 2001 From: Florian Sattler Date: Mon, 10 Sep 2018 15:46:52 +0200 Subject: [PATCH] [compiler] Fixed some perf related issues. This patch removes unnecessary copies and adds reserves to vectors that are filled in a loop afterwards. Fixing clang-tidy warning. Bug: v8:8015 Change-Id: I4e13c0445a9760e09ef03a62ae48be622ebecc6b Reviewed-on: https://chromium-review.googlesource.com/1209783 Reviewed-by: Michael Starzinger Commit-Queue: Florian Sattler Cr-Commit-Position: refs/heads/master@{#55776} --- src/compiler/bytecode-graph-builder.cc | 2 +- src/compiler/code-generator.cc | 2 +- src/compiler/escape-analysis.cc | 2 +- src/compiler/frame-states.cc | 6 ++++++ src/compiler/js-call-reducer.cc | 1 + src/compiler/js-generic-lowering.cc | 6 ++++-- src/compiler/store-store-elimination.cc | 10 +++++----- 7 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/compiler/bytecode-graph-builder.cc b/src/compiler/bytecode-graph-builder.cc index 0c061e797d..415fbd84d7 100644 --- a/src/compiler/bytecode-graph-builder.cc +++ b/src/compiler/bytecode-graph-builder.cc @@ -801,7 +801,7 @@ void BytecodeGraphBuilder::AdvanceToOsrEntryAndPeelLoops( int current_parent_offset = analysis.GetLoopInfoFor(osr_offset).parent_offset(); while (current_parent_offset != -1) { - LoopInfo current_parent_loop = + const LoopInfo& current_parent_loop = analysis.GetLoopInfoFor(current_parent_offset); // We iterate until the back edge of the parent loop, which we detect by // the offset that the JumpLoop targets. diff --git a/src/compiler/code-generator.cc b/src/compiler/code-generator.cc index 83060f9e38..6efaf55725 100644 --- a/src/compiler/code-generator.cc +++ b/src/compiler/code-generator.cc @@ -69,7 +69,7 @@ CodeGenerator::CodeGenerator( caller_registers_saved_(false), jump_tables_(nullptr), ools_(nullptr), - osr_helper_(osr_helper), + osr_helper_(std::move(osr_helper)), osr_pc_offset_(-1), optimized_out_literal_id_(-1), source_position_table_builder_( diff --git a/src/compiler/escape-analysis.cc b/src/compiler/escape-analysis.cc index 0e6822a9ca..0ef9410cac 100644 --- a/src/compiler/escape-analysis.cc +++ b/src/compiler/escape-analysis.cc @@ -282,7 +282,7 @@ EffectGraphReducer::EffectGraphReducer( state_(graph, kNumStates), revisit_(zone), stack_(zone), - reduce_(reduce) {} + reduce_(std::move(reduce)) {} void EffectGraphReducer::ReduceFrom(Node* node) { // Perform DFS and eagerly trigger revisitation as soon as possible. diff --git a/src/compiler/frame-states.cc b/src/compiler/frame-states.cc index 15ca8367b0..bd210d714d 100644 --- a/src/compiler/frame-states.cc +++ b/src/compiler/frame-states.cc @@ -145,6 +145,12 @@ Node* CreateStubBuiltinContinuationFrameState( // by the deoptimizer and aren't explicitly passed in the frame state. int stack_parameter_count = descriptor.GetRegisterParameterCount() - DeoptimizerParameterCountFor(mode); + // Reserving space in the vector, except for the case where + // stack_parameter_count is -1. + actual_parameters.reserve(stack_parameter_count >= 0 + ? stack_parameter_count + + descriptor.GetRegisterParameterCount() + : 0); for (int i = 0; i < stack_parameter_count; ++i) { actual_parameters.push_back( parameters[descriptor.GetRegisterParameterCount() + i]); diff --git a/src/compiler/js-call-reducer.cc b/src/compiler/js-call-reducer.cc index 49bc667752..8da2867f25 100644 --- a/src/compiler/js-call-reducer.cc +++ b/src/compiler/js-call-reducer.cc @@ -5533,6 +5533,7 @@ Node* JSCallReducer::CreateArtificialFrameState( const Operator* op0 = common()->StateValues(0, SparseInputMask::Dense()); Node* node0 = graph()->NewNode(op0); std::vector params; + params.reserve(parameter_count + 1); for (int parameter = 0; parameter < parameter_count + 1; ++parameter) { params.push_back(node->InputAt(1 + parameter)); } diff --git a/src/compiler/js-generic-lowering.cc b/src/compiler/js-generic-lowering.cc index ef40bd0005..8c9a723a97 100644 --- a/src/compiler/js-generic-lowering.cc +++ b/src/compiler/js-generic-lowering.cc @@ -95,12 +95,14 @@ REPLACE_STUB_CALL(RejectPromise) REPLACE_STUB_CALL(ResolvePromise) #undef REPLACE_STUB_CALL -void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, +void JSGenericLowering::ReplaceWithStubCall(Node* node, + Callable callable, CallDescriptor::Flags flags) { ReplaceWithStubCall(node, callable, flags, node->op()->properties()); } -void JSGenericLowering::ReplaceWithStubCall(Node* node, Callable callable, +void JSGenericLowering::ReplaceWithStubCall(Node* node, + Callable callable, CallDescriptor::Flags flags, Operator::Properties properties) { const CallInterfaceDescriptor& descriptor = callable.descriptor(); diff --git a/src/compiler/store-store-elimination.cc b/src/compiler/store-store-elimination.cc index ce2c71a3d7..b7b693c0bd 100644 --- a/src/compiler/store-store-elimination.cc +++ b/src/compiler/store-store-elimination.cc @@ -102,7 +102,7 @@ class UnobservablesSet final { UnobservablesSet(); // unvisited UnobservablesSet(const UnobservablesSet& other) : set_(other.set_) {} - UnobservablesSet Intersect(UnobservablesSet other, Zone* zone) const; + UnobservablesSet Intersect(const UnobservablesSet& other, Zone* zone) const; UnobservablesSet Add(UnobservableStore obs, Zone* zone) const; UnobservablesSet RemoveSameOffset(StoreOffset off, Zone* zone) const; @@ -140,7 +140,7 @@ class RedundantStoreFinder final { private: void VisitEffectfulNode(Node* node); UnobservablesSet RecomputeUseIntersection(Node* node); - UnobservablesSet RecomputeSet(Node* node, UnobservablesSet uses); + UnobservablesSet RecomputeSet(Node* node, const UnobservablesSet& uses); static bool CannotObserveStoreField(Node* node); void MarkForRevisit(Node* node); @@ -252,8 +252,8 @@ void StoreStoreElimination::Run(JSGraph* js_graph, Zone* temp_zone) { // Recompute unobservables-set for a node. Will also mark superfluous nodes // as to be removed. -UnobservablesSet RedundantStoreFinder::RecomputeSet(Node* node, - UnobservablesSet uses) { +UnobservablesSet RedundantStoreFinder::RecomputeSet( + Node* node, const UnobservablesSet& uses) { switch (node->op()->opcode()) { case IrOpcode::kStoreField: { Node* stored_to = node->InputAt(0); @@ -472,7 +472,7 @@ UnobservablesSet UnobservablesSet::VisitedEmpty(Zone* zone) { // Computes the intersection of two UnobservablesSets. May return // UnobservablesSet::Unvisited() instead of an empty UnobservablesSet for // speed. -UnobservablesSet UnobservablesSet::Intersect(UnobservablesSet other, +UnobservablesSet UnobservablesSet::Intersect(const UnobservablesSet& other, Zone* zone) const { if (IsEmpty() || other.IsEmpty()) { return Unvisited();