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