V8 Project
v8::internal::compiler::JSBinopReduction Class Reference
+ Collaboration diagram for v8::internal::compiler::JSBinopReduction:

Public Member Functions

 JSBinopReduction (JSTypedLowering *lowering, Node *node)
 
void ConvertInputsToNumber ()
 
void ConvertInputsToInt32 (bool left_signed, bool right_signed)
 
void ConvertInputsToString ()
 
void ConvertInputsForShift (bool left_signed)
 
void SwapInputs ()
 
Reduction ChangeToPureOperator (const Operator *op, bool invert=false)
 
bool OneInputIs (Type *t)
 
bool BothInputsAre (Type *t)
 
bool OneInputCannotBe (Type *t)
 
bool NeitherInputCanBe (Type *t)
 
Node * effect ()
 
Node * control ()
 
Node * context ()
 
Node * left ()
 
Node * right ()
 
Typeleft_type ()
 
Typeright_type ()
 
SimplifiedOperatorBuilder * simplified ()
 
Graphgraph ()
 
JSGraphjsgraph ()
 
JSOperatorBuilderjavascript ()
 
MachineOperatorBuilder * machine ()
 

Private Member Functions

Node * ConvertToString (Node *node)
 
Node * ConvertToNumber (Node *node)
 
bool TryNarrowingToI32 (Type *type, Node *node)
 
Node * ConvertToI32 (bool is_signed, Node *node)
 
void update_effect (Node *effect)
 

Private Attributes

JSTypedLowering * lowering_
 
Node * node_
 
Typeleft_type_
 
Typeright_type_
 

Detailed Description

Definition at line 45 of file js-typed-lowering.cc.

Constructor & Destructor Documentation

◆ JSBinopReduction()

v8::internal::compiler::JSBinopReduction::JSBinopReduction ( JSTypedLowering *  lowering,
Node *  node 
)
inline

Member Function Documentation

◆ BothInputsAre()

bool v8::internal::compiler::JSBinopReduction::BothInputsAre ( Type t)
inline

Definition at line 114 of file js-typed-lowering.cc.

114  {
115  return left_type_->Is(t) && right_type_->Is(t);
116  }
bool Is(TypeImpl *that)
Definition: types.h:390

References v8::internal::TypeImpl< Config >::Is(), left_type_, and right_type_.

Referenced by TryNarrowingToI32().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ChangeToPureOperator()

Reduction v8::internal::compiler::JSBinopReduction::ChangeToPureOperator ( const Operator op,
bool  invert = false 
)
inline

Definition at line 86 of file js-typed-lowering.cc.

86  {
91 
92  // Remove the effects from the node, if any, and update its effect usages.
95  }
96  // Remove the inputs corresponding to context, effect, and control.
98  // Finally, update the operator to the new one.
99  node_->set_op(op);
100 
101  if (invert) {
102  // Insert an boolean not to invert the value.
103  Node* value = graph()->NewNode(simplified()->BooleanNot(), node_);
104  node_->ReplaceUses(value);
105  // Note: ReplaceUses() smashes all uses, so smash it back here.
106  value->ReplaceInput(0, node_);
107  return lowering_->ReplaceWith(value);
108  }
109  return lowering_->Changed(node_);
110  }
Node * NewNode(const Operator *op, int input_count, Node **inputs)
Definition: graph.cc:24
SimplifiedOperatorBuilder * simplified()
static int GetEffectInputCount(const Operator *op)
static int GetValueInputCount(const Operator *op)
static bool HasContextInput(const Operator *op)
static int GetControlInputCount(const Operator *op)
#define DCHECK_EQ(v1, v2)
Definition: logging.h:206
static void RelaxEffects(Node *node)

References DCHECK_EQ, v8::internal::compiler::OperatorProperties::GetControlInputCount(), v8::internal::compiler::OperatorProperties::GetEffectInputCount(), v8::internal::compiler::OperatorProperties::GetValueInputCount(), graph(), v8::internal::compiler::OperatorProperties::HasContextInput(), lowering_, v8::internal::compiler::Graph::NewNode(), node_, v8::internal::compiler::RelaxEffects(), v8::internal::compiler::NodeProperties::RemoveNonValueInputs(), and simplified().

+ Here is the call graph for this function:

◆ context()

Node* v8::internal::compiler::JSBinopReduction::context ( )
inline

Definition at line 128 of file js-typed-lowering.cc.

References v8::internal::compiler::NodeProperties::GetContextInput(), and node_.

Referenced by ConvertToNumber(), and ConvertToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ control()

Node* v8::internal::compiler::JSBinopReduction::control ( )
inline

Definition at line 127 of file js-typed-lowering.cc.

static Node * GetControlInput(Node *node, int index=0)

References v8::internal::compiler::NodeProperties::GetControlInput(), and node_.

Referenced by ConvertToNumber(), and ConvertToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertInputsForShift()

void v8::internal::compiler::JSBinopReduction::ConvertInputsForShift ( bool  left_signed)
inline

Definition at line 69 of file js-typed-lowering.cc.

69  {
70  node_->ReplaceInput(0, ConvertToI32(left_signed, left()));
71  Node* rnum = ConvertToI32(false, right());
72  node_->ReplaceInput(1, graph()->NewNode(machine()->Word32And(), rnum,
73  jsgraph()->Int32Constant(0x1F)));
74  }
Node * ConvertToI32(bool is_signed, Node *node)

References ConvertToI32(), graph(), jsgraph(), left(), machine(), node_, and right().

+ Here is the call graph for this function:

◆ ConvertInputsToInt32()

void v8::internal::compiler::JSBinopReduction::ConvertInputsToInt32 ( bool  left_signed,
bool  right_signed 
)
inline

Definition at line 58 of file js-typed-lowering.cc.

58  {
59  node_->ReplaceInput(0, ConvertToI32(left_signed, left()));
60  node_->ReplaceInput(1, ConvertToI32(right_signed, right()));
61  }

References ConvertToI32(), left(), node_, and right().

+ Here is the call graph for this function:

◆ ConvertInputsToNumber()

void v8::internal::compiler::JSBinopReduction::ConvertInputsToNumber ( )
inline

Definition at line 53 of file js-typed-lowering.cc.

53  {
54  node_->ReplaceInput(0, ConvertToNumber(left()));
55  node_->ReplaceInput(1, ConvertToNumber(right()));
56  }

References ConvertToNumber(), left(), node_, and right().

+ Here is the call graph for this function:

◆ ConvertInputsToString()

void v8::internal::compiler::JSBinopReduction::ConvertInputsToString ( )
inline

Definition at line 63 of file js-typed-lowering.cc.

63  {
64  node_->ReplaceInput(0, ConvertToString(left()));
65  node_->ReplaceInput(1, ConvertToString(right()));
66  }

References ConvertToString(), left(), node_, and right().

+ Here is the call graph for this function:

◆ ConvertToI32()

Node* v8::internal::compiler::JSBinopReduction::ConvertToI32 ( bool  is_signed,
Node *  node 
)
inlineprivate

Definition at line 194 of file js-typed-lowering.cc.

194  {
195  Type* type = is_signed ? Type::Signed32() : Type::Unsigned32();
196  if (node->OwnedBy(node_)) {
197  // If this node {node_} has the only edge to {node}, then try narrowing
198  // its operation to an Int32 add or subtract.
199  if (TryNarrowingToI32(type, node)) return node;
200  } else {
201  // Otherwise, {node} has multiple uses. Leave it as is and let the
202  // further lowering passes deal with it, which use a full backwards
203  // fixpoint.
204  }
205 
206  // Avoid introducing too many eager NumberToXXnt32() operations.
207  node = ConvertToNumber(node);
208  Type* input_type = NodeProperties::GetBounds(node).upper;
209 
210  if (input_type->Is(type)) return node; // already in the value range.
211 
212  const Operator* op = is_signed ? simplified()->NumberToInt32()
213  : simplified()->NumberToUint32();
214  Node* n = graph()->NewNode(op, node);
215  return n;
216  }
bool TryNarrowingToI32(Type *type, Node *node)
TypeImpl< ZoneTypeConfig > Type

References ConvertToNumber(), v8::internal::compiler::NodeProperties::GetBounds(), graph(), v8::internal::TypeImpl< Config >::Is(), v8::internal::compiler::Graph::NewNode(), node_, simplified(), TryNarrowingToI32(), and v8::internal::BoundsImpl< Config >::upper.

Referenced by ConvertInputsForShift(), and ConvertInputsToInt32().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertToNumber()

Node* v8::internal::compiler::JSBinopReduction::ConvertToNumber ( Node *  node)
inlineprivate

Definition at line 156 of file js-typed-lowering.cc.

