From 261b142fc0c55de0a6eb1b9b442314df5c1248cb Mon Sep 17 00:00:00 2001 From: "titzer@chromium.org" Date: Tue, 26 Aug 2014 13:09:08 +0000 Subject: [PATCH] Introduce subclass wrappers for STL containers that make them a lot easier to use with Zone. For example, subclasses add constructors that wrap a Zone in a zone_allocator to save clients this verbosity. R=bmeurer@chromium.org, mstarzinger@chromium.org BUG= Review URL: https://codereview.chromium.org/505133003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23402 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/compiler/code-generator.cc | 8 ++--- src/compiler/code-generator.h | 14 ++------- src/compiler/generic-algorithm.h | 8 ++--- src/compiler/generic-node-inl.h | 2 +- src/compiler/generic-node.h | 10 ++---- src/compiler/graph-builder.cc | 2 +- src/compiler/graph-reducer.cc | 7 +++-- src/compiler/graph-reducer.h | 8 ++--- src/compiler/graph.cc | 6 ++-- src/compiler/graph.h | 6 ++-- src/compiler/instruction-selector.cc | 17 +++++----- src/compiler/instruction-selector.h | 5 +-- src/compiler/instruction.h | 24 ++++++--------- src/compiler/js-inlining.cc | 4 +-- src/compiler/node-aux-data-inl.h | 2 +- src/compiler/node-aux-data.h | 9 ++---- src/compiler/node.h | 15 +++------ src/compiler/raw-machine-assembler.h | 3 -- src/compiler/schedule.h | 13 ++++---- src/compiler/scheduler.cc | 11 +++---- src/compiler/scheduler.h | 3 -- src/compiler/simplified-lowering.cc | 13 +++----- src/compiler/structured-machine-assembler.cc | 21 ++++++------- src/compiler/structured-machine-assembler.h | 14 +++------ src/compiler/verifier.cc | 6 ++-- src/zone-containers.h | 46 ++++++++++++++++++++++++---- 26 files changed, 121 insertions(+), 156 deletions(-) diff --git a/src/compiler/code-generator.cc b/src/compiler/code-generator.cc index 1cbb596..243ef02 100644 --- a/src/compiler/code-generator.cc +++ b/src/compiler/code-generator.cc @@ -19,11 +19,9 @@ CodeGenerator::CodeGenerator(InstructionSequence* code) masm_(code->zone()->isolate(), NULL, 0), resolver_(this), safepoints_(code->zone()), - lazy_deoptimization_entries_( - LazyDeoptimizationEntries::allocator_type(code->zone())), - deoptimization_states_( - DeoptimizationStates::allocator_type(code->zone())), - deoptimization_literals_(Literals::allocator_type(code->zone())), + lazy_deoptimization_entries_(code->zone()), + deoptimization_states_(code->zone()), + deoptimization_literals_(code->zone()), translations_(code->zone()) { deoptimization_states_.resize(code->GetDeoptimizationEntryCount(), NULL); } diff --git a/src/compiler/code-generator.h b/src/compiler/code-generator.h index 14ee351..f06bb65 100644 --- a/src/compiler/code-generator.h +++ b/src/compiler/code-generator.h @@ -122,23 +122,15 @@ class CodeGenerator V8_FINAL : public GapResolver::Assembler { : translation_id_(translation_id) {} }; - typedef std::deque > - LazyDeoptimizationEntries; - typedef std::deque > - DeoptimizationStates; - typedef std::deque, zone_allocator > > Literals; - InstructionSequence* code_; BasicBlock* current_block_; SourcePosition current_source_position_; MacroAssembler masm_; GapResolver resolver_; SafepointTableBuilder safepoints_; - LazyDeoptimizationEntries lazy_deoptimization_entries_; - DeoptimizationStates deoptimization_states_; - Literals deoptimization_literals_; + ZoneDeque lazy_deoptimization_entries_; + ZoneDeque deoptimization_states_; + ZoneDeque > deoptimization_literals_; TranslationBuffer translations_; }; diff --git a/src/compiler/generic-algorithm.h b/src/compiler/generic-algorithm.h index c4681f9..c75f9cf 100644 --- a/src/compiler/generic-algorithm.h +++ b/src/compiler/generic-algorithm.h @@ -5,7 +5,6 @@ #ifndef V8_COMPILER_GENERIC_ALGORITHM_H_ #define V8_COMPILER_GENERIC_ALGORITHM_H_ -#include #include #include "src/compiler/generic-graph.h" @@ -45,10 +44,9 @@ class GenericGraphVisit { typedef typename Traits::Iterator Iterator; typedef std::pair NodeState; typedef zone_allocator ZoneNodeStateAllocator; - typedef std::deque NodeStateDeque; - typedef std::stack NodeStateStack; - NodeStateStack stack((NodeStateDeque(ZoneNodeStateAllocator(zone)))); - BoolVector visited(Traits::max_id(graph), false, ZoneBoolAllocator(zone)); + typedef std::stack> NodeStateStack; + NodeStateStack stack((ZoneDeque(zone))); + BoolVector visited(Traits::max_id(graph), false, zone); Node* current = *root_begin; while (true) { DCHECK(current != NULL); diff --git a/src/compiler/generic-node-inl.h b/src/compiler/generic-node-inl.h index 51d1a50..e7a8f90 100644 --- a/src/compiler/generic-node-inl.h +++ b/src/compiler/generic-node-inl.h @@ -141,7 +141,7 @@ template void GenericNode::EnsureAppendableInputs(Zone* zone) { if (!has_appendable_inputs_) { void* deque_buffer = zone->New(sizeof(InputDeque)); - InputDeque* deque = new (deque_buffer) InputDeque(ZoneInputAllocator(zone)); + InputDeque* deque = new (deque_buffer) InputDeque(zone); for (int i = 0; i < input_count_; ++i) { deque->push_back(inputs_.static_[i]); } diff --git a/src/compiler/generic-node.h b/src/compiler/generic-node.h index 0cfba72..d909943 100644 --- a/src/compiler/generic-node.h +++ b/src/compiler/generic-node.h @@ -5,19 +5,14 @@ #ifndef V8_COMPILER_GENERIC_NODE_H_ #define V8_COMPILER_GENERIC_NODE_H_ -#include - #include "src/v8.h" -#include "src/compiler/operator.h" -#include "src/zone.h" -#include "src/zone-allocator.h" +#include "src/zone-containers.h" namespace v8 { namespace internal { namespace compiler { -class Operator; class GenericGraphBase; typedef int NodeId; @@ -137,8 +132,7 @@ class GenericNode : public B { private: void AssignUniqueID(GenericGraphBase* graph); - typedef zone_allocator ZoneInputAllocator; - typedef std::deque InputDeque; + typedef ZoneDeque InputDeque; NodeId id_; int input_count_ : 31; diff --git a/src/compiler/graph-builder.cc b/src/compiler/graph-builder.cc index 36d62d4..504d25e 100644 --- a/src/compiler/graph-builder.cc +++ b/src/compiler/graph-builder.cc @@ -104,7 +104,7 @@ StructuredGraphBuilder::Environment::Environment( : builder_(builder), control_dependency_(control_dependency), effect_dependency_(control_dependency), - values_(NodeVector::allocator_type(zone())) {} + values_(zone()) {} StructuredGraphBuilder::Environment::Environment(const Environment& copy) diff --git a/src/compiler/graph-reducer.cc b/src/compiler/graph-reducer.cc index f062d4b..2a60b49 100644 --- a/src/compiler/graph-reducer.cc +++ b/src/compiler/graph-reducer.cc @@ -13,7 +13,7 @@ namespace internal { namespace compiler { GraphReducer::GraphReducer(Graph* graph) - : graph_(graph), reducers_(Reducers::allocator_type(graph->zone())) {} + : graph_(graph), reducers_(graph->zone()) {} static bool NodeIdIsLessThan(const Node* node, NodeId id) { @@ -22,14 +22,15 @@ static bool NodeIdIsLessThan(const Node* node, NodeId id) { void GraphReducer::ReduceNode(Node* node) { - Reducers::iterator skip = reducers_.end(); + ZoneVector::iterator skip = reducers_.end(); static const unsigned kMaxAttempts = 16; bool reduce = true; for (unsigned attempts = 0; attempts <= kMaxAttempts; ++attempts) { if (!reduce) return; reduce = false; // Assume we don't need to rerun any reducers. int before = graph_->NodeCount(); - for (Reducers::iterator i = reducers_.begin(); i != reducers_.end(); ++i) { + for (ZoneVector::iterator i = reducers_.begin(); + i != reducers_.end(); ++i) { if (i == skip) continue; // Skip this reducer. Reduction reduction = (*i)->Reduce(node); Node* replacement = reduction.replacement(); diff --git a/src/compiler/graph-reducer.h b/src/compiler/graph-reducer.h index b3534e8..028ea7c 100644 --- a/src/compiler/graph-reducer.h +++ b/src/compiler/graph-reducer.h @@ -5,9 +5,7 @@ #ifndef V8_COMPILER_GRAPH_REDUCER_H_ #define V8_COMPILER_GRAPH_REDUCER_H_ -#include - -#include "src/zone-allocator.h" +#include "src/zone-containers.h" namespace v8 { namespace internal { @@ -69,10 +67,8 @@ class GraphReducer V8_FINAL { void ReduceGraph(); private: - typedef std::list > Reducers; - Graph* graph_; - Reducers reducers_; + ZoneVector reducers_; DISALLOW_COPY_AND_ASSIGN(GraphReducer); }; diff --git a/src/compiler/graph.cc b/src/compiler/graph.cc index 3f47eac..42f632f 100644 --- a/src/compiler/graph.cc +++ b/src/compiler/graph.cc @@ -18,16 +18,14 @@ namespace v8 { namespace internal { namespace compiler { -Graph::Graph(Zone* zone) - : GenericGraph(zone), - decorators_(DecoratorVector::allocator_type(zone)) {} +Graph::Graph(Zone* zone) : GenericGraph(zone), decorators_(zone) {} Node* Graph::NewNode(Operator* op, int input_count, Node** inputs) { DCHECK(op->InputCount() <= input_count); Node* result = Node::New(this, input_count, inputs); result->Initialize(op); - for (DecoratorVector::iterator i = decorators_.begin(); + for (ZoneVector::iterator i = decorators_.begin(); i != decorators_.end(); ++i) { (*i)->Decorate(result); } diff --git a/src/compiler/graph.h b/src/compiler/graph.h index 64d297f..e59cc88 100644 --- a/src/compiler/graph.h +++ b/src/compiler/graph.h @@ -72,16 +72,14 @@ class Graph : public GenericGraph { } void RemoveDecorator(GraphDecorator* decorator) { - DecoratorVector::iterator it = + ZoneVector::iterator it = std::find(decorators_.begin(), decorators_.end(), decorator); DCHECK(it != decorators_.end()); decorators_.erase(it, it + 1); } private: - typedef std::vector > - DecoratorVector; - DecoratorVector decorators_; + ZoneVector decorators_; }; diff --git a/src/compiler/instruction-selector.cc b/src/compiler/instruction-selector.cc index e65b85b..3e3943f 100644 --- a/src/compiler/instruction-selector.cc +++ b/src/compiler/instruction-selector.cc @@ -21,9 +21,9 @@ InstructionSelector::InstructionSelector(InstructionSequence* sequence, source_positions_(source_positions), features_(features), current_block_(NULL), - instructions_(InstructionDeque::allocator_type(zone())), - defined_(graph()->NodeCount(), false, BoolVector::allocator_type(zone())), - used_(graph()->NodeCount(), false, BoolVector::allocator_type(zone())) {} + instructions_(zone()), + defined_(graph()->NodeCount(), false, zone()), + used_(graph()->NodeCount(), false, zone()) {} void InstructionSelector::SelectInstructions() { @@ -264,10 +264,10 @@ CallBuffer::CallBuffer(Zone* zone, CallDescriptor* d, FrameStateDescriptor* frame_desc) : descriptor(d), frame_state_descriptor(frame_desc), - output_nodes(NodeVector::allocator_type(zone)), - outputs(InstructionOperandVector::allocator_type(zone)), - instruction_args(InstructionOperandVector::allocator_type(zone)), - pushed_nodes(NodeVector::allocator_type(zone)) { + output_nodes(zone), + outputs(zone), + instruction_args(zone), + pushed_nodes(zone) { output_nodes.reserve(d->ReturnCount()); outputs.reserve(d->ReturnCount()); pushed_nodes.reserve(input_count()); @@ -1083,8 +1083,7 @@ void InstructionSelector::VisitDeoptimize(Node* deopt) { Node* state = deopt->InputAt(0); FrameStateDescriptor* descriptor = GetFrameStateDescriptor(state); - InstructionOperandVector inputs( - (InstructionOperandVector::allocator_type(zone()))); + InstructionOperandVector inputs(zone()); inputs.reserve(descriptor->size()); AddFrameStateInputs(state, &inputs, descriptor); diff --git a/src/compiler/instruction-selector.h b/src/compiler/instruction-selector.h index 470bc23..365ff0d 100644 --- a/src/compiler/instruction-selector.h +++ b/src/compiler/instruction-selector.h @@ -197,15 +197,12 @@ class InstructionSelector V8_FINAL { // =========================================================================== - typedef zone_allocator InstructionPtrZoneAllocator; - typedef std::deque Instructions; - Zone zone_; InstructionSequence* sequence_; SourcePositionTable* source_positions_; Features features_; BasicBlock* current_block_; - Instructions instructions_; + ZoneDeque instructions_; BoolVector defined_; BoolVector used_; }; diff --git a/src/compiler/instruction.h b/src/compiler/instruction.h index da01351..98c85bc 100644 --- a/src/compiler/instruction.h +++ b/src/compiler/instruction.h @@ -89,8 +89,7 @@ class InstructionOperand : public ZoneObject { unsigned value_; }; -typedef std::vector > - InstructionOperandVector; +typedef ZoneVector InstructionOperandVector; OStream& operator<<(OStream& os, const InstructionOperand& op); @@ -725,18 +724,13 @@ class FrameStateDescriptor : public ZoneObject { OStream& operator<<(OStream& os, const Constant& constant); -typedef std::deque > ConstantDeque; +typedef ZoneDeque ConstantDeque; typedef std::map, zone_allocator > > ConstantMap; - -typedef std::deque > - InstructionDeque; -typedef std::deque > PointerMapDeque; -typedef std::vector > - DeoptimizationVector; - +typedef ZoneDeque InstructionDeque; +typedef ZoneDeque PointerMapDeque; +typedef ZoneVector DeoptimizationVector; // Represents architecture-specific generated code before, during, and after // register allocation. @@ -749,14 +743,14 @@ class InstructionSequence V8_FINAL { schedule_(schedule), constants_(ConstantMap::key_compare(), ConstantMap::allocator_type(zone())), - immediates_(ConstantDeque::allocator_type(zone())), - instructions_(InstructionDeque::allocator_type(zone())), + immediates_(zone()), + instructions_(zone()), next_virtual_register_(graph->NodeCount()), - pointer_maps_(PointerMapDeque::allocator_type(zone())), + pointer_maps_(zone()), doubles_(std::less(), VirtualRegisterSet::allocator_type(zone())), references_(std::less(), VirtualRegisterSet::allocator_type(zone())), - deoptimization_entries_(DeoptimizationVector::allocator_type(zone())) {} + deoptimization_entries_(zone()) {} int NextVirtualRegister() { return next_virtual_register_++; } int VirtualRegisterCount() const { return next_virtual_register_; } diff --git a/src/compiler/js-inlining.cc b/src/compiler/js-inlining.cc index 542b7e5..4e8adb2 100644 --- a/src/compiler/js-inlining.cc +++ b/src/compiler/js-inlining.cc @@ -152,8 +152,8 @@ void Inlinee::UnifyReturn() { Operator* op_phi = jsgraph_->common()->Phi(predecessors); Operator* op_ephi = jsgraph_->common()->EffectPhi(predecessors); - NodeVector values(NodeVector::allocator_type(jsgraph_->zone())); - NodeVector effects(NodeVector::allocator_type(jsgraph_->zone())); + NodeVector values(jsgraph_->zone()); + NodeVector effects(jsgraph_->zone()); // Iterate over all control flow predecessors, // which must be return statements. InputIter iter = final_merge->inputs().begin(); diff --git a/src/compiler/node-aux-data-inl.h b/src/compiler/node-aux-data-inl.h index 679320a..79f1abf 100644 --- a/src/compiler/node-aux-data-inl.h +++ b/src/compiler/node-aux-data-inl.h @@ -15,7 +15,7 @@ namespace compiler { template NodeAuxData::NodeAuxData(Zone* zone) - : aux_data_(ZoneAllocator(zone)) {} + : aux_data_(zone) {} template diff --git a/src/compiler/node-aux-data.h b/src/compiler/node-aux-data.h index 1e83633..7acce33 100644 --- a/src/compiler/node-aux-data.h +++ b/src/compiler/node-aux-data.h @@ -5,9 +5,7 @@ #ifndef V8_COMPILER_NODE_AUX_DATA_H_ #define V8_COMPILER_NODE_AUX_DATA_H_ -#include - -#include "src/zone-allocator.h" +#include "src/zone-containers.h" namespace v8 { namespace internal { @@ -26,10 +24,7 @@ class NodeAuxData { inline T Get(Node* node); private: - typedef zone_allocator ZoneAllocator; - typedef std::vector TZoneVector; - - TZoneVector aux_data_; + ZoneVector aux_data_; }; } } diff --git a/src/compiler/node.h b/src/compiler/node.h index bba6390..a097452 100644 --- a/src/compiler/node.h +++ b/src/compiler/node.h @@ -54,8 +54,7 @@ class Node : public GenericNode { void Initialize(Operator* op) { set_op(op); } - void CollectProjections( - std::vector >* projections); + void CollectProjections(ZoneVector* projections); Node* FindProjection(int32_t projection_index); }; @@ -63,21 +62,15 @@ OStream& operator<<(OStream& os, const Node& n); typedef GenericGraphVisit::NullNodeVisitor NullNodeVisitor; -typedef zone_allocator NodePtrZoneAllocator; - -typedef std::set, NodePtrZoneAllocator> NodeSet; +typedef std::set, zone_allocator > NodeSet; typedef NodeSet::iterator NodeSetIter; typedef NodeSet::reverse_iterator NodeSetRIter; -typedef std::deque NodeDeque; -typedef NodeDeque::iterator NodeDequeIter; - -typedef std::vector NodeVector; +typedef ZoneVector NodeVector; typedef NodeVector::iterator NodeVectorIter; typedef NodeVector::reverse_iterator NodeVectorRIter; -typedef zone_allocator ZoneNodeVectorAllocator; -typedef std::vector NodeVectorVector; +typedef ZoneVector NodeVectorVector; typedef NodeVectorVector::iterator NodeVectorVectorIter; typedef NodeVectorVector::reverse_iterator NodeVectorVectorRIter; diff --git a/src/compiler/raw-machine-assembler.h b/src/compiler/raw-machine-assembler.h index 6839ade..4ada99d 100644 --- a/src/compiler/raw-machine-assembler.h +++ b/src/compiler/raw-machine-assembler.h @@ -108,9 +108,6 @@ class RawMachineAssembler : public GraphBuilder, BasicBlock* EnsureBlock(Label* label); BasicBlock* CurrentBlock(); - typedef std::vector > - RepresentationVector; - Schedule* schedule_; MachineOperatorBuilder machine_; CommonOperatorBuilder common_; diff --git a/src/compiler/schedule.h b/src/compiler/schedule.h index b9bb526..d54bae6 100644 --- a/src/compiler/schedule.h +++ b/src/compiler/schedule.h @@ -63,7 +63,7 @@ class BasicBlockData { deferred_(false), control_(kNone), control_input_(NULL), - nodes_(NodeVector::allocator_type(zone)) {} + nodes_(zone) {} inline bool IsLoopHeader() const { return loop_end_ >= 0; } inline bool LoopContains(BasicBlockData* block) const { @@ -145,8 +145,7 @@ class BasicBlock V8_FINAL : public GenericNode { typedef GenericGraphVisit::NullNodeVisitor NullBasicBlockVisitor; -typedef zone_allocator BasicBlockPtrZoneAllocator; -typedef std::vector BasicBlockVector; +typedef ZoneVector BasicBlockVector; typedef BasicBlockVector::iterator BasicBlockVectorIter; typedef BasicBlockVector::reverse_iterator BasicBlockVectorRIter; @@ -159,10 +158,10 @@ class Schedule : public GenericGraph { explicit Schedule(Zone* zone) : GenericGraph(zone), zone_(zone), - all_blocks_(BasicBlockVector::allocator_type(zone)), - nodeid_to_block_(BasicBlockVector::allocator_type(zone)), - rpo_order_(BasicBlockVector::allocator_type(zone)), - immediate_dominator_(BasicBlockVector::allocator_type(zone)) { + all_blocks_(zone), + nodeid_to_block_(zone), + rpo_order_(zone), + immediate_dominator_(zone) { SetStart(NewBasicBlock()); // entry. SetEnd(NewBasicBlock()); // exit. } diff --git a/src/compiler/scheduler.cc b/src/compiler/scheduler.cc index d32a707..bdca6b4 100644 --- a/src/compiler/scheduler.cc +++ b/src/compiler/scheduler.cc @@ -207,10 +207,10 @@ Scheduler::Scheduler(Zone* zone, Graph* graph, Schedule* schedule) : zone_(zone), graph_(graph), schedule_(schedule), - unscheduled_uses_(IntVector::allocator_type(zone)), - scheduled_nodes_(NodeVectorVector::allocator_type(zone)), - schedule_root_nodes_(NodeVector::allocator_type(zone)), - schedule_early_rpo_index_(IntVector::allocator_type(zone)) {} + unscheduled_uses_(zone), + scheduled_nodes_(zone), + schedule_root_nodes_(zone), + schedule_early_rpo_index_(zone) {} Schedule* Scheduler::ComputeSchedule(Graph* graph) { @@ -273,8 +273,7 @@ void Scheduler::PrepareAuxiliaryNodeData() { void Scheduler::PrepareAuxiliaryBlockData() { Zone* zone = schedule_->zone(); - scheduled_nodes_.resize(schedule_->BasicBlockCount(), - NodeVector(NodeVector::allocator_type(zone))); + scheduled_nodes_.resize(schedule_->BasicBlockCount(), NodeVector(zone)); schedule_->immediate_dominator_.resize(schedule_->BasicBlockCount(), NULL); } diff --git a/src/compiler/scheduler.h b/src/compiler/scheduler.h index a25e0a0..f7c7798 100644 --- a/src/compiler/scheduler.h +++ b/src/compiler/scheduler.h @@ -5,13 +5,10 @@ #ifndef V8_COMPILER_SCHEDULER_H_ #define V8_COMPILER_SCHEDULER_H_ -#include - #include "src/v8.h" #include "src/compiler/opcodes.h" #include "src/compiler/schedule.h" -#include "src/zone-allocator.h" #include "src/zone-containers.h" namespace v8 { diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc index 12f953f..75f23b2 100644 --- a/src/compiler/simplified-lowering.cc +++ b/src/compiler/simplified-lowering.cc @@ -4,9 +4,6 @@ #include "src/compiler/simplified-lowering.h" -#include -#include - #include "src/compiler/common-operator.h" #include "src/compiler/graph-inl.h" #include "src/compiler/node-properties-inl.h" @@ -65,13 +62,12 @@ class RepresentationSelector { : jsgraph_(jsgraph), count_(jsgraph->graph()->NodeCount()), info_(zone->NewArray(count_)), - nodes_(NodeVector::allocator_type(zone)), - replacements_(NodeVector::allocator_type(zone)), + nodes_(zone), + replacements_(zone), contains_js_nodes_(false), phase_(PROPAGATE), changer_(changer), - queue_(std::deque( - NodePtrZoneAllocator(zone))) { + queue_(zone) { memset(info_, 0, sizeof(NodeInfo) * count_); } @@ -704,8 +700,7 @@ class RepresentationSelector { bool contains_js_nodes_; // {true} if a JS operator was seen Phase phase_; // current phase of algorithm RepresentationChanger* changer_; // for inserting representation changes - - std::queue > queue_; + ZoneQueue queue_; // queue for traversing the graph NodeInfo* GetInfo(Node* node) { DCHECK(node->id() >= 0); diff --git a/src/compiler/structured-machine-assembler.cc b/src/compiler/structured-machine-assembler.cc index abf44cd..56da5fb 100644 --- a/src/compiler/structured-machine-assembler.cc +++ b/src/compiler/structured-machine-assembler.cc @@ -306,16 +306,14 @@ void StructuredMachineAssembler::AddBranch(Environment* environment, StructuredMachineAssembler::Environment::Environment(Zone* zone, BasicBlock* block, bool is_dead) - : block_(block), - variables_(NodeVector::allocator_type(zone)), - is_dead_(is_dead) {} + : block_(block), variables_(zone), is_dead_(is_dead) {} StructuredMachineAssembler::IfBuilder::IfBuilder( StructuredMachineAssembler* smasm) : smasm_(smasm), - if_clauses_(IfClauses::allocator_type(smasm_->zone())), - pending_exit_merges_(EnvironmentVector::allocator_type(smasm_->zone())) { + if_clauses_(smasm_->zone()), + pending_exit_merges_(smasm_->zone()) { DCHECK(smasm_->current_environment_ != NULL); PushNewIfClause(); DCHECK(!IsDone()); @@ -394,9 +392,9 @@ StructuredMachineAssembler::IfBuilder::IfClause::IfClause( Zone* zone, int initial_environment_size) : unresolved_list_tail_(NULL), initial_environment_size_(initial_environment_size), - expression_states_(ExpressionStates::allocator_type(zone)), - pending_then_merges_(PendingMergeStack::allocator_type(zone)), - pending_else_merges_(PendingMergeStack::allocator_type(zone)), + expression_states_(zone), + pending_then_merges_(zone), + pending_else_merges_(zone), then_environment_(NULL), else_environment_(NULL) { PushNewExpressionState(); @@ -439,8 +437,7 @@ void StructuredMachineAssembler::IfBuilder::IfClause::ResolvePendingMerges( smasm->current_environment_ = smasm->Copy(unresolved_list_tail_->environment_, truncate_at); } else { - EnvironmentVector environments( - EnvironmentVector::allocator_type(smasm->zone())); + EnvironmentVector environments(smasm->zone()); environments.reserve(data.size_); CopyEnvironments(data, &environments); DCHECK(static_cast(environments.size()) == data.size_); @@ -610,8 +607,8 @@ StructuredMachineAssembler::LoopBuilder::LoopBuilder( StructuredMachineAssembler* smasm) : smasm_(smasm), header_environment_(NULL), - pending_header_merges_(EnvironmentVector::allocator_type(smasm_->zone())), - pending_exit_merges_(EnvironmentVector::allocator_type(smasm_->zone())) { + pending_header_merges_(smasm_->zone()), + pending_exit_merges_(smasm_->zone()) { DCHECK(smasm_->current_environment_ != NULL); // Create header environment. header_environment_ = smasm_->CopyForLoopHeader(smasm_->current_environment_); diff --git a/src/compiler/structured-machine-assembler.h b/src/compiler/structured-machine-assembler.h index a6cb8ca..6bac9cd 100644 --- a/src/compiler/structured-machine-assembler.h +++ b/src/compiler/structured-machine-assembler.h @@ -101,8 +101,7 @@ class StructuredMachineAssembler private: bool ScheduleValid() { return schedule_ != NULL; } - typedef std::vector > - EnvironmentVector; + typedef ZoneVector EnvironmentVector; NodeVector* CurrentVars() { return ¤t_environment_->variables_; } Node*& VariableAt(Environment* environment, int offset); @@ -124,9 +123,6 @@ class StructuredMachineAssembler void MergeBackEdgesToLoopHeader(Environment* header, EnvironmentVector* environments); - typedef std::vector > - RepresentationVector; - Schedule* schedule_; MachineOperatorBuilder machine_; CommonOperatorBuilder common_; @@ -214,12 +210,10 @@ class StructuredMachineAssembler::IfBuilder { int pending_else_size_; }; - typedef std::vector > - ExpressionStates; - typedef std::vector > - PendingMergeStack; + typedef ZoneVector ExpressionStates; + typedef ZoneVector PendingMergeStack; struct IfClause; - typedef std::vector > IfClauses; + typedef ZoneVector IfClauses; struct PendingMergeStackRange { PendingMergeStack* merge_stack_; diff --git a/src/compiler/verifier.cc b/src/compiler/verifier.cc index 9b06e31..8b780e9 100644 --- a/src/compiler/verifier.cc +++ b/src/compiler/verifier.cc @@ -320,9 +320,9 @@ void ScheduleVerifier::Run(Schedule* schedule) { } // Verify that all blocks reachable from start are in the RPO. - BoolVector marked(count, false, BoolVector::allocator_type(zone)); + BoolVector marked(count, false, zone); { - std::queue queue; + ZoneQueue queue(zone); queue.push(start); marked[start->id()] = true; while (!queue.empty()) { @@ -358,7 +358,7 @@ void ScheduleVerifier::Run(Schedule* schedule) { // Compute a set of all the nodes that dominate a given node by using // a forward fixpoint. O(n^2). - std::queue queue; + ZoneQueue queue(zone); queue.push(start); dominators[start->id()] = new (zone) BitVector(count, zone); while (!queue.empty()) { diff --git a/src/zone-containers.h b/src/zone-containers.h index 1295ed7..f3ac1a8 100644 --- a/src/zone-containers.h +++ b/src/zone-containers.h @@ -5,6 +5,8 @@ #ifndef V8_ZONE_CONTAINERS_H_ #define V8_ZONE_CONTAINERS_H_ +#include +#include #include #include "src/zone-allocator.h" @@ -12,12 +14,44 @@ namespace v8 { namespace internal { -typedef std::vector BoolVector; - -typedef std::vector IntVector; -typedef IntVector::iterator IntVectorIter; -typedef IntVector::reverse_iterator IntVectorRIter; - +// A wrapper subclass for std::vector to make it easy to construct one +// that uses a zone allocator. +template +class ZoneVector : public std::vector> { + public: + // Constructs an empty vector. + explicit ZoneVector(Zone* zone) + : std::vector>(zone_allocator(zone)) {} + + // Constructs a new vector and fills it with {size} elements, each + // having the value {def}. + ZoneVector(int size, T def, Zone* zone) + : std::vector>(size, def, zone_allocator(zone)) {} +}; + +// A wrapper subclass std::deque to make it easy to construct one +// that uses a zone allocator. +template +class ZoneDeque : public std::deque> { + public: + explicit ZoneDeque(Zone* zone) + : std::deque>(zone_allocator(zone)) {} +}; + +// A wrapper subclass for std::queue to make it easy to construct one +// that uses a zone allocator. +template +class ZoneQueue : public std::queue>> { + public: + // Constructs an empty queue. + explicit ZoneQueue(Zone* zone) + : std::queue>>( + std::deque>(zone_allocator(zone))) {} +}; + +// Typedefs to shorten commonly used vectors. +typedef ZoneVector BoolVector; +typedef ZoneVector IntVector; } } // namespace v8::internal #endif // V8_ZONE_CONTAINERS_H_ -- 2.7.4