Commit 3cace296 authored by dcarney@chromium.org's avatar dcarney@chromium.org

convert BitVector to use pointer size blocks

additionally rename data-flow.* to bit-vector.* as at some point these file became very inaccurately named

BUG=
R=svenpanne@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25030}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25030 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f01e0831
...@@ -450,6 +450,8 @@ source_set("v8_base") { ...@@ -450,6 +450,8 @@ source_set("v8_base") {
"src/bignum-dtoa.h", "src/bignum-dtoa.h",
"src/bignum.cc", "src/bignum.cc",
"src/bignum.h", "src/bignum.h",
"src/bit-vector.cc",
"src/bit-vector.h",
"src/bootstrapper.cc", "src/bootstrapper.cc",
"src/bootstrapper.h", "src/bootstrapper.h",
"src/builtins.cc", "src/builtins.cc",
...@@ -602,8 +604,6 @@ source_set("v8_base") { ...@@ -602,8 +604,6 @@ source_set("v8_base") {
"src/cpu-profiler-inl.h", "src/cpu-profiler-inl.h",
"src/cpu-profiler.cc", "src/cpu-profiler.cc",
"src/cpu-profiler.h", "src/cpu-profiler.h",
"src/data-flow.cc",
"src/data-flow.h",
"src/date.cc", "src/date.cc",
"src/date.h", "src/date.h",
"src/dateparser-inl.h", "src/dateparser-inl.h",
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "src/data-flow.h" #include "src/bit-vector.h"
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/scopes.h" #include "src/scopes.h"
...@@ -28,12 +28,12 @@ void BitVector::Print() { ...@@ -28,12 +28,12 @@ void BitVector::Print() {
void BitVector::Iterator::Advance() { void BitVector::Iterator::Advance() {
current_++; current_++;
uint32_t val = current_value_; uintptr_t val = current_value_;
while (val == 0) { while (val == 0) {
current_index_++; current_index_++;
if (Done()) return; if (Done()) return;
val = target_->data_[current_index_]; val = target_->data_[current_index_];
current_ = current_index_ << 5; current_ = current_index_ << kDataBitShift;
} }
val = SkipZeroBytes(val); val = SkipZeroBytes(val);
val = SkipZeroBits(val); val = SkipZeroBits(val);
...@@ -44,8 +44,12 @@ void BitVector::Iterator::Advance() { ...@@ -44,8 +44,12 @@ void BitVector::Iterator::Advance() {
int BitVector::Count() const { int BitVector::Count() const {
int count = 0; int count = 0;
for (int i = 0; i < data_length_; i++) { for (int i = 0; i < data_length_; i++) {
int data = data_[i]; uintptr_t data = data_[i];
if (data != 0) count += base::bits::CountPopulation32(data); if (sizeof(data) == 8) {
count += base::bits::CountPopulation64(data);
} else {
count += base::bits::CountPopulation32(static_cast<uint32_t>(data));
}
} }
return count; return count;
} }
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
class BitVector: public ZoneObject { class BitVector : public ZoneObject {
public: public:
// Iterator for the elements of this BitVector. // Iterator for the elements of this BitVector.
class Iterator BASE_EMBEDDED { class Iterator BASE_EMBEDDED {
...@@ -28,7 +28,7 @@ class BitVector: public ZoneObject { ...@@ -28,7 +28,7 @@ class BitVector: public ZoneObject {
DCHECK(target->data_length_ > 0); DCHECK(target->data_length_ > 0);
Advance(); Advance();
} }
~Iterator() { } ~Iterator() {}
bool Done() const { return current_index_ >= target_->data_length_; } bool Done() const { return current_index_ >= target_->data_length_; }
void Advance(); void Advance();
...@@ -39,14 +39,14 @@ class BitVector: public ZoneObject { ...@@ -39,14 +39,14 @@ class BitVector: public ZoneObject {
} }
private: private:
uint32_t SkipZeroBytes(uint32_t val) { uintptr_t SkipZeroBytes(uintptr_t val) {
while ((val & 0xFF) == 0) { while ((val & 0xFF) == 0) {
val >>= 8; val >>= 8;
current_ += 8; current_ += 8;
} }
return val; return val;
} }
uint32_t SkipZeroBits(uint32_t val) { uintptr_t SkipZeroBits(uintptr_t val) {
while ((val & 0x1) == 0) { while ((val & 0x1) == 0) {
val >>= 1; val >>= 1;
current_++; current_++;
...@@ -56,16 +56,20 @@ class BitVector: public ZoneObject { ...@@ -56,16 +56,20 @@ class BitVector: public ZoneObject {
BitVector* target_; BitVector* target_;
int current_index_; int current_index_;
uint32_t current_value_; uintptr_t current_value_;
int current_; int current_;
friend class BitVector; friend class BitVector;
}; };
static const int kDataBits = kPointerSize * 8;
static const int kDataBitShift = kPointerSize == 8 ? 6 : 5;
static const uintptr_t kOne = 1; // This saves some static_casts.
BitVector(int length, Zone* zone) BitVector(int length, Zone* zone)
: length_(length), : length_(length),
data_length_(SizeFor(length)), data_length_(SizeFor(length)),
data_(zone->NewArray<uint32_t>(data_length_)) { data_(zone->NewArray<uintptr_t>(data_length_)) {
DCHECK(length > 0); DCHECK(length > 0);
Clear(); Clear();
} }
...@@ -73,18 +77,11 @@ class BitVector: public ZoneObject { ...@@ -73,18 +77,11 @@ class BitVector: public ZoneObject {
BitVector(const BitVector& other, Zone* zone) BitVector(const BitVector& other, Zone* zone)
: length_(other.length()), : length_(other.length()),
data_length_(SizeFor(length_)), data_length_(SizeFor(length_)),
data_(zone->NewArray<uint32_t>(data_length_)) { data_(zone->NewArray<uintptr_t>(data_length_)) {
CopyFrom(other); CopyFrom(other);
} }
static int SizeFor(int length) { static int SizeFor(int length) { return 1 + ((length - 1) / kDataBits); }
return 1 + ((length - 1) / 32);
}
BitVector& operator=(const BitVector& rhs) {
if (this != &rhs) CopyFrom(rhs);
return *this;
}
void CopyFrom(const BitVector& other) { void CopyFrom(const BitVector& other) {
DCHECK(other.length() <= length()); DCHECK(other.length() <= length());
...@@ -98,18 +95,18 @@ class BitVector: public ZoneObject { ...@@ -98,18 +95,18 @@ class BitVector: public ZoneObject {
bool Contains(int i) const { bool Contains(int i) const {
DCHECK(i >= 0 && i < length()); DCHECK(i >= 0 && i < length());
uint32_t block = data_[i / 32]; uintptr_t block = data_[i / kDataBits];
return (block & (1U << (i % 32))) != 0; return (block & (kOne << (i % kDataBits))) != 0;
} }
void Add(int i) { void Add(int i) {
DCHECK(i >= 0 && i < length()); DCHECK(i >= 0 && i < length());
data_[i / 32] |= (1U << (i % 32)); data_[i / kDataBits] |= (kOne << (i % kDataBits));
} }
void Remove(int i) { void Remove(int i) {
DCHECK(i >= 0 && i < length()); DCHECK(i >= 0 && i < length());
data_[i / 32] &= ~(1U << (i % 32)); data_[i / kDataBits] &= ~(kOne << (i % kDataBits));
} }
void Union(const BitVector& other) { void Union(const BitVector& other) {
...@@ -123,7 +120,7 @@ class BitVector: public ZoneObject { ...@@ -123,7 +120,7 @@ class BitVector: public ZoneObject {
DCHECK(other.length() == length()); DCHECK(other.length() == length());
bool changed = false; bool changed = false;
for (int i = 0; i < data_length_; i++) { for (int i = 0; i < data_length_; i++) {
uint32_t old_data = data_[i]; uintptr_t old_data = data_[i];
data_[i] |= other.data_[i]; data_[i] |= other.data_[i];
if (data_[i] != old_data) changed = true; if (data_[i] != old_data) changed = true;
} }
...@@ -141,7 +138,7 @@ class BitVector: public ZoneObject { ...@@ -141,7 +138,7 @@ class BitVector: public ZoneObject {
DCHECK(other.length() == length()); DCHECK(other.length() == length());
bool changed = false; bool changed = false;
for (int i = 0; i < data_length_; i++) { for (int i = 0; i < data_length_; i++) {
uint32_t old_data = data_[i]; uintptr_t old_data = data_[i];
data_[i] &= other.data_[i]; data_[i] &= other.data_[i];
if (data_[i] != old_data) changed = true; if (data_[i] != old_data) changed = true;
} }
...@@ -184,9 +181,11 @@ class BitVector: public ZoneObject { ...@@ -184,9 +181,11 @@ class BitVector: public ZoneObject {
#endif #endif
private: private:
int length_; const int length_;
int data_length_; const int data_length_;
uint32_t* data_; uintptr_t* const data_;
DISALLOW_COPY_AND_ASSIGN(BitVector);
}; };
...@@ -195,19 +194,19 @@ class GrowableBitVector BASE_EMBEDDED { ...@@ -195,19 +194,19 @@ class GrowableBitVector BASE_EMBEDDED {
class Iterator BASE_EMBEDDED { class Iterator BASE_EMBEDDED {
public: public:
Iterator(const GrowableBitVector* target, Zone* zone) Iterator(const GrowableBitVector* target, Zone* zone)
: it_(target->bits_ == NULL : it_(target->bits_ == NULL ? new (zone) BitVector(1, zone)
? new(zone) BitVector(1, zone) : target->bits_) {}
: target->bits_) { }
bool Done() const { return it_.Done(); } bool Done() const { return it_.Done(); }
void Advance() { it_.Advance(); } void Advance() { it_.Advance(); }
int Current() const { return it_.Current(); } int Current() const { return it_.Current(); }
private: private:
BitVector::Iterator it_; BitVector::Iterator it_;
}; };
GrowableBitVector() : bits_(NULL) { } GrowableBitVector() : bits_(NULL) {}
GrowableBitVector(int length, Zone* zone) GrowableBitVector(int length, Zone* zone)
: bits_(new(zone) BitVector(length, zone)) { } : bits_(new (zone) BitVector(length, zone)) {}
bool Contains(int value) const { bool Contains(int value) const {
if (!InBitsRange(value)) return false; if (!InBitsRange(value)) return false;
...@@ -225,7 +224,9 @@ class GrowableBitVector BASE_EMBEDDED { ...@@ -225,7 +224,9 @@ class GrowableBitVector BASE_EMBEDDED {
} }
} }
void Clear() { if (bits_ != NULL) bits_->Clear(); } void Clear() {
if (bits_ != NULL) bits_->Clear();
}
private: private:
static const int kInitialLength = 1024; static const int kInitialLength = 1024;
...@@ -238,7 +239,7 @@ class GrowableBitVector BASE_EMBEDDED { ...@@ -238,7 +239,7 @@ class GrowableBitVector BASE_EMBEDDED {
if (InBitsRange(value)) return; if (InBitsRange(value)) return;
int new_length = bits_ == NULL ? kInitialLength : bits_->length(); int new_length = bits_ == NULL ? kInitialLength : bits_->length();
while (new_length <= value) new_length *= 2; while (new_length <= value) new_length *= 2;
BitVector* new_bits = new(zone) BitVector(new_length, zone); BitVector* new_bits = new (zone) BitVector(new_length, zone);
if (bits_ != NULL) new_bits->CopyFrom(*bits_); if (bits_ != NULL) new_bits->CopyFrom(*bits_);
bits_ = new_bits; bits_ = new_bits;
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_ #define V8_COMPILER_AST_LOOP_ASSIGNMENT_ANALYZER_H_
#include "src/ast.h" #include "src/ast.h"
#include "src/data-flow.h" #include "src/bit-vector.h"
#include "src/v8.h" #include "src/v8.h"
#include "src/zone-containers.h" #include "src/zone-containers.h"
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "src/v8.h" #include "src/v8.h"
#include "src/data-flow.h" #include "src/bit-vector.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
...@@ -7,12 +7,12 @@ ...@@ -7,12 +7,12 @@
#include "src/compiler/scheduler.h" #include "src/compiler/scheduler.h"
#include "src/bit-vector.h"
#include "src/compiler/graph.h" #include "src/compiler/graph.h"
#include "src/compiler/graph-inl.h" #include "src/compiler/graph-inl.h"
#include "src/compiler/node.h" #include "src/compiler/node.h"
#include "src/compiler/node-properties.h" #include "src/compiler/node-properties.h"
#include "src/compiler/node-properties-inl.h" #include "src/compiler/node-properties-inl.h"
#include "src/data-flow.h"
namespace v8 { namespace v8 {
namespace internal { namespace internal {
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include "src/bit-vector.h"
#include "src/compiler/generic-algorithm.h" #include "src/compiler/generic-algorithm.h"
#include "src/compiler/generic-node-inl.h" #include "src/compiler/generic-node-inl.h"
#include "src/compiler/generic-node.h" #include "src/compiler/generic-node.h"
...@@ -21,7 +22,6 @@ ...@@ -21,7 +22,6 @@
#include "src/compiler/operator.h" #include "src/compiler/operator.h"
#include "src/compiler/schedule.h" #include "src/compiler/schedule.h"
#include "src/compiler/simplified-operator.h" #include "src/compiler/simplified-operator.h"
#include "src/data-flow.h"
#include "src/ostreams.h" #include "src/ostreams.h"
namespace v8 { namespace v8 {
......
...@@ -10,10 +10,10 @@ ...@@ -10,10 +10,10 @@
#include "src/allocation.h" #include "src/allocation.h"
#include "src/assert-scope.h" #include "src/assert-scope.h"
#include "src/ast.h" #include "src/ast.h"
#include "src/bit-vector.h"
#include "src/code-stubs.h" #include "src/code-stubs.h"
#include "src/codegen.h" #include "src/codegen.h"
#include "src/compiler.h" #include "src/compiler.h"
#include "src/data-flow.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/objects.h" #include "src/objects.h"
......
...@@ -11,9 +11,9 @@ ...@@ -11,9 +11,9 @@
#include "src/allocation.h" #include "src/allocation.h"
#include "src/base/bits.h" #include "src/base/bits.h"
#include "src/bit-vector.h"
#include "src/code-stubs.h" #include "src/code-stubs.h"
#include "src/conversions.h" #include "src/conversions.h"
#include "src/data-flow.h"
#include "src/deoptimizer.h" #include "src/deoptimizer.h"
#include "src/hydrogen-types.h" #include "src/hydrogen-types.h"
#include "src/small-pointer-list.h" #include "src/small-pointer-list.h"
......
...@@ -102,13 +102,13 @@ ...@@ -102,13 +102,13 @@
'test-atomicops.cc', 'test-atomicops.cc',
'test-bignum.cc', 'test-bignum.cc',
'test-bignum-dtoa.cc', 'test-bignum-dtoa.cc',
'test-bit-vector.cc',
'test-checks.cc', 'test-checks.cc',
'test-circular-queue.cc', 'test-circular-queue.cc',
'test-compiler.cc', 'test-compiler.cc',
'test-constantpool.cc', 'test-constantpool.cc',
'test-conversions.cc', 'test-conversions.cc',
'test-cpu-profiler.cc', 'test-cpu-profiler.cc',
'test-dataflow.cc',
'test-date.cc', 'test-date.cc',
'test-debug.cc', 'test-debug.cc',
'test-declarative-accessors.cc', 'test-declarative-accessors.cc',
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "src/v8.h" #include "src/v8.h"
#include "src/data-flow.h" #include "src/bit-vector.h"
#include "test/cctest/cctest.h" #include "test/cctest/cctest.h"
using namespace v8::internal; using namespace v8::internal;
...@@ -83,7 +83,7 @@ TEST(BitVector) { ...@@ -83,7 +83,7 @@ TEST(BitVector) {
BitVector v(15, &zone); BitVector v(15, &zone);
v.Add(0); v.Add(0);
BitVector w(15, &zone); BitVector w(15, &zone);
w = v; w.CopyFrom(v);
CHECK(w.Contains(0)); CHECK(w.Contains(0));
w.Add(1); w.Add(1);
BitVector u(w, &zone); BitVector u(w, &zone);
......
...@@ -363,6 +363,8 @@ ...@@ -363,6 +363,8 @@
'../../src/bignum-dtoa.h', '../../src/bignum-dtoa.h',
'../../src/bignum.cc', '../../src/bignum.cc',
'../../src/bignum.h', '../../src/bignum.h',
'../../src/bit-vector.cc',
'../../src/bit-vector.h',
'../../src/bootstrapper.cc', '../../src/bootstrapper.cc',
'../../src/bootstrapper.h', '../../src/bootstrapper.h',
'../../src/builtins.cc', '../../src/builtins.cc',
...@@ -515,8 +517,6 @@ ...@@ -515,8 +517,6 @@
'../../src/cpu-profiler-inl.h', '../../src/cpu-profiler-inl.h',
'../../src/cpu-profiler.cc', '../../src/cpu-profiler.cc',
'../../src/cpu-profiler.h', '../../src/cpu-profiler.h',
'../../src/data-flow.cc',
'../../src/data-flow.h',
'../../src/date.cc', '../../src/date.cc',
'../../src/date.h', '../../src/date.h',
'../../src/dateparser-inl.h', '../../src/dateparser-inl.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