156  {
157  // Avoid introducing too many eager ToNumber() operations.
158  Reduction reduced = lowering_->ReduceJSToNumberInput(node);
159  if (reduced.Changed()) return reduced.replacement();
160  Node* n = graph()->NewNode(javascript()->ToNumber(), node, context(),
161  effect(), control());
162  update_effect(n);
163  return n;
164  }
int ToNumber(Register reg)

References context(), control(), effect(), graph(), javascript(), lowering_, v8::internal::compiler::Graph::NewNode(), v8::internal::ToNumber(), and update_effect().

Referenced by ConvertInputsToNumber(), and ConvertToI32().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ConvertToString()

Node* v8::internal::compiler::JSBinopReduction::ConvertToString ( Node *  node)
inlineprivate

Definition at line 146 of file js-typed-lowering.cc.

146  {
147  // Avoid introducing too many eager ToString() operations.
148  Reduction reduced = lowering_->ReduceJSToStringInput(node);
149  if (reduced.Changed()) return reduced.replacement();
150  Node* n = graph()->NewNode(javascript()->ToString(), node, context(),
151  effect(), control());
152  update_effect(n);
153  return n;
154  }

References context(), control(), effect(), graph(), javascript(), lowering_, v8::internal::compiler::Graph::NewNode(), and update_effect().

Referenced by ConvertInputsToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ effect()

Node* v8::internal::compiler::JSBinopReduction::effect ( )
inline

Definition at line 126 of file js-typed-lowering.cc.

static Node * GetEffectInput(Node *node, int index=0)

References v8::internal::compiler::NodeProperties::GetEffectInput(), and node_.

Referenced by ConvertToNumber(), ConvertToString(), and update_effect().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ graph()

Graph* v8::internal::compiler::JSBinopReduction::graph ( )
inline

Definition at line 135 of file js-typed-lowering.cc.

135 { return lowering_->graph(); }

References lowering_.

Referenced by ChangeToPureOperator(), ConvertInputsForShift(), ConvertToI32(), ConvertToNumber(), and ConvertToString().

+ Here is the caller graph for this function:

◆ javascript()

JSOperatorBuilder* v8::internal::compiler::JSBinopReduction::javascript ( )
inline

Definition at line 137 of file js-typed-lowering.cc.

137 { return lowering_->javascript(); }

References lowering_.

Referenced by ConvertToNumber(), and ConvertToString().

+ Here is the caller graph for this function:

◆ jsgraph()

JSGraph* v8::internal::compiler::JSBinopReduction::jsgraph ( )
inline

Definition at line 136 of file js-typed-lowering.cc.

136 { return lowering_->jsgraph(); }

References lowering_.

Referenced by ConvertInputsForShift().

+ Here is the caller graph for this function:

◆ left()

Node* v8::internal::compiler::JSBinopReduction::left ( )
inline

Definition at line 129 of file js-typed-lowering.cc.

129 { return NodeProperties::GetValueInput(node_, 0); }
static Node * GetValueInput(Node *node, int index)

References v8::internal::compiler::NodeProperties::GetValueInput(), and node_.

Referenced by ConvertInputsForShift(), ConvertInputsToInt32(), ConvertInputsToNumber(), ConvertInputsToString(), and SwapInputs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ left_type()

Type* v8::internal::compiler::JSBinopReduction::left_type ( )
inline

Definition at line 131 of file js-typed-lowering.cc.

131 { return left_type_; }

References left_type_.

◆ machine()

MachineOperatorBuilder* v8::internal::compiler::JSBinopReduction::machine ( )
inline

Definition at line 138 of file js-typed-lowering.cc.

138 { return lowering_->machine(); }

References lowering_.

Referenced by ConvertInputsForShift().

+ Here is the caller graph for this function:

◆ NeitherInputCanBe()

bool v8::internal::compiler::JSBinopReduction::NeitherInputCanBe ( Type t)
inline

Definition at line 122 of file js-typed-lowering.cc.

122  {
123  return !left_type_->Maybe(t) && !right_type_->Maybe(t);
124  }
bool Maybe(TypeImpl *that)
Definition: types.cc:504

References left_type_, v8::internal::TypeImpl< Config >::Maybe(), and right_type_.

+ Here is the call graph for this function:

◆ OneInputCannotBe()

bool v8::internal::compiler::JSBinopReduction::OneInputCannotBe ( Type t)
inline

Definition at line 118 of file js-typed-lowering.cc.

