Commit d8735757 authored by Hannes Payer's avatar Hannes Payer Committed by Commit Bot

[turbofan] Add a --turbo_allocation_folding flag.

Change-Id: If8678bd244a0a4e21b1967c15da80e49643a33ea
Reviewed-on: https://chromium-review.googlesource.com/973001Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Hannes Payer <hpayer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#52101}
parent 977d9a8b
...@@ -55,6 +55,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -55,6 +55,7 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
kSwitchJumpTableEnabled = 1 << 13, kSwitchJumpTableEnabled = 1 << 13,
kGenerateSpeculationPoisonOnEntry = 1 << 14, kGenerateSpeculationPoisonOnEntry = 1 << 14,
kPoisonRegisterArguments = 1 << 15, kPoisonRegisterArguments = 1 << 15,
kAllocationFoldingEnabled = 1 << 16
}; };
// TODO(mtrofin): investigate if this might be generalized outside wasm, with // TODO(mtrofin): investigate if this might be generalized outside wasm, with
...@@ -195,6 +196,11 @@ class V8_EXPORT_PRIVATE CompilationInfo final { ...@@ -195,6 +196,11 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
return enabled; return enabled;
} }
void MarkAsAllocationFoldingEnabled() { SetFlag(kAllocationFoldingEnabled); }
bool is_allocation_folding_enabled() const {
return GetFlag(kAllocationFoldingEnabled);
}
// Code getters and setters. // Code getters and setters.
void SetCode(Handle<Code> code) { code_ = code; } void SetCode(Handle<Code> code) { code_ = code; }
......
...@@ -16,14 +16,16 @@ namespace internal { ...@@ -16,14 +16,16 @@ namespace internal {
namespace compiler { namespace compiler {
MemoryOptimizer::MemoryOptimizer(JSGraph* jsgraph, Zone* zone, MemoryOptimizer::MemoryOptimizer(JSGraph* jsgraph, Zone* zone,
LoadPoisoning load_poisoning) LoadPoisoning load_poisoning,
AllocationFolding allocation_folding)
: jsgraph_(jsgraph), : jsgraph_(jsgraph),
empty_state_(AllocationState::Empty(zone)), empty_state_(AllocationState::Empty(zone)),
pending_(zone), pending_(zone),
tokens_(zone), tokens_(zone),
zone_(zone), zone_(zone),
graph_assembler_(jsgraph, nullptr, nullptr, zone), graph_assembler_(jsgraph, nullptr, nullptr, zone),
load_poisoning_(load_poisoning) {} load_poisoning_(load_poisoning),
allocation_folding_(allocation_folding) {}
void MemoryOptimizer::Optimize() { void MemoryOptimizer::Optimize() {
EnqueueUses(graph()->start(), empty_state()); EnqueueUses(graph()->start(), empty_state());
...@@ -172,7 +174,8 @@ void MemoryOptimizer::VisitAllocateRaw(Node* node, ...@@ -172,7 +174,8 @@ void MemoryOptimizer::VisitAllocateRaw(Node* node,
Int32Matcher m(size); Int32Matcher m(size);
if (m.HasValue() && m.Value() < kMaxRegularHeapObjectSize) { if (m.HasValue() && m.Value() < kMaxRegularHeapObjectSize) {
int32_t const object_size = m.Value(); int32_t const object_size = m.Value();
if (state->size() <= kMaxRegularHeapObjectSize - object_size && if (allocation_folding_ == AllocationFolding::kDoAllocationFolding &&
state->size() <= kMaxRegularHeapObjectSize - object_size &&
state->group()->pretenure() == pretenure) { state->group()->pretenure() == pretenure) {
// We can fold this Allocate {node} into the allocation {group} // We can fold this Allocate {node} into the allocation {group}
// represented by the given {state}. Compute the upper bound for // represented by the given {state}. Compute the upper bound for
......
...@@ -31,7 +31,10 @@ typedef uint32_t NodeId; ...@@ -31,7 +31,10 @@ typedef uint32_t NodeId;
// implicitly. // implicitly.
class MemoryOptimizer final { class MemoryOptimizer final {
public: public:
MemoryOptimizer(JSGraph* jsgraph, Zone* zone, LoadPoisoning load_poisoning); enum class AllocationFolding { kDoAllocationFolding, kDontAllocationFolding };
MemoryOptimizer(JSGraph* jsgraph, Zone* zone, LoadPoisoning load_poisoning,
AllocationFolding allocation_folding);
~MemoryOptimizer() {} ~MemoryOptimizer() {}
void Optimize(); void Optimize();
...@@ -143,6 +146,7 @@ class MemoryOptimizer final { ...@@ -143,6 +146,7 @@ class MemoryOptimizer final {
Zone* const zone_; Zone* const zone_;
GraphAssembler graph_assembler_; GraphAssembler graph_assembler_;
LoadPoisoning load_poisoning_; LoadPoisoning load_poisoning_;
AllocationFolding allocation_folding_;
DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryOptimizer); DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryOptimizer);
}; };
......
...@@ -805,6 +805,9 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl( ...@@ -805,6 +805,9 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
if (FLAG_branch_load_poisoning) { if (FLAG_branch_load_poisoning) {
compilation_info()->MarkAsPoisonLoads(); compilation_info()->MarkAsPoisonLoads();
} }
if (FLAG_turbo_allocation_folding) {
compilation_info()->MarkAsAllocationFoldingEnabled();
}
if (compilation_info()->closure()->feedback_cell()->map() == if (compilation_info()->closure()->feedback_cell()->map() ==
isolate->heap()->one_closure_cell_map()) { isolate->heap()->one_closure_cell_map()) {
compilation_info()->MarkAsFunctionContextSpecializing(); compilation_info()->MarkAsFunctionContextSpecializing();
...@@ -1446,10 +1449,13 @@ struct MemoryOptimizationPhase { ...@@ -1446,10 +1449,13 @@ struct MemoryOptimizationPhase {
trimmer.TrimGraph(roots.begin(), roots.end()); trimmer.TrimGraph(roots.begin(), roots.end());
// Optimize allocations and load/store operations. // Optimize allocations and load/store operations.
MemoryOptimizer optimizer(data->jsgraph(), temp_zone, MemoryOptimizer optimizer(
data->info()->is_poison_loads() data->jsgraph(), temp_zone,
? LoadPoisoning::kDoPoison data->info()->is_poison_loads() ? LoadPoisoning::kDoPoison
: LoadPoisoning::kDontPoison); : LoadPoisoning::kDontPoison,
data->info()->is_allocation_folding_enabled()
? MemoryOptimizer::AllocationFolding::kDoAllocationFolding
: MemoryOptimizer::AllocationFolding::kDontAllocationFolding);
optimizer.Optimize(); optimizer.Optimize();
} }
}; };
......
...@@ -478,6 +478,7 @@ DEFINE_BOOL(turbo_loop_peeling, true, "Turbofan loop peeling") ...@@ -478,6 +478,7 @@ DEFINE_BOOL(turbo_loop_peeling, true, "Turbofan loop peeling")
DEFINE_BOOL(turbo_loop_variable, true, "Turbofan loop variable optimization") DEFINE_BOOL(turbo_loop_variable, true, "Turbofan loop variable optimization")
DEFINE_BOOL(turbo_cf_optimization, true, "optimize control flow in TurboFan") DEFINE_BOOL(turbo_cf_optimization, true, "optimize control flow in TurboFan")
DEFINE_BOOL(turbo_escape, true, "enable escape analysis") DEFINE_BOOL(turbo_escape, true, "enable escape analysis")
DEFINE_BOOL(turbo_allocation_folding, true, "Turbofan allocation folding")
DEFINE_BOOL(turbo_instruction_scheduling, false, DEFINE_BOOL(turbo_instruction_scheduling, false,
"enable instruction scheduling in TurboFan") "enable instruction scheduling in TurboFan")
DEFINE_BOOL(turbo_stress_instruction_scheduling, false, DEFINE_BOOL(turbo_stress_instruction_scheduling, false,
......
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