Commit 314e73d1 authored by svenpanne's avatar svenpanne Committed by Commit bot

Import Reversed adapter from Chromium and use it in v8.

Review URL: https://codereview.chromium.org/1098863003

Cr-Commit-Position: refs/heads/master@{#27947}
parent 497c5373
......@@ -1336,6 +1336,7 @@ source_set("v8_libbase") {
visibility = [ ":*" ] # Only targets in this file can depend on this.
sources = [
"src/base/adapters.h",
"src/base/atomicops.h",
"src/base/atomicops_internals_arm64_gcc.h",
"src/base/atomicops_internals_arm_gcc.h",
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Slightly adapted for inclusion in V8.
// Copyright 2014 the V8 project authors. All rights reserved.
#ifndef V8_BASE_ADAPTERS_H_
#define V8_BASE_ADAPTERS_H_
#include "src/base/macros.h"
namespace v8 {
namespace base {
// Internal adapter class for implementing base::Reversed.
template <typename T>
class ReversedAdapter {
public:
typedef decltype(static_cast<T*>(nullptr)->rbegin()) Iterator;
explicit ReversedAdapter(T& t) : t_(t) {}
ReversedAdapter(const ReversedAdapter& ra) : t_(ra.t_) {}
Iterator begin() const { return t_.rbegin(); }
Iterator end() const { return t_.rend(); }
private:
T& t_;
DISALLOW_ASSIGN(ReversedAdapter);
};
// Reversed returns a container adapter usable in a range-based "for" statement
// for iterating a reversible container in reverse order.
//
// Example:
//
// std::vector<int> v = ...;
// for (int i : base::Reversed(v)) {
// // iterates through v from back to front
// }
template <typename T>
ReversedAdapter<T> Reversed(T& t) {
return ReversedAdapter<T>(t);
}
} // namespace base
} // namespace v8
#endif // V8_BASE_ADAPTERS_H_
......@@ -228,6 +228,10 @@ V8_INLINE Dest bit_cast(Source const& source) {
}
// Put this in the private: declarations for a class to be unassignable.
#define DISALLOW_ASSIGN(TypeName) void operator=(const TypeName&)
// A macro to disallow the evil copy constructor and operator= functions
// This should be used in the private: declarations for a class
#define DISALLOW_COPY_AND_ASSIGN(TypeName) \
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
......@@ -1099,9 +1100,8 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
// TODO(dcarney): might be possible to use claim/poke instead
// Push any stack arguments.
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
++i) {
Emit(kArmPush, g.NoOutput(), g.UseRegister(*i));
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
Emit(kArmPush, g.NoOutput(), g.UseRegister(node));
}
// Pass label of exception handler block.
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
......@@ -831,13 +832,12 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
InitializeCallBuffer(node, &buffer, true, true);
// Push any stack arguments.
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
++i) {
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
// TODO(titzer): handle pushing double parameters.
InstructionOperand value =
g.CanBeImmediate(*i) ? g.UseImmediate(*i) : IsSupported(ATOM)
? g.UseRegister(*i)
: g.Use(*i);
g.CanBeImmediate(node)
? g.UseImmediate(node)
: IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node);
Emit(kIA32Push, g.NoOutput(), value);
}
......
......@@ -6,6 +6,7 @@
#include <limits>
#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
......@@ -465,9 +466,7 @@ void InstructionSelector::VisitBlock(BasicBlock* block) {
// Visit code in reverse control flow order, because architecture-specific
// matching may cover more than one node at a time.
for (BasicBlock::reverse_iterator i = block->rbegin(); i != block->rend();
++i) {
Node* node = *i;
for (auto node : base::Reversed(*block)) {
// Skip nodes that are unused or already defined.
if (!IsUsed(node) || IsDefined(node)) continue;
// Generate code for this node "top down", but schedule the code "bottom
......
......@@ -2,8 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/liveness-analyzer.h"
#include "src/base/adapters.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/liveness-analyzer.h"
#include "src/compiler/node.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/state-values-utils.h"
......@@ -97,8 +98,7 @@ void LivenessAnalyzerBlock::Process(BitVector* result,
// Copy the bitvector to the target bit vector.
result->CopyFrom(live_);
for (auto i = entries_.rbegin(); i != entries_.rend(); i++) {
auto entry = *i;
for (auto entry : base::Reversed(entries_)) {
switch (entry.kind()) {
case Entry::kLookup:
result->Add(entry.var());
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
......@@ -519,9 +520,8 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
g.TempImmediate(push_count << kPointerSizeLog2));
}
int slot = buffer.pushed_nodes.size() - 1;
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
++i) {
Emit(kMipsStoreToStackSlot, g.NoOutput(), g.UseRegister(*i),
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
Emit(kMipsStoreToStackSlot, g.NoOutput(), g.UseRegister(node),
g.TempImmediate(slot << kPointerSizeLog2));
slot--;
}
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/base/bits.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
......@@ -668,9 +669,8 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
g.TempImmediate(push_count << kPointerSizeLog2));
}
int slot = buffer.pushed_nodes.size() - 1;
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
++i) {
Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(*i),
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
Emit(kMips64StoreToStackSlot, g.NoOutput(), g.UseRegister(node),
g.TempImmediate(slot << kPointerSizeLog2));
slot--;
}
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
......@@ -1453,9 +1454,8 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
// Push any stack arguments.
// TODO(mbrandy): reverse order and use push only for first
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
i++) {
Emit(kPPC_Push, g.NoOutput(), g.UseRegister(*i));
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
Emit(kPPC_Push, g.NoOutput(), g.UseRegister(node));
}
// Pass label of exception handler block.
......
......@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/base/adapters.h"
#include "src/compiler/linkage.h"
#include "src/compiler/register-allocator.h"
#include "src/string-stream.h"
......@@ -1314,9 +1315,8 @@ void LiveRangeBuilder::MeetRegisterConstraints() {
void LiveRangeBuilder::ResolvePhis() {
// Process the blocks in reverse order.
for (auto i = code()->instruction_blocks().rbegin();
i != code()->instruction_blocks().rend(); ++i) {
ResolvePhis(*i);
for (InstructionBlock* block : base::Reversed(code()->instruction_blocks())) {
ResolvePhis(block);
}
}
......
......@@ -6,6 +6,7 @@
#include <iomanip>
#include "src/base/adapters.h"
#include "src/bit-vector.h"
#include "src/compiler/common-operator.h"
#include "src/compiler/control-equivalence.h"
......@@ -1622,8 +1623,8 @@ void Scheduler::SealFinalSchedule() {
for (NodeVector& nodes : scheduled_nodes_) {
BasicBlock::Id id = BasicBlock::Id::FromInt(block_num++);
BasicBlock* block = schedule_->GetBlockById(id);
for (auto i = nodes.rbegin(); i != nodes.rend(); ++i) {
schedule_->AddNode(block, *i);
for (Node* node : base::Reversed(nodes)) {
schedule_->AddNode(block, node);
}
}
}
......
......@@ -4,6 +4,7 @@
#include <algorithm>
#include "src/base/adapters.h"
#include "src/compiler/instruction-selector-impl.h"
#include "src/compiler/node-matchers.h"
#include "src/compiler/node-properties.h"
......@@ -1034,13 +1035,12 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
InitializeCallBuffer(node, &buffer, true, true);
// Push any stack arguments.
for (auto i = buffer.pushed_nodes.rbegin(); i != buffer.pushed_nodes.rend();
++i) {
for (Node* node : base::Reversed(buffer.pushed_nodes)) {
// TODO(titzer): handle pushing double parameters.
InstructionOperand value =
g.CanBeImmediate(*i) ? g.UseImmediate(*i) : IsSupported(ATOM)
? g.UseRegister(*i)
: g.Use(*i);
g.CanBeImmediate(node)
? g.UseImmediate(node)
: IsSupported(ATOM) ? g.UseRegister(node) : g.Use(node);
Emit(kX64Push, g.NoOutput(), value);
}
......
......@@ -1101,21 +1101,6 @@ class BailoutId {
};
template <class C>
class ContainerPointerWrapper {
public:
typedef typename C::iterator iterator;
typedef typename C::reverse_iterator reverse_iterator;
explicit ContainerPointerWrapper(C* container) : container_(container) {}
iterator begin() { return container_->begin(); }
iterator end() { return container_->end(); }
reverse_iterator rbegin() { return container_->rbegin(); }
reverse_iterator rend() { return container_->rend(); }
private:
C* container_;
};
// ----------------------------------------------------------------------------
// I/O support.
......
......@@ -1330,6 +1330,7 @@
'../..',
],
'sources': [
'../../src/base/adapters.h',
'../../src/base/atomicops.h',
'../../src/base/atomicops_internals_arm64_gcc.h',
'../../src/base/atomicops_internals_arm_gcc.h',
......
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