Commit 02649f08 authored by rossberg@chromium.org's avatar rossberg@chromium.org

Implement simple effect typing for variables

For that, we maintain an abstract store typing of all variables with LOCAL location (i.e., those that do not escape the function's own scope). We treat assignments as sequential effects that modify this store.

When control flow branches, we have to compute the disjunction of possible effects. To that end, we represent the store as a stack of effect sets, such that we can cheaply push and pop "local" effects when control flow has to branch.

In cases of non-local control transfer from an unknown source, we currently erase all knowledge about the store.

The 'switch' statement is still to come.

For a formulation of the typing rules, see:

https://docs.google.com/a/google.com/file/d/0B3wuXSv9YKuKeUNkVXZDemZ0Z1E

;)

R=jkummerow@chromium.org
BUG=

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15776 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5e853995
......@@ -389,7 +389,7 @@ class Expression: public AstNode {
protected:
explicit Expression(Isolate* isolate)
: bounds_(Type::None(), Type::Any(), isolate),
: bounds_(Bounds::Unbounded(isolate)),
id_(GetNextId(isolate)),
test_id_(GetNextId(isolate)) {}
void set_to_boolean_types(byte types) { to_boolean_types_ = types; }
......
This diff is collapsed.
......@@ -90,6 +90,12 @@ bool SplayTree<Config, Allocator>::FindInternal(const Key& key) {
}
template<typename Config, class Allocator>
bool SplayTree<Config, Allocator>::Contains(const Key& key) {
return FindInternal(key);
}
template<typename Config, class Allocator>
bool SplayTree<Config, Allocator>::Find(const Key& key, Locator* locator) {
if (FindInternal(key)) {
......@@ -293,9 +299,10 @@ void SplayTree<Config, Allocator>::ForEach(Callback* callback) {
template <typename Config, class Allocator> template <class Callback>
void SplayTree<Config, Allocator>::ForEachNode(Callback* callback) {
if (root_ == NULL) return;
// Pre-allocate some space for tiny trees.
List<Node*, Allocator> nodes_to_visit(10, allocator_);
if (root_ != NULL) nodes_to_visit.Add(root_, allocator_);
nodes_to_visit.Add(root_, allocator_);
int pos = 0;
while (pos < nodes_to_visit.length()) {
Node* node = nodes_to_visit[pos++];
......
......@@ -39,9 +39,9 @@ namespace internal {
//
// typedef Key: the key type
// typedef Value: the value type
// static const kNoKey: the dummy key used when no key is set
// static const kNoValue: the dummy value used to initialize nodes
// int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function
// static const Key kNoKey: the dummy key used when no key is set
// static Value kNoValue(): the dummy value used to initialize nodes
// static int (Compare)(Key& a, Key& b) -> {-1, 0, 1}: comparison function
//
// The tree is also parameterized by an allocation policy
// (Allocator). The policy is used for allocating lists in the C free
......@@ -74,6 +74,11 @@ class SplayTree {
UNREACHABLE();
}
AllocationPolicy allocator() { return allocator_; }
// Checks if there is a mapping for the key.
bool Contains(const Key& key);
// Inserts the given key in this tree with the given value. Returns
// true if a node was inserted, otherwise false. If found the locator
// is enabled and provides access to the mapping for the key.
......@@ -104,6 +109,9 @@ class SplayTree {
// Remove the node with the given key from the tree.
bool Remove(const Key& key);
// Remove all keys from the tree.
void Clear() { ResetRoot(); }
bool is_empty() { return root_ == NULL; }
// Perform the splay operation for the given key. Moves the node with
......
......@@ -303,6 +303,11 @@ struct Bounds {
explicit Bounds(Handle<Type> t) : lower(t), upper(t) {}
Bounds(Type* t, Isolate* isl) : lower(t, isl), upper(t, isl) {}
// Unrestricted bounds.
static Bounds Unbounded(Isolate* isl) {
return Bounds(Type::None(), Type::Any(), isl);
}
// Meet: both b1 and b2 are known to hold.
static Bounds Both(Bounds b1, Bounds b2, Isolate* isl) {
return Bounds(
......
This diff is collapsed.
......@@ -35,6 +35,7 @@
#include "compiler.h"
#include "type-info.h"
#include "types.h"
#include "effects.h"
#include "zone.h"
#include "scopes.h"
......@@ -57,8 +58,13 @@ class AstTyper: public AstVisitor {
private:
explicit AstTyper(CompilationInfo* info);
static const int kNoVar = INT_MIN;
typedef v8::internal::Effects<int, kNoVar> Effects;
typedef v8::internal::NestedEffects<int, kNoVar> Store;
CompilationInfo* info_;
TypeFeedbackOracle oracle_;
Store store_;
TypeFeedbackOracle* oracle() { return &oracle_; }
Zone* zone() const { return info_->zone(); }
......@@ -70,6 +76,17 @@ class AstTyper: public AstVisitor {
e->set_bounds(Bounds::NarrowLower(e->bounds(), t, isolate_));
}
Effects EnterEffects() {
store_ = store_.Push();
return store_.Top();
}
void ExitEffects() { store_ = store_.Pop(); }
int variable_index(Variable* var) {
return var->IsStackLocal() ? var->index() :
var->IsParameter() ? -var->index() : kNoVar;
}
void VisitDeclarations(ZoneList<Declaration*>* declarations);
void VisitStatements(ZoneList<Statement*>* statements);
......
......@@ -109,6 +109,12 @@ void* ZoneList<T>::operator new(size_t size, Zone* zone) {
}
template <typename T>
void* ZoneSplayTree<T>::operator new(size_t size, Zone* zone) {
return zone->New(static_cast<int>(size));
}
} } // namespace v8::internal
#endif // V8_ZONE_INL_H_
......@@ -177,6 +177,7 @@ struct ZoneAllocationPolicy {
explicit ZoneAllocationPolicy(Zone* zone) : zone_(zone) { }
INLINE(void* New(size_t size));
INLINE(static void Delete(void *pointer)) { }
Zone* zone() { return zone_; }
private:
Zone* zone_;
......@@ -246,6 +247,8 @@ class ZoneSplayTree: public SplayTree<Config, ZoneAllocationPolicy> {
explicit ZoneSplayTree(Zone* zone)
: SplayTree<Config, ZoneAllocationPolicy>(ZoneAllocationPolicy(zone)) {}
~ZoneSplayTree();
INLINE(void* operator new(size_t size, Zone* zone));
};
......
......@@ -290,6 +290,7 @@
'../../src/double.h',
'../../src/dtoa.cc',
'../../src/dtoa.h',
'../../src/effects.h',
'../../src/elements-kind.cc',
'../../src/elements-kind.h',
'../../src/elements.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