Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #ifndef ART_COMPILER_OPTIMIZING_NODES_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_H_ |
| 19 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 20 | #include <algorithm> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 21 | #include <array> |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 22 | #include <type_traits> |
| 23 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 24 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 25 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 26 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 27 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 28 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 29 | #include "handle.h" |
| 30 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 31 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 32 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 33 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 34 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 35 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 36 | #include "primitive.h" |
Nicolas Geoffray | 0e33643 | 2014-02-26 18:24:38 +0000 | [diff] [blame] | 37 | #include "utils/arena_bit_vector.h" |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 38 | |
| 39 | namespace art { |
| 40 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 41 | class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 42 | class HBasicBlock; |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 43 | class HCurrentMethod; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 44 | class HDoubleConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 45 | class HEnvironment; |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 46 | class HFakeString; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 47 | class HFloatConstant; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 48 | class HGraphBuilder; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 49 | class HGraphVisitor; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 50 | class HInstruction; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 51 | class HIntConstant; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 52 | class HInvoke; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 53 | class HLongConstant; |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 54 | class HNullConstant; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 55 | class HPhi; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 56 | class HSuspendCheck; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 57 | class HTryBoundary; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 58 | class LiveInterval; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 59 | class LocationSummary; |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 60 | class SlowPathCode; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 61 | class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 62 | |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 63 | namespace mirror { |
| 64 | class DexCache; |
| 65 | } // namespace mirror |
| 66 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 67 | static const int kDefaultNumberOfBlocks = 8; |
| 68 | static const int kDefaultNumberOfSuccessors = 2; |
| 69 | static const int kDefaultNumberOfPredecessors = 2; |
David Brazdil | b618ade | 2015-07-29 10:31:29 +0100 | [diff] [blame] | 70 | static const int kDefaultNumberOfExceptionalPredecessors = 0; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 71 | static const int kDefaultNumberOfDominatedBlocks = 1; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 72 | static const int kDefaultNumberOfBackEdges = 1; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 73 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 74 | static constexpr uint32_t kMaxIntShiftValue = 0x1f; |
| 75 | static constexpr uint64_t kMaxLongShiftValue = 0x3f; |
| 76 | |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 77 | static constexpr uint32_t kUnknownFieldIndex = static_cast<uint32_t>(-1); |
| 78 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 79 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 80 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 81 | static constexpr uint32_t kNoDexPc = -1; |
| 82 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 83 | enum IfCondition { |
| 84 | kCondEQ, |
| 85 | kCondNE, |
| 86 | kCondLT, |
| 87 | kCondLE, |
| 88 | kCondGT, |
| 89 | kCondGE, |
| 90 | }; |
| 91 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 92 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 93 | public: |
| 94 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 95 | |
| 96 | void AddInstruction(HInstruction* instruction); |
| 97 | void RemoveInstruction(HInstruction* instruction); |
| 98 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 99 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 100 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 101 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 102 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 103 | // Return true if this list contains `instruction`. |
| 104 | bool Contains(HInstruction* instruction) const; |
| 105 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 106 | // Return true if `instruction1` is found before `instruction2` in |
| 107 | // this instruction list and false otherwise. Abort if none |
| 108 | // of these instructions is found. |
| 109 | bool FoundBefore(const HInstruction* instruction1, |
| 110 | const HInstruction* instruction2) const; |
| 111 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 112 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 113 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 114 | |
| 115 | // Update the block of all instructions to be `block`. |
| 116 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 117 | |
| 118 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 119 | void Add(const HInstructionList& instruction_list); |
| 120 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 121 | // Return the number of instructions in the list. This is an expensive operation. |
| 122 | size_t CountSize() const; |
| 123 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 124 | private: |
| 125 | HInstruction* first_instruction_; |
| 126 | HInstruction* last_instruction_; |
| 127 | |
| 128 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 129 | friend class HGraph; |
| 130 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 131 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 132 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 133 | |
| 134 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 135 | }; |
| 136 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 137 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 138 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 139 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 140 | HGraph(ArenaAllocator* arena, |
| 141 | const DexFile& dex_file, |
| 142 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 143 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 144 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 145 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 146 | bool debuggable = false, |
| 147 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 148 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 149 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 150 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 151 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 152 | entry_block_(nullptr), |
| 153 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 154 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 155 | number_of_vregs_(0), |
| 156 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 157 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 158 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 159 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 160 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 161 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 162 | dex_file_(dex_file), |
| 163 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 164 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 165 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 166 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 167 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 168 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 169 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 170 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 171 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 172 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 173 | cached_current_method_(nullptr) { |
| 174 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 175 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 176 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 177 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 178 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 179 | |
| 180 | HBasicBlock* GetBlock(size_t id) const { |
| 181 | DCHECK_LT(id, blocks_.size()); |
| 182 | return blocks_[id]; |
| 183 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 184 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 185 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 186 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 187 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 188 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 189 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 190 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 191 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 192 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 193 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 194 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 195 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 196 | // Try building the SSA form of this graph, with dominance computation and loop |
| 197 | // recognition. Returns whether it was successful in doing all these steps. |
| 198 | bool TryBuildingSsa() { |
| 199 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 200 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 201 | // elimination phase checks the consistency of the graph when doing a post-order |
| 202 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 203 | // users remaining when being visited. |
| 204 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 205 | // Precompute per-block try membership before entering the SSA builder, |
| 206 | // which needs the information to build catch block phis from values of |
| 207 | // locals at throwing instructions inside try blocks. |
| 208 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 209 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 210 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 211 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 212 | } |
| 213 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 214 | void ComputeDominanceInformation(); |
| 215 | void ClearDominanceInformation(); |
| 216 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 217 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 218 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 219 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 220 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 221 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 222 | // Analyze all natural loops in this graph. Returns false if one |
| 223 | // loop is not natural, that is the header does not dominate the |
| 224 | // back edge. |
| 225 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 226 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 227 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 228 | // order and loop information. |
| 229 | void ComputeTryBlockInformation(); |
| 230 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 231 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 232 | // Returns the instruction used to replace the invoke expression or null if the |
| 233 | // invoke is for a void method. |
| 234 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 235 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 236 | // Need to add a couple of blocks to test if the loop body is entered and |
| 237 | // put deoptimization instructions, etc. |
| 238 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 239 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 240 | // Removes `block` from the graph. |
| 241 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 242 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 243 | // Splits the edge between `block` and `successor` while preserving the |
| 244 | // indices in the predecessor/successor lists. If there are multiple edges |
| 245 | // between the blocks, the lowest indices are used. |
| 246 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 247 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 248 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 249 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 250 | void SimplifyLoop(HBasicBlock* header); |
| 251 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 252 | int32_t GetNextInstructionId() { |
| 253 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 254 | return current_instruction_id_++; |
| 255 | } |
| 256 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 257 | int32_t GetCurrentInstructionId() const { |
| 258 | return current_instruction_id_; |
| 259 | } |
| 260 | |
| 261 | void SetCurrentInstructionId(int32_t id) { |
| 262 | current_instruction_id_ = id; |
| 263 | } |
| 264 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 265 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 266 | return maximum_number_of_out_vregs_; |
| 267 | } |
| 268 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 269 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 270 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 271 | } |
| 272 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 273 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 274 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 275 | } |
| 276 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 277 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 278 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 281 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 282 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 283 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 284 | } |
| 285 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 286 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 287 | number_of_vregs_ = number_of_vregs; |
| 288 | } |
| 289 | |
| 290 | uint16_t GetNumberOfVRegs() const { |
| 291 | return number_of_vregs_; |
| 292 | } |
| 293 | |
| 294 | void SetNumberOfInVRegs(uint16_t value) { |
| 295 | number_of_in_vregs_ = value; |
| 296 | } |
| 297 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 298 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 299 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 300 | return number_of_vregs_ - number_of_in_vregs_; |
| 301 | } |
| 302 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 303 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 304 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 305 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 306 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 307 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 308 | return linear_order_; |
| 309 | } |
| 310 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 311 | bool HasBoundsChecks() const { |
| 312 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 315 | void SetHasBoundsChecks(bool value) { |
| 316 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 317 | } |
| 318 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 319 | bool ShouldGenerateConstructorBarrier() const { |
| 320 | return should_generate_constructor_barrier_; |
| 321 | } |
| 322 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 323 | bool IsDebuggable() const { return debuggable_; } |
| 324 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 325 | // Returns a constant of the given type and value. If it does not exist |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 326 | // already, it is created and inserted into the graph. This method is only for |
| 327 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 328 | HConstant* GetConstant(Primitive::Type type, int64_t value, uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 329 | |
| 330 | // TODO: This is problematic for the consistency of reference type propagation |
| 331 | // because it can be created anytime after the pass and thus it will be left |
| 332 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 334 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 335 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 336 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 337 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 339 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 340 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 341 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 342 | return CreateConstant(bit_cast<int32_t, float>(value), &cached_float_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 343 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 344 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 345 | return CreateConstant(bit_cast<int64_t, double>(value), &cached_double_constants_, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 346 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 347 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 348 | HCurrentMethod* GetCurrentMethod(); |
| 349 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 350 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 351 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 352 | const DexFile& GetDexFile() const { |
| 353 | return dex_file_; |
| 354 | } |
| 355 | |
| 356 | uint32_t GetMethodIdx() const { |
| 357 | return method_idx_; |
| 358 | } |
| 359 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 360 | InvokeType GetInvokeType() const { |
| 361 | return invoke_type_; |
| 362 | } |
| 363 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 364 | InstructionSet GetInstructionSet() const { |
| 365 | return instruction_set_; |
| 366 | } |
| 367 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 368 | bool HasTryCatch() const { return has_try_catch_; } |
| 369 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 370 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 371 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 372 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 373 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 374 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 375 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 376 | template <class InstructionType, typename ValueType> |
| 377 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 378 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 379 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 380 | // Try to find an existing constant of the given value. |
| 381 | InstructionType* constant = nullptr; |
| 382 | auto cached_constant = cache->find(value); |
| 383 | if (cached_constant != cache->end()) { |
| 384 | constant = cached_constant->second; |
| 385 | } |
| 386 | |
| 387 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 388 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 389 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 390 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 391 | cache->Overwrite(value, constant); |
| 392 | InsertConstant(constant); |
| 393 | } |
| 394 | return constant; |
| 395 | } |
| 396 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 397 | void InsertConstant(HConstant* instruction); |
| 398 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 399 | // Cache a float constant into the graph. This method should only be |
| 400 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 401 | void CacheFloatConstant(HFloatConstant* constant); |
| 402 | |
| 403 | // See CacheFloatConstant comment. |
| 404 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 405 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 406 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 407 | |
| 408 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 409 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 410 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 411 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 412 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 413 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 414 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 415 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 416 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 417 | HBasicBlock* entry_block_; |
| 418 | HBasicBlock* exit_block_; |
| 419 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 420 | // The maximum number of virtual registers arguments passed to a HInvoke in this graph. |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 421 | uint16_t maximum_number_of_out_vregs_; |
| 422 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 423 | // The number of virtual registers in this method. Contains the parameters. |
| 424 | uint16_t number_of_vregs_; |
| 425 | |
| 426 | // The number of virtual registers used by parameters of this method. |
| 427 | uint16_t number_of_in_vregs_; |
| 428 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 429 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 430 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 431 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 432 | // Has bounds checks. We can totally skip BCE if it's false. |
| 433 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 434 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 435 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 436 | // try/catch-related passes if false. |
| 437 | bool has_try_catch_; |
| 438 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 439 | // Indicates whether the graph should be compiled in a way that |
| 440 | // ensures full debuggability. If false, we can apply more |
| 441 | // aggressive optimizations that may limit the level of debugging. |
| 442 | const bool debuggable_; |
| 443 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 444 | // The current id to assign to a newly added instruction. See HInstruction.id_. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 445 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 446 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 447 | // The dex file from which the method is from. |
| 448 | const DexFile& dex_file_; |
| 449 | |
| 450 | // The method index in the dex file. |
| 451 | const uint32_t method_idx_; |
| 452 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 453 | // If inlined, this encodes how the callee is being invoked. |
| 454 | const InvokeType invoke_type_; |
| 455 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 456 | // Whether the graph has been transformed to SSA form. Only used |
| 457 | // in debug mode to ensure we are not using properties only valid |
| 458 | // for non-SSA form (like the number of temporaries). |
| 459 | bool in_ssa_form_; |
| 460 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 461 | const bool should_generate_constructor_barrier_; |
| 462 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 463 | const InstructionSet instruction_set_; |
| 464 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 465 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 466 | HNullConstant* cached_null_constant_; |
| 467 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 468 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 469 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 470 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 471 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 472 | HCurrentMethod* cached_current_method_; |
| 473 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 474 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 475 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 476 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 477 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 478 | }; |
| 479 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 480 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 481 | public: |
| 482 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 483 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 484 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 485 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 486 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 487 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 488 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 489 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 490 | |
| 491 | HBasicBlock* GetHeader() const { |
| 492 | return header_; |
| 493 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 494 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 495 | void SetHeader(HBasicBlock* block) { |
| 496 | header_ = block; |
| 497 | } |
| 498 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 499 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 500 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 501 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 502 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 503 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 504 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 505 | } |
| 506 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 507 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 508 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 509 | } |
| 510 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 511 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 512 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 513 | } |
| 514 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 515 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 516 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 517 | } |
| 518 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 519 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 520 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 521 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 522 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 523 | } |
| 524 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 525 | // Returns the lifetime position of the back edge that has the |
| 526 | // greatest lifetime position. |
| 527 | size_t GetLifetimeEnd() const; |
| 528 | |
| 529 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 530 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 531 | } |
| 532 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 533 | // Finds blocks that are part of this loop. Returns whether the loop is a natural loop, |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 534 | // that is the header dominates the back edge. |
| 535 | bool Populate(); |
| 536 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 537 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 538 | // Populate(). If there are no back edges left, the loop info is completely |
| 539 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 540 | // inner loops first. |
| 541 | void Update(); |
| 542 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 543 | // Returns whether this loop information contains `block`. |
| 544 | // Note that this loop information *must* be populated before entering this function. |
| 545 | bool Contains(const HBasicBlock& block) const; |
| 546 | |
| 547 | // Returns whether this loop information is an inner loop of `other`. |
| 548 | // Note that `other` *must* be populated before entering this function. |
| 549 | bool IsIn(const HLoopInformation& other) const; |
| 550 | |
| 551 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 552 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 553 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 554 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 555 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 556 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 557 | // Internal recursive implementation of `Populate`. |
| 558 | void PopulateRecursive(HBasicBlock* block); |
| 559 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 560 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 561 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 562 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 563 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 564 | |
| 565 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 566 | }; |
| 567 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 568 | // Stores try/catch information for basic blocks. |
| 569 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 570 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 571 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 572 | public: |
| 573 | // Try block information constructor. |
| 574 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 575 | : try_entry_(&try_entry), |
| 576 | catch_dex_file_(nullptr), |
| 577 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 578 | DCHECK(try_entry_ != nullptr); |
| 579 | } |
| 580 | |
| 581 | // Catch block information constructor. |
| 582 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 583 | : try_entry_(nullptr), |
| 584 | catch_dex_file_(&dex_file), |
| 585 | catch_type_index_(catch_type_index) {} |
| 586 | |
| 587 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 588 | |
| 589 | const HTryBoundary& GetTryEntry() const { |
| 590 | DCHECK(IsTryBlock()); |
| 591 | return *try_entry_; |
| 592 | } |
| 593 | |
| 594 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 595 | |
| 596 | bool IsCatchAllTypeIndex() const { |
| 597 | DCHECK(IsCatchBlock()); |
| 598 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 599 | } |
| 600 | |
| 601 | uint16_t GetCatchTypeIndex() const { |
| 602 | DCHECK(IsCatchBlock()); |
| 603 | return catch_type_index_; |
| 604 | } |
| 605 | |
| 606 | const DexFile& GetCatchDexFile() const { |
| 607 | DCHECK(IsCatchBlock()); |
| 608 | return *catch_dex_file_; |
| 609 | } |
| 610 | |
| 611 | private: |
| 612 | // One of possibly several TryBoundary instructions entering the block's try. |
| 613 | // Only set for try blocks. |
| 614 | const HTryBoundary* try_entry_; |
| 615 | |
| 616 | // Exception type information. Only set for catch blocks. |
| 617 | const DexFile* catch_dex_file_; |
| 618 | const uint16_t catch_type_index_; |
| 619 | }; |
| 620 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 621 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 622 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 623 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 624 | // A block in a method. Contains the list of instructions represented |
| 625 | // as a double linked list. Each block knows its predecessors and |
| 626 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 627 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 628 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 629 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 630 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 631 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 632 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 633 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 634 | loop_information_(nullptr), |
| 635 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 636 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 637 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 638 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 639 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 640 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 641 | try_catch_information_(nullptr) { |
| 642 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 643 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 644 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 645 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 646 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 647 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 648 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 649 | } |
| 650 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 651 | HBasicBlock* GetPredecessor(size_t pred_idx) const { |
| 652 | DCHECK_LT(pred_idx, predecessors_.size()); |
| 653 | return predecessors_[pred_idx]; |
| 654 | } |
| 655 | |
| 656 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 657 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 658 | } |
| 659 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 660 | HBasicBlock* GetSuccessor(size_t succ_idx) const { |
| 661 | DCHECK_LT(succ_idx, successors_.size()); |
| 662 | return successors_[succ_idx]; |
| 663 | } |
| 664 | |
| 665 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 666 | return ContainsElement(successors_, block, start_from); |
| 667 | } |
| 668 | |
| 669 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 670 | return dominated_blocks_; |
| 671 | } |
| 672 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 673 | bool IsEntryBlock() const { |
| 674 | return graph_->GetEntryBlock() == this; |
| 675 | } |
| 676 | |
| 677 | bool IsExitBlock() const { |
| 678 | return graph_->GetExitBlock() == this; |
| 679 | } |
| 680 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 681 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 682 | bool IsSingleTryBoundary() const; |
| 683 | |
| 684 | // Returns true if this block emits nothing but a jump. |
| 685 | bool IsSingleJump() const { |
| 686 | HLoopInformation* loop_info = GetLoopInformation(); |
| 687 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 688 | // Back edges generate a suspend check. |
| 689 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 690 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 691 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 692 | void AddBackEdge(HBasicBlock* back_edge) { |
| 693 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 694 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 695 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 696 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 697 | loop_information_->AddBackEdge(back_edge); |
| 698 | } |
| 699 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 700 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 701 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 702 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 703 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 704 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 705 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 706 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 707 | HBasicBlock* GetDominator() const { return dominator_; } |
| 708 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 709 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 710 | |
| 711 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 712 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 713 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 714 | |
| 715 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 716 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 717 | } |
| 718 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 719 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 720 | |
| 721 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 722 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 723 | } |
| 724 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 725 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 726 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 727 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 728 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 729 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 730 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 731 | |
| 732 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 733 | successors_.push_back(block); |
| 734 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 737 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 738 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 739 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | new_block->predecessors_.push_back(this); |
| 741 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 744 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 745 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 746 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 747 | new_block->successors_.push_back(this); |
| 748 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 749 | } |
| 750 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 751 | // Insert `this` between `predecessor` and `successor. This method |
| 752 | // preserves the indicies, and will update the first edge found between |
| 753 | // `predecessor` and `successor`. |
| 754 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 755 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 756 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 757 | successor->predecessors_[predecessor_index] = this; |
| 758 | predecessor->successors_[successor_index] = this; |
| 759 | successors_.push_back(successor); |
| 760 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 761 | } |
| 762 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 763 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 764 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 765 | } |
| 766 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 767 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 768 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 769 | } |
| 770 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 771 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 772 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 773 | } |
| 774 | |
| 775 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 776 | predecessors_.push_back(block); |
| 777 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 778 | } |
| 779 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 780 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 781 | DCHECK_EQ(predecessors_.size(), 2u); |
| 782 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 783 | } |
| 784 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 785 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 786 | DCHECK_EQ(successors_.size(), 2u); |
| 787 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 788 | } |
| 789 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 790 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 791 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 792 | } |
| 793 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 794 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 795 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 796 | } |
| 797 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 798 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 799 | DCHECK_EQ(GetPredecessors().size(), 1u); |
| 800 | return GetPredecessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 804 | DCHECK_EQ(GetSuccessors().size(), 1u); |
| 805 | return GetSuccessor(0); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 806 | } |
| 807 | |
| 808 | // Returns whether the first occurrence of `predecessor` in the list of |
| 809 | // predecessors is at index `idx`. |
| 810 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | DCHECK_EQ(GetPredecessor(idx), predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 812 | return GetPredecessorIndexOf(predecessor) == idx; |
| 813 | } |
| 814 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 815 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 816 | // these are stored at the beginning of the successor list. |
| 817 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 818 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 819 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 820 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 821 | // Create a new block between this block and its predecessors. The new block |
| 822 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 823 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 824 | // loop and try/catch information are not updated. |
| 825 | HBasicBlock* CreateImmediateDominator(); |
| 826 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 827 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 828 | // created, latter block. Note that this method will add the block to the |
| 829 | // graph, create a Goto at the end of the former block and will create an edge |
| 830 | // between the blocks. It will not, however, update the reverse post order or |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 831 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 832 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 833 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 834 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 835 | // created block. Note that this method just updates raw block information, |
| 836 | // like predecessors, successors, dominators, and instruction list. It does not |
| 837 | // update the graph, reverse post order, loop information, nor make sure the |
| 838 | // blocks are consistent (for example ending with a control flow instruction). |
| 839 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 840 | |
| 841 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 842 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 843 | // that this method does not update the graph, reverse post order, loop |
| 844 | // information, nor make sure the blocks are consistent (for example ending |
| 845 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 846 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 847 | |
| 848 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 849 | // of `this` are moved to `other`. |
| 850 | // Note that this method does not update the graph, reverse post order, loop |
| 851 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 852 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 853 | void ReplaceWith(HBasicBlock* other); |
| 854 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 855 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 856 | // order, links to predecessors, successors, dominators and deletes the block |
| 857 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 858 | // predecessor of `other` and vice versa. |
| 859 | void MergeWith(HBasicBlock* other); |
| 860 | |
| 861 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 862 | // removes it from all loops it is included in and eventually from the graph. |
| 863 | // The block must not dominate any other block. Predecessors and successors |
| 864 | // are safely updated. |
| 865 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 866 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 867 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 868 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 869 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 870 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 871 | // Replace instruction `initial` with `replacement` within this block. |
| 872 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 873 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 874 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 875 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 876 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 877 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 878 | // instruction is not in use and removes it from the use lists of its inputs. |
| 879 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 880 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 881 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 882 | |
| 883 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 884 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 885 | } |
| 886 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 887 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 888 | DCHECK(IsLoopHeader()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 889 | return GetPredecessor(0) == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 890 | } |
| 891 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 892 | HLoopInformation* GetLoopInformation() const { |
| 893 | return loop_information_; |
| 894 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 895 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 896 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 897 | // loop_information if it is an outer loop of the passed loop information. |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 898 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 899 | void SetInLoop(HLoopInformation* info) { |
| 900 | if (IsLoopHeader()) { |
| 901 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 902 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 903 | loop_information_ = info; |
| 904 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 905 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 906 | // Note that a non loop header having a loop information means this loop information |
| 907 | // has already been populated |
| 908 | loop_information_ = info; |
| 909 | } else { |
| 910 | // Block is part of an inner loop. Do not update the loop information. |
| 911 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 912 | // at this point, because this method is being called while populating `info`. |
| 913 | } |
| 914 | } |
| 915 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 916 | // Raw update of the loop information. |
| 917 | void SetLoopInformation(HLoopInformation* info) { |
| 918 | loop_information_ = info; |
| 919 | } |
| 920 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 921 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 922 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 923 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 924 | |
| 925 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 926 | try_catch_information_ = try_catch_information; |
| 927 | } |
| 928 | |
| 929 | bool IsTryBlock() const { |
| 930 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 931 | } |
| 932 | |
| 933 | bool IsCatchBlock() const { |
| 934 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 935 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 936 | |
| 937 | // Returns the try entry that this block's successors should have. They will |
| 938 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 939 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 940 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 941 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 942 | bool HasThrowingInstructions() const; |
| 943 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 944 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 945 | bool Dominates(HBasicBlock* block) const; |
| 946 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 947 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 948 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 949 | |
| 950 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 951 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 952 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 953 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 954 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 955 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 956 | bool HasSinglePhi() const; |
| 957 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 958 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 959 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 960 | ArenaVector<HBasicBlock*> predecessors_; |
| 961 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 962 | HInstructionList instructions_; |
| 963 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 964 | HLoopInformation* loop_information_; |
| 965 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 966 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 967 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 968 | // The dex program counter of the first instruction of this block. |
| 969 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 970 | size_t lifetime_start_; |
| 971 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 972 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 973 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 974 | friend class HGraph; |
| 975 | friend class HInstruction; |
| 976 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 977 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 978 | }; |
| 979 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 980 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 981 | // from the innermost to the outermost. |
| 982 | class HLoopInformationOutwardIterator : public ValueObject { |
| 983 | public: |
| 984 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 985 | : current_(block.GetLoopInformation()) {} |
| 986 | |
| 987 | bool Done() const { return current_ == nullptr; } |
| 988 | |
| 989 | void Advance() { |
| 990 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 991 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 992 | } |
| 993 | |
| 994 | HLoopInformation* Current() const { |
| 995 | DCHECK(!Done()); |
| 996 | return current_; |
| 997 | } |
| 998 | |
| 999 | private: |
| 1000 | HLoopInformation* current_; |
| 1001 | |
| 1002 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 1003 | }; |
| 1004 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1005 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1006 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1007 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1008 | M(ArrayGet, Instruction) \ |
| 1009 | M(ArrayLength, Instruction) \ |
| 1010 | M(ArraySet, Instruction) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1011 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1012 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1013 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1014 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1015 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1016 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1017 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1018 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1019 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1020 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1021 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1022 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1023 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1024 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1025 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1026 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1027 | M(FloatConstant, Constant) \ |
| 1028 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1029 | M(GreaterThan, Condition) \ |
| 1030 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1031 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1032 | M(InstanceFieldGet, Instruction) \ |
| 1033 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1034 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1035 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1036 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1037 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1038 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1039 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1040 | M(LessThan, Condition) \ |
| 1041 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1042 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1043 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1044 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1045 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1046 | M(Local, Instruction) \ |
| 1047 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1048 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1049 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1050 | M(Mul, BinaryOperation) \ |
| 1051 | M(Neg, UnaryOperation) \ |
| 1052 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1053 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1054 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1055 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1056 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1057 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1058 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1059 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1060 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1061 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1062 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1063 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1064 | M(Return, Instruction) \ |
| 1065 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1066 | M(Shl, BinaryOperation) \ |
| 1067 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1068 | M(StaticFieldGet, Instruction) \ |
| 1069 | M(StaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1070 | M(StoreLocal, Instruction) \ |
| 1071 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1072 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1073 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1074 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1075 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1076 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1077 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1078 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1079 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1080 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1081 | |
| 1082 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1083 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1084 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1085 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1086 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1087 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1088 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1089 | |
| 1090 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1091 | |
| 1092 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1093 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1094 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1095 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1096 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1097 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1098 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1099 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1100 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1101 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1102 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1103 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1104 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1105 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1106 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1107 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1108 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1109 | #undef FORWARD_DECLARATION |
| 1110 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1111 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1112 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1113 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1114 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1115 | H##type* As##type() OVERRIDE { return this; } \ |
| 1116 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1117 | return other->Is##type(); \ |
| 1118 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1119 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1120 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1121 | template <typename T> class HUseList; |
| 1122 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1123 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1124 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1125 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1126 | HUseListNode* GetPrevious() const { return prev_; } |
| 1127 | HUseListNode* GetNext() const { return next_; } |
| 1128 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1129 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1130 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1131 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1132 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1133 | HUseListNode(T user, size_t index) |
| 1134 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1135 | |
| 1136 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1137 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1138 | HUseListNode<T>* prev_; |
| 1139 | HUseListNode<T>* next_; |
| 1140 | |
| 1141 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1142 | |
| 1143 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1144 | }; |
| 1145 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1146 | template <typename T> |
| 1147 | class HUseList : public ValueObject { |
| 1148 | public: |
| 1149 | HUseList() : first_(nullptr) {} |
| 1150 | |
| 1151 | void Clear() { |
| 1152 | first_ = nullptr; |
| 1153 | } |
| 1154 | |
| 1155 | // Adds a new entry at the beginning of the use list and returns |
| 1156 | // the newly created node. |
| 1157 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1158 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1159 | if (IsEmpty()) { |
| 1160 | first_ = new_node; |
| 1161 | } else { |
| 1162 | first_->prev_ = new_node; |
| 1163 | new_node->next_ = first_; |
| 1164 | first_ = new_node; |
| 1165 | } |
| 1166 | return new_node; |
| 1167 | } |
| 1168 | |
| 1169 | HUseListNode<T>* GetFirst() const { |
| 1170 | return first_; |
| 1171 | } |
| 1172 | |
| 1173 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1174 | DCHECK(node != nullptr); |
| 1175 | DCHECK(Contains(node)); |
| 1176 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1177 | if (node->prev_ != nullptr) { |
| 1178 | node->prev_->next_ = node->next_; |
| 1179 | } |
| 1180 | if (node->next_ != nullptr) { |
| 1181 | node->next_->prev_ = node->prev_; |
| 1182 | } |
| 1183 | if (node == first_) { |
| 1184 | first_ = node->next_; |
| 1185 | } |
| 1186 | } |
| 1187 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1188 | bool Contains(const HUseListNode<T>* node) const { |
| 1189 | if (node == nullptr) { |
| 1190 | return false; |
| 1191 | } |
| 1192 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1193 | if (current == node) { |
| 1194 | return true; |
| 1195 | } |
| 1196 | } |
| 1197 | return false; |
| 1198 | } |
| 1199 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1200 | bool IsEmpty() const { |
| 1201 | return first_ == nullptr; |
| 1202 | } |
| 1203 | |
| 1204 | bool HasOnlyOneUse() const { |
| 1205 | return first_ != nullptr && first_->next_ == nullptr; |
| 1206 | } |
| 1207 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1208 | size_t SizeSlow() const { |
| 1209 | size_t count = 0; |
| 1210 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1211 | ++count; |
| 1212 | } |
| 1213 | return count; |
| 1214 | } |
| 1215 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1216 | private: |
| 1217 | HUseListNode<T>* first_; |
| 1218 | }; |
| 1219 | |
| 1220 | template<typename T> |
| 1221 | class HUseIterator : public ValueObject { |
| 1222 | public: |
| 1223 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1224 | |
| 1225 | bool Done() const { return current_ == nullptr; } |
| 1226 | |
| 1227 | void Advance() { |
| 1228 | DCHECK(!Done()); |
| 1229 | current_ = current_->GetNext(); |
| 1230 | } |
| 1231 | |
| 1232 | HUseListNode<T>* Current() const { |
| 1233 | DCHECK(!Done()); |
| 1234 | return current_; |
| 1235 | } |
| 1236 | |
| 1237 | private: |
| 1238 | HUseListNode<T>* current_; |
| 1239 | |
| 1240 | friend class HValue; |
| 1241 | }; |
| 1242 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1243 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1244 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1245 | // by the used instructions. |
| 1246 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1247 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1248 | public: |
| 1249 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1250 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1251 | |
| 1252 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1253 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1254 | DCHECK(instruction_ != nullptr); |
| 1255 | DCHECK(use_node_ != nullptr); |
| 1256 | DCHECK(old_record.use_node_ == nullptr); |
| 1257 | } |
| 1258 | |
| 1259 | HInstruction* GetInstruction() const { return instruction_; } |
| 1260 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1261 | |
| 1262 | private: |
| 1263 | // Instruction used by the user. |
| 1264 | HInstruction* instruction_; |
| 1265 | |
| 1266 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1267 | HUseListNode<T>* use_node_; |
| 1268 | }; |
| 1269 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1270 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1271 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1272 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1273 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1274 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1275 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1276 | * modify the value of a reference field read [although it may modify the |
| 1277 | * reference fetch prior to reading the field, which is represented by its own |
| 1278 | * write/read dependence]). The analysis makes conservative points-to |
| 1279 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1280 | * the same, and any reference read depends on any reference read without |
| 1281 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1282 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1283 | * The internal representation uses 38-bit and is described in the table below. |
| 1284 | * The first line indicates the side effect, and for field/array accesses the |
| 1285 | * second line indicates the type of the access (in the order of the |
| 1286 | * Primitive::Type enum). |
| 1287 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1288 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1289 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1290 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1291 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1292 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1293 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1294 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1295 | * |
| 1296 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1297 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1298 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1299 | class SideEffects : public ValueObject { |
| 1300 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1301 | SideEffects() : flags_(0) {} |
| 1302 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1303 | static SideEffects None() { |
| 1304 | return SideEffects(0); |
| 1305 | } |
| 1306 | |
| 1307 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1308 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1309 | } |
| 1310 | |
| 1311 | static SideEffects AllChanges() { |
| 1312 | return SideEffects(kAllChangeBits); |
| 1313 | } |
| 1314 | |
| 1315 | static SideEffects AllDependencies() { |
| 1316 | return SideEffects(kAllDependOnBits); |
| 1317 | } |
| 1318 | |
| 1319 | static SideEffects AllExceptGCDependency() { |
| 1320 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1321 | } |
| 1322 | |
| 1323 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1324 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1325 | } |
| 1326 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1327 | static SideEffects AllWrites() { |
| 1328 | return SideEffects(kAllWrites); |
| 1329 | } |
| 1330 | |
| 1331 | static SideEffects AllReads() { |
| 1332 | return SideEffects(kAllReads); |
| 1333 | } |
| 1334 | |
| 1335 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1336 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1337 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1338 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1341 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1342 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1343 | } |
| 1344 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1345 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1346 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1347 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1348 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1349 | } |
| 1350 | |
| 1351 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1352 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1353 | } |
| 1354 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1355 | static SideEffects CanTriggerGC() { |
| 1356 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1357 | } |
| 1358 | |
| 1359 | static SideEffects DependsOnGC() { |
| 1360 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1361 | } |
| 1362 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1363 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1364 | SideEffects Union(SideEffects other) const { |
| 1365 | return SideEffects(flags_ | other.flags_); |
| 1366 | } |
| 1367 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1368 | SideEffects Exclusion(SideEffects other) const { |
| 1369 | return SideEffects(flags_ & ~other.flags_); |
| 1370 | } |
| 1371 | |
| 1372 | bool Includes(SideEffects other) const { |
| 1373 | return (other.flags_ & flags_) == other.flags_; |
| 1374 | } |
| 1375 | |
| 1376 | bool HasSideEffects() const { |
| 1377 | return (flags_ & kAllChangeBits); |
| 1378 | } |
| 1379 | |
| 1380 | bool HasDependencies() const { |
| 1381 | return (flags_ & kAllDependOnBits); |
| 1382 | } |
| 1383 | |
| 1384 | // Returns true if there are no side effects or dependencies. |
| 1385 | bool DoesNothing() const { |
| 1386 | return flags_ == 0; |
| 1387 | } |
| 1388 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1389 | // Returns true if something is written. |
| 1390 | bool DoesAnyWrite() const { |
| 1391 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1392 | } |
| 1393 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1394 | // Returns true if something is read. |
| 1395 | bool DoesAnyRead() const { |
| 1396 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1397 | } |
| 1398 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1399 | // Returns true if potentially everything is written and read |
| 1400 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1401 | bool DoesAllReadWrite() const { |
| 1402 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1403 | } |
| 1404 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1405 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1406 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1407 | } |
| 1408 | |
| 1409 | // Returns true if this may read something written by other. |
| 1410 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1411 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1412 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1413 | } |
| 1414 | |
| 1415 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1416 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1417 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1418 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1419 | for (int s = kLastBit; s >= 0; s--) { |
| 1420 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1421 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1422 | // This is a bit for the GC side effect. |
| 1423 | if (current_bit_is_set) { |
| 1424 | flags += "GC"; |
| 1425 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1426 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1427 | } else { |
| 1428 | // This is a bit for the array/field analysis. |
| 1429 | // The underscore character stands for the 'can trigger GC' bit. |
| 1430 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1431 | if (current_bit_is_set) { |
| 1432 | flags += kDebug[s]; |
| 1433 | } |
| 1434 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1435 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1436 | flags += "|"; |
| 1437 | } |
| 1438 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1439 | } |
| 1440 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1441 | } |
| 1442 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1443 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1444 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1445 | private: |
| 1446 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1447 | |
| 1448 | static constexpr int kFieldWriteOffset = 0; |
| 1449 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1450 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1451 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1452 | |
| 1453 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1454 | |
| 1455 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1456 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1457 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1458 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1459 | |
| 1460 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1461 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1462 | |
| 1463 | // Aliases. |
| 1464 | |
| 1465 | static_assert(kChangeBits == kDependOnBits, |
| 1466 | "the 'change' bits should match the 'depend on' bits."); |
| 1467 | |
| 1468 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1469 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1470 | static constexpr uint64_t kAllWrites = |
| 1471 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1472 | static constexpr uint64_t kAllReads = |
| 1473 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1474 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1475 | // Work around the fact that HIR aliases I/F and J/D. |
| 1476 | // TODO: remove this interceptor once HIR types are clean |
| 1477 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1478 | switch (type) { |
| 1479 | case Primitive::kPrimInt: |
| 1480 | case Primitive::kPrimFloat: |
| 1481 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1482 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1483 | case Primitive::kPrimLong: |
| 1484 | case Primitive::kPrimDouble: |
| 1485 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1486 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1487 | default: |
| 1488 | return TypeFlag(type, offset); |
| 1489 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1490 | } |
| 1491 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1492 | // Translates type to bit flag. |
| 1493 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1494 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1495 | const uint64_t one = 1; |
| 1496 | const int shift = type; // 0-based consecutive enum |
| 1497 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1498 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1499 | return one << (type + offset); |
| 1500 | } |
| 1501 | |
| 1502 | // Private constructor on direct flags value. |
| 1503 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1504 | |
| 1505 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1506 | }; |
| 1507 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1508 | // 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] | 1509 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1510 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1511 | HEnvironment(ArenaAllocator* arena, |
| 1512 | size_t number_of_vregs, |
| 1513 | const DexFile& dex_file, |
| 1514 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1515 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1516 | InvokeType invoke_type, |
| 1517 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1518 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1519 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1520 | parent_(nullptr), |
| 1521 | dex_file_(dex_file), |
| 1522 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1523 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1524 | invoke_type_(invoke_type), |
| 1525 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1526 | } |
| 1527 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1528 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1529 | : HEnvironment(arena, |
| 1530 | to_copy.Size(), |
| 1531 | to_copy.GetDexFile(), |
| 1532 | to_copy.GetMethodIdx(), |
| 1533 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1534 | to_copy.GetInvokeType(), |
| 1535 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1536 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1537 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1538 | if (parent_ != nullptr) { |
| 1539 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1540 | } else { |
| 1541 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1542 | parent_->CopyFrom(parent); |
| 1543 | if (parent->GetParent() != nullptr) { |
| 1544 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1545 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1546 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1547 | } |
| 1548 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1549 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1550 | void CopyFrom(HEnvironment* environment); |
| 1551 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1552 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1553 | // input to the loop phi instead. This is for inserting instructions that |
| 1554 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1555 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1556 | |
| 1557 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1558 | DCHECK_LT(index, Size()); |
| 1559 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
| 1562 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1563 | DCHECK_LT(index, Size()); |
| 1564 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1567 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1568 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1569 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1570 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1571 | HEnvironment* GetParent() const { return parent_; } |
| 1572 | |
| 1573 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1574 | DCHECK_LT(index, Size()); |
| 1575 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1579 | DCHECK_LT(index, Size()); |
| 1580 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1581 | } |
| 1582 | |
| 1583 | uint32_t GetDexPc() const { |
| 1584 | return dex_pc_; |
| 1585 | } |
| 1586 | |
| 1587 | uint32_t GetMethodIdx() const { |
| 1588 | return method_idx_; |
| 1589 | } |
| 1590 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1591 | InvokeType GetInvokeType() const { |
| 1592 | return invoke_type_; |
| 1593 | } |
| 1594 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1595 | const DexFile& GetDexFile() const { |
| 1596 | return dex_file_; |
| 1597 | } |
| 1598 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1599 | HInstruction* GetHolder() const { |
| 1600 | return holder_; |
| 1601 | } |
| 1602 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1603 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1604 | // Record instructions' use entries of this environment for constant-time removal. |
| 1605 | // It should only be called by HInstruction when a new environment use is added. |
| 1606 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1607 | DCHECK(env_use->GetUser() == this); |
| 1608 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1609 | DCHECK_LT(index, Size()); |
| 1610 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1611 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1612 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1613 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1614 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1615 | HEnvironment* parent_; |
| 1616 | const DexFile& dex_file_; |
| 1617 | const uint32_t method_idx_; |
| 1618 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1619 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1620 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1621 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1622 | HInstruction* const holder_; |
| 1623 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1624 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1625 | |
| 1626 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1627 | }; |
| 1628 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1629 | class ReferenceTypeInfo : ValueObject { |
| 1630 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1631 | typedef Handle<mirror::Class> TypeHandle; |
| 1632 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1633 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1634 | // The constructor will check that the type_handle is valid. |
| 1635 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1636 | } |
| 1637 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1638 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1639 | |
| 1640 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1641 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1642 | } |
| 1643 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1644 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1645 | return IsValidHandle(type_handle_); |
| 1646 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1647 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1648 | |
| 1649 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1650 | DCHECK(IsValid()); |
| 1651 | return GetTypeHandle()->IsObjectClass(); |
| 1652 | } |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1653 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1654 | DCHECK(IsValid()); |
| 1655 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1656 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1657 | |
| 1658 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1659 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1660 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1661 | DCHECK(IsValid()); |
| 1662 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1663 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1664 | } |
| 1665 | |
| 1666 | // Returns true if the type information provide the same amount of details. |
| 1667 | // 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] | 1668 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1669 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1670 | if (!IsValid() && !rti.IsValid()) { |
| 1671 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1672 | return true; |
| 1673 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1674 | if (!IsValid() || !rti.IsValid()) { |
| 1675 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1676 | return false; |
| 1677 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1678 | return IsExact() == rti.IsExact() |
| 1679 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1680 | } |
| 1681 | |
| 1682 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1683 | ReferenceTypeInfo(); |
| 1684 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1685 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1686 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1687 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1688 | // 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] | 1689 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1690 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1691 | }; |
| 1692 | |
| 1693 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1694 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1695 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1696 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1697 | HInstruction(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1698 | : previous_(nullptr), |
| 1699 | next_(nullptr), |
| 1700 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1701 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1702 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1703 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1704 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1705 | locations_(nullptr), |
| 1706 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1707 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1708 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1709 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1710 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1711 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1712 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1713 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1714 | enum InstructionKind { |
| 1715 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1716 | }; |
| 1717 | #undef DECLARE_KIND |
| 1718 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1719 | HInstruction* GetNext() const { return next_; } |
| 1720 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1721 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1722 | HInstruction* GetNextDisregardingMoves() const; |
| 1723 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1724 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1725 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1726 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1727 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1728 | bool IsInBlock() const { return block_ != nullptr; } |
| 1729 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1730 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1731 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1732 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1733 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1734 | |
| 1735 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1736 | virtual const char* DebugName() const = 0; |
| 1737 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1738 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1739 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1740 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1741 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1742 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1743 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1744 | |
| 1745 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1746 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1747 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1748 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1749 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1750 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1751 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1752 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1753 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1754 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1755 | // Does not apply for all instructions, but having this at top level greatly |
| 1756 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1757 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1758 | virtual bool CanBeNull() const { |
| 1759 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1760 | return true; |
| 1761 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1762 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1763 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1764 | UNUSED(obj); |
| 1765 | return false; |
| 1766 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1767 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1768 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1769 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1770 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1771 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1772 | return reference_type_info_; |
| 1773 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1774 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1775 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1776 | DCHECK(user != nullptr); |
| 1777 | HUseListNode<HInstruction*>* use = |
| 1778 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1779 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1780 | } |
| 1781 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1782 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1783 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1784 | HUseListNode<HEnvironment*>* env_use = |
| 1785 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1786 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1787 | } |
| 1788 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1789 | void RemoveAsUserOfInput(size_t input) { |
| 1790 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1791 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1792 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1793 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1794 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1795 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1796 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1797 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1798 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1799 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1800 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1801 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1802 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1803 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1804 | // Does this instruction strictly dominate `other_instruction`? |
| 1805 | // Returns false if this instruction and `other_instruction` are the same. |
| 1806 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1807 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1808 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1809 | int GetId() const { return id_; } |
| 1810 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1811 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1812 | int GetSsaIndex() const { return ssa_index_; } |
| 1813 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1814 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1815 | |
| 1816 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1817 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1818 | // Set the `environment_` field. Raw because this method does not |
| 1819 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1820 | void SetRawEnvironment(HEnvironment* environment) { |
| 1821 | DCHECK(environment_ == nullptr); |
| 1822 | DCHECK_EQ(environment->GetHolder(), this); |
| 1823 | environment_ = environment; |
| 1824 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1825 | |
| 1826 | // Set the environment of this instruction, copying it from `environment`. While |
| 1827 | // copying, the uses lists are being updated. |
| 1828 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1829 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1830 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1831 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1832 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1833 | if (environment->GetParent() != nullptr) { |
| 1834 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1835 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1836 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1837 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1838 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1839 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1840 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1841 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1842 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1843 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1844 | if (environment->GetParent() != nullptr) { |
| 1845 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1846 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1847 | } |
| 1848 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1849 | // Returns the number of entries in the environment. Typically, that is the |
| 1850 | // number of dex registers in a method. It could be more in case of inlining. |
| 1851 | size_t EnvironmentSize() const; |
| 1852 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1853 | LocationSummary* GetLocations() const { return locations_; } |
| 1854 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1855 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1856 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1857 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1858 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1859 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1860 | // uses of this instruction by `other` are *not* updated. |
| 1861 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1862 | ReplaceWith(other); |
| 1863 | other->ReplaceInput(this, use_index); |
| 1864 | } |
| 1865 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1866 | // Move `this` instruction before `cursor`. |
| 1867 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1868 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1869 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1870 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1871 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1872 | virtual H##type* As##type() { return nullptr; } |
| 1873 | |
| 1874 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1875 | #undef INSTRUCTION_TYPE_CHECK |
| 1876 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1877 | // Returns whether the instruction can be moved within the graph. |
| 1878 | virtual bool CanBeMoved() const { return false; } |
| 1879 | |
| 1880 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1881 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1882 | UNUSED(other); |
| 1883 | return false; |
| 1884 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1885 | |
| 1886 | // Returns whether any data encoded in the two instructions is equal. |
| 1887 | // This method does not look at the inputs. Both instructions must be |
| 1888 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1889 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1890 | UNUSED(other); |
| 1891 | return false; |
| 1892 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1893 | |
| 1894 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1895 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1896 | // 2) Their inputs are identical. |
| 1897 | bool Equals(HInstruction* other) const; |
| 1898 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1899 | virtual InstructionKind GetKind() const = 0; |
| 1900 | |
| 1901 | virtual size_t ComputeHashCode() const { |
| 1902 | size_t result = GetKind(); |
| 1903 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1904 | result = (result * 31) + InputAt(i)->GetId(); |
| 1905 | } |
| 1906 | return result; |
| 1907 | } |
| 1908 | |
| 1909 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1910 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1911 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1912 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1913 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1914 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1915 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1916 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1917 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1918 | |
| 1919 | // Returns whether the code generation of the instruction will require to have access |
| 1920 | // to the current method. Such instructions are: |
| 1921 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1922 | // to walk the stack and have the current method stored at a specific stack address. |
| 1923 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1924 | // fields of the current method. |
| 1925 | bool NeedsCurrentMethod() const { |
| 1926 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1927 | } |
| 1928 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1929 | virtual bool NeedsDexCache() const { return false; } |
| 1930 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1931 | // Does this instruction have any use in an environment before |
| 1932 | // control flow hits 'other'? |
| 1933 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1934 | |
| 1935 | // Remove all references to environment uses of this instruction. |
| 1936 | // The caller must ensure that this is safe to do. |
| 1937 | void RemoveEnvironmentUsers(); |
| 1938 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1939 | protected: |
| 1940 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1941 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1942 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1943 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1944 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1945 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1946 | HInstruction* previous_; |
| 1947 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1948 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1949 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1950 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1951 | // An instruction gets an id when it is added to the graph. |
| 1952 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1953 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1954 | int id_; |
| 1955 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1956 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 1957 | int ssa_index_; |
| 1958 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1959 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1960 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1961 | |
| 1962 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1963 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1964 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1965 | // The environment associated with this instruction. Not null if the instruction |
| 1966 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1967 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1968 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1969 | // Set by the code generator. |
| 1970 | LocationSummary* locations_; |
| 1971 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1972 | // Set by the liveness analysis. |
| 1973 | LiveInterval* live_interval_; |
| 1974 | |
| 1975 | // Set by the liveness analysis, this is the position in a linear |
| 1976 | // order of blocks where this instruction's live interval start. |
| 1977 | size_t lifetime_position_; |
| 1978 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1979 | const SideEffects side_effects_; |
| 1980 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1981 | // TODO: for primitive types this should be marked as invalid. |
| 1982 | ReferenceTypeInfo reference_type_info_; |
| 1983 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1984 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1985 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1986 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1987 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1988 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1989 | |
| 1990 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 1991 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1992 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1993 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1994 | class HInputIterator : public ValueObject { |
| 1995 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1996 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1997 | |
| 1998 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 1999 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2000 | void Advance() { index_++; } |
| 2001 | |
| 2002 | private: |
| 2003 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2004 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2005 | |
| 2006 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2007 | }; |
| 2008 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2009 | class HInstructionIterator : public ValueObject { |
| 2010 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2011 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2012 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2013 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2014 | } |
| 2015 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2016 | bool Done() const { return instruction_ == nullptr; } |
| 2017 | HInstruction* Current() const { return instruction_; } |
| 2018 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2019 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2020 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2021 | } |
| 2022 | |
| 2023 | private: |
| 2024 | HInstruction* instruction_; |
| 2025 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2026 | |
| 2027 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2028 | }; |
| 2029 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2030 | class HBackwardInstructionIterator : public ValueObject { |
| 2031 | public: |
| 2032 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2033 | : instruction_(instructions.last_instruction_) { |
| 2034 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2035 | } |
| 2036 | |
| 2037 | bool Done() const { return instruction_ == nullptr; } |
| 2038 | HInstruction* Current() const { return instruction_; } |
| 2039 | void Advance() { |
| 2040 | instruction_ = next_; |
| 2041 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2042 | } |
| 2043 | |
| 2044 | private: |
| 2045 | HInstruction* instruction_; |
| 2046 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2047 | |
| 2048 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2049 | }; |
| 2050 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2051 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2052 | class HTemplateInstruction: public HInstruction { |
| 2053 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2054 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2055 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2056 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2057 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2058 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2059 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2060 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2061 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2062 | DCHECK_LT(i, N); |
| 2063 | return inputs_[i]; |
| 2064 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2065 | |
| 2066 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2067 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2068 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2069 | } |
| 2070 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2071 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2072 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2073 | |
| 2074 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2075 | }; |
| 2076 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2077 | // HTemplateInstruction specialization for N=0. |
| 2078 | template<> |
| 2079 | class HTemplateInstruction<0>: public HInstruction { |
| 2080 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2081 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2082 | : HInstruction(side_effects, dex_pc) {} |
| 2083 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2084 | virtual ~HTemplateInstruction() {} |
| 2085 | |
| 2086 | size_t InputCount() const OVERRIDE { return 0; } |
| 2087 | |
| 2088 | protected: |
| 2089 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2090 | LOG(FATAL) << "Unreachable"; |
| 2091 | UNREACHABLE(); |
| 2092 | } |
| 2093 | |
| 2094 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2095 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2096 | LOG(FATAL) << "Unreachable"; |
| 2097 | UNREACHABLE(); |
| 2098 | } |
| 2099 | |
| 2100 | private: |
| 2101 | friend class SsaBuilder; |
| 2102 | }; |
| 2103 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2104 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2105 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2106 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2107 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc = kNoDexPc) |
| 2108 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2109 | virtual ~HExpression() {} |
| 2110 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2111 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2112 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2113 | protected: |
| 2114 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2115 | }; |
| 2116 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2117 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2118 | // instruction that branches to the exit block. |
| 2119 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2120 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2121 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2122 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2123 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2124 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2125 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2126 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2127 | |
| 2128 | private: |
| 2129 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2130 | }; |
| 2131 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2132 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2133 | // instruction that branches to the exit block. |
| 2134 | class HReturn : public HTemplateInstruction<1> { |
| 2135 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2136 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2137 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2138 | SetRawInputAt(0, value); |
| 2139 | } |
| 2140 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2141 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2142 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2143 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2144 | |
| 2145 | private: |
| 2146 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2147 | }; |
| 2148 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2149 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2150 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2151 | // exit block. |
| 2152 | class HExit : public HTemplateInstruction<0> { |
| 2153 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2154 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2155 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2156 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2157 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2158 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2159 | |
| 2160 | private: |
| 2161 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2162 | }; |
| 2163 | |
| 2164 | // Jumps from one block to another. |
| 2165 | class HGoto : public HTemplateInstruction<0> { |
| 2166 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2167 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2168 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2169 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2170 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2171 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2172 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2173 | } |
| 2174 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2175 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2176 | |
| 2177 | private: |
| 2178 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2179 | }; |
| 2180 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2181 | class HConstant : public HExpression<0> { |
| 2182 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2183 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2184 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2185 | |
| 2186 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2187 | |
| 2188 | virtual bool IsMinusOne() const { return false; } |
| 2189 | virtual bool IsZero() const { return false; } |
| 2190 | virtual bool IsOne() const { return false; } |
| 2191 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2192 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2193 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2194 | DECLARE_INSTRUCTION(Constant); |
| 2195 | |
| 2196 | private: |
| 2197 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2198 | }; |
| 2199 | |
| 2200 | class HNullConstant : public HConstant { |
| 2201 | public: |
| 2202 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2203 | return true; |
| 2204 | } |
| 2205 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2206 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2207 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2208 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2209 | |
| 2210 | DECLARE_INSTRUCTION(NullConstant); |
| 2211 | |
| 2212 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2213 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2214 | |
| 2215 | friend class HGraph; |
| 2216 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2217 | }; |
| 2218 | |
| 2219 | // Constants of the type int. Those can be from Dex instructions, or |
| 2220 | // synthesized (for example with the if-eqz instruction). |
| 2221 | class HIntConstant : public HConstant { |
| 2222 | public: |
| 2223 | int32_t GetValue() const { return value_; } |
| 2224 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2225 | uint64_t GetValueAsUint64() const OVERRIDE { return static_cast<uint64_t>(value_); } |
| 2226 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2227 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2228 | DCHECK(other->IsIntConstant()); |
| 2229 | return other->AsIntConstant()->value_ == value_; |
| 2230 | } |
| 2231 | |
| 2232 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2233 | |
| 2234 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2235 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2236 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2237 | |
| 2238 | DECLARE_INSTRUCTION(IntConstant); |
| 2239 | |
| 2240 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2241 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2242 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2243 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2244 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2245 | |
| 2246 | const int32_t value_; |
| 2247 | |
| 2248 | friend class HGraph; |
| 2249 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2250 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2251 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2252 | }; |
| 2253 | |
| 2254 | class HLongConstant : public HConstant { |
| 2255 | public: |
| 2256 | int64_t GetValue() const { return value_; } |
| 2257 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2258 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2259 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2260 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2261 | DCHECK(other->IsLongConstant()); |
| 2262 | return other->AsLongConstant()->value_ == value_; |
| 2263 | } |
| 2264 | |
| 2265 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2266 | |
| 2267 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2268 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2269 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2270 | |
| 2271 | DECLARE_INSTRUCTION(LongConstant); |
| 2272 | |
| 2273 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2274 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2275 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2276 | |
| 2277 | const int64_t value_; |
| 2278 | |
| 2279 | friend class HGraph; |
| 2280 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2281 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2282 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2283 | // Conditional branch. A block ending with an HIf instruction must have |
| 2284 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2285 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2286 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2287 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2288 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2289 | SetRawInputAt(0, input); |
| 2290 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2291 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2292 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2293 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2294 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2295 | return GetBlock()->GetSuccessor(0); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2296 | } |
| 2297 | |
| 2298 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2299 | return GetBlock()->GetSuccessor(1); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2300 | } |
| 2301 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2302 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2303 | |
| 2304 | private: |
| 2305 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2306 | }; |
| 2307 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2308 | |
| 2309 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2310 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2311 | // non-exceptional control flow. |
| 2312 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2313 | // higher indices in no particular order. |
| 2314 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2315 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2316 | enum BoundaryKind { |
| 2317 | kEntry, |
| 2318 | kExit, |
| 2319 | }; |
| 2320 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2321 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2322 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2323 | |
| 2324 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2325 | |
| 2326 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2327 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessor(0); } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2328 | |
| 2329 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2330 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2331 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2332 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2333 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
| 2336 | // If not present already, adds `handler` to its block's list of exception |
| 2337 | // handlers. |
| 2338 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2339 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2340 | GetBlock()->AddSuccessor(handler); |
| 2341 | } |
| 2342 | } |
| 2343 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2344 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2345 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2346 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2347 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2348 | DECLARE_INSTRUCTION(TryBoundary); |
| 2349 | |
| 2350 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2351 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2352 | |
| 2353 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2354 | }; |
| 2355 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2356 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2357 | // exceptional successors of its basic block. |
| 2358 | class HExceptionHandlerIterator : public ValueObject { |
| 2359 | public: |
| 2360 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2361 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2362 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2363 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
| 2364 | HBasicBlock* Current() const { return block_.GetSuccessor(index_); } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2365 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2366 | void Advance() { ++index_; } |
| 2367 | |
| 2368 | private: |
| 2369 | const HBasicBlock& block_; |
| 2370 | size_t index_; |
| 2371 | |
| 2372 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2373 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2374 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2375 | // Deoptimize to interpreter, upon checking a condition. |
| 2376 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2377 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2378 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2379 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2380 | SetRawInputAt(0, cond); |
| 2381 | } |
| 2382 | |
| 2383 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2384 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2385 | |
| 2386 | DECLARE_INSTRUCTION(Deoptimize); |
| 2387 | |
| 2388 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2389 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2390 | }; |
| 2391 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2392 | // Represents the ArtMethod that was passed as a first argument to |
| 2393 | // the method. It is used by instructions that depend on it, like |
| 2394 | // instructions that work with the dex cache. |
| 2395 | class HCurrentMethod : public HExpression<0> { |
| 2396 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2397 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2398 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2399 | |
| 2400 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2401 | |
| 2402 | private: |
| 2403 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2404 | }; |
| 2405 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2406 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2407 | // have one successor for each entry in the switch table, and the final successor |
| 2408 | // will be the block containing the next Dex opcode. |
| 2409 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2410 | public: |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2411 | HPackedSwitch(int32_t start_value, uint32_t num_entries, HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2412 | uint32_t dex_pc = kNoDexPc) |
| 2413 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2414 | start_value_(start_value), |
| 2415 | num_entries_(num_entries) { |
| 2416 | SetRawInputAt(0, input); |
| 2417 | } |
| 2418 | |
| 2419 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2420 | |
| 2421 | int32_t GetStartValue() const { return start_value_; } |
| 2422 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2423 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2424 | |
| 2425 | HBasicBlock* GetDefaultBlock() const { |
| 2426 | // Last entry is the default block. |
| 2427 | return GetBlock()->GetSuccessor(num_entries_); |
| 2428 | } |
| 2429 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2430 | |
| 2431 | private: |
| 2432 | int32_t start_value_; |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2433 | uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2434 | |
| 2435 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2436 | }; |
| 2437 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2438 | class HUnaryOperation : public HExpression<1> { |
| 2439 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2440 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2441 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2442 | SetRawInputAt(0, input); |
| 2443 | } |
| 2444 | |
| 2445 | HInstruction* GetInput() const { return InputAt(0); } |
| 2446 | Primitive::Type GetResultType() const { return GetType(); } |
| 2447 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2448 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2449 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2450 | UNUSED(other); |
| 2451 | return true; |
| 2452 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2453 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2454 | // Try to statically evaluate `operation` and return a HConstant |
| 2455 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2456 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2457 | HConstant* TryStaticEvaluation() const; |
| 2458 | |
| 2459 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2460 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2461 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2462 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2463 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2464 | |
| 2465 | private: |
| 2466 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2467 | }; |
| 2468 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2469 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2470 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2471 | HBinaryOperation(Primitive::Type result_type, |
| 2472 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2473 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2474 | SideEffects side_effects = SideEffects::None(), |
| 2475 | uint32_t dex_pc = kNoDexPc) |
| 2476 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2477 | SetRawInputAt(0, left); |
| 2478 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2481 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2482 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2483 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2484 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2485 | virtual bool IsCommutative() const { return false; } |
| 2486 | |
| 2487 | // Put constant on the right. |
| 2488 | // Returns whether order is changed. |
| 2489 | bool OrderInputsWithConstantOnTheRight() { |
| 2490 | HInstruction* left = InputAt(0); |
| 2491 | HInstruction* right = InputAt(1); |
| 2492 | if (left->IsConstant() && !right->IsConstant()) { |
| 2493 | ReplaceInput(right, 0); |
| 2494 | ReplaceInput(left, 1); |
| 2495 | return true; |
| 2496 | } |
| 2497 | return false; |
| 2498 | } |
| 2499 | |
| 2500 | // Order inputs by instruction id, but favor constant on the right side. |
| 2501 | // This helps GVN for commutative ops. |
| 2502 | void OrderInputs() { |
| 2503 | DCHECK(IsCommutative()); |
| 2504 | HInstruction* left = InputAt(0); |
| 2505 | HInstruction* right = InputAt(1); |
| 2506 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2507 | return; |
| 2508 | } |
| 2509 | if (OrderInputsWithConstantOnTheRight()) { |
| 2510 | return; |
| 2511 | } |
| 2512 | // Order according to instruction id. |
| 2513 | if (left->GetId() > right->GetId()) { |
| 2514 | ReplaceInput(right, 0); |
| 2515 | ReplaceInput(left, 1); |
| 2516 | } |
| 2517 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2518 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2519 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2520 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2521 | UNUSED(other); |
| 2522 | return true; |
| 2523 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2524 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2525 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2526 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2527 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2528 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2529 | |
| 2530 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2531 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2532 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2533 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2534 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2535 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2536 | return nullptr; |
| 2537 | } |
| 2538 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2539 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2540 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2541 | return nullptr; |
| 2542 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2543 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2544 | // 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] | 2545 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2546 | HConstant* GetConstantRight() const; |
| 2547 | |
| 2548 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2549 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2550 | HInstruction* GetLeastConstantLeft() const; |
| 2551 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2552 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2553 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2554 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2555 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2556 | }; |
| 2557 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2558 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2559 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2560 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2561 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2562 | kGtBias, // return 1 for NaN comparisons |
| 2563 | kLtBias, // return -1 for NaN comparisons |
| 2564 | }; |
| 2565 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2566 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2567 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2568 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2569 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2570 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2571 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2572 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2573 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2574 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2575 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2576 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2577 | // `instruction`, and disregard moves in between. |
| 2578 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2579 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2580 | DECLARE_INSTRUCTION(Condition); |
| 2581 | |
| 2582 | virtual IfCondition GetCondition() const = 0; |
| 2583 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2584 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2585 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2586 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2587 | |
| 2588 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2589 | |
| 2590 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2591 | return bias_ == other->AsCondition()->bias_; |
| 2592 | } |
| 2593 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2594 | bool IsFPConditionTrueIfNaN() const { |
| 2595 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2596 | IfCondition if_cond = GetCondition(); |
| 2597 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2598 | } |
| 2599 | |
| 2600 | bool IsFPConditionFalseIfNaN() const { |
| 2601 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2602 | IfCondition if_cond = GetCondition(); |
| 2603 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2604 | } |
| 2605 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2606 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2607 | // For register allocation purposes, returns whether this instruction needs to be |
| 2608 | // materialized (that is, not just be in the processor flags). |
| 2609 | bool needs_materialization_; |
| 2610 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2611 | // Needed if we merge a HCompare into a HCondition. |
| 2612 | ComparisonBias bias_; |
| 2613 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2614 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2615 | }; |
| 2616 | |
| 2617 | // Instruction to check if two inputs are equal to each other. |
| 2618 | class HEqual : public HCondition { |
| 2619 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2620 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2621 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2622 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2623 | bool IsCommutative() const OVERRIDE { return true; } |
| 2624 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2625 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2626 | |
| 2627 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2628 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2629 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2630 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2631 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2632 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2633 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2634 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2635 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2636 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2637 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2638 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2639 | return kCondEQ; |
| 2640 | } |
| 2641 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2642 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2643 | return kCondNE; |
| 2644 | } |
| 2645 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2646 | private: |
| 2647 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2648 | }; |
| 2649 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2650 | class HNotEqual : public HCondition { |
| 2651 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2652 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2653 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2654 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2655 | bool IsCommutative() const OVERRIDE { return true; } |
| 2656 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2657 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2658 | |
| 2659 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2660 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2661 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2662 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2663 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2664 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2665 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2666 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2667 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2668 | DECLARE_INSTRUCTION(NotEqual); |
| 2669 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2670 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2671 | return kCondNE; |
| 2672 | } |
| 2673 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2674 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2675 | return kCondEQ; |
| 2676 | } |
| 2677 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2678 | private: |
| 2679 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2680 | }; |
| 2681 | |
| 2682 | class HLessThan : public HCondition { |
| 2683 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2684 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2685 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2686 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2687 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2688 | |
| 2689 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2690 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2691 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2692 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2693 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2694 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2695 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2696 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2697 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2698 | DECLARE_INSTRUCTION(LessThan); |
| 2699 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2700 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2701 | return kCondLT; |
| 2702 | } |
| 2703 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2704 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2705 | return kCondGE; |
| 2706 | } |
| 2707 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2708 | private: |
| 2709 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2710 | }; |
| 2711 | |
| 2712 | class HLessThanOrEqual : public HCondition { |
| 2713 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2714 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2715 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2716 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2717 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2718 | |
| 2719 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2720 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2721 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2722 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2723 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2724 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2725 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2726 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2727 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2728 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2729 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2730 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2731 | return kCondLE; |
| 2732 | } |
| 2733 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2734 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2735 | return kCondGT; |
| 2736 | } |
| 2737 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2738 | private: |
| 2739 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2740 | }; |
| 2741 | |
| 2742 | class HGreaterThan : public HCondition { |
| 2743 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2744 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2745 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2746 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2747 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2748 | |
| 2749 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2750 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2751 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2752 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2753 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2754 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2755 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2756 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2757 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2758 | DECLARE_INSTRUCTION(GreaterThan); |
| 2759 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2760 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2761 | return kCondGT; |
| 2762 | } |
| 2763 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2764 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2765 | return kCondLE; |
| 2766 | } |
| 2767 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2768 | private: |
| 2769 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2770 | }; |
| 2771 | |
| 2772 | class HGreaterThanOrEqual : public HCondition { |
| 2773 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2774 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2775 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2776 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2777 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2778 | |
| 2779 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2780 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2781 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2782 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2783 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2784 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2785 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2786 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2787 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2788 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2789 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2790 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2791 | return kCondGE; |
| 2792 | } |
| 2793 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2794 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2795 | return kCondLT; |
| 2796 | } |
| 2797 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2798 | private: |
| 2799 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2800 | }; |
| 2801 | |
| 2802 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2803 | // Instruction to check how two inputs compare to each other. |
| 2804 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2805 | class HCompare : public HBinaryOperation { |
| 2806 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2807 | HCompare(Primitive::Type type, |
| 2808 | HInstruction* first, |
| 2809 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2810 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2811 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2812 | : HBinaryOperation(Primitive::kPrimInt, |
| 2813 | first, |
| 2814 | second, |
| 2815 | SideEffectsForArchRuntimeCalls(type), |
| 2816 | dex_pc), |
| 2817 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2818 | DCHECK_EQ(type, first->GetType()); |
| 2819 | DCHECK_EQ(type, second->GetType()); |
| 2820 | } |
| 2821 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2822 | template <typename T> |
| 2823 | 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] | 2824 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2825 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2826 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2827 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2828 | } |
| 2829 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2830 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2831 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2832 | } |
| 2833 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2834 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2835 | return bias_ == other->AsCompare()->bias_; |
| 2836 | } |
| 2837 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2838 | ComparisonBias GetBias() const { return bias_; } |
| 2839 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2840 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2841 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2842 | |
| 2843 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2844 | // MIPS64 uses a runtime call for FP comparisons. |
| 2845 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2846 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2847 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2848 | DECLARE_INSTRUCTION(Compare); |
| 2849 | |
| 2850 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2851 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2852 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2853 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2854 | }; |
| 2855 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2856 | // A local in the graph. Corresponds to a Dex register. |
| 2857 | class HLocal : public HTemplateInstruction<0> { |
| 2858 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2859 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2860 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2861 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2862 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2863 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2864 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2865 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2866 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2867 | // The Dex register number. |
| 2868 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2869 | |
| 2870 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2871 | }; |
| 2872 | |
| 2873 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2874 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2875 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2876 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2877 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2878 | SetRawInputAt(0, local); |
| 2879 | } |
| 2880 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2881 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2882 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2883 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2884 | |
| 2885 | private: |
| 2886 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2887 | }; |
| 2888 | |
| 2889 | // Store a value in a given local. This instruction has two inputs: the value |
| 2890 | // and the local. |
| 2891 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2892 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2893 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2894 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2895 | SetRawInputAt(0, local); |
| 2896 | SetRawInputAt(1, value); |
| 2897 | } |
| 2898 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2899 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2900 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2901 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2902 | |
| 2903 | private: |
| 2904 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2905 | }; |
| 2906 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2907 | class HFloatConstant : public HConstant { |
| 2908 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2909 | float GetValue() const { return value_; } |
| 2910 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2911 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2912 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2913 | } |
| 2914 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2915 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2916 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2917 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2918 | } |
| 2919 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2920 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2921 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2922 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2923 | 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] | 2924 | } |
| 2925 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2926 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2927 | } |
| 2928 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2929 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2930 | } |
| 2931 | bool IsNaN() const { |
| 2932 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2933 | } |
| 2934 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2935 | DECLARE_INSTRUCTION(FloatConstant); |
| 2936 | |
| 2937 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2938 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2939 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2940 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2941 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2942 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2943 | const float value_; |
| 2944 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2945 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2946 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2947 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2948 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2949 | }; |
| 2950 | |
| 2951 | class HDoubleConstant : public HConstant { |
| 2952 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2953 | double GetValue() const { return value_; } |
| 2954 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2955 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2956 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2957 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2958 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2959 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2960 | } |
| 2961 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2962 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2963 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2964 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2965 | 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] | 2966 | } |
| 2967 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2968 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2969 | } |
| 2970 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2971 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2972 | } |
| 2973 | bool IsNaN() const { |
| 2974 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2975 | } |
| 2976 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2977 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2978 | |
| 2979 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2980 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2981 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2982 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2983 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2984 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2985 | const double value_; |
| 2986 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2987 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2988 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2989 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2990 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 2991 | }; |
| 2992 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2993 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 2994 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 2995 | #include "intrinsics_list.h" |
| 2996 | kNone, |
| 2997 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 2998 | #undef INTRINSICS_LIST |
| 2999 | #undef OPTIMIZING_INTRINSICS |
| 3000 | }; |
| 3001 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3002 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3003 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3004 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3005 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3006 | }; |
| 3007 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3008 | class HInvoke : public HInstruction { |
| 3009 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3010 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3011 | |
| 3012 | // Runtime needs to walk the stack, so Dex -> Dex calls need to |
| 3013 | // know their environment. |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3014 | bool NeedsEnvironment() const OVERRIDE { |
| 3015 | return needs_environment_or_cache_ == kNeedsEnvironmentOrCache; |
| 3016 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3017 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3018 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3019 | SetRawInputAt(index, argument); |
| 3020 | } |
| 3021 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3022 | // Return the number of arguments. This number can be lower than |
| 3023 | // the number of inputs returned by InputCount(), as some invoke |
| 3024 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3025 | // inputs at the end of their list of inputs. |
| 3026 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3027 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3028 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3029 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3030 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3031 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3032 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3033 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3034 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3035 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3036 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3037 | return intrinsic_; |
| 3038 | } |
| 3039 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3040 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3041 | intrinsic_ = intrinsic; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3042 | needs_environment_or_cache_ = needs_env_or_cache; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3043 | } |
| 3044 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3045 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3046 | return GetEnvironment()->GetParent() != nullptr; |
| 3047 | } |
| 3048 | |
| 3049 | bool CanThrow() const OVERRIDE { return true; } |
| 3050 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3051 | DECLARE_INSTRUCTION(Invoke); |
| 3052 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3053 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3054 | HInvoke(ArenaAllocator* arena, |
| 3055 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3056 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3057 | Primitive::Type return_type, |
| 3058 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3059 | uint32_t dex_method_index, |
| 3060 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3061 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3062 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3063 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3064 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3065 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3066 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3067 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3068 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3069 | intrinsic_(Intrinsics::kNone), |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3070 | needs_environment_or_cache_(kNeedsEnvironmentOrCache) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3071 | } |
| 3072 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3073 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 3074 | DCHECK_LT(index, InputCount()); |
| 3075 | return inputs_[index]; |
| 3076 | } |
| 3077 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3078 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3079 | DCHECK_LT(index, InputCount()); |
| 3080 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3081 | } |
| 3082 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3083 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3084 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3085 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3086 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3087 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3088 | Intrinsics intrinsic_; |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3089 | IntrinsicNeedsEnvironmentOrCache needs_environment_or_cache_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3090 | |
| 3091 | private: |
| 3092 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3093 | }; |
| 3094 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3095 | class HInvokeUnresolved : public HInvoke { |
| 3096 | public: |
| 3097 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3098 | uint32_t number_of_arguments, |
| 3099 | Primitive::Type return_type, |
| 3100 | uint32_t dex_pc, |
| 3101 | uint32_t dex_method_index, |
| 3102 | InvokeType invoke_type) |
| 3103 | : HInvoke(arena, |
| 3104 | number_of_arguments, |
| 3105 | 0u /* number_of_other_inputs */, |
| 3106 | return_type, |
| 3107 | dex_pc, |
| 3108 | dex_method_index, |
| 3109 | invoke_type) { |
| 3110 | } |
| 3111 | |
| 3112 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3113 | |
| 3114 | private: |
| 3115 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3116 | }; |
| 3117 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3118 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3119 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3120 | // Requirements of this method call regarding the class |
| 3121 | // initialization (clinit) check of its declaring class. |
| 3122 | enum class ClinitCheckRequirement { |
| 3123 | kNone, // Class already initialized. |
| 3124 | kExplicit, // Static call having explicit clinit check as last input. |
| 3125 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3126 | }; |
| 3127 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3128 | // Determines how to load the target ArtMethod*. |
| 3129 | enum class MethodLoadKind { |
| 3130 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3131 | kStringInit, |
| 3132 | |
| 3133 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3134 | kRecursive, |
| 3135 | |
| 3136 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3137 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3138 | kDirectAddress, |
| 3139 | |
| 3140 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3141 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3142 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3143 | // the image relocatable or not. |
| 3144 | kDirectAddressWithFixup, |
| 3145 | |
| 3146 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3147 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3148 | // may cause class initialization (the entry may point to a resolution method), |
| 3149 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3150 | kDexCachePcRelative, |
| 3151 | |
| 3152 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3153 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3154 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3155 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3156 | kDexCacheViaMethod, |
| 3157 | }; |
| 3158 | |
| 3159 | // Determines the location of the code pointer. |
| 3160 | enum class CodePtrLocation { |
| 3161 | // Recursive call, use local PC-relative call instruction. |
| 3162 | kCallSelf, |
| 3163 | |
| 3164 | // Use PC-relative call instruction patched at link time. |
| 3165 | // Used for calls within an oat file, boot->boot or app->app. |
| 3166 | kCallPCRelative, |
| 3167 | |
| 3168 | // Call to a known target address, embed the direct address in code. |
| 3169 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3170 | kCallDirect, |
| 3171 | |
| 3172 | // Call to a target address that will be known at link time, embed the direct |
| 3173 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3174 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3175 | // the image relocatable or not. |
| 3176 | kCallDirectWithFixup, |
| 3177 | |
| 3178 | // Use code pointer from the ArtMethod*. |
| 3179 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3180 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3181 | kCallArtMethod, |
| 3182 | }; |
| 3183 | |
| 3184 | struct DispatchInfo { |
| 3185 | const MethodLoadKind method_load_kind; |
| 3186 | const CodePtrLocation code_ptr_location; |
| 3187 | // The method load data holds |
| 3188 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3189 | // Note that there are multiple string init methods, each having its own offset. |
| 3190 | // - the method address for kDirectAddress |
| 3191 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3192 | const uint64_t method_load_data; |
| 3193 | const uint64_t direct_code_ptr; |
| 3194 | }; |
| 3195 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3196 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3197 | uint32_t number_of_arguments, |
| 3198 | Primitive::Type return_type, |
| 3199 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3200 | uint32_t method_index, |
| 3201 | MethodReference target_method, |
| 3202 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3203 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3204 | InvokeType invoke_type, |
| 3205 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3206 | : HInvoke(arena, |
| 3207 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3208 | // There is one extra argument for the HCurrentMethod node, and |
| 3209 | // potentially one other if the clinit check is explicit, and one other |
| 3210 | // if the method is a string factory. |
| 3211 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3212 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3213 | return_type, |
| 3214 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3215 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3216 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3217 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3218 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3219 | target_method_(target_method), |
| 3220 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3221 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3222 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3223 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3224 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3225 | // TODO: for intrinsics we can generate implicit null checks. |
| 3226 | return false; |
| 3227 | } |
| 3228 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3229 | bool CanBeNull() const OVERRIDE { |
| 3230 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3231 | } |
| 3232 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3233 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3234 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3235 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3236 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3237 | bool NeedsDexCache() const OVERRIDE { |
| 3238 | if (intrinsic_ != Intrinsics::kNone) { return needs_environment_or_cache_; } |
| 3239 | return !IsRecursive() && !IsStringInit(); |
| 3240 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3241 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3242 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3243 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3244 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3245 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3246 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3247 | |
| 3248 | int32_t GetStringInitOffset() const { |
| 3249 | DCHECK(IsStringInit()); |
| 3250 | return dispatch_info_.method_load_data; |
| 3251 | } |
| 3252 | |
| 3253 | uint64_t GetMethodAddress() const { |
| 3254 | DCHECK(HasMethodAddress()); |
| 3255 | return dispatch_info_.method_load_data; |
| 3256 | } |
| 3257 | |
| 3258 | uint32_t GetDexCacheArrayOffset() const { |
| 3259 | DCHECK(HasPcRelDexCache()); |
| 3260 | return dispatch_info_.method_load_data; |
| 3261 | } |
| 3262 | |
| 3263 | uint64_t GetDirectCodePtr() const { |
| 3264 | DCHECK(HasDirectCodePtr()); |
| 3265 | return dispatch_info_.direct_code_ptr; |
| 3266 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3267 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3268 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3269 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3270 | // Is this instruction a call to a static method? |
| 3271 | bool IsStatic() const { |
| 3272 | return GetInvokeType() == kStatic; |
| 3273 | } |
| 3274 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3275 | // Remove the art::HLoadClass instruction set as last input by |
| 3276 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3277 | // the initial art::HClinitCheck instruction (only relevant for |
| 3278 | // static calls with explicit clinit check). |
| 3279 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3280 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3281 | size_t last_input_index = InputCount() - 1; |
| 3282 | HInstruction* last_input = InputAt(last_input_index); |
| 3283 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3284 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3285 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3286 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3287 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3288 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3289 | } |
| 3290 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3291 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3292 | if (!IsStringInit()) return false; |
| 3293 | // +1 for the current method. |
| 3294 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3295 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3296 | } |
| 3297 | |
| 3298 | void RemoveFakeStringArgumentAsLastInput() { |
| 3299 | DCHECK(IsStringInit()); |
| 3300 | size_t last_input_index = InputCount() - 1; |
| 3301 | HInstruction* last_input = InputAt(last_input_index); |
| 3302 | DCHECK(last_input != nullptr); |
| 3303 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3304 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3305 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3306 | } |
| 3307 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3308 | // Is this a call to a static method whose declaring class has an |
| 3309 | // explicit intialization check in the graph? |
| 3310 | bool IsStaticWithExplicitClinitCheck() const { |
| 3311 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3312 | } |
| 3313 | |
| 3314 | // Is this a call to a static method whose declaring class has an |
| 3315 | // implicit intialization check requirement? |
| 3316 | bool IsStaticWithImplicitClinitCheck() const { |
| 3317 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3318 | } |
| 3319 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3320 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3321 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3322 | protected: |
| 3323 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3324 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3325 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3326 | HInstruction* input = input_record.GetInstruction(); |
| 3327 | // `input` is the last input of a static invoke marked as having |
| 3328 | // an explicit clinit check. It must either be: |
| 3329 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3330 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3331 | DCHECK(input != nullptr); |
| 3332 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3333 | } |
| 3334 | return input_record; |
| 3335 | } |
| 3336 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3337 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3338 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3339 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3340 | // The target method may refer to different dex file or method index than the original |
| 3341 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3342 | // in derived class to increase visibility. |
| 3343 | MethodReference target_method_; |
| 3344 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3345 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3346 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3347 | }; |
| 3348 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3349 | class HInvokeVirtual : public HInvoke { |
| 3350 | public: |
| 3351 | HInvokeVirtual(ArenaAllocator* arena, |
| 3352 | uint32_t number_of_arguments, |
| 3353 | Primitive::Type return_type, |
| 3354 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3355 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3356 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3357 | : 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] | 3358 | vtable_index_(vtable_index) {} |
| 3359 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3360 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3361 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3362 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3363 | } |
| 3364 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3365 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3366 | |
| 3367 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3368 | |
| 3369 | private: |
| 3370 | const uint32_t vtable_index_; |
| 3371 | |
| 3372 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3373 | }; |
| 3374 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3375 | class HInvokeInterface : public HInvoke { |
| 3376 | public: |
| 3377 | HInvokeInterface(ArenaAllocator* arena, |
| 3378 | uint32_t number_of_arguments, |
| 3379 | Primitive::Type return_type, |
| 3380 | uint32_t dex_pc, |
| 3381 | uint32_t dex_method_index, |
| 3382 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3383 | : 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] | 3384 | imt_index_(imt_index) {} |
| 3385 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3386 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3387 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3388 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3389 | } |
| 3390 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3391 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3392 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3393 | |
| 3394 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3395 | |
| 3396 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3397 | const uint32_t imt_index_; |
| 3398 | |
| 3399 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3400 | }; |
| 3401 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3402 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3403 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3404 | HNewInstance(HCurrentMethod* current_method, |
| 3405 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3406 | uint16_t type_index, |
| 3407 | const DexFile& dex_file, |
| 3408 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3409 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3410 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3411 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3412 | entrypoint_(entrypoint) { |
| 3413 | SetRawInputAt(0, current_method); |
| 3414 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3415 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3416 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3417 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3418 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3419 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3420 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3421 | // It may throw when called on: |
| 3422 | // - interfaces |
| 3423 | // - abstract/innaccessible/unknown classes |
| 3424 | // TODO: optimize when possible. |
| 3425 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3426 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3427 | bool CanBeNull() const OVERRIDE { return false; } |
| 3428 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3429 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3430 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3431 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3432 | |
| 3433 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3434 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3435 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3436 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3437 | |
| 3438 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3439 | }; |
| 3440 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3441 | class HNeg : public HUnaryOperation { |
| 3442 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3443 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3444 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3445 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3446 | template <typename T> T Compute(T x) const { return -x; } |
| 3447 | |
| 3448 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3449 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3450 | } |
| 3451 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3452 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3453 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3454 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3455 | DECLARE_INSTRUCTION(Neg); |
| 3456 | |
| 3457 | private: |
| 3458 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3459 | }; |
| 3460 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3461 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3462 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3463 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3464 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3465 | uint32_t dex_pc, |
| 3466 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3467 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3468 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3469 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3470 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3471 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3472 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3473 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3474 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3475 | } |
| 3476 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3477 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3478 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3479 | |
| 3480 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3481 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3482 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3483 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3484 | bool CanThrow() const OVERRIDE { return true; } |
| 3485 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3486 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3487 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3488 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3489 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3490 | DECLARE_INSTRUCTION(NewArray); |
| 3491 | |
| 3492 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3493 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3494 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3495 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3496 | |
| 3497 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3498 | }; |
| 3499 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3500 | class HAdd : public HBinaryOperation { |
| 3501 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3502 | HAdd(Primitive::Type result_type, |
| 3503 | HInstruction* left, |
| 3504 | HInstruction* right, |
| 3505 | uint32_t dex_pc = kNoDexPc) |
| 3506 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3507 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3508 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3509 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3510 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3511 | |
| 3512 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3513 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3514 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3515 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3516 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3517 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3518 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3519 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3520 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3521 | DECLARE_INSTRUCTION(Add); |
| 3522 | |
| 3523 | private: |
| 3524 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3525 | }; |
| 3526 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3527 | class HSub : public HBinaryOperation { |
| 3528 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3529 | HSub(Primitive::Type result_type, |
| 3530 | HInstruction* left, |
| 3531 | HInstruction* right, |
| 3532 | uint32_t dex_pc = kNoDexPc) |
| 3533 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3534 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3535 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3536 | |
| 3537 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3538 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3539 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3540 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3541 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3542 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3543 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3544 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3545 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3546 | DECLARE_INSTRUCTION(Sub); |
| 3547 | |
| 3548 | private: |
| 3549 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3550 | }; |
| 3551 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3552 | class HMul : public HBinaryOperation { |
| 3553 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3554 | HMul(Primitive::Type result_type, |
| 3555 | HInstruction* left, |
| 3556 | HInstruction* right, |
| 3557 | uint32_t dex_pc = kNoDexPc) |
| 3558 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3559 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3560 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3561 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3562 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3563 | |
| 3564 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3565 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3566 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3567 | } |
| 3568 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3569 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3570 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3571 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3572 | |
| 3573 | DECLARE_INSTRUCTION(Mul); |
| 3574 | |
| 3575 | private: |
| 3576 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3577 | }; |
| 3578 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3579 | class HDiv : public HBinaryOperation { |
| 3580 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3581 | HDiv(Primitive::Type result_type, |
| 3582 | HInstruction* left, |
| 3583 | HInstruction* right, |
| 3584 | uint32_t dex_pc) |
| 3585 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3586 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3587 | template <typename T> |
| 3588 | T Compute(T x, T y) const { |
| 3589 | // Our graph structure ensures we never have 0 for `y` during |
| 3590 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3591 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3592 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3593 | return (y == -1) ? -x : x / y; |
| 3594 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3595 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3596 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3597 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3598 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3599 | } |
| 3600 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3601 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3602 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3603 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3604 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3605 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3606 | // The generated code can use a runtime call. |
| 3607 | return SideEffects::CanTriggerGC(); |
| 3608 | } |
| 3609 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3610 | DECLARE_INSTRUCTION(Div); |
| 3611 | |
| 3612 | private: |
| 3613 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3614 | }; |
| 3615 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3616 | class HRem : public HBinaryOperation { |
| 3617 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3618 | HRem(Primitive::Type result_type, |
| 3619 | HInstruction* left, |
| 3620 | HInstruction* right, |
| 3621 | uint32_t dex_pc) |
| 3622 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3623 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3624 | template <typename T> |
| 3625 | T Compute(T x, T y) const { |
| 3626 | // Our graph structure ensures we never have 0 for `y` during |
| 3627 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3628 | DCHECK_NE(y, 0); |
| 3629 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3630 | return (y == -1) ? 0 : x % y; |
| 3631 | } |
| 3632 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3633 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3634 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3635 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3636 | } |
| 3637 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3638 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3639 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3640 | } |
| 3641 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3642 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3643 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3644 | return SideEffects::CanTriggerGC(); |
| 3645 | } |
| 3646 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3647 | DECLARE_INSTRUCTION(Rem); |
| 3648 | |
| 3649 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3650 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3651 | }; |
| 3652 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3653 | class HDivZeroCheck : public HExpression<1> { |
| 3654 | public: |
| 3655 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3656 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3657 | SetRawInputAt(0, value); |
| 3658 | } |
| 3659 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3660 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3661 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3662 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3663 | |
| 3664 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3665 | UNUSED(other); |
| 3666 | return true; |
| 3667 | } |
| 3668 | |
| 3669 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3670 | bool CanThrow() const OVERRIDE { return true; } |
| 3671 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3672 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3673 | |
| 3674 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3675 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3676 | }; |
| 3677 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3678 | class HShl : public HBinaryOperation { |
| 3679 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3680 | HShl(Primitive::Type result_type, |
| 3681 | HInstruction* left, |
| 3682 | HInstruction* right, |
| 3683 | uint32_t dex_pc = kNoDexPc) |
| 3684 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3685 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3686 | template <typename T, typename U, typename V> |
| 3687 | T Compute(T x, U y, V max_shift_value) const { |
| 3688 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3689 | "V is not the unsigned integer type corresponding to T"); |
| 3690 | return x << (y & max_shift_value); |
| 3691 | } |
| 3692 | |
| 3693 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3694 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3695 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3696 | } |
| 3697 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3698 | // case is handled as `x << static_cast<int>(y)`. |
| 3699 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3700 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3701 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3702 | } |
| 3703 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3704 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3705 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3706 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3707 | |
| 3708 | DECLARE_INSTRUCTION(Shl); |
| 3709 | |
| 3710 | private: |
| 3711 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3712 | }; |
| 3713 | |
| 3714 | class HShr : public HBinaryOperation { |
| 3715 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3716 | HShr(Primitive::Type result_type, |
| 3717 | HInstruction* left, |
| 3718 | HInstruction* right, |
| 3719 | uint32_t dex_pc = kNoDexPc) |
| 3720 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3721 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3722 | template <typename T, typename U, typename V> |
| 3723 | T Compute(T x, U y, V max_shift_value) const { |
| 3724 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3725 | "V is not the unsigned integer type corresponding to T"); |
| 3726 | return x >> (y & max_shift_value); |
| 3727 | } |
| 3728 | |
| 3729 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3730 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3731 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3732 | } |
| 3733 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3734 | // case is handled as `x >> static_cast<int>(y)`. |
| 3735 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3736 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3737 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3738 | } |
| 3739 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3740 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3741 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3742 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3743 | |
| 3744 | DECLARE_INSTRUCTION(Shr); |
| 3745 | |
| 3746 | private: |
| 3747 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3748 | }; |
| 3749 | |
| 3750 | class HUShr : public HBinaryOperation { |
| 3751 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3752 | HUShr(Primitive::Type result_type, |
| 3753 | HInstruction* left, |
| 3754 | HInstruction* right, |
| 3755 | uint32_t dex_pc = kNoDexPc) |
| 3756 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3757 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3758 | template <typename T, typename U, typename V> |
| 3759 | T Compute(T x, U y, V max_shift_value) const { |
| 3760 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3761 | "V is not the unsigned integer type corresponding to T"); |
| 3762 | V ux = static_cast<V>(x); |
| 3763 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3764 | } |
| 3765 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3766 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3767 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3768 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3769 | } |
| 3770 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3771 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3772 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3773 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3774 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3775 | } |
| 3776 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3777 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3778 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3779 | } |
| 3780 | |
| 3781 | DECLARE_INSTRUCTION(UShr); |
| 3782 | |
| 3783 | private: |
| 3784 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3785 | }; |
| 3786 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3787 | class HAnd : public HBinaryOperation { |
| 3788 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3789 | HAnd(Primitive::Type result_type, |
| 3790 | HInstruction* left, |
| 3791 | HInstruction* right, |
| 3792 | uint32_t dex_pc = kNoDexPc) |
| 3793 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3794 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3795 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3796 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3797 | template <typename T, typename U> |
| 3798 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3799 | |
| 3800 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3801 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3802 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3803 | } |
| 3804 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3805 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3806 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3807 | } |
| 3808 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3809 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3810 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3811 | } |
| 3812 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3813 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3814 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3815 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3816 | |
| 3817 | DECLARE_INSTRUCTION(And); |
| 3818 | |
| 3819 | private: |
| 3820 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3821 | }; |
| 3822 | |
| 3823 | class HOr : public HBinaryOperation { |
| 3824 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3825 | HOr(Primitive::Type result_type, |
| 3826 | HInstruction* left, |
| 3827 | HInstruction* right, |
| 3828 | uint32_t dex_pc = kNoDexPc) |
| 3829 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3830 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3831 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3832 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3833 | template <typename T, typename U> |
| 3834 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3835 | |
| 3836 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3837 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3838 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3839 | } |
| 3840 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3841 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3842 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3843 | } |
| 3844 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3845 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3846 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3847 | } |
| 3848 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3849 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3850 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3851 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3852 | |
| 3853 | DECLARE_INSTRUCTION(Or); |
| 3854 | |
| 3855 | private: |
| 3856 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3857 | }; |
| 3858 | |
| 3859 | class HXor : public HBinaryOperation { |
| 3860 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3861 | HXor(Primitive::Type result_type, |
| 3862 | HInstruction* left, |
| 3863 | HInstruction* right, |
| 3864 | uint32_t dex_pc = kNoDexPc) |
| 3865 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3866 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3867 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3868 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3869 | template <typename T, typename U> |
| 3870 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3871 | |
| 3872 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3873 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3874 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3875 | } |
| 3876 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3877 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3878 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3879 | } |
| 3880 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3881 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3882 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3883 | } |
| 3884 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3885 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3886 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3887 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3888 | |
| 3889 | DECLARE_INSTRUCTION(Xor); |
| 3890 | |
| 3891 | private: |
| 3892 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3893 | }; |
| 3894 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3895 | // The value of a parameter in this method. Its location depends on |
| 3896 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3897 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3898 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3899 | HParameterValue(uint8_t index, |
| 3900 | Primitive::Type parameter_type, |
| 3901 | bool is_this = false) |
| 3902 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3903 | index_(index), |
| 3904 | is_this_(is_this), |
| 3905 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3906 | |
| 3907 | uint8_t GetIndex() const { return index_; } |
| 3908 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3909 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3910 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3911 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3912 | bool IsThis() const { return is_this_; } |
| 3913 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3914 | DECLARE_INSTRUCTION(ParameterValue); |
| 3915 | |
| 3916 | private: |
| 3917 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3918 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3919 | const uint8_t index_; |
| 3920 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3921 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3922 | const bool is_this_; |
| 3923 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3924 | bool can_be_null_; |
| 3925 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3926 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3927 | }; |
| 3928 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3929 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3930 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3931 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3932 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3933 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3934 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3935 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3936 | UNUSED(other); |
| 3937 | return true; |
| 3938 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3939 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3940 | template <typename T> T Compute(T x) const { return ~x; } |
| 3941 | |
| 3942 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3943 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3944 | } |
| 3945 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3946 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3947 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3948 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3949 | DECLARE_INSTRUCTION(Not); |
| 3950 | |
| 3951 | private: |
| 3952 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 3953 | }; |
| 3954 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3955 | class HBooleanNot : public HUnaryOperation { |
| 3956 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3957 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3958 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3959 | |
| 3960 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3961 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3962 | UNUSED(other); |
| 3963 | return true; |
| 3964 | } |
| 3965 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3966 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3967 | DCHECK(IsUint<1>(x)); |
| 3968 | return !x; |
| 3969 | } |
| 3970 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3971 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3972 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3973 | } |
| 3974 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3975 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3976 | UNREACHABLE(); |
| 3977 | } |
| 3978 | |
| 3979 | DECLARE_INSTRUCTION(BooleanNot); |
| 3980 | |
| 3981 | private: |
| 3982 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 3983 | }; |
| 3984 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3985 | class HTypeConversion : public HExpression<1> { |
| 3986 | public: |
| 3987 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3988 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3989 | : HExpression(result_type, |
| 3990 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 3991 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3992 | SetRawInputAt(0, input); |
| 3993 | DCHECK_NE(input->GetType(), result_type); |
| 3994 | } |
| 3995 | |
| 3996 | HInstruction* GetInput() const { return InputAt(0); } |
| 3997 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 3998 | Primitive::Type GetResultType() const { return GetType(); } |
| 3999 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4000 | // Required by the x86 and ARM code generators when producing calls |
| 4001 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4002 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4003 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4004 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4005 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4006 | // Try to statically evaluate the conversion and return a HConstant |
| 4007 | // containing the result. If the input cannot be converted, return nullptr. |
| 4008 | HConstant* TryStaticEvaluation() const; |
| 4009 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4010 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4011 | Primitive::Type result_type) { |
| 4012 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4013 | // in the compilation process we do not know what architecture we will |
| 4014 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4015 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4016 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4017 | return SideEffects::CanTriggerGC(); |
| 4018 | } |
| 4019 | return SideEffects::None(); |
| 4020 | } |
| 4021 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4022 | DECLARE_INSTRUCTION(TypeConversion); |
| 4023 | |
| 4024 | private: |
| 4025 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4026 | }; |
| 4027 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4028 | static constexpr uint32_t kNoRegNumber = -1; |
| 4029 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4030 | class HPhi : public HInstruction { |
| 4031 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4032 | HPhi(ArenaAllocator* arena, |
| 4033 | uint32_t reg_number, |
| 4034 | size_t number_of_inputs, |
| 4035 | Primitive::Type type, |
| 4036 | uint32_t dex_pc = kNoDexPc) |
| 4037 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4038 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4039 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4040 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4041 | is_live_(false), |
| 4042 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4043 | } |
| 4044 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4045 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4046 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4047 | switch (type) { |
| 4048 | case Primitive::kPrimBoolean: |
| 4049 | case Primitive::kPrimByte: |
| 4050 | case Primitive::kPrimShort: |
| 4051 | case Primitive::kPrimChar: |
| 4052 | return Primitive::kPrimInt; |
| 4053 | default: |
| 4054 | return type; |
| 4055 | } |
| 4056 | } |
| 4057 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4058 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4059 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4060 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4061 | |
| 4062 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4063 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4064 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4065 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4066 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4067 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4068 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4069 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4070 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4071 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4072 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4073 | void SetDead() { is_live_ = false; } |
| 4074 | void SetLive() { is_live_ = true; } |
| 4075 | bool IsDead() const { return !is_live_; } |
| 4076 | bool IsLive() const { return is_live_; } |
| 4077 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4078 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4079 | return other != nullptr |
| 4080 | && other->IsPhi() |
| 4081 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4082 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4083 | } |
| 4084 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4085 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4086 | // An equivalent phi is a phi having the same dex register and type. |
| 4087 | // It assumes that phis with the same dex register are adjacent. |
| 4088 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4089 | HInstruction* next = GetNext(); |
| 4090 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4091 | if (next->GetType() == GetType()) { |
| 4092 | return next->AsPhi(); |
| 4093 | } |
| 4094 | next = next->GetNext(); |
| 4095 | } |
| 4096 | return nullptr; |
| 4097 | } |
| 4098 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4099 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4100 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4101 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4102 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
| 4103 | DCHECK_LE(index, InputCount()); |
| 4104 | return inputs_[index]; |
| 4105 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4106 | |
| 4107 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4108 | DCHECK_LE(index, InputCount()); |
| 4109 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4110 | } |
| 4111 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4112 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4113 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4114 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4115 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4116 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4117 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4118 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4119 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4120 | }; |
| 4121 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4122 | class HNullCheck : public HExpression<1> { |
| 4123 | public: |
| 4124 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4125 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4126 | SetRawInputAt(0, value); |
| 4127 | } |
| 4128 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4129 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4130 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4131 | UNUSED(other); |
| 4132 | return true; |
| 4133 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4134 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4135 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4136 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4137 | bool CanThrow() const OVERRIDE { return true; } |
| 4138 | |
| 4139 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4140 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4141 | |
| 4142 | DECLARE_INSTRUCTION(NullCheck); |
| 4143 | |
| 4144 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4145 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4146 | }; |
| 4147 | |
| 4148 | class FieldInfo : public ValueObject { |
| 4149 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4150 | FieldInfo(MemberOffset field_offset, |
| 4151 | Primitive::Type field_type, |
| 4152 | bool is_volatile, |
| 4153 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4154 | const DexFile& dex_file, |
| 4155 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4156 | : field_offset_(field_offset), |
| 4157 | field_type_(field_type), |
| 4158 | is_volatile_(is_volatile), |
| 4159 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4160 | dex_file_(dex_file), |
| 4161 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4162 | |
| 4163 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4164 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4165 | uint32_t GetFieldIndex() const { return index_; } |
| 4166 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4167 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4168 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4169 | |
| 4170 | private: |
| 4171 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4172 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4173 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4174 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4175 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4176 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4177 | }; |
| 4178 | |
| 4179 | class HInstanceFieldGet : public HExpression<1> { |
| 4180 | public: |
| 4181 | HInstanceFieldGet(HInstruction* value, |
| 4182 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4183 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4184 | bool is_volatile, |
| 4185 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4186 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4187 | Handle<mirror::DexCache> dex_cache, |
| 4188 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4189 | : HExpression( |
| 4190 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4191 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4192 | 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] | 4193 | SetRawInputAt(0, value); |
| 4194 | } |
| 4195 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4196 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4197 | |
| 4198 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4199 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4200 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4201 | } |
| 4202 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4203 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4204 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4205 | } |
| 4206 | |
| 4207 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4208 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4209 | } |
| 4210 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4211 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4212 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4213 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4214 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4215 | |
| 4216 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4217 | |
| 4218 | private: |
| 4219 | const FieldInfo field_info_; |
| 4220 | |
| 4221 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4222 | }; |
| 4223 | |
| 4224 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4225 | public: |
| 4226 | HInstanceFieldSet(HInstruction* object, |
| 4227 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4228 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4229 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4230 | bool is_volatile, |
| 4231 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4232 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4233 | Handle<mirror::DexCache> dex_cache, |
| 4234 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4235 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4236 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4237 | 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] | 4238 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4239 | SetRawInputAt(0, object); |
| 4240 | SetRawInputAt(1, value); |
| 4241 | } |
| 4242 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4243 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4244 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4245 | } |
| 4246 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4247 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4248 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4249 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4250 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4251 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4252 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4253 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4254 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4255 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4256 | |
| 4257 | private: |
| 4258 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4259 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4260 | |
| 4261 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4262 | }; |
| 4263 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4264 | class HArrayGet : public HExpression<2> { |
| 4265 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4266 | HArrayGet(HInstruction* array, |
| 4267 | HInstruction* index, |
| 4268 | Primitive::Type type, |
| 4269 | uint32_t dex_pc = kNoDexPc) |
| 4270 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4271 | SetRawInputAt(0, array); |
| 4272 | SetRawInputAt(1, index); |
| 4273 | } |
| 4274 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4275 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4276 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4277 | UNUSED(other); |
| 4278 | return true; |
| 4279 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4280 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4281 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4282 | // TODO: We can be smarter here. |
| 4283 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4284 | // which generates the implicit null check. There are cases when these can be removed |
| 4285 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4286 | // implicit check here (as long as the address falls in the first page). |
| 4287 | return false; |
| 4288 | } |
| 4289 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4290 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4291 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4292 | HInstruction* GetArray() const { return InputAt(0); } |
| 4293 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4294 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4295 | DECLARE_INSTRUCTION(ArrayGet); |
| 4296 | |
| 4297 | private: |
| 4298 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4299 | }; |
| 4300 | |
| 4301 | class HArraySet : public HTemplateInstruction<3> { |
| 4302 | public: |
| 4303 | HArraySet(HInstruction* array, |
| 4304 | HInstruction* index, |
| 4305 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4306 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4307 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4308 | : HTemplateInstruction( |
| 4309 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4310 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4311 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4312 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
| 4313 | value_can_be_null_(true) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4314 | SetRawInputAt(0, array); |
| 4315 | SetRawInputAt(1, index); |
| 4316 | SetRawInputAt(2, value); |
| 4317 | } |
| 4318 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4319 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4320 | // We currently always call a runtime method to catch array store |
| 4321 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4322 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4323 | } |
| 4324 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4325 | // Can throw ArrayStoreException. |
| 4326 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4327 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4328 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4329 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4330 | // TODO: Same as for ArrayGet. |
| 4331 | return false; |
| 4332 | } |
| 4333 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4334 | void ClearNeedsTypeCheck() { |
| 4335 | needs_type_check_ = false; |
| 4336 | } |
| 4337 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4338 | void ClearValueCanBeNull() { |
| 4339 | value_can_be_null_ = false; |
| 4340 | } |
| 4341 | |
| 4342 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4343 | bool NeedsTypeCheck() const { return needs_type_check_; } |
| 4344 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4345 | HInstruction* GetArray() const { return InputAt(0); } |
| 4346 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4347 | HInstruction* GetValue() const { return InputAt(2); } |
| 4348 | |
| 4349 | Primitive::Type GetComponentType() const { |
| 4350 | // The Dex format does not type floating point index operations. Since the |
| 4351 | // `expected_component_type_` is set during building and can therefore not |
| 4352 | // be correct, we also check what is the value type. If it is a floating |
| 4353 | // point type, we must use that type. |
| 4354 | Primitive::Type value_type = GetValue()->GetType(); |
| 4355 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4356 | ? value_type |
| 4357 | : expected_component_type_; |
| 4358 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4359 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4360 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4361 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4362 | } |
| 4363 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4364 | DECLARE_INSTRUCTION(ArraySet); |
| 4365 | |
| 4366 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4367 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4368 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4369 | bool value_can_be_null_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4370 | |
| 4371 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4372 | }; |
| 4373 | |
| 4374 | class HArrayLength : public HExpression<1> { |
| 4375 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4376 | explicit HArrayLength(HInstruction* array, uint32_t dex_pc = kNoDexPc) |
| 4377 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4378 | // Note that arrays do not change length, so the instruction does not |
| 4379 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4380 | SetRawInputAt(0, array); |
| 4381 | } |
| 4382 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4383 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4384 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4385 | UNUSED(other); |
| 4386 | return true; |
| 4387 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4388 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4389 | return obj == InputAt(0); |
| 4390 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4391 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4392 | DECLARE_INSTRUCTION(ArrayLength); |
| 4393 | |
| 4394 | private: |
| 4395 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4396 | }; |
| 4397 | |
| 4398 | class HBoundsCheck : public HExpression<2> { |
| 4399 | public: |
| 4400 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4401 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4402 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4403 | SetRawInputAt(0, index); |
| 4404 | SetRawInputAt(1, length); |
| 4405 | } |
| 4406 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4407 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4408 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4409 | UNUSED(other); |
| 4410 | return true; |
| 4411 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4412 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4413 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4414 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4415 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4416 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4417 | |
| 4418 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4419 | |
| 4420 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4421 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4422 | }; |
| 4423 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4424 | /** |
| 4425 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4426 | * to stay live until the last HInstruction. This class |
| 4427 | * 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] | 4428 | * HInstruction stays live. `index` represents the stack location index of the |
| 4429 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4430 | */ |
| 4431 | class HTemporary : public HTemplateInstruction<0> { |
| 4432 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4433 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4434 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4435 | |
| 4436 | size_t GetIndex() const { return index_; } |
| 4437 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4438 | Primitive::Type GetType() const OVERRIDE { |
| 4439 | // The previous instruction is the one that will be stored in the temporary location. |
| 4440 | DCHECK(GetPrevious() != nullptr); |
| 4441 | return GetPrevious()->GetType(); |
| 4442 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4443 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4444 | DECLARE_INSTRUCTION(Temporary); |
| 4445 | |
| 4446 | private: |
| 4447 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4449 | }; |
| 4450 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4451 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4452 | public: |
| 4453 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4454 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4455 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4456 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4457 | return true; |
| 4458 | } |
| 4459 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4460 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4461 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4462 | |
| 4463 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4464 | |
| 4465 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4466 | // Only used for code generation, in order to share the same slow path between back edges |
| 4467 | // of a same loop. |
| 4468 | SlowPathCode* slow_path_; |
| 4469 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4470 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4471 | }; |
| 4472 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4473 | /** |
| 4474 | * Instruction to load a Class object. |
| 4475 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4476 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4477 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4478 | HLoadClass(HCurrentMethod* current_method, |
| 4479 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4480 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4481 | bool is_referrers_class, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4482 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4483 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4484 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4485 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4486 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4487 | generate_clinit_check_(false), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4488 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4489 | SetRawInputAt(0, current_method); |
| 4490 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4491 | |
| 4492 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4493 | |
| 4494 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4495 | return other->AsLoadClass()->type_index_ == type_index_; |
| 4496 | } |
| 4497 | |
| 4498 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4499 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4500 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4501 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4502 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4503 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4504 | bool NeedsEnvironment() const OVERRIDE { |
| 4505 | // Will call runtime and load the class if the class is not loaded yet. |
| 4506 | // TODO: finer grain decision. |
| 4507 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4508 | } |
| 4509 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4510 | bool MustGenerateClinitCheck() const { |
| 4511 | return generate_clinit_check_; |
| 4512 | } |
| 4513 | |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4514 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4515 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4516 | } |
| 4517 | |
| 4518 | bool CanCallRuntime() const { |
| 4519 | return MustGenerateClinitCheck() || !is_referrers_class_; |
| 4520 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4521 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4522 | bool CanThrow() const OVERRIDE { |
| 4523 | // May call runtime and and therefore can throw. |
| 4524 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4525 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4526 | } |
| 4527 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4528 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4529 | return loaded_class_rti_; |
| 4530 | } |
| 4531 | |
| 4532 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4533 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4534 | DCHECK(rti.IsExact()); |
| 4535 | loaded_class_rti_ = rti; |
| 4536 | } |
| 4537 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4538 | const DexFile& GetDexFile() { return dex_file_; } |
| 4539 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4540 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4541 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4542 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4543 | return SideEffects::CanTriggerGC(); |
| 4544 | } |
| 4545 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4546 | DECLARE_INSTRUCTION(LoadClass); |
| 4547 | |
| 4548 | private: |
| 4549 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4550 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4551 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4552 | // Whether this instruction must generate the initialization check. |
| 4553 | // Used for code generation. |
| 4554 | bool generate_clinit_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4555 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4556 | ReferenceTypeInfo loaded_class_rti_; |
| 4557 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4558 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4559 | }; |
| 4560 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4561 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4562 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4563 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4564 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4565 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4566 | SetRawInputAt(0, current_method); |
| 4567 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4568 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4569 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4570 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4571 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4572 | return other->AsLoadString()->string_index_ == string_index_; |
| 4573 | } |
| 4574 | |
| 4575 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4576 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4577 | uint32_t GetStringIndex() const { return string_index_; } |
| 4578 | |
| 4579 | // TODO: Can we deopt or debug when we resolve a string? |
| 4580 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4581 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4582 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4583 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4584 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4585 | return SideEffects::CanTriggerGC(); |
| 4586 | } |
| 4587 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4588 | DECLARE_INSTRUCTION(LoadString); |
| 4589 | |
| 4590 | private: |
| 4591 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4592 | |
| 4593 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4594 | }; |
| 4595 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4596 | /** |
| 4597 | * Performs an initialization check on its Class object input. |
| 4598 | */ |
| 4599 | class HClinitCheck : public HExpression<1> { |
| 4600 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4601 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4602 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4603 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4604 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4605 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4606 | SetRawInputAt(0, constant); |
| 4607 | } |
| 4608 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4609 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4610 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4611 | UNUSED(other); |
| 4612 | return true; |
| 4613 | } |
| 4614 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4615 | bool NeedsEnvironment() const OVERRIDE { |
| 4616 | // May call runtime to initialize the class. |
| 4617 | return true; |
| 4618 | } |
| 4619 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4620 | |
| 4621 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4622 | |
| 4623 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4624 | |
| 4625 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4626 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4627 | }; |
| 4628 | |
| 4629 | class HStaticFieldGet : public HExpression<1> { |
| 4630 | public: |
| 4631 | HStaticFieldGet(HInstruction* cls, |
| 4632 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4633 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4634 | bool is_volatile, |
| 4635 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4636 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4637 | Handle<mirror::DexCache> dex_cache, |
| 4638 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4639 | : HExpression( |
| 4640 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4641 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4642 | 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] | 4643 | SetRawInputAt(0, cls); |
| 4644 | } |
| 4645 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4646 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4647 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4648 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4649 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4650 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4651 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4652 | } |
| 4653 | |
| 4654 | size_t ComputeHashCode() const OVERRIDE { |
| 4655 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4656 | } |
| 4657 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4658 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4659 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4660 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4661 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4662 | |
| 4663 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4664 | |
| 4665 | private: |
| 4666 | const FieldInfo field_info_; |
| 4667 | |
| 4668 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4669 | }; |
| 4670 | |
| 4671 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4672 | public: |
| 4673 | HStaticFieldSet(HInstruction* cls, |
| 4674 | HInstruction* value, |
| 4675 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4676 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4677 | bool is_volatile, |
| 4678 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4679 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4680 | Handle<mirror::DexCache> dex_cache, |
| 4681 | uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4682 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4683 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4684 | 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] | 4685 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4686 | SetRawInputAt(0, cls); |
| 4687 | SetRawInputAt(1, value); |
| 4688 | } |
| 4689 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4690 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4691 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4692 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4693 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4694 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4695 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4696 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4697 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4698 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4699 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4700 | |
| 4701 | private: |
| 4702 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4703 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4704 | |
| 4705 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4706 | }; |
| 4707 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4708 | // Implement the move-exception DEX instruction. |
| 4709 | class HLoadException : public HExpression<0> { |
| 4710 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4711 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4712 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4713 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4714 | bool CanBeNull() const OVERRIDE { return false; } |
| 4715 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4716 | DECLARE_INSTRUCTION(LoadException); |
| 4717 | |
| 4718 | private: |
| 4719 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4720 | }; |
| 4721 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4722 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4723 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4724 | class HClearException : public HTemplateInstruction<0> { |
| 4725 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4726 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4727 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4728 | |
| 4729 | DECLARE_INSTRUCTION(ClearException); |
| 4730 | |
| 4731 | private: |
| 4732 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4733 | }; |
| 4734 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4735 | class HThrow : public HTemplateInstruction<1> { |
| 4736 | public: |
| 4737 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4738 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4739 | SetRawInputAt(0, exception); |
| 4740 | } |
| 4741 | |
| 4742 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4743 | |
| 4744 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4745 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4746 | bool CanThrow() const OVERRIDE { return true; } |
| 4747 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4748 | |
| 4749 | DECLARE_INSTRUCTION(Throw); |
| 4750 | |
| 4751 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4752 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4753 | }; |
| 4754 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4755 | /** |
| 4756 | * Implementation strategies for the code generator of a HInstanceOf |
| 4757 | * or `HCheckCast`. |
| 4758 | */ |
| 4759 | enum class TypeCheckKind { |
| 4760 | kExactCheck, // Can do a single class compare. |
| 4761 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4762 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4763 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4764 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4765 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4766 | }; |
| 4767 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4768 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4769 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4770 | HInstanceOf(HInstruction* object, |
| 4771 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4772 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4773 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4774 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4775 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4776 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4777 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4778 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4779 | SetRawInputAt(0, object); |
| 4780 | SetRawInputAt(1, constant); |
| 4781 | } |
| 4782 | |
| 4783 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4784 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4785 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4786 | return true; |
| 4787 | } |
| 4788 | |
| 4789 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4790 | return false; |
| 4791 | } |
| 4792 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4793 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4794 | |
| 4795 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4796 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4797 | // Used only in code generation. |
| 4798 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4799 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4800 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4801 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4802 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4803 | ? SideEffects::None() |
| 4804 | // Mips currently does runtime calls for any other checks. |
| 4805 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4806 | } |
| 4807 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4808 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4809 | |
| 4810 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4811 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4812 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4813 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4814 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4815 | }; |
| 4816 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4817 | class HBoundType : public HExpression<1> { |
| 4818 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4819 | // Constructs an HBoundType with the given upper_bound. |
| 4820 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4821 | HBoundType(HInstruction* input, |
| 4822 | ReferenceTypeInfo upper_bound, |
| 4823 | bool upper_can_be_null, |
| 4824 | uint32_t dex_pc = kNoDexPc) |
| 4825 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4826 | upper_bound_(upper_bound), |
| 4827 | upper_can_be_null_(upper_can_be_null), |
| 4828 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 4829 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4830 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4831 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4832 | } |
| 4833 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4834 | // GetUpper* should only be used in reference type propagation. |
| 4835 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 4836 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4837 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4838 | void SetCanBeNull(bool can_be_null) { |
| 4839 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 4840 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4841 | } |
| 4842 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4843 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4844 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4845 | DECLARE_INSTRUCTION(BoundType); |
| 4846 | |
| 4847 | private: |
| 4848 | // 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] | 4849 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 4850 | // It is used to bound the type in cases like: |
| 4851 | // if (x instanceof ClassX) { |
| 4852 | // // uper_bound_ will be ClassX |
| 4853 | // } |
| 4854 | const ReferenceTypeInfo upper_bound_; |
| 4855 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 4856 | // is false then can_be_null_ cannot be true). |
| 4857 | const bool upper_can_be_null_; |
| 4858 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4859 | |
| 4860 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 4861 | }; |
| 4862 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4863 | class HCheckCast : public HTemplateInstruction<2> { |
| 4864 | public: |
| 4865 | HCheckCast(HInstruction* object, |
| 4866 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4867 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4868 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4869 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4870 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4871 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4872 | SetRawInputAt(0, object); |
| 4873 | SetRawInputAt(1, constant); |
| 4874 | } |
| 4875 | |
| 4876 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4877 | |
| 4878 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4879 | return true; |
| 4880 | } |
| 4881 | |
| 4882 | bool NeedsEnvironment() const OVERRIDE { |
| 4883 | // Instruction may throw a CheckCastError. |
| 4884 | return true; |
| 4885 | } |
| 4886 | |
| 4887 | bool CanThrow() const OVERRIDE { return true; } |
| 4888 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4889 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4890 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4891 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4892 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4893 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4894 | |
| 4895 | DECLARE_INSTRUCTION(CheckCast); |
| 4896 | |
| 4897 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4898 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4899 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4900 | |
| 4901 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4902 | }; |
| 4903 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4904 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 4905 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4906 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4907 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4908 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 4909 | barrier_kind_(barrier_kind) {} |
| 4910 | |
| 4911 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 4912 | |
| 4913 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 4914 | |
| 4915 | private: |
| 4916 | const MemBarrierKind barrier_kind_; |
| 4917 | |
| 4918 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 4919 | }; |
| 4920 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4921 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 4922 | public: |
| 4923 | enum OperationKind { |
| 4924 | kEnter, |
| 4925 | kExit, |
| 4926 | }; |
| 4927 | |
| 4928 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4929 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4930 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 4931 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4932 | SetRawInputAt(0, object); |
| 4933 | } |
| 4934 | |
| 4935 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 4936 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 4937 | |
| 4938 | bool CanThrow() const OVERRIDE { |
| 4939 | // Verifier guarantees that monitor-exit cannot throw. |
| 4940 | // This is important because it allows the HGraphBuilder to remove |
| 4941 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 4942 | return IsEnter(); |
| 4943 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4944 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4945 | |
| 4946 | bool IsEnter() const { return kind_ == kEnter; } |
| 4947 | |
| 4948 | DECLARE_INSTRUCTION(MonitorOperation); |
| 4949 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4950 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4951 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 4952 | |
| 4953 | private: |
| 4954 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 4955 | }; |
| 4956 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4957 | /** |
| 4958 | * A HInstruction used as a marker for the replacement of new + <init> |
| 4959 | * of a String to a call to a StringFactory. Only baseline will see |
| 4960 | * the node at code generation, where it will be be treated as null. |
| 4961 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 4962 | * in the instruction simplifier. |
| 4963 | */ |
| 4964 | class HFakeString : public HTemplateInstruction<0> { |
| 4965 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4966 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 4967 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 4968 | |
| 4969 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 4970 | |
| 4971 | DECLARE_INSTRUCTION(FakeString); |
| 4972 | |
| 4973 | private: |
| 4974 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 4975 | }; |
| 4976 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 4977 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4978 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 4979 | MoveOperands(Location source, |
| 4980 | Location destination, |
| 4981 | Primitive::Type type, |
| 4982 | HInstruction* instruction) |
| 4983 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 4984 | |
| 4985 | Location GetSource() const { return source_; } |
| 4986 | Location GetDestination() const { return destination_; } |
| 4987 | |
| 4988 | void SetSource(Location value) { source_ = value; } |
| 4989 | void SetDestination(Location value) { destination_ = value; } |
| 4990 | |
| 4991 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 4992 | // destination (but not the source). |
| 4993 | Location MarkPending() { |
| 4994 | DCHECK(!IsPending()); |
| 4995 | Location dest = destination_; |
| 4996 | destination_ = Location::NoLocation(); |
| 4997 | return dest; |
| 4998 | } |
| 4999 | |
| 5000 | void ClearPending(Location dest) { |
| 5001 | DCHECK(IsPending()); |
| 5002 | destination_ = dest; |
| 5003 | } |
| 5004 | |
| 5005 | bool IsPending() const { |
| 5006 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5007 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5008 | } |
| 5009 | |
| 5010 | // True if this blocks a move from the given location. |
| 5011 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5012 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5013 | } |
| 5014 | |
| 5015 | // A move is redundant if it's been eliminated, if its source and |
| 5016 | // destination are the same, or if its destination is unneeded. |
| 5017 | bool IsRedundant() const { |
| 5018 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5019 | } |
| 5020 | |
| 5021 | // We clear both operands to indicate move that's been eliminated. |
| 5022 | void Eliminate() { |
| 5023 | source_ = destination_ = Location::NoLocation(); |
| 5024 | } |
| 5025 | |
| 5026 | bool IsEliminated() const { |
| 5027 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5028 | return source_.IsInvalid(); |
| 5029 | } |
| 5030 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5031 | Primitive::Type GetType() const { return type_; } |
| 5032 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5033 | bool Is64BitMove() const { |
| 5034 | return Primitive::Is64BitType(type_); |
| 5035 | } |
| 5036 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5037 | HInstruction* GetInstruction() const { return instruction_; } |
| 5038 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5039 | private: |
| 5040 | Location source_; |
| 5041 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5042 | // The type this move is for. |
| 5043 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5044 | // The instruction this move is assocatied with. Null when this move is |
| 5045 | // for moving an input in the expected locations of user (including a phi user). |
| 5046 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5047 | // in the same parallel move. |
| 5048 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5049 | }; |
| 5050 | |
| 5051 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5052 | |
| 5053 | class HParallelMove : public HTemplateInstruction<0> { |
| 5054 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5055 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5056 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5057 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5058 | moves_.reserve(kDefaultNumberOfMoves); |
| 5059 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5060 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5061 | void AddMove(Location source, |
| 5062 | Location destination, |
| 5063 | Primitive::Type type, |
| 5064 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5065 | DCHECK(source.IsValid()); |
| 5066 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5067 | if (kIsDebugBuild) { |
| 5068 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5069 | for (const MoveOperands& move : moves_) { |
| 5070 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5071 | // Special case the situation where the move is for the spill slot |
| 5072 | // of the instruction. |
| 5073 | if ((GetPrevious() == instruction) |
| 5074 | || ((GetPrevious() == nullptr) |
| 5075 | && instruction->IsPhi() |
| 5076 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5077 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5078 | << "Doing parallel moves for the same instruction."; |
| 5079 | } else { |
| 5080 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5081 | } |
| 5082 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5083 | } |
| 5084 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5085 | for (const MoveOperands& move : moves_) { |
| 5086 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5087 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5088 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5089 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5090 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5091 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5092 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5093 | } |
| 5094 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5095 | MoveOperands* MoveOperandsAt(size_t index) { |
| 5096 | DCHECK_LT(index, moves_.size()); |
| 5097 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5098 | } |
| 5099 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5100 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5101 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5102 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5103 | |
| 5104 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame^] | 5105 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5106 | |
| 5107 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5108 | }; |
| 5109 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5110 | } // namespace art |
| 5111 | |
| 5112 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5113 | #include "nodes_x86.h" |
| 5114 | #endif |
| 5115 | |
| 5116 | namespace art { |
| 5117 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5118 | class HGraphVisitor : public ValueObject { |
| 5119 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5120 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5121 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5122 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5123 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5124 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5125 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5126 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5127 | void VisitInsertionOrder(); |
| 5128 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5129 | // Visit the graph following dominator tree reverse post-order. |
| 5130 | void VisitReversePostOrder(); |
| 5131 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5132 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5133 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5134 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5135 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5136 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5137 | |
| 5138 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5139 | |
| 5140 | #undef DECLARE_VISIT_INSTRUCTION |
| 5141 | |
| 5142 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5143 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5144 | |
| 5145 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5146 | }; |
| 5147 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5148 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5149 | public: |
| 5150 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5151 | virtual ~HGraphDelegateVisitor() {} |
| 5152 | |
| 5153 | // Visit functions that delegate to to super class. |
| 5154 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5155 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5156 | |
| 5157 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5158 | |
| 5159 | #undef DECLARE_VISIT_INSTRUCTION |
| 5160 | |
| 5161 | private: |
| 5162 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5163 | }; |
| 5164 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5165 | class HInsertionOrderIterator : public ValueObject { |
| 5166 | public: |
| 5167 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5168 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5169 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
| 5170 | HBasicBlock* Current() const { return graph_.GetBlock(index_); } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5171 | void Advance() { ++index_; } |
| 5172 | |
| 5173 | private: |
| 5174 | const HGraph& graph_; |
| 5175 | size_t index_; |
| 5176 | |
| 5177 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5178 | }; |
| 5179 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5180 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5181 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5182 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5183 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5184 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5185 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5186 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5187 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5188 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5189 | void Advance() { ++index_; } |
| 5190 | |
| 5191 | private: |
| 5192 | const HGraph& graph_; |
| 5193 | size_t index_; |
| 5194 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5195 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5196 | }; |
| 5197 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5198 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5199 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5200 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5201 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5202 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5203 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5204 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5205 | |
| 5206 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5207 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5208 | void Advance() { --index_; } |
| 5209 | |
| 5210 | private: |
| 5211 | const HGraph& graph_; |
| 5212 | size_t index_; |
| 5213 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5214 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5215 | }; |
| 5216 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5217 | class HLinearPostOrderIterator : public ValueObject { |
| 5218 | public: |
| 5219 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5220 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5221 | |
| 5222 | bool Done() const { return index_ == 0; } |
| 5223 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5224 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5225 | |
| 5226 | void Advance() { |
| 5227 | --index_; |
| 5228 | DCHECK_GE(index_, 0U); |
| 5229 | } |
| 5230 | |
| 5231 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5232 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5233 | size_t index_; |
| 5234 | |
| 5235 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5236 | }; |
| 5237 | |
| 5238 | class HLinearOrderIterator : public ValueObject { |
| 5239 | public: |
| 5240 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5241 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5242 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5243 | bool Done() const { return index_ == order_.size(); } |
| 5244 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5245 | void Advance() { ++index_; } |
| 5246 | |
| 5247 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5248 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5249 | size_t index_; |
| 5250 | |
| 5251 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5252 | }; |
| 5253 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5254 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5255 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5256 | // block id. |
| 5257 | class HBlocksInLoopIterator : public ValueObject { |
| 5258 | public: |
| 5259 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5260 | : blocks_in_loop_(info.GetBlocks()), |
| 5261 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5262 | index_(0) { |
| 5263 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5264 | Advance(); |
| 5265 | } |
| 5266 | } |
| 5267 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5268 | bool Done() const { return index_ == blocks_.size(); } |
| 5269 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5270 | void Advance() { |
| 5271 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5272 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5273 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5274 | break; |
| 5275 | } |
| 5276 | } |
| 5277 | } |
| 5278 | |
| 5279 | private: |
| 5280 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5281 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5282 | size_t index_; |
| 5283 | |
| 5284 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5285 | }; |
| 5286 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5287 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5288 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5289 | // post order. |
| 5290 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5291 | public: |
| 5292 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5293 | : blocks_in_loop_(info.GetBlocks()), |
| 5294 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5295 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5296 | DCHECK(!blocks_.empty()); |
| 5297 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5298 | Advance(); |
| 5299 | } |
| 5300 | } |
| 5301 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5302 | bool Done() const { return index_ == blocks_.size(); } |
| 5303 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5304 | void Advance() { |
| 5305 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5306 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5307 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5308 | break; |
| 5309 | } |
| 5310 | } |
| 5311 | } |
| 5312 | |
| 5313 | private: |
| 5314 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5315 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5316 | size_t index_; |
| 5317 | |
| 5318 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5319 | }; |
| 5320 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5321 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5322 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5323 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5324 | : constant->AsLongConstant()->GetValue(); |
| 5325 | } |
| 5326 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5327 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5328 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5329 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5330 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5331 | // times and provide different class resolution but no two class loaders should ever |
| 5332 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5333 | // all sorts of weird failures. |
| 5334 | return &lhs == &rhs; |
| 5335 | } |
| 5336 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5337 | } // namespace art |
| 5338 | |
| 5339 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |