Commit 6f97beb5 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] make zone allocation of InstructionOperand explicit

BUG=

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

Cr-Commit-Position: refs/heads/master@{#26528}
parent 9030a267
...@@ -60,6 +60,10 @@ class InstructionOperand { ...@@ -60,6 +60,10 @@ class InstructionOperand {
ConvertTo(kind, index); ConvertTo(kind, index);
} }
static InstructionOperand* New(Zone* zone, Kind kind, int index) {
return New(zone, InstructionOperand(kind, index));
}
Kind kind() const { return KindField::decode(value_); } Kind kind() const { return KindField::decode(value_); }
int index() const { return static_cast<int>(value_) >> KindField::kSize; } int index() const { return static_cast<int>(value_) >> KindField::kSize; }
#define INSTRUCTION_OPERAND_PREDICATE(name, type) \ #define INSTRUCTION_OPERAND_PREDICATE(name, type) \
...@@ -80,14 +84,13 @@ class InstructionOperand { ...@@ -80,14 +84,13 @@ class InstructionOperand {
if (kind != UNALLOCATED) virtual_register_ = kInvalidVirtualRegister; if (kind != UNALLOCATED) virtual_register_ = kInvalidVirtualRegister;
} }
// TODO(dcarney): get rid of these protected:
void* operator new(size_t, void* location) { return location; } template <typename SubKindOperand>
void* operator new(size_t size, Zone* zone) { static SubKindOperand* New(Zone* zone, const SubKindOperand& op) {
return zone->New(static_cast<int>(size)); void* buffer = zone->New(sizeof(op));
return new (buffer) SubKindOperand(op);
} }
void operator delete(void* pointer, Zone* zone) { UNREACHABLE(); }
protected:
InstructionOperand(Kind kind, int index, int virtual_register) InstructionOperand(Kind kind, int index, int virtual_register)
: virtual_register_(virtual_register) { : virtual_register_(virtual_register) {
ConvertTo(kind, index); ConvertTo(kind, index);
...@@ -166,8 +169,10 @@ class UnallocatedOperand : public InstructionOperand { ...@@ -166,8 +169,10 @@ class UnallocatedOperand : public InstructionOperand {
value_ |= LifetimeField::encode(lifetime); value_ |= LifetimeField::encode(lifetime);
} }
UnallocatedOperand* Copy(Zone* zone) { return New(zone, *this); }
UnallocatedOperand* CopyUnconstrained(Zone* zone) { UnallocatedOperand* CopyUnconstrained(Zone* zone) {
return new (zone) UnallocatedOperand(ANY, virtual_register()); return New(zone, UnallocatedOperand(ANY, virtual_register()));
} }
static const UnallocatedOperand* cast(const InstructionOperand* op) { static const UnallocatedOperand* cast(const InstructionOperand* op) {
...@@ -349,7 +354,7 @@ std::ostream& operator<<(std::ostream& os, const PrintableMoveOperands& mo); ...@@ -349,7 +354,7 @@ std::ostream& operator<<(std::ostream& os, const PrintableMoveOperands& mo);
: InstructionOperand(kOperandKind, index) {} \ : InstructionOperand(kOperandKind, index) {} \
\ \
static SubKind##Operand* New(int index, Zone* zone) { \ static SubKind##Operand* New(int index, Zone* zone) { \
return new (zone) SubKind##Operand(index); \ return InstructionOperand::New(zone, SubKind##Operand(index)); \
} \ } \
\ \
static SubKind##Operand* cast(InstructionOperand* op) { \ static SubKind##Operand* cast(InstructionOperand* op) { \
...@@ -436,7 +441,7 @@ class PointerMap FINAL : public ZoneObject { ...@@ -436,7 +441,7 @@ class PointerMap FINAL : public ZoneObject {
std::ostream& operator<<(std::ostream& os, const PointerMap& pm); std::ostream& operator<<(std::ostream& os, const PointerMap& pm);
// TODO(titzer): s/PointerMap/ReferenceMap/ // TODO(titzer): s/PointerMap/ReferenceMap/
class Instruction : public ZoneObject { class Instruction {
public: public:
size_t OutputCount() const { return OutputCountField::decode(bit_field_); } size_t OutputCount() const { return OutputCountField::decode(bit_field_); }
const InstructionOperand* OutputAt(size_t i) const { const InstructionOperand* OutputAt(size_t i) const {
...@@ -535,12 +540,6 @@ class Instruction : public ZoneObject { ...@@ -535,12 +540,6 @@ class Instruction : public ZoneObject {
pointer_map_ = map; pointer_map_ = map;
} }
// Placement new operator so that we can smash instructions into
// zone-allocated memory.
void* operator new(size_t, void* location) { return location; }
void operator delete(void* pointer, void* location) { UNREACHABLE(); }
void OverwriteWithNop() { void OverwriteWithNop() {
opcode_ = ArchOpcodeField::encode(kArchNop); opcode_ = ArchOpcodeField::encode(kArchNop);
bit_field_ = 0; bit_field_ = 0;
...@@ -559,7 +558,6 @@ class Instruction : public ZoneObject { ...@@ -559,7 +558,6 @@ class Instruction : public ZoneObject {
InstructionOperand* inputs, size_t temp_count, InstructionOperand* inputs, size_t temp_count,
InstructionOperand* temps); InstructionOperand* temps);
protected:
typedef BitField<size_t, 0, 8> OutputCountField; typedef BitField<size_t, 0, 8> OutputCountField;
typedef BitField<size_t, 8, 16> InputCountField; typedef BitField<size_t, 8, 16> InputCountField;
typedef BitField<size_t, 24, 6> TempCountField; typedef BitField<size_t, 24, 6> TempCountField;
...@@ -570,6 +568,9 @@ class Instruction : public ZoneObject { ...@@ -570,6 +568,9 @@ class Instruction : public ZoneObject {
uint32_t bit_field_; uint32_t bit_field_;
PointerMap* pointer_map_; PointerMap* pointer_map_;
InstructionOperand operands_[1]; InstructionOperand operands_[1];
private:
DISALLOW_COPY_AND_ASSIGN(Instruction);
}; };
......
...@@ -29,8 +29,8 @@ MoveOperands* PrepareInsertAfter(ParallelMove* left, MoveOperands* move, ...@@ -29,8 +29,8 @@ MoveOperands* PrepareInsertAfter(ParallelMove* left, MoveOperands* move,
} }
DCHECK(!(replacement == to_eliminate && replacement != nullptr)); DCHECK(!(replacement == to_eliminate && replacement != nullptr));
if (replacement != nullptr) { if (replacement != nullptr) {
auto new_source = new (zone) InstructionOperand( auto new_source = InstructionOperand::New(
replacement->source()->kind(), replacement->source()->index()); zone, replacement->source()->kind(), replacement->source()->index());
move->set_source(new_source); move->set_source(new_source);
} }
return to_eliminate; return to_eliminate;
...@@ -186,8 +186,8 @@ void MoveOptimizer::FinalizeMoves(GapInstruction* gap) { ...@@ -186,8 +186,8 @@ void MoveOptimizer::FinalizeMoves(GapInstruction* gap) {
loads.push_back(move); loads.push_back(move);
// Replace source with copy for later use. // Replace source with copy for later use.
auto dest = move->destination(); auto dest = move->destination();
move->set_destination(new (code_zone()) move->set_destination(
InstructionOperand(dest->kind(), dest->index())); InstructionOperand::New(code_zone(), dest->kind(), dest->index()));
continue; continue;
} }
if ((found->destination()->IsStackSlot() || if ((found->destination()->IsStackSlot() ||
...@@ -199,7 +199,7 @@ void MoveOptimizer::FinalizeMoves(GapInstruction* gap) { ...@@ -199,7 +199,7 @@ void MoveOptimizer::FinalizeMoves(GapInstruction* gap) {
InstructionOperand::Kind found_kind = found->destination()->kind(); InstructionOperand::Kind found_kind = found->destination()->kind();
int found_index = found->destination()->index(); int found_index = found->destination()->index();
auto next_dest = auto next_dest =
new (code_zone()) InstructionOperand(found_kind, found_index); InstructionOperand::New(code_zone(), found_kind, found_index);
auto dest = move->destination(); auto dest = move->destination();
found->destination()->ConvertTo(dest->kind(), dest->index()); found->destination()->ConvertTo(dest->kind(), dest->index());
move->set_destination(next_dest); move->set_destination(next_dest);
......
...@@ -948,7 +948,7 @@ void RegisterAllocator::AssignSpillSlots() { ...@@ -948,7 +948,7 @@ void RegisterAllocator::AssignSpillSlots() {
auto op_kind = kind == DOUBLE_REGISTERS auto op_kind = kind == DOUBLE_REGISTERS
? InstructionOperand::DOUBLE_STACK_SLOT ? InstructionOperand::DOUBLE_STACK_SLOT
: InstructionOperand::STACK_SLOT; : InstructionOperand::STACK_SLOT;
auto op = new (code_zone()) InstructionOperand(op_kind, index); auto op = InstructionOperand::New(code_zone(), op_kind, index);
range->SetOperand(op); range->SetOperand(op);
} }
} }
...@@ -1105,9 +1105,9 @@ void RegisterAllocator::MeetRegisterConstraintsForLastInstructionInBlock( ...@@ -1105,9 +1105,9 @@ void RegisterAllocator::MeetRegisterConstraintsForLastInstructionInBlock(
// Create an unconstrained operand for the same virtual register // Create an unconstrained operand for the same virtual register
// and insert a gap move from the fixed output to the operand. // and insert a gap move from the fixed output to the operand.
UnallocatedOperand* output_copy = new (code_zone()) UnallocatedOperand* output_copy =
UnallocatedOperand(UnallocatedOperand::ANY, output_vreg); UnallocatedOperand(UnallocatedOperand::ANY, output_vreg)
.Copy(code_zone());
AddGapMove(gap_index, GapInstruction::START, output, output_copy); AddGapMove(gap_index, GapInstruction::START, output, output_copy);
} }
} }
......
...@@ -90,7 +90,7 @@ class InstructionTester : public HandleAndZoneScope { ...@@ -90,7 +90,7 @@ class InstructionTester : public HandleAndZoneScope {
} }
UnallocatedOperand* NewUnallocated(int vreg) { UnallocatedOperand* NewUnallocated(int vreg) {
return new (zone()) UnallocatedOperand(UnallocatedOperand::ANY, vreg); return UnallocatedOperand(UnallocatedOperand::ANY, vreg).Copy(zone());
} }
InstructionBlock* BlockAt(BasicBlock* block) { InstructionBlock* BlockAt(BasicBlock* block) {
......
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