Commit d7f55068 authored by Ben L. Titzer's avatar Ben L. Titzer Committed by Commit Bot

[turbofan] Move Dead node up to MachineGraph

In preparation for cleaning up PipelineData to use a MachineGraph
where appropriate, move the dead node up to MachineGraph.

R=ahaas@chromium.org

Bug: v8:7721
Change-Id: I3f9d456aef7cf4d80adbc93ae938636ffcc3712d
Reviewed-on: https://chromium-review.googlesource.com/1046828
Commit-Queue: Ben Titzer <titzer@chromium.org>
Reviewed-by: 's avatarAndreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53037}
parent 79c7e189
......@@ -13,143 +13,39 @@ namespace v8 {
namespace internal {
namespace compiler {
#define CACHED(name, expr) \
cached_nodes_[name] ? cached_nodes_[name] : (cached_nodes_[name] = (expr))
#define GET_CACHED_FIELD(ptr, expr) (*(ptr)) ? *(ptr) : (*(ptr) = (expr))
Node* JSGraph::AllocateInNewSpaceStubConstant() {
return CACHED(kAllocateInNewSpaceStubConstant,
HeapConstant(BUILTIN_CODE(isolate(), AllocateInNewSpace)));
}
Node* JSGraph::AllocateInOldSpaceStubConstant() {
return CACHED(kAllocateInOldSpaceStubConstant,
HeapConstant(BUILTIN_CODE(isolate(), AllocateInOldSpace)));
}
Node* JSGraph::ArrayConstructorStubConstant() {
return CACHED(kArrayConstructorStubConstant,
HeapConstant(ArrayConstructorStub(isolate()).GetCode()));
}
Node* JSGraph::ToNumberBuiltinConstant() {
return CACHED(kToNumberBuiltinConstant,
HeapConstant(BUILTIN_CODE(isolate(), ToNumber)));
}
#define DEFINE_GETTER(name, expr) \
Node* JSGraph::name() { return GET_CACHED_FIELD(&name##_, expr); }
Node* JSGraph::CEntryStubConstant(int result_size, SaveFPRegsMode save_doubles,
ArgvMode argv_mode, bool builtin_exit_frame) {
if (save_doubles == kDontSaveFPRegs && argv_mode == kArgvOnStack) {
DCHECK(result_size >= 1 && result_size <= 3);
if (!builtin_exit_frame) {
CachedNode key;
Node** ptr = nullptr;
if (result_size == 1) {
key = kCEntryStub1Constant;
ptr = &CEntryStub1Constant_;
} else if (result_size == 2) {
key = kCEntryStub2Constant;
ptr = &CEntryStub2Constant_;
} else {
DCHECK_EQ(3, result_size);
key = kCEntryStub3Constant;
ptr = &CEntryStub3Constant_;
}
return CACHED(key, HeapConstant(CodeFactory::CEntry(
isolate(), result_size, save_doubles, argv_mode,
builtin_exit_frame)));
return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
isolate(), result_size, save_doubles,
argv_mode, builtin_exit_frame)));
}
CachedNode key = builtin_exit_frame
? kCEntryStub1WithBuiltinExitFrameConstant
: kCEntryStub1Constant;
return CACHED(key, HeapConstant(CodeFactory::CEntry(isolate(), result_size,
save_doubles, argv_mode,
builtin_exit_frame)));
Node** ptr = builtin_exit_frame ? &CEntryStub1WithBuiltinExitFrameConstant_
: &CEntryStub1Constant_;
return GET_CACHED_FIELD(ptr, HeapConstant(CodeFactory::CEntry(
isolate(), result_size, save_doubles,
argv_mode, builtin_exit_frame)));
}
return HeapConstant(CodeFactory::CEntry(isolate(), result_size, save_doubles,
argv_mode, builtin_exit_frame));
}
Node* JSGraph::EmptyFixedArrayConstant() {
return CACHED(kEmptyFixedArrayConstant,
HeapConstant(factory()->empty_fixed_array()));
}
Node* JSGraph::EmptyStringConstant() {
return CACHED(kEmptyStringConstant, HeapConstant(factory()->empty_string()));
}
Node* JSGraph::FixedArrayMapConstant() {
return CACHED(kFixedArrayMapConstant,
HeapConstant(factory()->fixed_array_map()));
}
Node* JSGraph::PropertyArrayMapConstant() {
return CACHED(kPropertyArrayMapConstant,
HeapConstant(factory()->property_array_map()));
}
Node* JSGraph::FixedDoubleArrayMapConstant() {
return CACHED(kFixedDoubleArrayMapConstant,
HeapConstant(factory()->fixed_double_array_map()));
}
Node* JSGraph::HeapNumberMapConstant() {
return CACHED(kHeapNumberMapConstant,
HeapConstant(factory()->heap_number_map()));
}
Node* JSGraph::OptimizedOutConstant() {
return CACHED(kOptimizedOutConstant,
HeapConstant(factory()->optimized_out()));
}
Node* JSGraph::StaleRegisterConstant() {
return CACHED(kStaleRegisterConstant,
HeapConstant(factory()->stale_register()));
}
Node* JSGraph::UndefinedConstant() {
return CACHED(kUndefinedConstant, HeapConstant(factory()->undefined_value()));
}
Node* JSGraph::TheHoleConstant() {
return CACHED(kTheHoleConstant, HeapConstant(factory()->the_hole_value()));
}
Node* JSGraph::TrueConstant() {
return CACHED(kTrueConstant, HeapConstant(factory()->true_value()));
}
Node* JSGraph::FalseConstant() {
return CACHED(kFalseConstant, HeapConstant(factory()->false_value()));
}
Node* JSGraph::NullConstant() {
return CACHED(kNullConstant, HeapConstant(factory()->null_value()));
}
Node* JSGraph::ZeroConstant() {
return CACHED(kZeroConstant, NumberConstant(0.0));
}
Node* JSGraph::OneConstant() {
return CACHED(kOneConstant, NumberConstant(1.0));
}
Node* JSGraph::MinusOneConstant() {
return CACHED(kMinusOneConstant, NumberConstant(-1.0));
}
Node* JSGraph::NaNConstant() {
return CACHED(kNaNConstant,
NumberConstant(std::numeric_limits<double>::quiet_NaN()));
}
Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
Node** loc = cache_.FindHeapConstant(value);
if (*loc == nullptr) {
*loc = graph()->NewNode(common()->HeapConstant(value));
}
return *loc;
}
Node* JSGraph::Constant(Handle<Object> value) {
// Dereference the handle to determine if a number constant or other
// canonicalized node can be used.
......@@ -197,32 +93,87 @@ Node* JSGraph::NumberConstant(double value) {
return *loc;
}
Node* JSGraph::EmptyStateValues() {
return CACHED(kEmptyStateValues, graph()->NewNode(common()->StateValues(
0, SparseInputMask::Dense())));
}
Node* JSGraph::SingleDeadTypedStateValues() {
return CACHED(kSingleDeadTypedStateValues,
graph()->NewNode(common()->TypedStateValues(
new (graph()->zone()->New(sizeof(ZoneVector<MachineType>)))
ZoneVector<MachineType>(0, graph()->zone()),
SparseInputMask(SparseInputMask::kEndMarker << 1))));
}
Node* JSGraph::Dead() {
return CACHED(kDead, graph()->NewNode(common()->Dead()));
Node* JSGraph::HeapConstant(Handle<HeapObject> value) {
Node** loc = cache_.FindHeapConstant(value);
if (*loc == nullptr) {
*loc = graph()->NewNode(common()->HeapConstant(value));
}
return *loc;
}
void JSGraph::GetCachedNodes(NodeVector* nodes) {
cache_.GetCachedNodes(nodes);
for (size_t i = 0; i < arraysize(cached_nodes_); i++) {
if (Node* node = cached_nodes_[i]) {
if (!node->IsDead()) nodes->push_back(node);
}
}
#define DO_CACHED_FIELD(name) \
if (name##_) nodes->push_back(name##_);
CACHED_GLOBAL_LIST(DO_CACHED_FIELD)
CACHED_CENTRY_LIST(DO_CACHED_FIELD)
#undef DO_CACHED_FIELD
}
DEFINE_GETTER(AllocateInNewSpaceStubConstant,
HeapConstant(BUILTIN_CODE(isolate(), AllocateInNewSpace)))
DEFINE_GETTER(AllocateInOldSpaceStubConstant,
HeapConstant(BUILTIN_CODE(isolate(), AllocateInOldSpace)))
DEFINE_GETTER(ArrayConstructorStubConstant,
HeapConstant(ArrayConstructorStub(isolate()).GetCode()))
DEFINE_GETTER(ToNumberBuiltinConstant,
HeapConstant(BUILTIN_CODE(isolate(), ToNumber)))
DEFINE_GETTER(EmptyFixedArrayConstant,
HeapConstant(factory()->empty_fixed_array()))
DEFINE_GETTER(EmptyStringConstant, HeapConstant(factory()->empty_string()))
DEFINE_GETTER(FixedArrayMapConstant, HeapConstant(factory()->fixed_array_map()))
DEFINE_GETTER(PropertyArrayMapConstant,
HeapConstant(factory()->property_array_map()))
DEFINE_GETTER(FixedDoubleArrayMapConstant,
HeapConstant(factory()->fixed_double_array_map()))
DEFINE_GETTER(HeapNumberMapConstant, HeapConstant(factory()->heap_number_map()))
DEFINE_GETTER(OptimizedOutConstant, HeapConstant(factory()->optimized_out()))
DEFINE_GETTER(StaleRegisterConstant, HeapConstant(factory()->stale_register()))
DEFINE_GETTER(UndefinedConstant, HeapConstant(factory()->undefined_value()))
DEFINE_GETTER(TheHoleConstant, HeapConstant(factory()->the_hole_value()))
DEFINE_GETTER(TrueConstant, HeapConstant(factory()->true_value()))
DEFINE_GETTER(FalseConstant, HeapConstant(factory()->false_value()))
DEFINE_GETTER(NullConstant, HeapConstant(factory()->null_value()))
DEFINE_GETTER(ZeroConstant, NumberConstant(0.0))
DEFINE_GETTER(OneConstant, NumberConstant(1.0))
DEFINE_GETTER(MinusOneConstant, NumberConstant(-1.0))
DEFINE_GETTER(NaNConstant,
NumberConstant(std::numeric_limits<double>::quiet_NaN()))
DEFINE_GETTER(EmptyStateValues,
graph()->NewNode(common()->StateValues(0,
SparseInputMask::Dense())))
DEFINE_GETTER(SingleDeadTypedStateValues,
graph()->NewNode(common()->TypedStateValues(
new (graph()->zone()->New(sizeof(ZoneVector<MachineType>)))
ZoneVector<MachineType>(0, graph()->zone()),
SparseInputMask(SparseInputMask::kEndMarker << 1))))
#undef DEFINE_GETTER
#undef GET_CACHED_FIELD
} // namespace compiler
} // namespace internal
} // namespace v8
......@@ -32,39 +32,20 @@ class V8_EXPORT_PRIVATE JSGraph : public MachineGraph {
isolate_(isolate),
javascript_(javascript),
simplified_(simplified) {
for (int i = 0; i < kNumCachedNodes; i++) cached_nodes_[i] = nullptr;
}
// Canonicalized global constants.
Node* AllocateInNewSpaceStubConstant();
Node* AllocateInOldSpaceStubConstant();
Node* ArrayConstructorStubConstant();
Node* ToNumberBuiltinConstant();
// CEntryStubs are cached depending on the result size and other flags.
Node* CEntryStubConstant(int result_size,
SaveFPRegsMode save_doubles = kDontSaveFPRegs,
ArgvMode argv_mode = kArgvOnStack,
bool builtin_exit_frame = false);
Node* EmptyFixedArrayConstant();
Node* EmptyStringConstant();
Node* FixedArrayMapConstant();
Node* PropertyArrayMapConstant();
Node* FixedDoubleArrayMapConstant();
Node* HeapNumberMapConstant();
Node* OptimizedOutConstant();
Node* StaleRegisterConstant();
Node* UndefinedConstant();
Node* TheHoleConstant();
Node* TrueConstant();
Node* FalseConstant();
Node* NullConstant();
Node* ZeroConstant();
Node* OneConstant();
Node* NaNConstant();
Node* MinusOneConstant();
// Used for padding frames.
// Used for padding frames. (alias: the hole)
Node* PaddingConstant() { return TheHoleConstant(); }
// Used for stubs and runtime functions with no context. (alias: SMI zero)
Node* NoContextConstant() { return ZeroConstant(); }
// Creates a HeapConstant node, possibly canonicalized, and may access the
// heap to inspect the object.
Node* HeapConstant(Handle<HeapObject> value);
......@@ -93,66 +74,63 @@ class V8_EXPORT_PRIVATE JSGraph : public MachineGraph {
return Constant(immediate);
}
// Creates a dummy Constant node, used to satisfy calling conventions of
// stubs and runtime functions that do not require a context.
Node* NoContextConstant() { return ZeroConstant(); }
// Creates an empty StateValues node, used when we don't have any concrete
// values for a certain part of the frame state.
Node* EmptyStateValues();
// Typed state values with a single dead input. This is useful to represent
// dead accumulator.
Node* SingleDeadTypedStateValues();
// Create a control node that serves as dependency for dead nodes.
Node* Dead();
JSOperatorBuilder* javascript() const { return javascript_; }
SimplifiedOperatorBuilder* simplified() const { return simplified_; }
Isolate* isolate() const { return isolate_; }
Factory* factory() const { return isolate()->factory(); }
// Adds all the cached nodes to the given list.
void GetCachedNodes(NodeVector* nodes);
private:
enum CachedNode {
kAllocateInNewSpaceStubConstant,
kAllocateInOldSpaceStubConstant,
kArrayConstructorStubConstant,
kToNumberBuiltinConstant,
kCEntryStub1Constant,
kCEntryStub2Constant,
kCEntryStub3Constant,
kCEntryStub1WithBuiltinExitFrameConstant,
kEmptyFixedArrayConstant,
kEmptyStringConstant,
kFixedArrayMapConstant,
kFixedDoubleArrayMapConstant,
kPropertyArrayMapConstant,
kHeapNumberMapConstant,
kOptimizedOutConstant,
kStaleRegisterConstant,
kUndefinedConstant,
kTheHoleConstant,
kTrueConstant,
kFalseConstant,
kNullConstant,
kZeroConstant,
kOneConstant,
kMinusOneConstant,
kNaNConstant,
kEmptyStateValues,
kSingleDeadTypedStateValues,
kDead,
kNumCachedNodes // Must remain last.
};
// Cached global nodes.
#define CACHED_GLOBAL_LIST(V) \
V(AllocateInNewSpaceStubConstant) \
V(AllocateInOldSpaceStubConstant) \
V(ArrayConstructorStubConstant) \
V(ToNumberBuiltinConstant) \
V(EmptyFixedArrayConstant) \
V(EmptyStringConstant) \
V(FixedArrayMapConstant) \
V(PropertyArrayMapConstant) \
V(FixedDoubleArrayMapConstant) \
V(HeapNumberMapConstant) \
V(OptimizedOutConstant) \
V(StaleRegisterConstant) \
V(UndefinedConstant) \
V(TheHoleConstant) \
V(TrueConstant) \
V(FalseConstant) \
V(NullConstant) \
V(ZeroConstant) \
V(OneConstant) \
V(NaNConstant) \
V(MinusOneConstant) \
V(EmptyStateValues) \
V(SingleDeadTypedStateValues)
// Cached global node accessor methods.
#define DECLARE_GETTER(name) Node* name();
CACHED_GLOBAL_LIST(DECLARE_GETTER)
#undef DECLARE_FIELD
private:
Isolate* isolate_;
JSOperatorBuilder* javascript_;
SimplifiedOperatorBuilder* simplified_;
Node* cached_nodes_[kNumCachedNodes];
#define CACHED_CENTRY_LIST(V) \
V(CEntryStub1Constant) \
V(CEntryStub2Constant) \
V(CEntryStub3Constant) \
V(CEntryStub1WithBuiltinExitFrameConstant)
// Canonicalized global node fields.
#define DECLARE_FIELD(name) Node* name##_ = nullptr;
CACHED_GLOBAL_LIST(DECLARE_FIELD)
CACHED_CENTRY_LIST(DECLARE_FIELD)
#undef DECLARE_FIELD
// Internal helper to canonicalize a number constant.
Node* NumberConstant(double value);
DISALLOW_COPY_AND_ASSIGN(JSGraph);
......
......@@ -65,6 +65,11 @@ class V8_EXPORT_PRIVATE MachineGraph : public NON_EXPORTED_BASE(ZoneObject) {
Node* ExternalConstant(ExternalReference ref);
Node* ExternalConstant(Runtime::FunctionId function_id);
// Global cache of the dead node.
Node* Dead() {
return Dead_ ? Dead_ : Dead_ = graph_->NewNode(common_->Dead());
}
CommonOperatorBuilder* common() const { return common_; }
MachineOperatorBuilder* machine() const { return machine_; }
Graph* graph() const { return graph_; }
......@@ -75,6 +80,7 @@ class V8_EXPORT_PRIVATE MachineGraph : public NON_EXPORTED_BASE(ZoneObject) {
CommonOperatorBuilder* common_;
MachineOperatorBuilder* machine_;
CommonNodeCache cache_;
Node* Dead_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(MachineGraph);
};
......
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