v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
diamond.h
Go to the documentation of this file.
1// Copyright 2013 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_DIAMOND_H_
6#define V8_COMPILER_DIAMOND_H_
7
9#include "src/compiler/node.h"
11
12namespace v8 {
13namespace internal {
14namespace compiler {
15
16// A helper to make it easier to build diamond-shaped control patterns.
17struct Diamond {
24
28 graph = g;
29 common = b;
30 branch =
31 graph->NewNode(common->Branch(hint, semantics), cond, graph->start());
32 if_true = graph->NewNode(common->IfTrue(), branch);
33 if_false = graph->NewNode(common->IfFalse(), branch);
34 merge = graph->NewNode(common->Merge(2), if_true, if_false);
35 }
36
37 // Place {this} after {that} in control flow order.
38 void Chain(Diamond const& that) { branch->ReplaceInput(1, that.merge); }
39
40 // Place {this} after {that} in control flow order.
41 void Chain(Node* that) { branch->ReplaceInput(1, that); }
42
43 // Nest {this} into either the if_true or if_false branch of {that}.
44 void Nest(Diamond const& that, bool cond) {
45 if (cond) {
46 branch->ReplaceInput(1, that.if_true);
47 that.merge->ReplaceInput(0, merge);
48 } else {
49 branch->ReplaceInput(1, that.if_false);
50 that.merge->ReplaceInput(1, merge);
51 }
52 }
53
55 return graph->NewNode(common->Phi(rep, 2), tv, fv, merge);
56 }
57
58 Node* EffectPhi(Node* tv, Node* fv) {
59 return graph->NewNode(common->EffectPhi(2), tv, fv, merge);
60 }
61};
62
63} // namespace compiler
64} // namespace internal
65} // namespace v8
66
67#endif // V8_COMPILER_DIAMOND_H_
const Operator * Phi(MachineRepresentation representation, int value_input_count)
const Operator * EffectPhi(int effect_input_count)
const Operator * Merge(int control_input_count)
const Operator * Branch(BranchHint=BranchHint::kNone, BranchSemantics semantics=BranchSemantics::kUnspecified)
void ReplaceInput(int index, Node *new_to)
Definition node.h:76
void Nest(Diamond const &that, bool cond)
Definition diamond.h:44
CommonOperatorBuilder * common
Definition diamond.h:19
Diamond(TFGraph *g, CommonOperatorBuilder *b, Node *cond, BranchHint hint=BranchHint::kNone, BranchSemantics semantics=BranchSemantics::kUnspecified)
Definition diamond.h:25
Node * EffectPhi(Node *tv, Node *fv)
Definition diamond.h:58
Node * Phi(MachineRepresentation rep, Node *tv, Node *fv)
Definition diamond.h:54
void Chain(Diamond const &that)
Definition diamond.h:38