1 /*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "compiler_filter.h"
18
19 #include "utils.h"
20
21 namespace art {
22
IsBytecodeCompilationEnabled(Filter filter)23 bool CompilerFilter::IsBytecodeCompilationEnabled(Filter filter) {
24 switch (filter) {
25 case CompilerFilter::kVerifyNone:
26 case CompilerFilter::kVerifyAtRuntime:
27 case CompilerFilter::kVerifyProfile:
28 case CompilerFilter::kInterpretOnly: return false;
29
30 case CompilerFilter::kSpaceProfile:
31 case CompilerFilter::kSpace:
32 case CompilerFilter::kBalanced:
33 case CompilerFilter::kTime:
34 case CompilerFilter::kSpeedProfile:
35 case CompilerFilter::kSpeed:
36 case CompilerFilter::kEverythingProfile:
37 case CompilerFilter::kEverything: return true;
38 }
39 UNREACHABLE();
40 }
41
IsJniCompilationEnabled(Filter filter)42 bool CompilerFilter::IsJniCompilationEnabled(Filter filter) {
43 switch (filter) {
44 case CompilerFilter::kVerifyNone:
45 case CompilerFilter::kVerifyAtRuntime: return false;
46
47 case CompilerFilter::kVerifyProfile:
48 case CompilerFilter::kInterpretOnly:
49 case CompilerFilter::kSpaceProfile:
50 case CompilerFilter::kSpace:
51 case CompilerFilter::kBalanced:
52 case CompilerFilter::kTime:
53 case CompilerFilter::kSpeedProfile:
54 case CompilerFilter::kSpeed:
55 case CompilerFilter::kEverythingProfile:
56 case CompilerFilter::kEverything: return true;
57 }
58 UNREACHABLE();
59 }
60
IsVerificationEnabled(Filter filter)61 bool CompilerFilter::IsVerificationEnabled(Filter filter) {
62 switch (filter) {
63 case CompilerFilter::kVerifyNone:
64 case CompilerFilter::kVerifyAtRuntime: return false;
65
66 case CompilerFilter::kVerifyProfile:
67 case CompilerFilter::kInterpretOnly:
68 case CompilerFilter::kSpaceProfile:
69 case CompilerFilter::kSpace:
70 case CompilerFilter::kBalanced:
71 case CompilerFilter::kTime:
72 case CompilerFilter::kSpeedProfile:
73 case CompilerFilter::kSpeed:
74 case CompilerFilter::kEverythingProfile:
75 case CompilerFilter::kEverything: return true;
76 }
77 UNREACHABLE();
78 }
79
DependsOnImageChecksum(Filter filter)80 bool CompilerFilter::DependsOnImageChecksum(Filter filter) {
81 // We run dex2dex with verification, so the oat file will depend on the
82 // image checksum if verification is enabled.
83 return IsVerificationEnabled(filter);
84 }
85
DependsOnProfile(Filter filter)86 bool CompilerFilter::DependsOnProfile(Filter filter) {
87 switch (filter) {
88 case CompilerFilter::kVerifyNone:
89 case CompilerFilter::kVerifyAtRuntime:
90 case CompilerFilter::kInterpretOnly:
91 case CompilerFilter::kSpace:
92 case CompilerFilter::kBalanced:
93 case CompilerFilter::kTime:
94 case CompilerFilter::kSpeed:
95 case CompilerFilter::kEverything: return false;
96
97 case CompilerFilter::kVerifyProfile:
98 case CompilerFilter::kSpaceProfile:
99 case CompilerFilter::kSpeedProfile:
100 case CompilerFilter::kEverythingProfile: return true;
101 }
102 UNREACHABLE();
103 }
104
GetNonProfileDependentFilterFrom(Filter filter)105 CompilerFilter::Filter CompilerFilter::GetNonProfileDependentFilterFrom(Filter filter) {
106 switch (filter) {
107 case CompilerFilter::kVerifyNone:
108 case CompilerFilter::kVerifyAtRuntime:
109 case CompilerFilter::kInterpretOnly:
110 case CompilerFilter::kSpace:
111 case CompilerFilter::kBalanced:
112 case CompilerFilter::kTime:
113 case CompilerFilter::kSpeed:
114 case CompilerFilter::kEverything:
115 return filter;
116
117 case CompilerFilter::kVerifyProfile:
118 return CompilerFilter::kInterpretOnly;
119
120 case CompilerFilter::kSpaceProfile:
121 return CompilerFilter::kSpace;
122
123 case CompilerFilter::kSpeedProfile:
124 return CompilerFilter::kSpeed;
125
126 case CompilerFilter::kEverythingProfile:
127 return CompilerFilter::kEverything;
128 }
129 UNREACHABLE();
130 }
131
132
IsAsGoodAs(Filter current,Filter target)133 bool CompilerFilter::IsAsGoodAs(Filter current, Filter target) {
134 return current >= target;
135 }
136
NameOfFilter(Filter filter)137 std::string CompilerFilter::NameOfFilter(Filter filter) {
138 switch (filter) {
139 case CompilerFilter::kVerifyNone: return "verify-none";
140 case CompilerFilter::kVerifyAtRuntime: return "verify-at-runtime";
141 case CompilerFilter::kVerifyProfile: return "verify-profile";
142 case CompilerFilter::kInterpretOnly: return "interpret-only";
143 case CompilerFilter::kSpaceProfile: return "space-profile";
144 case CompilerFilter::kSpace: return "space";
145 case CompilerFilter::kBalanced: return "balanced";
146 case CompilerFilter::kTime: return "time";
147 case CompilerFilter::kSpeedProfile: return "speed-profile";
148 case CompilerFilter::kSpeed: return "speed";
149 case CompilerFilter::kEverythingProfile: return "everything-profile";
150 case CompilerFilter::kEverything: return "everything";
151 }
152 UNREACHABLE();
153 }
154
ParseCompilerFilter(const char * option,Filter * filter)155 bool CompilerFilter::ParseCompilerFilter(const char* option, Filter* filter) {
156 CHECK(filter != nullptr);
157
158 if (strcmp(option, "verify-none") == 0) {
159 *filter = kVerifyNone;
160 } else if (strcmp(option, "interpret-only") == 0) {
161 *filter = kInterpretOnly;
162 } else if (strcmp(option, "verify-profile") == 0) {
163 *filter = kVerifyProfile;
164 } else if (strcmp(option, "verify-at-runtime") == 0) {
165 *filter = kVerifyAtRuntime;
166 } else if (strcmp(option, "space") == 0) {
167 *filter = kSpace;
168 } else if (strcmp(option, "space-profile") == 0) {
169 *filter = kSpaceProfile;
170 } else if (strcmp(option, "balanced") == 0) {
171 *filter = kBalanced;
172 } else if (strcmp(option, "speed") == 0) {
173 *filter = kSpeed;
174 } else if (strcmp(option, "speed-profile") == 0) {
175 *filter = kSpeedProfile;
176 } else if (strcmp(option, "everything") == 0) {
177 *filter = kEverything;
178 } else if (strcmp(option, "everything-profile") == 0) {
179 *filter = kEverythingProfile;
180 } else if (strcmp(option, "time") == 0) {
181 *filter = kTime;
182 } else {
183 return false;
184 }
185 return true;
186 }
187
operator <<(std::ostream & os,const CompilerFilter::Filter & rhs)188 std::ostream& operator<<(std::ostream& os, const CompilerFilter::Filter& rhs) {
189 return os << CompilerFilter::NameOfFilter(rhs);
190 }
191
192 } // namespace art
193