1 | // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
2 | // for details. All rights reserved. Use of this source code is governed by a |
3 | // BSD-style license that can be found in the LICENSE file. |
4 | |
5 | #ifndef RUNTIME_VM_COMPILER_AOT_AOT_CALL_SPECIALIZER_H_ |
6 | #define RUNTIME_VM_COMPILER_AOT_AOT_CALL_SPECIALIZER_H_ |
7 | |
8 | #if defined(DART_PRECOMPILED_RUNTIME) |
9 | #error "AOT runtime should not use compiler sources (including header files)" |
10 | #endif // defined(DART_PRECOMPILED_RUNTIME) |
11 | |
12 | #include "vm/compiler/call_specializer.h" |
13 | |
14 | namespace dart { |
15 | |
16 | class Precompiler; |
17 | class SpeculativeInliningPolicy; |
18 | |
19 | class AotCallSpecializer : public CallSpecializer { |
20 | public: |
21 | AotCallSpecializer(Precompiler* precompiler, |
22 | FlowGraph* flow_graph, |
23 | SpeculativeInliningPolicy* speculative_policy); |
24 | |
25 | virtual ~AotCallSpecializer() {} |
26 | |
27 | virtual void VisitInstanceCall(InstanceCallInstr* instr); |
28 | virtual void VisitStaticCall(StaticCallInstr* instr); |
29 | virtual void VisitPolymorphicInstanceCall( |
30 | PolymorphicInstanceCallInstr* instr); |
31 | |
32 | virtual bool TryReplaceInstanceOfWithRangeCheck(InstanceCallInstr* call, |
33 | const AbstractType& type); |
34 | |
35 | private: |
36 | // Attempt to build ICData for call using propagated class-ids. |
37 | virtual bool TryCreateICData(InstanceCallInstr* call); |
38 | |
39 | bool TryCreateICDataForUniqueTarget(InstanceCallInstr* call); |
40 | |
41 | bool RecognizeRuntimeTypeGetter(InstanceCallInstr* call); |
42 | bool TryReplaceWithHaveSameRuntimeType(TemplateDartCall<0>* call); |
43 | |
44 | bool TryInlineFieldAccess(InstanceCallInstr* call); |
45 | bool TryInlineFieldAccess(StaticCallInstr* call); |
46 | |
47 | bool IsSupportedIntOperandForStaticDoubleOp(CompileType* operand_type); |
48 | Value* PrepareStaticOpInput(Value* input, intptr_t cid, Instruction* call); |
49 | |
50 | CompileType BuildStrengthenedReceiverType(Value* input, intptr_t cid); |
51 | |
52 | bool TryOptimizeInstanceCallUsingStaticTypes(InstanceCallInstr* instr); |
53 | |
54 | virtual bool TryOptimizeStaticCallUsingStaticTypes(StaticCallInstr* call); |
55 | |
56 | // If a call can be dispatched through the global dispatch table, replace |
57 | // it by a dispatch table call. |
58 | void TryReplaceWithDispatchTableCall(InstanceCallBaseInstr* call); |
59 | const Function& InterfaceTargetForTableDispatch(InstanceCallBaseInstr* call); |
60 | |
61 | // Try to replace a call with a more specialized instruction working on |
62 | // integers (e.g. BinaryInt64OpInstr, CheckedSmiComparisonInstr, |
63 | // RelationalOpInstr) |
64 | bool TryOptimizeIntegerOperation(TemplateDartCall<0>* call, Token::Kind kind); |
65 | |
66 | // Try to replace a call with a more specialized instruction working on |
67 | // doubles (e.g. BinaryDoubleOpInstr, CheckedSmiComparisonInstr, |
68 | // RelationalOpInstr) |
69 | bool TryOptimizeDoubleOperation(TemplateDartCall<0>* call, Token::Kind kind); |
70 | |
71 | // Check if o.m(...) [call] is actually an invocation through a getter |
72 | // o.get:m().call(...) given that the receiver of the call is a subclass |
73 | // of the [receiver_class]. If it is - then expand it into |
74 | // o.get:m.call(...) to avoid hitting dispatch through noSuchMethod. |
75 | bool TryExpandCallThroughGetter(const Class& receiver_class, |
76 | InstanceCallInstr* call); |
77 | |
78 | Definition* TryOptimizeMod(TemplateDartCall<0>* instr, |
79 | Token::Kind op_kind, |
80 | Value* left_value, |
81 | Value* right_value); |
82 | |
83 | virtual void ReplaceInstanceCallsWithDispatchTableCalls(); |
84 | |
85 | Precompiler* precompiler_; |
86 | |
87 | bool has_unique_no_such_method_; |
88 | |
89 | DISALLOW_COPY_AND_ASSIGN(AotCallSpecializer); |
90 | }; |
91 | |
92 | } // namespace dart |
93 | |
94 | #endif // RUNTIME_VM_COMPILER_AOT_AOT_CALL_SPECIALIZER_H_ |
95 | |