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 | #include "utils/growable_array.h" |
| 39 | |
| 40 | namespace art { |
| 41 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 42 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 43 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 44 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 45 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 46 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 47 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 48 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 49 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 50 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 51 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 52 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 53 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 54 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 55 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 56 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 57 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 58 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 59 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 60 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 61 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 62 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 63 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 64 | namespace mirror { |
| 65 | class DexCache; |
| 66 | } // namespace mirror |
| 67 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 68 | static const int kDefaultNumberOfBlocks = 8; |
| 69 | static const int kDefaultNumberOfSuccessors = 2; |
| 70 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 72 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 73 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 74 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 75 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 76 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 77 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 78 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
| 79 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 80 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 81 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 82 | static constexpr uint32_t kNoDexPc = -1; |
| 83 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 84 | enum IfCondition { |
| 85 | kCondEQ, |
| 86 | kCondNE, |
| 87 | kCondLT, |
| 88 | kCondLE, |
| 89 | kCondGT, |
| 90 | kCondGE, |
| 91 | }; |
| 92 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 93 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 94 | public: |
| 95 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 96 | |
| 97 | void AddInstruction(HInstruction* instruction); |
| 98 | void RemoveInstruction(HInstruction* instruction); |
| 99 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 100 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 101 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 102 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 103 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 104 | // Return true if this list contains `instruction`. |
| 105 | bool Contains(HInstruction* instruction) const; |
| 106 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 107 | // Return true if `instruction1` is found before `instruction2` in |
| 108 | // this instruction list and false otherwise. Abort if none |
| 109 | // of these instructions is found. |
| 110 | bool FoundBefore(const HInstruction* instruction1, |
| 111 | const HInstruction* instruction2) const; |
| 112 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 113 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 114 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 115 | |
| 116 | // Update the block of all instructions to be `block`. |
| 117 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 118 | |
| 119 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 120 | void Add(const HInstructionList& instruction_list); |
| 121 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 122 | // Return the number of instructions in the list. This is an expensive operation. |
| 123 | size_t CountSize() const; |
| 124 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 125 | private: |
| 126 | HInstruction* first_instruction_; |
| 127 | HInstruction* last_instruction_; |
| 128 | |
| 129 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 130 | friend class HGraph; |
| 131 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 132 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 133 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 134 | |
| 135 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 136 | }; |
| 137 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 138 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 139 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 140 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 141 | HGraph(ArenaAllocator* arena, |
| 142 | const DexFile& dex_file, |
| 143 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 144 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 145 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 146 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 147 | bool debuggable = false, |
| 148 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 149 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 150 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 151 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 152 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 153 | entry_block_(nullptr), |
| 154 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 155 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 156 | number_of_vregs_(0), |
| 157 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 158 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 159 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 160 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 161 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 162 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 163 | dex_file_(dex_file), |
| 164 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 165 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 166 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 167 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 168 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 169 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 170 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 171 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 172 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 173 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 174 | cached_current_method_(nullptr) { |
| 175 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 176 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 177 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 178 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 179 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 180 | |
| 181 | HBasicBlock* GetBlock(size_t id) const { |
| 182 | DCHECK_LT(id, blocks_.size()); |
| 183 | return blocks_[id]; |
| 184 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 185 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 186 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 187 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 188 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 189 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 190 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 191 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 192 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 193 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 194 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 195 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 196 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 197 | // Try building the SSA form of this graph, with dominance computation and loop |
| 198 | // recognition. Returns whether it was successful in doing all these steps. |
| 199 | bool TryBuildingSsa() { |
| 200 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 201 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 202 | // elimination phase checks the consistency of the graph when doing a post-order |
| 203 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 204 | // users remaining when being visited. |
| 205 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 206 | // Precompute per-block try membership before entering the SSA builder, |
| 207 | // which needs the information to build catch block phis from values of |
| 208 | // locals at throwing instructions inside try blocks. |
| 209 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 210 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 211 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 212 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | } |
| 214 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 215 | void ComputeDominanceInformation(); |
| 216 | void ClearDominanceInformation(); |
| 217 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 218 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 219 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 220 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 221 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 222 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 223 | // Analyze all natural loops in this graph. Returns false if one |
| 224 | // loop is not natural, that is the header does not dominate the |
| 225 | // back edge. |
| 226 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 227 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 228 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 229 | // order and loop information. |
| 230 | void ComputeTryBlockInformation(); |
| 231 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 232 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 233 | // Returns the instruction used to replace the invoke expression or null if the |
| 234 | // invoke is for a void method. |
| 235 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 236 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 237 | // Need to add a couple of blocks to test if the loop body is entered and |
| 238 | // put deoptimization instructions, etc. |
| 239 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 240 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 241 | // Removes `block` from the graph. |
| 242 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 243 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 244 | // Splits the edge between `block` and `successor` while preserving the |
| 245 | // indices in the predecessor/successor lists. If there are multiple edges |
| 246 | // between the blocks, the lowest indices are used. |
| 247 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 248 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 249 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 250 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 251 | void SimplifyLoop(HBasicBlock* header); |
| 252 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 253 | int32_t GetNextInstructionId() { |
| 254 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 255 | return current_instruction_id_++; |
| 256 | } |
| 257 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 258 | int32_t GetCurrentInstructionId() const { |
| 259 | return current_instruction_id_; |
| 260 | } |
| 261 | |
| 262 | void SetCurrentInstructionId(int32_t id) { |
| 263 | current_instruction_id_ = id; |
| 264 | } |
| 265 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 266 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 267 | return maximum_number_of_out_vregs_; |
| 268 | } |
| 269 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 270 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 271 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 272 | } |
| 273 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 274 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 275 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 276 | } |
| 277 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 278 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 279 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 280 | } |
| 281 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 282 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 283 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 284 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 285 | } |
| 286 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 287 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 288 | number_of_vregs_ = number_of_vregs; |
| 289 | } |
| 290 | |
| 291 | uint16_t GetNumberOfVRegs() const { |
| 292 | return number_of_vregs_; |
| 293 | } |
| 294 | |
| 295 | void SetNumberOfInVRegs(uint16_t value) { |
| 296 | number_of_in_vregs_ = value; |
| 297 | } |
| 298 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 299 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 300 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 301 | return number_of_vregs_ - number_of_in_vregs_; |
| 302 | } |
| 303 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 304 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 305 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 306 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 307 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 308 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 309 | return linear_order_; |
| 310 | } |
| 311 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 312 | bool HasBoundsChecks() const { |
| 313 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 316 | void SetHasBoundsChecks(bool value) { |
| 317 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 318 | } |
| 319 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 320 | bool ShouldGenerateConstructorBarrier() const { |
| 321 | return should_generate_constructor_barrier_; |
| 322 | } |
| 323 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 324 | bool IsDebuggable() const { return debuggable_; } |
| 325 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 326 | // 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] | 327 | // already, it is created and inserted into the graph. This method is only for |
| 328 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 329 | 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] | 330 | |
| 331 | // TODO: This is problematic for the consistency of reference type propagation |
| 332 | // because it can be created anytime after the pass and thus it will be left |
| 333 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 334 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 335 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 336 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 337 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 338 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 339 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 340 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 341 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 342 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 343 | 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] | 344 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 345 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 346 | 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] | 347 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 348 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 349 | HCurrentMethod* GetCurrentMethod(); |
| 350 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 351 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 352 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 353 | const DexFile& GetDexFile() const { |
| 354 | return dex_file_; |
| 355 | } |
| 356 | |
| 357 | uint32_t GetMethodIdx() const { |
| 358 | return method_idx_; |
| 359 | } |
| 360 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 361 | InvokeType GetInvokeType() const { |
| 362 | return invoke_type_; |
| 363 | } |
| 364 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 365 | InstructionSet GetInstructionSet() const { |
| 366 | return instruction_set_; |
| 367 | } |
| 368 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 369 | bool HasTryCatch() const { return has_try_catch_; } |
| 370 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 371 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 372 | private: |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 373 | void VisitBlockForDominatorTree(HBasicBlock* block, |
| 374 | HBasicBlock* predecessor, |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 375 | ArenaVector<size_t>* visits); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 376 | void FindBackEdges(ArenaBitVector* visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 377 | void VisitBlockForBackEdges(HBasicBlock* block, |
| 378 | ArenaBitVector* visited, |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 379 | ArenaBitVector* visiting); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 380 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 381 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 382 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 383 | template <class InstructionType, typename ValueType> |
| 384 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 385 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 386 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 387 | // Try to find an existing constant of the given value. |
| 388 | InstructionType* constant = nullptr; |
| 389 | auto cached_constant = cache->find(value); |
| 390 | if (cached_constant != cache->end()) { |
| 391 | constant = cached_constant->second; |
| 392 | } |
| 393 | |
| 394 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 395 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 396 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 397 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 398 | cache->Overwrite(value, constant); |
| 399 | InsertConstant(constant); |
| 400 | } |
| 401 | return constant; |
| 402 | } |
| 403 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 404 | void InsertConstant(HConstant* instruction); |
| 405 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 406 | // Cache a float constant into the graph. This method should only be |
| 407 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 408 | void CacheFloatConstant(HFloatConstant* constant); |
| 409 | |
| 410 | // See CacheFloatConstant comment. |
| 411 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 412 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 413 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 414 | |
| 415 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 416 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 417 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 418 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 419 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 420 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 421 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 422 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 423 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 424 | HBasicBlock* entry_block_; |
| 425 | HBasicBlock* exit_block_; |
| 426 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 427 | // 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] | 428 | uint16_t maximum_number_of_out_vregs_; |
| 429 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 430 | // The number of virtual registers in this method. Contains the parameters. |
| 431 | uint16_t number_of_vregs_; |
| 432 | |
| 433 | // The number of virtual registers used by parameters of this method. |
| 434 | uint16_t number_of_in_vregs_; |
| 435 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 436 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 437 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 438 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 439 | // Has bounds checks. We can totally skip BCE if it's false. |
| 440 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 441 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 442 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 443 | // try/catch-related passes if false. |
| 444 | bool has_try_catch_; |
| 445 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 446 | // Indicates whether the graph should be compiled in a way that |
| 447 | // ensures full debuggability. If false, we can apply more |
| 448 | // aggressive optimizations that may limit the level of debugging. |
| 449 | const bool debuggable_; |
| 450 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 451 | // 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] | 452 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 453 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 454 | // The dex file from which the method is from. |
| 455 | const DexFile& dex_file_; |
| 456 | |
| 457 | // The method index in the dex file. |
| 458 | const uint32_t method_idx_; |
| 459 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 460 | // If inlined, this encodes how the callee is being invoked. |
| 461 | const InvokeType invoke_type_; |
| 462 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 463 | // Whether the graph has been transformed to SSA form. Only used |
| 464 | // in debug mode to ensure we are not using properties only valid |
| 465 | // for non-SSA form (like the number of temporaries). |
| 466 | bool in_ssa_form_; |
| 467 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 468 | const bool should_generate_constructor_barrier_; |
| 469 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 470 | const InstructionSet instruction_set_; |
| 471 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 472 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 473 | HNullConstant* cached_null_constant_; |
| 474 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 475 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 476 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 477 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 478 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 479 | HCurrentMethod* cached_current_method_; |
| 480 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 481 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 482 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 483 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 484 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 485 | }; |
| 486 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 487 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 488 | public: |
| 489 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 490 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 491 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 492 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 493 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 494 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 495 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 496 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 497 | |
| 498 | HBasicBlock* GetHeader() const { |
| 499 | return header_; |
| 500 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 501 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 502 | void SetHeader(HBasicBlock* block) { |
| 503 | header_ = block; |
| 504 | } |
| 505 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 506 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 507 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 508 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 509 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 510 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 511 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 514 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 515 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 516 | } |
| 517 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 518 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 519 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 520 | } |
| 521 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 522 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 523 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 524 | } |
| 525 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 526 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 527 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 528 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 529 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 532 | // Returns the lifetime position of the back edge that has the |
| 533 | // greatest lifetime position. |
| 534 | size_t GetLifetimeEnd() const; |
| 535 | |
| 536 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 537 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 538 | } |
| 539 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 540 | // 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] | 541 | // that is the header dominates the back edge. |
| 542 | bool Populate(); |
| 543 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 544 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 545 | // Populate(). If there are no back edges left, the loop info is completely |
| 546 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 547 | // inner loops first. |
| 548 | void Update(); |
| 549 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 550 | // Returns whether this loop information contains `block`. |
| 551 | // Note that this loop information *must* be populated before entering this function. |
| 552 | bool Contains(const HBasicBlock& block) const; |
| 553 | |
| 554 | // Returns whether this loop information is an inner loop of `other`. |
| 555 | // Note that `other` *must* be populated before entering this function. |
| 556 | bool IsIn(const HLoopInformation& other) const; |
| 557 | |
| 558 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 559 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 560 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 561 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 562 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 563 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 564 | // Internal recursive implementation of `Populate`. |
| 565 | void PopulateRecursive(HBasicBlock* block); |
| 566 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 567 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 568 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 569 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 570 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 571 | |
| 572 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 573 | }; |
| 574 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 575 | // Stores try/catch information for basic blocks. |
| 576 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 577 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 578 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 579 | public: |
| 580 | // Try block information constructor. |
| 581 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 582 | : try_entry_(&try_entry), |
| 583 | catch_dex_file_(nullptr), |
| 584 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 585 | DCHECK(try_entry_ != nullptr); |
| 586 | } |
| 587 | |
| 588 | // Catch block information constructor. |
| 589 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 590 | : try_entry_(nullptr), |
| 591 | catch_dex_file_(&dex_file), |
| 592 | catch_type_index_(catch_type_index) {} |
| 593 | |
| 594 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 595 | |
| 596 | const HTryBoundary& GetTryEntry() const { |
| 597 | DCHECK(IsTryBlock()); |
| 598 | return *try_entry_; |
| 599 | } |
| 600 | |
| 601 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 602 | |
| 603 | bool IsCatchAllTypeIndex() const { |
| 604 | DCHECK(IsCatchBlock()); |
| 605 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 606 | } |
| 607 | |
| 608 | uint16_t GetCatchTypeIndex() const { |
| 609 | DCHECK(IsCatchBlock()); |
| 610 | return catch_type_index_; |
| 611 | } |
| 612 | |
| 613 | const DexFile& GetCatchDexFile() const { |
| 614 | DCHECK(IsCatchBlock()); |
| 615 | return *catch_dex_file_; |
| 616 | } |
| 617 | |
| 618 | private: |
| 619 | // One of possibly several TryBoundary instructions entering the block's try. |
| 620 | // Only set for try blocks. |
| 621 | const HTryBoundary* try_entry_; |
| 622 | |
| 623 | // Exception type information. Only set for catch blocks. |
| 624 | const DexFile* catch_dex_file_; |
| 625 | const uint16_t catch_type_index_; |
| 626 | }; |
| 627 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 628 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 629 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 630 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 631 | // A block in a method. Contains the list of instructions represented |
| 632 | // as a double linked list. Each block knows its predecessors and |
| 633 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 634 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 635 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 636 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 637 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 638 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 639 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 640 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 641 | loop_information_(nullptr), |
| 642 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 643 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 644 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 645 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 646 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 647 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 648 | try_catch_information_(nullptr) { |
| 649 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 650 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 651 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 652 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 653 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 654 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 655 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 658 | HBasicBlock* GetPredecessor(size_t pred_idx) const { |
| 659 | DCHECK_LT(pred_idx, predecessors_.size()); |
| 660 | return predecessors_[pred_idx]; |
| 661 | } |
| 662 | |
| 663 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 664 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 665 | } |
| 666 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 667 | HBasicBlock* GetSuccessor(size_t succ_idx) const { |
| 668 | DCHECK_LT(succ_idx, successors_.size()); |
| 669 | return successors_[succ_idx]; |
| 670 | } |
| 671 | |
| 672 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 673 | return ContainsElement(successors_, block, start_from); |
| 674 | } |
| 675 | |
| 676 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 677 | return dominated_blocks_; |
| 678 | } |
| 679 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 680 | bool IsEntryBlock() const { |
| 681 | return graph_->GetEntryBlock() == this; |
| 682 | } |
| 683 | |
| 684 | bool IsExitBlock() const { |
| 685 | return graph_->GetExitBlock() == this; |
| 686 | } |
| 687 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 688 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 689 | bool IsSingleTryBoundary() const; |
| 690 | |
| 691 | // Returns true if this block emits nothing but a jump. |
| 692 | bool IsSingleJump() const { |
| 693 | HLoopInformation* loop_info = GetLoopInformation(); |
| 694 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 695 | // Back edges generate a suspend check. |
| 696 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 697 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 698 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 699 | void AddBackEdge(HBasicBlock* back_edge) { |
| 700 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 701 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 702 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 703 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 704 | loop_information_->AddBackEdge(back_edge); |
| 705 | } |
| 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 708 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 709 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 710 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 711 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 712 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 713 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 714 | HBasicBlock* GetDominator() const { return dominator_; } |
| 715 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 716 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 717 | |
| 718 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 719 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 720 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 721 | |
| 722 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 723 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 724 | } |
| 725 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 726 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | |
| 728 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 729 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 730 | } |
| 731 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 732 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 733 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 734 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 735 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 736 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 737 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 738 | |
| 739 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | successors_.push_back(block); |
| 741 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 744 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 746 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->predecessors_.push_back(this); |
| 748 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 751 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 752 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 753 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 754 | new_block->successors_.push_back(this); |
| 755 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 756 | } |
| 757 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 758 | // Insert `this` between `predecessor` and `successor. This method |
| 759 | // preserves the indicies, and will update the first edge found between |
| 760 | // `predecessor` and `successor`. |
| 761 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 762 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 763 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | successor->predecessors_[predecessor_index] = this; |
| 765 | predecessor->successors_[successor_index] = this; |
| 766 | successors_.push_back(successor); |
| 767 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 768 | } |
| 769 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 770 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 771 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 772 | } |
| 773 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 774 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 775 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 776 | } |
| 777 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 780 | } |
| 781 | |
| 782 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 783 | predecessors_.push_back(block); |
| 784 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 785 | } |
| 786 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 787 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | DCHECK_EQ(predecessors_.size(), 2u); |
| 789 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 790 | } |
| 791 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 792 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 793 | DCHECK_EQ(successors_.size(), 2u); |
| 794 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 795 | } |
| 796 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 797 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 798 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 799 | } |
| 800 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 802 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 803 | } |
| 804 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 806 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| 807 | return GetPredecessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| 812 | return GetSuccessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| 815 | // Returns whether the first occurrence of `predecessor` in the list of |
| 816 | // predecessors is at index `idx`. |
| 817 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 818 | DCHECK_EQ(GetPredecessor(idx), predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 819 | return GetPredecessorIndexOf(predecessor) == idx; |
| 820 | } |
| 821 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 822 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 823 | // these are stored at the beginning of the successor list. |
| 824 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 825 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 826 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | |
| 828 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 829 | // created, latter block. Note that this method will add the block to the |
| 830 | // graph, create a Goto at the end of the former block and will create an edge |
| 831 | // between the blocks. It will not, however, update the reverse post order or |
| 832 | // loop information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 833 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 834 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 835 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 836 | // created block. Note that this method just updates raw block information, |
| 837 | // like predecessors, successors, dominators, and instruction list. It does not |
| 838 | // update the graph, reverse post order, loop information, nor make sure the |
| 839 | // blocks are consistent (for example ending with a control flow instruction). |
| 840 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 841 | |
| 842 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 843 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 844 | // that this method does not update the graph, reverse post order, loop |
| 845 | // information, nor make sure the blocks are consistent (for example ending |
| 846 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 847 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 848 | |
| 849 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 850 | // of `this` are moved to `other`. |
| 851 | // Note that this method does not update the graph, reverse post order, loop |
| 852 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 853 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 854 | void ReplaceWith(HBasicBlock* other); |
| 855 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 856 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 857 | // order, links to predecessors, successors, dominators and deletes the block |
| 858 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 859 | // predecessor of `other` and vice versa. |
| 860 | void MergeWith(HBasicBlock* other); |
| 861 | |
| 862 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 863 | // removes it from all loops it is included in and eventually from the graph. |
| 864 | // The block must not dominate any other block. Predecessors and successors |
| 865 | // are safely updated. |
| 866 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 867 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 868 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 869 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 870 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 871 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 872 | // Replace instruction `initial` with `replacement` within this block. |
| 873 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 874 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 875 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 876 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 877 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 878 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 879 | // instruction is not in use and removes it from the use lists of its inputs. |
| 880 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 881 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 882 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 883 | |
| 884 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 885 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 886 | } |
| 887 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 888 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 889 | DCHECK(IsLoopHeader()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 890 | return GetPredecessor(0) == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 891 | } |
| 892 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 893 | HLoopInformation* GetLoopInformation() const { |
| 894 | return loop_information_; |
| 895 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 896 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 897 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 898 | // 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] | 899 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 900 | void SetInLoop(HLoopInformation* info) { |
| 901 | if (IsLoopHeader()) { |
| 902 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 903 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 904 | loop_information_ = info; |
| 905 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 906 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 907 | // Note that a non loop header having a loop information means this loop information |
| 908 | // has already been populated |
| 909 | loop_information_ = info; |
| 910 | } else { |
| 911 | // Block is part of an inner loop. Do not update the loop information. |
| 912 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 913 | // at this point, because this method is being called while populating `info`. |
| 914 | } |
| 915 | } |
| 916 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 917 | // Raw update of the loop information. |
| 918 | void SetLoopInformation(HLoopInformation* info) { |
| 919 | loop_information_ = info; |
| 920 | } |
| 921 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 922 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 923 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 924 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 925 | |
| 926 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 927 | try_catch_information_ = try_catch_information; |
| 928 | } |
| 929 | |
| 930 | bool IsTryBlock() const { |
| 931 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 932 | } |
| 933 | |
| 934 | bool IsCatchBlock() const { |
| 935 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 936 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 937 | |
| 938 | // Returns the try entry that this block's successors should have. They will |
| 939 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 940 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 941 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 942 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 943 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 944 | bool Dominates(HBasicBlock* block) const; |
| 945 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 946 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 947 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 948 | |
| 949 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 950 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 951 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 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) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1059 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1060 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1061 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1062 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1063 | M(Return, Instruction) \ |
| 1064 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1065 | M(Shl, BinaryOperation) \ |
| 1066 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1067 | M(StaticFieldGet, Instruction) \ |
| 1068 | M(StaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1069 | M(StoreLocal, Instruction) \ |
| 1070 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1071 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1072 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1073 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1074 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1075 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1076 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1077 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1078 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1079 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1080 | |
| 1081 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1082 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1083 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1084 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1085 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1086 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1087 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1088 | |
| 1089 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1090 | |
| 1091 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1092 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1093 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1094 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1095 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1096 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1097 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1098 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1099 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1100 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1101 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1102 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1103 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1104 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1105 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1106 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1107 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1108 | #undef FORWARD_DECLARATION |
| 1109 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1110 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1111 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1112 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1113 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1114 | H##type* As##type() OVERRIDE { return this; } \ |
| 1115 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1116 | return other->Is##type(); \ |
| 1117 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1118 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1119 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1120 | template <typename T> class HUseList; |
| 1121 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1122 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1123 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1124 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1125 | HUseListNode* GetPrevious() const { return prev_; } |
| 1126 | HUseListNode* GetNext() const { return next_; } |
| 1127 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1128 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1129 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1130 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1131 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1132 | HUseListNode(T user, size_t index) |
| 1133 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1134 | |
| 1135 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1136 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1137 | HUseListNode<T>* prev_; |
| 1138 | HUseListNode<T>* next_; |
| 1139 | |
| 1140 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1141 | |
| 1142 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1143 | }; |
| 1144 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1145 | template <typename T> |
| 1146 | class HUseList : public ValueObject { |
| 1147 | public: |
| 1148 | HUseList() : first_(nullptr) {} |
| 1149 | |
| 1150 | void Clear() { |
| 1151 | first_ = nullptr; |
| 1152 | } |
| 1153 | |
| 1154 | // Adds a new entry at the beginning of the use list and returns |
| 1155 | // the newly created node. |
| 1156 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1157 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1158 | if (IsEmpty()) { |
| 1159 | first_ = new_node; |
| 1160 | } else { |
| 1161 | first_->prev_ = new_node; |
| 1162 | new_node->next_ = first_; |
| 1163 | first_ = new_node; |
| 1164 | } |
| 1165 | return new_node; |
| 1166 | } |
| 1167 | |
| 1168 | HUseListNode<T>* GetFirst() const { |
| 1169 | return first_; |
| 1170 | } |
| 1171 | |
| 1172 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1173 | DCHECK(node != nullptr); |
| 1174 | DCHECK(Contains(node)); |
| 1175 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1176 | if (node->prev_ != nullptr) { |
| 1177 | node->prev_->next_ = node->next_; |
| 1178 | } |
| 1179 | if (node->next_ != nullptr) { |
| 1180 | node->next_->prev_ = node->prev_; |
| 1181 | } |
| 1182 | if (node == first_) { |
| 1183 | first_ = node->next_; |
| 1184 | } |
| 1185 | } |
| 1186 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1187 | bool Contains(const HUseListNode<T>* node) const { |
| 1188 | if (node == nullptr) { |
| 1189 | return false; |
| 1190 | } |
| 1191 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1192 | if (current == node) { |
| 1193 | return true; |
| 1194 | } |
| 1195 | } |
| 1196 | return false; |
| 1197 | } |
| 1198 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1199 | bool IsEmpty() const { |
| 1200 | return first_ == nullptr; |
| 1201 | } |
| 1202 | |
| 1203 | bool HasOnlyOneUse() const { |
| 1204 | return first_ != nullptr && first_->next_ == nullptr; |
| 1205 | } |
| 1206 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1207 | size_t SizeSlow() const { |
| 1208 | size_t count = 0; |
| 1209 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1210 | ++count; |
| 1211 | } |
| 1212 | return count; |
| 1213 | } |
| 1214 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1215 | private: |
| 1216 | HUseListNode<T>* first_; |
| 1217 | }; |
| 1218 | |
| 1219 | template<typename T> |
| 1220 | class HUseIterator : public ValueObject { |
| 1221 | public: |
| 1222 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1223 | |
| 1224 | bool Done() const { return current_ == nullptr; } |
| 1225 | |
| 1226 | void Advance() { |
| 1227 | DCHECK(!Done()); |
| 1228 | current_ = current_->GetNext(); |
| 1229 | } |
| 1230 | |
| 1231 | HUseListNode<T>* Current() const { |
| 1232 | DCHECK(!Done()); |
| 1233 | return current_; |
| 1234 | } |
| 1235 | |
| 1236 | private: |
| 1237 | HUseListNode<T>* current_; |
| 1238 | |
| 1239 | friend class HValue; |
| 1240 | }; |
| 1241 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1242 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1243 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1244 | // by the used instructions. |
| 1245 | template <typename T> |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1246 | class HUserRecord { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1247 | public: |
| 1248 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1249 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1250 | |
| 1251 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1252 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1253 | DCHECK(instruction_ != nullptr); |
| 1254 | DCHECK(use_node_ != nullptr); |
| 1255 | DCHECK(old_record.use_node_ == nullptr); |
| 1256 | } |
| 1257 | |
| 1258 | HInstruction* GetInstruction() const { return instruction_; } |
| 1259 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1260 | |
| 1261 | private: |
| 1262 | // Instruction used by the user. |
| 1263 | HInstruction* instruction_; |
| 1264 | |
| 1265 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1266 | HUseListNode<T>* use_node_; |
| 1267 | }; |
| 1268 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1269 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1270 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1271 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1272 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1273 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1274 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1275 | * modify the value of a reference field read [although it may modify the |
| 1276 | * reference fetch prior to reading the field, which is represented by its own |
| 1277 | * write/read dependence]). The analysis makes conservative points-to |
| 1278 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1279 | * the same, and any reference read depends on any reference read without |
| 1280 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1281 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1282 | * The internal representation uses 38-bit and is described in the table below. |
| 1283 | * The first line indicates the side effect, and for field/array accesses the |
| 1284 | * second line indicates the type of the access (in the order of the |
| 1285 | * Primitive::Type enum). |
| 1286 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1287 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1288 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1289 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1290 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1291 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1292 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1293 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1294 | * |
| 1295 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1296 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1297 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1298 | class SideEffects : public ValueObject { |
| 1299 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1300 | SideEffects() : flags_(0) {} |
| 1301 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1302 | static SideEffects None() { |
| 1303 | return SideEffects(0); |
| 1304 | } |
| 1305 | |
| 1306 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1307 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1308 | } |
| 1309 | |
| 1310 | static SideEffects AllChanges() { |
| 1311 | return SideEffects(kAllChangeBits); |
| 1312 | } |
| 1313 | |
| 1314 | static SideEffects AllDependencies() { |
| 1315 | return SideEffects(kAllDependOnBits); |
| 1316 | } |
| 1317 | |
| 1318 | static SideEffects AllExceptGCDependency() { |
| 1319 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1320 | } |
| 1321 | |
| 1322 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1323 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1324 | } |
| 1325 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1326 | static SideEffects AllWrites() { |
| 1327 | return SideEffects(kAllWrites); |
| 1328 | } |
| 1329 | |
| 1330 | static SideEffects AllReads() { |
| 1331 | return SideEffects(kAllReads); |
| 1332 | } |
| 1333 | |
| 1334 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1335 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1336 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1337 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1338 | } |
| 1339 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1340 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1341 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1342 | } |
| 1343 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1344 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1345 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1346 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1347 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
| 1350 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1351 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1352 | } |
| 1353 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1354 | static SideEffects CanTriggerGC() { |
| 1355 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1356 | } |
| 1357 | |
| 1358 | static SideEffects DependsOnGC() { |
| 1359 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1360 | } |
| 1361 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1362 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1363 | SideEffects Union(SideEffects other) const { |
| 1364 | return SideEffects(flags_ | other.flags_); |
| 1365 | } |
| 1366 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1367 | SideEffects Exclusion(SideEffects other) const { |
| 1368 | return SideEffects(flags_ & ~other.flags_); |
| 1369 | } |
| 1370 | |
| 1371 | bool Includes(SideEffects other) const { |
| 1372 | return (other.flags_ & flags_) == other.flags_; |
| 1373 | } |
| 1374 | |
| 1375 | bool HasSideEffects() const { |
| 1376 | return (flags_ & kAllChangeBits); |
| 1377 | } |
| 1378 | |
| 1379 | bool HasDependencies() const { |
| 1380 | return (flags_ & kAllDependOnBits); |
| 1381 | } |
| 1382 | |
| 1383 | // Returns true if there are no side effects or dependencies. |
| 1384 | bool DoesNothing() const { |
| 1385 | return flags_ == 0; |
| 1386 | } |
| 1387 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1388 | // Returns true if something is written. |
| 1389 | bool DoesAnyWrite() const { |
| 1390 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1391 | } |
| 1392 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1393 | // Returns true if something is read. |
| 1394 | bool DoesAnyRead() const { |
| 1395 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1396 | } |
| 1397 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1398 | // Returns true if potentially everything is written and read |
| 1399 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1400 | bool DoesAllReadWrite() const { |
| 1401 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1402 | } |
| 1403 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1404 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1405 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1406 | } |
| 1407 | |
| 1408 | // Returns true if this may read something written by other. |
| 1409 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1410 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1411 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1412 | } |
| 1413 | |
| 1414 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1415 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1416 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1417 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1418 | for (int s = kLastBit; s >= 0; s--) { |
| 1419 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1420 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1421 | // This is a bit for the GC side effect. |
| 1422 | if (current_bit_is_set) { |
| 1423 | flags += "GC"; |
| 1424 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1425 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1426 | } else { |
| 1427 | // This is a bit for the array/field analysis. |
| 1428 | // The underscore character stands for the 'can trigger GC' bit. |
| 1429 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1430 | if (current_bit_is_set) { |
| 1431 | flags += kDebug[s]; |
| 1432 | } |
| 1433 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1434 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1435 | flags += "|"; |
| 1436 | } |
| 1437 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1438 | } |
| 1439 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1440 | } |
| 1441 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1442 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1443 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1444 | private: |
| 1445 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1446 | |
| 1447 | static constexpr int kFieldWriteOffset = 0; |
| 1448 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1449 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1450 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1451 | |
| 1452 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1453 | |
| 1454 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1455 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1456 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1457 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1458 | |
| 1459 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1460 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1461 | |
| 1462 | // Aliases. |
| 1463 | |
| 1464 | static_assert(kChangeBits == kDependOnBits, |
| 1465 | "the 'change' bits should match the 'depend on' bits."); |
| 1466 | |
| 1467 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1468 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1469 | static constexpr uint64_t kAllWrites = |
| 1470 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1471 | static constexpr uint64_t kAllReads = |
| 1472 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1473 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1474 | // Work around the fact that HIR aliases I/F and J/D. |
| 1475 | // TODO: remove this interceptor once HIR types are clean |
| 1476 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1477 | switch (type) { |
| 1478 | case Primitive::kPrimInt: |
| 1479 | case Primitive::kPrimFloat: |
| 1480 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1481 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1482 | case Primitive::kPrimLong: |
| 1483 | case Primitive::kPrimDouble: |
| 1484 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1485 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1486 | default: |
| 1487 | return TypeFlag(type, offset); |
| 1488 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1489 | } |
| 1490 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1491 | // Translates type to bit flag. |
| 1492 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1493 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1494 | const uint64_t one = 1; |
| 1495 | const int shift = type; // 0-based consecutive enum |
| 1496 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1497 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1498 | return one << (type + offset); |
| 1499 | } |
| 1500 | |
| 1501 | // Private constructor on direct flags value. |
| 1502 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1503 | |
| 1504 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1505 | }; |
| 1506 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1507 | // 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] | 1508 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1509 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1510 | HEnvironment(ArenaAllocator* arena, |
| 1511 | size_t number_of_vregs, |
| 1512 | const DexFile& dex_file, |
| 1513 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1514 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1515 | InvokeType invoke_type, |
| 1516 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1517 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1518 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1519 | parent_(nullptr), |
| 1520 | dex_file_(dex_file), |
| 1521 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1522 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1523 | invoke_type_(invoke_type), |
| 1524 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1525 | } |
| 1526 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1527 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1528 | : HEnvironment(arena, |
| 1529 | to_copy.Size(), |
| 1530 | to_copy.GetDexFile(), |
| 1531 | to_copy.GetMethodIdx(), |
| 1532 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1533 | to_copy.GetInvokeType(), |
| 1534 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1535 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1536 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1537 | if (parent_ != nullptr) { |
| 1538 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1539 | } else { |
| 1540 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1541 | parent_->CopyFrom(parent); |
| 1542 | if (parent->GetParent() != nullptr) { |
| 1543 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1544 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1545 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1546 | } |
| 1547 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1548 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1549 | void CopyFrom(HEnvironment* environment); |
| 1550 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1551 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1552 | // input to the loop phi instead. This is for inserting instructions that |
| 1553 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1554 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1555 | |
| 1556 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1557 | DCHECK_LT(index, Size()); |
| 1558 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1562 | DCHECK_LT(index, Size()); |
| 1563 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1564 | } |
| 1565 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1566 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1567 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1568 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1569 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1570 | HEnvironment* GetParent() const { return parent_; } |
| 1571 | |
| 1572 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1573 | DCHECK_LT(index, Size()); |
| 1574 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1575 | } |
| 1576 | |
| 1577 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1578 | DCHECK_LT(index, Size()); |
| 1579 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1580 | } |
| 1581 | |
| 1582 | uint32_t GetDexPc() const { |
| 1583 | return dex_pc_; |
| 1584 | } |
| 1585 | |
| 1586 | uint32_t GetMethodIdx() const { |
| 1587 | return method_idx_; |
| 1588 | } |
| 1589 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1590 | InvokeType GetInvokeType() const { |
| 1591 | return invoke_type_; |
| 1592 | } |
| 1593 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1594 | const DexFile& GetDexFile() const { |
| 1595 | return dex_file_; |
| 1596 | } |
| 1597 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1598 | HInstruction* GetHolder() const { |
| 1599 | return holder_; |
| 1600 | } |
| 1601 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1602 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1603 | // Record instructions' use entries of this environment for constant-time removal. |
| 1604 | // It should only be called by HInstruction when a new environment use is added. |
| 1605 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1606 | DCHECK(env_use->GetUser() == this); |
| 1607 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1608 | DCHECK_LT(index, Size()); |
| 1609 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1610 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1611 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1612 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1613 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1614 | HEnvironment* parent_; |
| 1615 | const DexFile& dex_file_; |
| 1616 | const uint32_t method_idx_; |
| 1617 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1618 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1619 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1620 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1621 | HInstruction* const holder_; |
| 1622 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1623 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1624 | |
| 1625 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1626 | }; |
| 1627 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1628 | class ReferenceTypeInfo : ValueObject { |
| 1629 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1630 | typedef Handle<mirror::Class> TypeHandle; |
| 1631 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1632 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1633 | // The constructor will check that the type_handle is valid. |
| 1634 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1635 | } |
| 1636 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1637 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1638 | |
| 1639 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1640 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1641 | } |
| 1642 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1643 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1644 | return IsValidHandle(type_handle_); |
| 1645 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1646 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1647 | |
| 1648 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1649 | DCHECK(IsValid()); |
| 1650 | return GetTypeHandle()->IsObjectClass(); |
| 1651 | } |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1652 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1653 | DCHECK(IsValid()); |
| 1654 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1655 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1656 | |
| 1657 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1658 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1659 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1660 | DCHECK(IsValid()); |
| 1661 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1662 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1663 | } |
| 1664 | |
| 1665 | // Returns true if the type information provide the same amount of details. |
| 1666 | // 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] | 1667 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1668 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1669 | if (!IsValid() && !rti.IsValid()) { |
| 1670 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1671 | return true; |
| 1672 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1673 | if (!IsValid() || !rti.IsValid()) { |
| 1674 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1675 | return false; |
| 1676 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1677 | return IsExact() == rti.IsExact() |
| 1678 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1679 | } |
| 1680 | |
| 1681 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1682 | ReferenceTypeInfo(); |
| 1683 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1684 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1685 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1686 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1687 | // 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] | 1688 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1689 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1690 | }; |
| 1691 | |
| 1692 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1693 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1694 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1695 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1696 | HInstruction(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1697 | : previous_(nullptr), |
| 1698 | next_(nullptr), |
| 1699 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1700 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1701 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1702 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1703 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1704 | locations_(nullptr), |
| 1705 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1706 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1707 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1708 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1709 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1710 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1711 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1712 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1713 | enum InstructionKind { |
| 1714 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1715 | }; |
| 1716 | #undef DECLARE_KIND |
| 1717 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1718 | HInstruction* GetNext() const { return next_; } |
| 1719 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1720 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1721 | HInstruction* GetNextDisregardingMoves() const; |
| 1722 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1723 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1724 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1725 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1726 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1727 | bool IsInBlock() const { return block_ != nullptr; } |
| 1728 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1729 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1730 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1731 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1732 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1733 | |
| 1734 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1735 | virtual const char* DebugName() const = 0; |
| 1736 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1737 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1738 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1739 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1740 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1741 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1742 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1743 | |
| 1744 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1745 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1746 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1747 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1748 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1749 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1750 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1751 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1752 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1753 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1754 | // Does not apply for all instructions, but having this at top level greatly |
| 1755 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1756 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1757 | virtual bool CanBeNull() const { |
| 1758 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1759 | return true; |
| 1760 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1761 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1762 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1763 | UNUSED(obj); |
| 1764 | return false; |
| 1765 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1766 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1767 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1768 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1769 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1770 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1771 | return reference_type_info_; |
| 1772 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1773 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1774 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1775 | DCHECK(user != nullptr); |
| 1776 | HUseListNode<HInstruction*>* use = |
| 1777 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1778 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1779 | } |
| 1780 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1781 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1782 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1783 | HUseListNode<HEnvironment*>* env_use = |
| 1784 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1785 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1786 | } |
| 1787 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1788 | void RemoveAsUserOfInput(size_t input) { |
| 1789 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1790 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1791 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1792 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1793 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1794 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1795 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1796 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1797 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1798 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1799 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1800 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1801 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1802 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1803 | // Does this instruction strictly dominate `other_instruction`? |
| 1804 | // Returns false if this instruction and `other_instruction` are the same. |
| 1805 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1806 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1807 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1808 | int GetId() const { return id_; } |
| 1809 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1810 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1811 | int GetSsaIndex() const { return ssa_index_; } |
| 1812 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1813 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1814 | |
| 1815 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1816 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1817 | // Set the `environment_` field. Raw because this method does not |
| 1818 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1819 | void SetRawEnvironment(HEnvironment* environment) { |
| 1820 | DCHECK(environment_ == nullptr); |
| 1821 | DCHECK_EQ(environment->GetHolder(), this); |
| 1822 | environment_ = environment; |
| 1823 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1824 | |
| 1825 | // Set the environment of this instruction, copying it from `environment`. While |
| 1826 | // copying, the uses lists are being updated. |
| 1827 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1828 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1829 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1830 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1831 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1832 | if (environment->GetParent() != nullptr) { |
| 1833 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1834 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1835 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1836 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1837 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1838 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1839 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1840 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1841 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1842 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1843 | if (environment->GetParent() != nullptr) { |
| 1844 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1845 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1846 | } |
| 1847 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1848 | // Returns the number of entries in the environment. Typically, that is the |
| 1849 | // number of dex registers in a method. It could be more in case of inlining. |
| 1850 | size_t EnvironmentSize() const; |
| 1851 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1852 | LocationSummary* GetLocations() const { return locations_; } |
| 1853 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1854 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1855 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1856 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1857 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1858 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1859 | // uses of this instruction by `other` are *not* updated. |
| 1860 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1861 | ReplaceWith(other); |
| 1862 | other->ReplaceInput(this, use_index); |
| 1863 | } |
| 1864 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1865 | // Move `this` instruction before `cursor`. |
| 1866 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1867 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1868 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1869 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1870 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1871 | virtual H##type* As##type() { return nullptr; } |
| 1872 | |
| 1873 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1874 | #undef INSTRUCTION_TYPE_CHECK |
| 1875 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1876 | // Returns whether the instruction can be moved within the graph. |
| 1877 | virtual bool CanBeMoved() const { return false; } |
| 1878 | |
| 1879 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1880 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1881 | UNUSED(other); |
| 1882 | return false; |
| 1883 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1884 | |
| 1885 | // Returns whether any data encoded in the two instructions is equal. |
| 1886 | // This method does not look at the inputs. Both instructions must be |
| 1887 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1888 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1889 | UNUSED(other); |
| 1890 | return false; |
| 1891 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1892 | |
| 1893 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1894 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1895 | // 2) Their inputs are identical. |
| 1896 | bool Equals(HInstruction* other) const; |
| 1897 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1898 | virtual InstructionKind GetKind() const = 0; |
| 1899 | |
| 1900 | virtual size_t ComputeHashCode() const { |
| 1901 | size_t result = GetKind(); |
| 1902 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1903 | result = (result * 31) + InputAt(i)->GetId(); |
| 1904 | } |
| 1905 | return result; |
| 1906 | } |
| 1907 | |
| 1908 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1909 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1910 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1911 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1912 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1913 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1914 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1915 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1916 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1917 | |
| 1918 | // Returns whether the code generation of the instruction will require to have access |
| 1919 | // to the current method. Such instructions are: |
| 1920 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1921 | // to walk the stack and have the current method stored at a specific stack address. |
| 1922 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1923 | // fields of the current method. |
| 1924 | bool NeedsCurrentMethod() const { |
| 1925 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1926 | } |
| 1927 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1928 | virtual bool NeedsDexCache() const { return false; } |
| 1929 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1930 | // Does this instruction have any use in an environment before |
| 1931 | // control flow hits 'other'? |
| 1932 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1933 | |
| 1934 | // Remove all references to environment uses of this instruction. |
| 1935 | // The caller must ensure that this is safe to do. |
| 1936 | void RemoveEnvironmentUsers(); |
| 1937 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1938 | protected: |
| 1939 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1940 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1941 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1942 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1943 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1944 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1945 | HInstruction* previous_; |
| 1946 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1947 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1948 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1949 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1950 | // An instruction gets an id when it is added to the graph. |
| 1951 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1952 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1953 | int id_; |
| 1954 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1955 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 1956 | int ssa_index_; |
| 1957 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1958 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1959 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1960 | |
| 1961 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1962 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1963 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1964 | // The environment associated with this instruction. Not null if the instruction |
| 1965 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1966 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1967 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1968 | // Set by the code generator. |
| 1969 | LocationSummary* locations_; |
| 1970 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1971 | // Set by the liveness analysis. |
| 1972 | LiveInterval* live_interval_; |
| 1973 | |
| 1974 | // Set by the liveness analysis, this is the position in a linear |
| 1975 | // order of blocks where this instruction's live interval start. |
| 1976 | size_t lifetime_position_; |
| 1977 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1978 | const SideEffects side_effects_; |
| 1979 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1980 | // TODO: for primitive types this should be marked as invalid. |
| 1981 | ReferenceTypeInfo reference_type_info_; |
| 1982 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1983 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1984 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1985 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1986 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1987 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1988 | |
| 1989 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 1990 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1991 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1992 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1993 | class HInputIterator : public ValueObject { |
| 1994 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1995 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1996 | |
| 1997 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 1998 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 1999 | void Advance() { index_++; } |
| 2000 | |
| 2001 | private: |
| 2002 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2003 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2004 | |
| 2005 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2006 | }; |
| 2007 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2008 | class HInstructionIterator : public ValueObject { |
| 2009 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2010 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2011 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2012 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2013 | } |
| 2014 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2015 | bool Done() const { return instruction_ == nullptr; } |
| 2016 | HInstruction* Current() const { return instruction_; } |
| 2017 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2018 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2019 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2020 | } |
| 2021 | |
| 2022 | private: |
| 2023 | HInstruction* instruction_; |
| 2024 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2025 | |
| 2026 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2027 | }; |
| 2028 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2029 | class HBackwardInstructionIterator : public ValueObject { |
| 2030 | public: |
| 2031 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2032 | : instruction_(instructions.last_instruction_) { |
| 2033 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2034 | } |
| 2035 | |
| 2036 | bool Done() const { return instruction_ == nullptr; } |
| 2037 | HInstruction* Current() const { return instruction_; } |
| 2038 | void Advance() { |
| 2039 | instruction_ = next_; |
| 2040 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2041 | } |
| 2042 | |
| 2043 | private: |
| 2044 | HInstruction* instruction_; |
| 2045 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2046 | |
| 2047 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2048 | }; |
| 2049 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2050 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2051 | class HTemplateInstruction: public HInstruction { |
| 2052 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2053 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2054 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2055 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2056 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2057 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2058 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2059 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2060 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2061 | DCHECK_LT(i, N); |
| 2062 | return inputs_[i]; |
| 2063 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2064 | |
| 2065 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2066 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2067 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2068 | } |
| 2069 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2070 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2071 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2072 | |
| 2073 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2074 | }; |
| 2075 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2076 | // HTemplateInstruction specialization for N=0. |
| 2077 | template<> |
| 2078 | class HTemplateInstruction<0>: public HInstruction { |
| 2079 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2080 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2081 | : HInstruction(side_effects, dex_pc) {} |
| 2082 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2083 | virtual ~HTemplateInstruction() {} |
| 2084 | |
| 2085 | size_t InputCount() const OVERRIDE { return 0; } |
| 2086 | |
| 2087 | protected: |
| 2088 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2089 | LOG(FATAL) << "Unreachable"; |
| 2090 | UNREACHABLE(); |
| 2091 | } |
| 2092 | |
| 2093 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2094 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2095 | LOG(FATAL) << "Unreachable"; |
| 2096 | UNREACHABLE(); |
| 2097 | } |
| 2098 | |
| 2099 | private: |
| 2100 | friend class SsaBuilder; |
| 2101 | }; |
| 2102 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2103 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2104 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2105 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2106 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2107 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2108 | virtual ~HExpression() {} |
| 2109 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2110 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2111 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2112 | protected: |
| 2113 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2114 | }; |
| 2115 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2116 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2117 | // instruction that branches to the exit block. |
| 2118 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2119 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2120 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2121 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2122 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2123 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2124 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2125 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2126 | |
| 2127 | private: |
| 2128 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2129 | }; |
| 2130 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2131 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2132 | // instruction that branches to the exit block. |
| 2133 | class HReturn : public HTemplateInstruction<1> { |
| 2134 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2135 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2136 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2137 | SetRawInputAt(0, value); |
| 2138 | } |
| 2139 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2140 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2141 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2142 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2143 | |
| 2144 | private: |
| 2145 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2146 | }; |
| 2147 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2148 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2149 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2150 | // exit block. |
| 2151 | class HExit : public HTemplateInstruction<0> { |
| 2152 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2153 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2154 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2155 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2156 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2157 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2158 | |
| 2159 | private: |
| 2160 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2161 | }; |
| 2162 | |
| 2163 | // Jumps from one block to another. |
| 2164 | class HGoto : public HTemplateInstruction<0> { |
| 2165 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2166 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2167 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2168 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2169 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2170 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2171 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2172 | } |
| 2173 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2174 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2175 | |
| 2176 | private: |
| 2177 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2178 | }; |
| 2179 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2180 | class HConstant : public HExpression<0> { |
| 2181 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2182 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2183 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2184 | |
| 2185 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2186 | |
| 2187 | virtual bool IsMinusOne() const { return false; } |
| 2188 | virtual bool IsZero() const { return false; } |
| 2189 | virtual bool IsOne() const { return false; } |
| 2190 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2191 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2192 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2193 | DECLARE_INSTRUCTION(Constant); |
| 2194 | |
| 2195 | private: |
| 2196 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2197 | }; |
| 2198 | |
| 2199 | class HNullConstant : public HConstant { |
| 2200 | public: |
| 2201 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2202 | return true; |
| 2203 | } |
| 2204 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2205 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2206 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2207 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2208 | |
| 2209 | DECLARE_INSTRUCTION(NullConstant); |
| 2210 | |
| 2211 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2212 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2213 | |
| 2214 | friend class HGraph; |
| 2215 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2216 | }; |
| 2217 | |
| 2218 | // Constants of the type int. Those can be from Dex instructions, or |
| 2219 | // synthesized (for example with the if-eqz instruction). |
| 2220 | class HIntConstant : public HConstant { |
| 2221 | public: |
| 2222 | int32_t GetValue() const { return value_; } |
| 2223 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2224 | uint64_t GetValueAsUint64() const OVERRIDE { return static_cast<uint64_t>(value_); } |
| 2225 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2226 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2227 | DCHECK(other->IsIntConstant()); |
| 2228 | return other->AsIntConstant()->value_ == value_; |
| 2229 | } |
| 2230 | |
| 2231 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2232 | |
| 2233 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2234 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2235 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2236 | |
| 2237 | DECLARE_INSTRUCTION(IntConstant); |
| 2238 | |
| 2239 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2240 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2241 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2242 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2243 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2244 | |
| 2245 | const int32_t value_; |
| 2246 | |
| 2247 | friend class HGraph; |
| 2248 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2249 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2250 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2251 | }; |
| 2252 | |
| 2253 | class HLongConstant : public HConstant { |
| 2254 | public: |
| 2255 | int64_t GetValue() const { return value_; } |
| 2256 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2257 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2258 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2259 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2260 | DCHECK(other->IsLongConstant()); |
| 2261 | return other->AsLongConstant()->value_ == value_; |
| 2262 | } |
| 2263 | |
| 2264 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2265 | |
| 2266 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2267 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2268 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2269 | |
| 2270 | DECLARE_INSTRUCTION(LongConstant); |
| 2271 | |
| 2272 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2273 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2274 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2275 | |
| 2276 | const int64_t value_; |
| 2277 | |
| 2278 | friend class HGraph; |
| 2279 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2280 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2281 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2282 | // Conditional branch. A block ending with an HIf instruction must have |
| 2283 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2284 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2285 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2286 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2287 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2288 | SetRawInputAt(0, input); |
| 2289 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2290 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2291 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2292 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2293 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2294 | return GetBlock()->GetSuccessor(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
| 2297 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2298 | return GetBlock()->GetSuccessor(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2299 | } |
| 2300 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2301 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2302 | |
| 2303 | private: |
| 2304 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2305 | }; |
| 2306 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2307 | |
| 2308 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2309 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2310 | // non-exceptional control flow. |
| 2311 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2312 | // higher indices in no particular order. |
| 2313 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2314 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2315 | enum BoundaryKind { |
| 2316 | kEntry, |
| 2317 | kExit, |
| 2318 | }; |
| 2319 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2320 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2321 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2322 | |
| 2323 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2324 | |
| 2325 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2326 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessor(0); } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2327 | |
| 2328 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2329 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2330 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2331 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2332 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2333 | } |
| 2334 | |
| 2335 | // If not present already, adds `handler` to its block's list of exception |
| 2336 | // handlers. |
| 2337 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2338 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2339 | GetBlock()->AddSuccessor(handler); |
| 2340 | } |
| 2341 | } |
| 2342 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2343 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2344 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2345 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2346 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2347 | DECLARE_INSTRUCTION(TryBoundary); |
| 2348 | |
| 2349 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2350 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2351 | |
| 2352 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2353 | }; |
| 2354 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2355 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2356 | // exceptional successors of its basic block. |
| 2357 | class HExceptionHandlerIterator : public ValueObject { |
| 2358 | public: |
| 2359 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2360 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2361 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2362 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
| 2363 | HBasicBlock* Current() const { return block_.GetSuccessor(index_); } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2364 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2365 | void Advance() { ++index_; } |
| 2366 | |
| 2367 | private: |
| 2368 | const HBasicBlock& block_; |
| 2369 | size_t index_; |
| 2370 | |
| 2371 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2372 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2373 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2374 | // Deoptimize to interpreter, upon checking a condition. |
| 2375 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2376 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2377 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2378 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2379 | SetRawInputAt(0, cond); |
| 2380 | } |
| 2381 | |
| 2382 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2383 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2384 | |
| 2385 | DECLARE_INSTRUCTION(Deoptimize); |
| 2386 | |
| 2387 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2388 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2389 | }; |
| 2390 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2391 | // Represents the ArtMethod that was passed as a first argument to |
| 2392 | // the method. It is used by instructions that depend on it, like |
| 2393 | // instructions that work with the dex cache. |
| 2394 | class HCurrentMethod : public HExpression<0> { |
| 2395 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2396 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2397 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2398 | |
| 2399 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2400 | |
| 2401 | private: |
| 2402 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2403 | }; |
| 2404 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2405 | class HUnaryOperation : public HExpression<1> { |
| 2406 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2407 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2408 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2409 | SetRawInputAt(0, input); |
| 2410 | } |
| 2411 | |
| 2412 | HInstruction* GetInput() const { return InputAt(0); } |
| 2413 | Primitive::Type GetResultType() const { return GetType(); } |
| 2414 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2415 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2416 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2417 | UNUSED(other); |
| 2418 | return true; |
| 2419 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2420 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2421 | // Try to statically evaluate `operation` and return a HConstant |
| 2422 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2423 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2424 | HConstant* TryStaticEvaluation() const; |
| 2425 | |
| 2426 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2427 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2428 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2429 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2430 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2431 | |
| 2432 | private: |
| 2433 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2434 | }; |
| 2435 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2436 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2437 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2438 | HBinaryOperation(Primitive::Type result_type, |
| 2439 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2440 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2441 | SideEffects side_effects = SideEffects::None(), |
| 2442 | uint32_t dex_pc = kNoDexPc) |
| 2443 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2444 | SetRawInputAt(0, left); |
| 2445 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2446 | } |
| 2447 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2448 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2449 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2450 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2451 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2452 | virtual bool IsCommutative() const { return false; } |
| 2453 | |
| 2454 | // Put constant on the right. |
| 2455 | // Returns whether order is changed. |
| 2456 | bool OrderInputsWithConstantOnTheRight() { |
| 2457 | HInstruction* left = InputAt(0); |
| 2458 | HInstruction* right = InputAt(1); |
| 2459 | if (left->IsConstant() && !right->IsConstant()) { |
| 2460 | ReplaceInput(right, 0); |
| 2461 | ReplaceInput(left, 1); |
| 2462 | return true; |
| 2463 | } |
| 2464 | return false; |
| 2465 | } |
| 2466 | |
| 2467 | // Order inputs by instruction id, but favor constant on the right side. |
| 2468 | // This helps GVN for commutative ops. |
| 2469 | void OrderInputs() { |
| 2470 | DCHECK(IsCommutative()); |
| 2471 | HInstruction* left = InputAt(0); |
| 2472 | HInstruction* right = InputAt(1); |
| 2473 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2474 | return; |
| 2475 | } |
| 2476 | if (OrderInputsWithConstantOnTheRight()) { |
| 2477 | return; |
| 2478 | } |
| 2479 | // Order according to instruction id. |
| 2480 | if (left->GetId() > right->GetId()) { |
| 2481 | ReplaceInput(right, 0); |
| 2482 | ReplaceInput(left, 1); |
| 2483 | } |
| 2484 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2485 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2486 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2487 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2488 | UNUSED(other); |
| 2489 | return true; |
| 2490 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2491 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2492 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2493 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2494 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2495 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2496 | |
| 2497 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2498 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2499 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2500 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2501 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2502 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2503 | return nullptr; |
| 2504 | } |
| 2505 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2506 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2507 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2508 | return nullptr; |
| 2509 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2510 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2511 | // 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] | 2512 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2513 | HConstant* GetConstantRight() const; |
| 2514 | |
| 2515 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2516 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2517 | HInstruction* GetLeastConstantLeft() const; |
| 2518 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2519 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2520 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2521 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2522 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2523 | }; |
| 2524 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2525 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2526 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2527 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2528 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2529 | kGtBias, // return 1 for NaN comparisons |
| 2530 | kLtBias, // return -1 for NaN comparisons |
| 2531 | }; |
| 2532 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2533 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2534 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2535 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2536 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2537 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2538 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2539 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2540 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2541 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2542 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2543 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2544 | // `instruction`, and disregard moves in between. |
| 2545 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2546 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2547 | DECLARE_INSTRUCTION(Condition); |
| 2548 | |
| 2549 | virtual IfCondition GetCondition() const = 0; |
| 2550 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2551 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2552 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2553 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2554 | |
| 2555 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2556 | |
| 2557 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2558 | return bias_ == other->AsCondition()->bias_; |
| 2559 | } |
| 2560 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2561 | bool IsFPConditionTrueIfNaN() const { |
| 2562 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2563 | IfCondition if_cond = GetCondition(); |
| 2564 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2565 | } |
| 2566 | |
| 2567 | bool IsFPConditionFalseIfNaN() const { |
| 2568 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2569 | IfCondition if_cond = GetCondition(); |
| 2570 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2571 | } |
| 2572 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2573 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2574 | // For register allocation purposes, returns whether this instruction needs to be |
| 2575 | // materialized (that is, not just be in the processor flags). |
| 2576 | bool needs_materialization_; |
| 2577 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2578 | // Needed if we merge a HCompare into a HCondition. |
| 2579 | ComparisonBias bias_; |
| 2580 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2581 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2582 | }; |
| 2583 | |
| 2584 | // Instruction to check if two inputs are equal to each other. |
| 2585 | class HEqual : public HCondition { |
| 2586 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2587 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2588 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2589 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2590 | bool IsCommutative() const OVERRIDE { return true; } |
| 2591 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2592 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2593 | |
| 2594 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2595 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2596 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2597 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2598 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2599 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2600 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2601 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2602 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2603 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2604 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2605 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2606 | return kCondEQ; |
| 2607 | } |
| 2608 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2609 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2610 | return kCondNE; |
| 2611 | } |
| 2612 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2613 | private: |
| 2614 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2615 | }; |
| 2616 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2617 | class HNotEqual : public HCondition { |
| 2618 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2619 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2620 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2621 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2622 | bool IsCommutative() const OVERRIDE { return true; } |
| 2623 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2624 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2625 | |
| 2626 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2627 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2628 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2629 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2630 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2631 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2632 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2633 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2634 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2635 | DECLARE_INSTRUCTION(NotEqual); |
| 2636 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2637 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2638 | return kCondNE; |
| 2639 | } |
| 2640 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2641 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2642 | return kCondEQ; |
| 2643 | } |
| 2644 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2645 | private: |
| 2646 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2647 | }; |
| 2648 | |
| 2649 | class HLessThan : public HCondition { |
| 2650 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2651 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2652 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2653 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2654 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2655 | |
| 2656 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2657 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2658 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2659 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2660 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2661 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2662 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2663 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2664 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2665 | DECLARE_INSTRUCTION(LessThan); |
| 2666 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2667 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2668 | return kCondLT; |
| 2669 | } |
| 2670 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2671 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2672 | return kCondGE; |
| 2673 | } |
| 2674 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2675 | private: |
| 2676 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2677 | }; |
| 2678 | |
| 2679 | class HLessThanOrEqual : public HCondition { |
| 2680 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2681 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2682 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2683 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2684 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2685 | |
| 2686 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2687 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2688 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2689 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2690 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2691 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2692 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2693 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2694 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2695 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2696 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2697 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2698 | return kCondLE; |
| 2699 | } |
| 2700 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2701 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2702 | return kCondGT; |
| 2703 | } |
| 2704 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2705 | private: |
| 2706 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2707 | }; |
| 2708 | |
| 2709 | class HGreaterThan : public HCondition { |
| 2710 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2711 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2712 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2713 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2714 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2715 | |
| 2716 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2717 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2718 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2719 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2720 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2721 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2722 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2723 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2724 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2725 | DECLARE_INSTRUCTION(GreaterThan); |
| 2726 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2727 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2728 | return kCondGT; |
| 2729 | } |
| 2730 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2731 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2732 | return kCondLE; |
| 2733 | } |
| 2734 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2735 | private: |
| 2736 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2737 | }; |
| 2738 | |
| 2739 | class HGreaterThanOrEqual : public HCondition { |
| 2740 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2741 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2742 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2743 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2744 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2745 | |
| 2746 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2747 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2748 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2749 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2750 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2751 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2752 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2753 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2754 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2755 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2756 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2757 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2758 | return kCondGE; |
| 2759 | } |
| 2760 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2761 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2762 | return kCondLT; |
| 2763 | } |
| 2764 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2765 | private: |
| 2766 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2767 | }; |
| 2768 | |
| 2769 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2770 | // Instruction to check how two inputs compare to each other. |
| 2771 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2772 | class HCompare : public HBinaryOperation { |
| 2773 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2774 | HCompare(Primitive::Type type, |
| 2775 | HInstruction* first, |
| 2776 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2777 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2778 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2779 | : HBinaryOperation(Primitive::kPrimInt, |
| 2780 | first, |
| 2781 | second, |
| 2782 | SideEffectsForArchRuntimeCalls(type), |
| 2783 | dex_pc), |
| 2784 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2785 | DCHECK_EQ(type, first->GetType()); |
| 2786 | DCHECK_EQ(type, second->GetType()); |
| 2787 | } |
| 2788 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2789 | template <typename T> |
| 2790 | 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] | 2791 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2792 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2793 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2794 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2795 | } |
| 2796 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2797 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2798 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2799 | } |
| 2800 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2801 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2802 | return bias_ == other->AsCompare()->bias_; |
| 2803 | } |
| 2804 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2805 | ComparisonBias GetBias() const { return bias_; } |
| 2806 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2807 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2808 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2809 | |
| 2810 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2811 | // MIPS64 uses a runtime call for FP comparisons. |
| 2812 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2813 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2814 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2815 | DECLARE_INSTRUCTION(Compare); |
| 2816 | |
| 2817 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2818 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2819 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2820 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2821 | }; |
| 2822 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2823 | // A local in the graph. Corresponds to a Dex register. |
| 2824 | class HLocal : public HTemplateInstruction<0> { |
| 2825 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2826 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2827 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2828 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2829 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2830 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2831 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2832 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2833 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2834 | // The Dex register number. |
| 2835 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2836 | |
| 2837 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2838 | }; |
| 2839 | |
| 2840 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2841 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2842 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2843 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2844 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2845 | SetRawInputAt(0, local); |
| 2846 | } |
| 2847 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2848 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2849 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2850 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2851 | |
| 2852 | private: |
| 2853 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2854 | }; |
| 2855 | |
| 2856 | // Store a value in a given local. This instruction has two inputs: the value |
| 2857 | // and the local. |
| 2858 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2859 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2860 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2861 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2862 | SetRawInputAt(0, local); |
| 2863 | SetRawInputAt(1, value); |
| 2864 | } |
| 2865 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2866 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2867 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2868 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2869 | |
| 2870 | private: |
| 2871 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2872 | }; |
| 2873 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2874 | class HFloatConstant : public HConstant { |
| 2875 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2876 | float GetValue() const { return value_; } |
| 2877 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2878 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2879 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2880 | } |
| 2881 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2882 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2883 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2884 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2885 | } |
| 2886 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2887 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2888 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2889 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2890 | 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] | 2891 | } |
| 2892 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2893 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2894 | } |
| 2895 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2896 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2897 | } |
| 2898 | bool IsNaN() const { |
| 2899 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2900 | } |
| 2901 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2902 | DECLARE_INSTRUCTION(FloatConstant); |
| 2903 | |
| 2904 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2905 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2906 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2907 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2908 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2909 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2910 | const float value_; |
| 2911 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2912 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2913 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2914 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2915 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2916 | }; |
| 2917 | |
| 2918 | class HDoubleConstant : public HConstant { |
| 2919 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2920 | double GetValue() const { return value_; } |
| 2921 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2922 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2923 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2924 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2925 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2926 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2929 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2930 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2931 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2932 | 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] | 2933 | } |
| 2934 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2935 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2936 | } |
| 2937 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2938 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2939 | } |
| 2940 | bool IsNaN() const { |
| 2941 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2944 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2945 | |
| 2946 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2947 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2948 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2949 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2950 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2951 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2952 | const double value_; |
| 2953 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2954 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2955 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2956 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2957 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2958 | }; |
| 2959 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2960 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2961 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2962 | #include "intrinsics_list.h" |
| 2963 | kNone, |
| 2964 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 2965 | #undef INTRINSICS_LIST |
| 2966 | #undef OPTIMIZING_INTRINSICS |
| 2967 | }; |
| 2968 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 2969 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2970 | enum IntrinsicNeedsEnvironmentOrCache { |
| 2971 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 2972 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 2973 | }; |
| 2974 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2975 | class HInvoke : public HInstruction { |
| 2976 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 2977 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2978 | |
| 2979 | // Runtime needs to walk the stack, so Dex -> Dex calls need to |
| 2980 | // know their environment. |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2981 | bool NeedsEnvironment() const OVERRIDE { |
| 2982 | return needs_environment_or_cache_ == kNeedsEnvironmentOrCache; |
| 2983 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2984 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 2985 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2986 | SetRawInputAt(index, argument); |
| 2987 | } |
| 2988 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 2989 | // Return the number of arguments. This number can be lower than |
| 2990 | // the number of inputs returned by InputCount(), as some invoke |
| 2991 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 2992 | // inputs at the end of their list of inputs. |
| 2993 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 2994 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2995 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2996 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 2997 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2998 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 2999 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3000 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3001 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3002 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3003 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3004 | return intrinsic_; |
| 3005 | } |
| 3006 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3007 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3008 | intrinsic_ = intrinsic; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3009 | needs_environment_or_cache_ = needs_env_or_cache; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3010 | } |
| 3011 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3012 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3013 | return GetEnvironment()->GetParent() != nullptr; |
| 3014 | } |
| 3015 | |
| 3016 | bool CanThrow() const OVERRIDE { return true; } |
| 3017 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3018 | DECLARE_INSTRUCTION(Invoke); |
| 3019 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3020 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3021 | HInvoke(ArenaAllocator* arena, |
| 3022 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3023 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3024 | Primitive::Type return_type, |
| 3025 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3026 | uint32_t dex_method_index, |
| 3027 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3028 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3029 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3030 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3031 | inputs_(number_of_arguments + number_of_other_inputs, arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3032 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3033 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3034 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3035 | intrinsic_(Intrinsics::kNone), |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3036 | needs_environment_or_cache_(kNeedsEnvironmentOrCache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3037 | } |
| 3038 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3039 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 3040 | DCHECK_LT(index, InputCount()); |
| 3041 | return inputs_[index]; |
| 3042 | } |
| 3043 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3044 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3045 | DCHECK_LT(index, InputCount()); |
| 3046 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3047 | } |
| 3048 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3049 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3050 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3051 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3052 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3053 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3054 | Intrinsics intrinsic_; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3055 | IntrinsicNeedsEnvironmentOrCache needs_environment_or_cache_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3056 | |
| 3057 | private: |
| 3058 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3059 | }; |
| 3060 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3061 | class HInvokeUnresolved : public HInvoke { |
| 3062 | public: |
| 3063 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3064 | uint32_t number_of_arguments, |
| 3065 | Primitive::Type return_type, |
| 3066 | uint32_t dex_pc, |
| 3067 | uint32_t dex_method_index, |
| 3068 | InvokeType invoke_type) |
| 3069 | : HInvoke(arena, |
| 3070 | number_of_arguments, |
| 3071 | 0u /* number_of_other_inputs */, |
| 3072 | return_type, |
| 3073 | dex_pc, |
| 3074 | dex_method_index, |
| 3075 | invoke_type) { |
| 3076 | } |
| 3077 | |
| 3078 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3079 | |
| 3080 | private: |
| 3081 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3082 | }; |
| 3083 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3084 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3085 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3086 | // Requirements of this method call regarding the class |
| 3087 | // initialization (clinit) check of its declaring class. |
| 3088 | enum class ClinitCheckRequirement { |
| 3089 | kNone, // Class already initialized. |
| 3090 | kExplicit, // Static call having explicit clinit check as last input. |
| 3091 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3092 | }; |
| 3093 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3094 | // Determines how to load the target ArtMethod*. |
| 3095 | enum class MethodLoadKind { |
| 3096 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3097 | kStringInit, |
| 3098 | |
| 3099 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3100 | kRecursive, |
| 3101 | |
| 3102 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3103 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3104 | kDirectAddress, |
| 3105 | |
| 3106 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3107 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3108 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3109 | // the image relocatable or not. |
| 3110 | kDirectAddressWithFixup, |
| 3111 | |
| 3112 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3113 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3114 | // may cause class initialization (the entry may point to a resolution method), |
| 3115 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3116 | kDexCachePcRelative, |
| 3117 | |
| 3118 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3119 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3120 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3121 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3122 | kDexCacheViaMethod, |
| 3123 | }; |
| 3124 | |
| 3125 | // Determines the location of the code pointer. |
| 3126 | enum class CodePtrLocation { |
| 3127 | // Recursive call, use local PC-relative call instruction. |
| 3128 | kCallSelf, |
| 3129 | |
| 3130 | // Use PC-relative call instruction patched at link time. |
| 3131 | // Used for calls within an oat file, boot->boot or app->app. |
| 3132 | kCallPCRelative, |
| 3133 | |
| 3134 | // Call to a known target address, embed the direct address in code. |
| 3135 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3136 | kCallDirect, |
| 3137 | |
| 3138 | // Call to a target address that will be known at link time, embed the direct |
| 3139 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3140 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3141 | // the image relocatable or not. |
| 3142 | kCallDirectWithFixup, |
| 3143 | |
| 3144 | // Use code pointer from the ArtMethod*. |
| 3145 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3146 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3147 | kCallArtMethod, |
| 3148 | }; |
| 3149 | |
| 3150 | struct DispatchInfo { |
| 3151 | const MethodLoadKind method_load_kind; |
| 3152 | const CodePtrLocation code_ptr_location; |
| 3153 | // The method load data holds |
| 3154 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3155 | // Note that there are multiple string init methods, each having its own offset. |
| 3156 | // - the method address for kDirectAddress |
| 3157 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3158 | const uint64_t method_load_data; |
| 3159 | const uint64_t direct_code_ptr; |
| 3160 | }; |
| 3161 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3162 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3163 | uint32_t number_of_arguments, |
| 3164 | Primitive::Type return_type, |
| 3165 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3166 | uint32_t method_index, |
| 3167 | MethodReference target_method, |
| 3168 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3169 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3170 | InvokeType invoke_type, |
| 3171 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3172 | : HInvoke(arena, |
| 3173 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3174 | // There is one extra argument for the HCurrentMethod node, and |
| 3175 | // potentially one other if the clinit check is explicit, and one other |
| 3176 | // if the method is a string factory. |
| 3177 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3178 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3179 | return_type, |
| 3180 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3181 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3182 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3183 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3184 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3185 | target_method_(target_method), |
| 3186 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3187 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3188 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3189 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3190 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3191 | // TODO: for intrinsics we can generate implicit null checks. |
| 3192 | return false; |
| 3193 | } |
| 3194 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3195 | bool CanBeNull() const OVERRIDE { |
| 3196 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3197 | } |
| 3198 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3199 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3200 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3201 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3202 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3203 | bool NeedsDexCache() const OVERRIDE { |
| 3204 | if (intrinsic_ != Intrinsics::kNone) { return needs_environment_or_cache_; } |
| 3205 | return !IsRecursive() && !IsStringInit(); |
| 3206 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3207 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3208 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3209 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3210 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3211 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3212 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3213 | |
| 3214 | int32_t GetStringInitOffset() const { |
| 3215 | DCHECK(IsStringInit()); |
| 3216 | return dispatch_info_.method_load_data; |
| 3217 | } |
| 3218 | |
| 3219 | uint64_t GetMethodAddress() const { |
| 3220 | DCHECK(HasMethodAddress()); |
| 3221 | return dispatch_info_.method_load_data; |
| 3222 | } |
| 3223 | |
| 3224 | uint32_t GetDexCacheArrayOffset() const { |
| 3225 | DCHECK(HasPcRelDexCache()); |
| 3226 | return dispatch_info_.method_load_data; |
| 3227 | } |
| 3228 | |
| 3229 | uint64_t GetDirectCodePtr() const { |
| 3230 | DCHECK(HasDirectCodePtr()); |
| 3231 | return dispatch_info_.direct_code_ptr; |
| 3232 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3233 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3234 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3235 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3236 | // Is this instruction a call to a static method? |
| 3237 | bool IsStatic() const { |
| 3238 | return GetInvokeType() == kStatic; |
| 3239 | } |
| 3240 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3241 | // Remove the art::HLoadClass instruction set as last input by |
| 3242 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3243 | // the initial art::HClinitCheck instruction (only relevant for |
| 3244 | // static calls with explicit clinit check). |
| 3245 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3246 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3247 | size_t last_input_index = InputCount() - 1; |
| 3248 | HInstruction* last_input = InputAt(last_input_index); |
| 3249 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3250 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3251 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3252 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3253 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3254 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3255 | } |
| 3256 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3257 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3258 | if (!IsStringInit()) return false; |
| 3259 | // +1 for the current method. |
| 3260 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3261 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3262 | } |
| 3263 | |
| 3264 | void RemoveFakeStringArgumentAsLastInput() { |
| 3265 | DCHECK(IsStringInit()); |
| 3266 | size_t last_input_index = InputCount() - 1; |
| 3267 | HInstruction* last_input = InputAt(last_input_index); |
| 3268 | DCHECK(last_input != nullptr); |
| 3269 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3270 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3271 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3272 | } |
| 3273 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3274 | // Is this a call to a static method whose declaring class has an |
| 3275 | // explicit intialization check in the graph? |
| 3276 | bool IsStaticWithExplicitClinitCheck() const { |
| 3277 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3278 | } |
| 3279 | |
| 3280 | // Is this a call to a static method whose declaring class has an |
| 3281 | // implicit intialization check requirement? |
| 3282 | bool IsStaticWithImplicitClinitCheck() const { |
| 3283 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3284 | } |
| 3285 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3286 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3287 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3288 | protected: |
| 3289 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3290 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3291 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3292 | HInstruction* input = input_record.GetInstruction(); |
| 3293 | // `input` is the last input of a static invoke marked as having |
| 3294 | // an explicit clinit check. It must either be: |
| 3295 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3296 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3297 | DCHECK(input != nullptr); |
| 3298 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3299 | } |
| 3300 | return input_record; |
| 3301 | } |
| 3302 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3303 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3304 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3305 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3306 | // The target method may refer to different dex file or method index than the original |
| 3307 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3308 | // in derived class to increase visibility. |
| 3309 | MethodReference target_method_; |
| 3310 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3311 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3312 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3313 | }; |
| 3314 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3315 | class HInvokeVirtual : public HInvoke { |
| 3316 | public: |
| 3317 | HInvokeVirtual(ArenaAllocator* arena, |
| 3318 | uint32_t number_of_arguments, |
| 3319 | Primitive::Type return_type, |
| 3320 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3321 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3322 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3323 | : 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] | 3324 | vtable_index_(vtable_index) {} |
| 3325 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3326 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3327 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3328 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3331 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3332 | |
| 3333 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3334 | |
| 3335 | private: |
| 3336 | const uint32_t vtable_index_; |
| 3337 | |
| 3338 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3339 | }; |
| 3340 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3341 | class HInvokeInterface : public HInvoke { |
| 3342 | public: |
| 3343 | HInvokeInterface(ArenaAllocator* arena, |
| 3344 | uint32_t number_of_arguments, |
| 3345 | Primitive::Type return_type, |
| 3346 | uint32_t dex_pc, |
| 3347 | uint32_t dex_method_index, |
| 3348 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3349 | : 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] | 3350 | imt_index_(imt_index) {} |
| 3351 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3352 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3353 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3354 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3355 | } |
| 3356 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3357 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3358 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3359 | |
| 3360 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3361 | |
| 3362 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3363 | const uint32_t imt_index_; |
| 3364 | |
| 3365 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3366 | }; |
| 3367 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3368 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3369 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3370 | HNewInstance(HCurrentMethod* current_method, |
| 3371 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3372 | uint16_t type_index, |
| 3373 | const DexFile& dex_file, |
| 3374 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3375 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3376 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3377 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3378 | entrypoint_(entrypoint) { |
| 3379 | SetRawInputAt(0, current_method); |
| 3380 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3381 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3382 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3383 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3384 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3385 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3386 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3387 | // It may throw when called on: |
| 3388 | // - interfaces |
| 3389 | // - abstract/innaccessible/unknown classes |
| 3390 | // TODO: optimize when possible. |
| 3391 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3392 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3393 | bool CanBeNull() const OVERRIDE { return false; } |
| 3394 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3395 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3396 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3397 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3398 | |
| 3399 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3400 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3401 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3402 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3403 | |
| 3404 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3405 | }; |
| 3406 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3407 | class HNeg : public HUnaryOperation { |
| 3408 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3409 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3410 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3411 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3412 | template <typename T> T Compute(T x) const { return -x; } |
| 3413 | |
| 3414 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3415 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3416 | } |
| 3417 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3418 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3419 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3420 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3421 | DECLARE_INSTRUCTION(Neg); |
| 3422 | |
| 3423 | private: |
| 3424 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3425 | }; |
| 3426 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3427 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3428 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3429 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3430 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3431 | uint32_t dex_pc, |
| 3432 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3433 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3434 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3435 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3436 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3437 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3438 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3439 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3440 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3441 | } |
| 3442 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3443 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3444 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3445 | |
| 3446 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3447 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3448 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3449 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3450 | bool CanThrow() const OVERRIDE { return true; } |
| 3451 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3452 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3453 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3454 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3455 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3456 | DECLARE_INSTRUCTION(NewArray); |
| 3457 | |
| 3458 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3459 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3460 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3461 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3462 | |
| 3463 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3464 | }; |
| 3465 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3466 | class HAdd : public HBinaryOperation { |
| 3467 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3468 | HAdd(Primitive::Type result_type, |
| 3469 | HInstruction* left, |
| 3470 | HInstruction* right, |
| 3471 | uint32_t dex_pc = kNoDexPc) |
| 3472 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3473 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3474 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3475 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3476 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3477 | |
| 3478 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3479 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3480 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3481 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3482 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3483 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3484 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3485 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3486 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3487 | DECLARE_INSTRUCTION(Add); |
| 3488 | |
| 3489 | private: |
| 3490 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3491 | }; |
| 3492 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3493 | class HSub : public HBinaryOperation { |
| 3494 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3495 | HSub(Primitive::Type result_type, |
| 3496 | HInstruction* left, |
| 3497 | HInstruction* right, |
| 3498 | uint32_t dex_pc = kNoDexPc) |
| 3499 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3500 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3501 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3502 | |
| 3503 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3504 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3505 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3506 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3507 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3508 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3509 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3510 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3511 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3512 | DECLARE_INSTRUCTION(Sub); |
| 3513 | |
| 3514 | private: |
| 3515 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3516 | }; |
| 3517 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3518 | class HMul : public HBinaryOperation { |
| 3519 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3520 | HMul(Primitive::Type result_type, |
| 3521 | HInstruction* left, |
| 3522 | HInstruction* right, |
| 3523 | uint32_t dex_pc = kNoDexPc) |
| 3524 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3525 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3526 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3527 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3528 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3529 | |
| 3530 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3531 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3532 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3533 | } |
| 3534 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3535 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3536 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3537 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3538 | |
| 3539 | DECLARE_INSTRUCTION(Mul); |
| 3540 | |
| 3541 | private: |
| 3542 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3543 | }; |
| 3544 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3545 | class HDiv : public HBinaryOperation { |
| 3546 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3547 | HDiv(Primitive::Type result_type, |
| 3548 | HInstruction* left, |
| 3549 | HInstruction* right, |
| 3550 | uint32_t dex_pc) |
| 3551 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3552 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3553 | template <typename T> |
| 3554 | T Compute(T x, T y) const { |
| 3555 | // Our graph structure ensures we never have 0 for `y` during |
| 3556 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3557 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3558 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3559 | return (y == -1) ? -x : x / y; |
| 3560 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3561 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3562 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3563 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3564 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3565 | } |
| 3566 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3567 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3568 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3569 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3570 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3571 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3572 | // The generated code can use a runtime call. |
| 3573 | return SideEffects::CanTriggerGC(); |
| 3574 | } |
| 3575 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3576 | DECLARE_INSTRUCTION(Div); |
| 3577 | |
| 3578 | private: |
| 3579 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3580 | }; |
| 3581 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3582 | class HRem : public HBinaryOperation { |
| 3583 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3584 | HRem(Primitive::Type result_type, |
| 3585 | HInstruction* left, |
| 3586 | HInstruction* right, |
| 3587 | uint32_t dex_pc) |
| 3588 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3589 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3590 | template <typename T> |
| 3591 | T Compute(T x, T y) const { |
| 3592 | // Our graph structure ensures we never have 0 for `y` during |
| 3593 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3594 | DCHECK_NE(y, 0); |
| 3595 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3596 | return (y == -1) ? 0 : x % y; |
| 3597 | } |
| 3598 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3599 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3600 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3601 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3602 | } |
| 3603 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3604 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3605 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3606 | } |
| 3607 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3608 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3609 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3610 | return SideEffects::CanTriggerGC(); |
| 3611 | } |
| 3612 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3613 | DECLARE_INSTRUCTION(Rem); |
| 3614 | |
| 3615 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3617 | }; |
| 3618 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3619 | class HDivZeroCheck : public HExpression<1> { |
| 3620 | public: |
| 3621 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3622 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3623 | SetRawInputAt(0, value); |
| 3624 | } |
| 3625 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3626 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3627 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3628 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3629 | |
| 3630 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3631 | UNUSED(other); |
| 3632 | return true; |
| 3633 | } |
| 3634 | |
| 3635 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3636 | bool CanThrow() const OVERRIDE { return true; } |
| 3637 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3638 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3639 | |
| 3640 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3641 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3642 | }; |
| 3643 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3644 | class HShl : public HBinaryOperation { |
| 3645 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3646 | HShl(Primitive::Type result_type, |
| 3647 | HInstruction* left, |
| 3648 | HInstruction* right, |
| 3649 | uint32_t dex_pc = kNoDexPc) |
| 3650 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3651 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3652 | template <typename T, typename U, typename V> |
| 3653 | T Compute(T x, U y, V max_shift_value) const { |
| 3654 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3655 | "V is not the unsigned integer type corresponding to T"); |
| 3656 | return x << (y & max_shift_value); |
| 3657 | } |
| 3658 | |
| 3659 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3660 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3661 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3662 | } |
| 3663 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3664 | // case is handled as `x << static_cast<int>(y)`. |
| 3665 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3666 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3667 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3668 | } |
| 3669 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3670 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3671 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3672 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3673 | |
| 3674 | DECLARE_INSTRUCTION(Shl); |
| 3675 | |
| 3676 | private: |
| 3677 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3678 | }; |
| 3679 | |
| 3680 | class HShr : public HBinaryOperation { |
| 3681 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3682 | HShr(Primitive::Type result_type, |
| 3683 | HInstruction* left, |
| 3684 | HInstruction* right, |
| 3685 | uint32_t dex_pc = kNoDexPc) |
| 3686 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3687 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3688 | template <typename T, typename U, typename V> |
| 3689 | T Compute(T x, U y, V max_shift_value) const { |
| 3690 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3691 | "V is not the unsigned integer type corresponding to T"); |
| 3692 | return x >> (y & max_shift_value); |
| 3693 | } |
| 3694 | |
| 3695 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3696 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3697 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3698 | } |
| 3699 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3700 | // case is handled as `x >> static_cast<int>(y)`. |
| 3701 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3702 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3703 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3704 | } |
| 3705 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3706 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3707 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3708 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3709 | |
| 3710 | DECLARE_INSTRUCTION(Shr); |
| 3711 | |
| 3712 | private: |
| 3713 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3714 | }; |
| 3715 | |
| 3716 | class HUShr : public HBinaryOperation { |
| 3717 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3718 | HUShr(Primitive::Type result_type, |
| 3719 | HInstruction* left, |
| 3720 | HInstruction* right, |
| 3721 | uint32_t dex_pc = kNoDexPc) |
| 3722 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3723 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3724 | template <typename T, typename U, typename V> |
| 3725 | T Compute(T x, U y, V max_shift_value) const { |
| 3726 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3727 | "V is not the unsigned integer type corresponding to T"); |
| 3728 | V ux = static_cast<V>(x); |
| 3729 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3730 | } |
| 3731 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3732 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3733 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3734 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3735 | } |
| 3736 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3737 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3738 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3739 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3740 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3741 | } |
| 3742 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3743 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3744 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3745 | } |
| 3746 | |
| 3747 | DECLARE_INSTRUCTION(UShr); |
| 3748 | |
| 3749 | private: |
| 3750 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3751 | }; |
| 3752 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3753 | class HAnd : public HBinaryOperation { |
| 3754 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3755 | HAnd(Primitive::Type result_type, |
| 3756 | HInstruction* left, |
| 3757 | HInstruction* right, |
| 3758 | uint32_t dex_pc = kNoDexPc) |
| 3759 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3760 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3761 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3762 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3763 | template <typename T, typename U> |
| 3764 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3765 | |
| 3766 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3767 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3768 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3769 | } |
| 3770 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3771 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3772 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3773 | } |
| 3774 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3775 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3776 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3777 | } |
| 3778 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3779 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3780 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3781 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3782 | |
| 3783 | DECLARE_INSTRUCTION(And); |
| 3784 | |
| 3785 | private: |
| 3786 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3787 | }; |
| 3788 | |
| 3789 | class HOr : public HBinaryOperation { |
| 3790 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3791 | HOr(Primitive::Type result_type, |
| 3792 | HInstruction* left, |
| 3793 | HInstruction* right, |
| 3794 | uint32_t dex_pc = kNoDexPc) |
| 3795 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3796 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3797 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3798 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3799 | template <typename T, typename U> |
| 3800 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3801 | |
| 3802 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3803 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3804 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3805 | } |
| 3806 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3807 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3808 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3809 | } |
| 3810 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3811 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3812 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3813 | } |
| 3814 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3815 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3816 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3817 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3818 | |
| 3819 | DECLARE_INSTRUCTION(Or); |
| 3820 | |
| 3821 | private: |
| 3822 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3823 | }; |
| 3824 | |
| 3825 | class HXor : public HBinaryOperation { |
| 3826 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3827 | HXor(Primitive::Type result_type, |
| 3828 | HInstruction* left, |
| 3829 | HInstruction* right, |
| 3830 | uint32_t dex_pc = kNoDexPc) |
| 3831 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3832 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3833 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3834 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3835 | template <typename T, typename U> |
| 3836 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3837 | |
| 3838 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3839 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3840 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3841 | } |
| 3842 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3843 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3844 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3845 | } |
| 3846 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3847 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3848 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3849 | } |
| 3850 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3851 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3852 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3853 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3854 | |
| 3855 | DECLARE_INSTRUCTION(Xor); |
| 3856 | |
| 3857 | private: |
| 3858 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3859 | }; |
| 3860 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3861 | // The value of a parameter in this method. Its location depends on |
| 3862 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3863 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3864 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3865 | HParameterValue(uint8_t index, |
| 3866 | Primitive::Type parameter_type, |
| 3867 | bool is_this = false) |
| 3868 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3869 | index_(index), |
| 3870 | is_this_(is_this), |
| 3871 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3872 | |
| 3873 | uint8_t GetIndex() const { return index_; } |
| 3874 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3875 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3876 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3877 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3878 | bool IsThis() const { return is_this_; } |
| 3879 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3880 | DECLARE_INSTRUCTION(ParameterValue); |
| 3881 | |
| 3882 | private: |
| 3883 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3884 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3885 | const uint8_t index_; |
| 3886 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3887 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3888 | const bool is_this_; |
| 3889 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3890 | bool can_be_null_; |
| 3891 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3892 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3893 | }; |
| 3894 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3895 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3896 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3897 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3898 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3899 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3900 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3901 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3902 | UNUSED(other); |
| 3903 | return true; |
| 3904 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3905 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3906 | template <typename T> T Compute(T x) const { return ~x; } |
| 3907 | |
| 3908 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3909 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3910 | } |
| 3911 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3912 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3913 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3914 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3915 | DECLARE_INSTRUCTION(Not); |
| 3916 | |
| 3917 | private: |
| 3918 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 3919 | }; |
| 3920 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3921 | class HBooleanNot : public HUnaryOperation { |
| 3922 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3923 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3924 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3925 | |
| 3926 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3927 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3928 | UNUSED(other); |
| 3929 | return true; |
| 3930 | } |
| 3931 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3932 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3933 | DCHECK(IsUint<1>(x)); |
| 3934 | return !x; |
| 3935 | } |
| 3936 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3937 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3938 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3939 | } |
| 3940 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3941 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3942 | UNREACHABLE(); |
| 3943 | } |
| 3944 | |
| 3945 | DECLARE_INSTRUCTION(BooleanNot); |
| 3946 | |
| 3947 | private: |
| 3948 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 3949 | }; |
| 3950 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3951 | class HTypeConversion : public HExpression<1> { |
| 3952 | public: |
| 3953 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3954 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3955 | : HExpression(result_type, |
| 3956 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 3957 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3958 | SetRawInputAt(0, input); |
| 3959 | DCHECK_NE(input->GetType(), result_type); |
| 3960 | } |
| 3961 | |
| 3962 | HInstruction* GetInput() const { return InputAt(0); } |
| 3963 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 3964 | Primitive::Type GetResultType() const { return GetType(); } |
| 3965 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3966 | // Required by the x86 and ARM code generators when producing calls |
| 3967 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3968 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3969 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 3970 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3971 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 3972 | // Try to statically evaluate the conversion and return a HConstant |
| 3973 | // containing the result. If the input cannot be converted, return nullptr. |
| 3974 | HConstant* TryStaticEvaluation() const; |
| 3975 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3976 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 3977 | Primitive::Type result_type) { |
| 3978 | // Some architectures may not require the 'GC' side effects, but at this point |
| 3979 | // in the compilation process we do not know what architecture we will |
| 3980 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 3981 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 3982 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3983 | return SideEffects::CanTriggerGC(); |
| 3984 | } |
| 3985 | return SideEffects::None(); |
| 3986 | } |
| 3987 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3988 | DECLARE_INSTRUCTION(TypeConversion); |
| 3989 | |
| 3990 | private: |
| 3991 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 3992 | }; |
| 3993 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 3994 | static constexpr uint32_t kNoRegNumber = -1; |
| 3995 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3996 | class HPhi : public HInstruction { |
| 3997 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3998 | HPhi(ArenaAllocator* arena, |
| 3999 | uint32_t reg_number, |
| 4000 | size_t number_of_inputs, |
| 4001 | Primitive::Type type, |
| 4002 | uint32_t dex_pc = kNoDexPc) |
| 4003 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4004 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4005 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4006 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4007 | is_live_(false), |
| 4008 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4009 | } |
| 4010 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4011 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4012 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4013 | switch (type) { |
| 4014 | case Primitive::kPrimBoolean: |
| 4015 | case Primitive::kPrimByte: |
| 4016 | case Primitive::kPrimShort: |
| 4017 | case Primitive::kPrimChar: |
| 4018 | return Primitive::kPrimInt; |
| 4019 | default: |
| 4020 | return type; |
| 4021 | } |
| 4022 | } |
| 4023 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4024 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4025 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4026 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4027 | |
| 4028 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4029 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4030 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4031 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4032 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4033 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4034 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4035 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4036 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4037 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4038 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4039 | void SetDead() { is_live_ = false; } |
| 4040 | void SetLive() { is_live_ = true; } |
| 4041 | bool IsDead() const { return !is_live_; } |
| 4042 | bool IsLive() const { return is_live_; } |
| 4043 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4044 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4045 | return other != nullptr |
| 4046 | && other->IsPhi() |
| 4047 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4048 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4049 | } |
| 4050 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4051 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4052 | // An equivalent phi is a phi having the same dex register and type. |
| 4053 | // It assumes that phis with the same dex register are adjacent. |
| 4054 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4055 | HInstruction* next = GetNext(); |
| 4056 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4057 | if (next->GetType() == GetType()) { |
| 4058 | return next->AsPhi(); |
| 4059 | } |
| 4060 | next = next->GetNext(); |
| 4061 | } |
| 4062 | return nullptr; |
| 4063 | } |
| 4064 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4065 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4066 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4067 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4068 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 4069 | DCHECK_LE(index, InputCount()); |
| 4070 | return inputs_[index]; |
| 4071 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4072 | |
| 4073 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4074 | DCHECK_LE(index, InputCount()); |
| 4075 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4076 | } |
| 4077 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4078 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4079 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4080 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4081 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4082 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4083 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4084 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4085 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4086 | }; |
| 4087 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4088 | class HNullCheck : public HExpression<1> { |
| 4089 | public: |
| 4090 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4091 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4092 | SetRawInputAt(0, value); |
| 4093 | } |
| 4094 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4095 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4096 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4097 | UNUSED(other); |
| 4098 | return true; |
| 4099 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4100 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4101 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4102 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4103 | bool CanThrow() const OVERRIDE { return true; } |
| 4104 | |
| 4105 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4106 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4107 | |
| 4108 | DECLARE_INSTRUCTION(NullCheck); |
| 4109 | |
| 4110 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4111 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4112 | }; |
| 4113 | |
| 4114 | class FieldInfo : public ValueObject { |
| 4115 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4116 | FieldInfo(MemberOffset field_offset, |
| 4117 | Primitive::Type field_type, |
| 4118 | bool is_volatile, |
| 4119 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4120 | const DexFile& dex_file, |
| 4121 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4122 | : field_offset_(field_offset), |
| 4123 | field_type_(field_type), |
| 4124 | is_volatile_(is_volatile), |
| 4125 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4126 | dex_file_(dex_file), |
| 4127 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4128 | |
| 4129 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4130 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4131 | uint32_t GetFieldIndex() const { return index_; } |
| 4132 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4133 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4134 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4135 | |
| 4136 | private: |
| 4137 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4138 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4139 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4140 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4141 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4142 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4143 | }; |
| 4144 | |
| 4145 | class HInstanceFieldGet : public HExpression<1> { |
| 4146 | public: |
| 4147 | HInstanceFieldGet(HInstruction* value, |
| 4148 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4149 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4150 | bool is_volatile, |
| 4151 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4152 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4153 | Handle<mirror::DexCache> dex_cache, |
| 4154 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4155 | : HExpression( |
| 4156 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4157 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4158 | 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] | 4159 | SetRawInputAt(0, value); |
| 4160 | } |
| 4161 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4162 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4163 | |
| 4164 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4165 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4166 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4167 | } |
| 4168 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4169 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4170 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4171 | } |
| 4172 | |
| 4173 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4174 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4175 | } |
| 4176 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4177 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4178 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4179 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4180 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4181 | |
| 4182 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4183 | |
| 4184 | private: |
| 4185 | const FieldInfo field_info_; |
| 4186 | |
| 4187 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4188 | }; |
| 4189 | |
| 4190 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4191 | public: |
| 4192 | HInstanceFieldSet(HInstruction* object, |
| 4193 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4194 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4195 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4196 | bool is_volatile, |
| 4197 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4198 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4199 | Handle<mirror::DexCache> dex_cache, |
| 4200 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4201 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4202 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4203 | 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] | 4204 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4205 | SetRawInputAt(0, object); |
| 4206 | SetRawInputAt(1, value); |
| 4207 | } |
| 4208 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4209 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4210 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4211 | } |
| 4212 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4213 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4214 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4215 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4216 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4217 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4218 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4219 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4220 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4221 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4222 | |
| 4223 | private: |
| 4224 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4225 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4226 | |
| 4227 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4228 | }; |
| 4229 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4230 | class HArrayGet : public HExpression<2> { |
| 4231 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4232 | HArrayGet(HInstruction* array, |
| 4233 | HInstruction* index, |
| 4234 | Primitive::Type type, |
| 4235 | uint32_t dex_pc = kNoDexPc) |
| 4236 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4237 | SetRawInputAt(0, array); |
| 4238 | SetRawInputAt(1, index); |
| 4239 | } |
| 4240 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4241 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4242 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4243 | UNUSED(other); |
| 4244 | return true; |
| 4245 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4246 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4247 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4248 | // TODO: We can be smarter here. |
| 4249 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4250 | // which generates the implicit null check. There are cases when these can be removed |
| 4251 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4252 | // implicit check here (as long as the address falls in the first page). |
| 4253 | return false; |
| 4254 | } |
| 4255 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4256 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4257 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4258 | HInstruction* GetArray() const { return InputAt(0); } |
| 4259 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4260 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4261 | DECLARE_INSTRUCTION(ArrayGet); |
| 4262 | |
| 4263 | private: |
| 4264 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4265 | }; |
| 4266 | |
| 4267 | class HArraySet : public HTemplateInstruction<3> { |
| 4268 | public: |
| 4269 | HArraySet(HInstruction* array, |
| 4270 | HInstruction* index, |
| 4271 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4272 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4273 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4274 | : HTemplateInstruction( |
| 4275 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4276 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4277 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4278 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
| 4279 | value_can_be_null_(true) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4280 | SetRawInputAt(0, array); |
| 4281 | SetRawInputAt(1, index); |
| 4282 | SetRawInputAt(2, value); |
| 4283 | } |
| 4284 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4285 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4286 | // We currently always call a runtime method to catch array store |
| 4287 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4288 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4289 | } |
| 4290 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4291 | // Can throw ArrayStoreException. |
| 4292 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4293 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4294 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4295 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4296 | // TODO: Same as for ArrayGet. |
| 4297 | return false; |
| 4298 | } |
| 4299 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4300 | void ClearNeedsTypeCheck() { |
| 4301 | needs_type_check_ = false; |
| 4302 | } |
| 4303 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4304 | void ClearValueCanBeNull() { |
| 4305 | value_can_be_null_ = false; |
| 4306 | } |
| 4307 | |
| 4308 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4309 | bool NeedsTypeCheck() const { return needs_type_check_; } |
| 4310 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4311 | HInstruction* GetArray() const { return InputAt(0); } |
| 4312 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4313 | HInstruction* GetValue() const { return InputAt(2); } |
| 4314 | |
| 4315 | Primitive::Type GetComponentType() const { |
| 4316 | // The Dex format does not type floating point index operations. Since the |
| 4317 | // `expected_component_type_` is set during building and can therefore not |
| 4318 | // be correct, we also check what is the value type. If it is a floating |
| 4319 | // point type, we must use that type. |
| 4320 | Primitive::Type value_type = GetValue()->GetType(); |
| 4321 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4322 | ? value_type |
| 4323 | : expected_component_type_; |
| 4324 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4325 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4326 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4327 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4328 | } |
| 4329 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4330 | DECLARE_INSTRUCTION(ArraySet); |
| 4331 | |
| 4332 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4333 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4334 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4335 | bool value_can_be_null_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4336 | |
| 4337 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4338 | }; |
| 4339 | |
| 4340 | class HArrayLength : public HExpression<1> { |
| 4341 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4342 | explicit HArrayLength(HInstruction* array, uint32_t dex_pc = kNoDexPc) |
| 4343 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4344 | // Note that arrays do not change length, so the instruction does not |
| 4345 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4346 | SetRawInputAt(0, array); |
| 4347 | } |
| 4348 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4349 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4350 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4351 | UNUSED(other); |
| 4352 | return true; |
| 4353 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4354 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4355 | return obj == InputAt(0); |
| 4356 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4357 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4358 | DECLARE_INSTRUCTION(ArrayLength); |
| 4359 | |
| 4360 | private: |
| 4361 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4362 | }; |
| 4363 | |
| 4364 | class HBoundsCheck : public HExpression<2> { |
| 4365 | public: |
| 4366 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4367 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4368 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4369 | SetRawInputAt(0, index); |
| 4370 | SetRawInputAt(1, length); |
| 4371 | } |
| 4372 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4373 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4374 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4375 | UNUSED(other); |
| 4376 | return true; |
| 4377 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4378 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4379 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4381 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4382 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4383 | |
| 4384 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4385 | |
| 4386 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4387 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4388 | }; |
| 4389 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4390 | /** |
| 4391 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4392 | * to stay live until the last HInstruction. This class |
| 4393 | * 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] | 4394 | * HInstruction stays live. `index` represents the stack location index of the |
| 4395 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4396 | */ |
| 4397 | class HTemporary : public HTemplateInstruction<0> { |
| 4398 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4399 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4400 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4401 | |
| 4402 | size_t GetIndex() const { return index_; } |
| 4403 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4404 | Primitive::Type GetType() const OVERRIDE { |
| 4405 | // The previous instruction is the one that will be stored in the temporary location. |
| 4406 | DCHECK(GetPrevious() != nullptr); |
| 4407 | return GetPrevious()->GetType(); |
| 4408 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4409 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4410 | DECLARE_INSTRUCTION(Temporary); |
| 4411 | |
| 4412 | private: |
| 4413 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4414 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4415 | }; |
| 4416 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4417 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4418 | public: |
| 4419 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4420 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4421 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4422 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4423 | return true; |
| 4424 | } |
| 4425 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4426 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4427 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4428 | |
| 4429 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4430 | |
| 4431 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4432 | // Only used for code generation, in order to share the same slow path between back edges |
| 4433 | // of a same loop. |
| 4434 | SlowPathCode* slow_path_; |
| 4435 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4436 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4437 | }; |
| 4438 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4439 | /** |
| 4440 | * Instruction to load a Class object. |
| 4441 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4442 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4443 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4444 | HLoadClass(HCurrentMethod* current_method, |
| 4445 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4446 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4447 | bool is_referrers_class, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4448 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4449 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4450 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4451 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4452 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4453 | generate_clinit_check_(false), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4454 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4455 | SetRawInputAt(0, current_method); |
| 4456 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4457 | |
| 4458 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4459 | |
| 4460 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4461 | return other->AsLoadClass()->type_index_ == type_index_; |
| 4462 | } |
| 4463 | |
| 4464 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4465 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4466 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4467 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4468 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4469 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4470 | bool NeedsEnvironment() const OVERRIDE { |
| 4471 | // Will call runtime and load the class if the class is not loaded yet. |
| 4472 | // TODO: finer grain decision. |
| 4473 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4474 | } |
| 4475 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4476 | bool MustGenerateClinitCheck() const { |
| 4477 | return generate_clinit_check_; |
| 4478 | } |
| 4479 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4480 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4481 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4482 | } |
| 4483 | |
| 4484 | bool CanCallRuntime() const { |
| 4485 | return MustGenerateClinitCheck() || !is_referrers_class_; |
| 4486 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4487 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4488 | bool CanThrow() const OVERRIDE { |
| 4489 | // May call runtime and and therefore can throw. |
| 4490 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4491 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4492 | } |
| 4493 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4494 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4495 | return loaded_class_rti_; |
| 4496 | } |
| 4497 | |
| 4498 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4499 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4500 | DCHECK(rti.IsExact()); |
| 4501 | loaded_class_rti_ = rti; |
| 4502 | } |
| 4503 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4504 | const DexFile& GetDexFile() { return dex_file_; } |
| 4505 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4506 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4507 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4508 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4509 | return SideEffects::CanTriggerGC(); |
| 4510 | } |
| 4511 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4512 | DECLARE_INSTRUCTION(LoadClass); |
| 4513 | |
| 4514 | private: |
| 4515 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4516 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4517 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4518 | // Whether this instruction must generate the initialization check. |
| 4519 | // Used for code generation. |
| 4520 | bool generate_clinit_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4521 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4522 | ReferenceTypeInfo loaded_class_rti_; |
| 4523 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4524 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4525 | }; |
| 4526 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4527 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4528 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4529 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4530 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4531 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4532 | SetRawInputAt(0, current_method); |
| 4533 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4534 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4535 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4536 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4537 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4538 | return other->AsLoadString()->string_index_ == string_index_; |
| 4539 | } |
| 4540 | |
| 4541 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4542 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4543 | uint32_t GetStringIndex() const { return string_index_; } |
| 4544 | |
| 4545 | // TODO: Can we deopt or debug when we resolve a string? |
| 4546 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4547 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4548 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4549 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4550 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4551 | return SideEffects::CanTriggerGC(); |
| 4552 | } |
| 4553 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4554 | DECLARE_INSTRUCTION(LoadString); |
| 4555 | |
| 4556 | private: |
| 4557 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4558 | |
| 4559 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4560 | }; |
| 4561 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4562 | /** |
| 4563 | * Performs an initialization check on its Class object input. |
| 4564 | */ |
| 4565 | class HClinitCheck : public HExpression<1> { |
| 4566 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4567 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4568 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4569 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4570 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4571 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4572 | SetRawInputAt(0, constant); |
| 4573 | } |
| 4574 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4575 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4576 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4577 | UNUSED(other); |
| 4578 | return true; |
| 4579 | } |
| 4580 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4581 | bool NeedsEnvironment() const OVERRIDE { |
| 4582 | // May call runtime to initialize the class. |
| 4583 | return true; |
| 4584 | } |
| 4585 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4586 | |
| 4587 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4588 | |
| 4589 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4590 | |
| 4591 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4592 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4593 | }; |
| 4594 | |
| 4595 | class HStaticFieldGet : public HExpression<1> { |
| 4596 | public: |
| 4597 | HStaticFieldGet(HInstruction* cls, |
| 4598 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4599 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4600 | bool is_volatile, |
| 4601 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4602 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4603 | Handle<mirror::DexCache> dex_cache, |
| 4604 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4605 | : HExpression( |
| 4606 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4607 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4608 | 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] | 4609 | SetRawInputAt(0, cls); |
| 4610 | } |
| 4611 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4612 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4613 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4614 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4615 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4616 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4617 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4618 | } |
| 4619 | |
| 4620 | size_t ComputeHashCode() const OVERRIDE { |
| 4621 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4622 | } |
| 4623 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4624 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4625 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4626 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4627 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4628 | |
| 4629 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4630 | |
| 4631 | private: |
| 4632 | const FieldInfo field_info_; |
| 4633 | |
| 4634 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4635 | }; |
| 4636 | |
| 4637 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4638 | public: |
| 4639 | HStaticFieldSet(HInstruction* cls, |
| 4640 | HInstruction* value, |
| 4641 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4642 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4643 | bool is_volatile, |
| 4644 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4645 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4646 | Handle<mirror::DexCache> dex_cache, |
| 4647 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4648 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4649 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4650 | 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] | 4651 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4652 | SetRawInputAt(0, cls); |
| 4653 | SetRawInputAt(1, value); |
| 4654 | } |
| 4655 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4656 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4657 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4658 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4660 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4661 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4662 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4663 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4664 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4665 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4666 | |
| 4667 | private: |
| 4668 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4669 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4670 | |
| 4671 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4672 | }; |
| 4673 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4674 | // Implement the move-exception DEX instruction. |
| 4675 | class HLoadException : public HExpression<0> { |
| 4676 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4677 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4678 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4679 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4680 | bool CanBeNull() const OVERRIDE { return false; } |
| 4681 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4682 | DECLARE_INSTRUCTION(LoadException); |
| 4683 | |
| 4684 | private: |
| 4685 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4686 | }; |
| 4687 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4688 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4689 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4690 | class HClearException : public HTemplateInstruction<0> { |
| 4691 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4692 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4693 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4694 | |
| 4695 | DECLARE_INSTRUCTION(ClearException); |
| 4696 | |
| 4697 | private: |
| 4698 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4699 | }; |
| 4700 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4701 | class HThrow : public HTemplateInstruction<1> { |
| 4702 | public: |
| 4703 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4704 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4705 | SetRawInputAt(0, exception); |
| 4706 | } |
| 4707 | |
| 4708 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4709 | |
| 4710 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4711 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4712 | bool CanThrow() const OVERRIDE { return true; } |
| 4713 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4714 | |
| 4715 | DECLARE_INSTRUCTION(Throw); |
| 4716 | |
| 4717 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4718 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4719 | }; |
| 4720 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4721 | /** |
| 4722 | * Implementation strategies for the code generator of a HInstanceOf |
| 4723 | * or `HCheckCast`. |
| 4724 | */ |
| 4725 | enum class TypeCheckKind { |
| 4726 | kExactCheck, // Can do a single class compare. |
| 4727 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4728 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4729 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4730 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4731 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4732 | }; |
| 4733 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4734 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4735 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4736 | HInstanceOf(HInstruction* object, |
| 4737 | HLoadClass* constant, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4738 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4739 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4740 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4741 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4742 | dex_pc), |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4743 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4744 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4745 | SetRawInputAt(0, object); |
| 4746 | SetRawInputAt(1, constant); |
| 4747 | } |
| 4748 | |
| 4749 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4750 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4751 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4752 | return true; |
| 4753 | } |
| 4754 | |
| 4755 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4756 | return false; |
| 4757 | } |
| 4758 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4759 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4760 | |
| 4761 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4762 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4763 | // Used only in code generation. |
| 4764 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4765 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4766 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4767 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4768 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4769 | ? SideEffects::None() |
| 4770 | // Mips currently does runtime calls for any other checks. |
| 4771 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4772 | } |
| 4773 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4774 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4775 | |
| 4776 | private: |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4777 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4778 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4779 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4780 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4781 | }; |
| 4782 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4783 | class HBoundType : public HExpression<1> { |
| 4784 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4785 | // Constructs an HBoundType with the given upper_bound. |
| 4786 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4787 | HBoundType(HInstruction* input, |
| 4788 | ReferenceTypeInfo upper_bound, |
| 4789 | bool upper_can_be_null, |
| 4790 | uint32_t dex_pc = kNoDexPc) |
| 4791 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4792 | upper_bound_(upper_bound), |
| 4793 | upper_can_be_null_(upper_can_be_null), |
| 4794 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 4795 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4796 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4797 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4798 | } |
| 4799 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4800 | // GetUpper* should only be used in reference type propagation. |
| 4801 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 4802 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4803 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4804 | void SetCanBeNull(bool can_be_null) { |
| 4805 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 4806 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4807 | } |
| 4808 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4809 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4810 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4811 | DECLARE_INSTRUCTION(BoundType); |
| 4812 | |
| 4813 | private: |
| 4814 | // 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] | 4815 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 4816 | // It is used to bound the type in cases like: |
| 4817 | // if (x instanceof ClassX) { |
| 4818 | // // uper_bound_ will be ClassX |
| 4819 | // } |
| 4820 | const ReferenceTypeInfo upper_bound_; |
| 4821 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 4822 | // is false then can_be_null_ cannot be true). |
| 4823 | const bool upper_can_be_null_; |
| 4824 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4825 | |
| 4826 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 4827 | }; |
| 4828 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4829 | class HCheckCast : public HTemplateInstruction<2> { |
| 4830 | public: |
| 4831 | HCheckCast(HInstruction* object, |
| 4832 | HLoadClass* constant, |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4833 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4834 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4835 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4836 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4837 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4838 | SetRawInputAt(0, object); |
| 4839 | SetRawInputAt(1, constant); |
| 4840 | } |
| 4841 | |
| 4842 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4843 | |
| 4844 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4845 | return true; |
| 4846 | } |
| 4847 | |
| 4848 | bool NeedsEnvironment() const OVERRIDE { |
| 4849 | // Instruction may throw a CheckCastError. |
| 4850 | return true; |
| 4851 | } |
| 4852 | |
| 4853 | bool CanThrow() const OVERRIDE { return true; } |
| 4854 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4855 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4856 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4857 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4858 | |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4859 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4860 | |
| 4861 | DECLARE_INSTRUCTION(CheckCast); |
| 4862 | |
| 4863 | private: |
Nicolas Geoffray | 64acf30 | 2015-09-14 22:20:29 +0100 | [diff] [blame] | 4864 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4865 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4866 | |
| 4867 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4868 | }; |
| 4869 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4870 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 4871 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4872 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4873 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4874 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4875 | barrier_kind_(barrier_kind) {} |
| 4876 | |
| 4877 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 4878 | |
| 4879 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 4880 | |
| 4881 | private: |
| 4882 | const MemBarrierKind barrier_kind_; |
| 4883 | |
| 4884 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 4885 | }; |
| 4886 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4887 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 4888 | public: |
| 4889 | enum OperationKind { |
| 4890 | kEnter, |
| 4891 | kExit, |
| 4892 | }; |
| 4893 | |
| 4894 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4895 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4896 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 4897 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4898 | SetRawInputAt(0, object); |
| 4899 | } |
| 4900 | |
| 4901 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 4902 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 4903 | |
| 4904 | bool CanThrow() const OVERRIDE { |
| 4905 | // Verifier guarantees that monitor-exit cannot throw. |
| 4906 | // This is important because it allows the HGraphBuilder to remove |
| 4907 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 4908 | return IsEnter(); |
| 4909 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4910 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4911 | |
| 4912 | bool IsEnter() const { return kind_ == kEnter; } |
| 4913 | |
| 4914 | DECLARE_INSTRUCTION(MonitorOperation); |
| 4915 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4916 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4917 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4918 | |
| 4919 | private: |
| 4920 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 4921 | }; |
| 4922 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4923 | /** |
| 4924 | * A HInstruction used as a marker for the replacement of new + <init> |
| 4925 | * of a String to a call to a StringFactory. Only baseline will see |
| 4926 | * the node at code generation, where it will be be treated as null. |
| 4927 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 4928 | * in the instruction simplifier. |
| 4929 | */ |
| 4930 | class HFakeString : public HTemplateInstruction<0> { |
| 4931 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4932 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 4933 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4934 | |
| 4935 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 4936 | |
| 4937 | DECLARE_INSTRUCTION(FakeString); |
| 4938 | |
| 4939 | private: |
| 4940 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 4941 | }; |
| 4942 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 4943 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4944 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 4945 | MoveOperands(Location source, |
| 4946 | Location destination, |
| 4947 | Primitive::Type type, |
| 4948 | HInstruction* instruction) |
| 4949 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4950 | |
| 4951 | Location GetSource() const { return source_; } |
| 4952 | Location GetDestination() const { return destination_; } |
| 4953 | |
| 4954 | void SetSource(Location value) { source_ = value; } |
| 4955 | void SetDestination(Location value) { destination_ = value; } |
| 4956 | |
| 4957 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 4958 | // destination (but not the source). |
| 4959 | Location MarkPending() { |
| 4960 | DCHECK(!IsPending()); |
| 4961 | Location dest = destination_; |
| 4962 | destination_ = Location::NoLocation(); |
| 4963 | return dest; |
| 4964 | } |
| 4965 | |
| 4966 | void ClearPending(Location dest) { |
| 4967 | DCHECK(IsPending()); |
| 4968 | destination_ = dest; |
| 4969 | } |
| 4970 | |
| 4971 | bool IsPending() const { |
| 4972 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 4973 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 4974 | } |
| 4975 | |
| 4976 | // True if this blocks a move from the given location. |
| 4977 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 4978 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | // A move is redundant if it's been eliminated, if its source and |
| 4982 | // destination are the same, or if its destination is unneeded. |
| 4983 | bool IsRedundant() const { |
| 4984 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 4985 | } |
| 4986 | |
| 4987 | // We clear both operands to indicate move that's been eliminated. |
| 4988 | void Eliminate() { |
| 4989 | source_ = destination_ = Location::NoLocation(); |
| 4990 | } |
| 4991 | |
| 4992 | bool IsEliminated() const { |
| 4993 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 4994 | return source_.IsInvalid(); |
| 4995 | } |
| 4996 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 4997 | Primitive::Type GetType() const { return type_; } |
| 4998 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 4999 | bool Is64BitMove() const { |
| 5000 | return Primitive::Is64BitType(type_); |
| 5001 | } |
| 5002 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5003 | HInstruction* GetInstruction() const { return instruction_; } |
| 5004 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5005 | private: |
| 5006 | Location source_; |
| 5007 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5008 | // The type this move is for. |
| 5009 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5010 | // The instruction this move is assocatied with. Null when this move is |
| 5011 | // for moving an input in the expected locations of user (including a phi user). |
| 5012 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5013 | // in the same parallel move. |
| 5014 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5015 | }; |
| 5016 | |
| 5017 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5018 | |
| 5019 | class HParallelMove : public HTemplateInstruction<0> { |
| 5020 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5021 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
| 5022 | : HTemplateInstruction(SideEffects::None(), dex_pc), moves_(arena, kDefaultNumberOfMoves) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5023 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5024 | void AddMove(Location source, |
| 5025 | Location destination, |
| 5026 | Primitive::Type type, |
| 5027 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5028 | DCHECK(source.IsValid()); |
| 5029 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5030 | if (kIsDebugBuild) { |
| 5031 | if (instruction != nullptr) { |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5032 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5033 | if (moves_.Get(i).GetInstruction() == instruction) { |
| 5034 | // Special case the situation where the move is for the spill slot |
| 5035 | // of the instruction. |
| 5036 | if ((GetPrevious() == instruction) |
| 5037 | || ((GetPrevious() == nullptr) |
| 5038 | && instruction->IsPhi() |
| 5039 | && instruction->GetBlock() == GetBlock())) { |
| 5040 | DCHECK_NE(destination.GetKind(), moves_.Get(i).GetDestination().GetKind()) |
| 5041 | << "Doing parallel moves for the same instruction."; |
| 5042 | } else { |
| 5043 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5044 | } |
| 5045 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5046 | } |
| 5047 | } |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5048 | for (size_t i = 0, e = moves_.Size(); i < e; ++i) { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5049 | DCHECK(!destination.OverlapsWith(moves_.Get(i).GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5050 | << "Overlapped destination for two moves in a parallel move: " |
| 5051 | << moves_.Get(i).GetSource() << " ==> " << moves_.Get(i).GetDestination() << " and " |
| 5052 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5053 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5054 | } |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5055 | moves_.Add(MoveOperands(source, destination, type, instruction)); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5056 | } |
| 5057 | |
| 5058 | MoveOperands* MoveOperandsAt(size_t index) const { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5059 | return moves_.GetRawStorage() + index; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5060 | } |
| 5061 | |
| 5062 | size_t NumMoves() const { return moves_.Size(); } |
| 5063 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5064 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5065 | |
| 5066 | private: |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5067 | GrowableArray<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5068 | |
| 5069 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5070 | }; |
| 5071 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5072 | } // namespace art |
| 5073 | |
| 5074 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5075 | #include "nodes_x86.h" |
| 5076 | #endif |
| 5077 | |
| 5078 | namespace art { |
| 5079 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5080 | class HGraphVisitor : public ValueObject { |
| 5081 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5082 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5083 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5084 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5085 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5086 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5087 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5088 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5089 | void VisitInsertionOrder(); |
| 5090 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5091 | // Visit the graph following dominator tree reverse post-order. |
| 5092 | void VisitReversePostOrder(); |
| 5093 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5094 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5095 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5096 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5097 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5098 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5099 | |
| 5100 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5101 | |
| 5102 | #undef DECLARE_VISIT_INSTRUCTION |
| 5103 | |
| 5104 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5105 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5106 | |
| 5107 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5108 | }; |
| 5109 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5110 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5111 | public: |
| 5112 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5113 | virtual ~HGraphDelegateVisitor() {} |
| 5114 | |
| 5115 | // Visit functions that delegate to to super class. |
| 5116 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5117 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5118 | |
| 5119 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5120 | |
| 5121 | #undef DECLARE_VISIT_INSTRUCTION |
| 5122 | |
| 5123 | private: |
| 5124 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5125 | }; |
| 5126 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5127 | class HInsertionOrderIterator : public ValueObject { |
| 5128 | public: |
| 5129 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5130 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5131 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
| 5132 | HBasicBlock* Current() const { return graph_.GetBlock(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5133 | void Advance() { ++index_; } |
| 5134 | |
| 5135 | private: |
| 5136 | const HGraph& graph_; |
| 5137 | size_t index_; |
| 5138 | |
| 5139 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5140 | }; |
| 5141 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5142 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5143 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5144 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5145 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5146 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5147 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5148 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5149 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5150 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5151 | void Advance() { ++index_; } |
| 5152 | |
| 5153 | private: |
| 5154 | const HGraph& graph_; |
| 5155 | size_t index_; |
| 5156 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5157 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5158 | }; |
| 5159 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5160 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5161 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5162 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5163 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5164 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5165 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5166 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5167 | |
| 5168 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5169 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5170 | void Advance() { --index_; } |
| 5171 | |
| 5172 | private: |
| 5173 | const HGraph& graph_; |
| 5174 | size_t index_; |
| 5175 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5176 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5177 | }; |
| 5178 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5179 | class HLinearPostOrderIterator : public ValueObject { |
| 5180 | public: |
| 5181 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5182 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5183 | |
| 5184 | bool Done() const { return index_ == 0; } |
| 5185 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5186 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5187 | |
| 5188 | void Advance() { |
| 5189 | --index_; |
| 5190 | DCHECK_GE(index_, 0U); |
| 5191 | } |
| 5192 | |
| 5193 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5194 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5195 | size_t index_; |
| 5196 | |
| 5197 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5198 | }; |
| 5199 | |
| 5200 | class HLinearOrderIterator : public ValueObject { |
| 5201 | public: |
| 5202 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5203 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5204 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5205 | bool Done() const { return index_ == order_.size(); } |
| 5206 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5207 | void Advance() { ++index_; } |
| 5208 | |
| 5209 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5210 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5211 | size_t index_; |
| 5212 | |
| 5213 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5214 | }; |
| 5215 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5216 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5217 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5218 | // block id. |
| 5219 | class HBlocksInLoopIterator : public ValueObject { |
| 5220 | public: |
| 5221 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5222 | : blocks_in_loop_(info.GetBlocks()), |
| 5223 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5224 | index_(0) { |
| 5225 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5226 | Advance(); |
| 5227 | } |
| 5228 | } |
| 5229 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5230 | bool Done() const { return index_ == blocks_.size(); } |
| 5231 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5232 | void Advance() { |
| 5233 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5234 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5235 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5236 | break; |
| 5237 | } |
| 5238 | } |
| 5239 | } |
| 5240 | |
| 5241 | private: |
| 5242 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5243 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5244 | size_t index_; |
| 5245 | |
| 5246 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5247 | }; |
| 5248 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5249 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5250 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5251 | // post order. |
| 5252 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5253 | public: |
| 5254 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5255 | : blocks_in_loop_(info.GetBlocks()), |
| 5256 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5257 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5258 | DCHECK(!blocks_.empty()); |
| 5259 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5260 | Advance(); |
| 5261 | } |
| 5262 | } |
| 5263 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5264 | bool Done() const { return index_ == blocks_.size(); } |
| 5265 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5266 | void Advance() { |
| 5267 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5268 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5269 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5270 | break; |
| 5271 | } |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | private: |
| 5276 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5277 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5278 | size_t index_; |
| 5279 | |
| 5280 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5281 | }; |
| 5282 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5283 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5284 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5285 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5286 | : constant->AsLongConstant()->GetValue(); |
| 5287 | } |
| 5288 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5289 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5290 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5291 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5292 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5293 | // times and provide different class resolution but no two class loaders should ever |
| 5294 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5295 | // all sorts of weird failures. |
| 5296 | return &lhs == &rhs; |
| 5297 | } |
| 5298 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5299 | } // namespace art |
| 5300 | |
| 5301 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |