5 #ifndef V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ 6 #define V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_ 8 #include "src/compiler/bytecode-analysis.h" 9 #include "src/compiler/js-graph.h" 10 #include "src/compiler/js-type-hint-lowering.h" 11 #include "src/compiler/state-values-utils.h" 12 #include "src/interpreter/bytecode-array-iterator.h" 13 #include "src/interpreter/bytecode-flags.h" 14 #include "src/interpreter/bytecodes.h" 15 #include "src/source-position-table.h" 25 class SourcePositionTable;
37 int inlining_id = SourcePosition::kNotInlined,
39 bool stack_check =
true,
bool analyze_environment_liveness =
true);
49 void RemoveMergeEnvironmentsBeforeOffset(
int limit_offset);
50 void AdvanceToOsrEntryAndPeelLoops(
54 void VisitSingleBytecode(
56 void VisitBytecodes();
59 Node* GetFunctionClosure();
62 Node* BuildLoadNativeContextField(
int index);
68 void set_environment(
Environment* env) { environment_ = env; }
69 const Environment* environment()
const {
return environment_; }
73 Node* NewNode(
const Operator* op,
bool incomplete =
false) {
74 return MakeNode(op, 0, static_cast<Node**>(
nullptr), incomplete);
78 Node* buffer[] = {n1};
79 return MakeNode(op, arraysize(buffer), buffer,
false);
83 Node* buffer[] = {n1, n2};
84 return MakeNode(op, arraysize(buffer), buffer,
false);
88 Node* buffer[] = {n1, n2, n3};
89 return MakeNode(op, arraysize(buffer), buffer,
false);
93 Node* buffer[] = {n1, n2, n3, n4};
94 return MakeNode(op, arraysize(buffer), buffer,
false);
99 Node* buffer[] = {n1, n2, n3, n4, n5, n6};
100 return MakeNode(op, arraysize(buffer), buffer,
false);
104 Node* NewIfTrue() {
return NewNode(common()->IfTrue()); }
105 Node* NewIfFalse() {
return NewNode(common()->IfFalse()); }
106 Node* NewIfValue(int32_t value) {
return NewNode(common()->IfValue(value)); }
107 Node* NewIfDefault() {
return NewNode(common()->IfDefault()); }
108 Node* NewMerge() {
return NewNode(common()->Merge(1),
true); }
109 Node* NewLoop() {
return NewNode(common()->Loop(1),
true); }
110 Node* NewBranch(
Node* condition, BranchHint hint = BranchHint::kNone,
111 IsSafetyCheck is_safety_check = IsSafetyCheck::kSafetyCheck) {
112 return NewNode(common()->Branch(hint, is_safety_check), condition);
114 Node* NewSwitch(
Node* condition,
int control_output_count) {
115 return NewNode(common()->Switch(control_output_count), condition);
120 Node* NewEffectPhi(
int count,
Node* input,
Node* control);
129 Node* MakeNode(
const Operator* op,
int value_input_count,
130 Node*
const* value_inputs,
bool incomplete);
132 Node** EnsureInputBufferSize(
int size);
134 Node*
const* GetCallArgumentsFromRegisters(
Node* callee,
Node* receiver,
137 Node*
const* ProcessCallVarArgs(ConvertReceiverMode receiver_mode,
144 Node*
const* GetConstructArgumentsFromRegister(
149 Node* ProcessCallRuntimeArguments(
const Operator* call_runtime_op,
156 void PrepareEagerCheckpoint();
163 void BuildCreateArguments(CreateArgumentsType
type);
165 TypeofMode typeof_mode);
167 enum class StoreMode {
173 void BuildNamedStore(StoreMode store_mode);
174 void BuildLdaLookupSlot(TypeofMode typeof_mode);
175 void BuildLdaLookupContextSlot(TypeofMode typeof_mode);
176 void BuildLdaLookupGlobalSlot(TypeofMode typeof_mode);
177 void BuildCallVarArgs(ConvertReceiverMode receiver_mode);
178 void BuildCall(ConvertReceiverMode receiver_mode,
Node*
const* args,
179 size_t arg_count,
int slot_id);
180 void BuildCall(ConvertReceiverMode receiver_mode,
181 std::initializer_list<Node*> args,
int slot_id) {
182 BuildCall(receiver_mode, args.begin(), args.size(), slot_id);
184 void BuildUnaryOp(
const Operator* op);
185 void BuildBinaryOp(
const Operator* op);
186 void BuildBinaryOpWithImmediate(
const Operator* op);
187 void BuildCompareOp(
const Operator* op);
188 void BuildDelete(LanguageMode language_mode);
189 void BuildCastOperator(
const Operator* op);
190 void BuildHoleCheckAndThrow(
Node* condition, Runtime::FunctionId runtime_id,
191 Node* name =
nullptr);
231 BinaryOperationHint GetBinaryOperationHint(
int operand_index);
235 CompareOperationHint GetCompareOperationHint();
238 ForInMode GetForInMode(
int operand_index);
246 SpeculationMode GetSpeculationMode(
int slot_id)
const;
250 void BuildJumpIf(
Node* condition);
251 void BuildJumpIfNot(
Node* condition);
252 void BuildJumpIfEqual(
Node* comperand);
253 void BuildJumpIfNotEqual(
Node* comperand);
254 void BuildJumpIfTrue();
255 void BuildJumpIfFalse();
256 void BuildJumpIfToBooleanTrue();
257 void BuildJumpIfToBooleanFalse();
258 void BuildJumpIfNotHole();
259 void BuildJumpIfJSReceiver();
261 void BuildSwitchOnSmi(
Node* condition);
262 void BuildSwitchOnGeneratorState(
264 bool allow_fallthrough_on_executing);
267 void MergeIntoSuccessorEnvironment(
int target_offset);
268 void BuildLoopHeaderEnvironment(
int current_offset);
269 void SwitchToMergeEnvironment(
int current_offset);
272 void MergeControlToLeaveFunction(
Node* exit);
276 void BuildLoopExitsForBranch(
int target_offset);
278 void BuildLoopExitsUntilLoop(
int loop_offset,
285 void ExitThenEnterExceptionHandlers(
int current_offset);
293 static const int kInputBufferSizeIncrement = 64;
299 struct ExceptionHandler {
303 int context_register_;
307 Graph* graph()
const {
return jsgraph_->graph(); }
309 Zone* graph_zone()
const {
return graph()->zone(); }
310 JSGraph* jsgraph()
const {
return jsgraph_; }
311 Isolate* isolate()
const {
return jsgraph_->isolate(); }
314 return jsgraph_->simplified();
316 Zone* local_zone()
const {
return local_zone_; }
318 return bytecode_array_;
321 return feedback_vector_;
324 return type_hint_lowering_;
327 return frame_state_function_info_;
331 return *bytecode_iterator_;
334 void set_bytecode_iterator(
336 bytecode_iterator_ = bytecode_iterator;
340 return bytecode_analysis_;
344 bytecode_analysis_ = bytecode_analysis;
347 int currently_peeled_loop_offset()
const {
348 return currently_peeled_loop_offset_;
351 void set_currently_peeled_loop_offset(
int offset) {
352 currently_peeled_loop_offset_ = offset;
355 bool stack_check()
const {
return stack_check_; }
357 void set_stack_check(
bool stack_check) { stack_check_ = stack_check; }
359 bool analyze_environment_liveness()
const {
360 return analyze_environment_liveness_;
363 int current_exception_handler() {
return current_exception_handler_; }
365 void set_current_exception_handler(
int index) {
366 current_exception_handler_ = index;
369 bool needs_eager_checkpoint()
const {
return needs_eager_checkpoint_; }
370 void mark_as_needing_eager_checkpoint(
bool value) {
371 needs_eager_checkpoint_ = value;
376 #define DECLARE_VISIT_BYTECODE(name, ...) void Visit##name(); 377 BYTECODE_LIST(DECLARE_VISIT_BYTECODE)
378 #undef DECLARE_VISIT_BYTECODE 391 int currently_peeled_loop_offset_;
393 bool analyze_environment_liveness_;
411 int current_exception_handler_;
414 int input_buffer_size_;
415 Node** input_buffer_;
420 bool needs_eager_checkpoint_;
438 static int const kBinaryOperationHintIndex = 1;
439 static int const kCountOperationHintIndex = 0;
440 static int const kBinaryOperationSmiHintIndex = 1;
441 static int const kUnaryOperationHintIndex = 0;
450 #endif // V8_COMPILER_BYTECODE_GRAPH_BUILDER_H_