Skip to content

Commit b65a272

Browse files
nico-hartmannV8 LUCI CQ
authored andcommitted
[compiler] Generalize InstructionSelectorT for Turboshaft (part 12)
This CL ports more of the instruction selector implementation to support Turboshaft. In particular, the handling of: - TryChange Bug: v8:12783 Change-Id: Icd15fc770967bf5381766ba67a5dec4edccef7c4 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4770774 Reviewed-by: Darius Mercadier <dmercadier@chromium.org> Commit-Queue: Nico Hartmann <nicohartmann@chromium.org> Cr-Commit-Position: refs/heads/main@{#89497}
1 parent a01e3a5 commit b65a272

6 files changed

Lines changed: 177 additions & 141 deletions

File tree

src/compiler/backend/arm64/instruction-selector-arm64.cc

Lines changed: 93 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2338,20 +2338,25 @@ void InstructionSelectorT<Adapter>::VisitTruncateFloat32ToUint32(node_t node) {
23382338
}
23392339

23402340
template <typename Adapter>
2341-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat32ToInt64(Node* node) {
2342-
Arm64OperandGeneratorT<Adapter> g(this);
2341+
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat32ToInt64(
2342+
node_t node) {
2343+
if constexpr (Adapter::IsTurboshaft) {
2344+
UNIMPLEMENTED();
2345+
} else {
2346+
Arm64OperandGeneratorT<Adapter> g(this);
23432347

2344-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2345-
InstructionOperand outputs[2];
2346-
size_t output_count = 0;
2347-
outputs[output_count++] = g.DefineAsRegister(node);
2348+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2349+
InstructionOperand outputs[2];
2350+
size_t output_count = 0;
2351+
outputs[output_count++] = g.DefineAsRegister(node);
23482352

2349-
Node* success_output = NodeProperties::FindProjection(node, 1);
2350-
if (success_output) {
2351-
outputs[output_count++] = g.DefineAsRegister(success_output);
2352-
}
2353+
Node* success_output = NodeProperties::FindProjection(node, 1);
2354+
if (success_output) {
2355+
outputs[output_count++] = g.DefineAsRegister(success_output);
2356+
}
23532357

2354-
Emit(kArm64Float32ToInt64, output_count, outputs, 1, inputs);
2358+
Emit(kArm64Float32ToInt64, output_count, outputs, 1, inputs);
2359+
}
23552360
}
23562361

23572362
template <typename Adapter>
@@ -2372,89 +2377,111 @@ void InstructionSelectorT<Adapter>::VisitTruncateFloat64ToInt64(node_t node) {
23722377
}
23732378

23742379
template <typename Adapter>
2375-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt64(Node* node) {
2376-
Arm64OperandGeneratorT<Adapter> g(this);
2380+
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt64(
2381+
node_t node) {
2382+
if constexpr (Adapter::IsTurboshaft) {
2383+
UNIMPLEMENTED();
2384+
} else {
2385+
Arm64OperandGeneratorT<Adapter> g(this);
23772386

2378-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2379-
InstructionOperand outputs[2];
2380-
size_t output_count = 0;
2381-
outputs[output_count++] = g.DefineAsRegister(node);
2387+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2388+
InstructionOperand outputs[2];
2389+
size_t output_count = 0;
2390+
outputs[output_count++] = g.DefineAsRegister(node);
23822391

2383-
Node* success_output = NodeProperties::FindProjection(node, 1);
2384-
if (success_output) {
2385-
outputs[output_count++] = g.DefineAsRegister(success_output);
2386-
}
2392+
Node* success_output = NodeProperties::FindProjection(node, 1);
2393+
if (success_output) {
2394+
outputs[output_count++] = g.DefineAsRegister(success_output);
2395+
}
23872396

2388-
Emit(kArm64Float64ToInt64, output_count, outputs, 1, inputs);
2397+
Emit(kArm64Float64ToInt64, output_count, outputs, 1, inputs);
2398+
}
23892399
}
23902400

23912401
template <typename Adapter>
23922402
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat32ToUint64(
2393-
Node* node) {
2394-
Arm64OperandGeneratorT<Adapter> g(this);
2403+
node_t node) {
2404+
if constexpr (Adapter::IsTurboshaft) {
2405+
UNIMPLEMENTED();
2406+
} else {
2407+
Arm64OperandGeneratorT<Adapter> g(this);
23952408

2396-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2397-
InstructionOperand outputs[2];
2398-
size_t output_count = 0;
2399-
outputs[output_count++] = g.DefineAsRegister(node);
2409+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2410+
InstructionOperand outputs[2];
2411+
size_t output_count = 0;
2412+
outputs[output_count++] = g.DefineAsRegister(node);
24002413

2401-
Node* success_output = NodeProperties::FindProjection(node, 1);
2402-
if (success_output) {
2403-
outputs[output_count++] = g.DefineAsRegister(success_output);
2404-
}
2414+
Node* success_output = NodeProperties::FindProjection(node, 1);
2415+
if (success_output) {
2416+
outputs[output_count++] = g.DefineAsRegister(success_output);
2417+
}
24052418

2406-
Emit(kArm64Float32ToUint64, output_count, outputs, 1, inputs);
2419+
Emit(kArm64Float32ToUint64, output_count, outputs, 1, inputs);
2420+
}
24072421
}
24082422

24092423
template <typename Adapter>
24102424
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToUint64(
2411-
Node* node) {
2412-
Arm64OperandGeneratorT<Adapter> g(this);
2425+
node_t node) {
2426+
if constexpr (Adapter::IsTurboshaft) {
2427+
UNIMPLEMENTED();
2428+
} else {
2429+
Arm64OperandGeneratorT<Adapter> g(this);
24132430

2414-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2415-
InstructionOperand outputs[2];
2416-
size_t output_count = 0;
2417-
outputs[output_count++] = g.DefineAsRegister(node);
2431+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2432+
InstructionOperand outputs[2];
2433+
size_t output_count = 0;
2434+
outputs[output_count++] = g.DefineAsRegister(node);
24182435

2419-
Node* success_output = NodeProperties::FindProjection(node, 1);
2420-
if (success_output) {
2421-
outputs[output_count++] = g.DefineAsRegister(success_output);
2422-
}
2436+
Node* success_output = NodeProperties::FindProjection(node, 1);
2437+
if (success_output) {
2438+
outputs[output_count++] = g.DefineAsRegister(success_output);
2439+
}
24232440

2424-
Emit(kArm64Float64ToUint64, output_count, outputs, 1, inputs);
2441+
Emit(kArm64Float64ToUint64, output_count, outputs, 1, inputs);
2442+
}
24252443
}
24262444

24272445
template <typename Adapter>
2428-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt32(Node* node) {
2429-
Arm64OperandGeneratorT<Adapter> g(this);
2430-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2431-
InstructionOperand outputs[2];
2432-
size_t output_count = 0;
2433-
outputs[output_count++] = g.DefineAsRegister(node);
2446+
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt32(
2447+
node_t node) {
2448+
if constexpr (Adapter::IsTurboshaft) {
2449+
UNIMPLEMENTED();
2450+
} else {
2451+
Arm64OperandGeneratorT<Adapter> g(this);
2452+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2453+
InstructionOperand outputs[2];
2454+
size_t output_count = 0;
2455+
outputs[output_count++] = g.DefineAsRegister(node);
24342456

2435-
Node* success_output = NodeProperties::FindProjection(node, 1);
2436-
if (success_output) {
2437-
outputs[output_count++] = g.DefineAsRegister(success_output);
2438-
}
2457+
Node* success_output = NodeProperties::FindProjection(node, 1);
2458+
if (success_output) {
2459+
outputs[output_count++] = g.DefineAsRegister(success_output);
2460+
}
24392461

2440-
Emit(kArm64Float64ToInt32, output_count, outputs, 1, inputs);
2462+
Emit(kArm64Float64ToInt32, output_count, outputs, 1, inputs);
2463+
}
24412464
}
24422465

24432466
template <typename Adapter>
24442467
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToUint32(
2445-
Node* node) {
2446-
Arm64OperandGeneratorT<Adapter> g(this);
2447-
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2448-
InstructionOperand outputs[2];
2449-
size_t output_count = 0;
2450-
outputs[output_count++] = g.DefineAsRegister(node);
2468+
node_t node) {
2469+
if constexpr (Adapter::IsTurboshaft) {
2470+
UNIMPLEMENTED();
2471+
} else {
2472+
Arm64OperandGeneratorT<Adapter> g(this);
2473+
InstructionOperand inputs[] = {g.UseRegister(node->InputAt(0))};
2474+
InstructionOperand outputs[2];
2475+
size_t output_count = 0;
2476+
outputs[output_count++] = g.DefineAsRegister(node);
24512477

2452-
Node* success_output = NodeProperties::FindProjection(node, 1);
2453-
if (success_output) {
2454-
outputs[output_count++] = g.DefineAsRegister(success_output);
2455-
}
2478+
Node* success_output = NodeProperties::FindProjection(node, 1);
2479+
if (success_output) {
2480+
outputs[output_count++] = g.DefineAsRegister(success_output);
2481+
}
24562482

2457-
Emit(kArm64Float64ToUint32, output_count, outputs, 1, inputs);
2483+
Emit(kArm64Float64ToUint32, output_count, outputs, 1, inputs);
2484+
}
24582485
}
24592486

24602487
template <typename Adapter>

src/compiler/backend/instruction-selector.cc

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,40 +1896,12 @@ VISIT_UNSUPPORTED_OP(ChangeFloat64ToInt64)
18961896
VISIT_UNSUPPORTED_OP(ChangeFloat64ToUint64)
18971897
VISIT_UNSUPPORTED_OP(TruncateFloat64ToInt64)
18981898
VISIT_UNSUPPORTED_OP(TruncateInt64ToInt32)
1899-
1900-
template <typename Adapter>
1901-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat32ToInt64(Node* node) {
1902-
UNIMPLEMENTED();
1903-
}
1904-
1905-
template <typename Adapter>
1906-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt64(Node* node) {
1907-
UNIMPLEMENTED();
1908-
}
1909-
1910-
template <typename Adapter>
1911-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat32ToUint64(
1912-
Node* node) {
1913-
UNIMPLEMENTED();
1914-
}
1915-
1916-
template <typename Adapter>
1917-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToUint64(
1918-
Node* node) {
1919-
UNIMPLEMENTED();
1920-
}
1921-
1922-
template <typename Adapter>
1923-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToInt32(Node* node) {
1924-
UNIMPLEMENTED();
1925-
}
1926-
1927-
template <typename Adapter>
1928-
void InstructionSelectorT<Adapter>::VisitTryTruncateFloat64ToUint32(
1929-
Node* node) {
1930-
UNIMPLEMENTED();
1931-
}
1932-
1899+
VISIT_UNSUPPORTED_OP(TryTruncateFloat32ToInt64)
1900+
VISIT_UNSUPPORTED_OP(TryTruncateFloat64ToInt64)
1901+
VISIT_UNSUPPORTED_OP(TryTruncateFloat32ToUint64)
1902+
VISIT_UNSUPPORTED_OP(TryTruncateFloat64ToUint64)
1903+
VISIT_UNSUPPORTED_OP(TryTruncateFloat64ToInt32)
1904+
VISIT_UNSUPPORTED_OP(TryTruncateFloat64ToUint32)
19331905
VISIT_UNSUPPORTED_OP(RoundInt64ToFloat32)
19341906
VISIT_UNSUPPORTED_OP(RoundInt64ToFloat64)
19351907
VISIT_UNSUPPORTED_OP(RoundUint64ToFloat32)
@@ -2186,19 +2158,19 @@ void InstructionSelectorT<Adapter>::VisitPhi(node_t node) {
21862158
template <>
21872159
void InstructionSelectorT<TurboshaftAdapter>::VisitProjection(
21882160
turboshaft::OpIndex node) {
2189-
const turboshaft::ProjectionOp& projection =
2190-
this->Get(node).Cast<turboshaft::ProjectionOp>();
2191-
const turboshaft::Operation& value_op = this->Get(projection.input());
2192-
if (value_op.Is<turboshaft::OverflowCheckedBinopOp>()) {
2161+
using namespace turboshaft; // NOLINT(build/namespaces)
2162+
const ProjectionOp& projection = this->Get(node).Cast<ProjectionOp>();
2163+
const Operation& value_op = this->Get(projection.input());
2164+
if (value_op.Is<OverflowCheckedBinopOp>() || value_op.Is<TryChangeOp>()) {
21932165
if (projection.index == 0u) {
21942166
EmitIdentity(node);
21952167
} else {
21962168
DCHECK_EQ(1u, projection.index);
21972169
MarkAsUsed(projection.input());
21982170
}
2199-
} else if (value_op.Is<turboshaft::DidntThrowOp>()) {
2171+
} else if (value_op.Is<DidntThrowOp>()) {
22002172
// Nothing to do here?
2201-
} else if (value_op.Is<turboshaft::CallOp>()) {
2173+
} else if (value_op.Is<CallOp>()) {
22022174
// Call projections need to be behind the call's DidntThrow.
22032175
UNREACHABLE();
22042176
} else {
@@ -4393,6 +4365,34 @@ void InstructionSelectorT<TurboshaftAdapter>::VisitNode(
43934365
}
43944366
UNREACHABLE();
43954367
}
4368+
case Opcode::kTryChange: {
4369+
const TryChangeOp& try_change = op.Cast<TryChangeOp>();
4370+
MarkAsRepresentation(try_change.to.machine_representation(), node);
4371+
DCHECK(try_change.kind ==
4372+
TryChangeOp::Kind::kSignedFloatTruncateOverflowUndefined ||
4373+
try_change.kind ==
4374+
TryChangeOp::Kind::kUnsignedFloatTruncateOverflowUndefined);
4375+
const bool is_signed =
4376+
try_change.kind ==
4377+
TryChangeOp::Kind::kSignedFloatTruncateOverflowUndefined;
4378+
switch (multi(try_change.from, try_change.to, is_signed)) {
4379+
case multi(Rep::Float64(), Rep::Word64(), true):
4380+
return VisitTryTruncateFloat64ToInt64(node);
4381+
case multi(Rep::Float64(), Rep::Word64(), false):
4382+
return VisitTryTruncateFloat64ToUint64(node);
4383+
case multi(Rep::Float64(), Rep::Word32(), true):
4384+
return VisitTryTruncateFloat64ToInt32(node);
4385+
case multi(Rep::Float64(), Rep::Word32(), false):
4386+
return VisitTryTruncateFloat64ToUint32(node);
4387+
case multi(Rep::Float32(), Rep::Word64(), true):
4388+
return VisitTryTruncateFloat32ToInt64(node);
4389+
case multi(Rep::Float32(), Rep::Word64(), false):
4390+
return VisitTryTruncateFloat32ToUint64(node);
4391+
default:
4392+
UNREACHABLE();
4393+
}
4394+
UNREACHABLE();
4395+
}
43964396
case Opcode::kConstant: {
43974397
const ConstantOp& constant = op.Cast<ConstantOp>();
43984398
switch (constant.kind) {
@@ -4899,7 +4899,6 @@ void InstructionSelectorT<TurboshaftAdapter>::VisitNode(
48994899
#undef UNREACHABLE_CASE
49004900

49014901
case Opcode::kTailCall:
4902-
case Opcode::kTryChange:
49034902
case Opcode::kWord32PairBinop:
49044903
case Opcode::kBitcastWord32PairToFloat64:
49054904
case Opcode::kSelect:

src/compiler/backend/instruction-selector.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,12 @@ class InstructionSelectorT final : public Adapter {
874874
DECLARE_GENERATOR_T(StackSlot)
875875
DECLARE_GENERATOR_T(LoadRootRegister)
876876
DECLARE_GENERATOR_T(DebugBreak)
877+
DECLARE_GENERATOR_T(TryTruncateFloat32ToInt64)
878+
DECLARE_GENERATOR_T(TryTruncateFloat64ToInt64)
879+
DECLARE_GENERATOR_T(TryTruncateFloat32ToUint64)
880+
DECLARE_GENERATOR_T(TryTruncateFloat64ToUint64)
881+
DECLARE_GENERATOR_T(TryTruncateFloat64ToInt32)
882+
DECLARE_GENERATOR_T(TryTruncateFloat64ToUint32)
877883
#undef DECLARE_GENERATOR_T
878884

879885
#define DECLARE_GENERATOR(x) void Visit##x(Node* node);
@@ -918,12 +924,6 @@ class InstructionSelectorT final : public Adapter {
918924
DECLARE_GENERATOR(BitcastTaggedToWordForTagAndSmiBits)
919925
DECLARE_GENERATOR(BitcastWordToTaggedSigned)
920926
DECLARE_GENERATOR(TruncateFloat64ToUint32)
921-
DECLARE_GENERATOR(TryTruncateFloat32ToInt64)
922-
DECLARE_GENERATOR(TryTruncateFloat64ToInt64)
923-
DECLARE_GENERATOR(TryTruncateFloat32ToUint64)
924-
DECLARE_GENERATOR(TryTruncateFloat64ToUint64)
925-
DECLARE_GENERATOR(TryTruncateFloat64ToInt32)
926-
DECLARE_GENERATOR(TryTruncateFloat64ToUint32)
927927
DECLARE_GENERATOR(Float64InsertLowWord32)
928928
DECLARE_GENERATOR(Float64InsertHighWord32)
929929
DECLARE_GENERATOR(Word32Select)

0 commit comments

Comments
 (0)