118  {
119  return !left_type_->Maybe(t) || !right_type_->Maybe(t);
120  }

References left_type_, v8::internal::TypeImpl< Config >::Maybe(), and right_type_.

+ Here is the call graph for this function:

◆ OneInputIs()

bool v8::internal::compiler::JSBinopReduction::OneInputIs ( Type t)
inline

Definition at line 112 of file js-typed-lowering.cc.

112 { return left_type_->Is(t) || right_type_->Is(t); }

References v8::internal::TypeImpl< Config >::Is(), left_type_, and right_type_.

+ Here is the call graph for this function:

◆ right()

Node* v8::internal::compiler::JSBinopReduction::right ( )
inline

Definition at line 130 of file js-typed-lowering.cc.

130 { return NodeProperties::GetValueInput(node_, 1); }

References v8::internal::compiler::NodeProperties::GetValueInput(), and node_.

Referenced by ConvertInputsForShift(), ConvertInputsToInt32(), ConvertInputsToNumber(), ConvertInputsToString(), and SwapInputs().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ right_type()

Type* v8::internal::compiler::JSBinopReduction::right_type ( )
inline

Definition at line 132 of file js-typed-lowering.cc.

132 { return right_type_; }

References right_type_.

◆ simplified()

SimplifiedOperatorBuilder* v8::internal::compiler::JSBinopReduction::simplified ( )
inline

Definition at line 134 of file js-typed-lowering.cc.

134 { return lowering_->simplified(); }

References lowering_.

Referenced by ChangeToPureOperator(), and ConvertToI32().

+ Here is the caller graph for this function:

◆ SwapInputs()

void v8::internal::compiler::JSBinopReduction::SwapInputs ( )
inline

Definition at line 76 of file js-typed-lowering.cc.

76  {
77  Node* l = left();
78  Node* r = right();
79  node_->ReplaceInput(0, r);
80  node_->ReplaceInput(1, l);
81  std::swap(left_type_, right_type_);
82  }

References left(), left_type_, node_, right(), and right_type_.

+ Here is the call graph for this function:

◆ TryNarrowingToI32()

bool v8::internal::compiler::JSBinopReduction::TryNarrowingToI32 ( Type type,
Node *  node 
)
inlineprivate

Definition at line 167 of file js-typed-lowering.cc.

167  {
168  switch (node->opcode()) {
169  case IrOpcode::kFloat64Add:
170  case IrOpcode::kNumberAdd: {
171  JSBinopReduction r(lowering_, node);
172  if (r.BothInputsAre(Type::Integral32())) {
173  node->set_op(lowering_->machine()->Int32Add());
174  // TODO(titzer): narrow bounds instead of overwriting.
175  NodeProperties::SetBounds(node, Bounds(type));
176  return true;
177  }
178  }
179  case IrOpcode::kFloat64Sub:
180  case IrOpcode::kNumberSubtract: {
181  JSBinopReduction r(lowering_, node);
182  if (r.BothInputsAre(Type::Integral32())) {
183  node->set_op(lowering_->machine()->Int32Sub());
184  // TODO(titzer): narrow bounds instead of overwriting.
185  NodeProperties::SetBounds(node, Bounds(type));
186  return true;
187  }
188  }
189  default:
190  return false;
191  }
192  }
JSBinopReduction(JSTypedLowering *lowering, Node *node)
static void SetBounds(Node *node, Bounds bounds)
BoundsImpl< ZoneTypeConfig > Bounds
Definition: types.h:1047

References BothInputsAre(), lowering_, and v8::internal::compiler::NodeProperties::SetBounds().

Referenced by ConvertToI32().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ update_effect()

void v8::internal::compiler::JSBinopReduction::update_effect ( Node *  effect)
inlineprivate

Definition at line 218 of file js-typed-lowering.cc.

218  {
220  }
static void ReplaceEffectInput(Node *node, Node *effect, int index=0)

References effect(), node_, and v8::internal::compiler::NodeProperties::ReplaceEffectInput().

Referenced by ConvertToNumber(), and ConvertToString().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Member Data Documentation

◆ left_type_

Type* v8::internal::compiler::JSBinopReduction::left_type_
private

◆ lowering_

JSTypedLowering* v8::internal::compiler::JSBinopReduction::lowering_
private

◆ node_

◆ right_type_

Type* v8::internal::compiler::JSBinopReduction::right_type_
private

The documentation for this class was generated from the following file: