Commit 8392d9c4 authored by dcarney's avatar dcarney Committed by Commit bot

[turbofan] Make AllocatedOperand an InstructionOperand::Kind.

This is preparatory work to have MachineTypes encoded in AllocatedOperands.

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

Cr-Commit-Position: refs/heads/master@{#27698}
parent f190a6d2
......@@ -46,19 +46,22 @@ std::ostream& operator<<(std::ostream& os,
<< "]";
case InstructionOperand::IMMEDIATE:
return os << "[immediate:" << ImmediateOperand::cast(op).index() << "]";
case InstructionOperand::STACK_SLOT:
return os << "[stack:" << StackSlotOperand::cast(op).index() << "]";
case InstructionOperand::DOUBLE_STACK_SLOT:
return os << "[double_stack:" << DoubleStackSlotOperand::cast(op).index()
<< "]";
case InstructionOperand::REGISTER:
return os << "["
<< conf->general_register_name(
RegisterOperand::cast(op).index()) << "|R]";
case InstructionOperand::DOUBLE_REGISTER:
return os << "["
<< conf->double_register_name(
DoubleRegisterOperand::cast(op).index()) << "|R]";
case InstructionOperand::ALLOCATED:
switch (AllocatedOperand::cast(op).allocated_kind()) {
case AllocatedOperand::STACK_SLOT:
return os << "[stack:" << StackSlotOperand::cast(op).index() << "]";
case AllocatedOperand::DOUBLE_STACK_SLOT:
return os << "[double_stack:"
<< DoubleStackSlotOperand::cast(op).index() << "]";
case AllocatedOperand::REGISTER:
return os << "["
<< conf->general_register_name(
RegisterOperand::cast(op).index()) << "|R]";
case AllocatedOperand::DOUBLE_REGISTER:
return os << "["
<< conf->double_register_name(
DoubleRegisterOperand::cast(op).index()) << "|R]";
}
case InstructionOperand::INVALID:
return os << "(x)";
}
......
This diff is collapsed.
......@@ -707,13 +707,13 @@ InstructionOperand* RegisterAllocator::AllocateFixed(
DCHECK(operand->HasFixedPolicy());
InstructionOperand allocated;
if (operand->HasFixedSlotPolicy()) {
allocated = AllocatedOperand(InstructionOperand::STACK_SLOT,
allocated = AllocatedOperand(AllocatedOperand::STACK_SLOT,
operand->fixed_slot_index());
} else if (operand->HasFixedRegisterPolicy()) {
allocated = AllocatedOperand(InstructionOperand::REGISTER,
allocated = AllocatedOperand(AllocatedOperand::REGISTER,
operand->fixed_register_index());
} else if (operand->HasFixedDoubleRegisterPolicy()) {
allocated = AllocatedOperand(InstructionOperand::DOUBLE_REGISTER,
allocated = AllocatedOperand(AllocatedOperand::DOUBLE_REGISTER,
operand->fixed_register_index());
} else {
UNREACHABLE();
......@@ -976,8 +976,8 @@ void RegisterAllocator::AssignSpillSlots() {
auto kind = range->Kind();
int index = frame()->AllocateSpillSlot(kind == DOUBLE_REGISTERS);
auto op_kind = kind == DOUBLE_REGISTERS
? InstructionOperand::DOUBLE_STACK_SLOT
: InstructionOperand::STACK_SLOT;
? AllocatedOperand::DOUBLE_STACK_SLOT
: AllocatedOperand::STACK_SLOT;
auto op = AllocatedOperand::New(code_zone(), op_kind, index);
range->SetOperand(op);
}
......
......@@ -32,8 +32,28 @@ class InterpreterState {
}
private:
struct Key {
bool is_constant;
AllocatedOperand::AllocatedKind kind;
int index;
bool operator<(const Key& other) const {
if (this->is_constant != other.is_constant) {
return this->is_constant;
}
if (this->kind != other.kind) {
return this->kind < other.kind;
}
return this->index < other.index;
}
bool operator==(const Key& other) const {
return this->is_constant == other.is_constant &&
this->kind == other.kind && this->index == other.index;
}
};
// Internally, the state is a normalized permutation of (kind,index) pairs.
typedef std::pair<InstructionOperand::Kind, int> Key;
typedef Key Value;
typedef std::map<Key, Value> OperandMap;
......@@ -51,22 +71,27 @@ class InterpreterState {
}
static Key KeyFor(const InstructionOperand* op) {
int v = op->IsConstant() ? ConstantOperand::cast(op)->virtual_register()
: AllocatedOperand::cast(op)->index();
return Key(op->kind(), v);
bool is_constant = op->IsConstant();
AllocatedOperand::AllocatedKind kind;
int index;
if (!is_constant) {
index = AllocatedOperand::cast(op)->index();
kind = AllocatedOperand::cast(op)->allocated_kind();
} else {
index = ConstantOperand::cast(op)->virtual_register();
kind = AllocatedOperand::REGISTER;
}
Key key = {is_constant, kind, index};
return key;
}
static Value ValueFor(const InstructionOperand* op) {
int v = op->IsConstant() ? ConstantOperand::cast(op)->virtual_register()
: AllocatedOperand::cast(op)->index();
return Value(op->kind(), v);
}
static Value ValueFor(const InstructionOperand* op) { return KeyFor(op); }
static InstructionOperand FromKey(Key key) {
if (key.first == InstructionOperand::CONSTANT) {
return ConstantOperand(key.second);
if (key.is_constant) {
return ConstantOperand(key.index);
}
return AllocatedOperand(key.first, key.second);
return AllocatedOperand(key.kind, key.index);
}
friend std::ostream& operator<<(std::ostream& os,
......
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