blob: ba01c2b22eaaae22df25d6e5ef3373e3261c9cd0 [file] [log] [blame]
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001/*
2 * Copyright (C) 2014 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#ifndef ART_COMPILER_OPTIMIZING_NODES_H_
18#define ART_COMPILER_OPTIMIZING_NODES_H_
19
Mathieu Chartierb666f482015-02-18 14:33:14 -080020#include "base/arena_object.h"
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +000021#include "entrypoints/quick/quick_entrypoints_enum.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000022#include "handle.h"
23#include "handle_scope.h"
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000024#include "invoke_type.h"
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +010025#include "locations.h"
Calin Juravleacf735c2015-02-12 15:25:22 +000026#include "mirror/class.h"
Nicolas Geoffraye5038322014-07-04 09:41:32 +010027#include "offsets.h"
Ian Rogerse63db272014-07-15 15:36:11 -070028#include "primitive.h"
Nicolas Geoffray0e336432014-02-26 18:24:38 +000029#include "utils/arena_bit_vector.h"
Nicolas Geoffray818f2102014-02-18 16:43:35 +000030#include "utils/growable_array.h"
31
32namespace art {
33
34class HBasicBlock;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010035class HEnvironment;
Nicolas Geoffray818f2102014-02-18 16:43:35 +000036class HInstruction;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +000037class HIntConstant;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000038class HInvoke;
Nicolas Geoffray818f2102014-02-18 16:43:35 +000039class HGraphVisitor;
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +000040class HNullConstant;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010041class HPhi;
Nicolas Geoffray3c049742014-09-24 18:10:46 +010042class HSuspendCheck;
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +010043class LiveInterval;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +000044class LocationSummary;
Nicolas Geoffray818f2102014-02-18 16:43:35 +000045
46static const int kDefaultNumberOfBlocks = 8;
47static const int kDefaultNumberOfSuccessors = 2;
48static const int kDefaultNumberOfPredecessors = 2;
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +010049static const int kDefaultNumberOfDominatedBlocks = 1;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +000050static const int kDefaultNumberOfBackEdges = 1;
Nicolas Geoffray818f2102014-02-18 16:43:35 +000051
Calin Juravle9aec02f2014-11-18 23:06:35 +000052static constexpr uint32_t kMaxIntShiftValue = 0x1f;
53static constexpr uint64_t kMaxLongShiftValue = 0x3f;
54
Dave Allison20dfc792014-06-16 20:44:29 -070055enum IfCondition {
56 kCondEQ,
57 kCondNE,
58 kCondLT,
59 kCondLE,
60 kCondGT,
61 kCondGE,
62};
63
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010064class HInstructionList {
65 public:
66 HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {}
67
68 void AddInstruction(HInstruction* instruction);
69 void RemoveInstruction(HInstruction* instruction);
70
Roland Levillain6b469232014-09-25 10:10:38 +010071 // Return true if this list contains `instruction`.
72 bool Contains(HInstruction* instruction) const;
73
Roland Levillainccc07a92014-09-16 14:48:16 +010074 // Return true if `instruction1` is found before `instruction2` in
75 // this instruction list and false otherwise. Abort if none
76 // of these instructions is found.
77 bool FoundBefore(const HInstruction* instruction1,
78 const HInstruction* instruction2) const;
79
Nicolas Geoffray276d9da2015-02-02 18:24:11 +000080 bool IsEmpty() const { return first_instruction_ == nullptr; }
81 void Clear() { first_instruction_ = last_instruction_ = nullptr; }
82
83 // Update the block of all instructions to be `block`.
84 void SetBlockOfInstructions(HBasicBlock* block) const;
85
86 void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list);
87 void Add(const HInstructionList& instruction_list);
88
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010089 private:
90 HInstruction* first_instruction_;
91 HInstruction* last_instruction_;
92
93 friend class HBasicBlock;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +000094 friend class HGraph;
95 friend class HInstruction;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010096 friend class HInstructionIterator;
Nicolas Geoffray804d0932014-05-02 08:46:00 +010097 friend class HBackwardInstructionIterator;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +010098
99 DISALLOW_COPY_AND_ASSIGN(HInstructionList);
100};
101
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000102// Control-flow graph of a method. Contains a list of basic blocks.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700103class HGraph : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000104 public:
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000105 HGraph(ArenaAllocator* arena, int start_instruction_id = 0)
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000106 : arena_(arena),
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000107 blocks_(arena, kDefaultNumberOfBlocks),
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100108 reverse_post_order_(arena, kDefaultNumberOfBlocks),
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700109 entry_block_(nullptr),
110 exit_block_(nullptr),
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100111 maximum_number_of_out_vregs_(0),
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100112 number_of_vregs_(0),
113 number_of_in_vregs_(0),
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000114 temporaries_vreg_slots_(0),
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000115 current_instruction_id_(start_instruction_id) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000116
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000117 ArenaAllocator* GetArena() const { return arena_; }
Nicolas Geoffray804d0932014-05-02 08:46:00 +0100118 const GrowableArray<HBasicBlock*>& GetBlocks() const { return blocks_; }
Roland Levillain93445682014-10-06 19:24:02 +0100119 HBasicBlock* GetBlock(size_t id) const { return blocks_.Get(id); }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000120
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000121 HBasicBlock* GetEntryBlock() const { return entry_block_; }
122 HBasicBlock* GetExitBlock() const { return exit_block_; }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000123
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000124 void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; }
125 void SetExitBlock(HBasicBlock* block) { exit_block_ = block; }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000126
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000127 void AddBlock(HBasicBlock* block);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100128
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000129 // Try building the SSA form of this graph, with dominance computation and loop
130 // recognition. Returns whether it was successful in doing all these steps.
131 bool TryBuildingSsa() {
132 BuildDominatorTree();
133 TransformToSsa();
134 return AnalyzeNaturalLoops();
135 }
136
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000137 void BuildDominatorTree();
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000138 void TransformToSsa();
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100139 void SimplifyCFG();
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000140
Nicolas Geoffrayf5370122014-12-02 11:51:19 +0000141 // Analyze all natural loops in this graph. Returns false if one
142 // loop is not natural, that is the header does not dominate the
143 // back edge.
144 bool AnalyzeNaturalLoops() const;
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100145
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000146 // Inline this graph in `outer_graph`, replacing the given `invoke` instruction.
147 void InlineInto(HGraph* outer_graph, HInvoke* invoke);
148
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100149 void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor);
150 void SimplifyLoop(HBasicBlock* header);
151
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000152 int32_t GetNextInstructionId() {
153 DCHECK_NE(current_instruction_id_, INT32_MAX);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000154 return current_instruction_id_++;
155 }
156
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000157 int32_t GetCurrentInstructionId() const {
158 return current_instruction_id_;
159 }
160
161 void SetCurrentInstructionId(int32_t id) {
162 current_instruction_id_ = id;
163 }
164
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100165 uint16_t GetMaximumNumberOfOutVRegs() const {
166 return maximum_number_of_out_vregs_;
167 }
168
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000169 void SetMaximumNumberOfOutVRegs(uint16_t new_value) {
170 maximum_number_of_out_vregs_ = new_value;
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100171 }
172
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000173 void UpdateTemporariesVRegSlots(size_t slots) {
174 temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_);
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100175 }
176
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000177 size_t GetTemporariesVRegSlots() const {
178 return temporaries_vreg_slots_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100179 }
180
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100181 void SetNumberOfVRegs(uint16_t number_of_vregs) {
182 number_of_vregs_ = number_of_vregs;
183 }
184
185 uint16_t GetNumberOfVRegs() const {
186 return number_of_vregs_;
187 }
188
189 void SetNumberOfInVRegs(uint16_t value) {
190 number_of_in_vregs_ = value;
191 }
192
Nicolas Geoffrayab032bc2014-07-15 12:55:21 +0100193 uint16_t GetNumberOfLocalVRegs() const {
194 return number_of_vregs_ - number_of_in_vregs_;
195 }
196
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100197 const GrowableArray<HBasicBlock*>& GetReversePostOrder() const {
198 return reverse_post_order_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100199 }
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100200
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000201 HNullConstant* GetNullConstant();
202
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000203 private:
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000204 HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const;
205 void VisitBlockForDominatorTree(HBasicBlock* block,
206 HBasicBlock* predecessor,
207 GrowableArray<size_t>* visits);
Nicolas Geoffray804d0932014-05-02 08:46:00 +0100208 void FindBackEdges(ArenaBitVector* visited);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000209 void VisitBlockForBackEdges(HBasicBlock* block,
210 ArenaBitVector* visited,
Nicolas Geoffray804d0932014-05-02 08:46:00 +0100211 ArenaBitVector* visiting);
Roland Levillainfc600dc2014-12-02 17:16:31 +0000212 void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000213 void RemoveDeadBlocks(const ArenaBitVector& visited) const;
Jean Christophe Beyler53d9da82014-12-04 13:28:25 -0800214 void RemoveBlock(HBasicBlock* block) const;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000215
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000216 ArenaAllocator* const arena_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000217
218 // List of blocks in insertion order.
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000219 GrowableArray<HBasicBlock*> blocks_;
220
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100221 // List of blocks to perform a reverse post order tree traversal.
222 GrowableArray<HBasicBlock*> reverse_post_order_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000223
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000224 HBasicBlock* entry_block_;
225 HBasicBlock* exit_block_;
226
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100227 // The maximum number of virtual registers arguments passed to a HInvoke in this graph.
Nicolas Geoffray4a34a422014-04-03 10:38:37 +0100228 uint16_t maximum_number_of_out_vregs_;
229
Nicolas Geoffrayf583e592014-04-07 13:20:42 +0100230 // The number of virtual registers in this method. Contains the parameters.
231 uint16_t number_of_vregs_;
232
233 // The number of virtual registers used by parameters of this method.
234 uint16_t number_of_in_vregs_;
235
Calin Juravlef97f9fb2014-11-11 15:38:19 +0000236 // Number of vreg size slots that the temporaries use (used in baseline compiler).
237 size_t temporaries_vreg_slots_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +0100238
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000239 // The current id to assign to a newly added instruction. See HInstruction.id_.
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000240 int32_t current_instruction_id_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000241
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000242 // Cached null constant that might be created when building SSA form.
243 HNullConstant* cached_null_constant_;
244
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000245 ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1);
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000246 DISALLOW_COPY_AND_ASSIGN(HGraph);
247};
248
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700249class HLoopInformation : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000250 public:
251 HLoopInformation(HBasicBlock* header, HGraph* graph)
252 : header_(header),
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100253 suspend_check_(nullptr),
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100254 back_edges_(graph->GetArena(), kDefaultNumberOfBackEdges),
Nicolas Geoffrayb09aacb2014-09-17 18:21:53 +0100255 // Make bit vector growable, as the number of blocks may change.
256 blocks_(graph->GetArena(), graph->GetBlocks().Size(), true) {}
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100257
258 HBasicBlock* GetHeader() const {
259 return header_;
260 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000261
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000262 void SetHeader(HBasicBlock* block) {
263 header_ = block;
264 }
265
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100266 HSuspendCheck* GetSuspendCheck() const { return suspend_check_; }
267 void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; }
268 bool HasSuspendCheck() const { return suspend_check_ != nullptr; }
269
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000270 void AddBackEdge(HBasicBlock* back_edge) {
271 back_edges_.Add(back_edge);
272 }
273
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100274 void RemoveBackEdge(HBasicBlock* back_edge) {
275 back_edges_.Delete(back_edge);
276 }
277
278 bool IsBackEdge(HBasicBlock* block) {
279 for (size_t i = 0, e = back_edges_.Size(); i < e; ++i) {
280 if (back_edges_.Get(i) == block) return true;
281 }
282 return false;
283 }
284
Nicolas Geoffraya8eed3a2014-11-24 17:47:10 +0000285 size_t NumberOfBackEdges() const {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000286 return back_edges_.Size();
287 }
288
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100289 HBasicBlock* GetPreHeader() const;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100290
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100291 const GrowableArray<HBasicBlock*>& GetBackEdges() const {
292 return back_edges_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100293 }
294
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100295 void ClearBackEdges() {
296 back_edges_.Reset();
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100297 }
298
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100299 // Find blocks that are part of this loop. Returns whether the loop is a natural loop,
300 // that is the header dominates the back edge.
301 bool Populate();
302
303 // Returns whether this loop information contains `block`.
304 // Note that this loop information *must* be populated before entering this function.
305 bool Contains(const HBasicBlock& block) const;
306
307 // Returns whether this loop information is an inner loop of `other`.
308 // Note that `other` *must* be populated before entering this function.
309 bool IsIn(const HLoopInformation& other) const;
310
311 const ArenaBitVector& GetBlocks() const { return blocks_; }
312
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000313 void Add(HBasicBlock* block);
314
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000315 private:
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100316 // Internal recursive implementation of `Populate`.
317 void PopulateRecursive(HBasicBlock* block);
318
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000319 HBasicBlock* header_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100320 HSuspendCheck* suspend_check_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000321 GrowableArray<HBasicBlock*> back_edges_;
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100322 ArenaBitVector blocks_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000323
324 DISALLOW_COPY_AND_ASSIGN(HLoopInformation);
325};
326
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100327static constexpr size_t kNoLifetime = -1;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100328static constexpr uint32_t kNoDexPc = -1;
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100329
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000330// A block in a method. Contains the list of instructions represented
331// as a double linked list. Each block knows its predecessors and
332// successors.
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100333
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700334class HBasicBlock : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000335 public:
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100336 explicit HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc)
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000337 : graph_(graph),
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000338 predecessors_(graph->GetArena(), kDefaultNumberOfPredecessors),
339 successors_(graph->GetArena(), kDefaultNumberOfSuccessors),
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000340 loop_information_(nullptr),
341 dominator_(nullptr),
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100342 dominated_blocks_(graph->GetArena(), kDefaultNumberOfDominatedBlocks),
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100343 block_id_(-1),
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100344 dex_pc_(dex_pc),
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100345 lifetime_start_(kNoLifetime),
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000346 lifetime_end_(kNoLifetime),
347 is_catch_block_(false) {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000348
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100349 const GrowableArray<HBasicBlock*>& GetPredecessors() const {
350 return predecessors_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000351 }
352
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100353 const GrowableArray<HBasicBlock*>& GetSuccessors() const {
354 return successors_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000355 }
356
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100357 const GrowableArray<HBasicBlock*>& GetDominatedBlocks() const {
358 return dominated_blocks_;
359 }
360
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100361 bool IsEntryBlock() const {
362 return graph_->GetEntryBlock() == this;
363 }
364
365 bool IsExitBlock() const {
366 return graph_->GetExitBlock() == this;
367 }
368
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000369 void AddBackEdge(HBasicBlock* back_edge) {
370 if (loop_information_ == nullptr) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000371 loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000372 }
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100373 DCHECK_EQ(loop_information_->GetHeader(), this);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000374 loop_information_->AddBackEdge(back_edge);
375 }
376
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000377 HGraph* GetGraph() const { return graph_; }
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000378 void SetGraph(HGraph* graph) { graph_ = graph; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000379
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000380 int GetBlockId() const { return block_id_; }
381 void SetBlockId(int id) { block_id_ = id; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000382
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000383 HBasicBlock* GetDominator() const { return dominator_; }
384 void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; }
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100385 void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.Add(block); }
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000386 void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) {
387 for (size_t i = 0, e = dominated_blocks_.Size(); i < e; ++i) {
388 if (dominated_blocks_.Get(i) == existing) {
389 dominated_blocks_.Put(i, new_block);
390 return;
391 }
392 }
393 LOG(FATAL) << "Unreachable";
394 UNREACHABLE();
395 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000396
397 int NumberOfBackEdges() const {
398 return loop_information_ == nullptr
399 ? 0
400 : loop_information_->NumberOfBackEdges();
401 }
402
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100403 HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; }
404 HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; }
Nicolas Geoffrayf635e632014-05-14 09:43:38 +0100405 const HInstructionList& GetInstructions() const { return instructions_; }
406 const HInstructionList& GetPhis() const { return phis_; }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +0100407 HInstruction* GetFirstPhi() const { return phis_.first_instruction_; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000408
409 void AddSuccessor(HBasicBlock* block) {
410 successors_.Add(block);
411 block->predecessors_.Add(this);
412 }
413
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +0100414 void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) {
415 size_t successor_index = GetSuccessorIndexOf(existing);
416 DCHECK_NE(successor_index, static_cast<size_t>(-1));
417 existing->RemovePredecessor(this);
418 new_block->predecessors_.Add(this);
419 successors_.Put(successor_index, new_block);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000420 }
421
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000422 void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) {
423 size_t predecessor_index = GetPredecessorIndexOf(existing);
424 DCHECK_NE(predecessor_index, static_cast<size_t>(-1));
425 existing->RemoveSuccessor(this);
426 new_block->successors_.Add(this);
427 predecessors_.Put(predecessor_index, new_block);
428 }
429
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +0100430 void RemovePredecessor(HBasicBlock* block) {
431 predecessors_.Delete(block);
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100432 }
433
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000434 void RemoveSuccessor(HBasicBlock* block) {
435 successors_.Delete(block);
436 }
437
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100438 void ClearAllPredecessors() {
439 predecessors_.Reset();
440 }
441
442 void AddPredecessor(HBasicBlock* block) {
443 predecessors_.Add(block);
444 block->successors_.Add(this);
445 }
446
Nicolas Geoffray604c6e42014-09-17 12:08:44 +0100447 void SwapPredecessors() {
Nicolas Geoffrayc83d4412014-09-18 16:46:20 +0100448 DCHECK_EQ(predecessors_.Size(), 2u);
Nicolas Geoffray604c6e42014-09-17 12:08:44 +0100449 HBasicBlock* temp = predecessors_.Get(0);
450 predecessors_.Put(0, predecessors_.Get(1));
451 predecessors_.Put(1, temp);
452 }
453
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100454 size_t GetPredecessorIndexOf(HBasicBlock* predecessor) {
455 for (size_t i = 0, e = predecessors_.Size(); i < e; ++i) {
456 if (predecessors_.Get(i) == predecessor) {
457 return i;
458 }
459 }
460 return -1;
461 }
462
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +0100463 size_t GetSuccessorIndexOf(HBasicBlock* successor) {
464 for (size_t i = 0, e = successors_.Size(); i < e; ++i) {
465 if (successors_.Get(i) == successor) {
466 return i;
467 }
468 }
469 return -1;
470 }
471
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000472 // Split the block into two blocks just after `cursor`. Returns the newly
473 // created block. Note that this method just updates raw block information,
474 // like predecessors, successors, dominators, and instruction list. It does not
475 // update the graph, reverse post order, loop information, nor make sure the
476 // blocks are consistent (for example ending with a control flow instruction).
477 HBasicBlock* SplitAfter(HInstruction* cursor);
478
479 // Merge `other` at the end of `this`. Successors and dominated blocks of
480 // `other` are changed to be successors and dominated blocks of `this`. Note
481 // that this method does not update the graph, reverse post order, loop
482 // information, nor make sure the blocks are consistent (for example ending
483 // with a control flow instruction).
484 void MergeWith(HBasicBlock* other);
485
486 // Replace `this` with `other`. Predecessors, successors, and dominated blocks
487 // of `this` are moved to `other`.
488 // Note that this method does not update the graph, reverse post order, loop
489 // information, nor make sure the blocks are consistent (for example ending
490 void ReplaceWith(HBasicBlock* other);
491
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000492 void AddInstruction(HInstruction* instruction);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100493 void RemoveInstruction(HInstruction* instruction);
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +0100494 void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor);
Roland Levillainccc07a92014-09-16 14:48:16 +0100495 // Replace instruction `initial` with `replacement` within this block.
496 void ReplaceAndRemoveInstructionWith(HInstruction* initial,
497 HInstruction* replacement);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100498 void AddPhi(HPhi* phi);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +0100499 void InsertPhiAfter(HPhi* instruction, HPhi* cursor);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100500 void RemovePhi(HPhi* phi);
501
502 bool IsLoopHeader() const {
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100503 return (loop_information_ != nullptr) && (loop_information_->GetHeader() == this);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100504 }
505
Roland Levillain6b879dd2014-09-22 17:13:44 +0100506 bool IsLoopPreHeaderFirstPredecessor() const {
507 DCHECK(IsLoopHeader());
508 DCHECK(!GetPredecessors().IsEmpty());
509 return GetPredecessors().Get(0) == GetLoopInformation()->GetPreHeader();
510 }
511
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100512 HLoopInformation* GetLoopInformation() const {
513 return loop_information_;
514 }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000515
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000516 // Set the loop_information_ on this block. Overrides the current
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100517 // loop_information if it is an outer loop of the passed loop information.
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000518 // Note that this method is called while creating the loop information.
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100519 void SetInLoop(HLoopInformation* info) {
520 if (IsLoopHeader()) {
521 // Nothing to do. This just means `info` is an outer loop.
522 } else if (loop_information_ == nullptr) {
523 loop_information_ = info;
524 } else if (loop_information_->Contains(*info->GetHeader())) {
525 // Block is currently part of an outer loop. Make it part of this inner loop.
526 // Note that a non loop header having a loop information means this loop information
527 // has already been populated
528 loop_information_ = info;
529 } else {
530 // Block is part of an inner loop. Do not update the loop information.
531 // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()`
532 // at this point, because this method is being called while populating `info`.
533 }
534 }
535
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000536 // Raw update of the loop information.
537 void SetLoopInformation(HLoopInformation* info) {
538 loop_information_ = info;
539 }
540
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +0100541 bool IsInLoop() const { return loop_information_ != nullptr; }
542
Nicolas Geoffray622d9c32014-05-12 16:11:02 +0100543 // Returns wheter this block dominates the blocked passed as parameter.
544 bool Dominates(HBasicBlock* block) const;
545
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100546 size_t GetLifetimeStart() const { return lifetime_start_; }
547 size_t GetLifetimeEnd() const { return lifetime_end_; }
548
549 void SetLifetimeStart(size_t start) { lifetime_start_ = start; }
550 void SetLifetimeEnd(size_t end) { lifetime_end_ = end; }
551
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100552 uint32_t GetDexPc() const { return dex_pc_; }
553
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000554 bool IsCatchBlock() const { return is_catch_block_; }
555 void SetIsCatchBlock() { is_catch_block_ = true; }
556
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000557 private:
Nicolas Geoffray276d9da2015-02-02 18:24:11 +0000558 HGraph* graph_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000559 GrowableArray<HBasicBlock*> predecessors_;
560 GrowableArray<HBasicBlock*> successors_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100561 HInstructionList instructions_;
562 HInstructionList phis_;
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +0000563 HLoopInformation* loop_information_;
564 HBasicBlock* dominator_;
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100565 GrowableArray<HBasicBlock*> dominated_blocks_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000566 int block_id_;
Nicolas Geoffray3c049742014-09-24 18:10:46 +0100567 // The dex program counter of the first instruction of this block.
568 const uint32_t dex_pc_;
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100569 size_t lifetime_start_;
570 size_t lifetime_end_;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000571 bool is_catch_block_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000572
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000573 friend class HGraph;
574 friend class HInstruction;
575
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000576 DISALLOW_COPY_AND_ASSIGN(HBasicBlock);
577};
578
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100579#define FOR_EACH_CONCRETE_INSTRUCTION(M) \
580 M(Add, BinaryOperation) \
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000581 M(And, BinaryOperation) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000582 M(ArrayGet, Instruction) \
583 M(ArrayLength, Instruction) \
584 M(ArraySet, Instruction) \
585 M(BoundsCheck, Instruction) \
Calin Juravleb1498f62015-02-16 13:13:29 +0000586 M(BoundType, Instruction) \
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000587 M(CheckCast, Instruction) \
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100588 M(ClinitCheck, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000589 M(Compare, BinaryOperation) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100590 M(Condition, BinaryOperation) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000591 M(Div, BinaryOperation) \
Calin Juravled0d48522014-11-04 16:40:20 +0000592 M(DivZeroCheck, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000593 M(DoubleConstant, Constant) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100594 M(Equal, Condition) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000595 M(Exit, Instruction) \
596 M(FloatConstant, Constant) \
597 M(Goto, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100598 M(GreaterThan, Condition) \
599 M(GreaterThanOrEqual, Condition) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100600 M(If, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000601 M(InstanceFieldGet, Instruction) \
602 M(InstanceFieldSet, Instruction) \
Nicolas Geoffray57a88d42014-11-10 15:09:21 +0000603 M(InstanceOf, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100604 M(IntConstant, Constant) \
Nicolas Geoffray52839d12014-11-07 17:47:25 +0000605 M(InvokeInterface, Invoke) \
Nicolas Geoffraye53798a2014-12-01 10:31:54 +0000606 M(InvokeStaticOrDirect, Invoke) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100607 M(InvokeVirtual, Invoke) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000608 M(LessThan, Condition) \
609 M(LessThanOrEqual, Condition) \
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000610 M(LoadClass, Instruction) \
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000611 M(LoadException, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100612 M(LoadLocal, Instruction) \
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +0000613 M(LoadString, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100614 M(Local, Instruction) \
615 M(LongConstant, Constant) \
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +0000616 M(MonitorOperation, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000617 M(Mul, BinaryOperation) \
618 M(Neg, UnaryOperation) \
619 M(NewArray, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100620 M(NewInstance, Instruction) \
Roland Levillain1cc5f2512014-10-22 18:06:21 +0100621 M(Not, UnaryOperation) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000622 M(NotEqual, Condition) \
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +0000623 M(NullConstant, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000624 M(NullCheck, Instruction) \
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000625 M(Or, BinaryOperation) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100626 M(ParallelMove, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000627 M(ParameterValue, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100628 M(Phi, Instruction) \
Calin Juravle9aec02f2014-11-18 23:06:35 +0000629 M(Rem, BinaryOperation) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100630 M(Return, Instruction) \
631 M(ReturnVoid, Instruction) \
Calin Juravle9aec02f2014-11-18 23:06:35 +0000632 M(Shl, BinaryOperation) \
633 M(Shr, BinaryOperation) \
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +0100634 M(StaticFieldGet, Instruction) \
635 M(StaticFieldSet, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100636 M(StoreLocal, Instruction) \
637 M(Sub, BinaryOperation) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100638 M(SuspendCheck, Instruction) \
Calin Juravle7c4954d2014-10-28 16:57:40 +0000639 M(Temporary, Instruction) \
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +0000640 M(Throw, Instruction) \
Roland Levillaindff1f282014-11-05 14:15:05 +0000641 M(TypeConversion, Instruction) \
Calin Juravle9aec02f2014-11-18 23:06:35 +0000642 M(UShr, BinaryOperation) \
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +0000643 M(Xor, BinaryOperation) \
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000644
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100645#define FOR_EACH_INSTRUCTION(M) \
646 FOR_EACH_CONCRETE_INSTRUCTION(M) \
647 M(Constant, Instruction) \
Roland Levillain88cb1752014-10-20 16:36:47 +0100648 M(UnaryOperation, Instruction) \
Calin Juravle34bacdf2014-10-07 20:23:36 +0100649 M(BinaryOperation, Instruction) \
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100650 M(Invoke, Instruction)
Dave Allison20dfc792014-06-16 20:44:29 -0700651
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100652#define FORWARD_DECLARATION(type, super) class H##type;
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000653FOR_EACH_INSTRUCTION(FORWARD_DECLARATION)
654#undef FORWARD_DECLARATION
655
Roland Levillainccc07a92014-09-16 14:48:16 +0100656#define DECLARE_INSTRUCTION(type) \
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100657 virtual InstructionKind GetKind() const { return k##type; } \
Roland Levillainccc07a92014-09-16 14:48:16 +0100658 virtual const char* DebugName() const { return #type; } \
659 virtual const H##type* As##type() const OVERRIDE { return this; } \
660 virtual H##type* As##type() OVERRIDE { return this; } \
661 virtual bool InstructionTypeEquals(HInstruction* other) const { \
662 return other->Is##type(); \
663 } \
664 virtual void Accept(HGraphVisitor* visitor)
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000665
David Brazdiled596192015-01-23 10:39:45 +0000666template <typename T> class HUseList;
667
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100668template <typename T>
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700669class HUseListNode : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000670 public:
David Brazdiled596192015-01-23 10:39:45 +0000671 HUseListNode* GetPrevious() const { return prev_; }
672 HUseListNode* GetNext() const { return next_; }
673 T GetUser() const { return user_; }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100674 size_t GetIndex() const { return index_; }
675
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000676 private:
David Brazdiled596192015-01-23 10:39:45 +0000677 HUseListNode(T user, size_t index)
678 : user_(user), index_(index), prev_(nullptr), next_(nullptr) {}
679
680 T const user_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100681 const size_t index_;
David Brazdiled596192015-01-23 10:39:45 +0000682 HUseListNode<T>* prev_;
683 HUseListNode<T>* next_;
684
685 friend class HUseList<T>;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +0000686
687 DISALLOW_COPY_AND_ASSIGN(HUseListNode);
688};
689
David Brazdiled596192015-01-23 10:39:45 +0000690template <typename T>
691class HUseList : public ValueObject {
692 public:
693 HUseList() : first_(nullptr) {}
694
695 void Clear() {
696 first_ = nullptr;
697 }
698
699 // Adds a new entry at the beginning of the use list and returns
700 // the newly created node.
701 HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) {
David Brazdilea55b932015-01-27 17:12:29 +0000702 HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index);
David Brazdiled596192015-01-23 10:39:45 +0000703 if (IsEmpty()) {
704 first_ = new_node;
705 } else {
706 first_->prev_ = new_node;
707 new_node->next_ = first_;
708 first_ = new_node;
709 }
710 return new_node;
711 }
712
713 HUseListNode<T>* GetFirst() const {
714 return first_;
715 }
716
717 void Remove(HUseListNode<T>* node) {
718 if (node->prev_ != nullptr) {
719 node->prev_->next_ = node->next_;
720 }
721 if (node->next_ != nullptr) {
722 node->next_->prev_ = node->prev_;
723 }
724 if (node == first_) {
725 first_ = node->next_;
726 }
727 }
728
729 bool IsEmpty() const {
730 return first_ == nullptr;
731 }
732
733 bool HasOnlyOneUse() const {
734 return first_ != nullptr && first_->next_ == nullptr;
735 }
736
737 private:
738 HUseListNode<T>* first_;
739};
740
741template<typename T>
742class HUseIterator : public ValueObject {
743 public:
744 explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {}
745
746 bool Done() const { return current_ == nullptr; }
747
748 void Advance() {
749 DCHECK(!Done());
750 current_ = current_->GetNext();
751 }
752
753 HUseListNode<T>* Current() const {
754 DCHECK(!Done());
755 return current_;
756 }
757
758 private:
759 HUseListNode<T>* current_;
760
761 friend class HValue;
762};
763
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100764// Represents the side effects an instruction may have.
765class SideEffects : public ValueObject {
766 public:
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100767 SideEffects() : flags_(0) {}
768
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100769 static SideEffects None() {
770 return SideEffects(0);
771 }
772
773 static SideEffects All() {
774 return SideEffects(ChangesSomething().flags_ | DependsOnSomething().flags_);
775 }
776
777 static SideEffects ChangesSomething() {
778 return SideEffects((1 << kFlagChangesCount) - 1);
779 }
780
781 static SideEffects DependsOnSomething() {
782 int count = kFlagDependsOnCount - kFlagChangesCount;
783 return SideEffects(((1 << count) - 1) << kFlagChangesCount);
784 }
785
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100786 SideEffects Union(SideEffects other) const {
787 return SideEffects(flags_ | other.flags_);
788 }
789
Roland Levillain72bceff2014-09-15 18:29:00 +0100790 bool HasSideEffects() const {
791 size_t all_bits_set = (1 << kFlagChangesCount) - 1;
792 return (flags_ & all_bits_set) != 0;
793 }
794
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100795 bool HasAllSideEffects() const {
796 size_t all_bits_set = (1 << kFlagChangesCount) - 1;
797 return all_bits_set == (flags_ & all_bits_set);
798 }
799
800 bool DependsOn(SideEffects other) const {
801 size_t depends_flags = other.ComputeDependsFlags();
802 return (flags_ & depends_flags) != 0;
803 }
804
805 bool HasDependencies() const {
806 int count = kFlagDependsOnCount - kFlagChangesCount;
807 size_t all_bits_set = (1 << count) - 1;
808 return ((flags_ >> kFlagChangesCount) & all_bits_set) != 0;
809 }
810
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100811 private:
812 static constexpr int kFlagChangesSomething = 0;
813 static constexpr int kFlagChangesCount = kFlagChangesSomething + 1;
814
815 static constexpr int kFlagDependsOnSomething = kFlagChangesCount;
816 static constexpr int kFlagDependsOnCount = kFlagDependsOnSomething + 1;
817
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100818 explicit SideEffects(size_t flags) : flags_(flags) {}
819
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100820 size_t ComputeDependsFlags() const {
821 return flags_ << kFlagChangesCount;
822 }
823
824 size_t flags_;
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100825};
826
David Brazdiled596192015-01-23 10:39:45 +0000827// A HEnvironment object contains the values of virtual registers at a given location.
828class HEnvironment : public ArenaObject<kArenaAllocMisc> {
829 public:
830 HEnvironment(ArenaAllocator* arena, size_t number_of_vregs)
831 : vregs_(arena, number_of_vregs) {
832 vregs_.SetSize(number_of_vregs);
833 for (size_t i = 0; i < number_of_vregs; i++) {
834 vregs_.Put(i, VRegInfo(nullptr, nullptr));
835 }
836 }
837
838 void CopyFrom(HEnvironment* env);
839
840 void SetRawEnvAt(size_t index, HInstruction* instruction) {
841 vregs_.Put(index, VRegInfo(instruction, nullptr));
842 }
843
844 // Record instructions' use entries of this environment for constant-time removal.
845 void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) {
846 DCHECK(env_use->GetUser() == this);
847 size_t index = env_use->GetIndex();
848 VRegInfo info = vregs_.Get(index);
849 DCHECK(info.vreg_ != nullptr);
850 DCHECK(info.node_ == nullptr);
851 vregs_.Put(index, VRegInfo(info.vreg_, env_use));
852 }
853
854 HInstruction* GetInstructionAt(size_t index) const {
855 return vregs_.Get(index).vreg_;
856 }
857
858 HUseListNode<HEnvironment*>* GetInstructionEnvUseAt(size_t index) const {
859 return vregs_.Get(index).node_;
860 }
861
862 size_t Size() const { return vregs_.Size(); }
863
864 private:
865 struct VRegInfo {
866 HInstruction* vreg_;
867 HUseListNode<HEnvironment*>* node_;
868
869 VRegInfo(HInstruction* instruction, HUseListNode<HEnvironment*>* env_use)
870 : vreg_(instruction), node_(env_use) {}
871 };
872
873 GrowableArray<VRegInfo> vregs_;
874
875 DISALLOW_COPY_AND_ASSIGN(HEnvironment);
876};
877
Calin Juravleacf735c2015-02-12 15:25:22 +0000878class ReferenceTypeInfo : ValueObject {
879 public:
Calin Juravleb1498f62015-02-16 13:13:29 +0000880 typedef Handle<mirror::Class> TypeHandle;
881
882 static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact)
883 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
884 if (type_handle->IsObjectClass()) {
885 // Override the type handle to be consistent with the case when we get to
886 // Top but don't have the Object class available. It avoids having to guess
887 // what value the type_handle has when it's Top.
888 return ReferenceTypeInfo(TypeHandle(), is_exact, true);
889 } else {
890 return ReferenceTypeInfo(type_handle, is_exact, false);
891 }
892 }
893
894 static ReferenceTypeInfo CreateTop(bool is_exact) {
895 return ReferenceTypeInfo(TypeHandle(), is_exact, true);
Calin Juravleacf735c2015-02-12 15:25:22 +0000896 }
897
898 bool IsExact() const { return is_exact_; }
899 bool IsTop() const { return is_top_; }
900
901 Handle<mirror::Class> GetTypeHandle() const { return type_handle_; }
902
Calin Juravleb1498f62015-02-16 13:13:29 +0000903 bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Calin Juravleacf735c2015-02-12 15:25:22 +0000904 if (IsTop()) {
905 // Top (equivalent for java.lang.Object) is supertype of anything.
906 return true;
907 }
908 if (rti.IsTop()) {
909 // If we get here `this` is not Top() so it can't be a supertype.
910 return false;
911 }
912 return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get());
913 }
914
915 // Returns true if the type information provide the same amount of details.
916 // Note that it does not mean that the instructions have the same actual type
917 // (e.g. tops are equal but they can be the result of a merge).
918 bool IsEqual(ReferenceTypeInfo rti) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
919 if (IsExact() != rti.IsExact()) {
920 return false;
921 }
922 if (IsTop() && rti.IsTop()) {
923 // `Top` means java.lang.Object, so the types are equivalent.
924 return true;
925 }
926 if (IsTop() || rti.IsTop()) {
927 // If only one is top or object than they are not equivalent.
928 // NB: We need this extra check because the type_handle of `Top` is invalid
929 // and we cannot inspect its reference.
930 return false;
931 }
932
933 // Finally check the types.
934 return GetTypeHandle().Get() == rti.GetTypeHandle().Get();
935 }
936
937 private:
Calin Juravleb1498f62015-02-16 13:13:29 +0000938 ReferenceTypeInfo() : ReferenceTypeInfo(TypeHandle(), false, true) {}
939 ReferenceTypeInfo(TypeHandle type_handle, bool is_exact, bool is_top)
940 : type_handle_(type_handle), is_exact_(is_exact), is_top_(is_top) {}
941
Calin Juravleacf735c2015-02-12 15:25:22 +0000942 // The class of the object.
Calin Juravleb1498f62015-02-16 13:13:29 +0000943 TypeHandle type_handle_;
Calin Juravleacf735c2015-02-12 15:25:22 +0000944 // Whether or not the type is exact or a superclass of the actual type.
Calin Juravleb1498f62015-02-16 13:13:29 +0000945 // Whether or not we have any information about this type.
Calin Juravleacf735c2015-02-12 15:25:22 +0000946 bool is_exact_;
947 // A true value here means that the object type should be java.lang.Object.
948 // We don't have access to the corresponding mirror object every time so this
949 // flag acts as a substitute. When true, the TypeHandle refers to a null
950 // pointer and should not be used.
951 bool is_top_;
952};
953
954std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs);
955
Ian Rogers6a3c1fc2014-10-31 00:33:20 -0700956class HInstruction : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000957 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100958 explicit HInstruction(SideEffects side_effects)
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000959 : previous_(nullptr),
960 next_(nullptr),
961 block_(nullptr),
962 id_(-1),
Nicolas Geoffray804d0932014-05-02 08:46:00 +0100963 ssa_index_(-1),
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100964 environment_(nullptr),
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +0100965 locations_(nullptr),
966 live_interval_(nullptr),
Nicolas Geoffray065bf772014-09-03 14:51:22 +0100967 lifetime_position_(kNoLifetime),
Calin Juravleb1498f62015-02-16 13:13:29 +0000968 side_effects_(side_effects),
969 reference_type_info_(ReferenceTypeInfo::CreateTop(/* is_exact */ false)) {}
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +0000970
Dave Allison20dfc792014-06-16 20:44:29 -0700971 virtual ~HInstruction() {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000972
Nicolas Geoffray360231a2014-10-08 21:07:48 +0100973#define DECLARE_KIND(type, super) k##type,
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +0100974 enum InstructionKind {
975 FOR_EACH_INSTRUCTION(DECLARE_KIND)
976 };
977#undef DECLARE_KIND
978
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000979 HInstruction* GetNext() const { return next_; }
980 HInstruction* GetPrevious() const { return previous_; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000981
Calin Juravle77520bc2015-01-12 18:45:46 +0000982 HInstruction* GetNextDisregardingMoves() const;
983 HInstruction* GetPreviousDisregardingMoves() const;
984
Nicolas Geoffray787c3072014-03-17 10:20:19 +0000985 HBasicBlock* GetBlock() const { return block_; }
986 void SetBlock(HBasicBlock* block) { block_ = block; }
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +0100987 bool IsInBlock() const { return block_ != nullptr; }
988 bool IsInLoop() const { return block_->IsInLoop(); }
Nicolas Geoffray3ac17fc2014-08-06 23:02:54 +0100989 bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +0000990
Roland Levillain6b879dd2014-09-22 17:13:44 +0100991 virtual size_t InputCount() const = 0;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100992 virtual HInstruction* InputAt(size_t i) const = 0;
Nicolas Geoffray818f2102014-02-18 16:43:35 +0000993
994 virtual void Accept(HGraphVisitor* visitor) = 0;
995 virtual const char* DebugName() const = 0;
996
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100997 virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +0100998 virtual void SetRawInputAt(size_t index, HInstruction* input) = 0;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +0100999
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001000 virtual bool NeedsEnvironment() const { return false; }
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +01001001 virtual bool IsControlFlow() const { return false; }
Roland Levillaine161a2a2014-10-03 12:45:18 +01001002 virtual bool CanThrow() const { return false; }
Roland Levillain72bceff2014-09-15 18:29:00 +01001003 bool HasSideEffects() const { return side_effects_.HasSideEffects(); }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001004
Calin Juravle61d544b2015-02-23 16:46:57 +00001005 virtual bool ActAsNullConstant() const { return false; }
1006
Calin Juravle10e244f2015-01-26 18:54:32 +00001007 // Does not apply for all instructions, but having this at top level greatly
1008 // simplifies the null check elimination.
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001009 virtual bool CanBeNull() const {
1010 DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types";
1011 return true;
1012 }
Calin Juravle10e244f2015-01-26 18:54:32 +00001013
Calin Juravle77520bc2015-01-12 18:45:46 +00001014 virtual bool CanDoImplicitNullCheck() const { return false; }
1015
Calin Juravleacf735c2015-02-12 15:25:22 +00001016 void SetReferenceTypeInfo(ReferenceTypeInfo reference_type_info) {
Calin Juravle61d544b2015-02-23 16:46:57 +00001017 DCHECK_EQ(GetType(), Primitive::kPrimNot);
Calin Juravleacf735c2015-02-12 15:25:22 +00001018 reference_type_info_ = reference_type_info;
1019 }
1020
Calin Juravle61d544b2015-02-23 16:46:57 +00001021 ReferenceTypeInfo GetReferenceTypeInfo() const {
1022 DCHECK_EQ(GetType(), Primitive::kPrimNot);
1023 return reference_type_info_;
1024 }
Calin Juravleacf735c2015-02-12 15:25:22 +00001025
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001026 void AddUseAt(HInstruction* user, size_t index) {
David Brazdiled596192015-01-23 10:39:45 +00001027 uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena());
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001028 }
1029
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001030 void AddEnvUseAt(HEnvironment* user, size_t index) {
Nicolas Geoffray724c9632014-09-22 12:27:27 +01001031 DCHECK(user != nullptr);
David Brazdiled596192015-01-23 10:39:45 +00001032 HUseListNode<HEnvironment*>* env_use =
1033 env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena());
1034 user->RecordEnvUse(env_use);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001035 }
1036
1037 void RemoveUser(HInstruction* user, size_t index);
David Brazdiled596192015-01-23 10:39:45 +00001038 void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001039
David Brazdilea55b932015-01-27 17:12:29 +00001040 const HUseList<HInstruction*>& GetUses() { return uses_; }
1041 const HUseList<HEnvironment*>& GetEnvUses() { return env_uses_; }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001042
David Brazdiled596192015-01-23 10:39:45 +00001043 bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); }
1044 bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001045
Roland Levillain6c82d402014-10-13 16:10:27 +01001046 // Does this instruction strictly dominate `other_instruction`?
1047 // Returns false if this instruction and `other_instruction` are the same.
1048 // Aborts if this instruction and `other_instruction` are both phis.
1049 bool StrictlyDominates(HInstruction* other_instruction) const;
Roland Levillainccc07a92014-09-16 14:48:16 +01001050
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001051 int GetId() const { return id_; }
1052 void SetId(int id) { id_ = id; }
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001053
Nicolas Geoffray804d0932014-05-02 08:46:00 +01001054 int GetSsaIndex() const { return ssa_index_; }
1055 void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; }
1056 bool HasSsaIndex() const { return ssa_index_ != -1; }
1057
1058 bool HasEnvironment() const { return environment_ != nullptr; }
1059 HEnvironment* GetEnvironment() const { return environment_; }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001060 void SetEnvironment(HEnvironment* environment) { environment_ = environment; }
1061
Nicolas Geoffray39468442014-09-02 15:17:15 +01001062 // Returns the number of entries in the environment. Typically, that is the
1063 // number of dex registers in a method. It could be more in case of inlining.
1064 size_t EnvironmentSize() const;
1065
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001066 LocationSummary* GetLocations() const { return locations_; }
1067 void SetLocations(LocationSummary* locations) { locations_ = locations; }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001068
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001069 void ReplaceWith(HInstruction* instruction);
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001070 void ReplaceInput(HInstruction* replacement, size_t index);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001071
Nicolas Geoffray82091da2015-01-26 10:02:45 +00001072 // Move `this` instruction before `cursor`.
1073 void MoveBefore(HInstruction* cursor);
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001074
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001075#define INSTRUCTION_TYPE_CHECK(type, super) \
Roland Levillainccc07a92014-09-16 14:48:16 +01001076 bool Is##type() const { return (As##type() != nullptr); } \
1077 virtual const H##type* As##type() const { return nullptr; } \
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001078 virtual H##type* As##type() { return nullptr; }
1079
1080 FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK)
1081#undef INSTRUCTION_TYPE_CHECK
1082
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001083 // Returns whether the instruction can be moved within the graph.
1084 virtual bool CanBeMoved() const { return false; }
1085
1086 // Returns whether the two instructions are of the same kind.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001087 virtual bool InstructionTypeEquals(HInstruction* other) const {
1088 UNUSED(other);
1089 return false;
1090 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001091
1092 // Returns whether any data encoded in the two instructions is equal.
1093 // This method does not look at the inputs. Both instructions must be
1094 // of the same type, otherwise the method has undefined behavior.
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001095 virtual bool InstructionDataEquals(HInstruction* other) const {
1096 UNUSED(other);
1097 return false;
1098 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001099
1100 // Returns whether two instructions are equal, that is:
Calin Juravleddb7df22014-11-25 20:56:51 +00001101 // 1) They have the same type and contain the same data (InstructionDataEquals).
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001102 // 2) Their inputs are identical.
1103 bool Equals(HInstruction* other) const;
1104
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +01001105 virtual InstructionKind GetKind() const = 0;
1106
1107 virtual size_t ComputeHashCode() const {
1108 size_t result = GetKind();
1109 for (size_t i = 0, e = InputCount(); i < e; ++i) {
1110 result = (result * 31) + InputAt(i)->GetId();
1111 }
1112 return result;
1113 }
1114
1115 SideEffects GetSideEffects() const { return side_effects_; }
1116
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01001117 size_t GetLifetimePosition() const { return lifetime_position_; }
1118 void SetLifetimePosition(size_t position) { lifetime_position_ = position; }
1119 LiveInterval* GetLiveInterval() const { return live_interval_; }
1120 void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; }
1121 bool HasLiveInterval() const { return live_interval_ != nullptr; }
1122
Nicolas Geoffrayc0572a42015-02-06 14:35:25 +00001123 bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); }
1124
1125 // Returns whether the code generation of the instruction will require to have access
1126 // to the current method. Such instructions are:
1127 // (1): Instructions that require an environment, as calling the runtime requires
1128 // to walk the stack and have the current method stored at a specific stack address.
1129 // (2): Object literals like classes and strings, that are loaded from the dex cache
1130 // fields of the current method.
1131 bool NeedsCurrentMethod() const {
1132 return NeedsEnvironment() || IsLoadClass() || IsLoadString();
1133 }
1134
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001135 private:
1136 HInstruction* previous_;
1137 HInstruction* next_;
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001138 HBasicBlock* block_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001139
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001140 // An instruction gets an id when it is added to the graph.
1141 // It reflects creation order. A negative id means the instruction
Nicolas Geoffray39468442014-09-02 15:17:15 +01001142 // has not been added to the graph.
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001143 int id_;
1144
Nicolas Geoffray804d0932014-05-02 08:46:00 +01001145 // When doing liveness analysis, instructions that have uses get an SSA index.
1146 int ssa_index_;
1147
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001148 // List of instructions that have this instruction as input.
David Brazdiled596192015-01-23 10:39:45 +00001149 HUseList<HInstruction*> uses_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001150
1151 // List of environments that contain this instruction.
David Brazdiled596192015-01-23 10:39:45 +00001152 HUseList<HEnvironment*> env_uses_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001153
Nicolas Geoffray39468442014-09-02 15:17:15 +01001154 // The environment associated with this instruction. Not null if the instruction
1155 // might jump out of the method.
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001156 HEnvironment* environment_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001157
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001158 // Set by the code generator.
1159 LocationSummary* locations_;
1160
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01001161 // Set by the liveness analysis.
1162 LiveInterval* live_interval_;
1163
1164 // Set by the liveness analysis, this is the position in a linear
1165 // order of blocks where this instruction's live interval start.
1166 size_t lifetime_position_;
1167
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001168 const SideEffects side_effects_;
1169
Calin Juravleacf735c2015-02-12 15:25:22 +00001170 // TODO: for primitive types this should be marked as invalid.
1171 ReferenceTypeInfo reference_type_info_;
1172
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001173 friend class HBasicBlock;
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001174 friend class HGraph;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001175 friend class HInstructionList;
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001176
1177 DISALLOW_COPY_AND_ASSIGN(HInstruction);
1178};
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001179std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001180
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001181class HInputIterator : public ValueObject {
1182 public:
Dave Allison20dfc792014-06-16 20:44:29 -07001183 explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {}
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001184
1185 bool Done() const { return index_ == instruction_->InputCount(); }
1186 HInstruction* Current() const { return instruction_->InputAt(index_); }
1187 void Advance() { index_++; }
1188
1189 private:
1190 HInstruction* instruction_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001191 size_t index_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001192
1193 DISALLOW_COPY_AND_ASSIGN(HInputIterator);
1194};
1195
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001196class HInstructionIterator : public ValueObject {
1197 public:
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001198 explicit HInstructionIterator(const HInstructionList& instructions)
1199 : instruction_(instructions.first_instruction_) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001200 next_ = Done() ? nullptr : instruction_->GetNext();
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001201 }
1202
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001203 bool Done() const { return instruction_ == nullptr; }
1204 HInstruction* Current() const { return instruction_; }
1205 void Advance() {
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001206 instruction_ = next_;
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001207 next_ = Done() ? nullptr : instruction_->GetNext();
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001208 }
1209
1210 private:
1211 HInstruction* instruction_;
1212 HInstruction* next_;
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01001213
1214 DISALLOW_COPY_AND_ASSIGN(HInstructionIterator);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001215};
1216
Nicolas Geoffray804d0932014-05-02 08:46:00 +01001217class HBackwardInstructionIterator : public ValueObject {
1218 public:
1219 explicit HBackwardInstructionIterator(const HInstructionList& instructions)
1220 : instruction_(instructions.last_instruction_) {
1221 next_ = Done() ? nullptr : instruction_->GetPrevious();
1222 }
1223
1224 bool Done() const { return instruction_ == nullptr; }
1225 HInstruction* Current() const { return instruction_; }
1226 void Advance() {
1227 instruction_ = next_;
1228 next_ = Done() ? nullptr : instruction_->GetPrevious();
1229 }
1230
1231 private:
1232 HInstruction* instruction_;
1233 HInstruction* next_;
Nicolas Geoffrayddb311f2014-05-16 09:28:54 +01001234
1235 DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator);
Nicolas Geoffray804d0932014-05-02 08:46:00 +01001236};
1237
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001238// An embedded container with N elements of type T. Used (with partial
1239// specialization for N=0) because embedded arrays cannot have size 0.
1240template<typename T, intptr_t N>
1241class EmbeddedArray {
1242 public:
Dave Allison20dfc792014-06-16 20:44:29 -07001243 EmbeddedArray() : elements_() {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001244
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001245 intptr_t GetLength() const { return N; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001246
1247 const T& operator[](intptr_t i) const {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001248 DCHECK_LT(i, GetLength());
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001249 return elements_[i];
1250 }
1251
1252 T& operator[](intptr_t i) {
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001253 DCHECK_LT(i, GetLength());
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001254 return elements_[i];
1255 }
1256
1257 const T& At(intptr_t i) const {
1258 return (*this)[i];
1259 }
1260
1261 void SetAt(intptr_t i, const T& val) {
1262 (*this)[i] = val;
1263 }
1264
1265 private:
1266 T elements_[N];
1267};
1268
1269template<typename T>
1270class EmbeddedArray<T, 0> {
1271 public:
1272 intptr_t length() const { return 0; }
1273 const T& operator[](intptr_t i) const {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001274 UNUSED(i);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001275 LOG(FATAL) << "Unreachable";
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001276 UNREACHABLE();
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001277 }
1278 T& operator[](intptr_t i) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001279 UNUSED(i);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001280 LOG(FATAL) << "Unreachable";
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001281 UNREACHABLE();
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001282 }
1283};
1284
1285template<intptr_t N>
1286class HTemplateInstruction: public HInstruction {
1287 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001288 HTemplateInstruction<N>(SideEffects side_effects)
1289 : HInstruction(side_effects), inputs_() {}
Dave Allison20dfc792014-06-16 20:44:29 -07001290 virtual ~HTemplateInstruction() {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001291
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001292 virtual size_t InputCount() const { return N; }
1293 virtual HInstruction* InputAt(size_t i) const { return inputs_[i]; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001294
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001295 protected:
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001296 virtual void SetRawInputAt(size_t i, HInstruction* instruction) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001297 inputs_[i] = instruction;
1298 }
1299
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001300 private:
1301 EmbeddedArray<HInstruction*, N> inputs_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001302
1303 friend class SsaBuilder;
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001304};
1305
Dave Allison20dfc792014-06-16 20:44:29 -07001306template<intptr_t N>
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001307class HExpression : public HTemplateInstruction<N> {
Dave Allison20dfc792014-06-16 20:44:29 -07001308 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001309 HExpression<N>(Primitive::Type type, SideEffects side_effects)
1310 : HTemplateInstruction<N>(side_effects), type_(type) {}
Dave Allison20dfc792014-06-16 20:44:29 -07001311 virtual ~HExpression() {}
1312
1313 virtual Primitive::Type GetType() const { return type_; }
1314
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001315 protected:
1316 Primitive::Type type_;
Dave Allison20dfc792014-06-16 20:44:29 -07001317};
1318
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001319// Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow
1320// instruction that branches to the exit block.
1321class HReturnVoid : public HTemplateInstruction<0> {
1322 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001323 HReturnVoid() : HTemplateInstruction(SideEffects::None()) {}
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +01001324
1325 virtual bool IsControlFlow() const { return true; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001326
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001327 DECLARE_INSTRUCTION(ReturnVoid);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001328
1329 private:
1330 DISALLOW_COPY_AND_ASSIGN(HReturnVoid);
1331};
1332
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001333// Represents dex's RETURN opcodes. A HReturn is a control flow
1334// instruction that branches to the exit block.
1335class HReturn : public HTemplateInstruction<1> {
1336 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001337 explicit HReturn(HInstruction* value) : HTemplateInstruction(SideEffects::None()) {
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001338 SetRawInputAt(0, value);
1339 }
1340
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +01001341 virtual bool IsControlFlow() const { return true; }
1342
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001343 DECLARE_INSTRUCTION(Return);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001344
1345 private:
1346 DISALLOW_COPY_AND_ASSIGN(HReturn);
1347};
1348
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001349// The exit instruction is the only instruction of the exit block.
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001350// Instructions aborting the method (HThrow and HReturn) must branch to the
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001351// exit block.
1352class HExit : public HTemplateInstruction<0> {
1353 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001354 HExit() : HTemplateInstruction(SideEffects::None()) {}
Nicolas Geoffrayec7e4722014-06-06 11:24:33 +01001355
1356 virtual bool IsControlFlow() const { return true; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001357
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001358 DECLARE_INSTRUCTION(Exit);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001359
1360 private:
1361 DISALLOW_COPY_AND_ASSIGN(HExit);
1362};
1363
1364// Jumps from one block to another.
1365class HGoto : public HTemplateInstruction<0> {
1366 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001367 HGoto() : HTemplateInstruction(SideEffects::None()) {}
1368
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001369 bool IsControlFlow() const OVERRIDE { return true; }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001370
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001371 HBasicBlock* GetSuccessor() const {
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01001372 return GetBlock()->GetSuccessors().Get(0);
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00001373 }
1374
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001375 DECLARE_INSTRUCTION(Goto);
Nicolas Geoffray818f2102014-02-18 16:43:35 +00001376
1377 private:
1378 DISALLOW_COPY_AND_ASSIGN(HGoto);
1379};
1380
Dave Allison20dfc792014-06-16 20:44:29 -07001381
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001382// Conditional branch. A block ending with an HIf instruction must have
1383// two successors.
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001384class HIf : public HTemplateInstruction<1> {
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001385 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001386 explicit HIf(HInstruction* input) : HTemplateInstruction(SideEffects::None()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001387 SetRawInputAt(0, input);
1388 }
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001389
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00001390 bool IsControlFlow() const OVERRIDE { return true; }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001391
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001392 HBasicBlock* IfTrueSuccessor() const {
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01001393 return GetBlock()->GetSuccessors().Get(0);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001394 }
1395
1396 HBasicBlock* IfFalseSuccessor() const {
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01001397 return GetBlock()->GetSuccessors().Get(1);
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001398 }
1399
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001400 DECLARE_INSTRUCTION(If);
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001401
Dave Allison20dfc792014-06-16 20:44:29 -07001402 virtual bool IsIfInstruction() const { return true; }
1403
Nicolas Geoffraybe9a92a2014-02-25 14:22:56 +00001404 private:
1405 DISALLOW_COPY_AND_ASSIGN(HIf);
1406};
1407
Roland Levillain88cb1752014-10-20 16:36:47 +01001408class HUnaryOperation : public HExpression<1> {
1409 public:
1410 HUnaryOperation(Primitive::Type result_type, HInstruction* input)
1411 : HExpression(result_type, SideEffects::None()) {
1412 SetRawInputAt(0, input);
1413 }
1414
1415 HInstruction* GetInput() const { return InputAt(0); }
1416 Primitive::Type GetResultType() const { return GetType(); }
1417
1418 virtual bool CanBeMoved() const { return true; }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001419 virtual bool InstructionDataEquals(HInstruction* other) const {
1420 UNUSED(other);
1421 return true;
1422 }
Roland Levillain88cb1752014-10-20 16:36:47 +01001423
Roland Levillain9240d6a2014-10-20 16:47:04 +01001424 // Try to statically evaluate `operation` and return a HConstant
1425 // containing the result of this evaluation. If `operation` cannot
1426 // be evaluated as a constant, return nullptr.
1427 HConstant* TryStaticEvaluation() const;
1428
1429 // Apply this operation to `x`.
1430 virtual int32_t Evaluate(int32_t x) const = 0;
1431 virtual int64_t Evaluate(int64_t x) const = 0;
1432
Roland Levillain88cb1752014-10-20 16:36:47 +01001433 DECLARE_INSTRUCTION(UnaryOperation);
1434
1435 private:
1436 DISALLOW_COPY_AND_ASSIGN(HUnaryOperation);
1437};
1438
Dave Allison20dfc792014-06-16 20:44:29 -07001439class HBinaryOperation : public HExpression<2> {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001440 public:
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001441 HBinaryOperation(Primitive::Type result_type,
1442 HInstruction* left,
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001443 HInstruction* right) : HExpression(result_type, SideEffects::None()) {
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001444 SetRawInputAt(0, left);
1445 SetRawInputAt(1, right);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001446 }
1447
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001448 HInstruction* GetLeft() const { return InputAt(0); }
1449 HInstruction* GetRight() const { return InputAt(1); }
Dave Allison20dfc792014-06-16 20:44:29 -07001450 Primitive::Type GetResultType() const { return GetType(); }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001451
1452 virtual bool IsCommutative() { return false; }
1453
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001454 virtual bool CanBeMoved() const { return true; }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001455 virtual bool InstructionDataEquals(HInstruction* other) const {
1456 UNUSED(other);
1457 return true;
1458 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001459
Roland Levillain9240d6a2014-10-20 16:47:04 +01001460 // Try to statically evaluate `operation` and return a HConstant
Roland Levillain556c3d12014-09-18 15:25:07 +01001461 // containing the result of this evaluation. If `operation` cannot
1462 // be evaluated as a constant, return nullptr.
Roland Levillain9240d6a2014-10-20 16:47:04 +01001463 HConstant* TryStaticEvaluation() const;
Roland Levillain556c3d12014-09-18 15:25:07 +01001464
1465 // Apply this operation to `x` and `y`.
1466 virtual int32_t Evaluate(int32_t x, int32_t y) const = 0;
1467 virtual int64_t Evaluate(int64_t x, int64_t y) const = 0;
1468
Roland Levillainccc07a92014-09-16 14:48:16 +01001469 DECLARE_INSTRUCTION(BinaryOperation);
1470
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001471 private:
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001472 DISALLOW_COPY_AND_ASSIGN(HBinaryOperation);
1473};
1474
Dave Allison20dfc792014-06-16 20:44:29 -07001475class HCondition : public HBinaryOperation {
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001476 public:
Dave Allison20dfc792014-06-16 20:44:29 -07001477 HCondition(HInstruction* first, HInstruction* second)
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001478 : HBinaryOperation(Primitive::kPrimBoolean, first, second),
1479 needs_materialization_(true) {}
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001480
1481 virtual bool IsCommutative() { return true; }
Nicolas Geoffray18efde52014-09-22 15:51:11 +01001482
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001483 bool NeedsMaterialization() const { return needs_materialization_; }
1484 void ClearNeedsMaterialization() { needs_materialization_ = false; }
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00001485
Nicolas Geoffray18efde52014-09-22 15:51:11 +01001486 // For code generation purposes, returns whether this instruction is just before
1487 // `if_`, and disregard moves in between.
1488 bool IsBeforeWhenDisregardMoves(HIf* if_) const;
1489
Dave Allison20dfc792014-06-16 20:44:29 -07001490 DECLARE_INSTRUCTION(Condition);
1491
1492 virtual IfCondition GetCondition() const = 0;
1493
1494 private:
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001495 // For register allocation purposes, returns whether this instruction needs to be
1496 // materialized (that is, not just be in the processor flags).
1497 bool needs_materialization_;
1498
Dave Allison20dfc792014-06-16 20:44:29 -07001499 DISALLOW_COPY_AND_ASSIGN(HCondition);
1500};
1501
1502// Instruction to check if two inputs are equal to each other.
1503class HEqual : public HCondition {
1504 public:
1505 HEqual(HInstruction* first, HInstruction* second)
1506 : HCondition(first, second) {}
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001507
Roland Levillain93445682014-10-06 19:24:02 +01001508 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1509 return x == y ? 1 : 0;
1510 }
1511 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1512 return x == y ? 1 : 0;
1513 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001514
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001515 DECLARE_INSTRUCTION(Equal);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001516
Dave Allison20dfc792014-06-16 20:44:29 -07001517 virtual IfCondition GetCondition() const {
1518 return kCondEQ;
1519 }
1520
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001521 private:
1522 DISALLOW_COPY_AND_ASSIGN(HEqual);
1523};
1524
Dave Allison20dfc792014-06-16 20:44:29 -07001525class HNotEqual : public HCondition {
1526 public:
1527 HNotEqual(HInstruction* first, HInstruction* second)
1528 : HCondition(first, second) {}
1529
Roland Levillain93445682014-10-06 19:24:02 +01001530 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1531 return x != y ? 1 : 0;
1532 }
1533 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1534 return x != y ? 1 : 0;
1535 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001536
Dave Allison20dfc792014-06-16 20:44:29 -07001537 DECLARE_INSTRUCTION(NotEqual);
1538
1539 virtual IfCondition GetCondition() const {
1540 return kCondNE;
1541 }
1542
1543 private:
1544 DISALLOW_COPY_AND_ASSIGN(HNotEqual);
1545};
1546
1547class HLessThan : public HCondition {
1548 public:
1549 HLessThan(HInstruction* first, HInstruction* second)
1550 : HCondition(first, second) {}
1551
Roland Levillain93445682014-10-06 19:24:02 +01001552 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1553 return x < y ? 1 : 0;
1554 }
1555 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1556 return x < y ? 1 : 0;
1557 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001558
Dave Allison20dfc792014-06-16 20:44:29 -07001559 DECLARE_INSTRUCTION(LessThan);
1560
1561 virtual IfCondition GetCondition() const {
1562 return kCondLT;
1563 }
1564
1565 private:
1566 DISALLOW_COPY_AND_ASSIGN(HLessThan);
1567};
1568
1569class HLessThanOrEqual : public HCondition {
1570 public:
1571 HLessThanOrEqual(HInstruction* first, HInstruction* second)
1572 : HCondition(first, second) {}
1573
Roland Levillain93445682014-10-06 19:24:02 +01001574 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1575 return x <= y ? 1 : 0;
1576 }
1577 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1578 return x <= y ? 1 : 0;
1579 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001580
Dave Allison20dfc792014-06-16 20:44:29 -07001581 DECLARE_INSTRUCTION(LessThanOrEqual);
1582
1583 virtual IfCondition GetCondition() const {
1584 return kCondLE;
1585 }
1586
1587 private:
1588 DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual);
1589};
1590
1591class HGreaterThan : public HCondition {
1592 public:
1593 HGreaterThan(HInstruction* first, HInstruction* second)
1594 : HCondition(first, second) {}
1595
Roland Levillain93445682014-10-06 19:24:02 +01001596 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1597 return x > y ? 1 : 0;
1598 }
1599 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1600 return x > y ? 1 : 0;
1601 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001602
Dave Allison20dfc792014-06-16 20:44:29 -07001603 DECLARE_INSTRUCTION(GreaterThan);
1604
1605 virtual IfCondition GetCondition() const {
1606 return kCondGT;
1607 }
1608
1609 private:
1610 DISALLOW_COPY_AND_ASSIGN(HGreaterThan);
1611};
1612
1613class HGreaterThanOrEqual : public HCondition {
1614 public:
1615 HGreaterThanOrEqual(HInstruction* first, HInstruction* second)
1616 : HCondition(first, second) {}
1617
Roland Levillain93445682014-10-06 19:24:02 +01001618 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
1619 return x >= y ? 1 : 0;
1620 }
1621 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
1622 return x >= y ? 1 : 0;
1623 }
Roland Levillain556c3d12014-09-18 15:25:07 +01001624
Dave Allison20dfc792014-06-16 20:44:29 -07001625 DECLARE_INSTRUCTION(GreaterThanOrEqual);
1626
1627 virtual IfCondition GetCondition() const {
1628 return kCondGE;
1629 }
1630
1631 private:
1632 DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual);
1633};
1634
1635
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001636// Instruction to check how two inputs compare to each other.
1637// Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1.
1638class HCompare : public HBinaryOperation {
1639 public:
Calin Juravleddb7df22014-11-25 20:56:51 +00001640 // The bias applies for floating point operations and indicates how NaN
1641 // comparisons are treated:
1642 enum Bias {
1643 kNoBias, // bias is not applicable (i.e. for long operation)
1644 kGtBias, // return 1 for NaN comparisons
1645 kLtBias, // return -1 for NaN comparisons
1646 };
1647
1648 HCompare(Primitive::Type type, HInstruction* first, HInstruction* second, Bias bias)
1649 : HBinaryOperation(Primitive::kPrimInt, first, second), bias_(bias) {
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001650 DCHECK_EQ(type, first->GetType());
1651 DCHECK_EQ(type, second->GetType());
1652 }
1653
Calin Juravleddb7df22014-11-25 20:56:51 +00001654 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
Roland Levillain556c3d12014-09-18 15:25:07 +01001655 return
1656 x == y ? 0 :
1657 x > y ? 1 :
1658 -1;
1659 }
Calin Juravleddb7df22014-11-25 20:56:51 +00001660
1661 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
Roland Levillain556c3d12014-09-18 15:25:07 +01001662 return
1663 x == y ? 0 :
1664 x > y ? 1 :
1665 -1;
1666 }
1667
Calin Juravleddb7df22014-11-25 20:56:51 +00001668 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
1669 return bias_ == other->AsCompare()->bias_;
1670 }
1671
1672 bool IsGtBias() { return bias_ == kGtBias; }
1673
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001674 DECLARE_INSTRUCTION(Compare);
1675
1676 private:
Calin Juravleddb7df22014-11-25 20:56:51 +00001677 const Bias bias_;
1678
Nicolas Geoffray412f10c2014-06-19 10:00:34 +01001679 DISALLOW_COPY_AND_ASSIGN(HCompare);
1680};
1681
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001682// A local in the graph. Corresponds to a Dex register.
1683class HLocal : public HTemplateInstruction<0> {
1684 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001685 explicit HLocal(uint16_t reg_number)
1686 : HTemplateInstruction(SideEffects::None()), reg_number_(reg_number) {}
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001687
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001688 DECLARE_INSTRUCTION(Local);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001689
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001690 uint16_t GetRegNumber() const { return reg_number_; }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001691
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001692 private:
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001693 // The Dex register number.
1694 const uint16_t reg_number_;
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001695
1696 DISALLOW_COPY_AND_ASSIGN(HLocal);
1697};
1698
1699// Load a given local. The local is an input of this instruction.
Dave Allison20dfc792014-06-16 20:44:29 -07001700class HLoadLocal : public HExpression<1> {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001701 public:
Roland Levillain5799fc02014-09-25 12:15:20 +01001702 HLoadLocal(HLocal* local, Primitive::Type type)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001703 : HExpression(type, SideEffects::None()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001704 SetRawInputAt(0, local);
1705 }
1706
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001707 HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); }
1708
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001709 DECLARE_INSTRUCTION(LoadLocal);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001710
1711 private:
1712 DISALLOW_COPY_AND_ASSIGN(HLoadLocal);
1713};
1714
1715// Store a value in a given local. This instruction has two inputs: the value
1716// and the local.
1717class HStoreLocal : public HTemplateInstruction<2> {
1718 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001719 HStoreLocal(HLocal* local, HInstruction* value) : HTemplateInstruction(SideEffects::None()) {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001720 SetRawInputAt(0, local);
1721 SetRawInputAt(1, value);
1722 }
1723
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001724 HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); }
1725
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001726 DECLARE_INSTRUCTION(StoreLocal);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001727
1728 private:
1729 DISALLOW_COPY_AND_ASSIGN(HStoreLocal);
1730};
1731
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001732class HConstant : public HExpression<0> {
1733 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001734 explicit HConstant(Primitive::Type type) : HExpression(type, SideEffects::None()) {}
1735
1736 virtual bool CanBeMoved() const { return true; }
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001737
1738 DECLARE_INSTRUCTION(Constant);
1739
1740 private:
1741 DISALLOW_COPY_AND_ASSIGN(HConstant);
1742};
1743
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01001744class HFloatConstant : public HConstant {
1745 public:
1746 explicit HFloatConstant(float value) : HConstant(Primitive::kPrimFloat), value_(value) {}
1747
1748 float GetValue() const { return value_; }
1749
1750 virtual bool InstructionDataEquals(HInstruction* other) const {
1751 return bit_cast<float, int32_t>(other->AsFloatConstant()->value_) ==
1752 bit_cast<float, int32_t>(value_);
1753 }
1754
1755 virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); }
1756
1757 DECLARE_INSTRUCTION(FloatConstant);
1758
1759 private:
1760 const float value_;
1761
1762 DISALLOW_COPY_AND_ASSIGN(HFloatConstant);
1763};
1764
1765class HDoubleConstant : public HConstant {
1766 public:
1767 explicit HDoubleConstant(double value) : HConstant(Primitive::kPrimDouble), value_(value) {}
1768
1769 double GetValue() const { return value_; }
1770
1771 virtual bool InstructionDataEquals(HInstruction* other) const {
1772 return bit_cast<double, int64_t>(other->AsDoubleConstant()->value_) ==
1773 bit_cast<double, int64_t>(value_);
1774 }
1775
1776 virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); }
1777
1778 DECLARE_INSTRUCTION(DoubleConstant);
1779
1780 private:
1781 const double value_;
1782
1783 DISALLOW_COPY_AND_ASSIGN(HDoubleConstant);
1784};
1785
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001786class HNullConstant : public HConstant {
1787 public:
1788 HNullConstant() : HConstant(Primitive::kPrimNot) {}
1789
1790 bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE {
1791 return true;
1792 }
1793
1794 size_t ComputeHashCode() const OVERRIDE { return 0; }
1795
Calin Juravle61d544b2015-02-23 16:46:57 +00001796 bool ActAsNullConstant() const OVERRIDE { return true; }
1797
Nicolas Geoffrayd6138ef2015-02-18 14:48:53 +00001798 DECLARE_INSTRUCTION(NullConstant);
1799
1800 private:
1801 DISALLOW_COPY_AND_ASSIGN(HNullConstant);
1802};
1803
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001804// Constants of the type int. Those can be from Dex instructions, or
1805// synthesized (for example with the if-eqz instruction).
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001806class HIntConstant : public HConstant {
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001807 public:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001808 explicit HIntConstant(int32_t value) : HConstant(Primitive::kPrimInt), value_(value) {}
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001809
Nicolas Geoffray787c3072014-03-17 10:20:19 +00001810 int32_t GetValue() const { return value_; }
Nicolas Geoffraybab4ed72014-03-11 17:53:17 +00001811
Calin Juravle61d544b2015-02-23 16:46:57 +00001812 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001813 return other->AsIntConstant()->value_ == value_;
1814 }
1815
Calin Juravle61d544b2015-02-23 16:46:57 +00001816 size_t ComputeHashCode() const OVERRIDE { return GetValue(); }
1817
1818 // TODO: Null is represented by the `0` constant. In most cases we replace it
1819 // with a HNullConstant but we don't do it when comparing (a != null). This
1820 // method is an workaround until we fix the above.
1821 bool ActAsNullConstant() const OVERRIDE { return value_ == 0; }
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +01001822
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001823 DECLARE_INSTRUCTION(IntConstant);
Nicolas Geoffray3ff386a2014-03-04 14:46:47 +00001824
1825 private:
1826 const int32_t value_;
1827
1828 DISALLOW_COPY_AND_ASSIGN(HIntConstant);
1829};
1830
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001831class HLongConstant : public HConstant {
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001832 public:
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01001833 explicit HLongConstant(int64_t value) : HConstant(Primitive::kPrimLong), value_(value) {}
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001834
1835 int64_t GetValue() const { return value_; }
1836
Nicolas Geoffray065bf772014-09-03 14:51:22 +01001837 virtual bool InstructionDataEquals(HInstruction* other) const {
1838 return other->AsLongConstant()->value_ == value_;
1839 }
1840
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +01001841 virtual size_t ComputeHashCode() const { return static_cast<size_t>(GetValue()); }
1842
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01001843 DECLARE_INSTRUCTION(LongConstant);
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001844
1845 private:
1846 const int64_t value_;
1847
1848 DISALLOW_COPY_AND_ASSIGN(HLongConstant);
1849};
1850
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001851enum class Intrinsics {
1852#define OPTIMIZING_INTRINSICS(Name, IsStatic) k ## Name,
1853#include "intrinsics_list.h"
1854 kNone,
1855 INTRINSICS_LIST(OPTIMIZING_INTRINSICS)
1856#undef INTRINSICS_LIST
1857#undef OPTIMIZING_INTRINSICS
1858};
1859std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic);
1860
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001861class HInvoke : public HInstruction {
1862 public:
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001863 virtual size_t InputCount() const { return inputs_.Size(); }
1864 virtual HInstruction* InputAt(size_t i) const { return inputs_.Get(i); }
1865
1866 // Runtime needs to walk the stack, so Dex -> Dex calls need to
1867 // know their environment.
Calin Juravle77520bc2015-01-12 18:45:46 +00001868 bool NeedsEnvironment() const OVERRIDE { return true; }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001869
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001870 void SetArgumentAt(size_t index, HInstruction* argument) {
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01001871 SetRawInputAt(index, argument);
1872 }
1873
1874 virtual void SetRawInputAt(size_t index, HInstruction* input) {
1875 inputs_.Put(index, input);
Nicolas Geoffray4a34a422014-04-03 10:38:37 +01001876 }
1877
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001878 virtual Primitive::Type GetType() const { return return_type_; }
1879
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001880 uint32_t GetDexPc() const { return dex_pc_; }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001881
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001882 uint32_t GetDexMethodIndex() const { return dex_method_index_; }
1883
1884 Intrinsics GetIntrinsic() {
1885 return intrinsic_;
1886 }
1887
1888 void SetIntrinsic(Intrinsics intrinsic) {
1889 intrinsic_ = intrinsic;
1890 }
1891
Nicolas Geoffray360231a2014-10-08 21:07:48 +01001892 DECLARE_INSTRUCTION(Invoke);
1893
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001894 protected:
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001895 HInvoke(ArenaAllocator* arena,
1896 uint32_t number_of_arguments,
1897 Primitive::Type return_type,
1898 uint32_t dex_pc,
1899 uint32_t dex_method_index)
1900 : HInstruction(SideEffects::All()),
1901 inputs_(arena, number_of_arguments),
1902 return_type_(return_type),
1903 dex_pc_(dex_pc),
1904 dex_method_index_(dex_method_index),
1905 intrinsic_(Intrinsics::kNone) {
1906 inputs_.SetSize(number_of_arguments);
1907 }
1908
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001909 GrowableArray<HInstruction*> inputs_;
Nicolas Geoffray01bc96d2014-04-11 17:43:50 +01001910 const Primitive::Type return_type_;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01001911 const uint32_t dex_pc_;
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001912 const uint32_t dex_method_index_;
1913 Intrinsics intrinsic_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001914
1915 private:
1916 DISALLOW_COPY_AND_ASSIGN(HInvoke);
1917};
1918
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001919class HInvokeStaticOrDirect : public HInvoke {
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001920 public:
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001921 HInvokeStaticOrDirect(ArenaAllocator* arena,
1922 uint32_t number_of_arguments,
1923 Primitive::Type return_type,
1924 uint32_t dex_pc,
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001925 uint32_t dex_method_index,
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001926 bool is_recursive,
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001927 InvokeType invoke_type)
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001928 : HInvoke(arena, number_of_arguments, return_type, dex_pc, dex_method_index),
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001929 invoke_type_(invoke_type),
1930 is_recursive_(is_recursive) {}
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001931
Calin Juravle77520bc2015-01-12 18:45:46 +00001932 bool CanDoImplicitNullCheck() const OVERRIDE {
1933 // We access the method via the dex cache so we can't do an implicit null check.
1934 // TODO: for intrinsics we can generate implicit null checks.
1935 return false;
1936 }
1937
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001938 InvokeType GetInvokeType() const { return invoke_type_; }
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001939 bool IsRecursive() const { return is_recursive_; }
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001940
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001941 DECLARE_INSTRUCTION(InvokeStaticOrDirect);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001942
1943 private:
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001944 const InvokeType invoke_type_;
Nicolas Geoffray1cf95282014-12-12 19:22:03 +00001945 const bool is_recursive_;
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001946
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00001947 DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect);
Nicolas Geoffray8ccc3f52014-03-19 10:34:11 +00001948};
1949
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001950class HInvokeVirtual : public HInvoke {
1951 public:
1952 HInvokeVirtual(ArenaAllocator* arena,
1953 uint32_t number_of_arguments,
1954 Primitive::Type return_type,
1955 uint32_t dex_pc,
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001956 uint32_t dex_method_index,
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001957 uint32_t vtable_index)
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001958 : HInvoke(arena, number_of_arguments, return_type, dex_pc, dex_method_index),
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001959 vtable_index_(vtable_index) {}
1960
Calin Juravle77520bc2015-01-12 18:45:46 +00001961 bool CanDoImplicitNullCheck() const OVERRIDE {
1962 // TODO: Add implicit null checks in intrinsics.
1963 return !GetLocations()->Intrinsified();
1964 }
1965
Nicolas Geoffraye982f0b2014-08-13 02:11:24 +01001966 uint32_t GetVTableIndex() const { return vtable_index_; }
1967
1968 DECLARE_INSTRUCTION(InvokeVirtual);
1969
1970 private:
1971 const uint32_t vtable_index_;
1972
1973 DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual);
1974};
1975
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001976class HInvokeInterface : public HInvoke {
1977 public:
1978 HInvokeInterface(ArenaAllocator* arena,
1979 uint32_t number_of_arguments,
1980 Primitive::Type return_type,
1981 uint32_t dex_pc,
1982 uint32_t dex_method_index,
1983 uint32_t imt_index)
Andreas Gampe71fb52f2014-12-29 17:43:08 -08001984 : HInvoke(arena, number_of_arguments, return_type, dex_pc, dex_method_index),
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001985 imt_index_(imt_index) {}
1986
Calin Juravle77520bc2015-01-12 18:45:46 +00001987 bool CanDoImplicitNullCheck() const OVERRIDE {
1988 // TODO: Add implicit null checks in intrinsics.
1989 return !GetLocations()->Intrinsified();
1990 }
1991
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001992 uint32_t GetImtIndex() const { return imt_index_; }
1993 uint32_t GetDexMethodIndex() const { return dex_method_index_; }
1994
1995 DECLARE_INSTRUCTION(InvokeInterface);
1996
1997 private:
Nicolas Geoffray52839d12014-11-07 17:47:25 +00001998 const uint32_t imt_index_;
1999
2000 DISALLOW_COPY_AND_ASSIGN(HInvokeInterface);
2001};
2002
Dave Allison20dfc792014-06-16 20:44:29 -07002003class HNewInstance : public HExpression<0> {
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002004 public:
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002005 HNewInstance(uint32_t dex_pc, uint16_t type_index, QuickEntrypointEnum entrypoint)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002006 : HExpression(Primitive::kPrimNot, SideEffects::None()),
2007 dex_pc_(dex_pc),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002008 type_index_(type_index),
2009 entrypoint_(entrypoint) {}
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002010
2011 uint32_t GetDexPc() const { return dex_pc_; }
2012 uint16_t GetTypeIndex() const { return type_index_; }
2013
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002014 // Calls runtime so needs an environment.
Calin Juravle92a6ed22014-12-02 18:58:03 +00002015 bool NeedsEnvironment() const OVERRIDE { return true; }
2016 // It may throw when called on:
2017 // - interfaces
2018 // - abstract/innaccessible/unknown classes
2019 // TODO: optimize when possible.
2020 bool CanThrow() const OVERRIDE { return true; }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002021
Calin Juravle10e244f2015-01-26 18:54:32 +00002022 bool CanBeNull() const OVERRIDE { return false; }
2023
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002024 QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; }
2025
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01002026 DECLARE_INSTRUCTION(NewInstance);
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002027
2028 private:
2029 const uint32_t dex_pc_;
2030 const uint16_t type_index_;
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002031 const QuickEntrypointEnum entrypoint_;
Nicolas Geoffray2e7038a2014-04-03 18:49:58 +01002032
2033 DISALLOW_COPY_AND_ASSIGN(HNewInstance);
2034};
2035
Roland Levillain88cb1752014-10-20 16:36:47 +01002036class HNeg : public HUnaryOperation {
2037 public:
2038 explicit HNeg(Primitive::Type result_type, HInstruction* input)
2039 : HUnaryOperation(result_type, input) {}
2040
Roland Levillain9240d6a2014-10-20 16:47:04 +01002041 virtual int32_t Evaluate(int32_t x) const OVERRIDE { return -x; }
2042 virtual int64_t Evaluate(int64_t x) const OVERRIDE { return -x; }
2043
Roland Levillain88cb1752014-10-20 16:36:47 +01002044 DECLARE_INSTRUCTION(Neg);
2045
2046 private:
2047 DISALLOW_COPY_AND_ASSIGN(HNeg);
2048};
2049
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002050class HNewArray : public HExpression<1> {
2051 public:
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002052 HNewArray(HInstruction* length,
2053 uint32_t dex_pc,
2054 uint16_t type_index,
2055 QuickEntrypointEnum entrypoint)
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002056 : HExpression(Primitive::kPrimNot, SideEffects::None()),
2057 dex_pc_(dex_pc),
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002058 type_index_(type_index),
2059 entrypoint_(entrypoint) {
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002060 SetRawInputAt(0, length);
2061 }
2062
2063 uint32_t GetDexPc() const { return dex_pc_; }
2064 uint16_t GetTypeIndex() const { return type_index_; }
2065
2066 // Calls runtime so needs an environment.
Calin Juravle10e244f2015-01-26 18:54:32 +00002067 bool NeedsEnvironment() const OVERRIDE { return true; }
2068
2069 bool CanBeNull() const OVERRIDE { return false; }
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002070
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002071 QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; }
2072
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002073 DECLARE_INSTRUCTION(NewArray);
2074
2075 private:
2076 const uint32_t dex_pc_;
2077 const uint16_t type_index_;
Nicolas Geoffraycb1b00a2015-01-28 14:50:01 +00002078 const QuickEntrypointEnum entrypoint_;
Nicolas Geoffraya3d05a42014-10-20 17:41:32 +01002079
2080 DISALLOW_COPY_AND_ASSIGN(HNewArray);
2081};
2082
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002083class HAdd : public HBinaryOperation {
2084 public:
2085 HAdd(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2086 : HBinaryOperation(result_type, left, right) {}
2087
2088 virtual bool IsCommutative() { return true; }
2089
Roland Levillain93445682014-10-06 19:24:02 +01002090 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
2091 return x + y;
2092 }
2093 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
2094 return x + y;
2095 }
Roland Levillain556c3d12014-09-18 15:25:07 +01002096
Nicolas Geoffrayd8ee7372014-03-28 15:43:40 +00002097 DECLARE_INSTRUCTION(Add);
2098
2099 private:
2100 DISALLOW_COPY_AND_ASSIGN(HAdd);
2101};
2102
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002103class HSub : public HBinaryOperation {
2104 public:
2105 HSub(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2106 : HBinaryOperation(result_type, left, right) {}
2107
Roland Levillain93445682014-10-06 19:24:02 +01002108 virtual int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
2109 return x - y;
2110 }
2111 virtual int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
2112 return x - y;
2113 }
Roland Levillain556c3d12014-09-18 15:25:07 +01002114
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002115 DECLARE_INSTRUCTION(Sub);
2116
2117 private:
2118 DISALLOW_COPY_AND_ASSIGN(HSub);
2119};
2120
Calin Juravle34bacdf2014-10-07 20:23:36 +01002121class HMul : public HBinaryOperation {
2122 public:
2123 HMul(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2124 : HBinaryOperation(result_type, left, right) {}
2125
2126 virtual bool IsCommutative() { return true; }
2127
2128 virtual int32_t Evaluate(int32_t x, int32_t y) const { return x * y; }
2129 virtual int64_t Evaluate(int64_t x, int64_t y) const { return x * y; }
2130
2131 DECLARE_INSTRUCTION(Mul);
2132
2133 private:
2134 DISALLOW_COPY_AND_ASSIGN(HMul);
2135};
2136
Calin Juravle7c4954d2014-10-28 16:57:40 +00002137class HDiv : public HBinaryOperation {
2138 public:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002139 HDiv(Primitive::Type result_type, HInstruction* left, HInstruction* right, uint32_t dex_pc)
2140 : HBinaryOperation(result_type, left, right), dex_pc_(dex_pc) {}
Calin Juravle7c4954d2014-10-28 16:57:40 +00002141
Nicolas Geoffraycd2de0c2014-11-06 15:59:38 +00002142 virtual int32_t Evaluate(int32_t x, int32_t y) const {
2143 // Our graph structure ensures we never have 0 for `y` during constant folding.
2144 DCHECK_NE(y, 0);
Calin Juravlebacfec32014-11-14 15:54:36 +00002145 // Special case -1 to avoid getting a SIGFPE on x86(_64).
Nicolas Geoffraycd2de0c2014-11-06 15:59:38 +00002146 return (y == -1) ? -x : x / y;
2147 }
Calin Juravlebacfec32014-11-14 15:54:36 +00002148
2149 virtual int64_t Evaluate(int64_t x, int64_t y) const {
2150 DCHECK_NE(y, 0);
2151 // Special case -1 to avoid getting a SIGFPE on x86(_64).
2152 return (y == -1) ? -x : x / y;
2153 }
Calin Juravle7c4954d2014-10-28 16:57:40 +00002154
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002155 uint32_t GetDexPc() const { return dex_pc_; }
2156
Calin Juravle7c4954d2014-10-28 16:57:40 +00002157 DECLARE_INSTRUCTION(Div);
2158
2159 private:
Calin Juravled6fb6cf2014-11-11 19:07:44 +00002160 const uint32_t dex_pc_;
2161
Calin Juravle7c4954d2014-10-28 16:57:40 +00002162 DISALLOW_COPY_AND_ASSIGN(HDiv);
2163};
2164
Calin Juravlebacfec32014-11-14 15:54:36 +00002165class HRem : public HBinaryOperation {
2166 public:
2167 HRem(Primitive::Type result_type, HInstruction* left, HInstruction* right, uint32_t dex_pc)
2168 : HBinaryOperation(result_type, left, right), dex_pc_(dex_pc) {}
2169
2170 virtual int32_t Evaluate(int32_t x, int32_t y) const {
2171 DCHECK_NE(y, 0);
2172 // Special case -1 to avoid getting a SIGFPE on x86(_64).
2173 return (y == -1) ? 0 : x % y;
2174 }
2175
2176 virtual int64_t Evaluate(int64_t x, int64_t y) const {
2177 DCHECK_NE(y, 0);
2178 // Special case -1 to avoid getting a SIGFPE on x86(_64).
2179 return (y == -1) ? 0 : x % y;
2180 }
2181
2182 uint32_t GetDexPc() const { return dex_pc_; }
2183
2184 DECLARE_INSTRUCTION(Rem);
2185
2186 private:
2187 const uint32_t dex_pc_;
2188
2189 DISALLOW_COPY_AND_ASSIGN(HRem);
2190};
2191
Calin Juravled0d48522014-11-04 16:40:20 +00002192class HDivZeroCheck : public HExpression<1> {
2193 public:
2194 HDivZeroCheck(HInstruction* value, uint32_t dex_pc)
2195 : HExpression(value->GetType(), SideEffects::None()), dex_pc_(dex_pc) {
2196 SetRawInputAt(0, value);
2197 }
2198
2199 bool CanBeMoved() const OVERRIDE { return true; }
2200
2201 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
2202 UNUSED(other);
2203 return true;
2204 }
2205
2206 bool NeedsEnvironment() const OVERRIDE { return true; }
2207 bool CanThrow() const OVERRIDE { return true; }
2208
2209 uint32_t GetDexPc() const { return dex_pc_; }
2210
2211 DECLARE_INSTRUCTION(DivZeroCheck);
2212
2213 private:
2214 const uint32_t dex_pc_;
2215
2216 DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck);
2217};
2218
Calin Juravle9aec02f2014-11-18 23:06:35 +00002219class HShl : public HBinaryOperation {
2220 public:
2221 HShl(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2222 : HBinaryOperation(result_type, left, right) {}
2223
2224 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x << (y & kMaxIntShiftValue); }
2225 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x << (y & kMaxLongShiftValue); }
2226
2227 DECLARE_INSTRUCTION(Shl);
2228
2229 private:
2230 DISALLOW_COPY_AND_ASSIGN(HShl);
2231};
2232
2233class HShr : public HBinaryOperation {
2234 public:
2235 HShr(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2236 : HBinaryOperation(result_type, left, right) {}
2237
2238 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x >> (y & kMaxIntShiftValue); }
2239 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x >> (y & kMaxLongShiftValue); }
2240
2241 DECLARE_INSTRUCTION(Shr);
2242
2243 private:
2244 DISALLOW_COPY_AND_ASSIGN(HShr);
2245};
2246
2247class HUShr : public HBinaryOperation {
2248 public:
2249 HUShr(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2250 : HBinaryOperation(result_type, left, right) {}
2251
2252 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE {
2253 uint32_t ux = static_cast<uint32_t>(x);
2254 uint32_t uy = static_cast<uint32_t>(y) & kMaxIntShiftValue;
2255 return static_cast<int32_t>(ux >> uy);
2256 }
2257
2258 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE {
2259 uint64_t ux = static_cast<uint64_t>(x);
2260 uint64_t uy = static_cast<uint64_t>(y) & kMaxLongShiftValue;
2261 return static_cast<int64_t>(ux >> uy);
2262 }
2263
2264 DECLARE_INSTRUCTION(UShr);
2265
2266 private:
2267 DISALLOW_COPY_AND_ASSIGN(HUShr);
2268};
2269
Nicolas Geoffray9574c4b2014-11-12 13:19:37 +00002270class HAnd : public HBinaryOperation {
2271 public:
2272 HAnd(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2273 : HBinaryOperation(result_type, left, right) {}
2274
2275 bool IsCommutative() OVERRIDE { return true; }
2276
2277 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x & y; }
2278 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x & y; }
2279
2280 DECLARE_INSTRUCTION(And);
2281
2282 private:
2283 DISALLOW_COPY_AND_ASSIGN(HAnd);
2284};
2285
2286class HOr : public HBinaryOperation {
2287 public:
2288 HOr(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2289 : HBinaryOperation(result_type, left, right) {}
2290
2291 bool IsCommutative() OVERRIDE { return true; }
2292
2293 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x | y; }
2294 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x | y; }
2295
2296 DECLARE_INSTRUCTION(Or);
2297
2298 private:
2299 DISALLOW_COPY_AND_ASSIGN(HOr);
2300};
2301
2302class HXor : public HBinaryOperation {
2303 public:
2304 HXor(Primitive::Type result_type, HInstruction* left, HInstruction* right)
2305 : HBinaryOperation(result_type, left, right) {}
2306
2307 bool IsCommutative() OVERRIDE { return true; }
2308
2309 int32_t Evaluate(int32_t x, int32_t y) const OVERRIDE { return x ^ y; }
2310 int64_t Evaluate(int64_t x, int64_t y) const OVERRIDE { return x ^ y; }
2311
2312 DECLARE_INSTRUCTION(Xor);
2313
2314 private:
2315 DISALLOW_COPY_AND_ASSIGN(HXor);
2316};
2317
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002318// The value of a parameter in this method. Its location depends on
2319// the calling convention.
Dave Allison20dfc792014-06-16 20:44:29 -07002320class HParameterValue : public HExpression<0> {
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002321 public:
Calin Juravle10e244f2015-01-26 18:54:32 +00002322 HParameterValue(uint8_t index, Primitive::Type parameter_type, bool is_this = false)
2323 : HExpression(parameter_type, SideEffects::None()), index_(index), is_this_(is_this) {}
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002324
2325 uint8_t GetIndex() const { return index_; }
2326
Calin Juravle10e244f2015-01-26 18:54:32 +00002327 bool CanBeNull() const OVERRIDE { return !is_this_; }
2328
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002329 DECLARE_INSTRUCTION(ParameterValue);
2330
2331 private:
2332 // The index of this parameter in the parameters list. Must be less
Calin Juravle10e244f2015-01-26 18:54:32 +00002333 // than HGraph::number_of_in_vregs_.
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002334 const uint8_t index_;
2335
Calin Juravle10e244f2015-01-26 18:54:32 +00002336 // Whether or not the parameter value corresponds to 'this' argument.
2337 const bool is_this_;
2338
Nicolas Geoffrayf583e592014-04-07 13:20:42 +01002339 DISALLOW_COPY_AND_ASSIGN(HParameterValue);
2340};
2341
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002342class HNot : public HUnaryOperation {
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002343 public:
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002344 explicit HNot(Primitive::Type result_type, HInstruction* input)
2345 : HUnaryOperation(result_type, input) {}
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002346
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002347 virtual bool CanBeMoved() const { return true; }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002348 virtual bool InstructionDataEquals(HInstruction* other) const {
2349 UNUSED(other);
2350 return true;
2351 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002352
Roland Levillain1cc5f2512014-10-22 18:06:21 +01002353 virtual int32_t Evaluate(int32_t x) const OVERRIDE { return ~x; }
2354 virtual int64_t Evaluate(int64_t x) const OVERRIDE { return ~x; }
2355
Nicolas Geoffrayb55f8352014-04-07 15:26:35 +01002356 DECLARE_INSTRUCTION(Not);
2357
2358 private:
2359 DISALLOW_COPY_AND_ASSIGN(HNot);
2360};
2361
Roland Levillaindff1f282014-11-05 14:15:05 +00002362class HTypeConversion : public HExpression<1> {
2363 public:
2364 // Instantiate a type conversion of `input` to `result_type`.
Roland Levillain624279f2014-12-04 11:54:28 +00002365 HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc)
2366 : HExpression(result_type, SideEffects::None()), dex_pc_(dex_pc) {
Roland Levillaindff1f282014-11-05 14:15:05 +00002367 SetRawInputAt(0, input);
2368 DCHECK_NE(input->GetType(), result_type);
2369 }
2370
2371 HInstruction* GetInput() const { return InputAt(0); }
2372 Primitive::Type GetInputType() const { return GetInput()->GetType(); }
2373 Primitive::Type GetResultType() const { return GetType(); }
2374
Roland Levillain624279f2014-12-04 11:54:28 +00002375 // Required by the x86 and ARM code generators when producing calls
2376 // to the runtime.
2377 uint32_t GetDexPc() const { return dex_pc_; }
2378
Roland Levillaindff1f282014-11-05 14:15:05 +00002379 bool CanBeMoved() const OVERRIDE { return true; }
Roland Levillained9b1952014-11-06 11:10:17 +00002380 bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; }
Roland Levillaindff1f282014-11-05 14:15:05 +00002381
2382 DECLARE_INSTRUCTION(TypeConversion);
2383
2384 private:
Roland Levillain624279f2014-12-04 11:54:28 +00002385 const uint32_t dex_pc_;
2386
Roland Levillaindff1f282014-11-05 14:15:05 +00002387 DISALLOW_COPY_AND_ASSIGN(HTypeConversion);
2388};
2389
Nicolas Geoffray276d9da2015-02-02 18:24:11 +00002390static constexpr uint32_t kNoRegNumber = -1;
2391
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002392class HPhi : public HInstruction {
2393 public:
2394 HPhi(ArenaAllocator* arena, uint32_t reg_number, size_t number_of_inputs, Primitive::Type type)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002395 : HInstruction(SideEffects::None()),
2396 inputs_(arena, number_of_inputs),
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002397 reg_number_(reg_number),
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +01002398 type_(type),
Calin Juravle10e244f2015-01-26 18:54:32 +00002399 is_live_(false),
2400 can_be_null_(true) {
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002401 inputs_.SetSize(number_of_inputs);
2402 }
2403
Calin Juravle10e244f2015-01-26 18:54:32 +00002404 size_t InputCount() const OVERRIDE { return inputs_.Size(); }
2405 HInstruction* InputAt(size_t i) const OVERRIDE { return inputs_.Get(i); }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002406
Calin Juravle10e244f2015-01-26 18:54:32 +00002407 void SetRawInputAt(size_t index, HInstruction* input) OVERRIDE {
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002408 inputs_.Put(index, input);
2409 }
2410
2411 void AddInput(HInstruction* input);
2412
Calin Juravle10e244f2015-01-26 18:54:32 +00002413 Primitive::Type GetType() const OVERRIDE { return type_; }
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01002414 void SetType(Primitive::Type type) { type_ = type; }
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002415
Calin Juravle10e244f2015-01-26 18:54:32 +00002416 bool CanBeNull() const OVERRIDE { return can_be_null_; }
2417 void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; }
2418
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002419 uint32_t GetRegNumber() const { return reg_number_; }
2420
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +01002421 void SetDead() { is_live_ = false; }
2422 void SetLive() { is_live_ = true; }
2423 bool IsDead() const { return !is_live_; }
2424 bool IsLive() const { return is_live_; }
2425
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01002426 DECLARE_INSTRUCTION(Phi);
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002427
Nicolas Geoffray96f89a22014-07-11 10:57:49 +01002428 private:
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002429 GrowableArray<HInstruction*> inputs_;
2430 const uint32_t reg_number_;
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01002431 Primitive::Type type_;
Nicolas Geoffray7dc206a2014-07-11 09:49:49 +01002432 bool is_live_;
Calin Juravle10e244f2015-01-26 18:54:32 +00002433 bool can_be_null_;
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002434
Nicolas Geoffrayc32e7702014-04-24 12:43:16 +01002435 DISALLOW_COPY_AND_ASSIGN(HPhi);
2436};
2437
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002438class HNullCheck : public HExpression<1> {
2439 public:
2440 HNullCheck(HInstruction* value, uint32_t dex_pc)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002441 : HExpression(value->GetType(), SideEffects::None()), dex_pc_(dex_pc) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002442 SetRawInputAt(0, value);
2443 }
2444
Calin Juravle10e244f2015-01-26 18:54:32 +00002445 bool CanBeMoved() const OVERRIDE { return true; }
2446 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002447 UNUSED(other);
2448 return true;
2449 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002450
Calin Juravle10e244f2015-01-26 18:54:32 +00002451 bool NeedsEnvironment() const OVERRIDE { return true; }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002452
Calin Juravle10e244f2015-01-26 18:54:32 +00002453 bool CanThrow() const OVERRIDE { return true; }
2454
2455 bool CanBeNull() const OVERRIDE { return false; }
Roland Levillaine161a2a2014-10-03 12:45:18 +01002456
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002457 uint32_t GetDexPc() const { return dex_pc_; }
2458
2459 DECLARE_INSTRUCTION(NullCheck);
2460
2461 private:
2462 const uint32_t dex_pc_;
2463
2464 DISALLOW_COPY_AND_ASSIGN(HNullCheck);
2465};
2466
2467class FieldInfo : public ValueObject {
2468 public:
Calin Juravle52c48962014-12-16 17:02:57 +00002469 FieldInfo(MemberOffset field_offset, Primitive::Type field_type, bool is_volatile)
2470 : field_offset_(field_offset), field_type_(field_type), is_volatile_(is_volatile) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002471
2472 MemberOffset GetFieldOffset() const { return field_offset_; }
Nicolas Geoffray39468442014-09-02 15:17:15 +01002473 Primitive::Type GetFieldType() const { return field_type_; }
Calin Juravle52c48962014-12-16 17:02:57 +00002474 bool IsVolatile() const { return is_volatile_; }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002475
2476 private:
2477 const MemberOffset field_offset_;
Nicolas Geoffray39468442014-09-02 15:17:15 +01002478 const Primitive::Type field_type_;
Calin Juravle52c48962014-12-16 17:02:57 +00002479 const bool is_volatile_;
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002480};
2481
2482class HInstanceFieldGet : public HExpression<1> {
2483 public:
2484 HInstanceFieldGet(HInstruction* value,
2485 Primitive::Type field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00002486 MemberOffset field_offset,
2487 bool is_volatile)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002488 : HExpression(field_type, SideEffects::DependsOnSomething()),
Calin Juravle52c48962014-12-16 17:02:57 +00002489 field_info_(field_offset, field_type, is_volatile) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002490 SetRawInputAt(0, value);
2491 }
2492
Calin Juravle10c9cbe2014-12-19 10:50:19 +00002493 bool CanBeMoved() const OVERRIDE { return !IsVolatile(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002494
2495 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
2496 HInstanceFieldGet* other_get = other->AsInstanceFieldGet();
2497 return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue();
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002498 }
2499
Calin Juravle77520bc2015-01-12 18:45:46 +00002500 bool CanDoImplicitNullCheck() const OVERRIDE {
2501 return GetFieldOffset().Uint32Value() < kPageSize;
2502 }
2503
2504 size_t ComputeHashCode() const OVERRIDE {
Nicolas Geoffrayd31cf3d2014-09-08 17:30:24 +01002505 return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue();
2506 }
2507
Calin Juravle52c48962014-12-16 17:02:57 +00002508 const FieldInfo& GetFieldInfo() const { return field_info_; }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002509 MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
Nicolas Geoffray39468442014-09-02 15:17:15 +01002510 Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002511 bool IsVolatile() const { return field_info_.IsVolatile(); }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002512
2513 DECLARE_INSTRUCTION(InstanceFieldGet);
2514
2515 private:
2516 const FieldInfo field_info_;
2517
2518 DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet);
2519};
2520
2521class HInstanceFieldSet : public HTemplateInstruction<2> {
2522 public:
2523 HInstanceFieldSet(HInstruction* object,
2524 HInstruction* value,
Nicolas Geoffray39468442014-09-02 15:17:15 +01002525 Primitive::Type field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00002526 MemberOffset field_offset,
2527 bool is_volatile)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002528 : HTemplateInstruction(SideEffects::ChangesSomething()),
Calin Juravle52c48962014-12-16 17:02:57 +00002529 field_info_(field_offset, field_type, is_volatile) {
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002530 SetRawInputAt(0, object);
2531 SetRawInputAt(1, value);
2532 }
2533
Calin Juravle77520bc2015-01-12 18:45:46 +00002534 bool CanDoImplicitNullCheck() const OVERRIDE {
2535 return GetFieldOffset().Uint32Value() < kPageSize;
2536 }
2537
Calin Juravle52c48962014-12-16 17:02:57 +00002538 const FieldInfo& GetFieldInfo() const { return field_info_; }
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002539 MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
Nicolas Geoffray39468442014-09-02 15:17:15 +01002540 Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002541 bool IsVolatile() const { return field_info_.IsVolatile(); }
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002542 HInstruction* GetValue() const { return InputAt(1); }
2543
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002544 DECLARE_INSTRUCTION(InstanceFieldSet);
2545
2546 private:
2547 const FieldInfo field_info_;
2548
2549 DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet);
2550};
2551
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002552class HArrayGet : public HExpression<2> {
2553 public:
2554 HArrayGet(HInstruction* array, HInstruction* index, Primitive::Type type)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002555 : HExpression(type, SideEffects::DependsOnSomething()) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002556 SetRawInputAt(0, array);
2557 SetRawInputAt(1, index);
2558 }
2559
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002560 bool CanBeMoved() const OVERRIDE { return true; }
2561 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002562 UNUSED(other);
2563 return true;
2564 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002565 bool CanDoImplicitNullCheck() const OVERRIDE {
2566 // TODO: We can be smarter here.
2567 // Currently, the array access is always preceded by an ArrayLength or a NullCheck
2568 // which generates the implicit null check. There are cases when these can be removed
2569 // to produce better code. If we ever add optimizations to do so we should allow an
2570 // implicit check here (as long as the address falls in the first page).
2571 return false;
2572 }
2573
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002574 void SetType(Primitive::Type type) { type_ = type; }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002575
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002576 HInstruction* GetArray() const { return InputAt(0); }
2577 HInstruction* GetIndex() const { return InputAt(1); }
2578
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002579 DECLARE_INSTRUCTION(ArrayGet);
2580
2581 private:
2582 DISALLOW_COPY_AND_ASSIGN(HArrayGet);
2583};
2584
2585class HArraySet : public HTemplateInstruction<3> {
2586 public:
2587 HArraySet(HInstruction* array,
2588 HInstruction* index,
2589 HInstruction* value,
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002590 Primitive::Type expected_component_type,
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002591 uint32_t dex_pc)
2592 : HTemplateInstruction(SideEffects::ChangesSomething()),
2593 dex_pc_(dex_pc),
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002594 expected_component_type_(expected_component_type),
2595 needs_type_check_(value->GetType() == Primitive::kPrimNot) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002596 SetRawInputAt(0, array);
2597 SetRawInputAt(1, index);
2598 SetRawInputAt(2, value);
2599 }
2600
Calin Juravle77520bc2015-01-12 18:45:46 +00002601 bool NeedsEnvironment() const OVERRIDE {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002602 // We currently always call a runtime method to catch array store
2603 // exceptions.
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002604 return needs_type_check_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002605 }
2606
Calin Juravle77520bc2015-01-12 18:45:46 +00002607 bool CanDoImplicitNullCheck() const OVERRIDE {
2608 // TODO: Same as for ArrayGet.
2609 return false;
2610 }
2611
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002612 void ClearNeedsTypeCheck() {
2613 needs_type_check_ = false;
2614 }
2615
2616 bool NeedsTypeCheck() const { return needs_type_check_; }
2617
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002618 uint32_t GetDexPc() const { return dex_pc_; }
2619
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002620 HInstruction* GetArray() const { return InputAt(0); }
2621 HInstruction* GetIndex() const { return InputAt(1); }
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002622 HInstruction* GetValue() const { return InputAt(2); }
2623
2624 Primitive::Type GetComponentType() const {
2625 // The Dex format does not type floating point index operations. Since the
2626 // `expected_component_type_` is set during building and can therefore not
2627 // be correct, we also check what is the value type. If it is a floating
2628 // point type, we must use that type.
2629 Primitive::Type value_type = GetValue()->GetType();
2630 return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble))
2631 ? value_type
2632 : expected_component_type_;
2633 }
Nicolas Geoffray39468442014-09-02 15:17:15 +01002634
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002635 DECLARE_INSTRUCTION(ArraySet);
2636
2637 private:
2638 const uint32_t dex_pc_;
Nicolas Geoffray102cbed2014-10-15 18:31:05 +01002639 const Primitive::Type expected_component_type_;
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002640 bool needs_type_check_;
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002641
2642 DISALLOW_COPY_AND_ASSIGN(HArraySet);
2643};
2644
2645class HArrayLength : public HExpression<1> {
2646 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002647 explicit HArrayLength(HInstruction* array)
2648 : HExpression(Primitive::kPrimInt, SideEffects::None()) {
2649 // Note that arrays do not change length, so the instruction does not
2650 // depend on any write.
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002651 SetRawInputAt(0, array);
2652 }
2653
Calin Juravle77520bc2015-01-12 18:45:46 +00002654 bool CanBeMoved() const OVERRIDE { return true; }
2655 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002656 UNUSED(other);
2657 return true;
2658 }
Calin Juravle77520bc2015-01-12 18:45:46 +00002659 bool CanDoImplicitNullCheck() const OVERRIDE { return true; }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002660
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002661 DECLARE_INSTRUCTION(ArrayLength);
2662
2663 private:
2664 DISALLOW_COPY_AND_ASSIGN(HArrayLength);
2665};
2666
2667class HBoundsCheck : public HExpression<2> {
2668 public:
2669 HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc)
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002670 : HExpression(index->GetType(), SideEffects::None()), dex_pc_(dex_pc) {
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002671 DCHECK(index->GetType() == Primitive::kPrimInt);
2672 SetRawInputAt(0, index);
2673 SetRawInputAt(1, length);
2674 }
2675
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002676 virtual bool CanBeMoved() const { return true; }
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07002677 virtual bool InstructionDataEquals(HInstruction* other) const {
2678 UNUSED(other);
2679 return true;
2680 }
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002681
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002682 virtual bool NeedsEnvironment() const { return true; }
2683
Roland Levillaine161a2a2014-10-03 12:45:18 +01002684 virtual bool CanThrow() const { return true; }
2685
Nicolas Geoffray3c7bb982014-07-23 16:04:16 +01002686 uint32_t GetDexPc() const { return dex_pc_; }
2687
2688 DECLARE_INSTRUCTION(BoundsCheck);
2689
2690 private:
2691 const uint32_t dex_pc_;
2692
2693 DISALLOW_COPY_AND_ASSIGN(HBoundsCheck);
2694};
2695
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002696/**
2697 * Some DEX instructions are folded into multiple HInstructions that need
2698 * to stay live until the last HInstruction. This class
2699 * is used as a marker for the baseline compiler to ensure its preceding
Calin Juravlef97f9fb2014-11-11 15:38:19 +00002700 * HInstruction stays live. `index` represents the stack location index of the
2701 * instruction (the actual offset is computed as index * vreg_size).
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002702 */
2703class HTemporary : public HTemplateInstruction<0> {
2704 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01002705 explicit HTemporary(size_t index) : HTemplateInstruction(SideEffects::None()), index_(index) {}
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002706
2707 size_t GetIndex() const { return index_; }
2708
Nicolas Geoffray421e9f92014-11-11 18:21:53 +00002709 Primitive::Type GetType() const OVERRIDE {
2710 // The previous instruction is the one that will be stored in the temporary location.
2711 DCHECK(GetPrevious() != nullptr);
2712 return GetPrevious()->GetType();
2713 }
Nicolas Geoffrayf43083d2014-11-07 10:48:10 +00002714
Nicolas Geoffraye5038322014-07-04 09:41:32 +01002715 DECLARE_INSTRUCTION(Temporary);
2716
2717 private:
2718 const size_t index_;
2719
2720 DISALLOW_COPY_AND_ASSIGN(HTemporary);
2721};
2722
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002723class HSuspendCheck : public HTemplateInstruction<0> {
2724 public:
2725 explicit HSuspendCheck(uint32_t dex_pc)
Nicolas Geoffray9ebc72c2014-09-25 16:33:42 +01002726 : HTemplateInstruction(SideEffects::None()), dex_pc_(dex_pc) {}
Nicolas Geoffrayfbc695f2014-09-15 15:33:30 +00002727
2728 virtual bool NeedsEnvironment() const {
2729 return true;
2730 }
2731
2732 uint32_t GetDexPc() const { return dex_pc_; }
2733
2734 DECLARE_INSTRUCTION(SuspendCheck);
2735
2736 private:
2737 const uint32_t dex_pc_;
2738
2739 DISALLOW_COPY_AND_ASSIGN(HSuspendCheck);
2740};
2741
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002742/**
2743 * Instruction to load a Class object.
2744 */
2745class HLoadClass : public HExpression<0> {
2746 public:
2747 HLoadClass(uint16_t type_index,
2748 bool is_referrers_class,
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002749 uint32_t dex_pc)
2750 : HExpression(Primitive::kPrimNot, SideEffects::None()),
2751 type_index_(type_index),
2752 is_referrers_class_(is_referrers_class),
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002753 dex_pc_(dex_pc),
Calin Juravleb1498f62015-02-16 13:13:29 +00002754 generate_clinit_check_(false),
2755 loaded_class_rti_(ReferenceTypeInfo::CreateTop(/* is_exact */ false)) {}
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002756
2757 bool CanBeMoved() const OVERRIDE { return true; }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002758
2759 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
2760 return other->AsLoadClass()->type_index_ == type_index_;
2761 }
2762
2763 size_t ComputeHashCode() const OVERRIDE { return type_index_; }
2764
2765 uint32_t GetDexPc() const { return dex_pc_; }
2766 uint16_t GetTypeIndex() const { return type_index_; }
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002767 bool IsReferrersClass() const { return is_referrers_class_; }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002768
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002769 bool NeedsEnvironment() const OVERRIDE {
2770 // Will call runtime and load the class if the class is not loaded yet.
2771 // TODO: finer grain decision.
2772 return !is_referrers_class_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002773 }
2774
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002775 bool MustGenerateClinitCheck() const {
2776 return generate_clinit_check_;
2777 }
2778
2779 void SetMustGenerateClinitCheck() {
2780 generate_clinit_check_ = true;
2781 }
2782
2783 bool CanCallRuntime() const {
2784 return MustGenerateClinitCheck() || !is_referrers_class_;
2785 }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002786
Nicolas Geoffray82091da2015-01-26 10:02:45 +00002787 bool CanThrow() const OVERRIDE {
2788 // May call runtime and and therefore can throw.
2789 // TODO: finer grain decision.
2790 return !is_referrers_class_;
2791 }
2792
Calin Juravleacf735c2015-02-12 15:25:22 +00002793 ReferenceTypeInfo GetLoadedClassRTI() {
2794 return loaded_class_rti_;
2795 }
2796
2797 void SetLoadedClassRTI(ReferenceTypeInfo rti) {
2798 // Make sure we only set exact types (the loaded class should never be merged).
2799 DCHECK(rti.IsExact());
2800 loaded_class_rti_ = rti;
2801 }
2802
2803 bool IsResolved() {
2804 return loaded_class_rti_.IsExact();
2805 }
2806
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002807 DECLARE_INSTRUCTION(LoadClass);
2808
2809 private:
2810 const uint16_t type_index_;
2811 const bool is_referrers_class_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002812 const uint32_t dex_pc_;
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002813 // Whether this instruction must generate the initialization check.
2814 // Used for code generation.
2815 bool generate_clinit_check_;
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002816
Calin Juravleacf735c2015-02-12 15:25:22 +00002817 ReferenceTypeInfo loaded_class_rti_;
2818
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002819 DISALLOW_COPY_AND_ASSIGN(HLoadClass);
2820};
2821
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002822class HLoadString : public HExpression<0> {
2823 public:
2824 HLoadString(uint32_t string_index, uint32_t dex_pc)
2825 : HExpression(Primitive::kPrimNot, SideEffects::None()),
2826 string_index_(string_index),
2827 dex_pc_(dex_pc) {}
2828
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002829 bool CanBeMoved() const OVERRIDE { return true; }
2830
Nicolas Geoffrayb5f62b32014-10-30 10:58:41 +00002831 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
2832 return other->AsLoadString()->string_index_ == string_index_;
2833 }
2834
2835 size_t ComputeHashCode() const OVERRIDE { return string_index_; }
2836
2837 uint32_t GetDexPc() const { return dex_pc_; }
2838 uint32_t GetStringIndex() const { return string_index_; }
2839
2840 // TODO: Can we deopt or debug when we resolve a string?
2841 bool NeedsEnvironment() const OVERRIDE { return false; }
2842
2843 DECLARE_INSTRUCTION(LoadString);
2844
2845 private:
2846 const uint32_t string_index_;
2847 const uint32_t dex_pc_;
2848
2849 DISALLOW_COPY_AND_ASSIGN(HLoadString);
2850};
2851
Nicolas Geoffraye53798a2014-12-01 10:31:54 +00002852// TODO: Pass this check to HInvokeStaticOrDirect nodes.
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002853/**
2854 * Performs an initialization check on its Class object input.
2855 */
2856class HClinitCheck : public HExpression<1> {
2857 public:
2858 explicit HClinitCheck(HLoadClass* constant, uint32_t dex_pc)
2859 : HExpression(Primitive::kPrimNot, SideEffects::All()),
2860 dex_pc_(dex_pc) {
2861 SetRawInputAt(0, constant);
2862 }
2863
Nicolas Geoffray424f6762014-11-03 14:51:25 +00002864 bool CanBeMoved() const OVERRIDE { return true; }
2865 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
2866 UNUSED(other);
2867 return true;
2868 }
2869
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002870 bool NeedsEnvironment() const OVERRIDE {
2871 // May call runtime to initialize the class.
2872 return true;
2873 }
2874
2875 uint32_t GetDexPc() const { return dex_pc_; }
2876
2877 HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); }
2878
2879 DECLARE_INSTRUCTION(ClinitCheck);
2880
2881 private:
2882 const uint32_t dex_pc_;
2883
2884 DISALLOW_COPY_AND_ASSIGN(HClinitCheck);
2885};
2886
2887class HStaticFieldGet : public HExpression<1> {
2888 public:
2889 HStaticFieldGet(HInstruction* cls,
2890 Primitive::Type field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00002891 MemberOffset field_offset,
2892 bool is_volatile)
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002893 : HExpression(field_type, SideEffects::DependsOnSomething()),
Calin Juravle52c48962014-12-16 17:02:57 +00002894 field_info_(field_offset, field_type, is_volatile) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002895 SetRawInputAt(0, cls);
2896 }
2897
Calin Juravle52c48962014-12-16 17:02:57 +00002898
Calin Juravle10c9cbe2014-12-19 10:50:19 +00002899 bool CanBeMoved() const OVERRIDE { return !IsVolatile(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002900
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002901 bool InstructionDataEquals(HInstruction* other) const OVERRIDE {
Calin Juravle52c48962014-12-16 17:02:57 +00002902 HStaticFieldGet* other_get = other->AsStaticFieldGet();
2903 return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue();
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002904 }
2905
2906 size_t ComputeHashCode() const OVERRIDE {
2907 return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue();
2908 }
2909
Calin Juravle52c48962014-12-16 17:02:57 +00002910 const FieldInfo& GetFieldInfo() const { return field_info_; }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002911 MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
2912 Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002913 bool IsVolatile() const { return field_info_.IsVolatile(); }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002914
2915 DECLARE_INSTRUCTION(StaticFieldGet);
2916
2917 private:
2918 const FieldInfo field_info_;
2919
2920 DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet);
2921};
2922
2923class HStaticFieldSet : public HTemplateInstruction<2> {
2924 public:
2925 HStaticFieldSet(HInstruction* cls,
2926 HInstruction* value,
2927 Primitive::Type field_type,
Calin Juravle52c48962014-12-16 17:02:57 +00002928 MemberOffset field_offset,
2929 bool is_volatile)
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002930 : HTemplateInstruction(SideEffects::ChangesSomething()),
Calin Juravle52c48962014-12-16 17:02:57 +00002931 field_info_(field_offset, field_type, is_volatile) {
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002932 SetRawInputAt(0, cls);
2933 SetRawInputAt(1, value);
2934 }
2935
Calin Juravle52c48962014-12-16 17:02:57 +00002936 const FieldInfo& GetFieldInfo() const { return field_info_; }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002937 MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); }
2938 Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); }
Calin Juravle52c48962014-12-16 17:02:57 +00002939 bool IsVolatile() const { return field_info_.IsVolatile(); }
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002940
Nicolas Geoffrayaf07bc12014-11-12 18:08:09 +00002941 HInstruction* GetValue() const { return InputAt(1); }
2942
Nicolas Geoffray19a19cf2014-10-22 16:07:05 +01002943 DECLARE_INSTRUCTION(StaticFieldSet);
2944
2945 private:
2946 const FieldInfo field_info_;
2947
2948 DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet);
2949};
2950
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002951// Implement the move-exception DEX instruction.
2952class HLoadException : public HExpression<0> {
2953 public:
2954 HLoadException() : HExpression(Primitive::kPrimNot, SideEffects::None()) {}
2955
2956 DECLARE_INSTRUCTION(LoadException);
2957
2958 private:
2959 DISALLOW_COPY_AND_ASSIGN(HLoadException);
2960};
2961
2962class HThrow : public HTemplateInstruction<1> {
2963 public:
2964 HThrow(HInstruction* exception, uint32_t dex_pc)
2965 : HTemplateInstruction(SideEffects::None()), dex_pc_(dex_pc) {
2966 SetRawInputAt(0, exception);
2967 }
2968
2969 bool IsControlFlow() const OVERRIDE { return true; }
2970
2971 bool NeedsEnvironment() const OVERRIDE { return true; }
2972
Nicolas Geoffray82091da2015-01-26 10:02:45 +00002973 bool CanThrow() const OVERRIDE { return true; }
2974
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002975 uint32_t GetDexPc() const { return dex_pc_; }
2976
2977 DECLARE_INSTRUCTION(Throw);
2978
2979 private:
Nicolas Geoffray82091da2015-01-26 10:02:45 +00002980 const uint32_t dex_pc_;
Nicolas Geoffrayde58ab22014-11-05 12:46:03 +00002981
2982 DISALLOW_COPY_AND_ASSIGN(HThrow);
2983};
2984
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002985class HInstanceOf : public HExpression<2> {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002986 public:
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00002987 HInstanceOf(HInstruction* object,
2988 HLoadClass* constant,
2989 bool class_is_final,
2990 uint32_t dex_pc)
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00002991 : HExpression(Primitive::kPrimBoolean, SideEffects::None()),
2992 class_is_final_(class_is_final),
2993 dex_pc_(dex_pc) {
2994 SetRawInputAt(0, object);
2995 SetRawInputAt(1, constant);
2996 }
2997
2998 bool CanBeMoved() const OVERRIDE { return true; }
2999
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003000 bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003001 return true;
3002 }
3003
3004 bool NeedsEnvironment() const OVERRIDE {
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003005 return false;
3006 }
3007
3008 uint32_t GetDexPc() const { return dex_pc_; }
3009
3010 bool IsClassFinal() const { return class_is_final_; }
3011
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003012 DECLARE_INSTRUCTION(InstanceOf);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003013
3014 private:
3015 const bool class_is_final_;
3016 const uint32_t dex_pc_;
3017
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003018 DISALLOW_COPY_AND_ASSIGN(HInstanceOf);
3019};
3020
Calin Juravleb1498f62015-02-16 13:13:29 +00003021class HBoundType : public HExpression<1> {
3022 public:
3023 HBoundType(HInstruction* input, ReferenceTypeInfo bound_type)
3024 : HExpression(Primitive::kPrimNot, SideEffects::None()),
3025 bound_type_(bound_type) {
Calin Juravle61d544b2015-02-23 16:46:57 +00003026 DCHECK_EQ(input->GetType(), Primitive::kPrimNot);
Calin Juravleb1498f62015-02-16 13:13:29 +00003027 SetRawInputAt(0, input);
3028 }
3029
3030 const ReferenceTypeInfo& GetBoundType() const { return bound_type_; }
3031
3032 bool CanBeNull() const OVERRIDE {
3033 // `null instanceof ClassX` always return false so we can't be null.
3034 return false;
3035 }
3036
3037 DECLARE_INSTRUCTION(BoundType);
3038
3039 private:
3040 // Encodes the most upper class that this instruction can have. In other words
3041 // it is always the case that GetBoundType().IsSupertypeOf(GetReferenceType()).
3042 // It is used to bound the type in cases like `if (x instanceof ClassX) {}`
3043 const ReferenceTypeInfo bound_type_;
3044
3045 DISALLOW_COPY_AND_ASSIGN(HBoundType);
3046};
3047
Nicolas Geoffray57a88d42014-11-10 15:09:21 +00003048class HCheckCast : public HTemplateInstruction<2> {
3049 public:
3050 HCheckCast(HInstruction* object,
3051 HLoadClass* constant,
3052 bool class_is_final,
3053 uint32_t dex_pc)
3054 : HTemplateInstruction(SideEffects::None()),
3055 class_is_final_(class_is_final),
3056 dex_pc_(dex_pc) {
3057 SetRawInputAt(0, object);
3058 SetRawInputAt(1, constant);
3059 }
3060
3061 bool CanBeMoved() const OVERRIDE { return true; }
3062
3063 bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE {
3064 return true;
3065 }
3066
3067 bool NeedsEnvironment() const OVERRIDE {
3068 // Instruction may throw a CheckCastError.
3069 return true;
3070 }
3071
3072 bool CanThrow() const OVERRIDE { return true; }
3073
3074 uint32_t GetDexPc() const { return dex_pc_; }
3075
3076 bool IsClassFinal() const { return class_is_final_; }
3077
3078 DECLARE_INSTRUCTION(CheckCast);
3079
3080 private:
3081 const bool class_is_final_;
3082 const uint32_t dex_pc_;
3083
3084 DISALLOW_COPY_AND_ASSIGN(HCheckCast);
Nicolas Geoffray6f5c41f2014-11-06 08:59:20 +00003085};
3086
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003087class HMonitorOperation : public HTemplateInstruction<1> {
3088 public:
3089 enum OperationKind {
3090 kEnter,
3091 kExit,
3092 };
3093
3094 HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc)
3095 : HTemplateInstruction(SideEffects::None()), kind_(kind), dex_pc_(dex_pc) {
3096 SetRawInputAt(0, object);
3097 }
3098
3099 // Instruction may throw a Java exception, so we need an environment.
3100 bool NeedsEnvironment() const OVERRIDE { return true; }
3101 bool CanThrow() const OVERRIDE { return true; }
3102
3103 uint32_t GetDexPc() const { return dex_pc_; }
3104
3105 bool IsEnter() const { return kind_ == kEnter; }
3106
3107 DECLARE_INSTRUCTION(MonitorOperation);
3108
Calin Juravle52c48962014-12-16 17:02:57 +00003109 private:
Nicolas Geoffrayb7baf5c2014-11-11 16:29:44 +00003110 const OperationKind kind_;
3111 const uint32_t dex_pc_;
3112
3113 private:
3114 DISALLOW_COPY_AND_ASSIGN(HMonitorOperation);
3115};
3116
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003117class MoveOperands : public ArenaObject<kArenaAllocMisc> {
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003118 public:
Nicolas Geoffray740475d2014-09-29 10:33:25 +01003119 MoveOperands(Location source, Location destination, HInstruction* instruction)
3120 : source_(source), destination_(destination), instruction_(instruction) {}
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003121
3122 Location GetSource() const { return source_; }
3123 Location GetDestination() const { return destination_; }
3124
3125 void SetSource(Location value) { source_ = value; }
3126 void SetDestination(Location value) { destination_ = value; }
3127
3128 // The parallel move resolver marks moves as "in-progress" by clearing the
3129 // destination (but not the source).
3130 Location MarkPending() {
3131 DCHECK(!IsPending());
3132 Location dest = destination_;
3133 destination_ = Location::NoLocation();
3134 return dest;
3135 }
3136
3137 void ClearPending(Location dest) {
3138 DCHECK(IsPending());
3139 destination_ = dest;
3140 }
3141
3142 bool IsPending() const {
3143 DCHECK(!source_.IsInvalid() || destination_.IsInvalid());
3144 return destination_.IsInvalid() && !source_.IsInvalid();
3145 }
3146
3147 // True if this blocks a move from the given location.
3148 bool Blocks(Location loc) const {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003149 return !IsEliminated() && (source_.Contains(loc) || loc.Contains(source_));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003150 }
3151
3152 // A move is redundant if it's been eliminated, if its source and
3153 // destination are the same, or if its destination is unneeded.
3154 bool IsRedundant() const {
3155 return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_);
3156 }
3157
3158 // We clear both operands to indicate move that's been eliminated.
3159 void Eliminate() {
3160 source_ = destination_ = Location::NoLocation();
3161 }
3162
3163 bool IsEliminated() const {
3164 DCHECK(!source_.IsInvalid() || destination_.IsInvalid());
3165 return source_.IsInvalid();
3166 }
3167
Nicolas Geoffray740475d2014-09-29 10:33:25 +01003168 HInstruction* GetInstruction() const { return instruction_; }
3169
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003170 private:
3171 Location source_;
3172 Location destination_;
Nicolas Geoffray740475d2014-09-29 10:33:25 +01003173 // The instruction this move is assocatied with. Null when this move is
3174 // for moving an input in the expected locations of user (including a phi user).
3175 // This is only used in debug mode, to ensure we do not connect interval siblings
3176 // in the same parallel move.
3177 HInstruction* instruction_;
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003178};
3179
3180static constexpr size_t kDefaultNumberOfMoves = 4;
3181
3182class HParallelMove : public HTemplateInstruction<0> {
3183 public:
Nicolas Geoffray065bf772014-09-03 14:51:22 +01003184 explicit HParallelMove(ArenaAllocator* arena)
3185 : HTemplateInstruction(SideEffects::None()), moves_(arena, kDefaultNumberOfMoves) {}
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003186
Nicolas Geoffray42d1f5f2015-01-16 09:14:18 +00003187 void AddMove(Location source, Location destination, HInstruction* instruction) {
3188 DCHECK(source.IsValid());
3189 DCHECK(destination.IsValid());
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003190 if (kIsDebugBuild) {
3191 if (instruction != nullptr) {
Nicolas Geoffraydd8f8872015-01-15 15:37:37 +00003192 for (size_t i = 0, e = moves_.Size(); i < e; ++i) {
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003193 DCHECK_NE(moves_.Get(i).GetInstruction(), instruction)
3194 << "Doing parallel moves for the same instruction.";
Nicolas Geoffraydd8f8872015-01-15 15:37:37 +00003195 }
3196 }
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003197 for (size_t i = 0, e = moves_.Size(); i < e; ++i) {
3198 DCHECK(!destination.Equals(moves_.Get(i).GetDestination()))
3199 << "Same destination for two moves in a parallel move.";
3200 }
Nicolas Geoffray740475d2014-09-29 10:33:25 +01003201 }
Nicolas Geoffrayf7a0c4e2015-02-10 17:08:47 +00003202 moves_.Add(MoveOperands(source, destination, instruction));
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003203 }
3204
3205 MoveOperands* MoveOperandsAt(size_t index) const {
Nicolas Geoffray42d1f5f2015-01-16 09:14:18 +00003206 return moves_.GetRawStorage() + index;
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003207 }
3208
3209 size_t NumMoves() const { return moves_.Size(); }
3210
Nicolas Geoffraya7062e02014-05-22 12:50:17 +01003211 DECLARE_INSTRUCTION(ParallelMove);
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003212
3213 private:
Nicolas Geoffray42d1f5f2015-01-16 09:14:18 +00003214 GrowableArray<MoveOperands> moves_;
Nicolas Geoffray4e3d23a2014-05-22 18:32:45 +01003215
3216 DISALLOW_COPY_AND_ASSIGN(HParallelMove);
3217};
3218
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003219class HGraphVisitor : public ValueObject {
3220 public:
Dave Allison20dfc792014-06-16 20:44:29 -07003221 explicit HGraphVisitor(HGraph* graph) : graph_(graph) {}
3222 virtual ~HGraphVisitor() {}
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003223
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07003224 virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); }
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003225 virtual void VisitBasicBlock(HBasicBlock* block);
3226
Roland Levillain633021e2014-10-01 14:12:25 +01003227 // Visit the graph following basic block insertion order.
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003228 void VisitInsertionOrder();
3229
Roland Levillain633021e2014-10-01 14:12:25 +01003230 // Visit the graph following dominator tree reverse post-order.
3231 void VisitReversePostOrder();
3232
Nicolas Geoffray787c3072014-03-17 10:20:19 +00003233 HGraph* GetGraph() const { return graph_; }
Nicolas Geoffrayd4dd2552014-02-28 10:23:58 +00003234
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003235 // Visit functions for instruction classes.
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003236#define DECLARE_VISIT_INSTRUCTION(name, super) \
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003237 virtual void Visit##name(H##name* instr) { VisitInstruction(instr); }
3238
3239 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
3240
3241#undef DECLARE_VISIT_INSTRUCTION
3242
3243 private:
Ian Rogerscf7f1912014-10-22 22:06:39 -07003244 HGraph* const graph_;
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003245
3246 DISALLOW_COPY_AND_ASSIGN(HGraphVisitor);
3247};
3248
Nicolas Geoffray360231a2014-10-08 21:07:48 +01003249class HGraphDelegateVisitor : public HGraphVisitor {
3250 public:
3251 explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {}
3252 virtual ~HGraphDelegateVisitor() {}
3253
3254 // Visit functions that delegate to to super class.
3255#define DECLARE_VISIT_INSTRUCTION(name, super) \
3256 virtual void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); }
3257
3258 FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION)
3259
3260#undef DECLARE_VISIT_INSTRUCTION
3261
3262 private:
3263 DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor);
3264};
3265
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003266class HInsertionOrderIterator : public ValueObject {
3267 public:
3268 explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {}
3269
3270 bool Done() const { return index_ == graph_.GetBlocks().Size(); }
3271 HBasicBlock* Current() const { return graph_.GetBlocks().Get(index_); }
3272 void Advance() { ++index_; }
3273
3274 private:
3275 const HGraph& graph_;
3276 size_t index_;
3277
3278 DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator);
3279};
3280
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003281class HReversePostOrderIterator : public ValueObject {
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003282 public:
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003283 explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {}
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003284
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003285 bool Done() const { return index_ == graph_.GetReversePostOrder().Size(); }
3286 HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_); }
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003287 void Advance() { ++index_; }
3288
3289 private:
3290 const HGraph& graph_;
3291 size_t index_;
3292
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003293 DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator);
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003294};
3295
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003296class HPostOrderIterator : public ValueObject {
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003297 public:
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003298 explicit HPostOrderIterator(const HGraph& graph)
3299 : graph_(graph), index_(graph_.GetReversePostOrder().Size()) {}
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003300
3301 bool Done() const { return index_ == 0; }
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003302 HBasicBlock* Current() const { return graph_.GetReversePostOrder().Get(index_ - 1); }
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003303 void Advance() { --index_; }
3304
3305 private:
3306 const HGraph& graph_;
3307 size_t index_;
3308
Nicolas Geoffray622d9c32014-05-12 16:11:02 +01003309 DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator);
Nicolas Geoffray804d0932014-05-02 08:46:00 +01003310};
3311
Nicolas Geoffray82091da2015-01-26 10:02:45 +00003312// Iterator over the blocks that art part of the loop. Includes blocks part
3313// of an inner loop. The order in which the blocks are iterated is on their
3314// block id.
3315class HBlocksInLoopIterator : public ValueObject {
3316 public:
3317 explicit HBlocksInLoopIterator(const HLoopInformation& info)
3318 : blocks_in_loop_(info.GetBlocks()),
3319 blocks_(info.GetHeader()->GetGraph()->GetBlocks()),
3320 index_(0) {
3321 if (!blocks_in_loop_.IsBitSet(index_)) {
3322 Advance();
3323 }
3324 }
3325
3326 bool Done() const { return index_ == blocks_.Size(); }
3327 HBasicBlock* Current() const { return blocks_.Get(index_); }
3328 void Advance() {
3329 ++index_;
3330 for (size_t e = blocks_.Size(); index_ < e; ++index_) {
3331 if (blocks_in_loop_.IsBitSet(index_)) {
3332 break;
3333 }
3334 }
3335 }
3336
3337 private:
3338 const BitVector& blocks_in_loop_;
3339 const GrowableArray<HBasicBlock*>& blocks_;
3340 size_t index_;
3341
3342 DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator);
3343};
3344
Nicolas Geoffray818f2102014-02-18 16:43:35 +00003345} // namespace art
3346
3347#endif // ART_COMPILER_OPTIMIZING_NODES_H_