Replaced a bailout ID assertion with quadratic time complexity by a linear one.

This reduces the time to run our test suite in debug mode considerably (from
8:43 to 4:05 on my local workstation using 32 threads). Note that the assertion
is so fast now that it doesn't need to be hidden behind --enable-slow-asserts.
Furthermore, the bookkeeping of the set is not measurable in all our benchmarks,
so I intentionally avoided any #ifdef chaos to keep things simple.

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13312 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2013-01-04 12:48:18 +00:00
parent 0606abbaab
commit 8a2cca5207
4 changed files with 38 additions and 46 deletions

View File

@ -199,6 +199,40 @@ class BitVector: public ZoneObject {
uint32_t* data_;
};
class GrowableBitVector BASE_EMBEDDED {
public:
GrowableBitVector() : bits_(NULL) { }
bool Contains(int value) const {
if (!InBitsRange(value)) return false;
return bits_->Contains(value);
}
void Add(int value, Zone* zone) {
EnsureCapacity(value, zone);
bits_->Add(value);
}
private:
static const int kInitialLength = 1024;
bool InBitsRange(int value) const {
return bits_ != NULL && bits_->length() > value;
}
void EnsureCapacity(int value, Zone* zone) {
if (InBitsRange(value)) return;
int new_length = bits_ == NULL ? kInitialLength : bits_->length();
while (new_length <= value) new_length *= 2;
BitVector* new_bits = new(zone) BitVector(new_length, zone);
if (bits_ != NULL) new_bits->CopyFrom(*bits_);
bits_ = new_bits;
}
BitVector* bits_;
};
} } // namespace v8::internal

View File

@ -448,18 +448,8 @@ void FullCodeGenerator::PrepareForBailoutForId(BailoutId id, State state) {
StateField::encode(state) | PcField::encode(masm_->pc_offset());
ASSERT(Smi::IsValid(pc_and_state));
BailoutEntry entry = { id, pc_and_state };
#ifdef DEBUG
if (FLAG_enable_slow_asserts) {
// Assert that we don't have multiple bailout entries for the same node.
for (int i = 0; i < bailout_entries_.length(); i++) {
if (bailout_entries_.at(i).id == entry.id) {
AstPrinter printer;
PrintF("%s", printer.PrintProgram(info_->function()));
UNREACHABLE();
}
}
}
#endif // DEBUG
ASSERT(!prepared_bailout_ids_.Contains(id.ToInt()));
prepared_bailout_ids_.Add(id.ToInt(), zone());
bailout_entries_.Add(entry, zone());
}

View File

@ -35,6 +35,7 @@
#include "code-stubs.h"
#include "codegen.h"
#include "compiler.h"
#include "data-flow.h"
namespace v8 {
namespace internal {
@ -816,6 +817,7 @@ class FullCodeGenerator: public AstVisitor {
int module_index_;
const ExpressionContext* context_;
ZoneList<BailoutEntry> bailout_entries_;
GrowableBitVector prepared_bailout_ids_;
// TODO(svenpanne) Rename this to something like back_edges_ and rename
// related functions accordingly.
ZoneList<BailoutEntry> stack_checks_;

View File

@ -399,40 +399,6 @@ class LiveRange: public ZoneObject {
};
class GrowableBitVector BASE_EMBEDDED {
public:
GrowableBitVector() : bits_(NULL) { }
bool Contains(int value) const {
if (!InBitsRange(value)) return false;
return bits_->Contains(value);
}
void Add(int value, Zone* zone) {
EnsureCapacity(value, zone);
bits_->Add(value);
}
private:
static const int kInitialLength = 1024;
bool InBitsRange(int value) const {
return bits_ != NULL && bits_->length() > value;
}
void EnsureCapacity(int value, Zone* zone) {
if (InBitsRange(value)) return;
int new_length = bits_ == NULL ? kInitialLength : bits_->length();
while (new_length <= value) new_length *= 2;
BitVector* new_bits = new(zone) BitVector(new_length, zone);
if (bits_ != NULL) new_bits->CopyFrom(*bits_);
bits_ = new_bits;
}
BitVector* bits_;
};
class LAllocator BASE_EMBEDDED {
public:
LAllocator(int first_virtual_register, HGraph* graph);