Commit 3e2085eb authored by danno's avatar danno Committed by Commit bot

[turbofan] Add MachineType to LinkageLocation

By adding MachineType to LinkageLocation, it is possible not only to reason
about the location of a LinkageLocation on the stack, but also about it's
size. This will be useful in follow-on CLs that attempt to merge some of the
parameter passing logic of tail calls and normal (non-tail) calls.

As a nice side-effect, it is no longer necessary to separately keep a
MachineSignature in a CallDescriptor, because the MachineTypes contianed in
LinkageLocation for all of the Descriptor's parameters and return types are
sufficient. This CL therefore removes the MachineSignature from the
CallDescriptor and adjusts all the calling code accordingly, simplifying and
de-duplicating code in a bunch of places.

R=titzer@chromium.org, bmeurer@chromium.org
LOG=N

Review-Url: https://codereview.chromium.org/2124023003
Cr-Commit-Position: refs/heads/master@{#37633}
parent bec49a48
......@@ -1476,7 +1476,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -14,8 +14,8 @@ namespace internal {
namespace compiler {
namespace {
LinkageLocation regloc(Register reg) {
return LinkageLocation::ForRegister(reg.code());
LinkageLocation regloc(Register reg, MachineType type) {
return LinkageLocation::ForRegister(reg.code(), type);
}
......@@ -182,10 +182,10 @@ CallDescriptor* Linkage::GetSimplifiedCDescriptor(
CHECK(locations.return_count_ <= 2);
if (locations.return_count_ > 0) {
locations.AddReturn(regloc(kReturnRegister0));
locations.AddReturn(regloc(kReturnRegister0, msig->GetReturn(0)));
}
if (locations.return_count_ > 1) {
locations.AddReturn(regloc(kReturnRegister1));
locations.AddReturn(regloc(kReturnRegister1, msig->GetReturn(1)));
}
const int parameter_count = static_cast<int>(msig->parameter_count());
......@@ -207,10 +207,10 @@ CallDescriptor* Linkage::GetSimplifiedCDescriptor(
// Add register and/or stack parameter(s).
for (int i = 0; i < parameter_count; i++) {
if (i < kParamRegisterCount) {
locations.AddParam(regloc(kParamRegisters[i]));
locations.AddParam(regloc(kParamRegisters[i], msig->GetParam(i)));
} else {
locations.AddParam(
LinkageLocation::ForCallerFrameSlot(-1 - stack_offset));
locations.AddParam(LinkageLocation::ForCallerFrameSlot(
-1 - stack_offset, msig->GetParam(i)));
stack_offset++;
}
}
......@@ -229,7 +229,7 @@ CallDescriptor* Linkage::GetSimplifiedCDescriptor(
// The target for C calls is always an address (i.e. machine pointer).
MachineType target_type = MachineType::Pointer();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
CallDescriptor::Flags flags = CallDescriptor::kUseNativeStack;
if (set_initialize_root_flag) {
flags |= CallDescriptor::kInitializeRootRegister;
......@@ -239,7 +239,6 @@ CallDescriptor* Linkage::GetSimplifiedCDescriptor(
CallDescriptor::kCallAddress, // kind
target_type, // target MachineType
target_loc, // target location
msig, // machine_sig
locations.Build(), // location_sig
0, // stack_parameter_count
Operator::kNoProperties, // properties
......
......@@ -1097,7 +1097,7 @@ void InstructionSelector::EmitPrepareArguments(
InstructionOperand temps[] = {g.TempRegister()};
size_t const temp_count = arraysize(temps);
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr, temp_count, temps);
// Poke any stack arguments.
......
......@@ -68,9 +68,8 @@ class OperandGenerator {
return ConstantOperand(virtual_register);
}
InstructionOperand DefineAsLocation(Node* node, LinkageLocation location,
MachineRepresentation rep) {
return Define(node, ToUnallocatedOperand(location, rep, GetVReg(node)));
InstructionOperand DefineAsLocation(Node* node, LinkageLocation location) {
return Define(node, ToUnallocatedOperand(location, GetVReg(node)));
}
InstructionOperand DefineAsDualLocation(Node* node,
......@@ -144,20 +143,18 @@ class OperandGenerator {
return sequence()->AddImmediate(ToConstant(node));
}
InstructionOperand UseLocation(Node* node, LinkageLocation location,
MachineRepresentation rep) {
return Use(node, ToUnallocatedOperand(location, rep, GetVReg(node)));
InstructionOperand UseLocation(Node* node, LinkageLocation location) {
return Use(node, ToUnallocatedOperand(location, GetVReg(node)));
}
// Used to force gap moves from the from_location to the to_location
// immediately before an instruction.
InstructionOperand UsePointerLocation(LinkageLocation to_location,
LinkageLocation from_location) {
MachineRepresentation rep = MachineType::PointerRepresentation();
UnallocatedOperand casted_from_operand =
UnallocatedOperand::cast(TempLocation(from_location, rep));
UnallocatedOperand::cast(TempLocation(from_location));
selector_->Emit(kArchNop, casted_from_operand);
return ToUnallocatedOperand(to_location, rep,
return ToUnallocatedOperand(to_location,
casted_from_operand.virtual_register());
}
......@@ -185,10 +182,8 @@ class OperandGenerator {
return sequence()->AddImmediate(Constant(imm));
}
InstructionOperand TempLocation(LinkageLocation location,
MachineRepresentation rep) {
return ToUnallocatedOperand(location, rep,
sequence()->NextVirtualRegister());
InstructionOperand TempLocation(LinkageLocation location) {
return ToUnallocatedOperand(location, sequence()->NextVirtualRegister());
}
InstructionOperand Label(BasicBlock* block) {
......@@ -257,7 +252,6 @@ class OperandGenerator {
}
UnallocatedOperand ToUnallocatedOperand(LinkageLocation location,
MachineRepresentation rep,
int virtual_register) {
if (location.IsAnyRegister()) {
// any machine register.
......@@ -275,7 +269,7 @@ class OperandGenerator {
location.AsCalleeFrameSlot(), virtual_register);
}
// a fixed register.
if (IsFloatingPoint(rep)) {
if (IsFloatingPoint(location.GetType().representation())) {
return UnallocatedOperand(UnallocatedOperand::FIXED_FP_REGISTER,
location.AsRegister(), virtual_register);
}
......
......@@ -574,17 +574,17 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
bool output_is_live = buffer->output_nodes[i] != nullptr ||
i < outputs_needed_by_framestate;
if (output_is_live) {
MachineType type =
buffer->descriptor->GetReturnType(static_cast<int>(i));
MachineRepresentation rep =
buffer->descriptor->GetReturnType(static_cast<int>(i))
.representation();
LinkageLocation location =
buffer->descriptor->GetReturnLocation(static_cast<int>(i));
Node* output = buffer->output_nodes[i];
InstructionOperand op =
output == nullptr
? g.TempLocation(location, type.representation())
: g.DefineAsLocation(output, location, type.representation());
MarkAsRepresentation(type.representation(), op);
InstructionOperand op = output == nullptr
? g.TempLocation(location)
: g.DefineAsLocation(output, location);
MarkAsRepresentation(rep, op);
buffer->outputs.push_back(op);
}
......@@ -611,8 +611,7 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
break;
case CallDescriptor::kCallJSFunction:
buffer->instruction_args.push_back(
g.UseLocation(callee, buffer->descriptor->GetInputLocation(0),
buffer->descriptor->GetInputType(0).representation()));
g.UseLocation(callee, buffer->descriptor->GetInputLocation(0)));
break;
}
DCHECK_EQ(1u, buffer->instruction_args.size());
......@@ -679,9 +678,7 @@ void InstructionSelector::InitializeCallBuffer(Node* call, CallBuffer* buffer,
location = LinkageLocation::ConvertToTailCallerLocation(
location, stack_param_delta);
}
InstructionOperand op =
g.UseLocation(*iter, location,
buffer->descriptor->GetInputType(index).representation());
InstructionOperand op = g.UseLocation(*iter, location);
if (UnallocatedOperand::cast(op).HasFixedSlotPolicy() && !call_tail) {
int stack_index = -UnallocatedOperand::cast(op).fixed_slot_index() - 1;
if (static_cast<size_t>(stack_index) >= buffer->pushed_nodes.size()) {
......@@ -1606,9 +1603,7 @@ void InstructionSelector::VisitParameter(Node* node) {
? g.DefineAsDualLocation(
node, linkage()->GetParameterLocation(index),
linkage()->GetParameterSecondaryLocation(index))
: g.DefineAsLocation(
node, linkage()->GetParameterLocation(index),
linkage()->GetParameterType(index).representation());
: g.DefineAsLocation(node, linkage()->GetParameterLocation(index));
Emit(kArchNop, op);
}
......@@ -1619,17 +1614,15 @@ void InstructionSelector::VisitIfException(Node* node) {
Node* call = node->InputAt(1);
DCHECK_EQ(IrOpcode::kCall, call->opcode());
const CallDescriptor* descriptor = CallDescriptorOf(call->op());
Emit(kArchNop,
g.DefineAsLocation(node, descriptor->GetReturnLocation(0),
descriptor->GetReturnType(0).representation()));
Emit(kArchNop, g.DefineAsLocation(node, descriptor->GetReturnLocation(0)));
}
void InstructionSelector::VisitOsrValue(Node* node) {
OperandGenerator g(this);
int index = OpParameter<int>(node);
Emit(kArchNop, g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index),
MachineRepresentation::kTagged));
Emit(kArchNop,
g.DefineAsLocation(node, linkage()->GetOsrValueLocation(index)));
}
......@@ -1737,7 +1730,7 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
case CallDescriptor::kCallAddress:
opcode =
kArchCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount()));
MiscField::encode(static_cast<int>(descriptor->ParameterCount()));
break;
case CallDescriptor::kCallCodeObject:
opcode = kArchCallCodeObject | MiscField::encode(flags);
......@@ -1883,8 +1876,7 @@ void InstructionSelector::VisitReturn(Node* ret) {
auto value_locations = zone()->NewArray<InstructionOperand>(ret_count);
for (int i = 0; i < ret_count; ++i) {
value_locations[i] =
g.UseLocation(ret->InputAt(i), linkage()->GetReturnLocation(i),
linkage()->GetReturnType(i).representation());
g.UseLocation(ret->InputAt(i), linkage()->GetReturnLocation(i));
}
Emit(kArchRet, 0, nullptr, ret_count, value_locations);
}
......
This diff is collapsed.
......@@ -37,56 +37,63 @@ class LinkageLocation {
return !(*this == other);
}
static LinkageLocation ForAnyRegister() {
return LinkageLocation(REGISTER, ANY_REGISTER);
static LinkageLocation ForAnyRegister(
MachineType type = MachineType::None()) {
return LinkageLocation(REGISTER, ANY_REGISTER, type);
}
static LinkageLocation ForRegister(int32_t reg) {
static LinkageLocation ForRegister(int32_t reg,
MachineType type = MachineType::None()) {
DCHECK(reg >= 0);
return LinkageLocation(REGISTER, reg);
return LinkageLocation(REGISTER, reg, type);
}
static LinkageLocation ForCallerFrameSlot(int32_t slot) {
static LinkageLocation ForCallerFrameSlot(int32_t slot, MachineType type) {
DCHECK(slot < 0);
return LinkageLocation(STACK_SLOT, slot);
return LinkageLocation(STACK_SLOT, slot, type);
}
static LinkageLocation ForCalleeFrameSlot(int32_t slot) {
static LinkageLocation ForCalleeFrameSlot(int32_t slot, MachineType type) {
// TODO(titzer): bailout instead of crashing here.
DCHECK(slot >= 0 && slot < LinkageLocation::MAX_STACK_SLOT);
return LinkageLocation(STACK_SLOT, slot);
return LinkageLocation(STACK_SLOT, slot, type);
}
static LinkageLocation ForSavedCallerReturnAddress() {
return ForCalleeFrameSlot((StandardFrameConstants::kCallerPCOffset -
StandardFrameConstants::kCallerPCOffset) /
kPointerSize);
kPointerSize,
MachineType::Pointer());
}
static LinkageLocation ForSavedCallerFramePtr() {
return ForCalleeFrameSlot((StandardFrameConstants::kCallerPCOffset -
StandardFrameConstants::kCallerFPOffset) /
kPointerSize);
kPointerSize,
MachineType::Pointer());
}
static LinkageLocation ForSavedCallerConstantPool() {
DCHECK(V8_EMBEDDED_CONSTANT_POOL);
return ForCalleeFrameSlot((StandardFrameConstants::kCallerPCOffset -
StandardFrameConstants::kConstantPoolOffset) /
kPointerSize);
kPointerSize,
MachineType::AnyTagged());
}
static LinkageLocation ForSavedCallerFunction() {
return ForCalleeFrameSlot((StandardFrameConstants::kCallerPCOffset -
StandardFrameConstants::kFunctionOffset) /
kPointerSize);
kPointerSize,
MachineType::AnyTagged());
}
static LinkageLocation ConvertToTailCallerLocation(
LinkageLocation caller_location, int stack_param_delta) {
if (!caller_location.IsRegister()) {
return LinkageLocation(STACK_SLOT,
caller_location.GetLocation() + stack_param_delta);
caller_location.GetLocation() + stack_param_delta,
caller_location.GetType());
}
return caller_location;
}
......@@ -103,9 +110,22 @@ class LinkageLocation {
static const int32_t ANY_REGISTER = -1;
static const int32_t MAX_STACK_SLOT = 32767;
LinkageLocation(LocationType type, int32_t location) {
LinkageLocation(LocationType type, int32_t location,
MachineType machine_type) {
bit_field_ = TypeField::encode(type) |
((location << LocationField::kShift) & LocationField::kMask);
machine_type_ = machine_type;
}
MachineType GetType() const { return machine_type_; }
int GetSize() const {
return 1 << ElementSizeLog2Of(GetType().representation());
}
int GetSizeInPointers() const {
// Round up
return (GetSize() + kPointerSize - 1) / kPointerSize;
}
int32_t GetLocation() const {
......@@ -134,6 +154,7 @@ class LinkageLocation {
}
int32_t bit_field_;
MachineType machine_type_;
};
typedef Signature<LinkageLocation> LocationSignature;
......@@ -169,7 +190,6 @@ class CallDescriptor final : public ZoneObject {
typedef base::Flags<Flag> Flags;
CallDescriptor(Kind kind, MachineType target_type, LinkageLocation target_loc,
const MachineSignature* machine_sig,
LocationSignature* location_sig, size_t stack_param_count,
Operator::Properties properties,
RegList callee_saved_registers,
......@@ -178,7 +198,6 @@ class CallDescriptor final : public ZoneObject {
: kind_(kind),
target_type_(target_type),
target_loc_(target_loc),
machine_sig_(machine_sig),
location_sig_(location_sig),
stack_param_count_(stack_param_count),
properties_(properties),
......@@ -186,8 +205,6 @@ class CallDescriptor final : public ZoneObject {
callee_saved_fp_registers_(callee_saved_fp_registers),
flags_(flags),
debug_name_(debug_name) {
DCHECK(machine_sig->return_count() == location_sig->return_count());
DCHECK(machine_sig->parameter_count() == location_sig->parameter_count());
}
// Returns the kind of this call.
......@@ -204,10 +221,10 @@ class CallDescriptor final : public ZoneObject {
}
// The number of return values from this call.
size_t ReturnCount() const { return machine_sig_->return_count(); }
size_t ReturnCount() const { return location_sig_->return_count(); }
// The number of C parameters to this call.
size_t CParameterCount() const { return machine_sig_->parameter_count(); }
size_t ParameterCount() const { return location_sig_->parameter_count(); }
// The number of stack parameters to the call.
size_t StackParameterCount() const { return stack_param_count_; }
......@@ -221,7 +238,7 @@ class CallDescriptor final : public ZoneObject {
// The total number of inputs to this call, which includes the target,
// receiver, context, etc.
// TODO(titzer): this should input the framestate input too.
size_t InputCount() const { return 1 + machine_sig_->parameter_count(); }
size_t InputCount() const { return 1 + location_sig_->parameter_count(); }
size_t FrameStateCount() const { return NeedsFrameState() ? 1 : 0; }
......@@ -243,15 +260,19 @@ class CallDescriptor final : public ZoneObject {
return location_sig_->GetParam(index - 1);
}
const MachineSignature* GetMachineSignature() const { return machine_sig_; }
MachineSignature* GetMachineSignature(Zone* zone) const;
MachineType GetReturnType(size_t index) const {
return machine_sig_->GetReturn(index);
return location_sig_->GetReturn(index).GetType();
}
MachineType GetInputType(size_t index) const {
if (index == 0) return target_type_;
return machine_sig_->GetParam(index - 1);
return location_sig_->GetParam(index - 1).GetType();
}
MachineType GetParameterType(size_t index) const {
return location_sig_->GetParam(index).GetType();
}
// Operator properties describe how this call can be optimized, if at all.
......@@ -277,7 +298,6 @@ class CallDescriptor final : public ZoneObject {
const Kind kind_;
const MachineType target_type_;
const LinkageLocation target_loc_;
const MachineSignature* const machine_sig_;
const LocationSignature* const location_sig_;
const size_t stack_param_count_;
const Operator::Properties properties_;
......
......@@ -964,7 +964,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -1370,7 +1370,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -1867,7 +1867,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -142,8 +142,7 @@ void RawMachineAssembler::Comment(const char* msg) {
Node* RawMachineAssembler::CallN(CallDescriptor* desc, Node* function,
Node** args) {
int param_count =
static_cast<int>(desc->GetMachineSignature()->parameter_count());
int param_count = static_cast<int>(desc->ParameterCount());
int input_count = param_count + 1;
Node** buffer = zone()->NewArray<Node*>(input_count);
int index = 0;
......@@ -159,8 +158,7 @@ Node* RawMachineAssembler::CallNWithFrameState(CallDescriptor* desc,
Node* function, Node** args,
Node* frame_state) {
DCHECK(desc->NeedsFrameState());
int param_count =
static_cast<int>(desc->GetMachineSignature()->parameter_count());
int param_count = static_cast<int>(desc->ParameterCount());
int input_count = param_count + 2;
Node** buffer = zone()->NewArray<Node*>(input_count);
int index = 0;
......@@ -251,8 +249,7 @@ Node* RawMachineAssembler::CallRuntime4(Runtime::FunctionId function,
Node* RawMachineAssembler::TailCallN(CallDescriptor* desc, Node* function,
Node** args) {
int param_count =
static_cast<int>(desc->GetMachineSignature()->parameter_count());
int param_count = static_cast<int>(desc->ParameterCount());
int input_count = param_count + 1;
Node** buffer = zone()->NewArray<Node*>(input_count);
int index = 0;
......
......@@ -762,10 +762,7 @@ class RawMachineAssembler {
BasicBlock* CurrentBlock();
Schedule* schedule() { return schedule_; }
size_t parameter_count() const { return machine_sig()->parameter_count(); }
const MachineSignature* machine_sig() const {
return call_descriptor_->GetMachineSignature();
}
size_t parameter_count() const { return call_descriptor_->ParameterCount(); }
Isolate* isolate_;
Graph* graph_;
......
......@@ -1706,7 +1706,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -917,8 +917,7 @@ class RepresentationSelector {
void VisitCall(Node* node, SimplifiedLowering* lowering) {
const CallDescriptor* desc = CallDescriptorOf(node->op());
const MachineSignature* sig = desc->GetMachineSignature();
int params = static_cast<int>(sig->parameter_count());
int params = static_cast<int>(desc->ParameterCount());
// Propagate representation information from call descriptor.
for (int i = 0; i < node->InputCount(); i++) {
if (i == 0) {
......@@ -926,15 +925,14 @@ class RepresentationSelector {
ProcessInput(node, i, UseInfo::None());
} else if ((i - 1) < params) {
ProcessInput(node, i, TruncatingUseInfoFromRepresentation(
sig->GetParam(i - 1).representation()));
desc->GetInputType(i).representation()));
} else {
ProcessInput(node, i, UseInfo::None());
}
}
if (sig->return_count() > 0) {
SetOutput(node,
desc->GetMachineSignature()->GetReturn().representation());
if (desc->ReturnCount() > 0) {
SetOutput(node, desc->GetReturnType(0).representation());
} else {
SetOutput(node, MachineRepresentation::kTagged);
}
......
......@@ -22,6 +22,7 @@ using compiler::CallDescriptor;
using compiler::LinkageLocation;
namespace {
MachineType MachineTypeFor(LocalType type) {
switch (type) {
case kAstI32:
......@@ -40,20 +41,16 @@ MachineType MachineTypeFor(LocalType type) {
}
}
// Platform-specific configuration for C calling convention.
LinkageLocation regloc(Register reg) {
return LinkageLocation::ForRegister(reg.code());
LinkageLocation regloc(Register reg, MachineType type) {
return LinkageLocation::ForRegister(reg.code(), type);
}
LinkageLocation regloc(DoubleRegister reg) {
return LinkageLocation::ForRegister(reg.code());
LinkageLocation regloc(DoubleRegister reg, MachineType type) {
return LinkageLocation::ForRegister(reg.code(), type);
}
LinkageLocation stackloc(int i) {
return LinkageLocation::ForCallerFrameSlot(i);
LinkageLocation stackloc(int i, MachineType type) {
return LinkageLocation::ForCallerFrameSlot(i, type);
}
......@@ -187,23 +184,24 @@ struct Allocator {
if (type == kAstF32) {
int float_reg_code = reg.code() * 2;
DCHECK(float_reg_code < RegisterConfiguration::kMaxFPRegisters);
return regloc(DoubleRegister::from_code(float_reg_code));
return regloc(DoubleRegister::from_code(float_reg_code),
MachineTypeFor(type));
}
#endif
return regloc(reg);
return regloc(reg, MachineTypeFor(type));
} else {
int offset = -1 - stack_offset;
stack_offset += Words(type);
return stackloc(offset);
return stackloc(offset, MachineTypeFor(type));
}
} else {
// Allocate a general purpose register/stack location.
if (gp_offset < gp_count) {
return regloc(gp_regs[gp_offset++]);
return regloc(gp_regs[gp_offset++], MachineTypeFor(type));
} else {
int offset = -1 - stack_offset;
stack_offset += Words(type);
return stackloc(offset);
return stackloc(offset, MachineTypeFor(type));
}
}
}
......@@ -272,8 +270,6 @@ static Allocator GetParameterRegisters() {
// General code uses the above configuration data.
CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
FunctionSig* fsig) {
MachineSignature::Builder msig(zone, fsig->return_count(),
fsig->parameter_count());
LocationSignature::Builder locations(zone, fsig->return_count(),
fsig->parameter_count());
......@@ -283,7 +279,6 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
const int return_count = static_cast<int>(locations.return_count_);
for (int i = 0; i < return_count; i++) {
LocalType ret = fsig->GetReturn(i);
msig.AddReturn(MachineTypeFor(ret));
locations.AddReturn(rets.Next(ret));
}
......@@ -293,7 +288,6 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
const int parameter_count = static_cast<int>(fsig->parameter_count());
for (int i = 0; i < parameter_count; i++) {
LocalType param = fsig->GetParam(i);
msig.AddParam(MachineTypeFor(param));
locations.AddParam(params.Next(param));
}
......@@ -302,13 +296,12 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
// The target for WASM calls is always a code object.
MachineType target_type = MachineType::AnyTagged();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister();
LinkageLocation target_loc = LinkageLocation::ForAnyRegister(target_type);
return new (zone) CallDescriptor( // --
CallDescriptor::kCallCodeObject, // kind
target_type, // target MachineType
target_loc, // target location
msig.Build(), // machine_sig
locations.Build(), // location_sig
params.stack_offset, // stack_parameter_count
compiler::Operator::kNoProperties, // properties
......@@ -320,58 +313,52 @@ CallDescriptor* ModuleEnv::GetWasmCallDescriptor(Zone* zone,
CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor(
Zone* zone, CallDescriptor* descriptor) {
const MachineSignature* signature = descriptor->GetMachineSignature();
size_t parameter_count = signature->parameter_count();
size_t return_count = signature->return_count();
for (size_t i = 0; i < signature->parameter_count(); i++) {
if (signature->GetParam(i) == MachineType::Int64()) {
size_t parameter_count = descriptor->ParameterCount();
size_t return_count = descriptor->ReturnCount();
for (size_t i = 0; i < descriptor->ParameterCount(); i++) {
if (descriptor->GetParameterType(i) == MachineType::Int64()) {
// For each int64 input we get two int32 inputs.
parameter_count++;
}
}
for (size_t i = 0; i < signature->return_count(); i++) {
if (signature->GetReturn(i) == MachineType::Int64()) {
for (size_t i = 0; i < descriptor->ReturnCount(); i++) {
if (descriptor->GetReturnType(i) == MachineType::Int64()) {
// For each int64 return we get two int32 returns.
return_count++;
}
}
if (parameter_count == signature->parameter_count() &&
return_count == signature->return_count()) {
if (parameter_count == descriptor->ParameterCount() &&
return_count == descriptor->ReturnCount()) {
// If there is no int64 parameter or return value, we can just return the
// original descriptor.
return descriptor;
}
MachineSignature::Builder msig(zone, return_count, parameter_count);
LocationSignature::Builder locations(zone, return_count, parameter_count);
Allocator rets = GetReturnRegisters();
for (size_t i = 0; i < signature->return_count(); i++) {
if (signature->GetReturn(i) == MachineType::Int64()) {
for (size_t i = 0; i < descriptor->ReturnCount(); i++) {
if (descriptor->GetReturnType(i) == MachineType::Int64()) {
// For each int64 return we get two int32 returns.
msig.AddReturn(MachineType::Int32());
msig.AddReturn(MachineType::Int32());
locations.AddReturn(rets.Next(MachineRepresentation::kWord32));
locations.AddReturn(rets.Next(MachineRepresentation::kWord32));
} else {
msig.AddReturn(signature->GetReturn(i));
locations.AddReturn(rets.Next(signature->GetReturn(i).representation()));
locations.AddReturn(
rets.Next(descriptor->GetReturnType(i).representation()));
}
}
Allocator params = GetParameterRegisters();
for (size_t i = 0; i < signature->parameter_count(); i++) {
if (signature->GetParam(i) == MachineType::Int64()) {
for (size_t i = 0; i < descriptor->ParameterCount(); i++) {
if (descriptor->GetParameterType(i) == MachineType::Int64()) {
// For each int64 input we get two int32 inputs.
msig.AddParam(MachineType::Int32());
msig.AddParam(MachineType::Int32());
locations.AddParam(params.Next(MachineRepresentation::kWord32));
locations.AddParam(params.Next(MachineRepresentation::kWord32));
} else {
msig.AddParam(signature->GetParam(i));
locations.AddParam(params.Next(signature->GetParam(i).representation()));
locations.AddParam(
params.Next(descriptor->GetParameterType(i).representation()));
}
}
......@@ -379,7 +366,6 @@ CallDescriptor* ModuleEnv::GetI32WasmCallDescriptor(
descriptor->kind(), // kind
descriptor->GetInputType(0), // target MachineType
descriptor->GetInputLocation(0), // target location
msig.Build(), // machine_sig
locations.Build(), // location_sig
params.stack_offset, // stack_parameter_count
descriptor->properties(), // properties
......
......@@ -1431,7 +1431,7 @@ void InstructionSelector::EmitPrepareArguments(
// Prepare for C function call.
if (descriptor->IsCFunctionCall()) {
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr);
// Poke any stack arguments.
......
......@@ -1112,7 +1112,7 @@ void InstructionSelector::EmitPrepareArguments(
InstructionOperand temps[] = {g.TempRegister()};
size_t const temp_count = arraysize(temps);
Emit(kArchPrepareCallCFunction |
MiscField::encode(static_cast<int>(descriptor->CParameterCount())),
MiscField::encode(static_cast<int>(descriptor->ParameterCount())),
0, nullptr, 0, nullptr, temp_count, temps);
// Poke any stack arguments.
......
......@@ -25,24 +25,21 @@ namespace {
CallDescriptor* GetCallDescriptor(Zone* zone, int return_count,
int param_count) {
MachineSignature::Builder msig(zone, return_count, param_count);
LocationSignature::Builder locations(zone, return_count, param_count);
const RegisterConfiguration* config = RegisterConfiguration::Turbofan();
// Add return location(s).
CHECK(return_count <= config->num_allocatable_general_registers());
for (int i = 0; i < return_count; i++) {
msig.AddReturn(MachineType::Int32());
locations.AddReturn(
LinkageLocation::ForRegister(config->allocatable_general_codes()[i]));
locations.AddReturn(LinkageLocation::ForRegister(
config->allocatable_general_codes()[i], MachineType::AnyTagged()));
}
// Add register and/or stack parameter(s).
CHECK(param_count <= config->num_allocatable_general_registers());
for (int i = 0; i < param_count; i++) {
msig.AddParam(MachineType::Int32());
locations.AddParam(
LinkageLocation::ForRegister(config->allocatable_general_codes()[i]));
locations.AddParam(LinkageLocation::ForRegister(
config->allocatable_general_codes()[i], MachineType::AnyTagged()));
}
const RegList kCalleeSaveRegisters = 0;
......@@ -55,7 +52,6 @@ CallDescriptor* GetCallDescriptor(Zone* zone, int return_count,
CallDescriptor::kCallCodeObject, // kind
target_type, // target MachineType
target_loc, // target location
msig.Build(), // machine_sig
locations.Build(), // location_sig
0, // js_parameter_count
compiler::Operator::kNoProperties, // properties
......
......@@ -6428,7 +6428,6 @@ TEST(RunComputedCodeObject) {
CallDescriptor::kCallCodeObject, // kind
MachineType::AnyTagged(), // target_type
c->GetInputLocation(0), // target_loc
&sig, // machine_sig
&loc, // location_sig
0, // stack count
Operator::kNoProperties, // properties
......
......@@ -139,20 +139,20 @@ struct Allocator {
// TODO(bbudge) Modify wasm linkage to allow use of all float regs.
if (type.representation() == MachineRepresentation::kFloat32) code *= 2;
#endif
return LinkageLocation::ForRegister(code);
return LinkageLocation::ForRegister(code, type);
} else {
int offset = -1 - stack_offset;
stack_offset += StackWords(type);
return LinkageLocation::ForCallerFrameSlot(offset);
return LinkageLocation::ForCallerFrameSlot(offset, type);
}
} else {
// Allocate a general purpose register/stack location.
if (gp_offset < gp_count) {
return LinkageLocation::ForRegister(gp_regs[gp_offset++]);
return LinkageLocation::ForRegister(gp_regs[gp_offset++], type);
} else {
int offset = -1 - stack_offset;
stack_offset += StackWords(type);
return LinkageLocation::ForCallerFrameSlot(offset);
return LinkageLocation::ForCallerFrameSlot(offset, type);
}
}
}
......@@ -200,7 +200,6 @@ class RegisterConfig {
CallDescriptor::kCallCodeObject, // kind
target_type, // target MachineType
target_loc, // target location
msig, // machine_sig
locations.Build(), // location_sig
stack_param_count, // stack_parameter_count
compiler::Operator::kNoProperties, // properties
......@@ -271,9 +270,7 @@ Handle<Code> CompileGraph(const char* name, CallDescriptor* desc, Graph* graph,
Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) {
Zone zone(inner->GetIsolate()->allocator());
MachineSignature* msig =
const_cast<MachineSignature*>(desc->GetMachineSignature());
int param_count = static_cast<int>(msig->parameter_count());
int param_count = static_cast<int>(desc->ParameterCount());
GraphAndBuilders caller(&zone);
{
GraphAndBuilders& b = caller;
......@@ -299,6 +296,7 @@ Handle<Code> WrapWithCFunction(Handle<Code> inner, CallDescriptor* desc) {
b.graph()->SetEnd(ret);
}
MachineSignature* msig = desc->GetMachineSignature(&zone);
CallDescriptor* cdesc = Linkage::GetSimplifiedCDescriptor(&zone, msig);
return CompileGraph("wrapper", cdesc, caller.graph());
......@@ -419,7 +417,7 @@ void ArgsBuffer<float64>::Mutate() {
int ParamCount(CallDescriptor* desc) {
return static_cast<int>(desc->GetMachineSignature()->parameter_count());
return static_cast<int>(desc->ParameterCount());
}
......@@ -538,8 +536,7 @@ static void TestInt32Sub(CallDescriptor* desc) {
Handle<Code> inner_code = CompileGraph("Int32Sub", desc, inner.graph());
Handle<Code> wrapper = WrapWithCFunction(inner_code, desc);
MachineSignature* msig =
const_cast<MachineSignature*>(desc->GetMachineSignature());
MachineSignature* msig = desc->GetMachineSignature(&zone);
CodeRunner<int32_t> runnable(isolate, wrapper,
CSignature::FromMachine(&zone, msig));
......
......@@ -174,14 +174,12 @@ TEST_F(EffectControlLinearizerTest, FloatingDiamondsControlWiring) {
// BLOCK 6:
// m2: Merge(t2, f2)
// r1: Return(c1, c2)
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
LinkageLocation::ForRegister(0, MachineType::Pointer()),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags);
Node* p0 = Parameter(0);
......
......@@ -137,13 +137,15 @@ class InstructionSelectorTest : public TestWithContext,
// Add return location(s).
const int return_count = static_cast<int>(msig->return_count());
for (int i = 0; i < return_count; i++) {
locations.AddReturn(LinkageLocation::ForCallerFrameSlot(-1 - i));
locations.AddReturn(
LinkageLocation::ForCallerFrameSlot(-1 - i, msig->GetReturn(i)));
}
// Just put all parameters on the stack.
const int parameter_count = static_cast<int>(msig->parameter_count());
for (int i = 0; i < parameter_count; i++) {
locations.AddParam(LinkageLocation::ForCallerFrameSlot(-1 - i));
locations.AddParam(
LinkageLocation::ForCallerFrameSlot(-1 - i, msig->GetParam(i)));
}
const RegList kCalleeSaveRegisters = 0;
......@@ -155,7 +157,6 @@ class InstructionSelectorTest : public TestWithContext,
CallDescriptor::kCallAddress, // kind
target_type, // target MachineType
target_loc, // target location
msig, // machine_sig
locations.Build(), // location_sig
0, // stack_parameter_count
Operator::kNoProperties, // properties
......
......@@ -26,27 +26,24 @@ class LinkageTailCall : public TestWithZone {
CallDescriptor* NewStandardCallDescriptor(LocationSignature* locations) {
DCHECK(arraysize(kMachineTypes) >=
locations->return_count() + locations->parameter_count());
MachineSignature* types = new (zone()) MachineSignature(
locations->return_count(), locations->parameter_count(), kMachineTypes);
return new (zone()) CallDescriptor(CallDescriptor::kCallCodeObject,
MachineType::AnyTagged(),
LinkageLocation::ForAnyRegister(),
types, // machine_sig
locations, // location_sig
0, // js_parameter_count
Operator::kNoProperties, // properties
0, // callee-saved
0, // callee-saved fp
CallDescriptor::kNoFlags, // flags,
"");
return new (zone()) CallDescriptor(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForAnyRegister(MachineType::Pointer()),
locations, // location_sig
0, // js_parameter_count
Operator::kNoProperties, // properties
0, // callee-saved
0, // callee-saved fp
CallDescriptor::kNoFlags, // flags,
"");
}
LinkageLocation StackLocation(int loc) {
return LinkageLocation::ForCallerFrameSlot(-loc);
return LinkageLocation::ForCallerFrameSlot(-loc, MachineType::Pointer());
}
LinkageLocation RegisterLocation(int loc) {
return LinkageLocation::ForRegister(loc);
return LinkageLocation::ForRegister(loc, MachineType::Pointer());
}
};
......
......@@ -26,14 +26,12 @@ class TailCallOptimizationTest : public GraphTest {
TEST_F(TailCallOptimizationTest, CallCodeObject0) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
LinkageLocation::ForRegister(0, MachineType::Pointer()),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags);
Node* p0 = Parameter(0);
......@@ -48,14 +46,12 @@ TEST_F(TailCallOptimizationTest, CallCodeObject0) {
TEST_F(TailCallOptimizationTest, CallCodeObject1) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
LinkageLocation::ForRegister(0, MachineType::Pointer()),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
Node* p0 = Parameter(0);
......@@ -74,14 +70,12 @@ TEST_F(TailCallOptimizationTest, CallCodeObject1) {
TEST_F(TailCallOptimizationTest, CallCodeObject2) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallCodeObject, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
LinkageLocation::ForRegister(0, MachineType::Pointer()),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
Node* p0 = Parameter(0);
......@@ -98,14 +92,12 @@ TEST_F(TailCallOptimizationTest, CallCodeObject2) {
TEST_F(TailCallOptimizationTest, CallJSFunction0) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
LinkageLocation::ForRegister(0, MachineType::Pointer()),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kNoFlags);
Node* p0 = Parameter(0);
......@@ -120,14 +112,12 @@ TEST_F(TailCallOptimizationTest, CallJSFunction0) {
TEST_F(TailCallOptimizationTest, CallJSFunction1) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
LinkageLocation kLocationSignature[] = {
LinkageLocation::ForRegister(0, MachineType::Pointer()),
LinkageLocation::ForRegister(1, MachineType::Pointer())};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
Node* p0 = Parameter(0);
......@@ -146,14 +136,11 @@ TEST_F(TailCallOptimizationTest, CallJSFunction1) {
TEST_F(TailCallOptimizationTest, CallJSFunction2) {
MachineType kMachineSignature[] = {MachineType::AnyTagged(),
MachineType::AnyTagged()};
LinkageLocation kLocationSignature[] = {LinkageLocation::ForRegister(0),
LinkageLocation::ForRegister(1)};
const CallDescriptor* kCallDescriptor = new (zone()) CallDescriptor(
CallDescriptor::kCallJSFunction, MachineType::AnyTagged(),
LinkageLocation::ForRegister(0),
new (zone()) MachineSignature(1, 1, kMachineSignature),
new (zone()) LocationSignature(1, 1, kLocationSignature), 0,
Operator::kNoProperties, 0, 0, CallDescriptor::kSupportsTailCalls);
Node* p0 = Parameter(0);
......
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