Commit 28f424bc authored by mstarzinger's avatar mstarzinger Committed by Commit bot

[turbofan] Introduce CallDescriptorOf helper for safety.

This introduces a dedicated getter to extract call descriptors from
operators of call nodes (i.e. call and tail-call) to ensure that all
accesses are const-correct. An implicit cast of constness is undefined
behavior and hard to spot without sanitization.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#35570}
parent dee91da8
......@@ -98,6 +98,11 @@ SelectParameters const& SelectParametersOf(const Operator* const op) {
return OpParameter<SelectParameters>(op);
}
CallDescriptor const* CallDescriptorOf(const Operator* const op) {
DCHECK(op->opcode() == IrOpcode::kCall ||
op->opcode() == IrOpcode::kTailCall);
return OpParameter<CallDescriptor const*>(op);
}
size_t ProjectionIndexOf(const Operator* const op) {
DCHECK_EQ(IrOpcode::kProjection, op->opcode());
......
......@@ -88,6 +88,7 @@ std::ostream& operator<<(std::ostream&, SelectParameters const& p);
SelectParameters const& SelectParametersOf(const Operator* const);
CallDescriptor const* CallDescriptorOf(const Operator* const);
size_t ProjectionIndexOf(const Operator* const);
......
......@@ -1451,7 +1451,7 @@ void InstructionSelector::VisitIfException(Node* node) {
OperandGenerator g(this);
Node* call = node->InputAt(1);
DCHECK_EQ(IrOpcode::kCall, call->opcode());
const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(call);
const CallDescriptor* descriptor = CallDescriptorOf(call->op());
Emit(kArchNop,
g.DefineAsLocation(node, descriptor->GetReturnLocation(0),
descriptor->GetReturnType(0).representation()));
......@@ -1523,7 +1523,7 @@ void InstructionSelector::VisitConstant(Node* node) {
void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
OperandGenerator g(this);
const CallDescriptor* descriptor = OpParameter<const CallDescriptor*>(node);
const CallDescriptor* descriptor = CallDescriptorOf(node->op());
FrameStateDescriptor* frame_state_descriptor = nullptr;
if (descriptor->NeedsFrameState()) {
......@@ -1591,7 +1591,7 @@ void InstructionSelector::VisitCall(Node* node, BasicBlock* handler) {
void InstructionSelector::VisitTailCall(Node* node) {
OperandGenerator g(this);
CallDescriptor const* descriptor = OpParameter<CallDescriptor const*>(node);
CallDescriptor const* descriptor = CallDescriptorOf(node->op());
DCHECK_NE(0, descriptor->flags() & CallDescriptor::kSupportsTailCalls);
DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kPatchableCallSite);
DCHECK_EQ(0, descriptor->flags() & CallDescriptor::kNeedsNopAfterCall);
......
......@@ -225,7 +225,7 @@ void Int64Lowering::LowerNode(Node* node) {
case IrOpcode::kCall: {
// TODO(turbofan): Make WASM code const-correct wrt. CallDescriptor.
CallDescriptor* descriptor =
const_cast<CallDescriptor*>(OpParameter<const CallDescriptor*>(node));
const_cast<CallDescriptor*>(CallDescriptorOf(node->op()));
if (DefaultLowering(node) ||
(descriptor->ReturnCount() == 1 &&
descriptor->GetReturnType(0) == MachineType::Int64())) {
......
......@@ -88,7 +88,7 @@ bool CallDescriptor::HasSameReturnLocationsAs(
bool CallDescriptor::CanTailCall(const Node* node,
int* stack_param_delta) const {
CallDescriptor const* other = OpParameter<CallDescriptor const*>(node);
CallDescriptor const* other = CallDescriptorOf(node->op());
size_t current_input = 0;
size_t other_input = 0;
*stack_param_delta = 0;
......@@ -112,7 +112,7 @@ bool CallDescriptor::CanTailCall(const Node* node,
++current_input;
++other_input;
}
return HasSameReturnLocationsAs(OpParameter<CallDescriptor const*>(node));
return HasSameReturnLocationsAs(CallDescriptorOf(node->op()));
}
......
......@@ -633,7 +633,7 @@ class RepresentationSelector {
}
void VisitCall(Node* node, SimplifiedLowering* lowering) {
const CallDescriptor* desc = OpParameter<const CallDescriptor*>(node->op());
const CallDescriptor* desc = CallDescriptorOf(node->op());
const MachineSignature* sig = desc->GetMachineSignature();
int params = static_cast<int>(sig->parameter_count());
// Propagate representation information from call descriptor.
......
......@@ -20,7 +20,7 @@ Reduction TailCallOptimization::Reduce(Node* node) {
// other effect between the Call and the Return nodes.
Node* const call = NodeProperties::GetValueInput(node, 0);
if (call->opcode() == IrOpcode::kCall &&
OpParameter<CallDescriptor const*>(call)->SupportsTailCalls() &&
CallDescriptorOf(call->op())->SupportsTailCalls() &&
NodeProperties::GetEffectInput(node) == call &&
!NodeProperties::IsExceptionalCall(call)) {
Node* const control = NodeProperties::GetControlInput(node);
......@@ -71,7 +71,7 @@ Reduction TailCallOptimization::Reduce(Node* node) {
NodeProperties::GetValueInput(call, index));
}
NodeProperties::ChangeOp(
node, common()->TailCall(OpParameter<CallDescriptor const*>(call)));
node, common()->TailCall(CallDescriptorOf(call->op())));
return Changed(node);
}
}
......
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