Commit 6ee71526 authored by Jaroslav Sevcik's avatar Jaroslav Sevcik Committed by Commit Bot

[turbofan] Introduce JS heap broker.

As a first step towards moving accesses to the broker, this moves
heap accesses from BitsetType::Lub to the broker.

Bug: v8:7790
Change-Id: Ie240b84b979717caae42cb8aa06ee8d9877a446d
Reviewed-on: https://chromium-review.googlesource.com/1088695
Commit-Queue: Jaroslav Sevcik <jarin@chromium.org>
Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53571}
parent 907a3c68
...@@ -1693,6 +1693,8 @@ v8_source_set("v8_base") { ...@@ -1693,6 +1693,8 @@ v8_source_set("v8_base") {
"src/compiler/js-generic-lowering.h", "src/compiler/js-generic-lowering.h",
"src/compiler/js-graph.cc", "src/compiler/js-graph.cc",
"src/compiler/js-graph.h", "src/compiler/js-graph.h",
"src/compiler/js-heap-broker.cc",
"src/compiler/js-heap-broker.h",
"src/compiler/js-inlining-heuristic.cc", "src/compiler/js-inlining-heuristic.cc",
"src/compiler/js-inlining-heuristic.h", "src/compiler/js-inlining-heuristic.h",
"src/compiler/js-inlining.cc", "src/compiler/js-inlining.cc",
......
...@@ -237,8 +237,10 @@ Handle<Cell> PropertyAccessInfo::export_cell() const { ...@@ -237,8 +237,10 @@ Handle<Cell> PropertyAccessInfo::export_cell() const {
} }
AccessInfoFactory::AccessInfoFactory(CompilationDependencies* dependencies, AccessInfoFactory::AccessInfoFactory(CompilationDependencies* dependencies,
const JSHeapBroker* js_heap_broker,
Handle<Context> native_context, Zone* zone) Handle<Context> native_context, Zone* zone)
: dependencies_(dependencies), : dependencies_(dependencies),
js_heap_broker_(js_heap_broker),
native_context_(native_context), native_context_(native_context),
isolate_(native_context->GetIsolate()), isolate_(native_context->GetIsolate()),
type_cache_(TypeCache::Get()), type_cache_(TypeCache::Get()),
...@@ -398,8 +400,8 @@ bool AccessInfoFactory::ComputePropertyAccessInfo( ...@@ -398,8 +400,8 @@ bool AccessInfoFactory::ComputePropertyAccessInfo(
dependencies()->AssumeFieldOwner(field_owner_map); dependencies()->AssumeFieldOwner(field_owner_map);
// Remember the field map, and try to infer a useful type. // Remember the field map, and try to infer a useful type.
field_type = field_type = Type::For(js_heap_broker(),
Type::For(isolate(), descriptors_field_type->AsClass()); descriptors_field_type->AsClass());
field_map = descriptors_field_type->AsClass(); field_map = descriptors_field_type->AsClass();
} }
} }
...@@ -704,7 +706,8 @@ bool AccessInfoFactory::LookupTransition(Handle<Map> map, Handle<Name> name, ...@@ -704,7 +706,8 @@ bool AccessInfoFactory::LookupTransition(Handle<Map> map, Handle<Name> name,
dependencies()->AssumeFieldOwner(field_owner_map); dependencies()->AssumeFieldOwner(field_owner_map);
// Remember the field map, and try to infer a useful type. // Remember the field map, and try to infer a useful type.
field_type = Type::For(isolate(), descriptors_field_type->AsClass()); field_type =
Type::For(js_heap_broker(), descriptors_field_type->AsClass());
field_map = descriptors_field_type->AsClass(); field_map = descriptors_field_type->AsClass();
} }
} }
......
...@@ -141,6 +141,7 @@ class PropertyAccessInfo final { ...@@ -141,6 +141,7 @@ class PropertyAccessInfo final {
class AccessInfoFactory final { class AccessInfoFactory final {
public: public:
AccessInfoFactory(CompilationDependencies* dependencies, AccessInfoFactory(CompilationDependencies* dependencies,
const JSHeapBroker* js_heap_broker,
Handle<Context> native_context, Zone* zone); Handle<Context> native_context, Zone* zone);
bool ComputeElementAccessInfo(Handle<Map> map, AccessMode access_mode, bool ComputeElementAccessInfo(Handle<Map> map, AccessMode access_mode,
...@@ -167,12 +168,14 @@ class AccessInfoFactory final { ...@@ -167,12 +168,14 @@ class AccessInfoFactory final {
PropertyAccessInfo* access_info); PropertyAccessInfo* access_info);
CompilationDependencies* dependencies() const { return dependencies_; } CompilationDependencies* dependencies() const { return dependencies_; }
const JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
Factory* factory() const; Factory* factory() const;
Isolate* isolate() const { return isolate_; } Isolate* isolate() const { return isolate_; }
Handle<Context> native_context() const { return native_context_; } Handle<Context> native_context() const { return native_context_; }
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
CompilationDependencies* const dependencies_; CompilationDependencies* const dependencies_;
const JSHeapBroker* const js_heap_broker_;
Handle<Context> const native_context_; Handle<Context> const native_context_;
Isolate* const isolate_; Isolate* const isolate_;
TypeCache const& type_cache_; TypeCache const& type_cache_;
......
...@@ -776,7 +776,7 @@ Reduction JSCreateLowering::ReduceJSCreateArray(Node* node) { ...@@ -776,7 +776,7 @@ Reduction JSCreateLowering::ReduceJSCreateArray(Node* node) {
Node* new_target = NodeProperties::GetValueInput(node, 1); Node* new_target = NodeProperties::GetValueInput(node, 1);
Type new_target_type = Type new_target_type =
(target == new_target) (target == new_target)
? Type::HeapConstant(isolate(), constructor, zone()) ? Type::HeapConstant(js_heap_broker(), constructor, zone())
: NodeProperties::GetType(new_target); : NodeProperties::GetType(new_target);
// Extract original constructor function. // Extract original constructor function.
...@@ -1789,7 +1789,7 @@ Node* JSCreateLowering::AllocateFastLiteral( ...@@ -1789,7 +1789,7 @@ Node* JSCreateLowering::AllocateFastLiteral(
// Actually allocate and initialize the object. // Actually allocate and initialize the object.
AllocationBuilder builder(jsgraph(), effect, control); AllocationBuilder builder(jsgraph(), effect, control);
builder.Allocate(boilerplate_map->instance_size(), pretenure, builder.Allocate(boilerplate_map->instance_size(), pretenure,
Type::For(isolate(), boilerplate_map)); Type::For(js_heap_broker(), boilerplate_map));
builder.Store(AccessBuilder::ForMap(), boilerplate_map); builder.Store(AccessBuilder::ForMap(), boilerplate_map);
builder.Store(AccessBuilder::ForJSObjectPropertiesOrHash(), properties); builder.Store(AccessBuilder::ForJSObjectPropertiesOrHash(), properties);
builder.Store(AccessBuilder::ForJSObjectElements(), elements); builder.Store(AccessBuilder::ForJSObjectElements(), elements);
...@@ -1895,7 +1895,8 @@ Node* JSCreateLowering::AllocateLiteralRegExp(Node* effect, Node* control, ...@@ -1895,7 +1895,8 @@ Node* JSCreateLowering::AllocateLiteralRegExp(Node* effect, Node* control,
JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize; JSRegExp::kSize + JSRegExp::kInObjectFieldCount * kPointerSize;
AllocationBuilder builder(jsgraph(), effect, control); AllocationBuilder builder(jsgraph(), effect, control);
builder.Allocate(size, pretenure, Type::For(isolate(), boilerplate_map)); builder.Allocate(size, pretenure,
Type::For(js_heap_broker(), boilerplate_map));
builder.Store(AccessBuilder::ForMap(), boilerplate_map); builder.Store(AccessBuilder::ForMap(), boilerplate_map);
builder.Store(AccessBuilder::ForJSObjectPropertiesOrHash(), builder.Store(AccessBuilder::ForJSObjectPropertiesOrHash(),
handle(boilerplate->raw_properties_or_hash(), isolate())); handle(boilerplate->raw_properties_or_hash(), isolate()));
......
...@@ -23,6 +23,7 @@ namespace compiler { ...@@ -23,6 +23,7 @@ namespace compiler {
// Forward declarations. // Forward declarations.
class CommonOperatorBuilder; class CommonOperatorBuilder;
class JSGraph; class JSGraph;
class JSHeapBroker;
class JSOperatorBuilder; class JSOperatorBuilder;
class MachineOperatorBuilder; class MachineOperatorBuilder;
class SimplifiedOperatorBuilder; class SimplifiedOperatorBuilder;
...@@ -33,11 +34,12 @@ class V8_EXPORT_PRIVATE JSCreateLowering final ...@@ -33,11 +34,12 @@ class V8_EXPORT_PRIVATE JSCreateLowering final
: public NON_EXPORTED_BASE(AdvancedReducer) { : public NON_EXPORTED_BASE(AdvancedReducer) {
public: public:
JSCreateLowering(Editor* editor, CompilationDependencies* dependencies, JSCreateLowering(Editor* editor, CompilationDependencies* dependencies,
JSGraph* jsgraph, JSGraph* jsgraph, const JSHeapBroker* js_heap_broker,
Handle<Context> native_context, Zone* zone) Handle<Context> native_context, Zone* zone)
: AdvancedReducer(editor), : AdvancedReducer(editor),
dependencies_(dependencies), dependencies_(dependencies),
jsgraph_(jsgraph), jsgraph_(jsgraph),
js_heap_broker_(js_heap_broker),
native_context_(native_context), native_context_(native_context),
zone_(zone) {} zone_(zone) {}
~JSCreateLowering() final {} ~JSCreateLowering() final {}
...@@ -114,10 +116,12 @@ class V8_EXPORT_PRIVATE JSCreateLowering final ...@@ -114,10 +116,12 @@ class V8_EXPORT_PRIVATE JSCreateLowering final
CommonOperatorBuilder* common() const; CommonOperatorBuilder* common() const;
SimplifiedOperatorBuilder* simplified() const; SimplifiedOperatorBuilder* simplified() const;
CompilationDependencies* dependencies() const { return dependencies_; } CompilationDependencies* dependencies() const { return dependencies_; }
const JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
CompilationDependencies* const dependencies_; CompilationDependencies* const dependencies_;
JSGraph* const jsgraph_; JSGraph* const jsgraph_;
const JSHeapBroker* const js_heap_broker_;
Handle<Context> const native_context_; Handle<Context> const native_context_;
Zone* const zone_; Zone* const zone_;
}; };
......
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/compiler/js-heap-broker.h"
#include "src/objects-inl.h"
namespace v8 {
namespace internal {
namespace compiler {
JSHeapBroker::JSHeapBroker(Isolate* isolate) : isolate_(isolate) {}
HeapReferenceType JSHeapBroker::HeapReferenceTypeFromMap(Map* map) const {
AllowHandleDereference allow_handle_dereference;
Heap* heap = isolate_->heap();
HeapReferenceType::OddballType oddball_type = HeapReferenceType::kUnknown;
if (map->instance_type() == ODDBALL_TYPE) {
if (map == heap->undefined_map()) {
oddball_type = HeapReferenceType::kUndefined;
} else if (map == heap->null_map()) {
oddball_type = HeapReferenceType::kNull;
} else if (map == heap->boolean_map()) {
oddball_type = HeapReferenceType::kBoolean;
} else if (map == heap->the_hole_map()) {
oddball_type = HeapReferenceType::kHole;
} else {
DCHECK(map == heap->uninitialized_map() ||
map == heap->termination_exception_map() ||
map == heap->arguments_marker_map() ||
map == heap->optimized_out_map() ||
map == heap->stale_register_map());
}
}
HeapReferenceType::Flags flags(0);
if (map->is_undetectable()) flags |= HeapReferenceType::kUndetectable;
if (map->is_callable()) flags |= HeapReferenceType::kCallable;
return HeapReferenceType(map->instance_type(), flags, oddball_type);
}
HeapReferenceType JSHeapBroker::HeapReferenceTypeForObject(
Handle<HeapObject> object) const {
AllowHandleDereference allow_handle_dereference;
return HeapReferenceTypeFromMap(object->map());
}
} // namespace compiler
} // namespace internal
} // namespace v8
// Copyright 2018 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef V8_COMPILER_JS_HEAP_BROKER_H_
#define V8_COMPILER_JS_HEAP_BROKER_H_
#include "src/base/compiler-specific.h"
#include "src/globals.h"
#include "src/objects.h"
namespace v8 {
namespace internal {
namespace compiler {
class HeapReferenceType {
public:
enum OddballType : uint8_t { kUnknown, kBoolean, kUndefined, kNull, kHole };
enum Flag : uint8_t { kUndetectable = 1 << 0, kCallable = 1 << 1 };
typedef base::Flags<Flag> Flags;
HeapReferenceType(InstanceType instance_type, Flags flags,
OddballType oddball_type = kUnknown)
: instance_type_(instance_type),
oddball_type_(oddball_type),
flags_(flags) {}
OddballType oddball_type() const { return oddball_type_; }
InstanceType instance_type() const { return instance_type_; }
Flags flags() const { return flags_; }
bool is_callable() const { return flags_ & kCallable; }
bool is_undetectable() const { return flags_ & kUndetectable; }
private:
InstanceType const instance_type_;
OddballType const oddball_type_;
Flags const flags_;
};
class V8_EXPORT_PRIVATE JSHeapBroker : public NON_EXPORTED_BASE(ZoneObject) {
public:
JSHeapBroker(Isolate* isolate);
HeapReferenceType HeapReferenceTypeFromMap(Handle<Map> map) const {
return HeapReferenceTypeFromMap(*map);
}
HeapReferenceType HeapReferenceTypeForObject(Handle<HeapObject> object) const;
private:
HeapReferenceType HeapReferenceTypeFromMap(Map* map) const;
Isolate* const isolate_;
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_COMPILER_JS_HEAP_BROKER_H_
...@@ -58,11 +58,12 @@ struct JSNativeContextSpecialization::ScriptContextTableLookupResult { ...@@ -58,11 +58,12 @@ struct JSNativeContextSpecialization::ScriptContextTableLookupResult {
}; };
JSNativeContextSpecialization::JSNativeContextSpecialization( JSNativeContextSpecialization::JSNativeContextSpecialization(
Editor* editor, JSGraph* jsgraph, Flags flags, Editor* editor, JSGraph* jsgraph, const JSHeapBroker* js_heap_broker,
Handle<Context> native_context, CompilationDependencies* dependencies, Flags flags, Handle<Context> native_context,
Zone* zone) CompilationDependencies* dependencies, Zone* zone)
: AdvancedReducer(editor), : AdvancedReducer(editor),
jsgraph_(jsgraph), jsgraph_(jsgraph),
js_heap_broker_(js_heap_broker),
flags_(flags), flags_(flags),
global_object_(native_context->global_object()), global_object_(native_context->global_object()),
global_proxy_(JSGlobalProxy::cast(native_context->global_proxy())), global_proxy_(JSGlobalProxy::cast(native_context->global_proxy())),
...@@ -190,8 +191,8 @@ Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) { ...@@ -190,8 +191,8 @@ Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) {
// Compute property access info for @@hasInstance on {receiver}. // Compute property access info for @@hasInstance on {receiver}.
PropertyAccessInfo access_info; PropertyAccessInfo access_info;
AccessInfoFactory access_info_factory(dependencies(), native_context(), AccessInfoFactory access_info_factory(dependencies(), js_heap_broker(),
graph()->zone()); native_context(), graph()->zone());
if (!access_info_factory.ComputePropertyAccessInfo( if (!access_info_factory.ComputePropertyAccessInfo(
receiver_map, factory()->has_instance_symbol(), AccessMode::kLoad, receiver_map, factory()->has_instance_symbol(), AccessMode::kLoad,
&access_info)) { &access_info)) {
...@@ -477,8 +478,8 @@ Reduction JSNativeContextSpecialization::ReduceJSResolvePromise(Node* node) { ...@@ -477,8 +478,8 @@ Reduction JSNativeContextSpecialization::ReduceJSResolvePromise(Node* node) {
// Compute property access info for "then" on {resolution}. // Compute property access info for "then" on {resolution}.
PropertyAccessInfo access_info; PropertyAccessInfo access_info;
AccessInfoFactory access_info_factory(dependencies(), native_context(), AccessInfoFactory access_info_factory(dependencies(), js_heap_broker(),
graph()->zone()); native_context(), graph()->zone());
if (!access_info_factory.ComputePropertyAccessInfo( if (!access_info_factory.ComputePropertyAccessInfo(
MapHandles(resolution_maps.begin(), resolution_maps.end()), MapHandles(resolution_maps.begin(), resolution_maps.end()),
factory()->then_string(), AccessMode::kLoad, &access_info)) { factory()->then_string(), AccessMode::kLoad, &access_info)) {
...@@ -625,7 +626,7 @@ Reduction JSNativeContextSpecialization::ReduceGlobalAccess( ...@@ -625,7 +626,7 @@ Reduction JSNativeContextSpecialization::ReduceGlobalAccess(
Handle<HeapObject>::cast(property_cell_value)->map(), Handle<HeapObject>::cast(property_cell_value)->map(),
isolate()); isolate());
property_cell_value_type = property_cell_value_type =
Type::For(isolate(), property_cell_value_map); Type::For(js_heap_broker(), property_cell_value_map);
representation = MachineRepresentation::kTaggedPointer; representation = MachineRepresentation::kTaggedPointer;
// We can only use the property cell value map for map check // We can only use the property cell value map for map check
...@@ -798,8 +799,8 @@ Reduction JSNativeContextSpecialization::ReduceNamedAccess( ...@@ -798,8 +799,8 @@ Reduction JSNativeContextSpecialization::ReduceNamedAccess(
} }
// Compute property access infos for the receiver maps. // Compute property access infos for the receiver maps.
AccessInfoFactory access_info_factory(dependencies(), native_context(), AccessInfoFactory access_info_factory(dependencies(), js_heap_broker(),
graph()->zone()); native_context(), graph()->zone());
ZoneVector<PropertyAccessInfo> access_infos(zone()); ZoneVector<PropertyAccessInfo> access_infos(zone());
if (!access_info_factory.ComputePropertyAccessInfos( if (!access_info_factory.ComputePropertyAccessInfos(
receiver_maps, name, access_mode, &access_infos)) { receiver_maps, name, access_mode, &access_infos)) {
...@@ -1162,8 +1163,8 @@ Reduction JSNativeContextSpecialization::ReduceElementAccess( ...@@ -1162,8 +1163,8 @@ Reduction JSNativeContextSpecialization::ReduceElementAccess(
} else { } else {
// Retrieve the native context from the given {node}. // Retrieve the native context from the given {node}.
// Compute element access infos for the receiver maps. // Compute element access infos for the receiver maps.
AccessInfoFactory access_info_factory(dependencies(), native_context(), AccessInfoFactory access_info_factory(dependencies(), js_heap_broker(),
graph()->zone()); native_context(), graph()->zone());
ZoneVector<ElementAccessInfo> access_infos(zone()); ZoneVector<ElementAccessInfo> access_infos(zone());
if (!access_info_factory.ComputeElementAccessInfos( if (!access_info_factory.ComputeElementAccessInfos(
receiver_maps, access_mode, &access_infos)) { receiver_maps, access_mode, &access_infos)) {
...@@ -2061,8 +2062,8 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreDataPropertyInLiteral( ...@@ -2061,8 +2062,8 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreDataPropertyInLiteral(
Name::cast(nexus.GetFeedbackExtra()->ToStrongHeapObject()), isolate()); Name::cast(nexus.GetFeedbackExtra()->ToStrongHeapObject()), isolate());
PropertyAccessInfo access_info; PropertyAccessInfo access_info;
AccessInfoFactory access_info_factory(dependencies(), native_context(), AccessInfoFactory access_info_factory(dependencies(), js_heap_broker(),
graph()->zone()); native_context(), graph()->zone());
if (!access_info_factory.ComputePropertyAccessInfo( if (!access_info_factory.ComputePropertyAccessInfo(
receiver_map, cached_name, AccessMode::kStoreInLiteral, receiver_map, cached_name, AccessMode::kStoreInLiteral,
&access_info)) { &access_info)) {
......
...@@ -25,6 +25,7 @@ enum class AccessMode; ...@@ -25,6 +25,7 @@ enum class AccessMode;
class CommonOperatorBuilder; class CommonOperatorBuilder;
class ElementAccessInfo; class ElementAccessInfo;
class JSGraph; class JSGraph;
class JSHeapBroker;
class JSOperatorBuilder; class JSOperatorBuilder;
class MachineOperatorBuilder; class MachineOperatorBuilder;
class PropertyAccessInfo; class PropertyAccessInfo;
...@@ -45,7 +46,8 @@ class JSNativeContextSpecialization final : public AdvancedReducer { ...@@ -45,7 +46,8 @@ class JSNativeContextSpecialization final : public AdvancedReducer {
}; };
typedef base::Flags<Flag> Flags; typedef base::Flags<Flag> Flags;
JSNativeContextSpecialization(Editor* editor, JSGraph* jsgraph, Flags flags, JSNativeContextSpecialization(Editor* editor, JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker, Flags flags,
Handle<Context> native_context, Handle<Context> native_context,
CompilationDependencies* dependencies, CompilationDependencies* dependencies,
Zone* zone); Zone* zone);
...@@ -214,6 +216,8 @@ class JSNativeContextSpecialization final : public AdvancedReducer { ...@@ -214,6 +216,8 @@ class JSNativeContextSpecialization final : public AdvancedReducer {
Graph* graph() const; Graph* graph() const;
JSGraph* jsgraph() const { return jsgraph_; } JSGraph* jsgraph() const { return jsgraph_; }
const JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
Isolate* isolate() const; Isolate* isolate() const;
Factory* factory() const; Factory* factory() const;
CommonOperatorBuilder* common() const; CommonOperatorBuilder* common() const;
...@@ -227,6 +231,7 @@ class JSNativeContextSpecialization final : public AdvancedReducer { ...@@ -227,6 +231,7 @@ class JSNativeContextSpecialization final : public AdvancedReducer {
Zone* zone() const { return zone_; } Zone* zone() const { return zone_; }
JSGraph* const jsgraph_; JSGraph* const jsgraph_;
const JSHeapBroker* const js_heap_broker_;
Flags const flags_; Flags const flags_;
Handle<JSGlobalObject> global_object_; Handle<JSGlobalObject> global_object_;
Handle<JSGlobalProxy> global_proxy_; Handle<JSGlobalProxy> global_proxy_;
......
...@@ -405,11 +405,12 @@ class JSBinopReduction final { ...@@ -405,11 +405,12 @@ class JSBinopReduction final {
// - immediately put in type bounds for all new nodes // - immediately put in type bounds for all new nodes
// - relax effects from generic but not-side-effecting operations // - relax effects from generic but not-side-effecting operations
JSTypedLowering::JSTypedLowering(Editor* editor, JSGraph* jsgraph, Zone* zone) JSTypedLowering::JSTypedLowering(Editor* editor, JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker, Zone* zone)
: AdvancedReducer(editor), : AdvancedReducer(editor),
jsgraph_(jsgraph), jsgraph_(jsgraph),
empty_string_type_(Type::HeapConstant( empty_string_type_(Type::HeapConstant(
isolate(), factory()->empty_string(), graph()->zone())), js_heap_broker, factory()->empty_string(), graph()->zone())),
pointer_comparable_type_( pointer_comparable_type_(
Type::Union(Type::Oddball(), Type::Union(Type::Oddball(),
Type::Union(Type::SymbolOrReceiver(), empty_string_type_, Type::Union(Type::SymbolOrReceiver(), empty_string_type_,
......
...@@ -31,7 +31,8 @@ enum Signedness { kSigned, kUnsigned }; ...@@ -31,7 +31,8 @@ enum Signedness { kSigned, kUnsigned };
class V8_EXPORT_PRIVATE JSTypedLowering final class V8_EXPORT_PRIVATE JSTypedLowering final
: public NON_EXPORTED_BASE(AdvancedReducer) { : public NON_EXPORTED_BASE(AdvancedReducer) {
public: public:
JSTypedLowering(Editor* editor, JSGraph* jsgraph, Zone* zone); JSTypedLowering(Editor* editor, JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker, Zone* zone);
~JSTypedLowering() final {} ~JSTypedLowering() final {}
const char* reducer_name() const override { return "JSTypedLowering"; } const char* reducer_name() const override { return "JSTypedLowering"; }
......
...@@ -16,25 +16,29 @@ namespace v8 { ...@@ -16,25 +16,29 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
OperationTyper::OperationTyper(Isolate* isolate, Zone* zone) OperationTyper::OperationTyper(Isolate* isolate,
const JSHeapBroker* js_heap_broker, Zone* zone)
: zone_(zone), cache_(TypeCache::Get()) { : zone_(zone), cache_(TypeCache::Get()) {
Factory* factory = isolate->factory(); Factory* factory = isolate->factory();
infinity_ = Type::NewConstant(isolate, factory->infinity_value(), zone); infinity_ =
Type::NewConstant(js_heap_broker, factory->infinity_value(), zone);
minus_infinity_ = minus_infinity_ =
Type::NewConstant(isolate, factory->minus_infinity_value(), zone); Type::NewConstant(js_heap_broker, factory->minus_infinity_value(), zone);
Type truncating_to_zero = Type::MinusZeroOrNaN(); Type truncating_to_zero = Type::MinusZeroOrNaN();
DCHECK(!truncating_to_zero.Maybe(Type::Integral32())); DCHECK(!truncating_to_zero.Maybe(Type::Integral32()));
singleton_empty_string_ = singleton_empty_string_ =
Type::HeapConstant(isolate, factory->empty_string(), zone); Type::HeapConstant(js_heap_broker, factory->empty_string(), zone);
singleton_NaN_string_ = singleton_NaN_string_ =
Type::HeapConstant(isolate, factory->NaN_string(), zone); Type::HeapConstant(js_heap_broker, factory->NaN_string(), zone);
singleton_zero_string_ = singleton_zero_string_ =
Type::HeapConstant(isolate, factory->zero_string(), zone); Type::HeapConstant(js_heap_broker, factory->zero_string(), zone);
singleton_false_ = Type::HeapConstant(isolate, factory->false_value(), zone); singleton_false_ =
singleton_true_ = Type::HeapConstant(isolate, factory->true_value(), zone); Type::HeapConstant(js_heap_broker, factory->false_value(), zone);
singleton_true_ =
Type::HeapConstant(js_heap_broker, factory->true_value(), zone);
singleton_the_hole_ = singleton_the_hole_ =
Type::HeapConstant(isolate, factory->the_hole_value(), zone); Type::HeapConstant(js_heap_broker, factory->the_hole_value(), zone);
signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone); signed32ish_ = Type::Union(Type::Signed32(), truncating_to_zero, zone);
unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone); unsigned32ish_ = Type::Union(Type::Unsigned32(), truncating_to_zero, zone);
......
...@@ -27,7 +27,8 @@ class TypeCache; ...@@ -27,7 +27,8 @@ class TypeCache;
class V8_EXPORT_PRIVATE OperationTyper { class V8_EXPORT_PRIVATE OperationTyper {
public: public:
OperationTyper(Isolate* isolate, Zone* zone); OperationTyper(Isolate* isolate, const JSHeapBroker* js_heap_broker,
Zone* zone);
// Typing Phi. // Typing Phi.
Type Merge(Type left, Type right); Type Merge(Type left, Type right);
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "src/compiler/js-context-specialization.h" #include "src/compiler/js-context-specialization.h"
#include "src/compiler/js-create-lowering.h" #include "src/compiler/js-create-lowering.h"
#include "src/compiler/js-generic-lowering.h" #include "src/compiler/js-generic-lowering.h"
#include "src/compiler/js-heap-broker.h"
#include "src/compiler/js-inlining-heuristic.h" #include "src/compiler/js-inlining-heuristic.h"
#include "src/compiler/js-intrinsic-lowering.h" #include "src/compiler/js-intrinsic-lowering.h"
#include "src/compiler/js-native-context-specialization.h" #include "src/compiler/js-native-context-specialization.h"
...@@ -130,6 +131,7 @@ class PipelineData { ...@@ -130,6 +131,7 @@ class PipelineData {
javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_); javascript_ = new (graph_zone_) JSOperatorBuilder(graph_zone_);
jsgraph_ = new (graph_zone_) jsgraph_ = new (graph_zone_)
JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_); JSGraph(isolate_, graph_, common_, javascript_, simplified_, machine_);
js_heap_broker_ = new (graph_zone_) JSHeapBroker(isolate_);
} }
// For WebAssembly compile entry point. // For WebAssembly compile entry point.
...@@ -246,6 +248,8 @@ class PipelineData { ...@@ -246,6 +248,8 @@ class PipelineData {
return handle(info()->global_object(), isolate()); return handle(info()->global_object(), isolate());
} }
JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
Schedule* schedule() const { return schedule_; } Schedule* schedule() const { return schedule_; }
void set_schedule(Schedule* schedule) { void set_schedule(Schedule* schedule) {
DCHECK(!schedule_); DCHECK(!schedule_);
...@@ -416,6 +420,7 @@ class PipelineData { ...@@ -416,6 +420,7 @@ class PipelineData {
JSGraph* jsgraph_ = nullptr; JSGraph* jsgraph_ = nullptr;
MachineGraph* mcgraph_ = nullptr; MachineGraph* mcgraph_ = nullptr;
Schedule* schedule_ = nullptr; Schedule* schedule_ = nullptr;
JSHeapBroker* js_heap_broker_ = nullptr;
// All objects in the following group of fields are allocated in // All objects in the following group of fields are allocated in
// instruction_zone_. They are all set to nullptr when the instruction_zone_ // instruction_zone_. They are all set to nullptr when the instruction_zone_
...@@ -1160,8 +1165,8 @@ struct InliningPhase { ...@@ -1160,8 +1165,8 @@ struct InliningPhase {
flags |= JSNativeContextSpecialization::kBailoutOnUninitialized; flags |= JSNativeContextSpecialization::kBailoutOnUninitialized;
} }
JSNativeContextSpecialization native_context_specialization( JSNativeContextSpecialization native_context_specialization(
&graph_reducer, data->jsgraph(), flags, data->native_context(), &graph_reducer, data->jsgraph(), data->js_heap_broker(), flags,
data->info()->dependencies(), temp_zone); data->native_context(), data->info()->dependencies(), temp_zone);
JSInliningHeuristic inlining( JSInliningHeuristic inlining(
&graph_reducer, data->info()->is_inlining_enabled() &graph_reducer, data->info()->is_inlining_enabled()
? JSInliningHeuristic::kGeneralInlining ? JSInliningHeuristic::kGeneralInlining
...@@ -1234,12 +1239,14 @@ struct TypedLoweringPhase { ...@@ -1234,12 +1239,14 @@ struct TypedLoweringPhase {
data->common(), temp_zone); data->common(), temp_zone);
JSCreateLowering create_lowering( JSCreateLowering create_lowering(
&graph_reducer, data->info()->dependencies(), data->jsgraph(), &graph_reducer, data->info()->dependencies(), data->jsgraph(),
data->native_context(), temp_zone); data->js_heap_broker(), data->native_context(), temp_zone);
JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(), temp_zone); JSTypedLowering typed_lowering(&graph_reducer, data->jsgraph(),
data->js_heap_broker(), temp_zone);
ConstantFoldingReducer constant_folding_reducer(&graph_reducer, ConstantFoldingReducer constant_folding_reducer(&graph_reducer,
data->jsgraph()); data->jsgraph());
TypedOptimization typed_optimization( TypedOptimization typed_optimization(
&graph_reducer, data->info()->dependencies(), data->jsgraph()); &graph_reducer, data->info()->dependencies(), data->jsgraph(),
data->js_heap_broker());
SimplifiedOperatorReducer simple_reducer(&graph_reducer, data->jsgraph()); SimplifiedOperatorReducer simple_reducer(&graph_reducer, data->jsgraph());
CheckpointElimination checkpoint_elimination(&graph_reducer); CheckpointElimination checkpoint_elimination(&graph_reducer);
CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer, CommonOperatorReducer common_reducer(data->isolate(), &graph_reducer,
...@@ -1279,8 +1286,9 @@ struct SimplifiedLoweringPhase { ...@@ -1279,8 +1286,9 @@ struct SimplifiedLoweringPhase {
static const char* phase_name() { return "simplified lowering"; } static const char* phase_name() { return "simplified lowering"; }
void Run(PipelineData* data, Zone* temp_zone) { void Run(PipelineData* data, Zone* temp_zone) {
SimplifiedLowering lowering(data->jsgraph(), temp_zone, SimplifiedLowering lowering(data->jsgraph(), data->js_heap_broker(),
data->source_positions(), data->node_origins(), temp_zone, data->source_positions(),
data->node_origins(),
data->info()->GetPoisoningMitigationLevel()); data->info()->GetPoisoningMitigationLevel());
lowering.LowerAllNodes(); lowering.LowerAllNodes();
} }
...@@ -1326,12 +1334,12 @@ struct ConcurrentOptimizationPrepPhase { ...@@ -1326,12 +1334,12 @@ struct ConcurrentOptimizationPrepPhase {
// This is needed for escape analysis. // This is needed for escape analysis.
NodeProperties::SetType( NodeProperties::SetType(
data->jsgraph()->FalseConstant(), data->jsgraph()->FalseConstant(),
Type::HeapConstant(data->isolate(), Type::HeapConstant(data->js_heap_broker(),
data->isolate()->factory()->false_value(), data->isolate()->factory()->false_value(),
data->jsgraph()->zone())); data->jsgraph()->zone()));
NodeProperties::SetType( NodeProperties::SetType(
data->jsgraph()->TrueConstant(), data->jsgraph()->TrueConstant(),
Type::HeapConstant(data->isolate(), Type::HeapConstant(data->js_heap_broker(),
data->isolate()->factory()->true_value(), data->isolate()->factory()->true_value(),
data->jsgraph()->zone())); data->jsgraph()->zone()));
} }
...@@ -1475,8 +1483,8 @@ struct LoadEliminationPhase { ...@@ -1475,8 +1483,8 @@ struct LoadEliminationPhase {
data->machine(), temp_zone); data->machine(), temp_zone);
ConstantFoldingReducer constant_folding_reducer(&graph_reducer, ConstantFoldingReducer constant_folding_reducer(&graph_reducer,
data->jsgraph()); data->jsgraph());
TypeNarrowingReducer type_narrowing_reducer(&graph_reducer, TypeNarrowingReducer type_narrowing_reducer(&graph_reducer, data->jsgraph(),
data->jsgraph()); data->js_heap_broker());
AddReducer(data, &graph_reducer, &branch_condition_elimination); AddReducer(data, &graph_reducer, &branch_condition_elimination);
AddReducer(data, &graph_reducer, &dead_code_elimination); AddReducer(data, &graph_reducer, &dead_code_elimination);
AddReducer(data, &graph_reducer, &redundancy_elimination); AddReducer(data, &graph_reducer, &redundancy_elimination);
...@@ -1909,7 +1917,7 @@ bool PipelineImpl::CreateGraph() { ...@@ -1909,7 +1917,7 @@ bool PipelineImpl::CreateGraph() {
// Type the graph and keep the Typer running on newly created nodes within // Type the graph and keep the Typer running on newly created nodes within
// this scope; the Typer is automatically unlinked from the Graph once we // this scope; the Typer is automatically unlinked from the Graph once we
// leave this scope below. // leave this scope below.
Typer typer(isolate(), flags, data->graph()); Typer typer(isolate(), data->js_heap_broker(), flags, data->graph());
Run<TyperPhase>(&typer); Run<TyperPhase>(&typer);
RunPrintAndVerify(TyperPhase::phase_name()); RunPrintAndVerify(TyperPhase::phase_name());
......
...@@ -286,8 +286,8 @@ class RepresentationSelector { ...@@ -286,8 +286,8 @@ class RepresentationSelector {
bool weakened_ = false; bool weakened_ = false;
}; };
RepresentationSelector(JSGraph* jsgraph, Zone* zone, RepresentationSelector(JSGraph* jsgraph, const JSHeapBroker* js_heap_broker,
RepresentationChanger* changer, Zone* zone, RepresentationChanger* changer,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
NodeOriginTable* node_origins) NodeOriginTable* node_origins)
: jsgraph_(jsgraph), : jsgraph_(jsgraph),
...@@ -306,7 +306,7 @@ class RepresentationSelector { ...@@ -306,7 +306,7 @@ class RepresentationSelector {
source_positions_(source_positions), source_positions_(source_positions),
node_origins_(node_origins), node_origins_(node_origins),
type_cache_(TypeCache::Get()), type_cache_(TypeCache::Get()),
op_typer_(jsgraph->isolate(), graph_zone()) { op_typer_(jsgraph->isolate(), js_heap_broker, graph_zone()) {
} }
// Forward propagation of types from type feedback. // Forward propagation of types from type feedback.
...@@ -3252,11 +3252,14 @@ class RepresentationSelector { ...@@ -3252,11 +3252,14 @@ class RepresentationSelector {
Zone* graph_zone() { return jsgraph_->zone(); } Zone* graph_zone() { return jsgraph_->zone(); }
}; };
SimplifiedLowering::SimplifiedLowering(JSGraph* jsgraph, Zone* zone, SimplifiedLowering::SimplifiedLowering(JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker,
Zone* zone,
SourcePositionTable* source_positions, SourcePositionTable* source_positions,
NodeOriginTable* node_origins, NodeOriginTable* node_origins,
PoisoningMitigationLevel poisoning_level) PoisoningMitigationLevel poisoning_level)
: jsgraph_(jsgraph), : jsgraph_(jsgraph),
js_heap_broker_(js_heap_broker),
zone_(zone), zone_(zone),
type_cache_(TypeCache::Get()), type_cache_(TypeCache::Get()),
source_positions_(source_positions), source_positions_(source_positions),
...@@ -3265,8 +3268,8 @@ SimplifiedLowering::SimplifiedLowering(JSGraph* jsgraph, Zone* zone, ...@@ -3265,8 +3268,8 @@ SimplifiedLowering::SimplifiedLowering(JSGraph* jsgraph, Zone* zone,
void SimplifiedLowering::LowerAllNodes() { void SimplifiedLowering::LowerAllNodes() {
RepresentationChanger changer(jsgraph(), jsgraph()->isolate()); RepresentationChanger changer(jsgraph(), jsgraph()->isolate());
RepresentationSelector selector(jsgraph(), zone_, &changer, source_positions_, RepresentationSelector selector(jsgraph(), js_heap_broker_, zone_, &changer,
node_origins_); source_positions_, node_origins_);
selector.Run(this); selector.Run(this);
} }
......
...@@ -23,8 +23,8 @@ class TypeCache; ...@@ -23,8 +23,8 @@ class TypeCache;
class V8_EXPORT_PRIVATE SimplifiedLowering final { class V8_EXPORT_PRIVATE SimplifiedLowering final {
public: public:
SimplifiedLowering(JSGraph* jsgraph, Zone* zone, SimplifiedLowering(JSGraph* jsgraph, const JSHeapBroker* js_heap_broker,
SourcePositionTable* source_position, Zone* zone, SourcePositionTable* source_position,
NodeOriginTable* node_origins, NodeOriginTable* node_origins,
PoisoningMitigationLevel poisoning_level); PoisoningMitigationLevel poisoning_level);
~SimplifiedLowering() {} ~SimplifiedLowering() {}
...@@ -48,6 +48,7 @@ class V8_EXPORT_PRIVATE SimplifiedLowering final { ...@@ -48,6 +48,7 @@ class V8_EXPORT_PRIVATE SimplifiedLowering final {
private: private:
JSGraph* const jsgraph_; JSGraph* const jsgraph_;
const JSHeapBroker* js_heap_broker_;
Zone* const zone_; Zone* const zone_;
TypeCache const& type_cache_; TypeCache const& type_cache_;
SetOncePointer<Node> to_number_code_; SetOncePointer<Node> to_number_code_;
......
...@@ -11,10 +11,11 @@ namespace v8 { ...@@ -11,10 +11,11 @@ namespace v8 {
namespace internal { namespace internal {
namespace compiler { namespace compiler {
TypeNarrowingReducer::TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph) TypeNarrowingReducer::TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker)
: AdvancedReducer(editor), : AdvancedReducer(editor),
jsgraph_(jsgraph), jsgraph_(jsgraph),
op_typer_(jsgraph->isolate(), zone()) {} op_typer_(jsgraph->isolate(), js_heap_broker, zone()) {}
TypeNarrowingReducer::~TypeNarrowingReducer() {} TypeNarrowingReducer::~TypeNarrowingReducer() {}
...@@ -29,13 +30,10 @@ Reduction TypeNarrowingReducer::Reduce(Node* node) { ...@@ -29,13 +30,10 @@ Reduction TypeNarrowingReducer::Reduce(Node* node) {
Type right_type = NodeProperties::GetType(node->InputAt(1)); Type right_type = NodeProperties::GetType(node->InputAt(1));
if (left_type.Is(Type::PlainNumber()) && if (left_type.Is(Type::PlainNumber()) &&
right_type.Is(Type::PlainNumber())) { right_type.Is(Type::PlainNumber())) {
Factory* const factory = jsgraph()->isolate()->factory();
if (left_type.Max() < right_type.Min()) { if (left_type.Max() < right_type.Min()) {
new_type = Type::HeapConstant(jsgraph()->isolate(), new_type = op_typer_.singleton_true();
factory->true_value(), zone());
} else if (left_type.Min() >= right_type.Max()) { } else if (left_type.Min() >= right_type.Max()) {
new_type = Type::HeapConstant(jsgraph()->isolate(), new_type = op_typer_.singleton_false();
factory->false_value(), zone());
} }
} }
break; break;
......
...@@ -19,7 +19,8 @@ class JSGraph; ...@@ -19,7 +19,8 @@ class JSGraph;
class V8_EXPORT_PRIVATE TypeNarrowingReducer final class V8_EXPORT_PRIVATE TypeNarrowingReducer final
: public NON_EXPORTED_BASE(AdvancedReducer) { : public NON_EXPORTED_BASE(AdvancedReducer) {
public: public:
TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph); TypeNarrowingReducer(Editor* editor, JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker);
~TypeNarrowingReducer() final; ~TypeNarrowingReducer() final;
const char* reducer_name() const override { return "TypeNarrowingReducer"; } const char* reducer_name() const override { return "TypeNarrowingReducer"; }
......
...@@ -18,14 +18,15 @@ namespace compiler { ...@@ -18,14 +18,15 @@ namespace compiler {
TypedOptimization::TypedOptimization(Editor* editor, TypedOptimization::TypedOptimization(Editor* editor,
CompilationDependencies* dependencies, CompilationDependencies* dependencies,
JSGraph* jsgraph) JSGraph* jsgraph,
const JSHeapBroker* js_heap_broker)
: AdvancedReducer(editor), : AdvancedReducer(editor),
dependencies_(dependencies), dependencies_(dependencies),
jsgraph_(jsgraph), jsgraph_(jsgraph),
true_type_(Type::HeapConstant(jsgraph->isolate(), factory()->true_value(), true_type_(Type::HeapConstant(js_heap_broker, factory()->true_value(),
graph()->zone())), graph()->zone())),
false_type_(Type::HeapConstant( false_type_(Type::HeapConstant(js_heap_broker, factory()->false_value(),
jsgraph->isolate(), factory()->false_value(), graph()->zone())), graph()->zone())),
type_cache_(TypeCache::Get()) {} type_cache_(TypeCache::Get()) {}
TypedOptimization::~TypedOptimization() {} TypedOptimization::~TypedOptimization() {}
......
...@@ -28,7 +28,7 @@ class V8_EXPORT_PRIVATE TypedOptimization final ...@@ -28,7 +28,7 @@ class V8_EXPORT_PRIVATE TypedOptimization final
: public NON_EXPORTED_BASE(AdvancedReducer) { : public NON_EXPORTED_BASE(AdvancedReducer) {
public: public:
TypedOptimization(Editor* editor, CompilationDependencies* dependencies, TypedOptimization(Editor* editor, CompilationDependencies* dependencies,
JSGraph* jsgraph); JSGraph* jsgraph, const JSHeapBroker* js_heap_broker);
~TypedOptimization(); ~TypedOptimization();
const char* reducer_name() const override { return "TypedOptimization"; } const char* reducer_name() const override { return "TypedOptimization"; }
......
...@@ -33,13 +33,14 @@ class Typer::Decorator final : public GraphDecorator { ...@@ -33,13 +33,14 @@ class Typer::Decorator final : public GraphDecorator {
Typer* const typer_; Typer* const typer_;
}; };
Typer::Typer(Isolate* isolate, Flags flags, Graph* graph) Typer::Typer(Isolate* isolate, const JSHeapBroker* js_heap_broker, Flags flags,
: isolate_(isolate), Graph* graph)
flags_(flags), : flags_(flags),
graph_(graph), graph_(graph),
decorator_(nullptr), decorator_(nullptr),
cache_(TypeCache::Get()), cache_(TypeCache::Get()),
operation_typer_(isolate, zone()) { js_heap_broker_(js_heap_broker),
operation_typer_(isolate, js_heap_broker, zone()) {
singleton_false_ = operation_typer_.singleton_false(); singleton_false_ = operation_typer_.singleton_false();
singleton_true_ = operation_typer_.singleton_true(); singleton_true_ = operation_typer_.singleton_true();
...@@ -227,7 +228,6 @@ class Typer::Visitor : public Reducer { ...@@ -227,7 +228,6 @@ class Typer::Visitor : public Reducer {
Type Weaken(Node* node, Type current_type, Type previous_type); Type Weaken(Node* node, Type current_type, Type previous_type);
Zone* zone() { return typer_->zone(); } Zone* zone() { return typer_->zone(); }
Isolate* isolate() { return typer_->isolate(); }
Graph* graph() { return typer_->graph(); } Graph* graph() { return typer_->graph(); }
void SetWeakened(NodeId node_id) { weakened_nodes_.insert(node_id); } void SetWeakened(NodeId node_id) { weakened_nodes_.insert(node_id); }
...@@ -2178,7 +2178,7 @@ Type Typer::Visitor::TypeRuntimeAbort(Node* node) { UNREACHABLE(); } ...@@ -2178,7 +2178,7 @@ Type Typer::Visitor::TypeRuntimeAbort(Node* node) { UNREACHABLE(); }
// Heap constants. // Heap constants.
Type Typer::Visitor::TypeConstant(Handle<Object> value) { Type Typer::Visitor::TypeConstant(Handle<Object> value) {
return Type::NewConstant(isolate(), value, zone()); return Type::NewConstant(typer_->js_heap_broker(), value, zone());
} }
} // namespace compiler } // namespace compiler
......
...@@ -25,7 +25,8 @@ class V8_EXPORT_PRIVATE Typer { ...@@ -25,7 +25,8 @@ class V8_EXPORT_PRIVATE Typer {
}; };
typedef base::Flags<Flag> Flags; typedef base::Flags<Flag> Flags;
Typer(Isolate* isolate, Flags flags, Graph* graph); Typer(Isolate* isolate, const JSHeapBroker* js_heap_broker, Flags flags,
Graph* graph);
~Typer(); ~Typer();
void Run(); void Run();
...@@ -40,14 +41,14 @@ class V8_EXPORT_PRIVATE Typer { ...@@ -40,14 +41,14 @@ class V8_EXPORT_PRIVATE Typer {
Flags flags() const { return flags_; } Flags flags() const { return flags_; }
Graph* graph() const { return graph_; } Graph* graph() const { return graph_; }
Zone* zone() const { return graph()->zone(); } Zone* zone() const { return graph()->zone(); }
Isolate* isolate() const { return isolate_; }
OperationTyper* operation_typer() { return &operation_typer_; } OperationTyper* operation_typer() { return &operation_typer_; }
const JSHeapBroker* js_heap_broker() const { return js_heap_broker_; }
Isolate* const isolate_;
Flags const flags_; Flags const flags_;
Graph* const graph_; Graph* const graph_;
Decorator* decorator_; Decorator* decorator_;
TypeCache const& cache_; TypeCache const& cache_;
const JSHeapBroker* js_heap_broker_;
OperationTyper operation_typer_; OperationTyper operation_typer_;
Type singleton_false_; Type singleton_false_;
......
...@@ -132,10 +132,8 @@ Type::bitset Type::BitsetLub() const { ...@@ -132,10 +132,8 @@ Type::bitset Type::BitsetLub() const {
UNREACHABLE(); UNREACHABLE();
} }
Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) { Type::bitset BitsetType::Lub(HeapReferenceType const& type) {
DisallowHeapAllocation no_allocation; switch (type.instance_type()) {
Heap* heap = isolate->heap();
switch (map->instance_type()) {
case CONS_STRING_TYPE: case CONS_STRING_TYPE:
case CONS_ONE_BYTE_STRING_TYPE: case CONS_ONE_BYTE_STRING_TYPE:
case THIN_STRING_TYPE: case THIN_STRING_TYPE:
...@@ -165,16 +163,19 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) { ...@@ -165,16 +163,19 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) {
case BIGINT_TYPE: case BIGINT_TYPE:
return kBigInt; return kBigInt;
case ODDBALL_TYPE: { case ODDBALL_TYPE: {
if (map == heap->undefined_map()) return kUndefined; switch (type.oddball_type()) {
if (map == heap->null_map()) return kNull; case HeapReferenceType::kHole:
if (map == heap->boolean_map()) return kBoolean; return kHole;
if (map == heap->the_hole_map()) return kHole; case HeapReferenceType::kBoolean:
DCHECK(map == heap->uninitialized_map() || return kBoolean;
map == heap->termination_exception_map() || case HeapReferenceType::kNull:
map == heap->arguments_marker_map() || return kNull;
map == heap->optimized_out_map() || case HeapReferenceType::kUndefined:
map == heap->stale_register_map()); return kUndefined;
return kOtherInternal; case HeapReferenceType::kUnknown:
return kOtherInternal;
}
UNREACHABLE();
} }
case HEAP_NUMBER_TYPE: case HEAP_NUMBER_TYPE:
return kNumber; return kNumber;
...@@ -185,15 +186,15 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) { ...@@ -185,15 +186,15 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) {
case JS_GLOBAL_PROXY_TYPE: case JS_GLOBAL_PROXY_TYPE:
case JS_API_OBJECT_TYPE: case JS_API_OBJECT_TYPE:
case JS_SPECIAL_API_OBJECT_TYPE: case JS_SPECIAL_API_OBJECT_TYPE:
if (map->is_undetectable()) { if (type.is_undetectable()) {
// Currently we assume that every undetectable receiver is also // Currently we assume that every undetectable receiver is also
// callable, which is what we need to support document.all. We // callable, which is what we need to support document.all. We
// could add another Type bit to support other use cases in the // could add another Type bit to support other use cases in the
// future if necessary. // future if necessary.
DCHECK(map->is_callable()); DCHECK(type.is_callable());
return kOtherUndetectable; return kOtherUndetectable;
} }
if (map->is_callable()) { if (type.is_callable()) {
return kOtherCallable; return kOtherCallable;
} }
return kOtherObject; return kOtherObject;
...@@ -232,18 +233,18 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) { ...@@ -232,18 +233,18 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) {
case WASM_INSTANCE_TYPE: case WASM_INSTANCE_TYPE:
case WASM_MEMORY_TYPE: case WASM_MEMORY_TYPE:
case WASM_TABLE_TYPE: case WASM_TABLE_TYPE:
DCHECK(!map->is_callable()); DCHECK(!type.is_callable());
DCHECK(!map->is_undetectable()); DCHECK(!type.is_undetectable());
return kOtherObject; return kOtherObject;
case JS_BOUND_FUNCTION_TYPE: case JS_BOUND_FUNCTION_TYPE:
DCHECK(!map->is_undetectable()); DCHECK(!type.is_undetectable());
return kBoundFunction; return kBoundFunction;
case JS_FUNCTION_TYPE: case JS_FUNCTION_TYPE:
DCHECK(!map->is_undetectable()); DCHECK(!type.is_undetectable());
return kFunction; return kFunction;
case JS_PROXY_TYPE: case JS_PROXY_TYPE:
DCHECK(!map->is_undetectable()); DCHECK(!type.is_undetectable());
if (map->is_callable()) return kCallableProxy; if (type.is_callable()) return kCallableProxy;
return kOtherProxy; return kOtherProxy;
case MAP_TYPE: case MAP_TYPE:
case ALLOCATION_SITE_TYPE: case ALLOCATION_SITE_TYPE:
...@@ -329,12 +330,13 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) { ...@@ -329,12 +330,13 @@ Type::bitset BitsetType::Lub(Isolate* isolate, i::Map* map) {
UNREACHABLE(); UNREACHABLE();
} }
Type::bitset BitsetType::Lub(Isolate* isolate, i::Object* value) { Type::bitset BitsetType::Lub(const JSHeapBroker* js_heap_broker,
Handle<HeapObject> value) {
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
if (value->IsNumber()) { if (value->IsNumber()) {
return Lub(value->Number()); return Lub(value->Number());
} }
return Lub(isolate, i::HeapObject::cast(value)->map()); return Lub(js_heap_broker->HeapReferenceTypeForObject(value));
} }
Type::bitset BitsetType::Lub(double value) { Type::bitset BitsetType::Lub(double value) {
...@@ -811,14 +813,14 @@ Type Type::NewConstant(double value, Zone* zone) { ...@@ -811,14 +813,14 @@ Type Type::NewConstant(double value, Zone* zone) {
return OtherNumberConstant(value, zone); return OtherNumberConstant(value, zone);
} }
Type Type::NewConstant(Isolate* isolate, i::Handle<i::Object> value, Type Type::NewConstant(const JSHeapBroker* js_heap_broker,
Zone* zone) { Handle<i::Object> value, Zone* zone) {
if (value->IsNumber()) { if (value->IsNumber()) {
return NewConstant(value->Number(), zone); return NewConstant(value->Number(), zone);
} else if (value->IsString() && !value->IsInternalizedString()) { } else if (value->IsString() && !value->IsInternalizedString()) {
return Type::String(); return Type::String();
} }
return HeapConstant(isolate, i::Handle<i::HeapObject>::cast(value), zone); return HeapConstant(js_heap_broker, Handle<HeapObject>::cast(value), zone);
} }
Type Type::Union(Type type1, Type type2, Zone* zone) { Type Type::Union(Type type1, Type type2, Zone* zone) {
...@@ -1044,9 +1046,9 @@ Type Type::OtherNumberConstant(double value, Zone* zone) { ...@@ -1044,9 +1046,9 @@ Type Type::OtherNumberConstant(double value, Zone* zone) {
} }
// static // static
Type Type::HeapConstant(Isolate* isolate, i::Handle<i::HeapObject> value, Type Type::HeapConstant(const JSHeapBroker* js_heap_broker,
Zone* zone) { Handle<HeapObject> value, Zone* zone) {
return FromTypeBase(HeapConstantType::New(isolate, value, zone)); return FromTypeBase(HeapConstantType::New(js_heap_broker, value, zone));
} }
// static // static
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#define V8_COMPILER_TYPES_H_ #define V8_COMPILER_TYPES_H_
#include "src/base/compiler-specific.h" #include "src/base/compiler-specific.h"
#include "src/compiler/js-heap-broker.h"
#include "src/conversions.h" #include "src/conversions.h"
#include "src/globals.h" #include "src/globals.h"
#include "src/handles.h" #include "src/handles.h"
...@@ -250,8 +251,9 @@ class V8_EXPORT_PRIVATE BitsetType { ...@@ -250,8 +251,9 @@ class V8_EXPORT_PRIVATE BitsetType {
static double Max(bitset); static double Max(bitset);
static bitset Glb(double min, double max); static bitset Glb(double min, double max);
static bitset Lub(Isolate* isolate, i::Map* map); static bitset Lub(HeapReferenceType const& type);
static bitset Lub(Isolate* isolate, i::Object* value); static bitset Lub(const JSHeapBroker* js_heap_broker,
Handle<HeapObject> value);
static bitset Lub(double value); static bitset Lub(double value);
static bitset Lub(double min, double max); static bitset Lub(double min, double max);
static bitset ExpandInternals(bitset bits); static bitset ExpandInternals(bitset bits);
...@@ -361,27 +363,24 @@ class V8_EXPORT_PRIVATE Type { ...@@ -361,27 +363,24 @@ class V8_EXPORT_PRIVATE Type {
static Type UnsignedSmall() { return NewBitset(BitsetType::UnsignedSmall()); } static Type UnsignedSmall() { return NewBitset(BitsetType::UnsignedSmall()); }
static Type OtherNumberConstant(double value, Zone* zone); static Type OtherNumberConstant(double value, Zone* zone);
static Type HeapConstant(Isolate* isolate, i::Handle<i::HeapObject> value, static Type HeapConstant(const JSHeapBroker* js_heap_broker,
Zone* zone); Handle<HeapObject> value, Zone* zone);
static Type Range(double min, double max, Zone* zone); static Type Range(double min, double max, Zone* zone);
static Type Range(RangeType::Limits lims, Zone* zone); static Type Range(RangeType::Limits lims, Zone* zone);
static Type Tuple(Type first, Type second, Type third, Zone* zone); static Type Tuple(Type first, Type second, Type third, Zone* zone);
static Type Union(int length, Zone* zone); static Type Union(int length, Zone* zone);
// NewConstant is a factory that returns Constant, Range or Number. // NewConstant is a factory that returns Constant, Range or Number.
static Type NewConstant(Isolate* isolate, i::Handle<i::Object> value, static Type NewConstant(const JSHeapBroker* js_heap_broker,
Zone* zone); Handle<i::Object> value, Zone* zone);
static Type NewConstant(double value, Zone* zone); static Type NewConstant(double value, Zone* zone);
static Type Union(Type type1, Type type2, Zone* zone); static Type Union(Type type1, Type type2, Zone* zone);
static Type Intersect(Type type1, Type type2, Zone* zone); static Type Intersect(Type type1, Type type2, Zone* zone);
static Type For(Isolate* isolate, i::Map* map) { static Type For(const JSHeapBroker* js_heap_broker, Handle<i::Map> map) {
return NewBitset( HeapReferenceType type = js_heap_broker->HeapReferenceTypeFromMap(map);
BitsetType::ExpandInternals(BitsetType::Lub(isolate, map))); return NewBitset(BitsetType::ExpandInternals(BitsetType::Lub(type)));
}
static Type For(Isolate* isolate, i::Handle<i::Map> map) {
return For(isolate, *map);
} }
// Predicates. // Predicates.
...@@ -543,9 +542,9 @@ class V8_EXPORT_PRIVATE HeapConstantType : public NON_EXPORTED_BASE(TypeBase) { ...@@ -543,9 +542,9 @@ class V8_EXPORT_PRIVATE HeapConstantType : public NON_EXPORTED_BASE(TypeBase) {
friend class Type; friend class Type;
friend class BitsetType; friend class BitsetType;
static HeapConstantType* New(Isolate* isolate, i::Handle<i::HeapObject> value, static HeapConstantType* New(const JSHeapBroker* js_heap_broker,
Zone* zone) { i::Handle<i::HeapObject> value, Zone* zone) {
BitsetType::bitset bitset = BitsetType::Lub(isolate, *value); BitsetType::bitset bitset = BitsetType::Lub(js_heap_broker, value);
return new (zone->New(sizeof(HeapConstantType))) return new (zone->New(sizeof(HeapConstantType)))
HeapConstantType(bitset, value); HeapConstantType(bitset, value);
} }
......
...@@ -23,6 +23,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope { ...@@ -23,6 +23,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
public: public:
explicit JSTypedLoweringTester(int num_parameters = 0) explicit JSTypedLoweringTester(int num_parameters = 0)
: isolate(main_isolate()), : isolate(main_isolate()),
js_heap_broker(isolate),
binop(nullptr), binop(nullptr),
unop(nullptr), unop(nullptr),
javascript(main_zone()), javascript(main_zone()),
...@@ -30,7 +31,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope { ...@@ -30,7 +31,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
simplified(main_zone()), simplified(main_zone()),
common(main_zone()), common(main_zone()),
graph(main_zone()), graph(main_zone()),
typer(main_isolate(), Typer::kNoFlags, &graph), typer(main_isolate(), &js_heap_broker, Typer::kNoFlags, &graph),
context_node(nullptr) { context_node(nullptr) {
graph.SetStart(graph.NewNode(common.Start(num_parameters))); graph.SetStart(graph.NewNode(common.Start(num_parameters)));
graph.SetEnd(graph.NewNode(common.End(1), graph.start())); graph.SetEnd(graph.NewNode(common.End(1), graph.start()));
...@@ -38,6 +39,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope { ...@@ -38,6 +39,7 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
} }
Isolate* isolate; Isolate* isolate;
JSHeapBroker js_heap_broker;
const Operator* binop; const Operator* binop;
const Operator* unop; const Operator* unop;
JSOperatorBuilder javascript; JSOperatorBuilder javascript;
...@@ -86,7 +88,8 @@ class JSTypedLoweringTester : public HandleAndZoneScope { ...@@ -86,7 +88,8 @@ class JSTypedLoweringTester : public HandleAndZoneScope {
&machine); &machine);
// TODO(titzer): mock the GraphReducer here for better unit testing. // TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(main_zone(), &graph); GraphReducer graph_reducer(main_zone(), &graph);
JSTypedLowering reducer(&graph_reducer, &jsgraph, main_zone()); JSTypedLowering reducer(&graph_reducer, &jsgraph, &js_heap_broker,
main_zone());
Reduction reduction = reducer.Reduce(node); Reduction reduction = reducer.Reduce(node);
if (reduction.Changed()) return reduction.replacement(); if (reduction.Changed()) return reduction.replacement();
return node; return node;
......
...@@ -40,7 +40,7 @@ namespace compiler { ...@@ -40,7 +40,7 @@ namespace compiler {
class Types { class Types {
public: public:
Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng) Types(Zone* zone, Isolate* isolate, v8::base::RandomNumberGenerator* rng)
: zone_(zone), isolate_(isolate), rng_(rng) { : zone_(zone), js_heap_broker_(isolate), rng_(rng) {
#define DECLARE_TYPE(name, value) \ #define DECLARE_TYPE(name, value) \
name = Type::name(); \ name = Type::name(); \
types.push_back(name); types.push_back(name);
...@@ -65,13 +65,14 @@ class Types { ...@@ -65,13 +65,14 @@ class Types {
object2 = isolate->factory()->NewJSObjectFromMap(object_map); object2 = isolate->factory()->NewJSObjectFromMap(object_map);
array = isolate->factory()->NewJSArray(20); array = isolate->factory()->NewJSArray(20);
uninitialized = isolate->factory()->uninitialized_value(); uninitialized = isolate->factory()->uninitialized_value();
SmiConstant = Type::NewConstant(isolate, smi, zone); SmiConstant = Type::NewConstant(js_heap_broker(), smi, zone);
Signed32Constant = Type::NewConstant(isolate, signed32, zone); Signed32Constant = Type::NewConstant(js_heap_broker(), signed32, zone);
ObjectConstant1 = Type::HeapConstant(isolate, object1, zone); ObjectConstant1 = Type::HeapConstant(js_heap_broker(), object1, zone);
ObjectConstant2 = Type::HeapConstant(isolate, object2, zone); ObjectConstant2 = Type::HeapConstant(js_heap_broker(), object2, zone);
ArrayConstant = Type::HeapConstant(isolate, array, zone); ArrayConstant = Type::HeapConstant(js_heap_broker(), array, zone);
UninitializedConstant = Type::HeapConstant(isolate, uninitialized, zone); UninitializedConstant =
Type::HeapConstant(js_heap_broker(), uninitialized, zone);
values.push_back(smi); values.push_back(smi);
values.push_back(boxed_smi); values.push_back(boxed_smi);
...@@ -84,7 +85,7 @@ class Types { ...@@ -84,7 +85,7 @@ class Types {
values.push_back(float2); values.push_back(float2);
values.push_back(float3); values.push_back(float3);
for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) { for (ValueVector::iterator it = values.begin(); it != values.end(); ++it) {
types.push_back(Type::NewConstant(isolate, *it, zone)); types.push_back(Type::NewConstant(js_heap_broker(), *it, zone));
} }
integers.push_back(isolate->factory()->NewNumber(-V8_INFINITY)); integers.push_back(isolate->factory()->NewNumber(-V8_INFINITY));
...@@ -120,7 +121,7 @@ class Types { ...@@ -120,7 +121,7 @@ class Types {
#define DECLARE_TYPE(name, value) Type name; #define DECLARE_TYPE(name, value) Type name;
PROPER_BITSET_TYPE_LIST(DECLARE_TYPE) PROPER_BITSET_TYPE_LIST(DECLARE_TYPE)
#undef DECLARE_TYPE #undef DECLARE_TYPE
Type SignedSmall; Type SignedSmall;
Type UnsignedSmall; Type UnsignedSmall;
...@@ -142,11 +143,11 @@ class Types { ...@@ -142,11 +143,11 @@ class Types {
ValueVector integers; // "Integer" values used for range limits. ValueVector integers; // "Integer" values used for range limits.
Type NewConstant(Handle<i::Object> value) { Type NewConstant(Handle<i::Object> value) {
return Type::NewConstant(isolate_, value, zone_); return Type::NewConstant(js_heap_broker(), value, zone_);
} }
Type HeapConstant(Handle<i::HeapObject> value) { Type HeapConstant(Handle<i::HeapObject> value) {
return Type::HeapConstant(isolate_, value, zone_); return Type::HeapConstant(js_heap_broker(), value, zone_);
} }
Type Range(double min, double max) { return Type::Range(min, max, zone_); } Type Range(double min, double max) { return Type::Range(min, max, zone_); }
...@@ -184,7 +185,7 @@ class Types { ...@@ -184,7 +185,7 @@ class Types {
} }
case 1: { // constant case 1: { // constant
int i = rng_->NextInt(static_cast<int>(values.size())); int i = rng_->NextInt(static_cast<int>(values.size()));
return Type::NewConstant(isolate_, values[i], zone_); return Type::NewConstant(js_heap_broker(), values[i], zone_);
} }
case 2: { // range case 2: { // range
int i = rng_->NextInt(static_cast<int>(integers.size())); int i = rng_->NextInt(static_cast<int>(integers.size()));
...@@ -208,10 +209,11 @@ class Types { ...@@ -208,10 +209,11 @@ class Types {
} }
Zone* zone() { return zone_; } Zone* zone() { return zone_; }
const JSHeapBroker* js_heap_broker() const { return &js_heap_broker_; }
private: private:
Zone* zone_; Zone* zone_;
Isolate* isolate_; JSHeapBroker js_heap_broker_;
v8::base::RandomNumberGenerator* rng_; v8::base::RandomNumberGenerator* rng_;
}; };
......
...@@ -62,7 +62,10 @@ const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0, ...@@ -62,7 +62,10 @@ const double kIntegerValues[] = {-V8_INFINITY, INT_MIN, -1000.0, -42.0,
class ConstantFoldingReducerTest : public TypedGraphTest { class ConstantFoldingReducerTest : public TypedGraphTest {
public: public:
ConstantFoldingReducerTest() ConstantFoldingReducerTest()
: TypedGraphTest(3), simplified_(zone()), deps_(isolate(), zone()) {} : TypedGraphTest(3),
js_heap_broker_(isolate()),
simplified_(zone()),
deps_(isolate(), zone()) {}
~ConstantFoldingReducerTest() override {} ~ConstantFoldingReducerTest() override {}
protected: protected:
...@@ -78,16 +81,18 @@ class ConstantFoldingReducerTest : public TypedGraphTest { ...@@ -78,16 +81,18 @@ class ConstantFoldingReducerTest : public TypedGraphTest {
} }
SimplifiedOperatorBuilder* simplified() { return &simplified_; } SimplifiedOperatorBuilder* simplified() { return &simplified_; }
const JSHeapBroker* js_heap_broker() const { return &js_heap_broker_; }
private: private:
JSHeapBroker js_heap_broker_;
SimplifiedOperatorBuilder simplified_; SimplifiedOperatorBuilder simplified_;
CompilationDependencies deps_; CompilationDependencies deps_;
}; };
TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) { TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) {
{ {
Reduction r = Reduce(Parameter( Reduction r = Reduce(Parameter(Type::NewConstant(
Type::NewConstant(isolate(), factory()->minus_zero_value(), zone()))); js_heap_broker(), factory()->minus_zero_value(), zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0)); EXPECT_THAT(r.replacement(), IsNumberConstant(-0.0));
} }
...@@ -99,7 +104,7 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) { ...@@ -99,7 +104,7 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) {
{ {
Reduction r = Reduce(Parameter(Type::Union( Reduction r = Reduce(Parameter(Type::Union(
Type::MinusZero(), Type::MinusZero(),
Type::NewConstant(isolate(), factory()->NewNumber(0), zone()), Type::NewConstant(js_heap_broker(), factory()->NewNumber(0), zone()),
zone()))); zone())));
EXPECT_FALSE(r.Changed()); EXPECT_FALSE(r.Changed());
} }
...@@ -108,7 +113,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) { ...@@ -108,7 +113,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithMinusZero) {
TEST_F(ConstantFoldingReducerTest, ParameterWithNull) { TEST_F(ConstantFoldingReducerTest, ParameterWithNull) {
Handle<HeapObject> null = factory()->null_value(); Handle<HeapObject> null = factory()->null_value();
{ {
Reduction r = Reduce(Parameter(Type::NewConstant(isolate(), null, zone()))); Reduction r =
Reduce(Parameter(Type::NewConstant(js_heap_broker(), null, zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsHeapConstant(null)); EXPECT_THAT(r.replacement(), IsHeapConstant(null));
} }
...@@ -125,14 +131,14 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithNaN) { ...@@ -125,14 +131,14 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithNaN) {
std::numeric_limits<double>::signaling_NaN()}; std::numeric_limits<double>::signaling_NaN()};
TRACED_FOREACH(double, nan, kNaNs) { TRACED_FOREACH(double, nan, kNaNs) {
Handle<Object> constant = factory()->NewNumber(nan); Handle<Object> constant = factory()->NewNumber(nan);
Reduction r = Reduction r = Reduce(
Reduce(Parameter(Type::NewConstant(isolate(), constant, zone()))); Parameter(Type::NewConstant(js_heap_broker(), constant, zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN()));
} }
{ {
Reduction r = Reduce(Parameter( Reduction r = Reduce(Parameter(
Type::NewConstant(isolate(), factory()->nan_value(), zone()))); Type::NewConstant(js_heap_broker(), factory()->nan_value(), zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN())); EXPECT_THAT(r.replacement(), IsNumberConstant(IsNaN()));
} }
...@@ -146,8 +152,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithNaN) { ...@@ -146,8 +152,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithNaN) {
TEST_F(ConstantFoldingReducerTest, ParameterWithPlainNumber) { TEST_F(ConstantFoldingReducerTest, ParameterWithPlainNumber) {
TRACED_FOREACH(double, value, kFloat64Values) { TRACED_FOREACH(double, value, kFloat64Values) {
Handle<Object> constant = factory()->NewNumber(value); Handle<Object> constant = factory()->NewNumber(value);
Reduction r = Reduction r = Reduce(
Reduce(Parameter(Type::NewConstant(isolate(), constant, zone()))); Parameter(Type::NewConstant(js_heap_broker(), constant, zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsNumberConstant(value)); EXPECT_THAT(r.replacement(), IsNumberConstant(value));
} }
...@@ -166,8 +172,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithUndefined) { ...@@ -166,8 +172,8 @@ TEST_F(ConstantFoldingReducerTest, ParameterWithUndefined) {
EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); EXPECT_THAT(r.replacement(), IsHeapConstant(undefined));
} }
{ {
Reduction r = Reduction r = Reduce(
Reduce(Parameter(Type::NewConstant(isolate(), undefined, zone()))); Parameter(Type::NewConstant(js_heap_broker(), undefined, zone())));
ASSERT_TRUE(r.Changed()); ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsHeapConstant(undefined)); EXPECT_THAT(r.replacement(), IsHeapConstant(undefined));
} }
...@@ -188,10 +194,10 @@ TEST_F(ConstantFoldingReducerTest, ToBooleanWithFalsish) { ...@@ -188,10 +194,10 @@ TEST_F(ConstantFoldingReducerTest, ToBooleanWithFalsish) {
Type::Undefined(), Type::Undefined(),
Type::Union( Type::Union(
Type::Undetectable(), Type::Undetectable(),
Type::Union( Type::Union(Type::NewConstant(
Type::NewConstant( js_heap_broker(),
isolate(), factory()->false_value(), zone()), factory()->false_value(), zone()),
Type::Range(0.0, 0.0, zone()), zone()), Type::Range(0.0, 0.0, zone()), zone()),
zone()), zone()),
zone()), zone()),
zone()), zone()),
...@@ -206,7 +212,7 @@ TEST_F(ConstantFoldingReducerTest, ToBooleanWithFalsish) { ...@@ -206,7 +212,7 @@ TEST_F(ConstantFoldingReducerTest, ToBooleanWithFalsish) {
TEST_F(ConstantFoldingReducerTest, ToBooleanWithTruish) { TEST_F(ConstantFoldingReducerTest, ToBooleanWithTruish) {
Node* input = Parameter( Node* input = Parameter(
Type::Union( Type::Union(
Type::NewConstant(isolate(), factory()->true_value(), zone()), Type::NewConstant(js_heap_broker(), factory()->true_value(), zone()),
Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()), Type::Union(Type::DetectableReceiver(), Type::Symbol(), zone()),
zone()), zone()),
0); 0);
......
...@@ -18,6 +18,7 @@ GraphTest::GraphTest(int num_parameters) ...@@ -18,6 +18,7 @@ GraphTest::GraphTest(int num_parameters)
TestWithIsolateAndZone(), TestWithIsolateAndZone(),
common_(zone()), common_(zone()),
graph_(zone()), graph_(zone()),
js_heap_broker_(isolate()),
source_positions_(&graph_), source_positions_(&graph_),
node_origins_(&graph_) { node_origins_(&graph_) {
graph()->SetStart(graph()->NewNode(common()->Start(num_parameters))); graph()->SetStart(graph()->NewNode(common()->Start(num_parameters)));
...@@ -60,7 +61,7 @@ Node* GraphTest::NumberConstant(volatile double value) { ...@@ -60,7 +61,7 @@ Node* GraphTest::NumberConstant(volatile double value) {
Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) { Node* GraphTest::HeapConstant(const Handle<HeapObject>& value) {
Node* node = graph()->NewNode(common()->HeapConstant(value)); Node* node = graph()->NewNode(common()->HeapConstant(value));
Type type = Type::NewConstant(isolate(), value, zone()); Type type = Type::NewConstant(js_heap_broker(), value, zone());
NodeProperties::SetType(node, type); NodeProperties::SetType(node, type);
return node; return node;
} }
...@@ -110,7 +111,8 @@ Matcher<Node*> GraphTest::IsUndefinedConstant() { ...@@ -110,7 +111,8 @@ Matcher<Node*> GraphTest::IsUndefinedConstant() {
} }
TypedGraphTest::TypedGraphTest(int num_parameters) TypedGraphTest::TypedGraphTest(int num_parameters)
: GraphTest(num_parameters), typer_(isolate(), Typer::kNoFlags, graph()) {} : GraphTest(num_parameters),
typer_(isolate(), js_heap_broker(), Typer::kNoFlags, graph()) {}
TypedGraphTest::~TypedGraphTest() {} TypedGraphTest::~TypedGraphTest() {}
......
...@@ -62,10 +62,12 @@ class GraphTest : public virtual TestWithNativeContext, ...@@ -62,10 +62,12 @@ class GraphTest : public virtual TestWithNativeContext,
Graph* graph() { return &graph_; } Graph* graph() { return &graph_; }
SourcePositionTable* source_positions() { return &source_positions_; } SourcePositionTable* source_positions() { return &source_positions_; }
NodeOriginTable* node_origins() { return &node_origins_; } NodeOriginTable* node_origins() { return &node_origins_; }
const JSHeapBroker* js_heap_broker() { return &js_heap_broker_; }
private: private:
CommonOperatorBuilder common_; CommonOperatorBuilder common_;
Graph graph_; Graph graph_;
JSHeapBroker js_heap_broker_;
SourcePositionTable source_positions_; SourcePositionTable source_positions_;
NodeOriginTable node_origins_; NodeOriginTable node_origins_;
}; };
......
...@@ -41,8 +41,8 @@ class JSCreateLoweringTest : public TypedGraphTest { ...@@ -41,8 +41,8 @@ class JSCreateLoweringTest : public TypedGraphTest {
&machine); &machine);
// TODO(titzer): mock the GraphReducer here for better unit testing. // TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph()); GraphReducer graph_reducer(zone(), graph());
JSCreateLowering reducer(&graph_reducer, &deps_, &jsgraph, native_context(), JSCreateLowering reducer(&graph_reducer, &deps_, &jsgraph, js_heap_broker(),
zone()); native_context(), zone());
return reducer.Reduce(node); return reducer.Reduce(node);
} }
...@@ -70,8 +70,8 @@ class JSCreateLoweringTest : public TypedGraphTest { ...@@ -70,8 +70,8 @@ class JSCreateLoweringTest : public TypedGraphTest {
TEST_F(JSCreateLoweringTest, JSCreate) { TEST_F(JSCreateLoweringTest, JSCreate) {
Handle<JSFunction> function = isolate()->object_function(); Handle<JSFunction> function = isolate()->object_function();
Node* const target = Node* const target = Parameter(
Parameter(Type::HeapConstant(isolate(), function, graph()->zone())); Type::HeapConstant(js_heap_broker(), function, graph()->zone()));
Node* const context = Parameter(Type::Any()); Node* const context = Parameter(Type::Any());
Node* const effect = graph()->start(); Node* const effect = graph()->start();
Node* const control = graph()->start(); Node* const control = graph()->start();
......
...@@ -48,7 +48,7 @@ class JSTypedLoweringTest : public TypedGraphTest { ...@@ -48,7 +48,7 @@ class JSTypedLoweringTest : public TypedGraphTest {
&machine); &machine);
// TODO(titzer): mock the GraphReducer here for better unit testing. // TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph()); GraphReducer graph_reducer(zone(), graph());
JSTypedLowering reducer(&graph_reducer, &jsgraph, zone()); JSTypedLowering reducer(&graph_reducer, &jsgraph, js_heap_broker(), zone());
return reducer.Reduce(node); return reducer.Reduce(node);
} }
......
...@@ -42,12 +42,12 @@ class SimplifiedLoweringTest : public GraphTest { ...@@ -42,12 +42,12 @@ class SimplifiedLoweringTest : public GraphTest {
{ {
// Simplified lowering needs to run w/o the typer decorator so make sure // Simplified lowering needs to run w/o the typer decorator so make sure
// the object is not live at the same time. // the object is not live at the same time.
Typer typer(isolate(), Typer::kNoFlags, graph()); Typer typer(isolate(), js_heap_broker(), Typer::kNoFlags, graph());
typer.Run(); typer.Run();
} }
SimplifiedLowering lowering(jsgraph(), zone(), source_positions(), SimplifiedLowering lowering(jsgraph(), js_heap_broker(), zone(),
node_origins(), source_positions(), node_origins(),
PoisoningMitigationLevel::kDontPoison); PoisoningMitigationLevel::kDontPoison);
lowering.LowerAllNodes(); lowering.LowerAllNodes();
} }
......
...@@ -38,7 +38,8 @@ class TypedOptimizationTest : public TypedGraphTest { ...@@ -38,7 +38,8 @@ class TypedOptimizationTest : public TypedGraphTest {
&machine); &machine);
// TODO(titzer): mock the GraphReducer here for better unit testing. // TODO(titzer): mock the GraphReducer here for better unit testing.
GraphReducer graph_reducer(zone(), graph()); GraphReducer graph_reducer(zone(), graph());
TypedOptimization reducer(&graph_reducer, &deps_, &jsgraph); TypedOptimization reducer(&graph_reducer, &deps_, &jsgraph,
js_heap_broker());
return reducer.Reduce(node); return reducer.Reduce(node);
} }
......
...@@ -22,7 +22,8 @@ class TyperTest : public TypedGraphTest { ...@@ -22,7 +22,8 @@ class TyperTest : public TypedGraphTest {
public: public:
TyperTest() TyperTest()
: TypedGraphTest(3), : TypedGraphTest(3),
operation_typer_(isolate(), zone()), js_heap_broker_(isolate()),
operation_typer_(isolate(), &js_heap_broker_, zone()),
types_(zone(), isolate(), random_number_generator()), types_(zone(), isolate(), random_number_generator()),
javascript_(zone()), javascript_(zone()),
simplified_(zone()) { simplified_(zone()) {
...@@ -55,6 +56,7 @@ class TyperTest : public TypedGraphTest { ...@@ -55,6 +56,7 @@ class TyperTest : public TypedGraphTest {
const int kRepetitions = 50; const int kRepetitions = 50;
JSHeapBroker js_heap_broker_;
OperationTyper operation_typer_; OperationTyper operation_typer_;
Types types_; Types types_;
JSOperatorBuilder javascript_; JSOperatorBuilder javascript_;
...@@ -174,8 +176,8 @@ class TyperTest : public TypedGraphTest { ...@@ -174,8 +176,8 @@ class TyperTest : public TypedGraphTest {
for (int x2 = rmin; x2 < rmin + width; x2++) { for (int x2 = rmin; x2 < rmin + width; x2++) {
double result_value = opfun(x1, x2); double result_value = opfun(x1, x2);
Type result_type = Type::NewConstant( Type result_type = Type::NewConstant(
isolate(), isolate()->factory()->NewNumber(result_value), &js_heap_broker_,
zone()); isolate()->factory()->NewNumber(result_value), zone());
EXPECT_TRUE(result_type.Is(expected_type)); EXPECT_TRUE(result_type.Is(expected_type));
} }
} }
...@@ -196,21 +198,23 @@ class TyperTest : public TypedGraphTest { ...@@ -196,21 +198,23 @@ class TyperTest : public TypedGraphTest {
double x2 = RandomInt(r2.AsRange()); double x2 = RandomInt(r2.AsRange());
double result_value = opfun(x1, x2); double result_value = opfun(x1, x2);
Type result_type = Type::NewConstant( Type result_type = Type::NewConstant(
isolate(), isolate()->factory()->NewNumber(result_value), zone()); &js_heap_broker_, isolate()->factory()->NewNumber(result_value),
zone());
EXPECT_TRUE(result_type.Is(expected_type)); EXPECT_TRUE(result_type.Is(expected_type));
} }
} }
// Test extreme cases. // Test extreme cases.
double x1 = +1e-308; double x1 = +1e-308;
double x2 = -1e-308; double x2 = -1e-308;
Type r1 = Type::NewConstant(isolate(), isolate()->factory()->NewNumber(x1), Type r1 = Type::NewConstant(&js_heap_broker_,
zone()); isolate()->factory()->NewNumber(x1), zone());
Type r2 = Type::NewConstant(isolate(), isolate()->factory()->NewNumber(x2), Type r2 = Type::NewConstant(&js_heap_broker_,
zone()); isolate()->factory()->NewNumber(x2), zone());
Type expected_type = TypeBinaryOp(op, r1, r2); Type expected_type = TypeBinaryOp(op, r1, r2);
double result_value = opfun(x1, x2); double result_value = opfun(x1, x2);
Type result_type = Type::NewConstant( Type result_type = Type::NewConstant(
isolate(), isolate()->factory()->NewNumber(result_value), zone()); &js_heap_broker_, isolate()->factory()->NewNumber(result_value),
zone());
EXPECT_TRUE(result_type.Is(expected_type)); EXPECT_TRUE(result_type.Is(expected_type));
} }
...@@ -225,7 +229,7 @@ class TyperTest : public TypedGraphTest { ...@@ -225,7 +229,7 @@ class TyperTest : public TypedGraphTest {
double x2 = RandomInt(r2.AsRange()); double x2 = RandomInt(r2.AsRange());
bool result_value = opfun(x1, x2); bool result_value = opfun(x1, x2);
Type result_type = Type::NewConstant( Type result_type = Type::NewConstant(
isolate(), &js_heap_broker_,
result_value ? isolate()->factory()->true_value() result_value ? isolate()->factory()->true_value()
: isolate()->factory()->false_value(), : isolate()->factory()->false_value(),
zone()); zone());
...@@ -245,7 +249,8 @@ class TyperTest : public TypedGraphTest { ...@@ -245,7 +249,8 @@ class TyperTest : public TypedGraphTest {
int32_t x2 = static_cast<int32_t>(RandomInt(r2.AsRange())); int32_t x2 = static_cast<int32_t>(RandomInt(r2.AsRange()));
double result_value = opfun(x1, x2); double result_value = opfun(x1, x2);
Type result_type = Type::NewConstant( Type result_type = Type::NewConstant(
isolate(), isolate()->factory()->NewNumber(result_value), zone()); &js_heap_broker_, isolate()->factory()->NewNumber(result_value),
zone());
EXPECT_TRUE(result_type.Is(expected_type)); EXPECT_TRUE(result_type.Is(expected_type));
} }
} }
......
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