Commit d441160c authored by titzer@chromium.org's avatar titzer@chromium.org

Implement local check elimination on basic blocks.

BUG=
R=mstarzinger@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16970 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9c3ffc4f
......@@ -247,6 +247,7 @@ DEFINE_bool(collect_megamorphic_maps_from_stub_cache,
true,
"crankshaft harvests type feedback from stub cache")
DEFINE_bool(hydrogen_stats, false, "print statistics for hydrogen")
DEFINE_bool(trace_check_elimination, false, "trace check elimination phase")
DEFINE_bool(trace_hydrogen, false, "trace generated hydrogen to file")
DEFINE_string(trace_hydrogen_filter, "*", "hydrogen tracing filter")
DEFINE_bool(trace_hydrogen_stubs, false, "trace generated hydrogen for stubs")
......@@ -289,6 +290,7 @@ DEFINE_bool(array_index_dehoisting, true,
DEFINE_bool(analyze_environment_liveness, true,
"analyze liveness of environment slots and zap dead values")
DEFINE_bool(load_elimination, false, "use load elimination")
DEFINE_bool(check_elimination, false, "use check elimination")
DEFINE_bool(dead_code_elimination, true, "use dead code elimination")
DEFINE_bool(fold_constants, true, "use constant folding")
DEFINE_bool(trace_dead_code_elimination, false, "trace dead code elimination")
......
This diff is collapsed.
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_HYDROGEN_CHECK_ELIMINATION_H_
#define V8_HYDROGEN_CHECK_ELIMINATION_H_
#include "hydrogen.h"
namespace v8 {
namespace internal {
// Remove CheckMaps instructions through flow- and branch-sensitive analysis.
class HCheckEliminationPhase : public HPhase {
public:
explicit HCheckEliminationPhase(HGraph* graph)
: HPhase("H_Check Elimination", graph) { }
void Run();
private:
void EliminateLocalChecks(HBasicBlock* block);
};
} } // namespace v8::internal
#endif // V8_HYDROGEN_CHECK_ELIMINATION_H_
......@@ -3287,6 +3287,17 @@ class HConstant V8_FINAL : public HTemplateInstruction<0> {
return new_constant;
}
static HConstant* CreateAndInsertBefore(Zone* zone,
Unique<Object> unique,
bool is_not_in_new_space,
HInstruction* instruction) {
HConstant* new_constant = new(zone) HConstant(unique,
Representation::Tagged(), HType::Tagged(), false, is_not_in_new_space,
false, false);
new_constant->InsertBefore(instruction);
return new_constant;
}
Handle<Object> handle(Isolate* isolate) {
if (object_.handle().is_null()) {
// Default arguments to is_not_in_new_space depend on this heap number
......
......@@ -36,6 +36,7 @@
#include "hydrogen-bce.h"
#include "hydrogen-bch.h"
#include "hydrogen-canonicalize.h"
#include "hydrogen-check-elimination.h"
#include "hydrogen-dce.h"
#include "hydrogen-dehoist.h"
#include "hydrogen-deoptimizing-mark.h"
......@@ -3122,9 +3123,8 @@ bool HGraph::Optimize(BailoutReason* bailout_reason) {
return false;
}
// Remove dead code and phis
if (FLAG_check_elimination) Run<HCheckEliminationPhase>();
if (FLAG_dead_code_elimination) Run<HDeadCodeEliminationPhase>();
if (FLAG_use_escape_analysis) Run<HEscapeAnalysisPhase>();
if (FLAG_load_elimination) Run<HLoadEliminationPhase>();
......@@ -3162,12 +3162,8 @@ bool HGraph::Optimize(BailoutReason* bailout_reason) {
// Eliminate redundant stack checks on backwards branches.
Run<HStackCheckEliminationPhase>();
if (FLAG_array_bounds_checks_elimination) {
Run<HBoundsCheckEliminationPhase>();
}
if (FLAG_array_bounds_checks_hoisting) {
Run<HBoundsCheckHoistingPhase>();
}
if (FLAG_array_bounds_checks_elimination) Run<HBoundsCheckEliminationPhase>();
if (FLAG_array_bounds_checks_hoisting) Run<HBoundsCheckHoistingPhase>();
if (FLAG_array_index_dehoisting) Run<HDehoistIndexComputationsPhase>();
if (FLAG_dead_code_elimination) Run<HDeadCodeEliminationPhase>();
......
......@@ -120,6 +120,10 @@ class Unique V8_FINAL {
return handle_;
}
template <class S> static Unique<T> cast(Unique<S> that) {
return Unique<T>(that.raw_address_, Handle<T>::cast(that.handle_));
}
inline bool IsInitialized() const {
return raw_address_ != NULL || handle_.is_null();
}
......@@ -169,6 +173,17 @@ class UniqueSet V8_FINAL : public ZoneObject {
array_[size_++] = uniq;
}
// Remove an element from this set. Mutates this set. O(|this|)
void Remove(Unique<T> uniq) {
for (int i = 0; i < size_; i++) {
if (array_[i] == uniq) {
while (++i < size_) array_[i - 1] = array_[i];
size_--;
return;
}
}
}
// Compare this set against another set. O(|this|).
bool Equals(UniqueSet<T>* that) const {
if (that->size_ != this->size_) return false;
......@@ -273,6 +288,10 @@ class UniqueSet V8_FINAL : public ZoneObject {
return copy;
}
void Clear() {
size_ = 0;
}
inline int size() const {
return size_;
}
......
......@@ -165,6 +165,46 @@ TEST(UniqueSet_Add) {
}
TEST(UniqueSet_Remove) {
CcTest::InitializeVM();
MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
MAKE_UNIQUES_A_B_C;
Zone zone(isolate);
UniqueSet<String>* set = new(&zone) UniqueSet<String>();
set->Add(A, &zone);
set->Add(B, &zone);
set->Add(C, &zone);
CHECK_EQ(3, set->size());
set->Remove(A);
CHECK_EQ(2, set->size());
CHECK(!set->Contains(A));
CHECK(set->Contains(B));
CHECK(set->Contains(C));
set->Remove(A);
CHECK_EQ(2, set->size());
CHECK(!set->Contains(A));
CHECK(set->Contains(B));
CHECK(set->Contains(C));
set->Remove(B);
CHECK_EQ(1, set->size());
CHECK(!set->Contains(A));
CHECK(!set->Contains(B));
CHECK(set->Contains(C));
set->Remove(C);
CHECK_EQ(0, set->size());
CHECK(!set->Contains(A));
CHECK(!set->Contains(B));
CHECK(!set->Contains(C));
}
TEST(UniqueSet_Contains) {
CcTest::InitializeVM();
MAKE_HANDLES_AND_DISALLOW_ALLOCATION;
......
......@@ -334,6 +334,8 @@
'../../src/hydrogen-bch.h',
'../../src/hydrogen-canonicalize.cc',
'../../src/hydrogen-canonicalize.h',
'../../src/hydrogen-check-elimination.cc',
'../../src/hydrogen-check-elimination.h',
'../../src/hydrogen-dce.cc',
'../../src/hydrogen-dce.h',
'../../src/hydrogen-dehoist.cc',
......
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