Skip to content

Commit b9d806a

Browse files
StefanStojanovictargos
authored andcommitted
deps: patch V8 to support compilation with MSVC
This patches V8 v12.2 for Windows, by fixing multiple compilation errors caused by V8 being a Clang-oriented project. There are various types of errors fixed by this going from changing `using` directives and renaming to overcoming the differences in which Clang and MSVC see templates and metaprogramming. The changes introduced here are strictly meant as a patch only, so they shouldn't be pushed upstream. Refs: targos#13 Refs: targos#14 PR-URL: #51362 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 63b58bc commit b9d806a

31 files changed

+129
-131
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Reset this number to 0 on major V8 upgrades.
3939
# Increment by one for each non-official patch applied to deps/v8.
40-
'v8_embedder_string': '-node.6',
40+
'v8_embedder_string': '-node.7',
4141

4242
##### V8 defaults for Node.js #####
4343

deps/v8/src/builtins/builtins-collections-gen.cc

+3-4
Original file line numberDiff line numberDiff line change
@@ -2782,10 +2782,9 @@ TNode<Word32T> WeakCollectionsBuiltinsAssembler::ShouldShrink(
27822782

27832783
TNode<IntPtrT> WeakCollectionsBuiltinsAssembler::ValueIndexFromKeyIndex(
27842784
TNode<IntPtrT> key_index) {
2785-
return IntPtrAdd(
2786-
key_index,
2787-
IntPtrConstant(EphemeronHashTable::TodoShape::kEntryValueIndex -
2788-
EphemeronHashTable::kEntryKeyIndex));
2785+
return IntPtrAdd(key_index,
2786+
IntPtrConstant(EphemeronHashTable::ShapeT::kEntryValueIndex -
2787+
EphemeronHashTable::kEntryKeyIndex));
27892788
}
27902789

27912790
TF_BUILTIN(WeakMapConstructor, WeakCollectionsBuiltinsAssembler) {

deps/v8/src/codegen/code-stub-assembler.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -9455,7 +9455,7 @@ void CodeStubAssembler::NameDictionaryLookup(
94559455
CAST(UnsafeLoadFixedArrayElement(dictionary, index));
94569456
GotoIf(TaggedEqual(current, undefined), if_not_found);
94579457
if (mode == kFindExisting) {
9458-
if (Dictionary::TodoShape::kMatchNeedsHoleCheck) {
9458+
if (Dictionary::ShapeT::kMatchNeedsHoleCheck) {
94599459
GotoIf(TaggedEqual(current, TheHoleConstant()), &next_probe);
94609460
}
94619461
current = LoadName<Dictionary>(current);

deps/v8/src/compiler/turboshaft/assembler.h

+6
Original file line numberDiff line numberDiff line change
@@ -3934,8 +3934,14 @@ class TSAssembler
39343934
: public Assembler<reducer_list<TurboshaftAssemblerOpInterface, Reducers...,
39353935
TSReducerBase>> {
39363936
public:
3937+
#ifdef _WIN32
3938+
explicit TSAssembler(Graph& input_graph, Graph& output_graph,
3939+
Zone* phase_zone)
3940+
: Assembler(input_graph, output_graph, phase_zone) {}
3941+
#else
39373942
using Assembler<reducer_list<TurboshaftAssemblerOpInterface, Reducers...,
39383943
TSReducerBase>>::Assembler;
3944+
#endif
39393945
};
39403946

39413947
#include "src/compiler/turboshaft/undef-assembler-macros.inc"

deps/v8/src/compiler/turboshaft/code-elimination-and-simplification-phase.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ void CodeEliminationAndSimplificationPhase::Run(Zone* temp_zone) {
3232
// (which, for simplificy, doesn't use the Assembler helper
3333
// methods, but only calls Next::ReduceLoad/Store).
3434
DuplicationOptimizationReducer,
35-
ValueNumberingReducer>::Run(temp_zone);
35+
VariableReducerHotfix,
36+
ValueNumberingReducer>::Run<false>(temp_zone);
3637
}
3738

3839
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/copying-phase.h

+25-10
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ struct PaddingSpace {
3636
V8_EXPORT_PRIVATE std::ostream& operator<<(std::ostream& os,
3737
PaddingSpace padding);
3838

39+
template <class Next>
40+
class VariableReducerHotfix : public Next {
41+
public:
42+
TURBOSHAFT_REDUCER_BOILERPLATE()
43+
44+
void SetVariable(Variable var, OpIndex new_index) {}
45+
Variable NewLoopInvariantVariable(MaybeRegisterRepresentation rep) { return Variable(); }
46+
47+
OpIndex GetVariable(Variable var) { return OpIndex(); }
48+
OpIndex GetPredecessorValue(Variable var, int predecessor_index) { return OpIndex(); }
49+
};
50+
3951
template <typename Next>
4052
class ReducerBaseForwarder;
4153
template <typename Next>
@@ -46,6 +58,9 @@ class GraphVisitor : public Next {
4658
template <typename N>
4759
friend class ReducerBaseForwarder;
4860

61+
private:
62+
bool contains_variable_reducer_;
63+
4964
public:
5065
TURBOSHAFT_REDUCER_BOILERPLATE()
5166

@@ -66,7 +81,8 @@ class GraphVisitor : public Next {
6681
// `trace_reduction` is a template parameter to avoid paying for tracing at
6782
// runtime.
6883
template <bool trace_reduction>
69-
void VisitGraph() {
84+
void VisitGraph(bool contains_variable_reducer) {
85+
contains_variable_reducer_ = contains_variable_reducer;
7086
Asm().Analyze();
7187

7288
// Creating initial old-to-new Block mapping.
@@ -177,8 +193,7 @@ class GraphVisitor : public Next {
177193
DCHECK(old_index.valid());
178194
OpIndex result = op_mapping_[old_index];
179195

180-
if constexpr (reducer_list_contains<typename Next::ReducerList,
181-
VariableReducer>::value) {
196+
if (contains_variable_reducer_) {
182197
if (!result.valid()) {
183198
// {op_mapping} doesn't have a mapping for {old_index}. The assembler
184199
// should provide the mapping.
@@ -1294,8 +1309,7 @@ class GraphVisitor : public Next {
12941309
DCHECK(Asm().input_graph().BelongsToThisGraph(old_index));
12951310
DCHECK_IMPLIES(new_index.valid(),
12961311
Asm().output_graph().BelongsToThisGraph(new_index));
1297-
if constexpr (reducer_list_contains<typename Next::ReducerList,
1298-
VariableReducer>::value) {
1312+
if (contains_variable_reducer_) {
12991313
if (current_block_needs_variables_) {
13001314
MaybeVariable var = GetVariableFor(old_index);
13011315
if (!var.has_value()) {
@@ -1393,29 +1407,30 @@ template <template <class> class... Reducers>
13931407
class CopyingPhaseImpl {
13941408
public:
13951409
static void Run(Graph& input_graph, Zone* phase_zone,
1396-
bool trace_reductions = false) {
1410+
bool contains_variable_reducer, bool trace_reductions = false) {
13971411
TSAssembler<GraphVisitor, Reducers...> phase(
13981412
input_graph, input_graph.GetOrCreateCompanion(), phase_zone);
13991413
#ifdef DEBUG
14001414
if (trace_reductions) {
1401-
phase.template VisitGraph<true>();
1415+
phase.template VisitGraph<true>(contains_variable_reducer);
14021416
} else {
1403-
phase.template VisitGraph<false>();
1417+
phase.template VisitGraph<false>(contains_variable_reducer);
14041418
}
14051419
#else
1406-
phase.template VisitGraph<false>();
1420+
phase.template VisitGraph<false>(contains_variable_reducer);
14071421
#endif // DEBUG
14081422
}
14091423
};
14101424

14111425
template <template <typename> typename... Reducers>
14121426
class CopyingPhase {
14131427
public:
1428+
template <bool contains_variable_reducer>
14141429
static void Run(Zone* phase_zone) {
14151430
PipelineData& data = PipelineData::Get();
14161431
Graph& input_graph = data.graph();
14171432
CopyingPhaseImpl<Reducers...>::Run(
1418-
input_graph, phase_zone, data.info()->turboshaft_trace_reduction());
1433+
input_graph, phase_zone, contains_variable_reducer, data.info()->turboshaft_trace_reduction());
14191434
}
14201435
};
14211436

deps/v8/src/compiler/turboshaft/csa-optimize-phase.cc

+5-5
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ namespace v8::internal::compiler::turboshaft {
2525
void CsaLoadEliminationPhase::Run(Zone* temp_zone) {
2626
CopyingPhase<VariableReducer, MachineOptimizationReducer,
2727
RequiredOptimizationReducer,
28-
ValueNumberingReducer>::Run(temp_zone);
28+
ValueNumberingReducer>::Run<true>(temp_zone);
2929

3030
CopyingPhase<VariableReducer, LateLoadEliminationReducer,
3131
MachineOptimizationReducer, RequiredOptimizationReducer,
32-
ValueNumberingReducer>::Run(temp_zone);
32+
ValueNumberingReducer>::Run<true>(temp_zone);
3333
}
3434

3535
void CsaLateEscapeAnalysisPhase::Run(Zone* temp_zone) {
3636
CopyingPhase<VariableReducer, LateEscapeAnalysisReducer,
3737
MachineOptimizationReducer, RequiredOptimizationReducer,
38-
ValueNumberingReducer>::Run(temp_zone);
38+
ValueNumberingReducer>::Run<true>(temp_zone);
3939
}
4040

4141
void CsaBranchEliminationPhase::Run(Zone* temp_zone) {
4242
CopyingPhase<VariableReducer, MachineOptimizationReducer,
4343
BranchEliminationReducer, RequiredOptimizationReducer,
44-
ValueNumberingReducer>::Run(temp_zone);
44+
ValueNumberingReducer>::Run<true>(temp_zone);
4545
}
4646

4747
void CsaOptimizePhase::Run(Zone* temp_zone) {
@@ -51,7 +51,7 @@ void CsaOptimizePhase::Run(Zone* temp_zone) {
5151
CopyingPhase<VariableReducer, PretenuringPropagationReducer,
5252
MachineOptimizationReducer, MemoryOptimizationReducer,
5353
RequiredOptimizationReducer,
54-
ValueNumberingReducer>::Run(temp_zone);
54+
ValueNumberingReducer>::Run<true>(temp_zone);
5555
}
5656

5757
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/debug-feature-lowering-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace v8::internal::compiler::turboshaft {
1111

1212
void DebugFeatureLoweringPhase::Run(Zone* temp_zone) {
1313
#ifdef V8_ENABLE_DEBUG_CODE
14-
turboshaft::CopyingPhase<turboshaft::DebugFeatureLoweringReducer>::Run(
14+
turboshaft::CopyingPhase<turboshaft::DebugFeatureLoweringReducer>::Run<false>(
1515
temp_zone);
1616
#endif
1717
}

deps/v8/src/compiler/turboshaft/int64-lowering-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ void Int64LoweringPhase::Run(Zone* temp_zone) {
1616
#if V8_TARGET_ARCH_32_BIT
1717
turboshaft::CopyingPhase<
1818
turboshaft::Int64LoweringReducer, turboshaft::VariableReducer,
19-
turboshaft::RequiredOptimizationReducer>::Run(temp_zone);
19+
turboshaft::RequiredOptimizationReducer>::Run<true>(temp_zone);
2020
#else
2121
UNREACHABLE();
2222
#endif

deps/v8/src/compiler/turboshaft/loop-peeling-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void LoopPeelingPhase::Run(Zone* temp_zone) {
2323
turboshaft::VariableReducer,
2424
turboshaft::MachineOptimizationReducer,
2525
turboshaft::RequiredOptimizationReducer,
26-
turboshaft::ValueNumberingReducer>::Run(temp_zone);
26+
turboshaft::ValueNumberingReducer>::Run<true>(temp_zone);
2727
}
2828

2929
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/loop-unrolling-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ void LoopUnrollingPhase::Run(Zone* temp_zone) {
2222
turboshaft::VariableReducer,
2323
turboshaft::MachineOptimizationReducer,
2424
turboshaft::RequiredOptimizationReducer,
25-
turboshaft::ValueNumberingReducer>::Run(temp_zone);
25+
turboshaft::ValueNumberingReducer>::Run<true>(temp_zone);
2626
PipelineData::Get().clear_loop_unrolling_analyzer();
2727
}
2828
}

deps/v8/src/compiler/turboshaft/machine-lowering-phase.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ void MachineLoweringPhase::Run(Zone* temp_zone) {
2020
CopyingPhase<DataViewReducer, VariableReducer, MachineLoweringReducer,
2121
FastApiCallReducer, RequiredOptimizationReducer,
2222
SelectLoweringReducer,
23-
MachineOptimizationReducer>::Run(temp_zone);
23+
MachineOptimizationReducer>::Run<true>(temp_zone);
2424
} else {
2525
CopyingPhase<DataViewReducer, VariableReducer, MachineLoweringReducer,
2626
FastApiCallReducer, RequiredOptimizationReducer,
27-
SelectLoweringReducer>::Run(temp_zone);
27+
SelectLoweringReducer>::Run<true>(temp_zone);
2828
}
2929
}
3030

deps/v8/src/compiler/turboshaft/machine-optimization-reducer.h

+10-40
Original file line numberDiff line numberDiff line change
@@ -1333,53 +1333,23 @@ class MachineOptimizationReducer : public Next {
13331333
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
13341334
left, &x, rep_w, &k1) &&
13351335
matcher.MatchIntegralWordConstant(right, rep_w, &k2) &&
1336-
CountLeadingSignBits(k2, rep_w) > k1) {
1337-
if (matcher.Get(left).saturated_use_count.IsZero()) {
1338-
return __ Comparison(
1339-
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
1340-
rep_w);
1341-
} else if constexpr (reducer_list_contains<
1342-
ReducerList, ValueNumberingReducer>::value) {
1343-
// If the shift has uses, we only apply the transformation if the
1344-
// result would be GVNed away.
1345-
OpIndex rhs =
1346-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
1347-
static_assert(ComparisonOp::input_count == 2);
1348-
static_assert(sizeof(ComparisonOp) == 8);
1349-
base::SmallVector<OperationStorageSlot, 32> storage;
1350-
ComparisonOp* cmp =
1351-
CreateOperation<ComparisonOp>(storage, x, rhs, kind, rep_w);
1352-
if (__ WillGVNOp(*cmp)) {
1353-
return __ Comparison(x, rhs, kind, rep_w);
1354-
}
1355-
}
1336+
CountLeadingSignBits(k2, rep_w) > k1 &&
1337+
matcher.Get(left).saturated_use_count.IsZero()) {
1338+
return __ Comparison(
1339+
x, __ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), kind,
1340+
rep_w);
13561341
}
13571342
// k2 </<= (x >> k1) => (k2 << k1) </<= x if shifts reversible
13581343
// Only perform the transformation if the shift is not used yet, to
13591344
// avoid keeping both the shift and x alive.
13601345
if (matcher.MatchConstantShiftRightArithmeticShiftOutZeros(
13611346
right, &x, rep_w, &k1) &&
13621347
matcher.MatchIntegralWordConstant(left, rep_w, &k2) &&
1363-
CountLeadingSignBits(k2, rep_w) > k1) {
1364-
if (matcher.Get(right).saturated_use_count.IsZero()) {
1365-
return __ Comparison(
1366-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
1367-
rep_w);
1368-
} else if constexpr (reducer_list_contains<
1369-
ReducerList, ValueNumberingReducer>::value) {
1370-
// If the shift has uses, we only apply the transformation if the
1371-
// result would be GVNed away.
1372-
OpIndex lhs =
1373-
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w);
1374-
static_assert(ComparisonOp::input_count == 2);
1375-
static_assert(sizeof(ComparisonOp) == 8);
1376-
base::SmallVector<OperationStorageSlot, 32> storage;
1377-
ComparisonOp* cmp =
1378-
CreateOperation<ComparisonOp>(storage, lhs, x, kind, rep_w);
1379-
if (__ WillGVNOp(*cmp)) {
1380-
return __ Comparison(lhs, x, kind, rep_w);
1381-
}
1382-
}
1348+
CountLeadingSignBits(k2, rep_w) > k1 &&
1349+
matcher.Get(right).saturated_use_count.IsZero()) {
1350+
return __ Comparison(
1351+
__ WordConstant(base::bits::Unsigned(k2) << k1, rep_w), x, kind,
1352+
rep_w);
13831353
}
13841354
}
13851355
// Map 64bit to 32bit comparisons.

deps/v8/src/compiler/turboshaft/optimize-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ void OptimizePhase::Run(Zone* temp_zone) {
3030
turboshaft::MemoryOptimizationReducer,
3131
turboshaft::MachineOptimizationReducer,
3232
turboshaft::RequiredOptimizationReducer,
33-
turboshaft::ValueNumberingReducer>::Run(temp_zone);
33+
turboshaft::ValueNumberingReducer>::Run<true>(temp_zone);
3434
}
3535

3636
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/simplified-lowering-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
namespace v8::internal::compiler::turboshaft {
1111

1212
void SimplifiedLoweringPhase::Run(Zone* temp_zone) {
13-
CopyingPhase<SimplifiedLoweringReducer>::Run(temp_zone);
13+
CopyingPhase<SimplifiedLoweringReducer, VariableReducerHotfix>::Run<false>(temp_zone);
1414
}
1515

1616
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/simplified-lowering-reducer.h

+7-7
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ class SimplifiedLoweringReducer : public Next {
3232
OpIndex ig_index, const SpeculativeNumberBinopOp& op) {
3333
DCHECK_EQ(op.kind, SpeculativeNumberBinopOp::Kind::kSafeIntegerAdd);
3434

35-
OpIndex frame_state = Map(op.frame_state());
36-
V<Word32> left = ProcessInput(Map(op.left()), Rep::Word32(),
35+
OpIndex frame_state = MapImpl(op.frame_state());
36+
V<Word32> left = ProcessInput(MapImpl(op.left()), Rep::Word32(),
3737
CheckKind::kSigned32, frame_state);
38-
V<Word32> right = ProcessInput(Map(op.right()), Rep::Word32(),
38+
V<Word32> right = ProcessInput(MapImpl(op.right()), Rep::Word32(),
3939
CheckKind::kSigned32, frame_state);
4040

4141
V<Word32> result = __ OverflowCheckedBinop(
4242
left, right, OverflowCheckedBinopOp::Kind::kSignedAdd,
4343
WordRepresentation::Word32());
4444

4545
V<Word32> overflow = __ Projection(result, 1, Rep::Word32());
46-
__ DeoptimizeIf(overflow, Map(op.frame_state()),
46+
__ DeoptimizeIf(overflow, MapImpl(op.frame_state()),
4747
DeoptimizeReason::kOverflow, FeedbackSource{});
4848
return __ Projection(result, 0, Rep::Word32());
4949
}
@@ -52,10 +52,10 @@ class SimplifiedLoweringReducer : public Next {
5252
base::SmallVector<OpIndex, 8> return_values;
5353
for (OpIndex input : ret.return_values()) {
5454
return_values.push_back(
55-
ProcessInput(Map(input), Rep::Tagged(), CheckKind::kNone, {}));
55+
ProcessInput(MapImpl(input), Rep::Tagged(), CheckKind::kNone, {}));
5656
}
5757

58-
__ Return(Map(ret.pop_count()), base::VectorOf(return_values));
58+
__ Return(MapImpl(ret.pop_count()), base::VectorOf(return_values));
5959
return OpIndex::Invalid();
6060
}
6161

@@ -94,7 +94,7 @@ class SimplifiedLoweringReducer : public Next {
9494
}
9595
}
9696

97-
inline OpIndex Map(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
97+
inline OpIndex MapImpl(OpIndex ig_index) { return __ MapToNewGraph(ig_index); }
9898
};
9999

100100
#include "src/compiler/turboshaft/undef-assembler-macros.inc"

deps/v8/src/compiler/turboshaft/store-store-elimination-phase.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ void StoreStoreEliminationPhase::Run(Zone* temp_zone) {
2323
turboshaft::MachineOptimizationReducer,
2424
turboshaft::RequiredOptimizationReducer,
2525
turboshaft::BranchEliminationReducer,
26-
turboshaft::ValueNumberingReducer>::Run(temp_zone);
26+
turboshaft::ValueNumberingReducer>::Run<true>(temp_zone);
2727
}
2828

2929
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/type-assertions-phase.cc

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ void TypeAssertionsPhase::Run(Zone* temp_zone) {
2121
turboshaft::TypeInferenceReducerArgs::OutputGraphTyping::
2222
kPreserveFromInputGraph};
2323

24-
turboshaft::CopyingPhase<turboshaft::AssertTypesReducer,
24+
turboshaft::CopyingPhase<turboshaft::VariableReducerHotfix,
25+
turboshaft::AssertTypesReducer,
2526
turboshaft::ValueNumberingReducer,
26-
turboshaft::TypeInferenceReducer>::Run(temp_zone);
27+
turboshaft::TypeInferenceReducer>::Run<false>(temp_zone);
2728
}
2829

2930
} // namespace v8::internal::compiler::turboshaft

deps/v8/src/compiler/turboshaft/typed-optimizations-phase.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ void TypedOptimizationsPhase::Run(Zone* temp_zone) {
2323
turboshaft::TypeInferenceReducerArgs::OutputGraphTyping::kNone};
2424

2525
turboshaft::CopyingPhase<turboshaft::TypedOptimizationsReducer,
26-
turboshaft::TypeInferenceReducer>::Run(temp_zone);
26+
turboshaft::VariableReducerHotfix,
27+
turboshaft::TypeInferenceReducer>::Run<false>(temp_zone);
2728
}
2829

2930
} // namespace v8::internal::compiler::turboshaft

0 commit comments

Comments
 (0)