v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
explicit-truncation-reducer.h
Go to the documentation of this file.
1// Copyright 2023 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_COMPILER_TURBOSHAFT_EXPLICIT_TRUNCATION_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_EXPLICIT_TRUNCATION_REDUCER_H_
7
11
13
15
16// This reducer adds explicit int64 -> int32 truncation operations. This is
17// needed as Turbofan does not have an explicit truncation operation.
18// TODO(12783): Once the Turboshaft graph is not created from Turbofan, this
19// reducer can be removed.
20template <class Next>
22 : public UniformReducerAdapter<ExplicitTruncationReducer, Next> {
23 public:
24 TURBOSHAFT_REDUCER_BOILERPLATE(ExplicitTruncation)
25
26 template <Opcode opcode, typename Continuation, typename... Ts>
28 // Construct a temporary operation. The operation is needed for generic
29 // access to the inputs and the inputs representation.
30 using Op = typename opcode_to_operation_map<opcode>::Op;
31 Op* operation = CreateOperation<Op>(storage_, args...);
32
34 operation->inputs_rep(inputs_rep_storage_);
35 base::Vector<OpIndex> inputs = operation->inputs();
36 bool has_truncation = false;
37 for (size_t i = 0; i < reps.size(); ++i) {
40 Asm().input_graph().Get(inputs[i]).outputs_rep();
41 // We ignore any input operation that produces more than one value.
42 // These cannot be consumed directly and therefore require a projection.
43 // Assumption: A projection never performs an implicit truncation from
44 // word64 to word32.
45 if (actual_inputs_rep.size() == 1 &&
46 actual_inputs_rep[0] == RegisterRepresentation::Word64()) {
47 has_truncation = true;
48 inputs[i] = Next::ReduceChange(inputs[i], ChangeOp::Kind::kTruncate,
52 }
53 }
54 }
55
56 if (!has_truncation) {
57 // Just call the regular Reduce without any remapped values.
58 return Continuation{this}.Reduce(args...);
59 }
60
62 return operation->Explode(
63 [this](auto... args) -> OpIndex {
64 return Continuation{this}.Reduce(args...);
65 },
66 mapper);
67 }
68
69 private:
73};
74
76
77} // namespace v8::internal::compiler::turboshaft
78
79#endif // V8_COMPILER_TURBOSHAFT_EXPLICIT_TRUNCATION_REDUCER_H_
constexpr size_t size() const
Definition vector.h:70
static constexpr MaybeRegisterRepresentation Word32()
static constexpr RegisterRepresentation Word32()
static constexpr RegisterRepresentation Word64()
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
Definition assembler.h:823
base::Vector< const DirectHandle< Object > > args
Definition execution.cc:74
Op * CreateOperation(base::SmallVector< OperationStorageSlot, 32 > &storage, Args... args)