Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 24 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 25 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 26 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 27 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 29 | #include "handle.h" |
| 30 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 31 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 32 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 33 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 35 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 36 | #include "primitive.h" |
Nicolas Geoffray | 0e33643 | 2014-02-26 18:24:38 +0000 | [diff] [blame] | 37 | #include "utils/arena_bit_vector.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 41 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 42 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 44 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 45 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 46 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 48 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 50 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 51 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 52 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 54 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 55 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 56 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 57 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 58 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 59 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 60 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 63 | namespace mirror { |
| 64 | class DexCache; |
| 65 | } // namespace mirror |
| 66 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | static const int kDefaultNumberOfBlocks = 8; |
| 68 | static const int kDefaultNumberOfSuccessors = 2; |
| 69 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 70 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 74 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 75 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 76 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 77 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
| 78 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 79 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 80 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 81 | static constexpr uint32_t kNoDexPc = -1; |
| 82 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 83 | enum IfCondition { |
| 84 | kCondEQ, |
| 85 | kCondNE, |
| 86 | kCondLT, |
| 87 | kCondLE, |
| 88 | kCondGT, |
| 89 | kCondGE, |
| 90 | }; |
| 91 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 92 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 93 | public: |
| 94 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 95 | |
| 96 | void AddInstruction(HInstruction* instruction); |
| 97 | void RemoveInstruction(HInstruction* instruction); |
| 98 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 99 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 100 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 101 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 102 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 103 | // Return true if this list contains `instruction`. |
| 104 | bool Contains(HInstruction* instruction) const; |
| 105 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 106 | // Return true if `instruction1` is found before `instruction2` in |
| 107 | // this instruction list and false otherwise. Abort if none |
| 108 | // of these instructions is found. |
| 109 | bool FoundBefore(const HInstruction* instruction1, |
| 110 | const HInstruction* instruction2) const; |
| 111 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 112 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 113 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 114 | |
| 115 | // Update the block of all instructions to be `block`. |
| 116 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 117 | |
| 118 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 119 | void Add(const HInstructionList& instruction_list); |
| 120 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 121 | // Return the number of instructions in the list. This is an expensive operation. |
| 122 | size_t CountSize() const; |
| 123 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 124 | private: |
| 125 | HInstruction* first_instruction_; |
| 126 | HInstruction* last_instruction_; |
| 127 | |
| 128 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 129 | friend class HGraph; |
| 130 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 131 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 132 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 133 | |
| 134 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 135 | }; |
| 136 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 137 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 138 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 139 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 140 | HGraph(ArenaAllocator* arena, |
| 141 | const DexFile& dex_file, |
| 142 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 143 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 144 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 145 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 146 | bool debuggable = false, |
| 147 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 148 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 149 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 150 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 151 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 152 | entry_block_(nullptr), |
| 153 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 154 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 155 | number_of_vregs_(0), |
| 156 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 157 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 158 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 159 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 160 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 161 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 162 | dex_file_(dex_file), |
| 163 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 164 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 165 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 166 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 167 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 168 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 169 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 170 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 171 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 172 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 173 | cached_current_method_(nullptr) { |
| 174 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 175 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 176 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 177 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 178 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 179 | |
| 180 | HBasicBlock* GetBlock(size_t id) const { |
| 181 | DCHECK_LT(id, blocks_.size()); |
| 182 | return blocks_[id]; |
| 183 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 184 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 185 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 186 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 187 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 188 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 189 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 190 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 191 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 192 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 193 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 194 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 195 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 196 | // Try building the SSA form of this graph, with dominance computation and loop |
| 197 | // recognition. Returns whether it was successful in doing all these steps. |
| 198 | bool TryBuildingSsa() { |
| 199 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 200 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 201 | // elimination phase checks the consistency of the graph when doing a post-order |
| 202 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 203 | // users remaining when being visited. |
| 204 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 205 | // Precompute per-block try membership before entering the SSA builder, |
| 206 | // which needs the information to build catch block phis from values of |
| 207 | // locals at throwing instructions inside try blocks. |
| 208 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 209 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 210 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 211 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 214 | void ComputeDominanceInformation(); |
| 215 | void ClearDominanceInformation(); |
| 216 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 217 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 218 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 219 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 220 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 221 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 222 | // Analyze all natural loops in this graph. Returns false if one |
| 223 | // loop is not natural, that is the header does not dominate the |
| 224 | // back edge. |
| 225 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 226 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 227 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 228 | // order and loop information. |
| 229 | void ComputeTryBlockInformation(); |
| 230 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 231 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 232 | // Returns the instruction used to replace the invoke expression or null if the |
| 233 | // invoke is for a void method. |
| 234 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 235 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 236 | // Need to add a couple of blocks to test if the loop body is entered and |
| 237 | // put deoptimization instructions, etc. |
| 238 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 239 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 240 | // Removes `block` from the graph. |
| 241 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 242 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 243 | // Splits the edge between `block` and `successor` while preserving the |
| 244 | // indices in the predecessor/successor lists. If there are multiple edges |
| 245 | // between the blocks, the lowest indices are used. |
| 246 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 247 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 248 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 249 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 250 | void SimplifyLoop(HBasicBlock* header); |
| 251 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 252 | int32_t GetNextInstructionId() { |
| 253 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 254 | return current_instruction_id_++; |
| 255 | } |
| 256 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 257 | int32_t GetCurrentInstructionId() const { |
| 258 | return current_instruction_id_; |
| 259 | } |
| 260 | |
| 261 | void SetCurrentInstructionId(int32_t id) { |
| 262 | current_instruction_id_ = id; |
| 263 | } |
| 264 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 265 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 266 | return maximum_number_of_out_vregs_; |
| 267 | } |
| 268 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 269 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 270 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 273 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 274 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 275 | } |
| 276 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 277 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 278 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 281 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 282 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 283 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 286 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 287 | number_of_vregs_ = number_of_vregs; |
| 288 | } |
| 289 | |
| 290 | uint16_t GetNumberOfVRegs() const { |
| 291 | return number_of_vregs_; |
| 292 | } |
| 293 | |
| 294 | void SetNumberOfInVRegs(uint16_t value) { |
| 295 | number_of_in_vregs_ = value; |
| 296 | } |
| 297 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 298 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 299 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 300 | return number_of_vregs_ - number_of_in_vregs_; |
| 301 | } |
| 302 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 303 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 304 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 305 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 306 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 307 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 308 | return linear_order_; |
| 309 | } |
| 310 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 311 | bool HasBoundsChecks() const { |
| 312 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 315 | void SetHasBoundsChecks(bool value) { |
| 316 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 319 | bool ShouldGenerateConstructorBarrier() const { |
| 320 | return should_generate_constructor_barrier_; |
| 321 | } |
| 322 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 323 | bool IsDebuggable() const { return debuggable_; } |
| 324 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 325 | // Returns a constant of the given type and value. If it does not exist |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 326 | // already, it is created and inserted into the graph. This method is only for |
| 327 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 328 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 329 | |
| 330 | // TODO: This is problematic for the consistency of reference type propagation |
| 331 | // because it can be created anytime after the pass and thus it will be left |
| 332 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 334 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 335 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 336 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 337 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 339 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 340 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 341 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 342 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 343 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 344 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 345 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 346 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 347 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 348 | HCurrentMethod* GetCurrentMethod(); |
| 349 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 350 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 351 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 352 | const DexFile& GetDexFile() const { |
| 353 | return dex_file_; |
| 354 | } |
| 355 | |
| 356 | uint32_t GetMethodIdx() const { |
| 357 | return method_idx_; |
| 358 | } |
| 359 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 360 | InvokeType GetInvokeType() const { |
| 361 | return invoke_type_; |
| 362 | } |
| 363 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 364 | InstructionSet GetInstructionSet() const { |
| 365 | return instruction_set_; |
| 366 | } |
| 367 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 368 | bool HasTryCatch() const { return has_try_catch_; } |
| 369 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 370 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 371 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 372 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 373 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 374 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 375 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 376 | template <class InstructionType, typename ValueType> |
| 377 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 378 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 379 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 380 | // Try to find an existing constant of the given value. |
| 381 | InstructionType* constant = nullptr; |
| 382 | auto cached_constant = cache->find(value); |
| 383 | if (cached_constant != cache->end()) { |
| 384 | constant = cached_constant->second; |
| 385 | } |
| 386 | |
| 387 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 388 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 389 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 390 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 391 | cache->Overwrite(value, constant); |
| 392 | InsertConstant(constant); |
| 393 | } |
| 394 | return constant; |
| 395 | } |
| 396 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 397 | void InsertConstant(HConstant* instruction); |
| 398 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 399 | // Cache a float constant into the graph. This method should only be |
| 400 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 401 | void CacheFloatConstant(HFloatConstant* constant); |
| 402 | |
| 403 | // See CacheFloatConstant comment. |
| 404 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 405 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 406 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 407 | |
| 408 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 409 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 410 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 411 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 412 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 413 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 414 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 415 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 416 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 417 | HBasicBlock* entry_block_; |
| 418 | HBasicBlock* exit_block_; |
| 419 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 420 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 421 | uint16_t maximum_number_of_out_vregs_; |
| 422 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 423 | // The number of virtual registers in this method. Contains the parameters. |
| 424 | uint16_t number_of_vregs_; |
| 425 | |
| 426 | // The number of virtual registers used by parameters of this method. |
| 427 | uint16_t number_of_in_vregs_; |
| 428 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 429 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 430 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 431 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 432 | // Has bounds checks. We can totally skip BCE if it's false. |
| 433 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 434 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 435 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 436 | // try/catch-related passes if false. |
| 437 | bool has_try_catch_; |
| 438 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 439 | // Indicates whether the graph should be compiled in a way that |
| 440 | // ensures full debuggability. If false, we can apply more |
| 441 | // aggressive optimizations that may limit the level of debugging. |
| 442 | const bool debuggable_; |
| 443 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 444 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 445 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 446 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 447 | // The dex file from which the method is from. |
| 448 | const DexFile& dex_file_; |
| 449 | |
| 450 | // The method index in the dex file. |
| 451 | const uint32_t method_idx_; |
| 452 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 453 | // If inlined, this encodes how the callee is being invoked. |
| 454 | const InvokeType invoke_type_; |
| 455 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 456 | // Whether the graph has been transformed to SSA form. Only used |
| 457 | // in debug mode to ensure we are not using properties only valid |
| 458 | // for non-SSA form (like the number of temporaries). |
| 459 | bool in_ssa_form_; |
| 460 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 461 | const bool should_generate_constructor_barrier_; |
| 462 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 463 | const InstructionSet instruction_set_; |
| 464 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 465 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 466 | HNullConstant* cached_null_constant_; |
| 467 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 468 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 469 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 470 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 471 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 472 | HCurrentMethod* cached_current_method_; |
| 473 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 474 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 475 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 476 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 477 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 478 | }; |
| 479 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 480 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 481 | public: |
| 482 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 483 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 484 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 485 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 486 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 487 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 488 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 489 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 490 | |
| 491 | HBasicBlock* GetHeader() const { |
| 492 | return header_; |
| 493 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 494 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 495 | void SetHeader(HBasicBlock* block) { |
| 496 | header_ = block; |
| 497 | } |
| 498 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 499 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 500 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 501 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 502 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 503 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 504 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 507 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 508 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 509 | } |
| 510 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 511 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 512 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 515 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 516 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 519 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 520 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 521 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 522 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 525 | // Returns the lifetime position of the back edge that has the |
| 526 | // greatest lifetime position. |
| 527 | size_t GetLifetimeEnd() const; |
| 528 | |
| 529 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 530 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 533 | // Finds blocks that are part of this loop. Returns whether the loop is a natural loop, |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 534 | // that is the header dominates the back edge. |
| 535 | bool Populate(); |
| 536 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 537 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 538 | // Populate(). If there are no back edges left, the loop info is completely |
| 539 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 540 | // inner loops first. |
| 541 | void Update(); |
| 542 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 543 | // Returns whether this loop information contains `block`. |
| 544 | // Note that this loop information *must* be populated before entering this function. |
| 545 | bool Contains(const HBasicBlock& block) const; |
| 546 | |
| 547 | // Returns whether this loop information is an inner loop of `other`. |
| 548 | // Note that `other` *must* be populated before entering this function. |
| 549 | bool IsIn(const HLoopInformation& other) const; |
| 550 | |
| 551 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 552 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 553 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 554 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 555 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 556 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 557 | // Internal recursive implementation of `Populate`. |
| 558 | void PopulateRecursive(HBasicBlock* block); |
| 559 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 560 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 561 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 562 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 563 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 564 | |
| 565 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 566 | }; |
| 567 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 568 | // Stores try/catch information for basic blocks. |
| 569 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 570 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 571 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 572 | public: |
| 573 | // Try block information constructor. |
| 574 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 575 | : try_entry_(&try_entry), |
| 576 | catch_dex_file_(nullptr), |
| 577 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 578 | DCHECK(try_entry_ != nullptr); |
| 579 | } |
| 580 | |
| 581 | // Catch block information constructor. |
| 582 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 583 | : try_entry_(nullptr), |
| 584 | catch_dex_file_(&dex_file), |
| 585 | catch_type_index_(catch_type_index) {} |
| 586 | |
| 587 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 588 | |
| 589 | const HTryBoundary& GetTryEntry() const { |
| 590 | DCHECK(IsTryBlock()); |
| 591 | return *try_entry_; |
| 592 | } |
| 593 | |
| 594 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 595 | |
| 596 | bool IsCatchAllTypeIndex() const { |
| 597 | DCHECK(IsCatchBlock()); |
| 598 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 599 | } |
| 600 | |
| 601 | uint16_t GetCatchTypeIndex() const { |
| 602 | DCHECK(IsCatchBlock()); |
| 603 | return catch_type_index_; |
| 604 | } |
| 605 | |
| 606 | const DexFile& GetCatchDexFile() const { |
| 607 | DCHECK(IsCatchBlock()); |
| 608 | return *catch_dex_file_; |
| 609 | } |
| 610 | |
| 611 | private: |
| 612 | // One of possibly several TryBoundary instructions entering the block's try. |
| 613 | // Only set for try blocks. |
| 614 | const HTryBoundary* try_entry_; |
| 615 | |
| 616 | // Exception type information. Only set for catch blocks. |
| 617 | const DexFile* catch_dex_file_; |
| 618 | const uint16_t catch_type_index_; |
| 619 | }; |
| 620 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 621 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 622 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 623 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 624 | // A block in a method. Contains the list of instructions represented |
| 625 | // as a double linked list. Each block knows its predecessors and |
| 626 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 627 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 628 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 629 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 630 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 631 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 632 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 633 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 634 | loop_information_(nullptr), |
| 635 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 636 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 637 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 638 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 639 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 640 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 641 | try_catch_information_(nullptr) { |
| 642 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 643 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 644 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 645 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 646 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 647 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 648 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 651 | HBasicBlock* GetPredecessor(size_t pred_idx) const { |
| 652 | DCHECK_LT(pred_idx, predecessors_.size()); |
| 653 | return predecessors_[pred_idx]; |
| 654 | } |
| 655 | |
| 656 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 657 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 660 | HBasicBlock* GetSuccessor(size_t succ_idx) const { |
| 661 | DCHECK_LT(succ_idx, successors_.size()); |
| 662 | return successors_[succ_idx]; |
| 663 | } |
| 664 | |
| 665 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 666 | return ContainsElement(successors_, block, start_from); |
| 667 | } |
| 668 | |
| 669 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 670 | return dominated_blocks_; |
| 671 | } |
| 672 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 673 | bool IsEntryBlock() const { |
| 674 | return graph_->GetEntryBlock() == this; |
| 675 | } |
| 676 | |
| 677 | bool IsExitBlock() const { |
| 678 | return graph_->GetExitBlock() == this; |
| 679 | } |
| 680 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 681 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 682 | bool IsSingleTryBoundary() const; |
| 683 | |
| 684 | // Returns true if this block emits nothing but a jump. |
| 685 | bool IsSingleJump() const { |
| 686 | HLoopInformation* loop_info = GetLoopInformation(); |
| 687 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 688 | // Back edges generate a suspend check. |
| 689 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 690 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 691 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 692 | void AddBackEdge(HBasicBlock* back_edge) { |
| 693 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 694 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 695 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 697 | loop_information_->AddBackEdge(back_edge); |
| 698 | } |
| 699 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 700 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 701 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 702 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 703 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 704 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 705 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HBasicBlock* GetDominator() const { return dominator_; } |
| 708 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 709 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 710 | |
| 711 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 712 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 713 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 714 | |
| 715 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 716 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 717 | } |
| 718 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 719 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 720 | |
| 721 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 722 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 725 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 726 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 727 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 728 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 729 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 730 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 731 | |
| 732 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 733 | successors_.push_back(block); |
| 734 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 737 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 738 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 739 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | new_block->predecessors_.push_back(this); |
| 741 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 744 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 746 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->successors_.push_back(this); |
| 748 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 751 | // Insert `this` between `predecessor` and `successor. This method |
| 752 | // preserves the indicies, and will update the first edge found between |
| 753 | // `predecessor` and `successor`. |
| 754 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 755 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 756 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 757 | successor->predecessors_[predecessor_index] = this; |
| 758 | predecessor->successors_[successor_index] = this; |
| 759 | successors_.push_back(successor); |
| 760 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 761 | } |
| 762 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 763 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 767 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 768 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 771 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 772 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 776 | predecessors_.push_back(block); |
| 777 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 780 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 781 | DCHECK_EQ(predecessors_.size(), 2u); |
| 782 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 783 | } |
| 784 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 785 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 786 | DCHECK_EQ(successors_.size(), 2u); |
| 787 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 788 | } |
| 789 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 790 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 791 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 792 | } |
| 793 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 794 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 795 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 796 | } |
| 797 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 798 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 799 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| 800 | return GetPredecessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 804 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| 805 | return GetSuccessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // Returns whether the first occurrence of `predecessor` in the list of |
| 809 | // predecessors is at index `idx`. |
| 810 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetPredecessor(idx), predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 812 | return GetPredecessorIndexOf(predecessor) == idx; |
| 813 | } |
| 814 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 815 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 816 | // these are stored at the beginning of the successor list. |
| 817 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 818 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 819 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 820 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 821 | // Create a new block between this block and its predecessors. The new block |
| 822 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 823 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 824 | // loop and try/catch information are not updated. |
| 825 | HBasicBlock* CreateImmediateDominator(); |
| 826 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 828 | // created, latter block. Note that this method will add the block to the |
| 829 | // graph, create a Goto at the end of the former block and will create an edge |
| 830 | // between the blocks. It will not, however, update the reverse post order or |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 831 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 832 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 833 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 834 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 835 | // created block. Note that this method just updates raw block information, |
| 836 | // like predecessors, successors, dominators, and instruction list. It does not |
| 837 | // update the graph, reverse post order, loop information, nor make sure the |
| 838 | // blocks are consistent (for example ending with a control flow instruction). |
| 839 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 840 | |
| 841 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 842 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 843 | // that this method does not update the graph, reverse post order, loop |
| 844 | // information, nor make sure the blocks are consistent (for example ending |
| 845 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 846 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 847 | |
| 848 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 849 | // of `this` are moved to `other`. |
| 850 | // Note that this method does not update the graph, reverse post order, loop |
| 851 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 852 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 853 | void ReplaceWith(HBasicBlock* other); |
| 854 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 855 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 856 | // order, links to predecessors, successors, dominators and deletes the block |
| 857 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 858 | // predecessor of `other` and vice versa. |
| 859 | void MergeWith(HBasicBlock* other); |
| 860 | |
| 861 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 862 | // removes it from all loops it is included in and eventually from the graph. |
| 863 | // The block must not dominate any other block. Predecessors and successors |
| 864 | // are safely updated. |
| 865 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 866 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 867 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 868 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 869 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 870 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 871 | // Replace instruction `initial` with `replacement` within this block. |
| 872 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 873 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 874 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 875 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 876 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 877 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 878 | // instruction is not in use and removes it from the use lists of its inputs. |
| 879 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 880 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 881 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 882 | |
| 883 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 884 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 887 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 888 | DCHECK(IsLoopHeader()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 889 | return GetPredecessor(0) == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 890 | } |
| 891 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | HLoopInformation* GetLoopInformation() const { |
| 893 | return loop_information_; |
| 894 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 895 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 896 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 897 | // loop_information if it is an outer loop of the passed loop information. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 898 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 899 | void SetInLoop(HLoopInformation* info) { |
| 900 | if (IsLoopHeader()) { |
| 901 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 902 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 903 | loop_information_ = info; |
| 904 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 905 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 906 | // Note that a non loop header having a loop information means this loop information |
| 907 | // has already been populated |
| 908 | loop_information_ = info; |
| 909 | } else { |
| 910 | // Block is part of an inner loop. Do not update the loop information. |
| 911 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 912 | // at this point, because this method is being called while populating `info`. |
| 913 | } |
| 914 | } |
| 915 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 916 | // Raw update of the loop information. |
| 917 | void SetLoopInformation(HLoopInformation* info) { |
| 918 | loop_information_ = info; |
| 919 | } |
| 920 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 921 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 922 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 923 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 924 | |
| 925 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 926 | try_catch_information_ = try_catch_information; |
| 927 | } |
| 928 | |
| 929 | bool IsTryBlock() const { |
| 930 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 931 | } |
| 932 | |
| 933 | bool IsCatchBlock() const { |
| 934 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 935 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 936 | |
| 937 | // Returns the try entry that this block's successors should have. They will |
| 938 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 939 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 940 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 941 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 942 | bool HasThrowingInstructions() const; |
| 943 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 944 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 945 | bool Dominates(HBasicBlock* block) const; |
| 946 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 947 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 948 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 949 | |
| 950 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 951 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 952 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 953 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 954 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 955 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 956 | bool HasSinglePhi() const; |
| 957 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 958 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 959 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | ArenaVector<HBasicBlock*> predecessors_; |
| 961 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 962 | HInstructionList instructions_; |
| 963 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 964 | HLoopInformation* loop_information_; |
| 965 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 966 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 967 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 968 | // The dex program counter of the first instruction of this block. |
| 969 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 970 | size_t lifetime_start_; |
| 971 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 972 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 973 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 974 | friend class HGraph; |
| 975 | friend class HInstruction; |
| 976 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 977 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 978 | }; |
| 979 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 980 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 981 | // from the innermost to the outermost. |
| 982 | class HLoopInformationOutwardIterator : public ValueObject { |
| 983 | public: |
| 984 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 985 | : current_(block.GetLoopInformation()) {} |
| 986 | |
| 987 | bool Done() const { return current_ == nullptr; } |
| 988 | |
| 989 | void Advance() { |
| 990 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 991 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | HLoopInformation* Current() const { |
| 995 | DCHECK(!Done()); |
| 996 | return current_; |
| 997 | } |
| 998 | |
| 999 | private: |
| 1000 | HLoopInformation* current_; |
| 1001 | |
| 1002 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1003 | }; |
| 1004 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1005 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1006 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1007 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1008 | M(ArrayGet, Instruction) \ |
| 1009 | M(ArrayLength, Instruction) \ |
| 1010 | M(ArraySet, Instruction) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1011 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1012 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1013 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1014 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1015 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1016 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1017 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1019 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1020 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1021 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1022 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1023 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1024 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1025 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1026 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1027 | M(FloatConstant, Constant) \ |
| 1028 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1029 | M(GreaterThan, Condition) \ |
| 1030 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1031 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1032 | M(InstanceFieldGet, Instruction) \ |
| 1033 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1034 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1035 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1036 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1037 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1038 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1039 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1040 | M(LessThan, Condition) \ |
| 1041 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1042 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1043 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1044 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1045 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1046 | M(Local, Instruction) \ |
| 1047 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1048 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1049 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1050 | M(Mul, BinaryOperation) \ |
| 1051 | M(Neg, UnaryOperation) \ |
| 1052 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1054 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1055 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1056 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1057 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1058 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1059 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1060 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1061 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1062 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1063 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1064 | M(Return, Instruction) \ |
| 1065 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1066 | M(Shl, BinaryOperation) \ |
| 1067 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1068 | M(StaticFieldGet, Instruction) \ |
| 1069 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1070 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1071 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1072 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1073 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1074 | M(StoreLocal, Instruction) \ |
| 1075 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1076 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1077 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1078 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1079 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1080 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1081 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1082 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1083 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1084 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1085 | |
| 1086 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1087 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1088 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1089 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1090 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1091 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1092 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1093 | |
| 1094 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1095 | |
| 1096 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1097 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1098 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1099 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1100 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1101 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1102 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1103 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1104 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1105 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1106 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1107 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1108 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1109 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1110 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1111 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1112 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1113 | #undef FORWARD_DECLARATION |
| 1114 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1115 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1116 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1117 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1118 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1119 | H##type* As##type() OVERRIDE { return this; } \ |
| 1120 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1121 | return other->Is##type(); \ |
| 1122 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1123 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1124 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1125 | template <typename T> class HUseList; |
| 1126 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1127 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1128 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1129 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1130 | HUseListNode* GetPrevious() const { return prev_; } |
| 1131 | HUseListNode* GetNext() const { return next_; } |
| 1132 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1133 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1134 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1135 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1136 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1137 | HUseListNode(T user, size_t index) |
| 1138 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1139 | |
| 1140 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1141 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1142 | HUseListNode<T>* prev_; |
| 1143 | HUseListNode<T>* next_; |
| 1144 | |
| 1145 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1146 | |
| 1147 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1148 | }; |
| 1149 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1150 | template <typename T> |
| 1151 | class HUseList : public ValueObject { |
| 1152 | public: |
| 1153 | HUseList() : first_(nullptr) {} |
| 1154 | |
| 1155 | void Clear() { |
| 1156 | first_ = nullptr; |
| 1157 | } |
| 1158 | |
| 1159 | // Adds a new entry at the beginning of the use list and returns |
| 1160 | // the newly created node. |
| 1161 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1162 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1163 | if (IsEmpty()) { |
| 1164 | first_ = new_node; |
| 1165 | } else { |
| 1166 | first_->prev_ = new_node; |
| 1167 | new_node->next_ = first_; |
| 1168 | first_ = new_node; |
| 1169 | } |
| 1170 | return new_node; |
| 1171 | } |
| 1172 | |
| 1173 | HUseListNode<T>* GetFirst() const { |
| 1174 | return first_; |
| 1175 | } |
| 1176 | |
| 1177 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1178 | DCHECK(node != nullptr); |
| 1179 | DCHECK(Contains(node)); |
| 1180 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1181 | if (node->prev_ != nullptr) { |
| 1182 | node->prev_->next_ = node->next_; |
| 1183 | } |
| 1184 | if (node->next_ != nullptr) { |
| 1185 | node->next_->prev_ = node->prev_; |
| 1186 | } |
| 1187 | if (node == first_) { |
| 1188 | first_ = node->next_; |
| 1189 | } |
| 1190 | } |
| 1191 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1192 | bool Contains(const HUseListNode<T>* node) const { |
| 1193 | if (node == nullptr) { |
| 1194 | return false; |
| 1195 | } |
| 1196 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1197 | if (current == node) { |
| 1198 | return true; |
| 1199 | } |
| 1200 | } |
| 1201 | return false; |
| 1202 | } |
| 1203 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1204 | bool IsEmpty() const { |
| 1205 | return first_ == nullptr; |
| 1206 | } |
| 1207 | |
| 1208 | bool HasOnlyOneUse() const { |
| 1209 | return first_ != nullptr && first_->next_ == nullptr; |
| 1210 | } |
| 1211 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1212 | size_t SizeSlow() const { |
| 1213 | size_t count = 0; |
| 1214 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1215 | ++count; |
| 1216 | } |
| 1217 | return count; |
| 1218 | } |
| 1219 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1220 | private: |
| 1221 | HUseListNode<T>* first_; |
| 1222 | }; |
| 1223 | |
| 1224 | template<typename T> |
| 1225 | class HUseIterator : public ValueObject { |
| 1226 | public: |
| 1227 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1228 | |
| 1229 | bool Done() const { return current_ == nullptr; } |
| 1230 | |
| 1231 | void Advance() { |
| 1232 | DCHECK(!Done()); |
| 1233 | current_ = current_->GetNext(); |
| 1234 | } |
| 1235 | |
| 1236 | HUseListNode<T>* Current() const { |
| 1237 | DCHECK(!Done()); |
| 1238 | return current_; |
| 1239 | } |
| 1240 | |
| 1241 | private: |
| 1242 | HUseListNode<T>* current_; |
| 1243 | |
| 1244 | friend class HValue; |
| 1245 | }; |
| 1246 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1247 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1248 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1249 | // by the used instructions. |
| 1250 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1251 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1252 | public: |
| 1253 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1254 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1255 | |
| 1256 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1257 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1258 | DCHECK(instruction_ != nullptr); |
| 1259 | DCHECK(use_node_ != nullptr); |
| 1260 | DCHECK(old_record.use_node_ == nullptr); |
| 1261 | } |
| 1262 | |
| 1263 | HInstruction* GetInstruction() const { return instruction_; } |
| 1264 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1265 | |
| 1266 | private: |
| 1267 | // Instruction used by the user. |
| 1268 | HInstruction* instruction_; |
| 1269 | |
| 1270 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1271 | HUseListNode<T>* use_node_; |
| 1272 | }; |
| 1273 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1274 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1275 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1276 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1277 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1278 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1279 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1280 | * modify the value of a reference field read [although it may modify the |
| 1281 | * reference fetch prior to reading the field, which is represented by its own |
| 1282 | * write/read dependence]). The analysis makes conservative points-to |
| 1283 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1284 | * the same, and any reference read depends on any reference read without |
| 1285 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1286 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1287 | * The internal representation uses 38-bit and is described in the table below. |
| 1288 | * The first line indicates the side effect, and for field/array accesses the |
| 1289 | * second line indicates the type of the access (in the order of the |
| 1290 | * Primitive::Type enum). |
| 1291 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1292 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1293 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1294 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1295 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1296 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1297 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1298 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1299 | * |
| 1300 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1301 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1302 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1303 | class SideEffects : public ValueObject { |
| 1304 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1305 | SideEffects() : flags_(0) {} |
| 1306 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1307 | static SideEffects None() { |
| 1308 | return SideEffects(0); |
| 1309 | } |
| 1310 | |
| 1311 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1312 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1313 | } |
| 1314 | |
| 1315 | static SideEffects AllChanges() { |
| 1316 | return SideEffects(kAllChangeBits); |
| 1317 | } |
| 1318 | |
| 1319 | static SideEffects AllDependencies() { |
| 1320 | return SideEffects(kAllDependOnBits); |
| 1321 | } |
| 1322 | |
| 1323 | static SideEffects AllExceptGCDependency() { |
| 1324 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1325 | } |
| 1326 | |
| 1327 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1328 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1329 | } |
| 1330 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1331 | static SideEffects AllWrites() { |
| 1332 | return SideEffects(kAllWrites); |
| 1333 | } |
| 1334 | |
| 1335 | static SideEffects AllReads() { |
| 1336 | return SideEffects(kAllReads); |
| 1337 | } |
| 1338 | |
| 1339 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1340 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1341 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1342 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1345 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1346 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1347 | } |
| 1348 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1349 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1350 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1351 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1352 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1353 | } |
| 1354 | |
| 1355 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1356 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1357 | } |
| 1358 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1359 | static SideEffects CanTriggerGC() { |
| 1360 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1361 | } |
| 1362 | |
| 1363 | static SideEffects DependsOnGC() { |
| 1364 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1365 | } |
| 1366 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1367 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1368 | SideEffects Union(SideEffects other) const { |
| 1369 | return SideEffects(flags_ | other.flags_); |
| 1370 | } |
| 1371 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1372 | SideEffects Exclusion(SideEffects other) const { |
| 1373 | return SideEffects(flags_ & ~other.flags_); |
| 1374 | } |
| 1375 | |
| 1376 | bool Includes(SideEffects other) const { |
| 1377 | return (other.flags_ & flags_) == other.flags_; |
| 1378 | } |
| 1379 | |
| 1380 | bool HasSideEffects() const { |
| 1381 | return (flags_ & kAllChangeBits); |
| 1382 | } |
| 1383 | |
| 1384 | bool HasDependencies() const { |
| 1385 | return (flags_ & kAllDependOnBits); |
| 1386 | } |
| 1387 | |
| 1388 | // Returns true if there are no side effects or dependencies. |
| 1389 | bool DoesNothing() const { |
| 1390 | return flags_ == 0; |
| 1391 | } |
| 1392 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1393 | // Returns true if something is written. |
| 1394 | bool DoesAnyWrite() const { |
| 1395 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1398 | // Returns true if something is read. |
| 1399 | bool DoesAnyRead() const { |
| 1400 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1401 | } |
| 1402 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1403 | // Returns true if potentially everything is written and read |
| 1404 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1405 | bool DoesAllReadWrite() const { |
| 1406 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1407 | } |
| 1408 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1409 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1410 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | // Returns true if this may read something written by other. |
| 1414 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1415 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1416 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1417 | } |
| 1418 | |
| 1419 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1420 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1421 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1422 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1423 | for (int s = kLastBit; s >= 0; s--) { |
| 1424 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1425 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1426 | // This is a bit for the GC side effect. |
| 1427 | if (current_bit_is_set) { |
| 1428 | flags += "GC"; |
| 1429 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1430 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1431 | } else { |
| 1432 | // This is a bit for the array/field analysis. |
| 1433 | // The underscore character stands for the 'can trigger GC' bit. |
| 1434 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1435 | if (current_bit_is_set) { |
| 1436 | flags += kDebug[s]; |
| 1437 | } |
| 1438 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1439 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1440 | flags += "|"; |
| 1441 | } |
| 1442 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1443 | } |
| 1444 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1445 | } |
| 1446 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1447 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1448 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1449 | private: |
| 1450 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1451 | |
| 1452 | static constexpr int kFieldWriteOffset = 0; |
| 1453 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1454 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1455 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1456 | |
| 1457 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1458 | |
| 1459 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1460 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1461 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1462 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1463 | |
| 1464 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1465 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1466 | |
| 1467 | // Aliases. |
| 1468 | |
| 1469 | static_assert(kChangeBits == kDependOnBits, |
| 1470 | "the 'change' bits should match the 'depend on' bits."); |
| 1471 | |
| 1472 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1473 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1474 | static constexpr uint64_t kAllWrites = |
| 1475 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1476 | static constexpr uint64_t kAllReads = |
| 1477 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1478 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1479 | // Work around the fact that HIR aliases I/F and J/D. |
| 1480 | // TODO: remove this interceptor once HIR types are clean |
| 1481 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1482 | switch (type) { |
| 1483 | case Primitive::kPrimInt: |
| 1484 | case Primitive::kPrimFloat: |
| 1485 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1486 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1487 | case Primitive::kPrimLong: |
| 1488 | case Primitive::kPrimDouble: |
| 1489 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1490 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1491 | default: |
| 1492 | return TypeFlag(type, offset); |
| 1493 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1494 | } |
| 1495 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1496 | // Translates type to bit flag. |
| 1497 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1498 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1499 | const uint64_t one = 1; |
| 1500 | const int shift = type; // 0-based consecutive enum |
| 1501 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1502 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1503 | return one << (type + offset); |
| 1504 | } |
| 1505 | |
| 1506 | // Private constructor on direct flags value. |
| 1507 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1508 | |
| 1509 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1510 | }; |
| 1511 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1512 | // A HEnvironment object contains the values of virtual registers at a given location. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1513 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1514 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1515 | HEnvironment(ArenaAllocator* arena, |
| 1516 | size_t number_of_vregs, |
| 1517 | const DexFile& dex_file, |
| 1518 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1519 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1520 | InvokeType invoke_type, |
| 1521 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1522 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1523 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1524 | parent_(nullptr), |
| 1525 | dex_file_(dex_file), |
| 1526 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1527 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1528 | invoke_type_(invoke_type), |
| 1529 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1530 | } |
| 1531 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1532 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1533 | : HEnvironment(arena, |
| 1534 | to_copy.Size(), |
| 1535 | to_copy.GetDexFile(), |
| 1536 | to_copy.GetMethodIdx(), |
| 1537 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1538 | to_copy.GetInvokeType(), |
| 1539 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1540 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1541 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1542 | if (parent_ != nullptr) { |
| 1543 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1544 | } else { |
| 1545 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1546 | parent_->CopyFrom(parent); |
| 1547 | if (parent->GetParent() != nullptr) { |
| 1548 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1549 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1550 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1551 | } |
| 1552 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1553 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1554 | void CopyFrom(HEnvironment* environment); |
| 1555 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1556 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1557 | // input to the loop phi instead. This is for inserting instructions that |
| 1558 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1559 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1560 | |
| 1561 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1562 | DCHECK_LT(index, Size()); |
| 1563 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
| 1566 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1567 | DCHECK_LT(index, Size()); |
| 1568 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1569 | } |
| 1570 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1571 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1572 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1573 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1574 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1575 | HEnvironment* GetParent() const { return parent_; } |
| 1576 | |
| 1577 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1578 | DCHECK_LT(index, Size()); |
| 1579 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1583 | DCHECK_LT(index, Size()); |
| 1584 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | uint32_t GetDexPc() const { |
| 1588 | return dex_pc_; |
| 1589 | } |
| 1590 | |
| 1591 | uint32_t GetMethodIdx() const { |
| 1592 | return method_idx_; |
| 1593 | } |
| 1594 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1595 | InvokeType GetInvokeType() const { |
| 1596 | return invoke_type_; |
| 1597 | } |
| 1598 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1599 | const DexFile& GetDexFile() const { |
| 1600 | return dex_file_; |
| 1601 | } |
| 1602 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1603 | HInstruction* GetHolder() const { |
| 1604 | return holder_; |
| 1605 | } |
| 1606 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1607 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1608 | // Record instructions' use entries of this environment for constant-time removal. |
| 1609 | // It should only be called by HInstruction when a new environment use is added. |
| 1610 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1611 | DCHECK(env_use->GetUser() == this); |
| 1612 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1613 | DCHECK_LT(index, Size()); |
| 1614 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1615 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1616 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1617 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1618 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1619 | HEnvironment* parent_; |
| 1620 | const DexFile& dex_file_; |
| 1621 | const uint32_t method_idx_; |
| 1622 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1623 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1624 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1625 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1626 | HInstruction* const holder_; |
| 1627 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1628 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1629 | |
| 1630 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1631 | }; |
| 1632 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1633 | class ReferenceTypeInfo : ValueObject { |
| 1634 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1635 | typedef Handle<mirror::Class> TypeHandle; |
| 1636 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1637 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1638 | // The constructor will check that the type_handle is valid. |
| 1639 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1642 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1643 | |
| 1644 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1645 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1648 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1649 | return IsValidHandle(type_handle_); |
| 1650 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1651 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1652 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1653 | |
| 1654 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1655 | DCHECK(IsValid()); |
| 1656 | return GetTypeHandle()->IsObjectClass(); |
| 1657 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1658 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1659 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 1660 | DCHECK(IsValid()); |
| 1661 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1662 | } |
| 1663 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1664 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1665 | DCHECK(IsValid()); |
| 1666 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1667 | } |
| 1668 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1669 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1670 | DCHECK(IsValid()); |
| 1671 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1672 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1673 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1674 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 1675 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1676 | return GetTypeHandle()->IsArrayClass(); |
| 1677 | } |
| 1678 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 1679 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1680 | DCHECK(IsValid()); |
| 1681 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1682 | } |
| 1683 | |
| 1684 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1685 | DCHECK(IsValid()); |
| 1686 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1687 | } |
| 1688 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1689 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 1690 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1691 | if (!IsExact()) return false; |
| 1692 | if (!IsArrayClass()) return false; |
| 1693 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1694 | } |
| 1695 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 1696 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1697 | DCHECK(IsValid()); |
| 1698 | if (!IsExact()) return false; |
| 1699 | if (!IsArrayClass()) return false; |
| 1700 | if (!rti.IsArrayClass()) return false; |
| 1701 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1702 | rti.GetTypeHandle()->GetComponentType()); |
| 1703 | } |
| 1704 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1705 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1706 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1707 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1708 | DCHECK(IsValid()); |
| 1709 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1710 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1711 | } |
| 1712 | |
| 1713 | // Returns true if the type information provide the same amount of details. |
| 1714 | // Note that it does not mean that the instructions have the same actual type |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1715 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1716 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1717 | if (!IsValid() && !rti.IsValid()) { |
| 1718 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1719 | return true; |
| 1720 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1721 | if (!IsValid() || !rti.IsValid()) { |
| 1722 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1723 | return false; |
| 1724 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1725 | return IsExact() == rti.IsExact() |
| 1726 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1727 | } |
| 1728 | |
| 1729 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1730 | ReferenceTypeInfo(); |
| 1731 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1732 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1733 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1734 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1735 | // Whether or not the type is exact or a superclass of the actual type. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1736 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1737 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1738 | }; |
| 1739 | |
| 1740 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1741 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1742 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1743 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1744 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1745 | : previous_(nullptr), |
| 1746 | next_(nullptr), |
| 1747 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1748 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1749 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1750 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1751 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1752 | locations_(nullptr), |
| 1753 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1754 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1755 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1756 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1757 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1758 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1759 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1760 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1761 | enum InstructionKind { |
| 1762 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1763 | }; |
| 1764 | #undef DECLARE_KIND |
| 1765 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1766 | HInstruction* GetNext() const { return next_; } |
| 1767 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1768 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1769 | HInstruction* GetNextDisregardingMoves() const; |
| 1770 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1771 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1772 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1773 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1774 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1775 | bool IsInBlock() const { return block_ != nullptr; } |
| 1776 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1777 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1778 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1779 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1780 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1781 | |
| 1782 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1783 | virtual const char* DebugName() const = 0; |
| 1784 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1785 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1786 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1787 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1788 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1789 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1790 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1791 | |
| 1792 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1793 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1794 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1795 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1796 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1797 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1798 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1799 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1800 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1801 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1802 | // Does not apply for all instructions, but having this at top level greatly |
| 1803 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1804 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1805 | virtual bool CanBeNull() const { |
| 1806 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1807 | return true; |
| 1808 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1809 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1810 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1811 | UNUSED(obj); |
| 1812 | return false; |
| 1813 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1814 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1815 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1816 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1817 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1818 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1819 | return reference_type_info_; |
| 1820 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1821 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1822 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1823 | DCHECK(user != nullptr); |
| 1824 | HUseListNode<HInstruction*>* use = |
| 1825 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1826 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1827 | } |
| 1828 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1829 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1830 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1831 | HUseListNode<HEnvironment*>* env_use = |
| 1832 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1833 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1834 | } |
| 1835 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1836 | void RemoveAsUserOfInput(size_t input) { |
| 1837 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1838 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1839 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1840 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1841 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1842 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1843 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1844 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1845 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1846 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1847 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1848 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1849 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1850 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1851 | // Does this instruction strictly dominate `other_instruction`? |
| 1852 | // Returns false if this instruction and `other_instruction` are the same. |
| 1853 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1854 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1855 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1856 | int GetId() const { return id_; } |
| 1857 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1858 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1859 | int GetSsaIndex() const { return ssa_index_; } |
| 1860 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1861 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1862 | |
| 1863 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1864 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1865 | // Set the `environment_` field. Raw because this method does not |
| 1866 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1867 | void SetRawEnvironment(HEnvironment* environment) { |
| 1868 | DCHECK(environment_ == nullptr); |
| 1869 | DCHECK_EQ(environment->GetHolder(), this); |
| 1870 | environment_ = environment; |
| 1871 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1872 | |
| 1873 | // Set the environment of this instruction, copying it from `environment`. While |
| 1874 | // copying, the uses lists are being updated. |
| 1875 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1876 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1877 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1878 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1879 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1880 | if (environment->GetParent() != nullptr) { |
| 1881 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1882 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1883 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1884 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1885 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1886 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1887 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1888 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1889 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1890 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1891 | if (environment->GetParent() != nullptr) { |
| 1892 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1893 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1896 | // Returns the number of entries in the environment. Typically, that is the |
| 1897 | // number of dex registers in a method. It could be more in case of inlining. |
| 1898 | size_t EnvironmentSize() const; |
| 1899 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1900 | LocationSummary* GetLocations() const { return locations_; } |
| 1901 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1902 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1903 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1904 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1905 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1906 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1907 | // uses of this instruction by `other` are *not* updated. |
| 1908 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1909 | ReplaceWith(other); |
| 1910 | other->ReplaceInput(this, use_index); |
| 1911 | } |
| 1912 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1913 | // Move `this` instruction before `cursor`. |
| 1914 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1915 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1916 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1917 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1918 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1919 | virtual H##type* As##type() { return nullptr; } |
| 1920 | |
| 1921 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1922 | #undef INSTRUCTION_TYPE_CHECK |
| 1923 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1924 | // Returns whether the instruction can be moved within the graph. |
| 1925 | virtual bool CanBeMoved() const { return false; } |
| 1926 | |
| 1927 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1928 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1929 | UNUSED(other); |
| 1930 | return false; |
| 1931 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1932 | |
| 1933 | // Returns whether any data encoded in the two instructions is equal. |
| 1934 | // This method does not look at the inputs. Both instructions must be |
| 1935 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1936 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1937 | UNUSED(other); |
| 1938 | return false; |
| 1939 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1940 | |
| 1941 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1942 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1943 | // 2) Their inputs are identical. |
| 1944 | bool Equals(HInstruction* other) const; |
| 1945 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1946 | virtual InstructionKind GetKind() const = 0; |
| 1947 | |
| 1948 | virtual size_t ComputeHashCode() const { |
| 1949 | size_t result = GetKind(); |
| 1950 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1951 | result = (result * 31) + InputAt(i)->GetId(); |
| 1952 | } |
| 1953 | return result; |
| 1954 | } |
| 1955 | |
| 1956 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1957 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1958 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1959 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1960 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1961 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1962 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1963 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1964 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1965 | |
| 1966 | // Returns whether the code generation of the instruction will require to have access |
| 1967 | // to the current method. Such instructions are: |
| 1968 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1969 | // to walk the stack and have the current method stored at a specific stack address. |
| 1970 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1971 | // fields of the current method. |
| 1972 | bool NeedsCurrentMethod() const { |
| 1973 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1974 | } |
| 1975 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1976 | virtual bool NeedsDexCache() const { return false; } |
| 1977 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1978 | // Does this instruction have any use in an environment before |
| 1979 | // control flow hits 'other'? |
| 1980 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1981 | |
| 1982 | // Remove all references to environment uses of this instruction. |
| 1983 | // The caller must ensure that this is safe to do. |
| 1984 | void RemoveEnvironmentUsers(); |
| 1985 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1986 | protected: |
| 1987 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1988 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1989 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1990 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1991 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1992 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1993 | HInstruction* previous_; |
| 1994 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1995 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1996 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1997 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1998 | // An instruction gets an id when it is added to the graph. |
| 1999 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2000 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2001 | int id_; |
| 2002 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2003 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2004 | int ssa_index_; |
| 2005 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2006 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2007 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2008 | |
| 2009 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2010 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2011 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2012 | // The environment associated with this instruction. Not null if the instruction |
| 2013 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2014 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2015 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2016 | // Set by the code generator. |
| 2017 | LocationSummary* locations_; |
| 2018 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2019 | // Set by the liveness analysis. |
| 2020 | LiveInterval* live_interval_; |
| 2021 | |
| 2022 | // Set by the liveness analysis, this is the position in a linear |
| 2023 | // order of blocks where this instruction's live interval start. |
| 2024 | size_t lifetime_position_; |
| 2025 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2026 | const SideEffects side_effects_; |
| 2027 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2028 | // TODO: for primitive types this should be marked as invalid. |
| 2029 | ReferenceTypeInfo reference_type_info_; |
| 2030 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2031 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2032 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2033 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2034 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2035 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2036 | |
| 2037 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2038 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2039 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2040 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2041 | class HInputIterator : public ValueObject { |
| 2042 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2043 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2044 | |
| 2045 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2046 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2047 | void Advance() { index_++; } |
| 2048 | |
| 2049 | private: |
| 2050 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2051 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2052 | |
| 2053 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2054 | }; |
| 2055 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2056 | class HInstructionIterator : public ValueObject { |
| 2057 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2058 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2059 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2060 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2061 | } |
| 2062 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2063 | bool Done() const { return instruction_ == nullptr; } |
| 2064 | HInstruction* Current() const { return instruction_; } |
| 2065 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2066 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2067 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
| 2070 | private: |
| 2071 | HInstruction* instruction_; |
| 2072 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2073 | |
| 2074 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2075 | }; |
| 2076 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2077 | class HBackwardInstructionIterator : public ValueObject { |
| 2078 | public: |
| 2079 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2080 | : instruction_(instructions.last_instruction_) { |
| 2081 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2082 | } |
| 2083 | |
| 2084 | bool Done() const { return instruction_ == nullptr; } |
| 2085 | HInstruction* Current() const { return instruction_; } |
| 2086 | void Advance() { |
| 2087 | instruction_ = next_; |
| 2088 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2089 | } |
| 2090 | |
| 2091 | private: |
| 2092 | HInstruction* instruction_; |
| 2093 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2094 | |
| 2095 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2096 | }; |
| 2097 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2098 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2099 | class HTemplateInstruction: public HInstruction { |
| 2100 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2101 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2102 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2103 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2104 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2105 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2106 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2107 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2108 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2109 | DCHECK_LT(i, N); |
| 2110 | return inputs_[i]; |
| 2111 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2112 | |
| 2113 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2114 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2115 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2116 | } |
| 2117 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2118 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2119 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2120 | |
| 2121 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2122 | }; |
| 2123 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2124 | // HTemplateInstruction specialization for N=0. |
| 2125 | template<> |
| 2126 | class HTemplateInstruction<0>: public HInstruction { |
| 2127 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2128 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2129 | : HInstruction(side_effects, dex_pc) {} |
| 2130 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2131 | virtual ~HTemplateInstruction() {} |
| 2132 | |
| 2133 | size_t InputCount() const OVERRIDE { return 0; } |
| 2134 | |
| 2135 | protected: |
| 2136 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2137 | LOG(FATAL) << "Unreachable"; |
| 2138 | UNREACHABLE(); |
| 2139 | } |
| 2140 | |
| 2141 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2142 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2143 | LOG(FATAL) << "Unreachable"; |
| 2144 | UNREACHABLE(); |
| 2145 | } |
| 2146 | |
| 2147 | private: |
| 2148 | friend class SsaBuilder; |
| 2149 | }; |
| 2150 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2151 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2152 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2153 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2154 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2155 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2156 | virtual ~HExpression() {} |
| 2157 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2158 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2159 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2160 | protected: |
| 2161 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2162 | }; |
| 2163 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2164 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2165 | // instruction that branches to the exit block. |
| 2166 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2167 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2168 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2169 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2170 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2171 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2172 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2173 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2174 | |
| 2175 | private: |
| 2176 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2177 | }; |
| 2178 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2179 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2180 | // instruction that branches to the exit block. |
| 2181 | class HReturn : public HTemplateInstruction<1> { |
| 2182 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2183 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2184 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2185 | SetRawInputAt(0, value); |
| 2186 | } |
| 2187 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2188 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2189 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2190 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2191 | |
| 2192 | private: |
| 2193 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2194 | }; |
| 2195 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2196 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2197 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2198 | // exit block. |
| 2199 | class HExit : public HTemplateInstruction<0> { |
| 2200 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2201 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2202 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2203 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2204 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2205 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2206 | |
| 2207 | private: |
| 2208 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2209 | }; |
| 2210 | |
| 2211 | // Jumps from one block to another. |
| 2212 | class HGoto : public HTemplateInstruction<0> { |
| 2213 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2214 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2215 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2216 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2217 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2218 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2219 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2220 | } |
| 2221 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2222 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2223 | |
| 2224 | private: |
| 2225 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2226 | }; |
| 2227 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2228 | class HConstant : public HExpression<0> { |
| 2229 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2230 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2231 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2232 | |
| 2233 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2234 | |
| 2235 | virtual bool IsMinusOne() const { return false; } |
| 2236 | virtual bool IsZero() const { return false; } |
| 2237 | virtual bool IsOne() const { return false; } |
| 2238 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2239 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2240 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2241 | DECLARE_INSTRUCTION(Constant); |
| 2242 | |
| 2243 | private: |
| 2244 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2245 | }; |
| 2246 | |
| 2247 | class HNullConstant : public HConstant { |
| 2248 | public: |
| 2249 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2250 | return true; |
| 2251 | } |
| 2252 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2253 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2254 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2255 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2256 | |
| 2257 | DECLARE_INSTRUCTION(NullConstant); |
| 2258 | |
| 2259 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2260 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2261 | |
| 2262 | friend class HGraph; |
| 2263 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2264 | }; |
| 2265 | |
| 2266 | // Constants of the type int. Those can be from Dex instructions, or |
| 2267 | // synthesized (for example with the if-eqz instruction). |
| 2268 | class HIntConstant : public HConstant { |
| 2269 | public: |
| 2270 | int32_t GetValue() const { return value_; } |
| 2271 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2272 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2273 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2274 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2275 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2276 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2277 | DCHECK(other->IsIntConstant()); |
| 2278 | return other->AsIntConstant()->value_ == value_; |
| 2279 | } |
| 2280 | |
| 2281 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2282 | |
| 2283 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2284 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2285 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2286 | |
| 2287 | DECLARE_INSTRUCTION(IntConstant); |
| 2288 | |
| 2289 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2290 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2291 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2292 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2293 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2294 | |
| 2295 | const int32_t value_; |
| 2296 | |
| 2297 | friend class HGraph; |
| 2298 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2299 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2300 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2301 | }; |
| 2302 | |
| 2303 | class HLongConstant : public HConstant { |
| 2304 | public: |
| 2305 | int64_t GetValue() const { return value_; } |
| 2306 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2307 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2308 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2309 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2310 | DCHECK(other->IsLongConstant()); |
| 2311 | return other->AsLongConstant()->value_ == value_; |
| 2312 | } |
| 2313 | |
| 2314 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2315 | |
| 2316 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2317 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2318 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2319 | |
| 2320 | DECLARE_INSTRUCTION(LongConstant); |
| 2321 | |
| 2322 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2323 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2324 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2325 | |
| 2326 | const int64_t value_; |
| 2327 | |
| 2328 | friend class HGraph; |
| 2329 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2330 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2331 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2332 | // Conditional branch. A block ending with an HIf instruction must have |
| 2333 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2334 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2335 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2336 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2337 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2338 | SetRawInputAt(0, input); |
| 2339 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2340 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2341 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2342 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2343 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2344 | return GetBlock()->GetSuccessor(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2345 | } |
| 2346 | |
| 2347 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2348 | return GetBlock()->GetSuccessor(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2351 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2352 | |
| 2353 | private: |
| 2354 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2355 | }; |
| 2356 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2357 | |
| 2358 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2359 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2360 | // non-exceptional control flow. |
| 2361 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2362 | // higher indices in no particular order. |
| 2363 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2364 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2365 | enum BoundaryKind { |
| 2366 | kEntry, |
| 2367 | kExit, |
| 2368 | }; |
| 2369 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2370 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2371 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2372 | |
| 2373 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2374 | |
| 2375 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2376 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessor(0); } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2377 | |
| 2378 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2379 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2380 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2381 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2382 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2383 | } |
| 2384 | |
| 2385 | // If not present already, adds `handler` to its block's list of exception |
| 2386 | // handlers. |
| 2387 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2388 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2389 | GetBlock()->AddSuccessor(handler); |
| 2390 | } |
| 2391 | } |
| 2392 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2393 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2394 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2395 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2396 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2397 | DECLARE_INSTRUCTION(TryBoundary); |
| 2398 | |
| 2399 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2400 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2401 | |
| 2402 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2403 | }; |
| 2404 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2405 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2406 | // exceptional successors of its basic block. |
| 2407 | class HExceptionHandlerIterator : public ValueObject { |
| 2408 | public: |
| 2409 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2410 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2411 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2412 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
| 2413 | HBasicBlock* Current() const { return block_.GetSuccessor(index_); } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2414 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2415 | void Advance() { ++index_; } |
| 2416 | |
| 2417 | private: |
| 2418 | const HBasicBlock& block_; |
| 2419 | size_t index_; |
| 2420 | |
| 2421 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2422 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2423 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2424 | // Deoptimize to interpreter, upon checking a condition. |
| 2425 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2426 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2427 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2428 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2429 | SetRawInputAt(0, cond); |
| 2430 | } |
| 2431 | |
| 2432 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2433 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2434 | |
| 2435 | DECLARE_INSTRUCTION(Deoptimize); |
| 2436 | |
| 2437 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2438 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2439 | }; |
| 2440 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2441 | // Represents the ArtMethod that was passed as a first argument to |
| 2442 | // the method. It is used by instructions that depend on it, like |
| 2443 | // instructions that work with the dex cache. |
| 2444 | class HCurrentMethod : public HExpression<0> { |
| 2445 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2446 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2447 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2448 | |
| 2449 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2450 | |
| 2451 | private: |
| 2452 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2453 | }; |
| 2454 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2455 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2456 | // have one successor for each entry in the switch table, and the final successor |
| 2457 | // will be the block containing the next Dex opcode. |
| 2458 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2459 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2460 | HPackedSwitch(int32_t start_value, |
| 2461 | uint32_t num_entries, |
| 2462 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2463 | uint32_t dex_pc = kNoDexPc) |
| 2464 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2465 | start_value_(start_value), |
| 2466 | num_entries_(num_entries) { |
| 2467 | SetRawInputAt(0, input); |
| 2468 | } |
| 2469 | |
| 2470 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2471 | |
| 2472 | int32_t GetStartValue() const { return start_value_; } |
| 2473 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2474 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2475 | |
| 2476 | HBasicBlock* GetDefaultBlock() const { |
| 2477 | // Last entry is the default block. |
| 2478 | return GetBlock()->GetSuccessor(num_entries_); |
| 2479 | } |
| 2480 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2481 | |
| 2482 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2483 | const int32_t start_value_; |
| 2484 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2485 | |
| 2486 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2487 | }; |
| 2488 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2489 | class HUnaryOperation : public HExpression<1> { |
| 2490 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2491 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2492 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2493 | SetRawInputAt(0, input); |
| 2494 | } |
| 2495 | |
| 2496 | HInstruction* GetInput() const { return InputAt(0); } |
| 2497 | Primitive::Type GetResultType() const { return GetType(); } |
| 2498 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2499 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2500 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2501 | UNUSED(other); |
| 2502 | return true; |
| 2503 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2504 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2505 | // Try to statically evaluate `operation` and return a HConstant |
| 2506 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2507 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2508 | HConstant* TryStaticEvaluation() const; |
| 2509 | |
| 2510 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2511 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2512 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2513 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2514 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2515 | |
| 2516 | private: |
| 2517 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2518 | }; |
| 2519 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2520 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2521 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2522 | HBinaryOperation(Primitive::Type result_type, |
| 2523 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2524 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2525 | SideEffects side_effects = SideEffects::None(), |
| 2526 | uint32_t dex_pc = kNoDexPc) |
| 2527 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2528 | SetRawInputAt(0, left); |
| 2529 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2530 | } |
| 2531 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2532 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2533 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2534 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2535 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2536 | virtual bool IsCommutative() const { return false; } |
| 2537 | |
| 2538 | // Put constant on the right. |
| 2539 | // Returns whether order is changed. |
| 2540 | bool OrderInputsWithConstantOnTheRight() { |
| 2541 | HInstruction* left = InputAt(0); |
| 2542 | HInstruction* right = InputAt(1); |
| 2543 | if (left->IsConstant() && !right->IsConstant()) { |
| 2544 | ReplaceInput(right, 0); |
| 2545 | ReplaceInput(left, 1); |
| 2546 | return true; |
| 2547 | } |
| 2548 | return false; |
| 2549 | } |
| 2550 | |
| 2551 | // Order inputs by instruction id, but favor constant on the right side. |
| 2552 | // This helps GVN for commutative ops. |
| 2553 | void OrderInputs() { |
| 2554 | DCHECK(IsCommutative()); |
| 2555 | HInstruction* left = InputAt(0); |
| 2556 | HInstruction* right = InputAt(1); |
| 2557 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2558 | return; |
| 2559 | } |
| 2560 | if (OrderInputsWithConstantOnTheRight()) { |
| 2561 | return; |
| 2562 | } |
| 2563 | // Order according to instruction id. |
| 2564 | if (left->GetId() > right->GetId()) { |
| 2565 | ReplaceInput(right, 0); |
| 2566 | ReplaceInput(left, 1); |
| 2567 | } |
| 2568 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2569 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2570 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2571 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2572 | UNUSED(other); |
| 2573 | return true; |
| 2574 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2575 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2576 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2577 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2578 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2579 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2580 | |
| 2581 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2582 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2583 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2584 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2585 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2586 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2587 | return nullptr; |
| 2588 | } |
| 2589 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2590 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2591 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2592 | return nullptr; |
| 2593 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2594 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2595 | // Returns an input that can legally be used as the right input and is |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2596 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2597 | HConstant* GetConstantRight() const; |
| 2598 | |
| 2599 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2600 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2601 | HInstruction* GetLeastConstantLeft() const; |
| 2602 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2603 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2604 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2605 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2606 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2607 | }; |
| 2608 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2609 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2610 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2611 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2612 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2613 | kGtBias, // return 1 for NaN comparisons |
| 2614 | kLtBias, // return -1 for NaN comparisons |
| 2615 | }; |
| 2616 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2617 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2618 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2619 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2620 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2621 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2622 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2623 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2624 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2625 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2626 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2627 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2628 | // `instruction`, and disregard moves in between. |
| 2629 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2630 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2631 | DECLARE_INSTRUCTION(Condition); |
| 2632 | |
| 2633 | virtual IfCondition GetCondition() const = 0; |
| 2634 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2635 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2636 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2637 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2638 | |
| 2639 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2640 | |
| 2641 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2642 | return bias_ == other->AsCondition()->bias_; |
| 2643 | } |
| 2644 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2645 | bool IsFPConditionTrueIfNaN() const { |
| 2646 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2647 | IfCondition if_cond = GetCondition(); |
| 2648 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2649 | } |
| 2650 | |
| 2651 | bool IsFPConditionFalseIfNaN() const { |
| 2652 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2653 | IfCondition if_cond = GetCondition(); |
| 2654 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2655 | } |
| 2656 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2657 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2658 | // For register allocation purposes, returns whether this instruction needs to be |
| 2659 | // materialized (that is, not just be in the processor flags). |
| 2660 | bool needs_materialization_; |
| 2661 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2662 | // Needed if we merge a HCompare into a HCondition. |
| 2663 | ComparisonBias bias_; |
| 2664 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2665 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2666 | }; |
| 2667 | |
| 2668 | // Instruction to check if two inputs are equal to each other. |
| 2669 | class HEqual : public HCondition { |
| 2670 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2671 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2672 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2673 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2674 | bool IsCommutative() const OVERRIDE { return true; } |
| 2675 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2676 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2677 | |
| 2678 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2679 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2680 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2681 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2682 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2683 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2684 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2685 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2686 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2687 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2688 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2689 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2690 | return kCondEQ; |
| 2691 | } |
| 2692 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2693 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2694 | return kCondNE; |
| 2695 | } |
| 2696 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2697 | private: |
| 2698 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2699 | }; |
| 2700 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2701 | class HNotEqual : public HCondition { |
| 2702 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2703 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2704 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2705 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2706 | bool IsCommutative() const OVERRIDE { return true; } |
| 2707 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2708 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2709 | |
| 2710 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2711 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2712 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2713 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2714 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2715 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2716 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2717 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2718 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2719 | DECLARE_INSTRUCTION(NotEqual); |
| 2720 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2721 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2722 | return kCondNE; |
| 2723 | } |
| 2724 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2725 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2726 | return kCondEQ; |
| 2727 | } |
| 2728 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2729 | private: |
| 2730 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2731 | }; |
| 2732 | |
| 2733 | class HLessThan : public HCondition { |
| 2734 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2735 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2736 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2737 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2738 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2739 | |
| 2740 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2741 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2742 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2743 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2744 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2745 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2746 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2747 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2748 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2749 | DECLARE_INSTRUCTION(LessThan); |
| 2750 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2751 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2752 | return kCondLT; |
| 2753 | } |
| 2754 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2755 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2756 | return kCondGE; |
| 2757 | } |
| 2758 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2759 | private: |
| 2760 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2761 | }; |
| 2762 | |
| 2763 | class HLessThanOrEqual : public HCondition { |
| 2764 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2765 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2766 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2767 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2768 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2769 | |
| 2770 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2771 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2772 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2773 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2774 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2775 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2776 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2777 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2778 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2779 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2780 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2781 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2782 | return kCondLE; |
| 2783 | } |
| 2784 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2785 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2786 | return kCondGT; |
| 2787 | } |
| 2788 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2789 | private: |
| 2790 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2791 | }; |
| 2792 | |
| 2793 | class HGreaterThan : public HCondition { |
| 2794 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2795 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2796 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2797 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2798 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2799 | |
| 2800 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2801 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2802 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2803 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2804 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2805 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2806 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2807 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2808 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2809 | DECLARE_INSTRUCTION(GreaterThan); |
| 2810 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2811 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2812 | return kCondGT; |
| 2813 | } |
| 2814 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2815 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2816 | return kCondLE; |
| 2817 | } |
| 2818 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2819 | private: |
| 2820 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2821 | }; |
| 2822 | |
| 2823 | class HGreaterThanOrEqual : public HCondition { |
| 2824 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2825 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2826 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2827 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2828 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2829 | |
| 2830 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2831 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2832 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2833 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2834 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2835 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2836 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2837 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2838 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2839 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2840 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2841 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2842 | return kCondGE; |
| 2843 | } |
| 2844 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2845 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2846 | return kCondLT; |
| 2847 | } |
| 2848 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2849 | private: |
| 2850 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2851 | }; |
| 2852 | |
| 2853 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2854 | // Instruction to check how two inputs compare to each other. |
| 2855 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2856 | class HCompare : public HBinaryOperation { |
| 2857 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2858 | HCompare(Primitive::Type type, |
| 2859 | HInstruction* first, |
| 2860 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2861 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2862 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2863 | : HBinaryOperation(Primitive::kPrimInt, |
| 2864 | first, |
| 2865 | second, |
| 2866 | SideEffectsForArchRuntimeCalls(type), |
| 2867 | dex_pc), |
| 2868 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2869 | DCHECK_EQ(type, first->GetType()); |
| 2870 | DCHECK_EQ(type, second->GetType()); |
| 2871 | } |
| 2872 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2873 | template <typename T> |
| 2874 | int32_t Compute(T x, T y) const { return x == y ? 0 : x > y ? 1 : -1; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2875 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2876 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2877 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2878 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2879 | } |
| 2880 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2881 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2882 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2883 | } |
| 2884 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2885 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2886 | return bias_ == other->AsCompare()->bias_; |
| 2887 | } |
| 2888 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2889 | ComparisonBias GetBias() const { return bias_; } |
| 2890 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2891 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2892 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2893 | |
| 2894 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2895 | // MIPS64 uses a runtime call for FP comparisons. |
| 2896 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2897 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2898 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2899 | DECLARE_INSTRUCTION(Compare); |
| 2900 | |
| 2901 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2902 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2903 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2904 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2905 | }; |
| 2906 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2907 | // A local in the graph. Corresponds to a Dex register. |
| 2908 | class HLocal : public HTemplateInstruction<0> { |
| 2909 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2910 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2911 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2912 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2913 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2914 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2915 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2916 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2917 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2918 | // The Dex register number. |
| 2919 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2920 | |
| 2921 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2922 | }; |
| 2923 | |
| 2924 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2925 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2926 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2927 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2928 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2929 | SetRawInputAt(0, local); |
| 2930 | } |
| 2931 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2932 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2933 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2934 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2935 | |
| 2936 | private: |
| 2937 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2938 | }; |
| 2939 | |
| 2940 | // Store a value in a given local. This instruction has two inputs: the value |
| 2941 | // and the local. |
| 2942 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2943 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2944 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2945 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2946 | SetRawInputAt(0, local); |
| 2947 | SetRawInputAt(1, value); |
| 2948 | } |
| 2949 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2950 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2951 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2952 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2953 | |
| 2954 | private: |
| 2955 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2956 | }; |
| 2957 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2958 | class HFloatConstant : public HConstant { |
| 2959 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2960 | float GetValue() const { return value_; } |
| 2961 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2962 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2963 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2964 | } |
| 2965 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2966 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2967 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2968 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2969 | } |
| 2970 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2971 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2972 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2973 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2974 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2975 | } |
| 2976 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2977 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2978 | } |
| 2979 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2980 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2981 | } |
| 2982 | bool IsNaN() const { |
| 2983 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2986 | DECLARE_INSTRUCTION(FloatConstant); |
| 2987 | |
| 2988 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2989 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2990 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2991 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2992 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2993 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2994 | const float value_; |
| 2995 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2996 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2997 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2998 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2999 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3000 | }; |
| 3001 | |
| 3002 | class HDoubleConstant : public HConstant { |
| 3003 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3004 | double GetValue() const { return value_; } |
| 3005 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3006 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3007 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3008 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3009 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3010 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3011 | } |
| 3012 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3013 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3014 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3015 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3016 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3017 | } |
| 3018 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3019 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3020 | } |
| 3021 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3022 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3023 | } |
| 3024 | bool IsNaN() const { |
| 3025 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3026 | } |
| 3027 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3028 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3029 | |
| 3030 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3031 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3032 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3033 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3034 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3035 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3036 | const double value_; |
| 3037 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3038 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3039 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3040 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3041 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3042 | }; |
| 3043 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3044 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3045 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3046 | #include "intrinsics_list.h" |
| 3047 | kNone, |
| 3048 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3049 | #undef INTRINSICS_LIST |
| 3050 | #undef OPTIMIZING_INTRINSICS |
| 3051 | }; |
| 3052 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3053 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3054 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3055 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3056 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3057 | }; |
| 3058 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3059 | class HInvoke : public HInstruction { |
| 3060 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3061 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3062 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3063 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3064 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3065 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3066 | SetRawInputAt(index, argument); |
| 3067 | } |
| 3068 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3069 | // Return the number of arguments. This number can be lower than |
| 3070 | // the number of inputs returned by InputCount(), as some invoke |
| 3071 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3072 | // inputs at the end of their list of inputs. |
| 3073 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3074 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3075 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3076 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3077 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3078 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3079 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3080 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3081 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3082 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3083 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3084 | return intrinsic_; |
| 3085 | } |
| 3086 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3087 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3088 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3089 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3090 | return GetEnvironment()->GetParent() != nullptr; |
| 3091 | } |
| 3092 | |
| 3093 | bool CanThrow() const OVERRIDE { return true; } |
| 3094 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3095 | uint32_t* GetIntrinsicOptimizations() { |
| 3096 | return &intrinsic_optimizations_; |
| 3097 | } |
| 3098 | |
| 3099 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3100 | return &intrinsic_optimizations_; |
| 3101 | } |
| 3102 | |
| 3103 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3104 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3105 | DECLARE_INSTRUCTION(Invoke); |
| 3106 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3107 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3108 | HInvoke(ArenaAllocator* arena, |
| 3109 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3110 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3111 | Primitive::Type return_type, |
| 3112 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3113 | uint32_t dex_method_index, |
| 3114 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3115 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3116 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3117 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3118 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3119 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3120 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3121 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3122 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3123 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3124 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3125 | } |
| 3126 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3127 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 3128 | DCHECK_LT(index, InputCount()); |
| 3129 | return inputs_[index]; |
| 3130 | } |
| 3131 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3132 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3133 | DCHECK_LT(index, InputCount()); |
| 3134 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3135 | } |
| 3136 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3137 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3138 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3139 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3140 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3141 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3142 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3143 | |
| 3144 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3145 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3146 | |
| 3147 | private: |
| 3148 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3149 | }; |
| 3150 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3151 | class HInvokeUnresolved : public HInvoke { |
| 3152 | public: |
| 3153 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3154 | uint32_t number_of_arguments, |
| 3155 | Primitive::Type return_type, |
| 3156 | uint32_t dex_pc, |
| 3157 | uint32_t dex_method_index, |
| 3158 | InvokeType invoke_type) |
| 3159 | : HInvoke(arena, |
| 3160 | number_of_arguments, |
| 3161 | 0u /* number_of_other_inputs */, |
| 3162 | return_type, |
| 3163 | dex_pc, |
| 3164 | dex_method_index, |
| 3165 | invoke_type) { |
| 3166 | } |
| 3167 | |
| 3168 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3169 | |
| 3170 | private: |
| 3171 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3172 | }; |
| 3173 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3174 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3175 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3176 | // Requirements of this method call regarding the class |
| 3177 | // initialization (clinit) check of its declaring class. |
| 3178 | enum class ClinitCheckRequirement { |
| 3179 | kNone, // Class already initialized. |
| 3180 | kExplicit, // Static call having explicit clinit check as last input. |
| 3181 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3182 | }; |
| 3183 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3184 | // Determines how to load the target ArtMethod*. |
| 3185 | enum class MethodLoadKind { |
| 3186 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3187 | kStringInit, |
| 3188 | |
| 3189 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3190 | kRecursive, |
| 3191 | |
| 3192 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3193 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3194 | kDirectAddress, |
| 3195 | |
| 3196 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3197 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3198 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3199 | // the image relocatable or not. |
| 3200 | kDirectAddressWithFixup, |
| 3201 | |
| 3202 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3203 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3204 | // may cause class initialization (the entry may point to a resolution method), |
| 3205 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3206 | kDexCachePcRelative, |
| 3207 | |
| 3208 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3209 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3210 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3211 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3212 | kDexCacheViaMethod, |
| 3213 | }; |
| 3214 | |
| 3215 | // Determines the location of the code pointer. |
| 3216 | enum class CodePtrLocation { |
| 3217 | // Recursive call, use local PC-relative call instruction. |
| 3218 | kCallSelf, |
| 3219 | |
| 3220 | // Use PC-relative call instruction patched at link time. |
| 3221 | // Used for calls within an oat file, boot->boot or app->app. |
| 3222 | kCallPCRelative, |
| 3223 | |
| 3224 | // Call to a known target address, embed the direct address in code. |
| 3225 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3226 | kCallDirect, |
| 3227 | |
| 3228 | // Call to a target address that will be known at link time, embed the direct |
| 3229 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3230 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3231 | // the image relocatable or not. |
| 3232 | kCallDirectWithFixup, |
| 3233 | |
| 3234 | // Use code pointer from the ArtMethod*. |
| 3235 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3236 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3237 | kCallArtMethod, |
| 3238 | }; |
| 3239 | |
| 3240 | struct DispatchInfo { |
| 3241 | const MethodLoadKind method_load_kind; |
| 3242 | const CodePtrLocation code_ptr_location; |
| 3243 | // The method load data holds |
| 3244 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3245 | // Note that there are multiple string init methods, each having its own offset. |
| 3246 | // - the method address for kDirectAddress |
| 3247 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3248 | const uint64_t method_load_data; |
| 3249 | const uint64_t direct_code_ptr; |
| 3250 | }; |
| 3251 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3252 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3253 | uint32_t number_of_arguments, |
| 3254 | Primitive::Type return_type, |
| 3255 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3256 | uint32_t method_index, |
| 3257 | MethodReference target_method, |
| 3258 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3259 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3260 | InvokeType invoke_type, |
| 3261 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3262 | : HInvoke(arena, |
| 3263 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3264 | // There is one extra argument for the HCurrentMethod node, and |
| 3265 | // potentially one other if the clinit check is explicit, and one other |
| 3266 | // if the method is a string factory. |
| 3267 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3268 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3269 | return_type, |
| 3270 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3271 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3272 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3273 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3274 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3275 | target_method_(target_method), |
| 3276 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3277 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3278 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3279 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3280 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3281 | // TODO: for intrinsics we can generate implicit null checks. |
| 3282 | return false; |
| 3283 | } |
| 3284 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3285 | bool CanBeNull() const OVERRIDE { |
| 3286 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3287 | } |
| 3288 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3289 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3290 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3291 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3292 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3293 | bool NeedsDexCache() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3294 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3295 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3296 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3297 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3298 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3299 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3300 | |
| 3301 | int32_t GetStringInitOffset() const { |
| 3302 | DCHECK(IsStringInit()); |
| 3303 | return dispatch_info_.method_load_data; |
| 3304 | } |
| 3305 | |
| 3306 | uint64_t GetMethodAddress() const { |
| 3307 | DCHECK(HasMethodAddress()); |
| 3308 | return dispatch_info_.method_load_data; |
| 3309 | } |
| 3310 | |
| 3311 | uint32_t GetDexCacheArrayOffset() const { |
| 3312 | DCHECK(HasPcRelDexCache()); |
| 3313 | return dispatch_info_.method_load_data; |
| 3314 | } |
| 3315 | |
| 3316 | uint64_t GetDirectCodePtr() const { |
| 3317 | DCHECK(HasDirectCodePtr()); |
| 3318 | return dispatch_info_.direct_code_ptr; |
| 3319 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3320 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3321 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3322 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3323 | // Is this instruction a call to a static method? |
| 3324 | bool IsStatic() const { |
| 3325 | return GetInvokeType() == kStatic; |
| 3326 | } |
| 3327 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3328 | // Remove the art::HLoadClass instruction set as last input by |
| 3329 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3330 | // the initial art::HClinitCheck instruction (only relevant for |
| 3331 | // static calls with explicit clinit check). |
| 3332 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3333 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3334 | size_t last_input_index = InputCount() - 1; |
| 3335 | HInstruction* last_input = InputAt(last_input_index); |
| 3336 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3337 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3338 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3339 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3340 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3341 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3342 | } |
| 3343 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3344 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3345 | if (!IsStringInit()) return false; |
| 3346 | // +1 for the current method. |
| 3347 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3348 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3349 | } |
| 3350 | |
| 3351 | void RemoveFakeStringArgumentAsLastInput() { |
| 3352 | DCHECK(IsStringInit()); |
| 3353 | size_t last_input_index = InputCount() - 1; |
| 3354 | HInstruction* last_input = InputAt(last_input_index); |
| 3355 | DCHECK(last_input != nullptr); |
| 3356 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3357 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3358 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3359 | } |
| 3360 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3361 | // Is this a call to a static method whose declaring class has an |
| 3362 | // explicit intialization check in the graph? |
| 3363 | bool IsStaticWithExplicitClinitCheck() const { |
| 3364 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3365 | } |
| 3366 | |
| 3367 | // Is this a call to a static method whose declaring class has an |
| 3368 | // implicit intialization check requirement? |
| 3369 | bool IsStaticWithImplicitClinitCheck() const { |
| 3370 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3371 | } |
| 3372 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3373 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3374 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3375 | protected: |
| 3376 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3377 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3378 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3379 | HInstruction* input = input_record.GetInstruction(); |
| 3380 | // `input` is the last input of a static invoke marked as having |
| 3381 | // an explicit clinit check. It must either be: |
| 3382 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3383 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3384 | DCHECK(input != nullptr); |
| 3385 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3386 | } |
| 3387 | return input_record; |
| 3388 | } |
| 3389 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3390 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3391 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3392 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3393 | // The target method may refer to different dex file or method index than the original |
| 3394 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3395 | // in derived class to increase visibility. |
| 3396 | MethodReference target_method_; |
| 3397 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3398 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3399 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3400 | }; |
| 3401 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3402 | class HInvokeVirtual : public HInvoke { |
| 3403 | public: |
| 3404 | HInvokeVirtual(ArenaAllocator* arena, |
| 3405 | uint32_t number_of_arguments, |
| 3406 | Primitive::Type return_type, |
| 3407 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3408 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3409 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3410 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kVirtual), |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3411 | vtable_index_(vtable_index) {} |
| 3412 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3413 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3414 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3415 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3416 | } |
| 3417 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3418 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3419 | |
| 3420 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3421 | |
| 3422 | private: |
| 3423 | const uint32_t vtable_index_; |
| 3424 | |
| 3425 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3426 | }; |
| 3427 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3428 | class HInvokeInterface : public HInvoke { |
| 3429 | public: |
| 3430 | HInvokeInterface(ArenaAllocator* arena, |
| 3431 | uint32_t number_of_arguments, |
| 3432 | Primitive::Type return_type, |
| 3433 | uint32_t dex_pc, |
| 3434 | uint32_t dex_method_index, |
| 3435 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3436 | : HInvoke(arena, number_of_arguments, 0u, return_type, dex_pc, dex_method_index, kInterface), |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3437 | imt_index_(imt_index) {} |
| 3438 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3439 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3440 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3441 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3442 | } |
| 3443 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3444 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3445 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3446 | |
| 3447 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3448 | |
| 3449 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3450 | const uint32_t imt_index_; |
| 3451 | |
| 3452 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3453 | }; |
| 3454 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3455 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3456 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3457 | HNewInstance(HCurrentMethod* current_method, |
| 3458 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3459 | uint16_t type_index, |
| 3460 | const DexFile& dex_file, |
| 3461 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3462 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3463 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3464 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3465 | entrypoint_(entrypoint) { |
| 3466 | SetRawInputAt(0, current_method); |
| 3467 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3468 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3469 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3470 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3471 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3472 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3473 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3474 | // It may throw when called on: |
| 3475 | // - interfaces |
| 3476 | // - abstract/innaccessible/unknown classes |
| 3477 | // TODO: optimize when possible. |
| 3478 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3479 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3480 | bool CanBeNull() const OVERRIDE { return false; } |
| 3481 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3482 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3483 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3484 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3485 | |
| 3486 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3487 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3488 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3489 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3490 | |
| 3491 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3492 | }; |
| 3493 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3494 | class HNeg : public HUnaryOperation { |
| 3495 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3496 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3497 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3498 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3499 | template <typename T> T Compute(T x) const { return -x; } |
| 3500 | |
| 3501 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3502 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3503 | } |
| 3504 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3505 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3506 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3507 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3508 | DECLARE_INSTRUCTION(Neg); |
| 3509 | |
| 3510 | private: |
| 3511 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3512 | }; |
| 3513 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3514 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3515 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3516 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3517 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3518 | uint32_t dex_pc, |
| 3519 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3520 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3521 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3522 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3523 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3524 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3525 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3526 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3527 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3528 | } |
| 3529 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3530 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3531 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3532 | |
| 3533 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3534 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3535 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3536 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3537 | bool CanThrow() const OVERRIDE { return true; } |
| 3538 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3539 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3540 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3541 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3542 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3543 | DECLARE_INSTRUCTION(NewArray); |
| 3544 | |
| 3545 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3546 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3547 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3548 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3549 | |
| 3550 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3551 | }; |
| 3552 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3553 | class HAdd : public HBinaryOperation { |
| 3554 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3555 | HAdd(Primitive::Type result_type, |
| 3556 | HInstruction* left, |
| 3557 | HInstruction* right, |
| 3558 | uint32_t dex_pc = kNoDexPc) |
| 3559 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3560 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3561 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3562 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3563 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3564 | |
| 3565 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3566 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3567 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3568 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3569 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3570 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3571 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3572 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3573 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3574 | DECLARE_INSTRUCTION(Add); |
| 3575 | |
| 3576 | private: |
| 3577 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3578 | }; |
| 3579 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3580 | class HSub : public HBinaryOperation { |
| 3581 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3582 | HSub(Primitive::Type result_type, |
| 3583 | HInstruction* left, |
| 3584 | HInstruction* right, |
| 3585 | uint32_t dex_pc = kNoDexPc) |
| 3586 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3587 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3588 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3589 | |
| 3590 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3591 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3592 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3593 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3594 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3595 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3596 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3597 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3598 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3599 | DECLARE_INSTRUCTION(Sub); |
| 3600 | |
| 3601 | private: |
| 3602 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3603 | }; |
| 3604 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3605 | class HMul : public HBinaryOperation { |
| 3606 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3607 | HMul(Primitive::Type result_type, |
| 3608 | HInstruction* left, |
| 3609 | HInstruction* right, |
| 3610 | uint32_t dex_pc = kNoDexPc) |
| 3611 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3612 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3613 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3614 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3615 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3616 | |
| 3617 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3618 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3619 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3620 | } |
| 3621 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3622 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3623 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3624 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3625 | |
| 3626 | DECLARE_INSTRUCTION(Mul); |
| 3627 | |
| 3628 | private: |
| 3629 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3630 | }; |
| 3631 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3632 | class HDiv : public HBinaryOperation { |
| 3633 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3634 | HDiv(Primitive::Type result_type, |
| 3635 | HInstruction* left, |
| 3636 | HInstruction* right, |
| 3637 | uint32_t dex_pc) |
| 3638 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3639 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3640 | template <typename T> |
| 3641 | T Compute(T x, T y) const { |
| 3642 | // Our graph structure ensures we never have 0 for `y` during |
| 3643 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3644 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3645 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3646 | return (y == -1) ? -x : x / y; |
| 3647 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3648 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3649 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3650 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3651 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3652 | } |
| 3653 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3654 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3655 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3657 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3658 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3659 | // The generated code can use a runtime call. |
| 3660 | return SideEffects::CanTriggerGC(); |
| 3661 | } |
| 3662 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3663 | DECLARE_INSTRUCTION(Div); |
| 3664 | |
| 3665 | private: |
| 3666 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3667 | }; |
| 3668 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3669 | class HRem : public HBinaryOperation { |
| 3670 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3671 | HRem(Primitive::Type result_type, |
| 3672 | HInstruction* left, |
| 3673 | HInstruction* right, |
| 3674 | uint32_t dex_pc) |
| 3675 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3676 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3677 | template <typename T> |
| 3678 | T Compute(T x, T y) const { |
| 3679 | // Our graph structure ensures we never have 0 for `y` during |
| 3680 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3681 | DCHECK_NE(y, 0); |
| 3682 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3683 | return (y == -1) ? 0 : x % y; |
| 3684 | } |
| 3685 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3686 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3687 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3688 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3689 | } |
| 3690 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3691 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3692 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3693 | } |
| 3694 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3695 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3696 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3697 | return SideEffects::CanTriggerGC(); |
| 3698 | } |
| 3699 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3700 | DECLARE_INSTRUCTION(Rem); |
| 3701 | |
| 3702 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3703 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3704 | }; |
| 3705 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3706 | class HDivZeroCheck : public HExpression<1> { |
| 3707 | public: |
| 3708 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3709 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3710 | SetRawInputAt(0, value); |
| 3711 | } |
| 3712 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3713 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3714 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3715 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3716 | |
| 3717 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3718 | UNUSED(other); |
| 3719 | return true; |
| 3720 | } |
| 3721 | |
| 3722 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3723 | bool CanThrow() const OVERRIDE { return true; } |
| 3724 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3725 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3726 | |
| 3727 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3728 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3729 | }; |
| 3730 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3731 | class HShl : public HBinaryOperation { |
| 3732 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3733 | HShl(Primitive::Type result_type, |
| 3734 | HInstruction* left, |
| 3735 | HInstruction* right, |
| 3736 | uint32_t dex_pc = kNoDexPc) |
| 3737 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3738 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3739 | template <typename T, typename U, typename V> |
| 3740 | T Compute(T x, U y, V max_shift_value) const { |
| 3741 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3742 | "V is not the unsigned integer type corresponding to T"); |
| 3743 | return x << (y & max_shift_value); |
| 3744 | } |
| 3745 | |
| 3746 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3747 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3748 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3749 | } |
| 3750 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3751 | // case is handled as `x << static_cast<int>(y)`. |
| 3752 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3753 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3754 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3755 | } |
| 3756 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3757 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3758 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3759 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3760 | |
| 3761 | DECLARE_INSTRUCTION(Shl); |
| 3762 | |
| 3763 | private: |
| 3764 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3765 | }; |
| 3766 | |
| 3767 | class HShr : public HBinaryOperation { |
| 3768 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3769 | HShr(Primitive::Type result_type, |
| 3770 | HInstruction* left, |
| 3771 | HInstruction* right, |
| 3772 | uint32_t dex_pc = kNoDexPc) |
| 3773 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3774 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3775 | template <typename T, typename U, typename V> |
| 3776 | T Compute(T x, U y, V max_shift_value) const { |
| 3777 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3778 | "V is not the unsigned integer type corresponding to T"); |
| 3779 | return x >> (y & max_shift_value); |
| 3780 | } |
| 3781 | |
| 3782 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3783 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3784 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3785 | } |
| 3786 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3787 | // case is handled as `x >> static_cast<int>(y)`. |
| 3788 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3789 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3790 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3791 | } |
| 3792 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3793 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3794 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3795 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3796 | |
| 3797 | DECLARE_INSTRUCTION(Shr); |
| 3798 | |
| 3799 | private: |
| 3800 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3801 | }; |
| 3802 | |
| 3803 | class HUShr : public HBinaryOperation { |
| 3804 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3805 | HUShr(Primitive::Type result_type, |
| 3806 | HInstruction* left, |
| 3807 | HInstruction* right, |
| 3808 | uint32_t dex_pc = kNoDexPc) |
| 3809 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3810 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3811 | template <typename T, typename U, typename V> |
| 3812 | T Compute(T x, U y, V max_shift_value) const { |
| 3813 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3814 | "V is not the unsigned integer type corresponding to T"); |
| 3815 | V ux = static_cast<V>(x); |
| 3816 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3817 | } |
| 3818 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3819 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3820 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3821 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3822 | } |
| 3823 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3824 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3825 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3826 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3827 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3828 | } |
| 3829 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3830 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3831 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3832 | } |
| 3833 | |
| 3834 | DECLARE_INSTRUCTION(UShr); |
| 3835 | |
| 3836 | private: |
| 3837 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3838 | }; |
| 3839 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3840 | class HAnd : public HBinaryOperation { |
| 3841 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3842 | HAnd(Primitive::Type result_type, |
| 3843 | HInstruction* left, |
| 3844 | HInstruction* right, |
| 3845 | uint32_t dex_pc = kNoDexPc) |
| 3846 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3847 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3848 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3849 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3850 | template <typename T, typename U> |
| 3851 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3852 | |
| 3853 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3854 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3855 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3856 | } |
| 3857 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3858 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3859 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3860 | } |
| 3861 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3862 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3863 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3864 | } |
| 3865 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3866 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3867 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3868 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3869 | |
| 3870 | DECLARE_INSTRUCTION(And); |
| 3871 | |
| 3872 | private: |
| 3873 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3874 | }; |
| 3875 | |
| 3876 | class HOr : public HBinaryOperation { |
| 3877 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3878 | HOr(Primitive::Type result_type, |
| 3879 | HInstruction* left, |
| 3880 | HInstruction* right, |
| 3881 | uint32_t dex_pc = kNoDexPc) |
| 3882 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3883 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3884 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3885 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3886 | template <typename T, typename U> |
| 3887 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3888 | |
| 3889 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3890 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3891 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3892 | } |
| 3893 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3894 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3895 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3896 | } |
| 3897 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3898 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3899 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3900 | } |
| 3901 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3902 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3903 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3904 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3905 | |
| 3906 | DECLARE_INSTRUCTION(Or); |
| 3907 | |
| 3908 | private: |
| 3909 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3910 | }; |
| 3911 | |
| 3912 | class HXor : public HBinaryOperation { |
| 3913 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3914 | HXor(Primitive::Type result_type, |
| 3915 | HInstruction* left, |
| 3916 | HInstruction* right, |
| 3917 | uint32_t dex_pc = kNoDexPc) |
| 3918 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3919 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3920 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3921 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3922 | template <typename T, typename U> |
| 3923 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3924 | |
| 3925 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3926 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3927 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3928 | } |
| 3929 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3930 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3931 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3932 | } |
| 3933 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3934 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3935 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3936 | } |
| 3937 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3938 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3939 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3940 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3941 | |
| 3942 | DECLARE_INSTRUCTION(Xor); |
| 3943 | |
| 3944 | private: |
| 3945 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3946 | }; |
| 3947 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3948 | // The value of a parameter in this method. Its location depends on |
| 3949 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3950 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3951 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3952 | HParameterValue(uint8_t index, |
| 3953 | Primitive::Type parameter_type, |
| 3954 | bool is_this = false) |
| 3955 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3956 | index_(index), |
| 3957 | is_this_(is_this), |
| 3958 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3959 | |
| 3960 | uint8_t GetIndex() const { return index_; } |
| 3961 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3962 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3963 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3964 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3965 | bool IsThis() const { return is_this_; } |
| 3966 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3967 | DECLARE_INSTRUCTION(ParameterValue); |
| 3968 | |
| 3969 | private: |
| 3970 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3971 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3972 | const uint8_t index_; |
| 3973 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3974 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3975 | const bool is_this_; |
| 3976 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3977 | bool can_be_null_; |
| 3978 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3979 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3980 | }; |
| 3981 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3982 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3983 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3984 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3985 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3986 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3987 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3988 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3989 | UNUSED(other); |
| 3990 | return true; |
| 3991 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3992 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3993 | template <typename T> T Compute(T x) const { return ~x; } |
| 3994 | |
| 3995 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3996 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3997 | } |
| 3998 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3999 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4000 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4001 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4002 | DECLARE_INSTRUCTION(Not); |
| 4003 | |
| 4004 | private: |
| 4005 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4006 | }; |
| 4007 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4008 | class HBooleanNot : public HUnaryOperation { |
| 4009 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4010 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4011 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4012 | |
| 4013 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4014 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4015 | UNUSED(other); |
| 4016 | return true; |
| 4017 | } |
| 4018 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4019 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4020 | DCHECK(IsUint<1>(x)); |
| 4021 | return !x; |
| 4022 | } |
| 4023 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4024 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4025 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4026 | } |
| 4027 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4028 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4029 | UNREACHABLE(); |
| 4030 | } |
| 4031 | |
| 4032 | DECLARE_INSTRUCTION(BooleanNot); |
| 4033 | |
| 4034 | private: |
| 4035 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4036 | }; |
| 4037 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4038 | class HTypeConversion : public HExpression<1> { |
| 4039 | public: |
| 4040 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4041 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4042 | : HExpression(result_type, |
| 4043 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4044 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4045 | SetRawInputAt(0, input); |
| 4046 | DCHECK_NE(input->GetType(), result_type); |
| 4047 | } |
| 4048 | |
| 4049 | HInstruction* GetInput() const { return InputAt(0); } |
| 4050 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4051 | Primitive::Type GetResultType() const { return GetType(); } |
| 4052 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4053 | // Required by the x86 and ARM code generators when producing calls |
| 4054 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4055 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4056 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4057 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4058 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4059 | // Try to statically evaluate the conversion and return a HConstant |
| 4060 | // containing the result. If the input cannot be converted, return nullptr. |
| 4061 | HConstant* TryStaticEvaluation() const; |
| 4062 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4063 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4064 | Primitive::Type result_type) { |
| 4065 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4066 | // in the compilation process we do not know what architecture we will |
| 4067 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4068 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4069 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4070 | return SideEffects::CanTriggerGC(); |
| 4071 | } |
| 4072 | return SideEffects::None(); |
| 4073 | } |
| 4074 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4075 | DECLARE_INSTRUCTION(TypeConversion); |
| 4076 | |
| 4077 | private: |
| 4078 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4079 | }; |
| 4080 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4081 | static constexpr uint32_t kNoRegNumber = -1; |
| 4082 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4083 | class HPhi : public HInstruction { |
| 4084 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4085 | HPhi(ArenaAllocator* arena, |
| 4086 | uint32_t reg_number, |
| 4087 | size_t number_of_inputs, |
| 4088 | Primitive::Type type, |
| 4089 | uint32_t dex_pc = kNoDexPc) |
| 4090 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4091 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4092 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4093 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4094 | is_live_(false), |
| 4095 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4096 | } |
| 4097 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4098 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4099 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4100 | switch (type) { |
| 4101 | case Primitive::kPrimBoolean: |
| 4102 | case Primitive::kPrimByte: |
| 4103 | case Primitive::kPrimShort: |
| 4104 | case Primitive::kPrimChar: |
| 4105 | return Primitive::kPrimInt; |
| 4106 | default: |
| 4107 | return type; |
| 4108 | } |
| 4109 | } |
| 4110 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4111 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4112 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4113 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4114 | |
| 4115 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4116 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4117 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4118 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4119 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4120 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4121 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4122 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4123 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4124 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4125 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4126 | void SetDead() { is_live_ = false; } |
| 4127 | void SetLive() { is_live_ = true; } |
| 4128 | bool IsDead() const { return !is_live_; } |
| 4129 | bool IsLive() const { return is_live_; } |
| 4130 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4131 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4132 | return other != nullptr |
| 4133 | && other->IsPhi() |
| 4134 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4135 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4136 | } |
| 4137 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4138 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4139 | // An equivalent phi is a phi having the same dex register and type. |
| 4140 | // It assumes that phis with the same dex register are adjacent. |
| 4141 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4142 | HInstruction* next = GetNext(); |
| 4143 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4144 | if (next->GetType() == GetType()) { |
| 4145 | return next->AsPhi(); |
| 4146 | } |
| 4147 | next = next->GetNext(); |
| 4148 | } |
| 4149 | return nullptr; |
| 4150 | } |
| 4151 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4152 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4153 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4154 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4155 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 4156 | DCHECK_LE(index, InputCount()); |
| 4157 | return inputs_[index]; |
| 4158 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4159 | |
| 4160 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4161 | DCHECK_LE(index, InputCount()); |
| 4162 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4163 | } |
| 4164 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4165 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4166 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4167 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4168 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4169 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4170 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4171 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4172 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4173 | }; |
| 4174 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4175 | class HNullCheck : public HExpression<1> { |
| 4176 | public: |
| 4177 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4178 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4179 | SetRawInputAt(0, value); |
| 4180 | } |
| 4181 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4182 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4183 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4184 | UNUSED(other); |
| 4185 | return true; |
| 4186 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4187 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4188 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4189 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4190 | bool CanThrow() const OVERRIDE { return true; } |
| 4191 | |
| 4192 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4193 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4194 | |
| 4195 | DECLARE_INSTRUCTION(NullCheck); |
| 4196 | |
| 4197 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4198 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4199 | }; |
| 4200 | |
| 4201 | class FieldInfo : public ValueObject { |
| 4202 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4203 | FieldInfo(MemberOffset field_offset, |
| 4204 | Primitive::Type field_type, |
| 4205 | bool is_volatile, |
| 4206 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4207 | const DexFile& dex_file, |
| 4208 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4209 | : field_offset_(field_offset), |
| 4210 | field_type_(field_type), |
| 4211 | is_volatile_(is_volatile), |
| 4212 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4213 | dex_file_(dex_file), |
| 4214 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4215 | |
| 4216 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4217 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4218 | uint32_t GetFieldIndex() const { return index_; } |
| 4219 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4220 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4221 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4222 | |
| 4223 | private: |
| 4224 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4225 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4226 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4227 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4228 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4229 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4230 | }; |
| 4231 | |
| 4232 | class HInstanceFieldGet : public HExpression<1> { |
| 4233 | public: |
| 4234 | HInstanceFieldGet(HInstruction* value, |
| 4235 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4236 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4237 | bool is_volatile, |
| 4238 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4239 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4240 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4241 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4242 | : HExpression( |
| 4243 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4244 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4245 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4246 | SetRawInputAt(0, value); |
| 4247 | } |
| 4248 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4249 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4250 | |
| 4251 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4252 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4253 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4254 | } |
| 4255 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4256 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4257 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4258 | } |
| 4259 | |
| 4260 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4261 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4262 | } |
| 4263 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4264 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4265 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4266 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4267 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4268 | |
| 4269 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4270 | |
| 4271 | private: |
| 4272 | const FieldInfo field_info_; |
| 4273 | |
| 4274 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4275 | }; |
| 4276 | |
| 4277 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4278 | public: |
| 4279 | HInstanceFieldSet(HInstruction* object, |
| 4280 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4281 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4282 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4283 | bool is_volatile, |
| 4284 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4285 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4286 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4287 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4288 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4289 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4290 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4291 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4292 | SetRawInputAt(0, object); |
| 4293 | SetRawInputAt(1, value); |
| 4294 | } |
| 4295 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4296 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4297 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4300 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4301 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4302 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4303 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4304 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4305 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4306 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4307 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4308 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4309 | |
| 4310 | private: |
| 4311 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4312 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4313 | |
| 4314 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4315 | }; |
| 4316 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4317 | class HArrayGet : public HExpression<2> { |
| 4318 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4319 | HArrayGet(HInstruction* array, |
| 4320 | HInstruction* index, |
| 4321 | Primitive::Type type, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4322 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4323 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4324 | SetRawInputAt(0, array); |
| 4325 | SetRawInputAt(1, index); |
| 4326 | } |
| 4327 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4328 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4329 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4330 | UNUSED(other); |
| 4331 | return true; |
| 4332 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4333 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4334 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4335 | // TODO: We can be smarter here. |
| 4336 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4337 | // which generates the implicit null check. There are cases when these can be removed |
| 4338 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4339 | // implicit check here (as long as the address falls in the first page). |
| 4340 | return false; |
| 4341 | } |
| 4342 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4343 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4344 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4345 | HInstruction* GetArray() const { return InputAt(0); } |
| 4346 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4347 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4348 | DECLARE_INSTRUCTION(ArrayGet); |
| 4349 | |
| 4350 | private: |
| 4351 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4352 | }; |
| 4353 | |
| 4354 | class HArraySet : public HTemplateInstruction<3> { |
| 4355 | public: |
| 4356 | HArraySet(HInstruction* array, |
| 4357 | HInstruction* index, |
| 4358 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4359 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4360 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4361 | : HTemplateInstruction( |
| 4362 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4363 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4364 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4365 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4366 | value_can_be_null_(true), |
| 4367 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4368 | SetRawInputAt(0, array); |
| 4369 | SetRawInputAt(1, index); |
| 4370 | SetRawInputAt(2, value); |
| 4371 | } |
| 4372 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4373 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4374 | // We currently always call a runtime method to catch array store |
| 4375 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4376 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4377 | } |
| 4378 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4379 | // Can throw ArrayStoreException. |
| 4380 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4381 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4382 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4383 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4384 | // TODO: Same as for ArrayGet. |
| 4385 | return false; |
| 4386 | } |
| 4387 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4388 | void ClearNeedsTypeCheck() { |
| 4389 | needs_type_check_ = false; |
| 4390 | } |
| 4391 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4392 | void ClearValueCanBeNull() { |
| 4393 | value_can_be_null_ = false; |
| 4394 | } |
| 4395 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4396 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4397 | static_type_of_array_is_object_array_ = true; |
| 4398 | } |
| 4399 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4400 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4401 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4402 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4403 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4404 | HInstruction* GetArray() const { return InputAt(0); } |
| 4405 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4406 | HInstruction* GetValue() const { return InputAt(2); } |
| 4407 | |
| 4408 | Primitive::Type GetComponentType() const { |
| 4409 | // The Dex format does not type floating point index operations. Since the |
| 4410 | // `expected_component_type_` is set during building and can therefore not |
| 4411 | // be correct, we also check what is the value type. If it is a floating |
| 4412 | // point type, we must use that type. |
| 4413 | Primitive::Type value_type = GetValue()->GetType(); |
| 4414 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4415 | ? value_type |
| 4416 | : expected_component_type_; |
| 4417 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4418 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4419 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4420 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4421 | } |
| 4422 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4423 | DECLARE_INSTRUCTION(ArraySet); |
| 4424 | |
| 4425 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4426 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4427 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4428 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4429 | // Cached information for the reference_type_info_ so that codegen |
| 4430 | // does not need to inspect the static type. |
| 4431 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4432 | |
| 4433 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4434 | }; |
| 4435 | |
| 4436 | class HArrayLength : public HExpression<1> { |
| 4437 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame^] | 4438 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4439 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4440 | // Note that arrays do not change length, so the instruction does not |
| 4441 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4442 | SetRawInputAt(0, array); |
| 4443 | } |
| 4444 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4445 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4446 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4447 | UNUSED(other); |
| 4448 | return true; |
| 4449 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4450 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4451 | return obj == InputAt(0); |
| 4452 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4453 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4454 | DECLARE_INSTRUCTION(ArrayLength); |
| 4455 | |
| 4456 | private: |
| 4457 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4458 | }; |
| 4459 | |
| 4460 | class HBoundsCheck : public HExpression<2> { |
| 4461 | public: |
| 4462 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4463 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4464 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4465 | SetRawInputAt(0, index); |
| 4466 | SetRawInputAt(1, length); |
| 4467 | } |
| 4468 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4469 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4470 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4471 | UNUSED(other); |
| 4472 | return true; |
| 4473 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4474 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4475 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4476 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4477 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4478 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4479 | |
| 4480 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4481 | |
| 4482 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4483 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4484 | }; |
| 4485 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4486 | /** |
| 4487 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4488 | * to stay live until the last HInstruction. This class |
| 4489 | * is used as a marker for the baseline compiler to ensure its preceding |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 4490 | * HInstruction stays live. `index` represents the stack location index of the |
| 4491 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4492 | */ |
| 4493 | class HTemporary : public HTemplateInstruction<0> { |
| 4494 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4495 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4496 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4497 | |
| 4498 | size_t GetIndex() const { return index_; } |
| 4499 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4500 | Primitive::Type GetType() const OVERRIDE { |
| 4501 | // The previous instruction is the one that will be stored in the temporary location. |
| 4502 | DCHECK(GetPrevious() != nullptr); |
| 4503 | return GetPrevious()->GetType(); |
| 4504 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4505 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4506 | DECLARE_INSTRUCTION(Temporary); |
| 4507 | |
| 4508 | private: |
| 4509 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4510 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4511 | }; |
| 4512 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4513 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4514 | public: |
| 4515 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4516 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4517 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4518 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4519 | return true; |
| 4520 | } |
| 4521 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4522 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4523 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4524 | |
| 4525 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4526 | |
| 4527 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4528 | // Only used for code generation, in order to share the same slow path between back edges |
| 4529 | // of a same loop. |
| 4530 | SlowPathCode* slow_path_; |
| 4531 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4532 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4533 | }; |
| 4534 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4535 | /** |
| 4536 | * Instruction to load a Class object. |
| 4537 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4538 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4539 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4540 | HLoadClass(HCurrentMethod* current_method, |
| 4541 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4542 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4543 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4544 | uint32_t dex_pc, |
| 4545 | bool needs_access_check) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4546 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4547 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4548 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4549 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4550 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4551 | needs_access_check_(needs_access_check), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4552 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4553 | SetRawInputAt(0, current_method); |
| 4554 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4555 | |
| 4556 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4557 | |
| 4558 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4559 | return other->AsLoadClass()->type_index_ == type_index_; |
| 4560 | } |
| 4561 | |
| 4562 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4563 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4564 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4565 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4566 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4567 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4568 | bool NeedsEnvironment() const OVERRIDE { |
| 4569 | // Will call runtime and load the class if the class is not loaded yet. |
| 4570 | // TODO: finer grain decision. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4571 | return !is_referrers_class_ || needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4572 | } |
| 4573 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4574 | bool MustGenerateClinitCheck() const { |
| 4575 | return generate_clinit_check_; |
| 4576 | } |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4577 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4578 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4579 | } |
| 4580 | |
| 4581 | bool CanCallRuntime() const { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4582 | return MustGenerateClinitCheck() || !is_referrers_class_ || needs_access_check_; |
| 4583 | } |
| 4584 | |
| 4585 | bool NeedsAccessCheck() const { |
| 4586 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4587 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4588 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4589 | bool CanThrow() const OVERRIDE { |
| 4590 | // May call runtime and and therefore can throw. |
| 4591 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4592 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4593 | } |
| 4594 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4595 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4596 | return loaded_class_rti_; |
| 4597 | } |
| 4598 | |
| 4599 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4600 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4601 | DCHECK(rti.IsExact()); |
| 4602 | loaded_class_rti_ = rti; |
| 4603 | } |
| 4604 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4605 | const DexFile& GetDexFile() { return dex_file_; } |
| 4606 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4607 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4608 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4609 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4610 | return SideEffects::CanTriggerGC(); |
| 4611 | } |
| 4612 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4613 | DECLARE_INSTRUCTION(LoadClass); |
| 4614 | |
| 4615 | private: |
| 4616 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4617 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4618 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4619 | // Whether this instruction must generate the initialization check. |
| 4620 | // Used for code generation. |
| 4621 | bool generate_clinit_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4622 | bool needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4623 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4624 | ReferenceTypeInfo loaded_class_rti_; |
| 4625 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4626 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4627 | }; |
| 4628 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4629 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4630 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4631 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4632 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4633 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4634 | SetRawInputAt(0, current_method); |
| 4635 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4636 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4637 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4638 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4639 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4640 | return other->AsLoadString()->string_index_ == string_index_; |
| 4641 | } |
| 4642 | |
| 4643 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4644 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4645 | uint32_t GetStringIndex() const { return string_index_; } |
| 4646 | |
| 4647 | // TODO: Can we deopt or debug when we resolve a string? |
| 4648 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4649 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4650 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4651 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4652 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4653 | return SideEffects::CanTriggerGC(); |
| 4654 | } |
| 4655 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4656 | DECLARE_INSTRUCTION(LoadString); |
| 4657 | |
| 4658 | private: |
| 4659 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4660 | |
| 4661 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4662 | }; |
| 4663 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4664 | /** |
| 4665 | * Performs an initialization check on its Class object input. |
| 4666 | */ |
| 4667 | class HClinitCheck : public HExpression<1> { |
| 4668 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4669 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4670 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4671 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4672 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4673 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4674 | SetRawInputAt(0, constant); |
| 4675 | } |
| 4676 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4677 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4678 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4679 | UNUSED(other); |
| 4680 | return true; |
| 4681 | } |
| 4682 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4683 | bool NeedsEnvironment() const OVERRIDE { |
| 4684 | // May call runtime to initialize the class. |
| 4685 | return true; |
| 4686 | } |
| 4687 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4688 | |
| 4689 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4690 | |
| 4691 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4692 | |
| 4693 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4694 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4695 | }; |
| 4696 | |
| 4697 | class HStaticFieldGet : public HExpression<1> { |
| 4698 | public: |
| 4699 | HStaticFieldGet(HInstruction* cls, |
| 4700 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4701 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4702 | bool is_volatile, |
| 4703 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4704 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4705 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4706 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4707 | : HExpression( |
| 4708 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4709 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4710 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4711 | SetRawInputAt(0, cls); |
| 4712 | } |
| 4713 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4714 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4715 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4716 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4717 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4718 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4719 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4720 | } |
| 4721 | |
| 4722 | size_t ComputeHashCode() const OVERRIDE { |
| 4723 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4724 | } |
| 4725 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4726 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4727 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4728 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4729 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4730 | |
| 4731 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4732 | |
| 4733 | private: |
| 4734 | const FieldInfo field_info_; |
| 4735 | |
| 4736 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4737 | }; |
| 4738 | |
| 4739 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4740 | public: |
| 4741 | HStaticFieldSet(HInstruction* cls, |
| 4742 | HInstruction* value, |
| 4743 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4744 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4745 | bool is_volatile, |
| 4746 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4747 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4748 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4749 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4750 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4751 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4752 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4753 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4754 | SetRawInputAt(0, cls); |
| 4755 | SetRawInputAt(1, value); |
| 4756 | } |
| 4757 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4758 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4759 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4760 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4761 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4762 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4763 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4764 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4765 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4766 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4767 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4768 | |
| 4769 | private: |
| 4770 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4771 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4772 | |
| 4773 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4774 | }; |
| 4775 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4776 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 4777 | public: |
| 4778 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 4779 | Primitive::Type field_type, |
| 4780 | uint32_t field_index, |
| 4781 | uint32_t dex_pc) |
| 4782 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 4783 | field_index_(field_index) { |
| 4784 | SetRawInputAt(0, obj); |
| 4785 | } |
| 4786 | |
| 4787 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4788 | bool CanThrow() const OVERRIDE { return true; } |
| 4789 | |
| 4790 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4791 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4792 | |
| 4793 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 4794 | |
| 4795 | private: |
| 4796 | const uint32_t field_index_; |
| 4797 | |
| 4798 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 4799 | }; |
| 4800 | |
| 4801 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 4802 | public: |
| 4803 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 4804 | HInstruction* value, |
| 4805 | Primitive::Type field_type, |
| 4806 | uint32_t field_index, |
| 4807 | uint32_t dex_pc) |
| 4808 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 4809 | field_type_(field_type), |
| 4810 | field_index_(field_index) { |
| 4811 | DCHECK_EQ(field_type, value->GetType()); |
| 4812 | SetRawInputAt(0, obj); |
| 4813 | SetRawInputAt(1, value); |
| 4814 | } |
| 4815 | |
| 4816 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4817 | bool CanThrow() const OVERRIDE { return true; } |
| 4818 | |
| 4819 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4820 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4821 | |
| 4822 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 4823 | |
| 4824 | private: |
| 4825 | const Primitive::Type field_type_; |
| 4826 | const uint32_t field_index_; |
| 4827 | |
| 4828 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 4829 | }; |
| 4830 | |
| 4831 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 4832 | public: |
| 4833 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 4834 | uint32_t field_index, |
| 4835 | uint32_t dex_pc) |
| 4836 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 4837 | field_index_(field_index) { |
| 4838 | } |
| 4839 | |
| 4840 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4841 | bool CanThrow() const OVERRIDE { return true; } |
| 4842 | |
| 4843 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4844 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4845 | |
| 4846 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 4847 | |
| 4848 | private: |
| 4849 | const uint32_t field_index_; |
| 4850 | |
| 4851 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 4852 | }; |
| 4853 | |
| 4854 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 4855 | public: |
| 4856 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 4857 | Primitive::Type field_type, |
| 4858 | uint32_t field_index, |
| 4859 | uint32_t dex_pc) |
| 4860 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 4861 | field_type_(field_type), |
| 4862 | field_index_(field_index) { |
| 4863 | DCHECK_EQ(field_type, value->GetType()); |
| 4864 | SetRawInputAt(0, value); |
| 4865 | } |
| 4866 | |
| 4867 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4868 | bool CanThrow() const OVERRIDE { return true; } |
| 4869 | |
| 4870 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4871 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4872 | |
| 4873 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 4874 | |
| 4875 | private: |
| 4876 | const Primitive::Type field_type_; |
| 4877 | const uint32_t field_index_; |
| 4878 | |
| 4879 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 4880 | }; |
| 4881 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4882 | // Implement the move-exception DEX instruction. |
| 4883 | class HLoadException : public HExpression<0> { |
| 4884 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4885 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4886 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4887 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4888 | bool CanBeNull() const OVERRIDE { return false; } |
| 4889 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4890 | DECLARE_INSTRUCTION(LoadException); |
| 4891 | |
| 4892 | private: |
| 4893 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4894 | }; |
| 4895 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4896 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4897 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4898 | class HClearException : public HTemplateInstruction<0> { |
| 4899 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4900 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4901 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4902 | |
| 4903 | DECLARE_INSTRUCTION(ClearException); |
| 4904 | |
| 4905 | private: |
| 4906 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4907 | }; |
| 4908 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4909 | class HThrow : public HTemplateInstruction<1> { |
| 4910 | public: |
| 4911 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4912 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4913 | SetRawInputAt(0, exception); |
| 4914 | } |
| 4915 | |
| 4916 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4917 | |
| 4918 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4919 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4920 | bool CanThrow() const OVERRIDE { return true; } |
| 4921 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4922 | |
| 4923 | DECLARE_INSTRUCTION(Throw); |
| 4924 | |
| 4925 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4926 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4927 | }; |
| 4928 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4929 | /** |
| 4930 | * Implementation strategies for the code generator of a HInstanceOf |
| 4931 | * or `HCheckCast`. |
| 4932 | */ |
| 4933 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4934 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4935 | kExactCheck, // Can do a single class compare. |
| 4936 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4937 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4938 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4939 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4940 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4941 | }; |
| 4942 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4943 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4944 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4945 | HInstanceOf(HInstruction* object, |
| 4946 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4947 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4948 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4949 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4950 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4951 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4952 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4953 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4954 | SetRawInputAt(0, object); |
| 4955 | SetRawInputAt(1, constant); |
| 4956 | } |
| 4957 | |
| 4958 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4959 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4960 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4961 | return true; |
| 4962 | } |
| 4963 | |
| 4964 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4965 | return false; |
| 4966 | } |
| 4967 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4968 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4969 | |
| 4970 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4971 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4972 | // Used only in code generation. |
| 4973 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4974 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4975 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4976 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4977 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4978 | ? SideEffects::None() |
| 4979 | // Mips currently does runtime calls for any other checks. |
| 4980 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4981 | } |
| 4982 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4983 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4984 | |
| 4985 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4986 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4987 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4988 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4989 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4990 | }; |
| 4991 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4992 | class HBoundType : public HExpression<1> { |
| 4993 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4994 | // Constructs an HBoundType with the given upper_bound. |
| 4995 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4996 | HBoundType(HInstruction* input, |
| 4997 | ReferenceTypeInfo upper_bound, |
| 4998 | bool upper_can_be_null, |
| 4999 | uint32_t dex_pc = kNoDexPc) |
| 5000 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5001 | upper_bound_(upper_bound), |
| 5002 | upper_can_be_null_(upper_can_be_null), |
| 5003 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5004 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5005 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5006 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5007 | } |
| 5008 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5009 | // GetUpper* should only be used in reference type propagation. |
| 5010 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5011 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5012 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5013 | void SetCanBeNull(bool can_be_null) { |
| 5014 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5015 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5016 | } |
| 5017 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5018 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5019 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5020 | DECLARE_INSTRUCTION(BoundType); |
| 5021 | |
| 5022 | private: |
| 5023 | // Encodes the most upper class that this instruction can have. In other words |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5024 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5025 | // It is used to bound the type in cases like: |
| 5026 | // if (x instanceof ClassX) { |
| 5027 | // // uper_bound_ will be ClassX |
| 5028 | // } |
| 5029 | const ReferenceTypeInfo upper_bound_; |
| 5030 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5031 | // is false then can_be_null_ cannot be true). |
| 5032 | const bool upper_can_be_null_; |
| 5033 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5034 | |
| 5035 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5036 | }; |
| 5037 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5038 | class HCheckCast : public HTemplateInstruction<2> { |
| 5039 | public: |
| 5040 | HCheckCast(HInstruction* object, |
| 5041 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5042 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5043 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5044 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5045 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5046 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5047 | SetRawInputAt(0, object); |
| 5048 | SetRawInputAt(1, constant); |
| 5049 | } |
| 5050 | |
| 5051 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5052 | |
| 5053 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5054 | return true; |
| 5055 | } |
| 5056 | |
| 5057 | bool NeedsEnvironment() const OVERRIDE { |
| 5058 | // Instruction may throw a CheckCastError. |
| 5059 | return true; |
| 5060 | } |
| 5061 | |
| 5062 | bool CanThrow() const OVERRIDE { return true; } |
| 5063 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5064 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5065 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5066 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5067 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5068 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5069 | |
| 5070 | DECLARE_INSTRUCTION(CheckCast); |
| 5071 | |
| 5072 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5073 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5074 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5075 | |
| 5076 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5077 | }; |
| 5078 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5079 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5080 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5081 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5082 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5083 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5084 | barrier_kind_(barrier_kind) {} |
| 5085 | |
| 5086 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5087 | |
| 5088 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5089 | |
| 5090 | private: |
| 5091 | const MemBarrierKind barrier_kind_; |
| 5092 | |
| 5093 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5094 | }; |
| 5095 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5096 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5097 | public: |
| 5098 | enum OperationKind { |
| 5099 | kEnter, |
| 5100 | kExit, |
| 5101 | }; |
| 5102 | |
| 5103 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5104 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5105 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5106 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5107 | SetRawInputAt(0, object); |
| 5108 | } |
| 5109 | |
| 5110 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5111 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5112 | |
| 5113 | bool CanThrow() const OVERRIDE { |
| 5114 | // Verifier guarantees that monitor-exit cannot throw. |
| 5115 | // This is important because it allows the HGraphBuilder to remove |
| 5116 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5117 | return IsEnter(); |
| 5118 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5119 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5120 | |
| 5121 | bool IsEnter() const { return kind_ == kEnter; } |
| 5122 | |
| 5123 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5124 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5125 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5126 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5127 | |
| 5128 | private: |
| 5129 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5130 | }; |
| 5131 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5132 | /** |
| 5133 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5134 | * of a String to a call to a StringFactory. Only baseline will see |
| 5135 | * the node at code generation, where it will be be treated as null. |
| 5136 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5137 | * in the instruction simplifier. |
| 5138 | */ |
| 5139 | class HFakeString : public HTemplateInstruction<0> { |
| 5140 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5141 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5142 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5143 | |
| 5144 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5145 | |
| 5146 | DECLARE_INSTRUCTION(FakeString); |
| 5147 | |
| 5148 | private: |
| 5149 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5150 | }; |
| 5151 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5152 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5153 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5154 | MoveOperands(Location source, |
| 5155 | Location destination, |
| 5156 | Primitive::Type type, |
| 5157 | HInstruction* instruction) |
| 5158 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5159 | |
| 5160 | Location GetSource() const { return source_; } |
| 5161 | Location GetDestination() const { return destination_; } |
| 5162 | |
| 5163 | void SetSource(Location value) { source_ = value; } |
| 5164 | void SetDestination(Location value) { destination_ = value; } |
| 5165 | |
| 5166 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5167 | // destination (but not the source). |
| 5168 | Location MarkPending() { |
| 5169 | DCHECK(!IsPending()); |
| 5170 | Location dest = destination_; |
| 5171 | destination_ = Location::NoLocation(); |
| 5172 | return dest; |
| 5173 | } |
| 5174 | |
| 5175 | void ClearPending(Location dest) { |
| 5176 | DCHECK(IsPending()); |
| 5177 | destination_ = dest; |
| 5178 | } |
| 5179 | |
| 5180 | bool IsPending() const { |
| 5181 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5182 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5183 | } |
| 5184 | |
| 5185 | // True if this blocks a move from the given location. |
| 5186 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5187 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5188 | } |
| 5189 | |
| 5190 | // A move is redundant if it's been eliminated, if its source and |
| 5191 | // destination are the same, or if its destination is unneeded. |
| 5192 | bool IsRedundant() const { |
| 5193 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5194 | } |
| 5195 | |
| 5196 | // We clear both operands to indicate move that's been eliminated. |
| 5197 | void Eliminate() { |
| 5198 | source_ = destination_ = Location::NoLocation(); |
| 5199 | } |
| 5200 | |
| 5201 | bool IsEliminated() const { |
| 5202 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5203 | return source_.IsInvalid(); |
| 5204 | } |
| 5205 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5206 | Primitive::Type GetType() const { return type_; } |
| 5207 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5208 | bool Is64BitMove() const { |
| 5209 | return Primitive::Is64BitType(type_); |
| 5210 | } |
| 5211 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5212 | HInstruction* GetInstruction() const { return instruction_; } |
| 5213 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5214 | private: |
| 5215 | Location source_; |
| 5216 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5217 | // The type this move is for. |
| 5218 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5219 | // The instruction this move is assocatied with. Null when this move is |
| 5220 | // for moving an input in the expected locations of user (including a phi user). |
| 5221 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5222 | // in the same parallel move. |
| 5223 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5224 | }; |
| 5225 | |
| 5226 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5227 | |
| 5228 | class HParallelMove : public HTemplateInstruction<0> { |
| 5229 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5230 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5231 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5232 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5233 | moves_.reserve(kDefaultNumberOfMoves); |
| 5234 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5235 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5236 | void AddMove(Location source, |
| 5237 | Location destination, |
| 5238 | Primitive::Type type, |
| 5239 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5240 | DCHECK(source.IsValid()); |
| 5241 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5242 | if (kIsDebugBuild) { |
| 5243 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5244 | for (const MoveOperands& move : moves_) { |
| 5245 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5246 | // Special case the situation where the move is for the spill slot |
| 5247 | // of the instruction. |
| 5248 | if ((GetPrevious() == instruction) |
| 5249 | || ((GetPrevious() == nullptr) |
| 5250 | && instruction->IsPhi() |
| 5251 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5252 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5253 | << "Doing parallel moves for the same instruction."; |
| 5254 | } else { |
| 5255 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5256 | } |
| 5257 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5258 | } |
| 5259 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5260 | for (const MoveOperands& move : moves_) { |
| 5261 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5262 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5263 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5264 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5265 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5266 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5267 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5268 | } |
| 5269 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5270 | MoveOperands* MoveOperandsAt(size_t index) { |
| 5271 | DCHECK_LT(index, moves_.size()); |
| 5272 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5273 | } |
| 5274 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5275 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5276 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5277 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5278 | |
| 5279 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5280 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5281 | |
| 5282 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5283 | }; |
| 5284 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5285 | } // namespace art |
| 5286 | |
| 5287 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5288 | #include "nodes_x86.h" |
| 5289 | #endif |
| 5290 | |
| 5291 | namespace art { |
| 5292 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5293 | class HGraphVisitor : public ValueObject { |
| 5294 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5295 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5296 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5297 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5298 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5299 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5300 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5301 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5302 | void VisitInsertionOrder(); |
| 5303 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5304 | // Visit the graph following dominator tree reverse post-order. |
| 5305 | void VisitReversePostOrder(); |
| 5306 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5307 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5308 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5309 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5310 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5311 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5312 | |
| 5313 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5314 | |
| 5315 | #undef DECLARE_VISIT_INSTRUCTION |
| 5316 | |
| 5317 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5318 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5319 | |
| 5320 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5321 | }; |
| 5322 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5323 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5324 | public: |
| 5325 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5326 | virtual ~HGraphDelegateVisitor() {} |
| 5327 | |
| 5328 | // Visit functions that delegate to to super class. |
| 5329 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5330 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5331 | |
| 5332 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5333 | |
| 5334 | #undef DECLARE_VISIT_INSTRUCTION |
| 5335 | |
| 5336 | private: |
| 5337 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5338 | }; |
| 5339 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5340 | class HInsertionOrderIterator : public ValueObject { |
| 5341 | public: |
| 5342 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5343 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5344 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
| 5345 | HBasicBlock* Current() const { return graph_.GetBlock(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5346 | void Advance() { ++index_; } |
| 5347 | |
| 5348 | private: |
| 5349 | const HGraph& graph_; |
| 5350 | size_t index_; |
| 5351 | |
| 5352 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5353 | }; |
| 5354 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5355 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5356 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5357 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5358 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5359 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5360 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5361 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5362 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5363 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5364 | void Advance() { ++index_; } |
| 5365 | |
| 5366 | private: |
| 5367 | const HGraph& graph_; |
| 5368 | size_t index_; |
| 5369 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5370 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5371 | }; |
| 5372 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5373 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5374 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5375 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5376 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5377 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5378 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5379 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5380 | |
| 5381 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5382 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5383 | void Advance() { --index_; } |
| 5384 | |
| 5385 | private: |
| 5386 | const HGraph& graph_; |
| 5387 | size_t index_; |
| 5388 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5389 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5390 | }; |
| 5391 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5392 | class HLinearPostOrderIterator : public ValueObject { |
| 5393 | public: |
| 5394 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5395 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5396 | |
| 5397 | bool Done() const { return index_ == 0; } |
| 5398 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5399 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5400 | |
| 5401 | void Advance() { |
| 5402 | --index_; |
| 5403 | DCHECK_GE(index_, 0U); |
| 5404 | } |
| 5405 | |
| 5406 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5407 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5408 | size_t index_; |
| 5409 | |
| 5410 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5411 | }; |
| 5412 | |
| 5413 | class HLinearOrderIterator : public ValueObject { |
| 5414 | public: |
| 5415 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5416 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5417 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5418 | bool Done() const { return index_ == order_.size(); } |
| 5419 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5420 | void Advance() { ++index_; } |
| 5421 | |
| 5422 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5423 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5424 | size_t index_; |
| 5425 | |
| 5426 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5427 | }; |
| 5428 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5429 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5430 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5431 | // block id. |
| 5432 | class HBlocksInLoopIterator : public ValueObject { |
| 5433 | public: |
| 5434 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5435 | : blocks_in_loop_(info.GetBlocks()), |
| 5436 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5437 | index_(0) { |
| 5438 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5439 | Advance(); |
| 5440 | } |
| 5441 | } |
| 5442 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5443 | bool Done() const { return index_ == blocks_.size(); } |
| 5444 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5445 | void Advance() { |
| 5446 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5447 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5448 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5449 | break; |
| 5450 | } |
| 5451 | } |
| 5452 | } |
| 5453 | |
| 5454 | private: |
| 5455 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5456 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5457 | size_t index_; |
| 5458 | |
| 5459 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5460 | }; |
| 5461 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5462 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5463 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5464 | // post order. |
| 5465 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5466 | public: |
| 5467 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5468 | : blocks_in_loop_(info.GetBlocks()), |
| 5469 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5470 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5471 | DCHECK(!blocks_.empty()); |
| 5472 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5473 | Advance(); |
| 5474 | } |
| 5475 | } |
| 5476 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5477 | bool Done() const { return index_ == blocks_.size(); } |
| 5478 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5479 | void Advance() { |
| 5480 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5481 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5482 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5483 | break; |
| 5484 | } |
| 5485 | } |
| 5486 | } |
| 5487 | |
| 5488 | private: |
| 5489 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5490 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5491 | size_t index_; |
| 5492 | |
| 5493 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5494 | }; |
| 5495 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5496 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5497 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5498 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5499 | : constant->AsLongConstant()->GetValue(); |
| 5500 | } |
| 5501 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5502 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5503 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5504 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5505 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5506 | // times and provide different class resolution but no two class loaders should ever |
| 5507 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5508 | // all sorts of weird failures. |
| 5509 | return &lhs == &rhs; |
| 5510 | } |
| 5511 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5512 | } // namespace art |
| 5513 | |
| 5514 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |