Commit 7b59723d authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Implement proper caching of heap constants in the JSGraph.

With the handle canonicalization we can now easily cache heap constant
nodes based on the location of the HeapObject handle location.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#32876}
parent e3f0b5a4
......@@ -16,6 +16,11 @@ Node** CommonNodeCache::FindExternalConstant(ExternalReference value) {
}
Node** CommonNodeCache::FindHeapConstant(Handle<HeapObject> value) {
return heap_constants_.Find(zone(), bit_cast<intptr_t>(value.location()));
}
void CommonNodeCache::GetCachedNodes(ZoneVector<Node*>* nodes) {
int32_constants_.GetCachedNodes(nodes);
int64_constants_.GetCachedNodes(nodes);
......@@ -23,6 +28,7 @@ void CommonNodeCache::GetCachedNodes(ZoneVector<Node*>* nodes) {
float64_constants_.GetCachedNodes(nodes);
external_constants_.GetCachedNodes(nodes);
number_constants_.GetCachedNodes(nodes);
heap_constants_.GetCachedNodes(nodes);
}
} // namespace compiler
......
......@@ -12,6 +12,9 @@ namespace internal {
// Forward declarations.
class ExternalReference;
class HeapObject;
template <typename>
class Handle;
namespace compiler {
......@@ -47,6 +50,8 @@ class CommonNodeCache final {
return number_constants_.Find(zone(), bit_cast<int64_t>(value));
}
Node** FindHeapConstant(Handle<HeapObject> value);
// Return all nodes from the cache.
void GetCachedNodes(ZoneVector<Node*>* nodes);
......@@ -59,7 +64,8 @@ class CommonNodeCache final {
Int64NodeCache float64_constants_;
IntPtrNodeCache external_constants_;
Int64NodeCache number_constants_;
Zone* zone_;
IntPtrNodeCache heap_constants_;
Zone* const zone_;
DISALLOW_COPY_AND_ASSIGN(CommonNodeCache);
};
......
......@@ -11,12 +11,6 @@ namespace v8 {
namespace internal {
namespace compiler {
Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> value) {
// TODO(bmeurer): Flatten cons strings here before we canonicalize them?
return graph()->NewNode(common()->HeapConstant(value));
}
#define CACHED(name, expr) \
cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr))
......@@ -24,43 +18,40 @@ Node* JSGraph::ImmovableHeapConstant(Handle<HeapObject> value) {
Node* JSGraph::CEntryStubConstant(int result_size) {
if (result_size == 1) {
return CACHED(kCEntryStubConstant,
ImmovableHeapConstant(CEntryStub(isolate(), 1).GetCode()));
HeapConstant(CEntryStub(isolate(), 1).GetCode()));
}
return ImmovableHeapConstant(CEntryStub(isolate(), result_size).GetCode());
return HeapConstant(CEntryStub(isolate(), result_size).GetCode());
}
Node* JSGraph::EmptyFixedArrayConstant() {
return CACHED(kEmptyFixedArrayConstant,
ImmovableHeapConstant(factory()->empty_fixed_array()));
HeapConstant(factory()->empty_fixed_array()));
}
Node* JSGraph::UndefinedConstant() {
return CACHED(kUndefinedConstant,
ImmovableHeapConstant(factory()->undefined_value()));
return CACHED(kUndefinedConstant, HeapConstant(factory()->undefined_value()));
}
Node* JSGraph::TheHoleConstant() {
return CACHED(kTheHoleConstant,
ImmovableHeapConstant(factory()->the_hole_value()));
return CACHED(kTheHoleConstant, HeapConstant(factory()->the_hole_value()));
}
Node* JSGraph::TrueConstant() {
return CACHED(kTrueConstant, ImmovableHeapConstant(factory()->true_value()));
return CACHED(kTrueConstant, HeapConstant(factory()->true_value()));
}
Node* JSGraph::FalseConstant() {
return CACHED(kFalseConstant,
ImmovableHeapConstant(factory()->false_value()));
return CACHED(kFalseConstant, HeapConstant(factory()->false_value()));
}
Node* JSGraph::NullConstant() {
return CACHED(kNullConstant, ImmovableHeapConstant(factory()->null_value()));
return CACHED(kNullConstant, HeapConstant(factory()->null_value()));
}
......@@ -81,11 +72,12 @@ Node* JSGraph::NaNConstant() {
Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
// TODO(turbofan): canonicalize heap constants using <magic approach>.
// TODO(titzer): We could also match against the addresses of immortable
// immovables here, even without access to the heap, thus always
// canonicalizing references to them.
return ImmovableHeapConstant(value);
// TODO(bmeurer): Flatten cons strings here before we canonicalize them?
Node** loc = cache_.FindHeapConstant(value);
if (*loc == nullptr) {
*loc = graph()->NewNode(common()->HeapConstant(value));
}
return *loc;
}
......
......@@ -158,7 +158,6 @@ class JSGraph : public ZoneObject {
CommonNodeCache cache_;
Node* cached_nodes_[kNumCachedNodes];
Node* ImmovableHeapConstant(Handle<HeapObject> value);
Node* NumberConstant(double value);
DISALLOW_COPY_AND_ASSIGN(JSGraph);
......
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