v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
add-type-assertions-reducer.cc
Go to the documentation of this file.
1// Copyright 2019 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
9
10namespace v8 {
11namespace internal {
12namespace compiler {
13
14namespace {
15struct AddTypeAssertionsImpl {
16 JSGraph* jsgraph;
17 Schedule* schedule;
19
20 SimplifiedOperatorBuilder* simplified = jsgraph->simplified();
21 TFGraph* graph = jsgraph->graph();
22
23 void Run();
24 void ProcessBlock(BasicBlock* block);
25 void InsertAssertion(Node* asserted, Node* effect_successor);
26};
27
28void AddTypeAssertionsImpl::Run() {
29 for (BasicBlock* block : *(schedule->rpo_order())) {
30 ProcessBlock(block);
31 }
32}
33
34void AddTypeAssertionsImpl::ProcessBlock(BasicBlock* block) {
35 // To keep things simple, this only inserts type assertions for nodes that are
36 // followed by an effectful operation in the same basic block. We could build
37 // a proper new effect chain like in the EffectControlLinearizer, but right
38 // now, this doesn't quite seem worth the effort.
39 std::vector<Node*> pending;
40 bool inside_of_region = false;
41 for (Node* node : *block) {
42 if (node->opcode() == IrOpcode::kBeginRegion) {
43 inside_of_region = true;
44 } else if (inside_of_region) {
45 if (node->opcode() == IrOpcode::kFinishRegion) {
46 inside_of_region = false;
47 }
48 continue;
49 }
50 if (node->op()->EffectOutputCount() == 1 &&
51 node->op()->EffectInputCount() == 1) {
52 for (Node* pending_node : pending) {
53 InsertAssertion(pending_node, node);
54 }
55 pending.clear();
56 }
57 if (node->opcode() == IrOpcode::kAssertType ||
58 node->opcode() == IrOpcode::kAllocate ||
59 node->opcode() == IrOpcode::kObjectState ||
60 node->opcode() == IrOpcode::kObjectId ||
61 node->opcode() == IrOpcode::kPhi || !NodeProperties::IsTyped(node) ||
62 node->opcode() == IrOpcode::kUnreachable) {
63 continue;
64 }
65 Type type = NodeProperties::GetType(node);
66 if (type.CanBeAsserted()) {
67 pending.push_back(node);
68 }
69 }
70}
71
72void AddTypeAssertionsImpl::InsertAssertion(Node* asserted,
73 Node* effect_successor) {
74 Node* assertion = graph->NewNode(
75 simplified->AssertType(NodeProperties::GetType(asserted)), asserted,
76 NodeProperties::GetEffectInput(effect_successor));
77 NodeProperties::ReplaceEffectInput(effect_successor, assertion);
78}
79
80} // namespace
81
83 AddTypeAssertionsImpl{jsgraph, schedule, phase_zone}.Run();
84}
85
86} // namespace compiler
87} // namespace internal
88} // namespace v8
Schedule * schedule
JSGraph * jsgraph
friend Zone
Definition asm-types.cc:195
void AddTypeAssertions(JSGraph *jsgraph, Schedule *schedule, Zone *phase_zone)