Flutter Engine
The Flutter Engine
Public Member Functions | Private Member Functions | List of all members
dart::JitCallSpecializer Class Reference

#include <jit_call_specializer.h>

Inheritance diagram for dart::JitCallSpecializer:
dart::CallSpecializer dart::FlowGraphVisitor dart::InstructionVisitor dart::ValueObject

Public Member Functions

 JitCallSpecializer (FlowGraph *flow_graph, SpeculativeInliningPolicy *speculative_policy)
 
virtual ~JitCallSpecializer ()
 
virtual void VisitInstanceCall (InstanceCallInstr *instr)
 
virtual void VisitAllocateContext (AllocateContextInstr *instr)
 
virtual void VisitCloneContext (CloneContextInstr *instr)
 
- Public Member Functions inherited from dart::CallSpecializer
 CallSpecializer (FlowGraph *flow_graph, SpeculativeInliningPolicy *speculative_policy, bool should_clone_fields)
 
virtual ~CallSpecializer ()
 
FlowGraphflow_graph () const
 
void set_flow_graph (FlowGraph *flow_graph)
 
void ApplyICData ()
 
void ApplyClassIds ()
 
virtual void ReplaceInstanceCallsWithDispatchTableCalls ()
 
void InsertBefore (Instruction *next, Instruction *instr, Environment *env, FlowGraph::UseKind use_kind)
 
void InsertSpeculativeBefore (Instruction *next, Instruction *instr, Environment *env, FlowGraph::UseKind use_kind)
 
virtual void VisitStaticCall (StaticCallInstr *instr)
 
virtual void VisitLoadCodeUnits (LoadCodeUnitsInstr *instr)
 
- Public Member Functions inherited from dart::FlowGraphVisitor
 FlowGraphVisitor (const GrowableArray< BlockEntryInstr * > &block_order)
 
virtual ~FlowGraphVisitor ()
 
ForwardInstructionIteratorcurrent_iterator () const
 
virtual void VisitBlocks ()
 
- Public Member Functions inherited from dart::InstructionVisitor
 InstructionVisitor ()
 
virtual ~InstructionVisitor ()
 
- Public Member Functions inherited from dart::ValueObject
 ValueObject ()
 
 ~ValueObject ()
 

Private Member Functions

virtual bool IsAllowedForInlining (intptr_t deopt_id) const
 
virtual bool TryOptimizeStaticCallUsingStaticTypes (StaticCallInstr *call)
 

Additional Inherited Members

- Protected Member Functions inherited from dart::CallSpecializer
Threadthread () const
 
IsolateGroupisolate_group () const
 
Zonezone () const
 
const Functionfunction () const
 
bool TryReplaceWithBinaryOp (InstanceCallInstr *call, Token::Kind op_kind)
 
bool TryReplaceWithUnaryOp (InstanceCallInstr *call, Token::Kind op_kind)
 
bool TryReplaceWithEqualityOp (InstanceCallInstr *call, Token::Kind op_kind)
 
bool TryReplaceWithRelationalOp (InstanceCallInstr *call, Token::Kind op_kind)
 
bool TryInlineInstanceGetter (InstanceCallInstr *call)
 
bool TryInlineInstanceSetter (InstanceCallInstr *call)
 
bool TryInlineInstanceMethod (InstanceCallInstr *call)
 
void ReplaceWithInstanceOf (InstanceCallInstr *instr)
 
void ReplaceCallWithResult (Definition *call, Instruction *replacement, Definition *result)
 
void ReplaceCall (Definition *call, Definition *replacement)
 
void AddReceiverCheck (InstanceCallInstr *call)
 
void AddCheckNull (Value *to_check, const String &function_name, intptr_t deopt_id, Environment *deopt_environment, Instruction *insert_before)
 
virtual bool TryCreateICData (InstanceCallInstr *call)
 
virtual bool TryReplaceInstanceOfWithRangeCheck (InstanceCallInstr *call, const AbstractType &type)
 
