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