Commit 97499e33 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] cleanup PointerMap

rename to ReferenceMap
use ZoneVector for storage
drop dead code

BUG=

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

Cr-Commit-Position: refs/heads/master@{#27785}
parent 6fc394a1
......@@ -166,21 +166,18 @@ bool CodeGenerator::IsNextInAssemblyOrder(RpoNumber block) const {
}
void CodeGenerator::RecordSafepoint(PointerMap* pointers, Safepoint::Kind kind,
int arguments,
void CodeGenerator::RecordSafepoint(ReferenceMap* references,
Safepoint::Kind kind, int arguments,
Safepoint::DeoptMode deopt_mode) {
const ZoneList<InstructionOperand*>* operands =
pointers->GetNormalizedOperands();
Safepoint safepoint =
safepoints()->DefineSafepoint(masm(), kind, arguments, deopt_mode);
for (int i = 0; i < operands->length(); i++) {
InstructionOperand* pointer = operands->at(i);
if (pointer->IsStackSlot()) {
safepoint.DefinePointerSlot(StackSlotOperand::cast(pointer)->index(),
for (auto& operand : references->reference_operands()) {
if (operand.IsStackSlot()) {
safepoint.DefinePointerSlot(StackSlotOperand::cast(operand).index(),
zone());
} else if (pointer->IsRegister() && (kind & Safepoint::kWithRegisters)) {
Register reg = Register::FromAllocationIndex(
RegisterOperand::cast(pointer)->index());
} else if (operand.IsRegister() && (kind & Safepoint::kWithRegisters)) {
Register reg =
Register::FromAllocationIndex(RegisterOperand::cast(operand).index());
safepoint.DefinePointerRegister(reg, zone());
}
}
......@@ -339,7 +336,7 @@ void CodeGenerator::RecordCallPosition(Instruction* instr) {
bool needs_frame_state = (flags & CallDescriptor::kNeedsFrameState);
RecordSafepoint(
instr->pointer_map(), Safepoint::kSimple, 0,
instr->reference_map(), Safepoint::kSimple, 0,
needs_frame_state ? Safepoint::kLazyDeopt : Safepoint::kNoLazyDeopt);
if (flags & CallDescriptor::kHasExceptionHandler) {
......
......@@ -55,7 +55,7 @@ class CodeGenerator FINAL : public GapResolver::Assembler {
bool IsNextInAssemblyOrder(RpoNumber block) const;
// Record a safepoint with the given pointer map.
void RecordSafepoint(PointerMap* pointers, Safepoint::Kind kind,
void RecordSafepoint(ReferenceMap* references, Safepoint::Kind kind,
int arguments, Safepoint::DeoptMode deopt_mode);
// Assemble code for the specified instruction.
......
......@@ -126,7 +126,7 @@ Instruction::Instruction(InstructionCode opcode)
: opcode_(opcode),
bit_field_(OutputCountField::encode(0) | InputCountField::encode(0) |
TempCountField::encode(0) | IsCallField::encode(false)),
pointer_map_(NULL) {
reference_map_(NULL) {
parallel_moves_[0] = nullptr;
parallel_moves_[1] = nullptr;
}
......@@ -141,7 +141,7 @@ Instruction::Instruction(InstructionCode opcode, size_t output_count,
InputCountField::encode(input_count) |
TempCountField::encode(temp_count) |
IsCallField::encode(false)),
pointer_map_(NULL) {
reference_map_(NULL) {
parallel_moves_[0] = nullptr;
parallel_moves_[1] = nullptr;
size_t offset = 0;
......@@ -187,42 +187,27 @@ std::ostream& operator<<(std::ostream& os,
}
void PointerMap::RecordPointer(InstructionOperand* op, Zone* zone) {
void ReferenceMap::RecordReference(const InstructionOperand& op) {
// Do not record arguments as pointers.
if (op->IsStackSlot() && StackSlotOperand::cast(op)->index() < 0) return;
DCHECK(!op->IsDoubleRegister() && !op->IsDoubleStackSlot());
pointer_operands_.Add(op, zone);
if (op.IsStackSlot() && StackSlotOperand::cast(op).index() < 0) return;
DCHECK(!op.IsDoubleRegister() && !op.IsDoubleStackSlot());
reference_operands_.push_back(op);
}
void PointerMap::RemovePointer(InstructionOperand* op) {
// Do not record arguments as pointers.
if (op->IsStackSlot() && StackSlotOperand::cast(op)->index() < 0) return;
DCHECK(!op->IsDoubleRegister() && !op->IsDoubleStackSlot());
for (int i = 0; i < pointer_operands_.length(); ++i) {
if (pointer_operands_[i]->Equals(op)) {
pointer_operands_.Remove(i);
--i;
}
}
}
void PointerMap::RecordUntagged(InstructionOperand* op, Zone* zone) {
// Do not record arguments as pointers.
if (op->IsStackSlot() && StackSlotOperand::cast(op)->index() < 0) return;
DCHECK(!op->IsDoubleRegister() && !op->IsDoubleStackSlot());
untagged_operands_.Add(op, zone);
}
std::ostream& operator<<(std::ostream& os, const PointerMap& pm) {
std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm) {
os << "{";
for (ZoneList<InstructionOperand*>::iterator op =
pm.pointer_operands_.begin();
op != pm.pointer_operands_.end(); ++op) {
if (op != pm.pointer_operands_.begin()) os << ";";
os << *op;
bool first = true;
PrintableInstructionOperand poi = {RegisterConfiguration::ArchDefault(),
nullptr};
for (auto& op : pm.reference_operands_) {
if (!first) {
os << ";";
} else {
first = false;
}
poi.op_ = &op;
os << poi;
}
return os << "}";
}
......@@ -501,7 +486,7 @@ InstructionSequence::InstructionSequence(Isolate* isolate,
immediates_(zone()),
instructions_(zone()),
next_virtual_register_(0),
pointer_maps_(zone()),
reference_maps_(zone()),
doubles_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())),
references_(std::less<int>(), VirtualRegisterSet::allocator_type(zone())),
deoptimization_entries_(zone()) {
......@@ -546,12 +531,12 @@ void InstructionSequence::EndBlock(RpoNumber rpo) {
int InstructionSequence::AddInstruction(Instruction* instr) {
int index = static_cast<int>(instructions_.size());
instructions_.push_back(instr);
if (instr->NeedsPointerMap()) {
DCHECK(instr->pointer_map() == NULL);
PointerMap* pointer_map = new (zone()) PointerMap(zone());
pointer_map->set_instruction_position(index);
instr->set_pointer_map(pointer_map);
pointer_maps_.push_back(pointer_map);
if (instr->NeedsReferenceMap()) {
DCHECK(instr->reference_map() == NULL);
ReferenceMap* reference_map = new (zone()) ReferenceMap(zone());
reference_map->set_instruction_position(index);
instr->set_reference_map(reference_map);
reference_maps_.push_back(reference_map);
}
return index;
}
......
......@@ -518,19 +518,13 @@ struct PrintableParallelMove {
std::ostream& operator<<(std::ostream& os, const PrintableParallelMove& pm);
class PointerMap FINAL : public ZoneObject {
class ReferenceMap FINAL : public ZoneObject {
public:
explicit PointerMap(Zone* zone)
: pointer_operands_(8, zone),
untagged_operands_(0, zone),
instruction_position_(-1) {}
const ZoneList<InstructionOperand*>* GetNormalizedOperands() {
for (int i = 0; i < untagged_operands_.length(); ++i) {
RemovePointer(untagged_operands_[i]);
}
untagged_operands_.Clear();
return &pointer_operands_;
explicit ReferenceMap(Zone* zone)
: reference_operands_(8, zone), instruction_position_(-1) {}
const ZoneVector<InstructionOperand>& reference_operands() const {
return reference_operands_;
}
int instruction_position() const { return instruction_position_; }
......@@ -539,21 +533,17 @@ class PointerMap FINAL : public ZoneObject {
instruction_position_ = pos;
}
void RecordPointer(InstructionOperand* op, Zone* zone);
void RemovePointer(InstructionOperand* op);
void RecordUntagged(InstructionOperand* op, Zone* zone);
void RecordReference(const InstructionOperand& op);
private:
friend std::ostream& operator<<(std::ostream& os, const PointerMap& pm);
friend std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm);
ZoneList<InstructionOperand*> pointer_operands_;
ZoneList<InstructionOperand*> untagged_operands_;
ZoneVector<InstructionOperand> reference_operands_;
int instruction_position_;
};
std::ostream& operator<<(std::ostream& os, const PointerMap& pm);
std::ostream& operator<<(std::ostream& os, const ReferenceMap& pm);
// TODO(titzer): s/PointerMap/ReferenceMap/
class Instruction {
public:
size_t OutputCount() const { return OutputCountField::decode(bit_field_); }
......@@ -627,8 +617,8 @@ class Instruction {
return this;
}
bool IsCall() const { return IsCallField::decode(bit_field_); }
bool NeedsPointerMap() const { return IsCall(); }
bool HasPointerMap() const { return pointer_map_ != NULL; }
bool NeedsReferenceMap() const { return IsCall(); }
bool HasReferenceMap() const { return reference_map_ != NULL; }
bool IsSourcePosition() const {
return opcode() == kSourcePositionInstruction;
......@@ -637,18 +627,18 @@ class Instruction {
bool ClobbersRegisters() const { return IsCall(); }
bool ClobbersTemps() const { return IsCall(); }
bool ClobbersDoubleRegisters() const { return IsCall(); }
PointerMap* pointer_map() const { return pointer_map_; }
ReferenceMap* reference_map() const { return reference_map_; }
void set_pointer_map(PointerMap* map) {
DCHECK(NeedsPointerMap());
DCHECK(!pointer_map_);
pointer_map_ = map;
void set_reference_map(ReferenceMap* map) {
DCHECK(NeedsReferenceMap());
DCHECK(!reference_map_);
reference_map_ = map;
}
void OverwriteWithNop() {
opcode_ = ArchOpcodeField::encode(kArchNop);
bit_field_ = 0;
pointer_map_ = NULL;
reference_map_ = NULL;
}
bool IsNop() const {
......@@ -700,7 +690,7 @@ class Instruction {
InstructionCode opcode_;
uint32_t bit_field_;
ParallelMove* parallel_moves_[2];
PointerMap* pointer_map_;
ReferenceMap* reference_map_;
InstructionOperand operands_[1];
private:
......@@ -987,7 +977,7 @@ typedef std::map<int, Constant, std::less<int>,
zone_allocator<std::pair<int, Constant> > > ConstantMap;
typedef ZoneDeque<Instruction*> InstructionDeque;
typedef ZoneDeque<PointerMap*> PointerMapDeque;
typedef ZoneDeque<ReferenceMap*> ReferenceMapDeque;
typedef ZoneVector<FrameStateDescriptor*> DeoptimizationVector;
typedef ZoneVector<InstructionBlock*> InstructionBlocks;
......@@ -1053,7 +1043,7 @@ class InstructionSequence FINAL : public ZoneObject {
}
Isolate* isolate() const { return isolate_; }
const PointerMapDeque* pointer_maps() const { return &pointer_maps_; }
const ReferenceMapDeque* reference_maps() const { return &reference_maps_; }
Zone* zone() const { return zone_; }
// Used by the instruction selector while adding instructions.
......@@ -1133,7 +1123,7 @@ class InstructionSequence FINAL : public ZoneObject {
Immediates immediates_;
InstructionDeque instructions_;
int next_virtual_register_;
PointerMapDeque pointer_maps_;
ReferenceMapDeque reference_maps_;
VirtualRegisterSet doubles_;
VirtualRegisterSet references_;
DeoptimizationVector deoptimization_entries_;
......
......@@ -737,11 +737,11 @@ struct CommitAssignmentPhase {
};
struct PopulatePointerMapsPhase {
struct PopulateReferenceMapsPhase {
static const char* phase_name() { return "populate pointer maps"; }
void Run(PipelineData* data, Zone* temp_zone) {
data->register_allocator()->PopulatePointerMaps();
data->register_allocator()->PopulateReferenceMaps();
}
};
......@@ -1217,7 +1217,7 @@ void Pipeline::AllocateRegisters(const RegisterConfiguration* config,
Run<AssignSpillSlotsPhase>();
Run<CommitAssignmentPhase>();
Run<PopulatePointerMapsPhase>();
Run<PopulateReferenceMapsPhase>();
Run<ConnectRangesPhase>();
Run<ResolveControlFlowPhase>();
if (FLAG_turbo_move_optimization) {
......
......@@ -722,8 +722,8 @@ InstructionOperand* RegisterAllocator::AllocateFixed(
if (is_tagged) {
TRACE("Fixed reg is tagged at %d\n", pos);
auto instr = InstructionAt(pos);
if (instr->HasPointerMap()) {
instr->pointer_map()->RecordPointer(operand, code_zone());
if (instr->HasReferenceMap()) {
instr->reference_map()->RecordReference(*operand);
}
}
return operand;
......@@ -1226,8 +1226,8 @@ void RegisterAllocator::MeetConstraintsBefore(int instr_index) {
cur_input->set_virtual_register(second_output->virtual_register());
AddGapMove(instr_index, Instruction::END, input_copy, cur_input);
if (HasTaggedValue(input_vreg) && !HasTaggedValue(output_vreg)) {
if (second->HasPointerMap()) {
second->pointer_map()->RecordPointer(input_copy, code_zone());
if (second->HasReferenceMap()) {
second->reference_map()->RecordReference(*input_copy);
}
} else if (!HasTaggedValue(input_vreg) && HasTaggedValue(output_vreg)) {
// The input is assumed to immediately have a tagged representation,
......@@ -1411,8 +1411,8 @@ void RegisterAllocator::ResolvePhis(const InstructionBlock* block) {
code()->InstructionBlockAt(block->predecessors()[i]);
AddGapMove(cur_block->last_instruction_index(), Instruction::END,
&phi->inputs()[i], &output);
DCHECK(
!InstructionAt(cur_block->last_instruction_index())->HasPointerMap());
DCHECK(!InstructionAt(cur_block->last_instruction_index())
->HasReferenceMap());
}
auto live_range = LiveRangeFor(phi_vreg);
int gap_index = block->first_instruction_index();
......@@ -1700,7 +1700,7 @@ void RegisterAllocator::ResolveControlFlow(const InstructionBlock* block,
position = Instruction::START;
} else {
DCHECK(pred->SuccessorCount() == 1);
DCHECK(!InstructionAt(pred->last_instruction_index())->HasPointerMap());
DCHECK(!InstructionAt(pred->last_instruction_index())->HasReferenceMap());
gap_index = pred->last_instruction_index();
position = Instruction::END;
}
......@@ -1822,7 +1822,7 @@ bool RegisterAllocator::ExistsUseWithoutDefinition() {
bool RegisterAllocator::SafePointsAreInOrder() const {
int safe_point = 0;
for (auto map : *code()->pointer_maps()) {
for (auto map : *code()->reference_maps()) {
if (safe_point > map->instruction_position()) return false;
safe_point = map->instruction_position();
}
......@@ -1830,14 +1830,14 @@ bool RegisterAllocator::SafePointsAreInOrder() const {
}
void RegisterAllocator::PopulatePointerMaps() {
void RegisterAllocator::PopulateReferenceMaps() {
DCHECK(SafePointsAreInOrder());
// Iterate over all safe point positions and record a pointer
// for all spilled live ranges at this point.
int last_range_start = 0;
auto pointer_maps = code()->pointer_maps();
PointerMapDeque::const_iterator first_it = pointer_maps->begin();
auto reference_maps = code()->reference_maps();
ReferenceMapDeque::const_iterator first_it = reference_maps->begin();
for (LiveRange* range : live_ranges()) {
if (range == nullptr) continue;
// Iterate over the first parts of multi-part live ranges.
......@@ -1859,18 +1859,18 @@ void RegisterAllocator::PopulatePointerMaps() {
// Most of the ranges are in order, but not all. Keep an eye on when they
// step backwards and reset the first_it so we don't miss any safe points.
if (start < last_range_start) first_it = pointer_maps->begin();
if (start < last_range_start) first_it = reference_maps->begin();
last_range_start = start;
// Step across all the safe points that are before the start of this range,
// recording how far we step in order to save doing this for the next range.
for (; first_it != pointer_maps->end(); ++first_it) {
for (; first_it != reference_maps->end(); ++first_it) {
auto map = *first_it;
if (map->instruction_position() >= start) break;
}
// Step through the safe points to see whether they are in the range.
for (auto it = first_it; it != pointer_maps->end(); ++it) {
for (auto it = first_it; it != reference_maps->end(); ++it) {
auto map = *it;
int safe_point = map->instruction_position();
......@@ -1894,7 +1894,7 @@ void RegisterAllocator::PopulatePointerMaps() {
!range->GetSpillOperand()->IsConstant()) {
TRACE("Pointer for range %d (spilled at %d) at safe point %d\n",
range->id(), range->spill_start_index(), safe_point);
map->RecordPointer(range->GetSpillOperand(), code_zone());
map->RecordReference(*range->GetSpillOperand());
}
if (!cur->IsSpilled()) {
......@@ -1902,9 +1902,9 @@ void RegisterAllocator::PopulatePointerMaps() {
"Pointer in register for range %d (start at %d) "
"at safe point %d\n",
cur->id(), cur->Start().Value(), safe_point);
InstructionOperand* operand = cur->GetAssignedOperand(operand_cache());
DCHECK(!operand->IsStackSlot());
map->RecordPointer(operand, code_zone());
auto operand = cur->GetAssignedOperand();
DCHECK(!operand.IsStackSlot());
map->RecordReference(operand);
}
}
}
......
......@@ -480,7 +480,7 @@ class RegisterAllocator FINAL : public ZoneObject {
void CommitAssignment();
// Phase 7: compute values for pointer maps.
void PopulatePointerMaps(); // TODO(titzer): rename to PopulateReferenceMaps.
void PopulateReferenceMaps();
// Phase 8: reconnect split ranges with moves.
void ConnectRanges();
......
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