virtual bool TryOptimizeStaticCallUsingStaticTypes (StaticCallInstr *call)=0
 
void InlineImplicitInstanceGetter (Definition *call, const Field &field)
 
void AddCheckClass (Definition *to_check, const Cids &cids, intptr_t deopt_id, Environment *deopt_environment, Instruction *insert_before)
 
- Protected Member Functions inherited from dart::FlowGraphVisitor
void set_block_order (const GrowableArray< BlockEntryInstr * > &block_order)
 
- Protected Attributes inherited from dart::CallSpecializer
SpeculativeInliningPolicyspeculative_policy_
 
const bool should_clone_fields_
 
- Protected Attributes inherited from dart::FlowGraphVisitor
ForwardInstructionIteratorcurrent_iterator_
 

Detailed Description

Definition at line 16 of file jit_call_specializer.h.

Constructor & Destructor Documentation

◆ JitCallSpecializer()

dart::JitCallSpecializer::JitCallSpecializer ( FlowGraph flow_graph,
SpeculativeInliningPolicy speculative_policy 
)
explicit

Definition at line 32 of file jit_call_specializer.cc.

36 speculative_policy,
37 CompilerState::Current().should_clone_fields()) {}
FlowGraph * flow_graph() const
CallSpecializer(FlowGraph *flow_graph, SpeculativeInliningPolicy *speculative_policy, bool should_clone_fields)
static CompilerState & Current()

◆ ~JitCallSpecializer()

virtual dart::JitCallSpecializer::~JitCallSpecializer ( )
inlinevirtual

Definition at line 21 of file jit_call_specializer.h.

21{}

Member Function Documentation

◆ IsAllowedForInlining()

bool dart::JitCallSpecializer::IsAllowedForInlining ( intptr_t  deopt_id) const
privatevirtual

Definition at line 39 of file jit_call_specializer.cc.

39 {
40 return true;
41}

◆ TryOptimizeStaticCallUsingStaticTypes()

bool dart::JitCallSpecializer::TryOptimizeStaticCallUsingStaticTypes ( StaticCallInstr call)
privatevirtual

Implements dart::CallSpecializer.

Definition at line 43 of file jit_call_specializer.cc.

44 {
45 return false;
46}

◆ VisitAllocateContext()

void dart::JitCallSpecializer::VisitAllocateContext ( AllocateContextInstr instr)
virtual

Definition at line 211 of file jit_call_specializer.cc.

211 {
212 LowerContextAllocation(instr, instr->context_slots(), nullptr);
213}

◆ VisitCloneContext()

void dart::JitCallSpecializer::VisitCloneContext ( CloneContextInstr instr)
virtual

Definition at line 215 of file jit_call_specializer.cc.

215 {
216 LowerContextAllocation(instr, instr->context_slots(), instr->context_value());
217}

◆ VisitInstanceCall()

void dart::JitCallSpecializer::VisitInstanceCall ( InstanceCallInstr instr)
virtual

Definition at line 67 of file jit_call_specializer.cc.

