v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
constant-folding-reducer.cc
Go to the documentation of this file.
1// Copyright 2018 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
6
10
11namespace v8 {
12namespace internal {
13namespace compiler {
14
15namespace {
16Node* TryGetConstant(JSGraph* jsgraph, Node* node, JSHeapBroker* broker) {
17 Type type = NodeProperties::GetType(node);
18 Node* result;
19 if (type.IsNone()) {
20 result = nullptr;
21 } else if (type.Is(Type::Null())) {
22 result = jsgraph->NullConstant();
23 } else if (type.Is(Type::Undefined())) {
24 result = jsgraph->UndefinedConstant();
25 } else if (type.Is(Type::MinusZero())) {
26 result = jsgraph->MinusZeroConstant();
27 } else if (type.Is(Type::NaN())) {
28 result = jsgraph->NaNConstant();
29 } else if (type.IsHeapConstant()) {
30 result = jsgraph->ConstantNoHole(type.AsHeapConstant()->Ref(), broker);
31 } else if (type.Is(Type::PlainNumber()) && type.Min() == type.Max()) {
32 result = jsgraph->ConstantNoHole(type.Min());
33 } else {
34 result = nullptr;
35 }
36 DCHECK_EQ(result != nullptr, type.IsSingleton());
37 DCHECK_IMPLIES(result != nullptr,
38 type.Equals(NodeProperties::GetType(result)));
39 return result;
40}
41
42} // namespace
43
47
49
52 node->op()->HasProperty(Operator::kEliminatable) &&
53 node->opcode() != IrOpcode::kFinishRegion &&
54 node->opcode() != IrOpcode::kTypeGuard) {
55 Node* constant = TryGetConstant(jsgraph(), node, broker());
56 if (constant != nullptr) {
58 DCHECK_EQ(node->op()->ControlOutputCount(), 0);
59 ReplaceWithValue(node, constant);
60 return Replace(constant);
61 }
62 }
63 return NoChange();
64}
65
66} // namespace compiler
67} // namespace internal
68} // namespace v8
JSGraph * jsgraph
ConstantFoldingReducer(Editor *editor, JSGraph *jsgraph, JSHeapBroker *broker)
Node * ConstantNoHole(ObjectRef ref, JSHeapBroker *broker)
Definition js-graph.cc:51
static Type GetType(const Node *node)
static bool IsTyped(const Node *node)
JSHeapBroker *const broker_
JSHeapBroker * broker
ZoneVector< RpoNumber > & result
#define DCHECK_IMPLIES(v1, v2)
Definition logging.h:493
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485