Commit 4e0b7b0c authored by mtrofin's avatar mtrofin Committed by Commit bot

Separated the new register allocator in its own files.

Opportunistically removed GreedyAllocator::TryReuseSpillForPhi because it is actually unsuitable for Greedy. It was copied from Linear and it relies on hints, however, the current implementation of hints assumes linear scan.

This change doesn't aim to address performance nor correctness for Greedy.

BUG=

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

Cr-Commit-Position: refs/heads/master@{#29054}
parent 443f6765
......@@ -646,6 +646,8 @@ source_set("v8_base") {
"src/compiler/graph-visualizer.h",
"src/compiler/graph.cc",
"src/compiler/graph.h",
"src/compiler/greedy-allocator.cc",
"src/compiler/greedy-allocator.h",
"src/compiler/instruction-codes.h",
"src/compiler/instruction-selector-impl.h",
"src/compiler/instruction-selector.cc",
......
This diff is collapsed.
// Copyright 2015 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_GREEDY_ALLOCATOR_H_
#define V8_GREEDY_ALLOCATOR_H_
#include "src/compiler/register-allocator.h"
#include "src/zone-containers.h"
namespace v8 {
namespace internal {
namespace compiler {
class CoalescedLiveRanges;
// A variant of the LLVM Greedy Register Allocator. See
// http://blog.llvm.org/2011/09/greedy-register-allocation-in-llvm-30.html
class GreedyAllocator final : public RegisterAllocator {
public:
explicit GreedyAllocator(RegisterAllocationData* data, RegisterKind kind,
Zone* local_zone);
void AllocateRegisters();
private:
LifetimePosition GetSplittablePos(LifetimePosition pos);
const RegisterConfiguration* config() const { return data()->config(); }
Zone* local_zone() const { return local_zone_; }
int GetHintedRegister(LiveRange* range);
typedef ZonePriorityQueue<std::pair<unsigned, LiveRange*>> PQueue;
unsigned GetLiveRangeSize(LiveRange* range);
void Enqueue(LiveRange* range);
void Evict(LiveRange* range);
float CalculateSpillWeight(LiveRange* range);
float CalculateMaxSpillWeight(const ZoneSet<LiveRange*>& ranges);
bool TryAllocate(LiveRange* current, ZoneSet<LiveRange*>* conflicting);
bool TryAllocatePhysicalRegister(unsigned reg_id, LiveRange* range,
ZoneSet<LiveRange*>* conflicting);
bool HandleSpillOperands(LiveRange* range);
void AllocateBlockedRange(LiveRange* current, LifetimePosition pos,
bool spill);
LiveRange* SpillBetweenUntil(LiveRange* range, LifetimePosition start,
LifetimePosition until, LifetimePosition end);
void AssignRangeToRegister(int reg_id, LiveRange* range);
LifetimePosition FindProgressingSplitPosition(LiveRange* range,
bool* is_spill_pos);
Zone* local_zone_;
ZoneVector<CoalescedLiveRanges*> allocations_;
PQueue queue_;
DISALLOW_COPY_AND_ASSIGN(GreedyAllocator);
};
} // namespace compiler
} // namespace internal
} // namespace v8
#endif // V8_GREEDY_ALLOCATOR_H_
......@@ -20,6 +20,7 @@
#include "src/compiler/frame-elider.h"
#include "src/compiler/graph-replay.h"
#include "src/compiler/graph-visualizer.h"
#include "src/compiler/greedy-allocator.h"
#include "src/compiler/instruction.h"
#include "src/compiler/instruction-selector.h"
#include "src/compiler/js-builtin-reducer.h"
......
This diff is collapsed.
......@@ -607,6 +607,7 @@ class RegisterAllocationData final : public ZoneObject {
PhiMapValue* InitializePhiMap(const InstructionBlock* block,
PhiInstruction* phi);
PhiMapValue* GetPhiMapValueFor(int virtual_register);
bool IsBlockBoundary(LifetimePosition pos) const;
private:
Zone* const allocation_zone_;
......@@ -768,6 +769,8 @@ class RegisterAllocator : public ZoneObject {
LifetimePosition FindOptimalSpillingPos(LiveRange* range,
LifetimePosition pos);
const ZoneVector<LiveRange*>& GetFixedRegisters() const;
private:
RegisterAllocationData* const data_;
const RegisterKind mode_;
......@@ -840,55 +843,6 @@ class LinearScanAllocator final : public RegisterAllocator {
DISALLOW_COPY_AND_ASSIGN(LinearScanAllocator);
};
class CoalescedLiveRanges;
// A variant of the LLVM Greedy Register Allocator. See
// http://blog.llvm.org/2011/09/greedy-register-allocation-in-llvm-30.html
class GreedyAllocator final : public RegisterAllocator {
public:
explicit GreedyAllocator(RegisterAllocationData* data, RegisterKind kind,
Zone* local_zone);
void AllocateRegisters();
private:
LifetimePosition GetSplittablePos(LifetimePosition pos);
const RegisterConfiguration* config() const { return data()->config(); }
Zone* local_zone() const { return local_zone_; }
bool TryReuseSpillForPhi(LiveRange* range);
int GetHintedRegister(LiveRange* range);
typedef ZonePriorityQueue<std::pair<unsigned, LiveRange*>> PQueue;
unsigned GetLiveRangeSize(LiveRange* range);
void Enqueue(LiveRange* range);
void Evict(LiveRange* range);
float CalculateSpillWeight(LiveRange* range);
float CalculateMaxSpillWeight(const ZoneSet<LiveRange*>& ranges);
bool TryAllocate(LiveRange* current, ZoneSet<LiveRange*>* conflicting);
bool TryAllocatePhysicalRegister(unsigned reg_id, LiveRange* range,
ZoneSet<LiveRange*>* conflicting);
bool HandleSpillOperands(LiveRange* range);
void AllocateBlockedRange(LiveRange* current, LifetimePosition pos,
bool spill);
LiveRange* SpillBetweenUntil(LiveRange* range, LifetimePosition start,
LifetimePosition until, LifetimePosition end);
void AssignRangeToRegister(int reg_id, LiveRange* range);
LifetimePosition FindProgressingSplitPosition(LiveRange* range,
bool* is_spill_pos);
Zone* local_zone_;
ZoneVector<CoalescedLiveRanges*> allocations_;
PQueue queue_;
DISALLOW_COPY_AND_ASSIGN(GreedyAllocator);
};
class SpillSlotLocator final : public ZoneObject {
public:
......
......@@ -479,6 +479,8 @@
'../../src/compiler/graph-visualizer.h',
'../../src/compiler/graph.cc',
'../../src/compiler/graph.h',
'../../src/compiler/greedy-allocator.cc',
'../../src/compiler/greedy-allocator.h',
'../../src/compiler/instruction-codes.h',
'../../src/compiler/instruction-selector-impl.h',
'../../src/compiler/instruction-selector.cc',
......
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