67 {
68 const CallTargets& targets = instr->Targets();
69 if (targets.is_empty()) {
70 return; // No feedback.
71 }
72
73 const Token::Kind op_kind = instr->token_kind();
74
75 // Type test is special as it always gets converted into inlined code.
76 if (Token::IsTypeTestOperator(op_kind)) {
78 return;
79 }
80
81 if (op_kind == Token::kEQ && TryReplaceWithEqualityOp(instr, op_kind)) {
82 return;
83 }
84
85 if (Token::IsRelationalOperator(op_kind) &&
86 TryReplaceWithRelationalOp(instr, op_kind)) {
87 return;
88 }
89
90 if (Token::IsBinaryOperator(op_kind) &&
91 TryReplaceWithBinaryOp(instr, op_kind)) {
92 return;
93 }
94 if (Token::IsUnaryOperator(op_kind) &&
95 TryReplaceWithUnaryOp(instr, op_kind)) {
96 return;
97 }
98 if ((op_kind == Token::kGET) && TryInlineInstanceGetter(instr)) {
99 return;
100 }
101 if ((op_kind == Token::kSET) && TryInlineInstanceSetter(instr)) {
102 return;
103 }
104 if (TryInlineInstanceMethod(instr)) {
105 return;
106 }
107
108 bool has_one_target = targets.HasSingleTarget();
109 if (has_one_target) {
110 // Check if the single target is a polymorphic target, if it is,
111 // we don't have one target.
112 const Function& target = targets.FirstTarget();
113 if (target.recognized_kind() == MethodRecognizer::kObjectRuntimeType) {
115 targets) != Type::null();
116 } else {
117 has_one_target =
118 !target.is_polymorphic_target() && !target.IsDynamicallyOverridden();
119 }
120 }
121
122 if (has_one_target) {
123 const Function& target = targets.FirstTarget();
124 if (flow_graph()->CheckForInstanceCall(instr, target.kind()) ==
126 ReplaceWithStaticCall(instr, target, targets.AggregateCallCount());
127 return;
128 }
129 }
130
131 // If there is only one target we can make this into a deopting class check,
132 // followed by a call instruction that does not check the class of the
133 // receiver. This enables a lot of optimizations because after the class
134 // check we can probably inline the call and not worry about side effects.
135 // However, this can fall down if new receiver classes arrive at this call
136 // site after we generated optimized code. This causes a deopt, and after a
137 // few deopts we won't optimize this function any more at all. Therefore for
138 // very polymorphic sites we don't make this optimization, keeping it as a
139 // regular checked PolymorphicInstanceCall, which falls back to the slow but
140 // non-deopting megamorphic call stub when it sees new receiver classes.
141 if (has_one_target && FLAG_polymorphic_with_deopt &&
142 (!instr->ic_data()->HasDeoptReason(ICData::kDeoptCheckClass) ||
143 targets.length() <= FLAG_max_polymorphic_checks)) {
144 // Type propagation has not run yet, we cannot eliminate the check.
145 AddReceiverCheck(instr);
146
147 // Call can still deoptimize, do not detach environment from instr.
148 const Function& target = targets.FirstTarget();
149 ReplaceWithStaticCall(instr, target, targets.AggregateCallCount());
150 } else {
151 PolymorphicInstanceCallInstr* call =
153 /* complete = */ false);
154 instr->ReplaceWith(call, current_iterator());
155 }
156}
void AddReceiverCheck(InstanceCallInstr *call)
bool TryReplaceWithEqualityOp(InstanceCallInstr *call, Token::Kind op_kind)
bool TryInlineInstanceSetter(InstanceCallInstr *call)
bool TryInlineInstanceGetter(InstanceCallInstr *call)
bool TryReplaceWithRelationalOp(InstanceCallInstr *call, Token::Kind op_kind)
bool TryReplaceWithUnaryOp(InstanceCallInstr *call, Token::Kind op_kind)
void ReplaceWithInstanceOf(InstanceCallInstr *instr)
bool TryReplaceWithBinaryOp(InstanceCallInstr *call, Token::Kind op_kind)
bool TryInlineInstanceMethod(InstanceCallInstr *call)
ForwardInstructionIterator * current_iterator() const
Definition: il.h:11846
static ObjectPtr null()
Definition: object.h:433
static TypePtr ComputeRuntimeType(const CallTargets &targets)
Definition: il.cc:5568
static PolymorphicInstanceCallInstr * FromCall(Zone *zone, InstanceCallBaseInstr *call, const CallTargets &targets, bool complete)
Definition: il.h:4924
static bool IsTypeTestOperator(Kind tok)
Definition: token.h:244
static bool IsRelationalOperator(Kind tok)
Definition: token.h:232
static bool IsBinaryOperator(Token::Kind token)
Definition: token.cc:31
static bool IsUnaryOperator(Token::Kind token)
Definition: token.cc:41
uint32_t * target
#define Z
def call(args)
Definition: dom.py:159

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