v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
select-lowering-reducer.h
Go to the documentation of this file.
1// Copyright 2022 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_SELECT_LOWERING_REDUCER_H_
6#define V8_COMPILER_TURBOSHAFT_SELECT_LOWERING_REDUCER_H_
7
8#include "src/base/vector.h"
12
14
16
17// Lowers Select operations to diamonds.
18//
19// A Select is conceptually somewhat similar to a ternary if:
20//
21// res = Select(cond, val_true, val_false)
22//
23// means:
24//
25// res = cond ? val_true : val_false
26//
27// SelectLoweringReducer lowers such operations into:
28//
29// if (cond) {
30// res = val_true
31// } else {
32// res = val_false
33// }
34
35template <class Next>
36class SelectLoweringReducer : public Next {
37 public:
39
40 V<Any> REDUCE(Select)(V<Word32> cond, V<Any> vtrue, V<Any> vfalse,
42 SelectOp::Implementation implem) {
44 // We do not lower Select operations that should be implemented with
45 // CMove.
46 return Next::ReduceSelect(cond, vtrue, vfalse, rep, hint, implem);
47 }
48
49 Variable result = __ NewLoopInvariantVariable(rep);
50 IF (cond) {
51 __ SetVariable(result, vtrue);
52 } ELSE {
53 __ SetVariable(result, vfalse);
54 }
55
56 return __ GetVariable(result);
57 }
58};
59
61
62} // namespace v8::internal::compiler::turboshaft
63
64#endif // V8_COMPILER_TURBOSHAFT_SELECT_LOWERING_REDUCER_H_
#define REDUCE(operation)
#define ELSE
#define IF(...)
#define TURBOSHAFT_REDUCER_BOILERPLATE(Name)
Definition assembler.h:823
ZoneVector< RpoNumber > & result