Reviewers: Kevin Millikin,
Description:
Simple support for const variables in Crankshaft.
The approach is to handle the common case in the optimizing
compiler and to bailout for the rare corner cases.
This is done by initializing all local const-variables with
the hole value and disallowing any use of the hole value statically.
Please review this at http://codereview.chromium.org/6026006/
SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/
Affected files:
M src/hydrogen.h
M src/hydrogen.cc
Index: src/hydrogen.cc
===================================================================
--- src/hydrogen.cc (revision 6080)
+++ src/hydrogen.cc (working copy)
@@ -502,6 +502,11 @@
}
+HConstant* HGraph::GetConstantHole() {
+ return GetConstant(&constant_hole_, Heap::the_hole_value());
+}
+
+
void HSubgraph::AppendOptional(HSubgraph* graph,
bool on_true_branch,
HValue* boolean_value) {
@@ -891,6 +896,10 @@
phi_list_->Add(phi);
// We don't support phi uses of arguments for now.
if (phi->CheckFlag(HValue::kIsArguments)) return false;
+ // Check for the hole value (from an uninitialized const).
+ for (int k = 0; k < phi->OperandCount(); k++) {
+ if (phi->OperandAt(k) == GetConstantHole()) return false;
+ }
}
}
return true;
@@ -2220,7 +2229,7 @@
graph_->AssignDominators();
graph_->EliminateRedundantPhis();
if (!graph_->CollectPhis()) {
- Bailout("Phi-use of arguments object");
+ Bailout("Unsupported phi-use");
return NULL;
}
@@ -2329,6 +2338,8 @@
// We can't handle heap-allocated locals.
if (scope->num_heap_slots() > 0) BAILOUT("heap allocated locals");
+ if (scope->HasIllegalRedeclaration()) BAILOUT("illegal redeclaration");
+
HConstant* undefined_constant =
new HConstant(Factory::undefined_value(), Representation::Tagged());
AddInstruction(undefined_constant);
@@ -2936,10 +2947,15 @@
if (variable == NULL) {
BAILOUT("reference to rewritten variable");
} else if (variable->IsStackAllocated()) {
- if (environment()->Lookup(variable)->CheckFlag(HValue::kIsArguments)) {
+ HValue* value = environment()->Lookup(variable);
+ if (value->CheckFlag(HValue::kIsArguments)) {
BAILOUT("unsupported context for arguments object");
}
- ast_context()->ReturnValue(environment()->Lookup(variable));
+ if (variable->mode() == Variable::CONST &&
+ value == graph()->GetConstantHole()) {
+ BAILOUT("unsupported reference to const variable");
+ }
+ ast_context()->ReturnValue(value);
} else if (variable->is_global()) {
LookupResult lookup;
LookupGlobalPropertyCell(variable, &lookup, false);
@@ -3462,6 +3478,10 @@
}
if (var != NULL) {
+ if (var->mode() == Variable::CONST && expr->op() != Token::INIT_CONST)
{
+ BAILOUT("const re-assignment");
+ }
+
if (proxy->IsArguments()) BAILOUT("assignment to arguments");
// Handle the assignment.
@@ -4534,6 +4554,7 @@
bool inc = expr->op() == Token::INC;
if (var != NULL) {
+ if (var->mode() == Variable::CONST) BAILOUT("unsupported count
operation");
if (!var->is_global() && !var->IsStackAllocated()) {
BAILOUT("non-stack/non-global variable in count operation");
}
@@ -4888,16 +4909,18 @@
void HGraphBuilder::VisitDeclaration(Declaration* decl) {
// We allow only declarations that do not require code generation.
// The following all require code generation: global variables and
- // functions, variables with slot type LOOKUP, declarations with
- // mode CONST, and functions.
+ // functions, variables with slot type LOOKUP
Variable* var = decl->proxy()->var();
Slot* slot = var->AsSlot();
if (var->is_global() ||
(slot != NULL && slot->type() == Slot::LOOKUP) ||
- decl->mode() == Variable::CONST ||
decl->fun() != NULL) {
BAILOUT("unsupported declaration");
}
+
+ if (var->mode() == Variable::CONST) {
+ environment()->Bind(var, graph()->GetConstantHole());
+ }
}
Index: src/hydrogen.h
===================================================================
--- src/hydrogen.h (revision 6080)
+++ src/hydrogen.h (working copy)
@@ -324,6 +324,7 @@
HConstant* GetConstantMinus1();
HConstant* GetConstantTrue();
HConstant* GetConstantFalse();
+ HConstant* GetConstantHole();
HBasicBlock* CreateBasicBlock();
HArgumentsObject* GetArgumentsObject() const {
@@ -387,6 +388,7 @@
SetOncePointer<HConstant> constant_minus1_;
SetOncePointer<HConstant> constant_true_;
SetOncePointer<HConstant> constant_false_;
+ SetOncePointer<HConstant> constant_hole_;
SetOncePointer<HArgumentsObject> arguments_object_;
friend class HSubgraph;
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev