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 {
kSwitchJumpTableEnabled = 1 << 13,
kGenerateSpeculationPoisonOnEntry = 1 << 14,
kPoisonRegisterArguments = 1 << 15,
kAllocationFoldingEnabled = 1 << 16
};
// TODO(mtrofin): investigate if this might be generalized outside wasm, with
......@@ -195,6 +196,11 @@ class V8_EXPORT_PRIVATE CompilationInfo final {
return enabled;
}
void MarkAsAllocationFoldingEnabled() { SetFlag(kAllocationFoldingEnabled); }
bool is_allocation_folding_enabled() const {
return GetFlag(kAllocationFoldingEnabled);
}
// Code getters and setters.
void SetCode(Handle<Code> code) { code_ = code; }
......
......@@ -16,14 +16,16 @@ namespace internal {
namespace compiler {
MemoryOptimizer::MemoryOptimizer(JSGraph* jsgraph, Zone* zone,
LoadPoisoning load_poisoning)
LoadPoisoning load_poisoning,
AllocationFolding allocation_folding)
: jsgraph_(jsgraph),
empty_state_(AllocationState::Empty(zone)),
pending_(zone),
tokens_(zone),
zone_(zone),
graph_assembler_(jsgraph, nullptr, nullptr, zone),
load_poisoning_(load_poisoning) {}
load_poisoning_(load_poisoning),
allocation_folding_(allocation_folding) {}
void MemoryOptimizer::Optimize() {
EnqueueUses(graph()->start(), empty_state());
......@@ -172,7 +174,8 @@ void MemoryOptimizer::VisitAllocateRaw(Node* node,
Int32Matcher m(size);
if (m.HasValue() && m.Value() < kMaxRegularHeapObjectSize) {
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) {
// We can fold this Allocate {node} into the allocation {group}
// represented by the given {state}. Compute the upper bound for
......
......@@ -31,7 +31,10 @@ typedef uint32_t NodeId;
// implicitly.
class MemoryOptimizer final {
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() {}
void Optimize();
......@@ -143,6 +146,7 @@ class MemoryOptimizer final {
Zone* const zone_;
GraphAssembler graph_assembler_;
LoadPoisoning load_poisoning_;
AllocationFolding allocation_folding_;
DISALLOW_IMPLICIT_CONSTRUCTORS(MemoryOptimizer);
};
......
......@@ -805,6 +805,9 @@ PipelineCompilationJob::Status PipelineCompilationJob::PrepareJobImpl(
if (FLAG_branch_load_poisoning) {
compilation_info()->MarkAsPoisonLoads();
}
if (FLAG_turbo_allocation_folding) {
compilation_info()->MarkAsAllocationFoldingEnabled();
}
if (compilation_info()->closure()->feedback_cell()->map() ==
isolate->heap()->one_closure_cell_map()) {
compilation_info()->MarkAsFunctionContextSpecializing();
......@@ -1446,10 +1449,13 @@ struct MemoryOptimizationPhase {
trimmer.TrimGraph(roots.begin(), roots.end());
// Optimize allocations and load/store operations.
MemoryOptimizer optimizer(data->jsgraph(), temp_zone,
data->info()->is_poison_loads()
? LoadPoisoning::kDoPoison
: LoadPoisoning::kDontPoison);
MemoryOptimizer optimizer(
data->jsgraph(), temp_zone,
data->info()->is_poison_loads() ? LoadPoisoning::kDoPoison
: LoadPoisoning::kDontPoison,
data->info()->is_allocation_folding_enabled()
? MemoryOptimizer::AllocationFolding::kDoAllocationFolding
: MemoryOptimizer::AllocationFolding::kDontAllocationFolding);
optimizer.Optimize();
}
};
......
......@@ -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_cf_optimization, true, "optimize control flow in TurboFan")
DEFINE_BOOL(turbo_escape, true, "enable escape analysis")
DEFINE_BOOL(turbo_allocation_folding, true, "Turbofan allocation folding")
DEFINE_BOOL(turbo_instruction_scheduling, false,
"enable instruction scheduling in TurboFan")
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