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 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 180 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 181 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 182 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 183 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 184 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 185 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 186 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 187 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 188 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 189 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 190 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 191 | // Try building the SSA form of this graph, with dominance computation and loop |
| 192 | // recognition. Returns whether it was successful in doing all these steps. |
| 193 | bool TryBuildingSsa() { |
| 194 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 195 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 196 | // elimination phase checks the consistency of the graph when doing a post-order |
| 197 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 198 | // users remaining when being visited. |
| 199 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 200 | // Precompute per-block try membership before entering the SSA builder, |
| 201 | // which needs the information to build catch block phis from values of |
| 202 | // locals at throwing instructions inside try blocks. |
| 203 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 204 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 205 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 206 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 209 | void ComputeDominanceInformation(); |
| 210 | void ClearDominanceInformation(); |
| 211 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 212 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 213 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 214 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 215 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 216 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 217 | // Analyze all natural loops in this graph. Returns false if one |
| 218 | // loop is not natural, that is the header does not dominate the |
| 219 | // back edge. |
| 220 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 221 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 222 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 223 | // order and loop information. |
| 224 | void ComputeTryBlockInformation(); |
| 225 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 226 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 227 | // Returns the instruction used to replace the invoke expression or null if the |
| 228 | // invoke is for a void method. |
| 229 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 230 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 231 | // Need to add a couple of blocks to test if the loop body is entered and |
| 232 | // put deoptimization instructions, etc. |
| 233 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 234 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 235 | // Removes `block` from the graph. |
| 236 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 237 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 238 | // Splits the edge between `block` and `successor` while preserving the |
| 239 | // indices in the predecessor/successor lists. If there are multiple edges |
| 240 | // between the blocks, the lowest indices are used. |
| 241 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 242 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 243 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 244 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 245 | void SimplifyLoop(HBasicBlock* header); |
| 246 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 247 | int32_t GetNextInstructionId() { |
| 248 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 249 | return current_instruction_id_++; |
| 250 | } |
| 251 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 252 | int32_t GetCurrentInstructionId() const { |
| 253 | return current_instruction_id_; |
| 254 | } |
| 255 | |
| 256 | void SetCurrentInstructionId(int32_t id) { |
| 257 | current_instruction_id_ = id; |
| 258 | } |
| 259 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 260 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 261 | return maximum_number_of_out_vregs_; |
| 262 | } |
| 263 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 264 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 265 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 266 | } |
| 267 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 268 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 269 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 270 | } |
| 271 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 272 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 273 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 276 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 277 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 278 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 279 | } |
| 280 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 281 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 282 | number_of_vregs_ = number_of_vregs; |
| 283 | } |
| 284 | |
| 285 | uint16_t GetNumberOfVRegs() const { |
| 286 | return number_of_vregs_; |
| 287 | } |
| 288 | |
| 289 | void SetNumberOfInVRegs(uint16_t value) { |
| 290 | number_of_in_vregs_ = value; |
| 291 | } |
| 292 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 293 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 294 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 295 | return number_of_vregs_ - number_of_in_vregs_; |
| 296 | } |
| 297 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 298 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 299 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 300 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 301 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 302 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 303 | return linear_order_; |
| 304 | } |
| 305 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 306 | bool HasBoundsChecks() const { |
| 307 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 310 | void SetHasBoundsChecks(bool value) { |
| 311 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 312 | } |
| 313 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 314 | bool ShouldGenerateConstructorBarrier() const { |
| 315 | return should_generate_constructor_barrier_; |
| 316 | } |
| 317 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 318 | bool IsDebuggable() const { return debuggable_; } |
| 319 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 320 | // 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] | 321 | // already, it is created and inserted into the graph. This method is only for |
| 322 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 323 | 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] | 324 | |
| 325 | // TODO: This is problematic for the consistency of reference type propagation |
| 326 | // because it can be created anytime after the pass and thus it will be left |
| 327 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 328 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 329 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 330 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 331 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 332 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 333 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 334 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 335 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 336 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 337 | 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] | 338 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 339 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 340 | 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] | 341 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 342 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 343 | HCurrentMethod* GetCurrentMethod(); |
| 344 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 345 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 346 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 347 | const DexFile& GetDexFile() const { |
| 348 | return dex_file_; |
| 349 | } |
| 350 | |
| 351 | uint32_t GetMethodIdx() const { |
| 352 | return method_idx_; |
| 353 | } |
| 354 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 355 | InvokeType GetInvokeType() const { |
| 356 | return invoke_type_; |
| 357 | } |
| 358 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 359 | InstructionSet GetInstructionSet() const { |
| 360 | return instruction_set_; |
| 361 | } |
| 362 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 363 | bool HasTryCatch() const { return has_try_catch_; } |
| 364 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 365 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 366 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 367 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 368 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 369 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 370 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 371 | template <class InstructionType, typename ValueType> |
| 372 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 373 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 374 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 375 | // Try to find an existing constant of the given value. |
| 376 | InstructionType* constant = nullptr; |
| 377 | auto cached_constant = cache->find(value); |
| 378 | if (cached_constant != cache->end()) { |
| 379 | constant = cached_constant->second; |
| 380 | } |
| 381 | |
| 382 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 383 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 384 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 385 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 386 | cache->Overwrite(value, constant); |
| 387 | InsertConstant(constant); |
| 388 | } |
| 389 | return constant; |
| 390 | } |
| 391 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 392 | void InsertConstant(HConstant* instruction); |
| 393 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 394 | // Cache a float constant into the graph. This method should only be |
| 395 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 396 | void CacheFloatConstant(HFloatConstant* constant); |
| 397 | |
| 398 | // See CacheFloatConstant comment. |
| 399 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 400 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 401 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 402 | |
| 403 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 404 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 405 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 406 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 407 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 408 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 409 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 410 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 411 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 412 | HBasicBlock* entry_block_; |
| 413 | HBasicBlock* exit_block_; |
| 414 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 415 | // 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] | 416 | uint16_t maximum_number_of_out_vregs_; |
| 417 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 418 | // The number of virtual registers in this method. Contains the parameters. |
| 419 | uint16_t number_of_vregs_; |
| 420 | |
| 421 | // The number of virtual registers used by parameters of this method. |
| 422 | uint16_t number_of_in_vregs_; |
| 423 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 424 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 425 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 426 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 427 | // Has bounds checks. We can totally skip BCE if it's false. |
| 428 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 429 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 430 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 431 | // try/catch-related passes if false. |
| 432 | bool has_try_catch_; |
| 433 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 434 | // Indicates whether the graph should be compiled in a way that |
| 435 | // ensures full debuggability. If false, we can apply more |
| 436 | // aggressive optimizations that may limit the level of debugging. |
| 437 | const bool debuggable_; |
| 438 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 439 | // 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] | 440 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 441 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 442 | // The dex file from which the method is from. |
| 443 | const DexFile& dex_file_; |
| 444 | |
| 445 | // The method index in the dex file. |
| 446 | const uint32_t method_idx_; |
| 447 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 448 | // If inlined, this encodes how the callee is being invoked. |
| 449 | const InvokeType invoke_type_; |
| 450 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 451 | // Whether the graph has been transformed to SSA form. Only used |
| 452 | // in debug mode to ensure we are not using properties only valid |
| 453 | // for non-SSA form (like the number of temporaries). |
| 454 | bool in_ssa_form_; |
| 455 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 456 | const bool should_generate_constructor_barrier_; |
| 457 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 458 | const InstructionSet instruction_set_; |
| 459 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 460 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 461 | HNullConstant* cached_null_constant_; |
| 462 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 463 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 464 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 465 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 466 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 467 | HCurrentMethod* cached_current_method_; |
| 468 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 469 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 470 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 471 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 472 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 473 | }; |
| 474 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 475 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 476 | public: |
| 477 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 478 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 479 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 480 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 481 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 482 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 483 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 484 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 485 | |
| 486 | HBasicBlock* GetHeader() const { |
| 487 | return header_; |
| 488 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 489 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 490 | void SetHeader(HBasicBlock* block) { |
| 491 | header_ = block; |
| 492 | } |
| 493 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 494 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 495 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 496 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 497 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 498 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 499 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 500 | } |
| 501 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 502 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 503 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 504 | } |
| 505 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 506 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 507 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 508 | } |
| 509 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 510 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 511 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 512 | } |
| 513 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 514 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 515 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 516 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 517 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 518 | } |
| 519 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 520 | // Returns the lifetime position of the back edge that has the |
| 521 | // greatest lifetime position. |
| 522 | size_t GetLifetimeEnd() const; |
| 523 | |
| 524 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 525 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 528 | // 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] | 529 | // that is the header dominates the back edge. |
| 530 | bool Populate(); |
| 531 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 532 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 533 | // Populate(). If there are no back edges left, the loop info is completely |
| 534 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 535 | // inner loops first. |
| 536 | void Update(); |
| 537 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 538 | // Returns whether this loop information contains `block`. |
| 539 | // Note that this loop information *must* be populated before entering this function. |
| 540 | bool Contains(const HBasicBlock& block) const; |
| 541 | |
| 542 | // Returns whether this loop information is an inner loop of `other`. |
| 543 | // Note that `other` *must* be populated before entering this function. |
| 544 | bool IsIn(const HLoopInformation& other) const; |
| 545 | |
| 546 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 547 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 548 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 549 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 550 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 551 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 552 | // Internal recursive implementation of `Populate`. |
| 553 | void PopulateRecursive(HBasicBlock* block); |
| 554 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 555 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 556 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 557 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 558 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 559 | |
| 560 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 561 | }; |
| 562 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 563 | // Stores try/catch information for basic blocks. |
| 564 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 565 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 566 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 567 | public: |
| 568 | // Try block information constructor. |
| 569 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 570 | : try_entry_(&try_entry), |
| 571 | catch_dex_file_(nullptr), |
| 572 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 573 | DCHECK(try_entry_ != nullptr); |
| 574 | } |
| 575 | |
| 576 | // Catch block information constructor. |
| 577 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 578 | : try_entry_(nullptr), |
| 579 | catch_dex_file_(&dex_file), |
| 580 | catch_type_index_(catch_type_index) {} |
| 581 | |
| 582 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 583 | |
| 584 | const HTryBoundary& GetTryEntry() const { |
| 585 | DCHECK(IsTryBlock()); |
| 586 | return *try_entry_; |
| 587 | } |
| 588 | |
| 589 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 590 | |
| 591 | bool IsCatchAllTypeIndex() const { |
| 592 | DCHECK(IsCatchBlock()); |
| 593 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 594 | } |
| 595 | |
| 596 | uint16_t GetCatchTypeIndex() const { |
| 597 | DCHECK(IsCatchBlock()); |
| 598 | return catch_type_index_; |
| 599 | } |
| 600 | |
| 601 | const DexFile& GetCatchDexFile() const { |
| 602 | DCHECK(IsCatchBlock()); |
| 603 | return *catch_dex_file_; |
| 604 | } |
| 605 | |
| 606 | private: |
| 607 | // One of possibly several TryBoundary instructions entering the block's try. |
| 608 | // Only set for try blocks. |
| 609 | const HTryBoundary* try_entry_; |
| 610 | |
| 611 | // Exception type information. Only set for catch blocks. |
| 612 | const DexFile* catch_dex_file_; |
| 613 | const uint16_t catch_type_index_; |
| 614 | }; |
| 615 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 616 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 617 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 618 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 619 | // A block in a method. Contains the list of instructions represented |
| 620 | // as a double linked list. Each block knows its predecessors and |
| 621 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 622 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 623 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 624 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 625 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 626 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 627 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 628 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 629 | loop_information_(nullptr), |
| 630 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 631 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 632 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 633 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 634 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 635 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 636 | try_catch_information_(nullptr) { |
| 637 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 638 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 639 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 640 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 641 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 642 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 643 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 644 | } |
| 645 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 646 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 647 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 648 | } |
| 649 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 650 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 651 | return ContainsElement(successors_, block, start_from); |
| 652 | } |
| 653 | |
| 654 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 655 | return dominated_blocks_; |
| 656 | } |
| 657 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 658 | bool IsEntryBlock() const { |
| 659 | return graph_->GetEntryBlock() == this; |
| 660 | } |
| 661 | |
| 662 | bool IsExitBlock() const { |
| 663 | return graph_->GetExitBlock() == this; |
| 664 | } |
| 665 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 666 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 667 | bool IsSingleTryBoundary() const; |
| 668 | |
| 669 | // Returns true if this block emits nothing but a jump. |
| 670 | bool IsSingleJump() const { |
| 671 | HLoopInformation* loop_info = GetLoopInformation(); |
| 672 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 673 | // Back edges generate a suspend check. |
| 674 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 675 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 676 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 677 | void AddBackEdge(HBasicBlock* back_edge) { |
| 678 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 679 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 680 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 681 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 682 | loop_information_->AddBackEdge(back_edge); |
| 683 | } |
| 684 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 685 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 686 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 687 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 688 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 689 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 690 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 691 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 692 | HBasicBlock* GetDominator() const { return dominator_; } |
| 693 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 694 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 695 | |
| 696 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 697 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 698 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 699 | |
| 700 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 701 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 702 | } |
| 703 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 704 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 705 | |
| 706 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 707 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 708 | } |
| 709 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 710 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 711 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 712 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 713 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 714 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 715 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 716 | |
| 717 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 718 | successors_.push_back(block); |
| 719 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 720 | } |
| 721 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 722 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 723 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 724 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 725 | new_block->predecessors_.push_back(this); |
| 726 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 727 | } |
| 728 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 729 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 730 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 731 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 732 | new_block->successors_.push_back(this); |
| 733 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 736 | // Insert `this` between `predecessor` and `successor. This method |
| 737 | // preserves the indicies, and will update the first edge found between |
| 738 | // `predecessor` and `successor`. |
| 739 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 740 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 741 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 742 | successor->predecessors_[predecessor_index] = this; |
| 743 | predecessor->successors_[successor_index] = this; |
| 744 | successors_.push_back(successor); |
| 745 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 746 | } |
| 747 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 748 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 749 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 750 | } |
| 751 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 752 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 753 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 756 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 757 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 761 | predecessors_.push_back(block); |
| 762 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 763 | } |
| 764 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 765 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 766 | DCHECK_EQ(predecessors_.size(), 2u); |
| 767 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 768 | } |
| 769 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 770 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 771 | DCHECK_EQ(successors_.size(), 2u); |
| 772 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 773 | } |
| 774 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 775 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 776 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 777 | } |
| 778 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 779 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 780 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 781 | } |
| 782 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 783 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 784 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 785 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 789 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 790 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 791 | } |
| 792 | |
| 793 | // Returns whether the first occurrence of `predecessor` in the list of |
| 794 | // predecessors is at index `idx`. |
| 795 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 796 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 797 | return GetPredecessorIndexOf(predecessor) == idx; |
| 798 | } |
| 799 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 800 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 801 | // these are stored at the beginning of the successor list. |
| 802 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 803 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 804 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 806 | // Create a new block between this block and its predecessors. The new block |
| 807 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 808 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 809 | // loop and try/catch information are not updated. |
| 810 | HBasicBlock* CreateImmediateDominator(); |
| 811 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 812 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 813 | // created, latter block. Note that this method will add the block to the |
| 814 | // graph, create a Goto at the end of the former block and will create an edge |
| 815 | // 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] | 816 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 817 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 818 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 819 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 820 | // created block. Note that this method just updates raw block information, |
| 821 | // like predecessors, successors, dominators, and instruction list. It does not |
| 822 | // update the graph, reverse post order, loop information, nor make sure the |
| 823 | // blocks are consistent (for example ending with a control flow instruction). |
| 824 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 825 | |
| 826 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 827 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 828 | // that this method does not update the graph, reverse post order, loop |
| 829 | // information, nor make sure the blocks are consistent (for example ending |
| 830 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 831 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 832 | |
| 833 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 834 | // of `this` are moved to `other`. |
| 835 | // Note that this method does not update the graph, reverse post order, loop |
| 836 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 837 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 838 | void ReplaceWith(HBasicBlock* other); |
| 839 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 840 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 841 | // order, links to predecessors, successors, dominators and deletes the block |
| 842 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 843 | // predecessor of `other` and vice versa. |
| 844 | void MergeWith(HBasicBlock* other); |
| 845 | |
| 846 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 847 | // removes it from all loops it is included in and eventually from the graph. |
| 848 | // The block must not dominate any other block. Predecessors and successors |
| 849 | // are safely updated. |
| 850 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 851 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 852 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 853 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 854 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 855 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 856 | // Replace instruction `initial` with `replacement` within this block. |
| 857 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 858 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 859 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 860 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 861 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 862 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 863 | // instruction is not in use and removes it from the use lists of its inputs. |
| 864 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 865 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 866 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 867 | |
| 868 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 869 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 870 | } |
| 871 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 872 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 873 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 874 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 875 | } |
| 876 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 877 | HLoopInformation* GetLoopInformation() const { |
| 878 | return loop_information_; |
| 879 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 880 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 881 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 882 | // 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] | 883 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 884 | void SetInLoop(HLoopInformation* info) { |
| 885 | if (IsLoopHeader()) { |
| 886 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 887 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 888 | loop_information_ = info; |
| 889 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 890 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 891 | // Note that a non loop header having a loop information means this loop information |
| 892 | // has already been populated |
| 893 | loop_information_ = info; |
| 894 | } else { |
| 895 | // Block is part of an inner loop. Do not update the loop information. |
| 896 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 897 | // at this point, because this method is being called while populating `info`. |
| 898 | } |
| 899 | } |
| 900 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 901 | // Raw update of the loop information. |
| 902 | void SetLoopInformation(HLoopInformation* info) { |
| 903 | loop_information_ = info; |
| 904 | } |
| 905 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 906 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 907 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 908 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 909 | |
| 910 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 911 | try_catch_information_ = try_catch_information; |
| 912 | } |
| 913 | |
| 914 | bool IsTryBlock() const { |
| 915 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 916 | } |
| 917 | |
| 918 | bool IsCatchBlock() const { |
| 919 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 920 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 921 | |
| 922 | // Returns the try entry that this block's successors should have. They will |
| 923 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 924 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 925 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 926 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 927 | bool HasThrowingInstructions() const; |
| 928 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 929 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 930 | bool Dominates(HBasicBlock* block) const; |
| 931 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 932 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 933 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 934 | |
| 935 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 936 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 937 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 938 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 939 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 940 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 941 | bool HasSinglePhi() const; |
| 942 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 943 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 944 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 945 | ArenaVector<HBasicBlock*> predecessors_; |
| 946 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 947 | HInstructionList instructions_; |
| 948 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 949 | HLoopInformation* loop_information_; |
| 950 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 951 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 952 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 953 | // The dex program counter of the first instruction of this block. |
| 954 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 955 | size_t lifetime_start_; |
| 956 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 957 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 958 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 959 | friend class HGraph; |
| 960 | friend class HInstruction; |
| 961 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 962 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 963 | }; |
| 964 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 965 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 966 | // from the innermost to the outermost. |
| 967 | class HLoopInformationOutwardIterator : public ValueObject { |
| 968 | public: |
| 969 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 970 | : current_(block.GetLoopInformation()) {} |
| 971 | |
| 972 | bool Done() const { return current_ == nullptr; } |
| 973 | |
| 974 | void Advance() { |
| 975 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 976 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | HLoopInformation* Current() const { |
| 980 | DCHECK(!Done()); |
| 981 | return current_; |
| 982 | } |
| 983 | |
| 984 | private: |
| 985 | HLoopInformation* current_; |
| 986 | |
| 987 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 988 | }; |
| 989 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 990 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 991 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 992 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 993 | M(ArrayGet, Instruction) \ |
| 994 | M(ArrayLength, Instruction) \ |
| 995 | M(ArraySet, Instruction) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 996 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 997 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 998 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 999 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1000 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1001 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1002 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1003 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1004 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1005 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1006 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1007 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1008 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1009 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1010 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1011 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1012 | M(FloatConstant, Constant) \ |
| 1013 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1014 | M(GreaterThan, Condition) \ |
| 1015 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1016 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1017 | M(InstanceFieldGet, Instruction) \ |
| 1018 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1019 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1020 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1021 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1022 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1023 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1024 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1025 | M(LessThan, Condition) \ |
| 1026 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1027 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1028 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1029 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1030 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1031 | M(Local, Instruction) \ |
| 1032 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1033 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1034 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1035 | M(Mul, BinaryOperation) \ |
| 1036 | M(Neg, UnaryOperation) \ |
| 1037 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1038 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1039 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1040 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1041 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1042 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1043 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1044 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1045 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1046 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1047 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1048 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1049 | M(Return, Instruction) \ |
| 1050 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1051 | M(Shl, BinaryOperation) \ |
| 1052 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1053 | M(StaticFieldGet, Instruction) \ |
| 1054 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1055 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1056 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1057 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1058 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1059 | M(StoreLocal, Instruction) \ |
| 1060 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1061 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1062 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1063 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1064 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1065 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1066 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1067 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1068 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1069 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1070 | |
| 1071 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
| 1072 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1073 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1074 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1075 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1076 | M(X86ComputeBaseMethodAddress, Instruction) \ |
| 1077 | M(X86LoadFromConstantTable, Instruction) |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1078 | |
| 1079 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1080 | |
| 1081 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1082 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1083 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1084 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1085 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1086 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1087 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1088 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1089 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1090 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1091 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1092 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1093 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1094 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1095 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1096 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1097 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1098 | #undef FORWARD_DECLARATION |
| 1099 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1100 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1101 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1102 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1103 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1104 | H##type* As##type() OVERRIDE { return this; } \ |
| 1105 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1106 | return other->Is##type(); \ |
| 1107 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1108 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1109 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1110 | template <typename T> class HUseList; |
| 1111 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1112 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1113 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1114 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1115 | HUseListNode* GetPrevious() const { return prev_; } |
| 1116 | HUseListNode* GetNext() const { return next_; } |
| 1117 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1118 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1119 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1120 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1121 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1122 | HUseListNode(T user, size_t index) |
| 1123 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1124 | |
| 1125 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1126 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1127 | HUseListNode<T>* prev_; |
| 1128 | HUseListNode<T>* next_; |
| 1129 | |
| 1130 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1131 | |
| 1132 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1133 | }; |
| 1134 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1135 | template <typename T> |
| 1136 | class HUseList : public ValueObject { |
| 1137 | public: |
| 1138 | HUseList() : first_(nullptr) {} |
| 1139 | |
| 1140 | void Clear() { |
| 1141 | first_ = nullptr; |
| 1142 | } |
| 1143 | |
| 1144 | // Adds a new entry at the beginning of the use list and returns |
| 1145 | // the newly created node. |
| 1146 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1147 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1148 | if (IsEmpty()) { |
| 1149 | first_ = new_node; |
| 1150 | } else { |
| 1151 | first_->prev_ = new_node; |
| 1152 | new_node->next_ = first_; |
| 1153 | first_ = new_node; |
| 1154 | } |
| 1155 | return new_node; |
| 1156 | } |
| 1157 | |
| 1158 | HUseListNode<T>* GetFirst() const { |
| 1159 | return first_; |
| 1160 | } |
| 1161 | |
| 1162 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1163 | DCHECK(node != nullptr); |
| 1164 | DCHECK(Contains(node)); |
| 1165 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1166 | if (node->prev_ != nullptr) { |
| 1167 | node->prev_->next_ = node->next_; |
| 1168 | } |
| 1169 | if (node->next_ != nullptr) { |
| 1170 | node->next_->prev_ = node->prev_; |
| 1171 | } |
| 1172 | if (node == first_) { |
| 1173 | first_ = node->next_; |
| 1174 | } |
| 1175 | } |
| 1176 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1177 | bool Contains(const HUseListNode<T>* node) const { |
| 1178 | if (node == nullptr) { |
| 1179 | return false; |
| 1180 | } |
| 1181 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1182 | if (current == node) { |
| 1183 | return true; |
| 1184 | } |
| 1185 | } |
| 1186 | return false; |
| 1187 | } |
| 1188 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1189 | bool IsEmpty() const { |
| 1190 | return first_ == nullptr; |
| 1191 | } |
| 1192 | |
| 1193 | bool HasOnlyOneUse() const { |
| 1194 | return first_ != nullptr && first_->next_ == nullptr; |
| 1195 | } |
| 1196 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1197 | size_t SizeSlow() const { |
| 1198 | size_t count = 0; |
| 1199 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1200 | ++count; |
| 1201 | } |
| 1202 | return count; |
| 1203 | } |
| 1204 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1205 | private: |
| 1206 | HUseListNode<T>* first_; |
| 1207 | }; |
| 1208 | |
| 1209 | template<typename T> |
| 1210 | class HUseIterator : public ValueObject { |
| 1211 | public: |
| 1212 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1213 | |
| 1214 | bool Done() const { return current_ == nullptr; } |
| 1215 | |
| 1216 | void Advance() { |
| 1217 | DCHECK(!Done()); |
| 1218 | current_ = current_->GetNext(); |
| 1219 | } |
| 1220 | |
| 1221 | HUseListNode<T>* Current() const { |
| 1222 | DCHECK(!Done()); |
| 1223 | return current_; |
| 1224 | } |
| 1225 | |
| 1226 | private: |
| 1227 | HUseListNode<T>* current_; |
| 1228 | |
| 1229 | friend class HValue; |
| 1230 | }; |
| 1231 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1232 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1233 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1234 | // by the used instructions. |
| 1235 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1236 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1237 | public: |
| 1238 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1239 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1240 | |
| 1241 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1242 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1243 | DCHECK(instruction_ != nullptr); |
| 1244 | DCHECK(use_node_ != nullptr); |
| 1245 | DCHECK(old_record.use_node_ == nullptr); |
| 1246 | } |
| 1247 | |
| 1248 | HInstruction* GetInstruction() const { return instruction_; } |
| 1249 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1250 | |
| 1251 | private: |
| 1252 | // Instruction used by the user. |
| 1253 | HInstruction* instruction_; |
| 1254 | |
| 1255 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1256 | HUseListNode<T>* use_node_; |
| 1257 | }; |
| 1258 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1259 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1260 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1261 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1262 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1263 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1264 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1265 | * modify the value of a reference field read [although it may modify the |
| 1266 | * reference fetch prior to reading the field, which is represented by its own |
| 1267 | * write/read dependence]). The analysis makes conservative points-to |
| 1268 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1269 | * the same, and any reference read depends on any reference read without |
| 1270 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1271 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1272 | * The internal representation uses 38-bit and is described in the table below. |
| 1273 | * The first line indicates the side effect, and for field/array accesses the |
| 1274 | * second line indicates the type of the access (in the order of the |
| 1275 | * Primitive::Type enum). |
| 1276 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1277 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1278 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1279 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1280 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1281 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1282 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1283 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1284 | * |
| 1285 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1286 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1287 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1288 | class SideEffects : public ValueObject { |
| 1289 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1290 | SideEffects() : flags_(0) {} |
| 1291 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1292 | static SideEffects None() { |
| 1293 | return SideEffects(0); |
| 1294 | } |
| 1295 | |
| 1296 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1297 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1298 | } |
| 1299 | |
| 1300 | static SideEffects AllChanges() { |
| 1301 | return SideEffects(kAllChangeBits); |
| 1302 | } |
| 1303 | |
| 1304 | static SideEffects AllDependencies() { |
| 1305 | return SideEffects(kAllDependOnBits); |
| 1306 | } |
| 1307 | |
| 1308 | static SideEffects AllExceptGCDependency() { |
| 1309 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1310 | } |
| 1311 | |
| 1312 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1313 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1314 | } |
| 1315 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1316 | static SideEffects AllWrites() { |
| 1317 | return SideEffects(kAllWrites); |
| 1318 | } |
| 1319 | |
| 1320 | static SideEffects AllReads() { |
| 1321 | return SideEffects(kAllReads); |
| 1322 | } |
| 1323 | |
| 1324 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1325 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1326 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1327 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1328 | } |
| 1329 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1330 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1331 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1332 | } |
| 1333 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1334 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1335 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1336 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1337 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1338 | } |
| 1339 | |
| 1340 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1341 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1342 | } |
| 1343 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1344 | static SideEffects CanTriggerGC() { |
| 1345 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1346 | } |
| 1347 | |
| 1348 | static SideEffects DependsOnGC() { |
| 1349 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1350 | } |
| 1351 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1352 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1353 | SideEffects Union(SideEffects other) const { |
| 1354 | return SideEffects(flags_ | other.flags_); |
| 1355 | } |
| 1356 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1357 | SideEffects Exclusion(SideEffects other) const { |
| 1358 | return SideEffects(flags_ & ~other.flags_); |
| 1359 | } |
| 1360 | |
| 1361 | bool Includes(SideEffects other) const { |
| 1362 | return (other.flags_ & flags_) == other.flags_; |
| 1363 | } |
| 1364 | |
| 1365 | bool HasSideEffects() const { |
| 1366 | return (flags_ & kAllChangeBits); |
| 1367 | } |
| 1368 | |
| 1369 | bool HasDependencies() const { |
| 1370 | return (flags_ & kAllDependOnBits); |
| 1371 | } |
| 1372 | |
| 1373 | // Returns true if there are no side effects or dependencies. |
| 1374 | bool DoesNothing() const { |
| 1375 | return flags_ == 0; |
| 1376 | } |
| 1377 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1378 | // Returns true if something is written. |
| 1379 | bool DoesAnyWrite() const { |
| 1380 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1381 | } |
| 1382 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1383 | // Returns true if something is read. |
| 1384 | bool DoesAnyRead() const { |
| 1385 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1386 | } |
| 1387 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1388 | // Returns true if potentially everything is written and read |
| 1389 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1390 | bool DoesAllReadWrite() const { |
| 1391 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1392 | } |
| 1393 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1394 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1395 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1396 | } |
| 1397 | |
| 1398 | // Returns true if this may read something written by other. |
| 1399 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1400 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1401 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1405 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1406 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1407 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1408 | for (int s = kLastBit; s >= 0; s--) { |
| 1409 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1410 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1411 | // This is a bit for the GC side effect. |
| 1412 | if (current_bit_is_set) { |
| 1413 | flags += "GC"; |
| 1414 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1415 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1416 | } else { |
| 1417 | // This is a bit for the array/field analysis. |
| 1418 | // The underscore character stands for the 'can trigger GC' bit. |
| 1419 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1420 | if (current_bit_is_set) { |
| 1421 | flags += kDebug[s]; |
| 1422 | } |
| 1423 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1424 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1425 | flags += "|"; |
| 1426 | } |
| 1427 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1428 | } |
| 1429 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1430 | } |
| 1431 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1432 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1433 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1434 | private: |
| 1435 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1436 | |
| 1437 | static constexpr int kFieldWriteOffset = 0; |
| 1438 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1439 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1440 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1441 | |
| 1442 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1443 | |
| 1444 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1445 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1446 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1447 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1448 | |
| 1449 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1450 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1451 | |
| 1452 | // Aliases. |
| 1453 | |
| 1454 | static_assert(kChangeBits == kDependOnBits, |
| 1455 | "the 'change' bits should match the 'depend on' bits."); |
| 1456 | |
| 1457 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1458 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1459 | static constexpr uint64_t kAllWrites = |
| 1460 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1461 | static constexpr uint64_t kAllReads = |
| 1462 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1463 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1464 | // Work around the fact that HIR aliases I/F and J/D. |
| 1465 | // TODO: remove this interceptor once HIR types are clean |
| 1466 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1467 | switch (type) { |
| 1468 | case Primitive::kPrimInt: |
| 1469 | case Primitive::kPrimFloat: |
| 1470 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1471 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1472 | case Primitive::kPrimLong: |
| 1473 | case Primitive::kPrimDouble: |
| 1474 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1475 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1476 | default: |
| 1477 | return TypeFlag(type, offset); |
| 1478 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1479 | } |
| 1480 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1481 | // Translates type to bit flag. |
| 1482 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1483 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1484 | const uint64_t one = 1; |
| 1485 | const int shift = type; // 0-based consecutive enum |
| 1486 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1487 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1488 | return one << (type + offset); |
| 1489 | } |
| 1490 | |
| 1491 | // Private constructor on direct flags value. |
| 1492 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1493 | |
| 1494 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1495 | }; |
| 1496 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1497 | // 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] | 1498 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1499 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1500 | HEnvironment(ArenaAllocator* arena, |
| 1501 | size_t number_of_vregs, |
| 1502 | const DexFile& dex_file, |
| 1503 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1504 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1505 | InvokeType invoke_type, |
| 1506 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1507 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1508 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1509 | parent_(nullptr), |
| 1510 | dex_file_(dex_file), |
| 1511 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1512 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1513 | invoke_type_(invoke_type), |
| 1514 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1515 | } |
| 1516 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1517 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1518 | : HEnvironment(arena, |
| 1519 | to_copy.Size(), |
| 1520 | to_copy.GetDexFile(), |
| 1521 | to_copy.GetMethodIdx(), |
| 1522 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1523 | to_copy.GetInvokeType(), |
| 1524 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1525 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1526 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1527 | if (parent_ != nullptr) { |
| 1528 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1529 | } else { |
| 1530 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1531 | parent_->CopyFrom(parent); |
| 1532 | if (parent->GetParent() != nullptr) { |
| 1533 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1534 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1535 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1536 | } |
| 1537 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1538 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1539 | void CopyFrom(HEnvironment* environment); |
| 1540 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1541 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1542 | // input to the loop phi instead. This is for inserting instructions that |
| 1543 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1544 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1545 | |
| 1546 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1547 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
| 1550 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1551 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1552 | } |
| 1553 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1554 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1555 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1556 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1557 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1558 | HEnvironment* GetParent() const { return parent_; } |
| 1559 | |
| 1560 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1561 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1565 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1566 | } |
| 1567 | |
| 1568 | uint32_t GetDexPc() const { |
| 1569 | return dex_pc_; |
| 1570 | } |
| 1571 | |
| 1572 | uint32_t GetMethodIdx() const { |
| 1573 | return method_idx_; |
| 1574 | } |
| 1575 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1576 | InvokeType GetInvokeType() const { |
| 1577 | return invoke_type_; |
| 1578 | } |
| 1579 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1580 | const DexFile& GetDexFile() const { |
| 1581 | return dex_file_; |
| 1582 | } |
| 1583 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1584 | HInstruction* GetHolder() const { |
| 1585 | return holder_; |
| 1586 | } |
| 1587 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1588 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1589 | // Record instructions' use entries of this environment for constant-time removal. |
| 1590 | // It should only be called by HInstruction when a new environment use is added. |
| 1591 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1592 | DCHECK(env_use->GetUser() == this); |
| 1593 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1594 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1595 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1596 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1597 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1598 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1599 | HEnvironment* parent_; |
| 1600 | const DexFile& dex_file_; |
| 1601 | const uint32_t method_idx_; |
| 1602 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1603 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1604 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1605 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1606 | HInstruction* const holder_; |
| 1607 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1608 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1609 | |
| 1610 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1611 | }; |
| 1612 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1613 | class ReferenceTypeInfo : ValueObject { |
| 1614 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1615 | typedef Handle<mirror::Class> TypeHandle; |
| 1616 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1617 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1618 | // The constructor will check that the type_handle is valid. |
| 1619 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1622 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1623 | |
| 1624 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1625 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1626 | } |
| 1627 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1628 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1629 | return IsValidHandle(type_handle_); |
| 1630 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1631 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1632 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1633 | |
| 1634 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1635 | DCHECK(IsValid()); |
| 1636 | return GetTypeHandle()->IsObjectClass(); |
| 1637 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1638 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1639 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1640 | return IsValid() && GetTypeHandle()->IsStringClass(); |
| 1641 | } |
| 1642 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1643 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1644 | DCHECK(IsValid()); |
| 1645 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1646 | } |
| 1647 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1648 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1649 | DCHECK(IsValid()); |
| 1650 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1651 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1652 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1653 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1654 | return GetTypeHandle()->IsArrayClass(); |
| 1655 | } |
| 1656 | |
| 1657 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1658 | if (!IsExact()) return false; |
| 1659 | if (!IsArrayClass()) return false; |
| 1660 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1661 | } |
| 1662 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1663 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1664 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1665 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1666 | DCHECK(IsValid()); |
| 1667 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1668 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1669 | } |
| 1670 | |
| 1671 | // Returns true if the type information provide the same amount of details. |
| 1672 | // 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] | 1673 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1674 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1675 | if (!IsValid() && !rti.IsValid()) { |
| 1676 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1677 | return true; |
| 1678 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1679 | if (!IsValid() || !rti.IsValid()) { |
| 1680 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1681 | return false; |
| 1682 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1683 | return IsExact() == rti.IsExact() |
| 1684 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1688 | ReferenceTypeInfo(); |
| 1689 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1690 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1691 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1692 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1693 | // 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] | 1694 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1695 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1696 | }; |
| 1697 | |
| 1698 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1699 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1700 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1701 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1702 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1703 | : previous_(nullptr), |
| 1704 | next_(nullptr), |
| 1705 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1706 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1707 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1708 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1709 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1710 | locations_(nullptr), |
| 1711 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1712 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1713 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1714 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1715 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1716 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1717 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1718 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1719 | enum InstructionKind { |
| 1720 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1721 | }; |
| 1722 | #undef DECLARE_KIND |
| 1723 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1724 | HInstruction* GetNext() const { return next_; } |
| 1725 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1726 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1727 | HInstruction* GetNextDisregardingMoves() const; |
| 1728 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1729 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1730 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1731 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1732 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1733 | bool IsInBlock() const { return block_ != nullptr; } |
| 1734 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1735 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1736 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1737 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1738 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1739 | |
| 1740 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1741 | virtual const char* DebugName() const = 0; |
| 1742 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1743 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1744 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1745 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1746 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1747 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1748 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1749 | |
| 1750 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1751 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1752 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1753 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1754 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1755 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1756 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1757 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1758 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1759 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1760 | // Does not apply for all instructions, but having this at top level greatly |
| 1761 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1762 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1763 | virtual bool CanBeNull() const { |
| 1764 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1765 | return true; |
| 1766 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1767 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1768 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj) const { |
| 1769 | UNUSED(obj); |
| 1770 | return false; |
| 1771 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1772 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1773 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1774 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1775 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1776 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1777 | return reference_type_info_; |
| 1778 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1779 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1780 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1781 | DCHECK(user != nullptr); |
| 1782 | HUseListNode<HInstruction*>* use = |
| 1783 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1784 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1785 | } |
| 1786 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1787 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1788 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1789 | HUseListNode<HEnvironment*>* env_use = |
| 1790 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1791 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1792 | } |
| 1793 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1794 | void RemoveAsUserOfInput(size_t input) { |
| 1795 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1796 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1797 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1798 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1799 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1800 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1801 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1802 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1803 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1804 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1805 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1806 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1807 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1808 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1809 | // Does this instruction strictly dominate `other_instruction`? |
| 1810 | // Returns false if this instruction and `other_instruction` are the same. |
| 1811 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1812 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1813 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1814 | int GetId() const { return id_; } |
| 1815 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1816 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1817 | int GetSsaIndex() const { return ssa_index_; } |
| 1818 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1819 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1820 | |
| 1821 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1822 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1823 | // Set the `environment_` field. Raw because this method does not |
| 1824 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1825 | void SetRawEnvironment(HEnvironment* environment) { |
| 1826 | DCHECK(environment_ == nullptr); |
| 1827 | DCHECK_EQ(environment->GetHolder(), this); |
| 1828 | environment_ = environment; |
| 1829 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1830 | |
| 1831 | // Set the environment of this instruction, copying it from `environment`. While |
| 1832 | // copying, the uses lists are being updated. |
| 1833 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1834 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1835 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1836 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1837 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1838 | if (environment->GetParent() != nullptr) { |
| 1839 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1840 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1841 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1842 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1843 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1844 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1845 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1846 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1847 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1848 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1849 | if (environment->GetParent() != nullptr) { |
| 1850 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1851 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1852 | } |
| 1853 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1854 | // Returns the number of entries in the environment. Typically, that is the |
| 1855 | // number of dex registers in a method. It could be more in case of inlining. |
| 1856 | size_t EnvironmentSize() const; |
| 1857 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1858 | LocationSummary* GetLocations() const { return locations_; } |
| 1859 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1860 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1861 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1862 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1863 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1864 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1865 | // uses of this instruction by `other` are *not* updated. |
| 1866 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1867 | ReplaceWith(other); |
| 1868 | other->ReplaceInput(this, use_index); |
| 1869 | } |
| 1870 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1871 | // Move `this` instruction before `cursor`. |
| 1872 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1873 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1874 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1875 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1876 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1877 | virtual H##type* As##type() { return nullptr; } |
| 1878 | |
| 1879 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1880 | #undef INSTRUCTION_TYPE_CHECK |
| 1881 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1882 | // Returns whether the instruction can be moved within the graph. |
| 1883 | virtual bool CanBeMoved() const { return false; } |
| 1884 | |
| 1885 | // Returns whether the two instructions are of the same kind. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1886 | virtual bool InstructionTypeEquals(HInstruction* other) const { |
| 1887 | UNUSED(other); |
| 1888 | return false; |
| 1889 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1890 | |
| 1891 | // Returns whether any data encoded in the two instructions is equal. |
| 1892 | // This method does not look at the inputs. Both instructions must be |
| 1893 | // of the same type, otherwise the method has undefined behavior. |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1894 | virtual bool InstructionDataEquals(HInstruction* other) const { |
| 1895 | UNUSED(other); |
| 1896 | return false; |
| 1897 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1898 | |
| 1899 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1900 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1901 | // 2) Their inputs are identical. |
| 1902 | bool Equals(HInstruction* other) const; |
| 1903 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1904 | virtual InstructionKind GetKind() const = 0; |
| 1905 | |
| 1906 | virtual size_t ComputeHashCode() const { |
| 1907 | size_t result = GetKind(); |
| 1908 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1909 | result = (result * 31) + InputAt(i)->GetId(); |
| 1910 | } |
| 1911 | return result; |
| 1912 | } |
| 1913 | |
| 1914 | SideEffects GetSideEffects() const { return side_effects_; } |
| 1915 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1916 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1917 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1918 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1919 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1920 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1921 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1922 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1923 | |
| 1924 | // Returns whether the code generation of the instruction will require to have access |
| 1925 | // to the current method. Such instructions are: |
| 1926 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1927 | // to walk the stack and have the current method stored at a specific stack address. |
| 1928 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1929 | // fields of the current method. |
| 1930 | bool NeedsCurrentMethod() const { |
| 1931 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1932 | } |
| 1933 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1934 | virtual bool NeedsDexCache() const { return false; } |
| 1935 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1936 | // Does this instruction have any use in an environment before |
| 1937 | // control flow hits 'other'? |
| 1938 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1939 | |
| 1940 | // Remove all references to environment uses of this instruction. |
| 1941 | // The caller must ensure that this is safe to do. |
| 1942 | void RemoveEnvironmentUsers(); |
| 1943 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1944 | protected: |
| 1945 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1946 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1947 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1948 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1949 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 1950 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1951 | HInstruction* previous_; |
| 1952 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1953 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1954 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1955 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1956 | // An instruction gets an id when it is added to the graph. |
| 1957 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1958 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1959 | int id_; |
| 1960 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1961 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 1962 | int ssa_index_; |
| 1963 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1964 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1965 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1966 | |
| 1967 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1968 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1969 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1970 | // The environment associated with this instruction. Not null if the instruction |
| 1971 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1972 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1973 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1974 | // Set by the code generator. |
| 1975 | LocationSummary* locations_; |
| 1976 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1977 | // Set by the liveness analysis. |
| 1978 | LiveInterval* live_interval_; |
| 1979 | |
| 1980 | // Set by the liveness analysis, this is the position in a linear |
| 1981 | // order of blocks where this instruction's live interval start. |
| 1982 | size_t lifetime_position_; |
| 1983 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1984 | const SideEffects side_effects_; |
| 1985 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1986 | // TODO: for primitive types this should be marked as invalid. |
| 1987 | ReferenceTypeInfo reference_type_info_; |
| 1988 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1989 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1990 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1991 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1992 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1993 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1994 | |
| 1995 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 1996 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1997 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1998 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1999 | class HInputIterator : public ValueObject { |
| 2000 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2001 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2002 | |
| 2003 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2004 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2005 | void Advance() { index_++; } |
| 2006 | |
| 2007 | private: |
| 2008 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2009 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2010 | |
| 2011 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2012 | }; |
| 2013 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2014 | class HInstructionIterator : public ValueObject { |
| 2015 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2016 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2017 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2018 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2019 | } |
| 2020 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2021 | bool Done() const { return instruction_ == nullptr; } |
| 2022 | HInstruction* Current() const { return instruction_; } |
| 2023 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2024 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2025 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2026 | } |
| 2027 | |
| 2028 | private: |
| 2029 | HInstruction* instruction_; |
| 2030 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2031 | |
| 2032 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2033 | }; |
| 2034 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2035 | class HBackwardInstructionIterator : public ValueObject { |
| 2036 | public: |
| 2037 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2038 | : instruction_(instructions.last_instruction_) { |
| 2039 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2040 | } |
| 2041 | |
| 2042 | bool Done() const { return instruction_ == nullptr; } |
| 2043 | HInstruction* Current() const { return instruction_; } |
| 2044 | void Advance() { |
| 2045 | instruction_ = next_; |
| 2046 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2047 | } |
| 2048 | |
| 2049 | private: |
| 2050 | HInstruction* instruction_; |
| 2051 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2052 | |
| 2053 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2054 | }; |
| 2055 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2056 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2057 | class HTemplateInstruction: public HInstruction { |
| 2058 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2059 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2060 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2061 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2062 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2063 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2064 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2065 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2066 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2067 | DCHECK_LT(i, N); |
| 2068 | return inputs_[i]; |
| 2069 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2070 | |
| 2071 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2072 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2073 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2076 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2077 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2078 | |
| 2079 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2080 | }; |
| 2081 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2082 | // HTemplateInstruction specialization for N=0. |
| 2083 | template<> |
| 2084 | class HTemplateInstruction<0>: public HInstruction { |
| 2085 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2086 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2087 | : HInstruction(side_effects, dex_pc) {} |
| 2088 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2089 | virtual ~HTemplateInstruction() {} |
| 2090 | |
| 2091 | size_t InputCount() const OVERRIDE { return 0; } |
| 2092 | |
| 2093 | protected: |
| 2094 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2095 | LOG(FATAL) << "Unreachable"; |
| 2096 | UNREACHABLE(); |
| 2097 | } |
| 2098 | |
| 2099 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2100 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2101 | LOG(FATAL) << "Unreachable"; |
| 2102 | UNREACHABLE(); |
| 2103 | } |
| 2104 | |
| 2105 | private: |
| 2106 | friend class SsaBuilder; |
| 2107 | }; |
| 2108 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2109 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2110 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2111 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2112 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2113 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2114 | virtual ~HExpression() {} |
| 2115 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2116 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2117 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2118 | protected: |
| 2119 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2120 | }; |
| 2121 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2122 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2123 | // instruction that branches to the exit block. |
| 2124 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2125 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2126 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2127 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2128 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2129 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2130 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2131 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2132 | |
| 2133 | private: |
| 2134 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2135 | }; |
| 2136 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2137 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2138 | // instruction that branches to the exit block. |
| 2139 | class HReturn : public HTemplateInstruction<1> { |
| 2140 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2141 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2142 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2143 | SetRawInputAt(0, value); |
| 2144 | } |
| 2145 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2146 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2147 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2148 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2149 | |
| 2150 | private: |
| 2151 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2152 | }; |
| 2153 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2154 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2155 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2156 | // exit block. |
| 2157 | class HExit : public HTemplateInstruction<0> { |
| 2158 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2159 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2160 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2161 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2162 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2163 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2164 | |
| 2165 | private: |
| 2166 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2167 | }; |
| 2168 | |
| 2169 | // Jumps from one block to another. |
| 2170 | class HGoto : public HTemplateInstruction<0> { |
| 2171 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2172 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2173 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2174 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2175 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2176 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2177 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2180 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | |
| 2182 | private: |
| 2183 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2184 | }; |
| 2185 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2186 | class HConstant : public HExpression<0> { |
| 2187 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2188 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2189 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2190 | |
| 2191 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2192 | |
| 2193 | virtual bool IsMinusOne() const { return false; } |
| 2194 | virtual bool IsZero() const { return false; } |
| 2195 | virtual bool IsOne() const { return false; } |
| 2196 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2197 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2198 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2199 | DECLARE_INSTRUCTION(Constant); |
| 2200 | |
| 2201 | private: |
| 2202 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2203 | }; |
| 2204 | |
| 2205 | class HNullConstant : public HConstant { |
| 2206 | public: |
| 2207 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2208 | return true; |
| 2209 | } |
| 2210 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2211 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2212 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2213 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2214 | |
| 2215 | DECLARE_INSTRUCTION(NullConstant); |
| 2216 | |
| 2217 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2218 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2219 | |
| 2220 | friend class HGraph; |
| 2221 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2222 | }; |
| 2223 | |
| 2224 | // Constants of the type int. Those can be from Dex instructions, or |
| 2225 | // synthesized (for example with the if-eqz instruction). |
| 2226 | class HIntConstant : public HConstant { |
| 2227 | public: |
| 2228 | int32_t GetValue() const { return value_; } |
| 2229 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2230 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2231 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2232 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2233 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2234 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2235 | DCHECK(other->IsIntConstant()); |
| 2236 | return other->AsIntConstant()->value_ == value_; |
| 2237 | } |
| 2238 | |
| 2239 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2240 | |
| 2241 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2242 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2243 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2244 | |
| 2245 | DECLARE_INSTRUCTION(IntConstant); |
| 2246 | |
| 2247 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2248 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2249 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2250 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2251 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2252 | |
| 2253 | const int32_t value_; |
| 2254 | |
| 2255 | friend class HGraph; |
| 2256 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2257 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2258 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2259 | }; |
| 2260 | |
| 2261 | class HLongConstant : public HConstant { |
| 2262 | public: |
| 2263 | int64_t GetValue() const { return value_; } |
| 2264 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2265 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2266 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2267 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2268 | DCHECK(other->IsLongConstant()); |
| 2269 | return other->AsLongConstant()->value_ == value_; |
| 2270 | } |
| 2271 | |
| 2272 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2273 | |
| 2274 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2275 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2276 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2277 | |
| 2278 | DECLARE_INSTRUCTION(LongConstant); |
| 2279 | |
| 2280 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2281 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2282 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2283 | |
| 2284 | const int64_t value_; |
| 2285 | |
| 2286 | friend class HGraph; |
| 2287 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2288 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2289 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2290 | // Conditional branch. A block ending with an HIf instruction must have |
| 2291 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2292 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2293 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2294 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2295 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2296 | SetRawInputAt(0, input); |
| 2297 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2298 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2299 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2300 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2301 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2302 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2303 | } |
| 2304 | |
| 2305 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2306 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2307 | } |
| 2308 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2309 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2310 | |
| 2311 | private: |
| 2312 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2313 | }; |
| 2314 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2315 | |
| 2316 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2317 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2318 | // non-exceptional control flow. |
| 2319 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2320 | // higher indices in no particular order. |
| 2321 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2322 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2323 | enum BoundaryKind { |
| 2324 | kEntry, |
| 2325 | kExit, |
| 2326 | }; |
| 2327 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2328 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2329 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2330 | |
| 2331 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2332 | |
| 2333 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2334 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2335 | |
| 2336 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2337 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2338 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2339 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2340 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2341 | } |
| 2342 | |
| 2343 | // If not present already, adds `handler` to its block's list of exception |
| 2344 | // handlers. |
| 2345 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2346 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2347 | GetBlock()->AddSuccessor(handler); |
| 2348 | } |
| 2349 | } |
| 2350 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2351 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2352 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2353 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2354 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2355 | DECLARE_INSTRUCTION(TryBoundary); |
| 2356 | |
| 2357 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2358 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2359 | |
| 2360 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2361 | }; |
| 2362 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2363 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2364 | // exceptional successors of its basic block. |
| 2365 | class HExceptionHandlerIterator : public ValueObject { |
| 2366 | public: |
| 2367 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2368 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2369 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2370 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2371 | HBasicBlock* Current() const { return block_.GetSuccessors()[index_]; } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2372 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2373 | void Advance() { ++index_; } |
| 2374 | |
| 2375 | private: |
| 2376 | const HBasicBlock& block_; |
| 2377 | size_t index_; |
| 2378 | |
| 2379 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2380 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2381 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2382 | // Deoptimize to interpreter, upon checking a condition. |
| 2383 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2384 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2385 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2386 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2387 | SetRawInputAt(0, cond); |
| 2388 | } |
| 2389 | |
| 2390 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2391 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2392 | |
| 2393 | DECLARE_INSTRUCTION(Deoptimize); |
| 2394 | |
| 2395 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2396 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2397 | }; |
| 2398 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2399 | // Represents the ArtMethod that was passed as a first argument to |
| 2400 | // the method. It is used by instructions that depend on it, like |
| 2401 | // instructions that work with the dex cache. |
| 2402 | class HCurrentMethod : public HExpression<0> { |
| 2403 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2404 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2405 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2406 | |
| 2407 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2408 | |
| 2409 | private: |
| 2410 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2411 | }; |
| 2412 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2413 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2414 | // have one successor for each entry in the switch table, and the final successor |
| 2415 | // will be the block containing the next Dex opcode. |
| 2416 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2417 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2418 | HPackedSwitch(int32_t start_value, |
| 2419 | uint32_t num_entries, |
| 2420 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2421 | uint32_t dex_pc = kNoDexPc) |
| 2422 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2423 | start_value_(start_value), |
| 2424 | num_entries_(num_entries) { |
| 2425 | SetRawInputAt(0, input); |
| 2426 | } |
| 2427 | |
| 2428 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2429 | |
| 2430 | int32_t GetStartValue() const { return start_value_; } |
| 2431 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2432 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2433 | |
| 2434 | HBasicBlock* GetDefaultBlock() const { |
| 2435 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2436 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2437 | } |
| 2438 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2439 | |
| 2440 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2441 | const int32_t start_value_; |
| 2442 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2443 | |
| 2444 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2445 | }; |
| 2446 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2447 | class HUnaryOperation : public HExpression<1> { |
| 2448 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2449 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2450 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2451 | SetRawInputAt(0, input); |
| 2452 | } |
| 2453 | |
| 2454 | HInstruction* GetInput() const { return InputAt(0); } |
| 2455 | Primitive::Type GetResultType() const { return GetType(); } |
| 2456 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2457 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2458 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2459 | UNUSED(other); |
| 2460 | return true; |
| 2461 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2462 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2463 | // Try to statically evaluate `operation` and return a HConstant |
| 2464 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2465 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2466 | HConstant* TryStaticEvaluation() const; |
| 2467 | |
| 2468 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2469 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2470 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2471 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2472 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2473 | |
| 2474 | private: |
| 2475 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2476 | }; |
| 2477 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2478 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2479 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2480 | HBinaryOperation(Primitive::Type result_type, |
| 2481 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2482 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2483 | SideEffects side_effects = SideEffects::None(), |
| 2484 | uint32_t dex_pc = kNoDexPc) |
| 2485 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2486 | SetRawInputAt(0, left); |
| 2487 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2488 | } |
| 2489 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2490 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2491 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2492 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2493 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2494 | virtual bool IsCommutative() const { return false; } |
| 2495 | |
| 2496 | // Put constant on the right. |
| 2497 | // Returns whether order is changed. |
| 2498 | bool OrderInputsWithConstantOnTheRight() { |
| 2499 | HInstruction* left = InputAt(0); |
| 2500 | HInstruction* right = InputAt(1); |
| 2501 | if (left->IsConstant() && !right->IsConstant()) { |
| 2502 | ReplaceInput(right, 0); |
| 2503 | ReplaceInput(left, 1); |
| 2504 | return true; |
| 2505 | } |
| 2506 | return false; |
| 2507 | } |
| 2508 | |
| 2509 | // Order inputs by instruction id, but favor constant on the right side. |
| 2510 | // This helps GVN for commutative ops. |
| 2511 | void OrderInputs() { |
| 2512 | DCHECK(IsCommutative()); |
| 2513 | HInstruction* left = InputAt(0); |
| 2514 | HInstruction* right = InputAt(1); |
| 2515 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2516 | return; |
| 2517 | } |
| 2518 | if (OrderInputsWithConstantOnTheRight()) { |
| 2519 | return; |
| 2520 | } |
| 2521 | // Order according to instruction id. |
| 2522 | if (left->GetId() > right->GetId()) { |
| 2523 | ReplaceInput(right, 0); |
| 2524 | ReplaceInput(left, 1); |
| 2525 | } |
| 2526 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2527 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2528 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2529 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2530 | UNUSED(other); |
| 2531 | return true; |
| 2532 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2533 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2534 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2535 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2536 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2537 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2538 | |
| 2539 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2540 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2541 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2542 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2543 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2544 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2545 | return nullptr; |
| 2546 | } |
| 2547 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2548 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2549 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2550 | return nullptr; |
| 2551 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2552 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2553 | // 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] | 2554 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2555 | HConstant* GetConstantRight() const; |
| 2556 | |
| 2557 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2558 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2559 | HInstruction* GetLeastConstantLeft() const; |
| 2560 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2561 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2562 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2563 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2564 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2565 | }; |
| 2566 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2567 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2568 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2569 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2570 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2571 | kGtBias, // return 1 for NaN comparisons |
| 2572 | kLtBias, // return -1 for NaN comparisons |
| 2573 | }; |
| 2574 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2575 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2576 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2577 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2578 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2579 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2580 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2581 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2582 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2583 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2584 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2585 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2586 | // `instruction`, and disregard moves in between. |
| 2587 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2588 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2589 | DECLARE_INSTRUCTION(Condition); |
| 2590 | |
| 2591 | virtual IfCondition GetCondition() const = 0; |
| 2592 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2593 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2594 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2595 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2596 | |
| 2597 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2598 | |
| 2599 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2600 | return bias_ == other->AsCondition()->bias_; |
| 2601 | } |
| 2602 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2603 | bool IsFPConditionTrueIfNaN() const { |
| 2604 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2605 | IfCondition if_cond = GetCondition(); |
| 2606 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2607 | } |
| 2608 | |
| 2609 | bool IsFPConditionFalseIfNaN() const { |
| 2610 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2611 | IfCondition if_cond = GetCondition(); |
| 2612 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2613 | } |
| 2614 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2615 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2616 | // For register allocation purposes, returns whether this instruction needs to be |
| 2617 | // materialized (that is, not just be in the processor flags). |
| 2618 | bool needs_materialization_; |
| 2619 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2620 | // Needed if we merge a HCompare into a HCondition. |
| 2621 | ComparisonBias bias_; |
| 2622 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2623 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2624 | }; |
| 2625 | |
| 2626 | // Instruction to check if two inputs are equal to each other. |
| 2627 | class HEqual : public HCondition { |
| 2628 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2629 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2630 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2631 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2632 | bool IsCommutative() const OVERRIDE { return true; } |
| 2633 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2634 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2635 | |
| 2636 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2637 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2638 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2639 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2640 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2641 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2642 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2643 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2644 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2645 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2646 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2647 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2648 | return kCondEQ; |
| 2649 | } |
| 2650 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2651 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2652 | return kCondNE; |
| 2653 | } |
| 2654 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2655 | private: |
| 2656 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2657 | }; |
| 2658 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2659 | class HNotEqual : public HCondition { |
| 2660 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2661 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2662 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2663 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2664 | bool IsCommutative() const OVERRIDE { return true; } |
| 2665 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2666 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2667 | |
| 2668 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2669 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2670 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2671 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2672 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2673 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2674 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2675 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2676 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2677 | DECLARE_INSTRUCTION(NotEqual); |
| 2678 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2679 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2680 | return kCondNE; |
| 2681 | } |
| 2682 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2683 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2684 | return kCondEQ; |
| 2685 | } |
| 2686 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2687 | private: |
| 2688 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2689 | }; |
| 2690 | |
| 2691 | class HLessThan : public HCondition { |
| 2692 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2693 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2694 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2695 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2696 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2697 | |
| 2698 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2699 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2700 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2701 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2702 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2703 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2704 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2705 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2706 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2707 | DECLARE_INSTRUCTION(LessThan); |
| 2708 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2709 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2710 | return kCondLT; |
| 2711 | } |
| 2712 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2713 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2714 | return kCondGE; |
| 2715 | } |
| 2716 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2717 | private: |
| 2718 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2719 | }; |
| 2720 | |
| 2721 | class HLessThanOrEqual : public HCondition { |
| 2722 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2723 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2724 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2725 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2726 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2727 | |
| 2728 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2729 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2730 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2731 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2732 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2733 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2734 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2735 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2736 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2737 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2738 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2739 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2740 | return kCondLE; |
| 2741 | } |
| 2742 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2743 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2744 | return kCondGT; |
| 2745 | } |
| 2746 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2747 | private: |
| 2748 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2749 | }; |
| 2750 | |
| 2751 | class HGreaterThan : public HCondition { |
| 2752 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2753 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2754 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2755 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2756 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2757 | |
| 2758 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2759 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2760 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2761 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2762 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2763 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2764 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2765 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2766 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2767 | DECLARE_INSTRUCTION(GreaterThan); |
| 2768 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2769 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2770 | return kCondGT; |
| 2771 | } |
| 2772 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2773 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2774 | return kCondLE; |
| 2775 | } |
| 2776 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2777 | private: |
| 2778 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2779 | }; |
| 2780 | |
| 2781 | class HGreaterThanOrEqual : public HCondition { |
| 2782 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2783 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2784 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2785 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2786 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2787 | |
| 2788 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2789 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2790 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2791 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2792 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2793 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2794 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2795 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2796 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2797 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2798 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2799 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2800 | return kCondGE; |
| 2801 | } |
| 2802 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2803 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2804 | return kCondLT; |
| 2805 | } |
| 2806 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2807 | private: |
| 2808 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2809 | }; |
| 2810 | |
| 2811 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2812 | // Instruction to check how two inputs compare to each other. |
| 2813 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2814 | class HCompare : public HBinaryOperation { |
| 2815 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2816 | HCompare(Primitive::Type type, |
| 2817 | HInstruction* first, |
| 2818 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2819 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2820 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2821 | : HBinaryOperation(Primitive::kPrimInt, |
| 2822 | first, |
| 2823 | second, |
| 2824 | SideEffectsForArchRuntimeCalls(type), |
| 2825 | dex_pc), |
| 2826 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2827 | DCHECK_EQ(type, first->GetType()); |
| 2828 | DCHECK_EQ(type, second->GetType()); |
| 2829 | } |
| 2830 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2831 | template <typename T> |
| 2832 | 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] | 2833 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2834 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2835 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2836 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2837 | } |
| 2838 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2839 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2840 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2841 | } |
| 2842 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2843 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2844 | return bias_ == other->AsCompare()->bias_; |
| 2845 | } |
| 2846 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2847 | ComparisonBias GetBias() const { return bias_; } |
| 2848 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2849 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2850 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2851 | |
| 2852 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 2853 | // MIPS64 uses a runtime call for FP comparisons. |
| 2854 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 2855 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2856 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2857 | DECLARE_INSTRUCTION(Compare); |
| 2858 | |
| 2859 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2860 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 2861 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2862 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 2863 | }; |
| 2864 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2865 | // A local in the graph. Corresponds to a Dex register. |
| 2866 | class HLocal : public HTemplateInstruction<0> { |
| 2867 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2868 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2869 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2870 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2871 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2872 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2873 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2874 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2875 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2876 | // The Dex register number. |
| 2877 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2878 | |
| 2879 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 2880 | }; |
| 2881 | |
| 2882 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2883 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2884 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2885 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2886 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2887 | SetRawInputAt(0, local); |
| 2888 | } |
| 2889 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2890 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2891 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2892 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2893 | |
| 2894 | private: |
| 2895 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 2896 | }; |
| 2897 | |
| 2898 | // Store a value in a given local. This instruction has two inputs: the value |
| 2899 | // and the local. |
| 2900 | class HStoreLocal : public HTemplateInstruction<2> { |
| 2901 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2902 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2903 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2904 | SetRawInputAt(0, local); |
| 2905 | SetRawInputAt(1, value); |
| 2906 | } |
| 2907 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2908 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 2909 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2910 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2911 | |
| 2912 | private: |
| 2913 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 2914 | }; |
| 2915 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2916 | class HFloatConstant : public HConstant { |
| 2917 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2918 | float GetValue() const { return value_; } |
| 2919 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2920 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2921 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 2922 | } |
| 2923 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2924 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2925 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2926 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2927 | } |
| 2928 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2929 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2930 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2931 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2932 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>((-1.0f)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2933 | } |
| 2934 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2935 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2936 | } |
| 2937 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2938 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 2939 | } |
| 2940 | bool IsNaN() const { |
| 2941 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2942 | } |
| 2943 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2944 | DECLARE_INSTRUCTION(FloatConstant); |
| 2945 | |
| 2946 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2947 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 2948 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 2949 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2950 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2951 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2952 | const float value_; |
| 2953 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2954 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2955 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2956 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2957 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 2958 | }; |
| 2959 | |
| 2960 | class HDoubleConstant : public HConstant { |
| 2961 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2962 | double GetValue() const { return value_; } |
| 2963 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2964 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 2965 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2966 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2967 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2968 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2969 | } |
| 2970 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2971 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2972 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2973 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2974 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>((-1.0)); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2975 | } |
| 2976 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2977 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2978 | } |
| 2979 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 2980 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 2981 | } |
| 2982 | bool IsNaN() const { |
| 2983 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2984 | } |
| 2985 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2986 | DECLARE_INSTRUCTION(DoubleConstant); |
| 2987 | |
| 2988 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2989 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 2990 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 2991 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2992 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2993 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2994 | const double value_; |
| 2995 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2996 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 2997 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 2998 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2999 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3000 | }; |
| 3001 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3002 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3003 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3004 | #include "intrinsics_list.h" |
| 3005 | kNone, |
| 3006 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3007 | #undef INTRINSICS_LIST |
| 3008 | #undef OPTIMIZING_INTRINSICS |
| 3009 | }; |
| 3010 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3011 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3012 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3013 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3014 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3015 | }; |
| 3016 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3017 | class HInvoke : public HInstruction { |
| 3018 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3019 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3020 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3021 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3022 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3023 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3024 | SetRawInputAt(index, argument); |
| 3025 | } |
| 3026 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3027 | // Return the number of arguments. This number can be lower than |
| 3028 | // the number of inputs returned by InputCount(), as some invoke |
| 3029 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3030 | // inputs at the end of their list of inputs. |
| 3031 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3032 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3033 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3034 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3035 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3036 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3037 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3038 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3039 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3040 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3041 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3042 | return intrinsic_; |
| 3043 | } |
| 3044 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3045 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3046 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3047 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3048 | return GetEnvironment()->GetParent() != nullptr; |
| 3049 | } |
| 3050 | |
| 3051 | bool CanThrow() const OVERRIDE { return true; } |
| 3052 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3053 | uint32_t* GetIntrinsicOptimizations() { |
| 3054 | return &intrinsic_optimizations_; |
| 3055 | } |
| 3056 | |
| 3057 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3058 | return &intrinsic_optimizations_; |
| 3059 | } |
| 3060 | |
| 3061 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3062 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3063 | DECLARE_INSTRUCTION(Invoke); |
| 3064 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3065 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3066 | HInvoke(ArenaAllocator* arena, |
| 3067 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3068 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3069 | Primitive::Type return_type, |
| 3070 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3071 | uint32_t dex_method_index, |
| 3072 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3073 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3074 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3075 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3076 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3077 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3078 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3079 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3080 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3081 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3082 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3083 | } |
| 3084 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3085 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3086 | return inputs_[index]; |
| 3087 | } |
| 3088 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3089 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3090 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3091 | } |
| 3092 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3093 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3094 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3095 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3096 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3097 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3098 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3099 | |
| 3100 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3101 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3102 | |
| 3103 | private: |
| 3104 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3105 | }; |
| 3106 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3107 | class HInvokeUnresolved : public HInvoke { |
| 3108 | public: |
| 3109 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3110 | uint32_t number_of_arguments, |
| 3111 | Primitive::Type return_type, |
| 3112 | uint32_t dex_pc, |
| 3113 | uint32_t dex_method_index, |
| 3114 | InvokeType invoke_type) |
| 3115 | : HInvoke(arena, |
| 3116 | number_of_arguments, |
| 3117 | 0u /* number_of_other_inputs */, |
| 3118 | return_type, |
| 3119 | dex_pc, |
| 3120 | dex_method_index, |
| 3121 | invoke_type) { |
| 3122 | } |
| 3123 | |
| 3124 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3125 | |
| 3126 | private: |
| 3127 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3128 | }; |
| 3129 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3130 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3131 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3132 | // Requirements of this method call regarding the class |
| 3133 | // initialization (clinit) check of its declaring class. |
| 3134 | enum class ClinitCheckRequirement { |
| 3135 | kNone, // Class already initialized. |
| 3136 | kExplicit, // Static call having explicit clinit check as last input. |
| 3137 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3138 | }; |
| 3139 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3140 | // Determines how to load the target ArtMethod*. |
| 3141 | enum class MethodLoadKind { |
| 3142 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3143 | kStringInit, |
| 3144 | |
| 3145 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3146 | kRecursive, |
| 3147 | |
| 3148 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3149 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3150 | kDirectAddress, |
| 3151 | |
| 3152 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3153 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3154 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3155 | // the image relocatable or not. |
| 3156 | kDirectAddressWithFixup, |
| 3157 | |
| 3158 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3159 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3160 | // may cause class initialization (the entry may point to a resolution method), |
| 3161 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3162 | kDexCachePcRelative, |
| 3163 | |
| 3164 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3165 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3166 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3167 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3168 | kDexCacheViaMethod, |
| 3169 | }; |
| 3170 | |
| 3171 | // Determines the location of the code pointer. |
| 3172 | enum class CodePtrLocation { |
| 3173 | // Recursive call, use local PC-relative call instruction. |
| 3174 | kCallSelf, |
| 3175 | |
| 3176 | // Use PC-relative call instruction patched at link time. |
| 3177 | // Used for calls within an oat file, boot->boot or app->app. |
| 3178 | kCallPCRelative, |
| 3179 | |
| 3180 | // Call to a known target address, embed the direct address in code. |
| 3181 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3182 | kCallDirect, |
| 3183 | |
| 3184 | // Call to a target address that will be known at link time, embed the direct |
| 3185 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3186 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3187 | // the image relocatable or not. |
| 3188 | kCallDirectWithFixup, |
| 3189 | |
| 3190 | // Use code pointer from the ArtMethod*. |
| 3191 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3192 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3193 | kCallArtMethod, |
| 3194 | }; |
| 3195 | |
| 3196 | struct DispatchInfo { |
| 3197 | const MethodLoadKind method_load_kind; |
| 3198 | const CodePtrLocation code_ptr_location; |
| 3199 | // The method load data holds |
| 3200 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3201 | // Note that there are multiple string init methods, each having its own offset. |
| 3202 | // - the method address for kDirectAddress |
| 3203 | // - the dex cache arrays offset for kDexCachePcRel. |
| 3204 | const uint64_t method_load_data; |
| 3205 | const uint64_t direct_code_ptr; |
| 3206 | }; |
| 3207 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3208 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3209 | uint32_t number_of_arguments, |
| 3210 | Primitive::Type return_type, |
| 3211 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3212 | uint32_t method_index, |
| 3213 | MethodReference target_method, |
| 3214 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3215 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3216 | InvokeType invoke_type, |
| 3217 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3218 | : HInvoke(arena, |
| 3219 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3220 | // There is one extra argument for the HCurrentMethod node, and |
| 3221 | // potentially one other if the clinit check is explicit, and one other |
| 3222 | // if the method is a string factory. |
| 3223 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3224 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3225 | return_type, |
| 3226 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3227 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3228 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3229 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3230 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3231 | target_method_(target_method), |
| 3232 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3233 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3234 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 3235 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3236 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3237 | // TODO: for intrinsics we can generate implicit null checks. |
| 3238 | return false; |
| 3239 | } |
| 3240 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3241 | bool CanBeNull() const OVERRIDE { |
| 3242 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3243 | } |
| 3244 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3245 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3246 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3247 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3248 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3249 | bool NeedsDexCache() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3250 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3251 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3252 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
| 3253 | bool HasPcRelDexCache() const { return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; } |
| 3254 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3255 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3256 | |
| 3257 | int32_t GetStringInitOffset() const { |
| 3258 | DCHECK(IsStringInit()); |
| 3259 | return dispatch_info_.method_load_data; |
| 3260 | } |
| 3261 | |
| 3262 | uint64_t GetMethodAddress() const { |
| 3263 | DCHECK(HasMethodAddress()); |
| 3264 | return dispatch_info_.method_load_data; |
| 3265 | } |
| 3266 | |
| 3267 | uint32_t GetDexCacheArrayOffset() const { |
| 3268 | DCHECK(HasPcRelDexCache()); |
| 3269 | return dispatch_info_.method_load_data; |
| 3270 | } |
| 3271 | |
| 3272 | uint64_t GetDirectCodePtr() const { |
| 3273 | DCHECK(HasDirectCodePtr()); |
| 3274 | return dispatch_info_.direct_code_ptr; |
| 3275 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3276 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3277 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3278 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3279 | // Is this instruction a call to a static method? |
| 3280 | bool IsStatic() const { |
| 3281 | return GetInvokeType() == kStatic; |
| 3282 | } |
| 3283 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3284 | // Remove the art::HLoadClass instruction set as last input by |
| 3285 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3286 | // the initial art::HClinitCheck instruction (only relevant for |
| 3287 | // static calls with explicit clinit check). |
| 3288 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3289 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3290 | size_t last_input_index = InputCount() - 1; |
| 3291 | HInstruction* last_input = InputAt(last_input_index); |
| 3292 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3293 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3294 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3295 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3296 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3297 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3298 | } |
| 3299 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3300 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3301 | if (!IsStringInit()) return false; |
| 3302 | // +1 for the current method. |
| 3303 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3304 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3305 | } |
| 3306 | |
| 3307 | void RemoveFakeStringArgumentAsLastInput() { |
| 3308 | DCHECK(IsStringInit()); |
| 3309 | size_t last_input_index = InputCount() - 1; |
| 3310 | HInstruction* last_input = InputAt(last_input_index); |
| 3311 | DCHECK(last_input != nullptr); |
| 3312 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3313 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3314 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3315 | } |
| 3316 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3317 | // Is this a call to a static method whose declaring class has an |
| 3318 | // explicit intialization check in the graph? |
| 3319 | bool IsStaticWithExplicitClinitCheck() const { |
| 3320 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3321 | } |
| 3322 | |
| 3323 | // Is this a call to a static method whose declaring class has an |
| 3324 | // implicit intialization check requirement? |
| 3325 | bool IsStaticWithImplicitClinitCheck() const { |
| 3326 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3327 | } |
| 3328 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3329 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3330 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3331 | protected: |
| 3332 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3333 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3334 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3335 | HInstruction* input = input_record.GetInstruction(); |
| 3336 | // `input` is the last input of a static invoke marked as having |
| 3337 | // an explicit clinit check. It must either be: |
| 3338 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3339 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3340 | DCHECK(input != nullptr); |
| 3341 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3342 | } |
| 3343 | return input_record; |
| 3344 | } |
| 3345 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3346 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3347 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3348 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3349 | // The target method may refer to different dex file or method index than the original |
| 3350 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3351 | // in derived class to increase visibility. |
| 3352 | MethodReference target_method_; |
| 3353 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3354 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3355 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3356 | }; |
| 3357 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3358 | class HInvokeVirtual : public HInvoke { |
| 3359 | public: |
| 3360 | HInvokeVirtual(ArenaAllocator* arena, |
| 3361 | uint32_t number_of_arguments, |
| 3362 | Primitive::Type return_type, |
| 3363 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3364 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3365 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3366 | : 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] | 3367 | vtable_index_(vtable_index) {} |
| 3368 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3369 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3370 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3371 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3372 | } |
| 3373 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3374 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3375 | |
| 3376 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3377 | |
| 3378 | private: |
| 3379 | const uint32_t vtable_index_; |
| 3380 | |
| 3381 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3382 | }; |
| 3383 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3384 | class HInvokeInterface : public HInvoke { |
| 3385 | public: |
| 3386 | HInvokeInterface(ArenaAllocator* arena, |
| 3387 | uint32_t number_of_arguments, |
| 3388 | Primitive::Type return_type, |
| 3389 | uint32_t dex_pc, |
| 3390 | uint32_t dex_method_index, |
| 3391 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3392 | : 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] | 3393 | imt_index_(imt_index) {} |
| 3394 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3395 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3396 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3397 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3398 | } |
| 3399 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3400 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3401 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3402 | |
| 3403 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3404 | |
| 3405 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3406 | const uint32_t imt_index_; |
| 3407 | |
| 3408 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3409 | }; |
| 3410 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3411 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3412 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3413 | HNewInstance(HCurrentMethod* current_method, |
| 3414 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3415 | uint16_t type_index, |
| 3416 | const DexFile& dex_file, |
| 3417 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3418 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3419 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3420 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3421 | entrypoint_(entrypoint) { |
| 3422 | SetRawInputAt(0, current_method); |
| 3423 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3424 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3425 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3426 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3427 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3428 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3429 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3430 | // It may throw when called on: |
| 3431 | // - interfaces |
| 3432 | // - abstract/innaccessible/unknown classes |
| 3433 | // TODO: optimize when possible. |
| 3434 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3435 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3436 | bool CanBeNull() const OVERRIDE { return false; } |
| 3437 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3438 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3439 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3440 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3441 | |
| 3442 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3443 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3444 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3445 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3446 | |
| 3447 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3448 | }; |
| 3449 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3450 | class HNeg : public HUnaryOperation { |
| 3451 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3452 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3453 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3454 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3455 | template <typename T> T Compute(T x) const { return -x; } |
| 3456 | |
| 3457 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3458 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3459 | } |
| 3460 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3461 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3462 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3463 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3464 | DECLARE_INSTRUCTION(Neg); |
| 3465 | |
| 3466 | private: |
| 3467 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3468 | }; |
| 3469 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3470 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3471 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3472 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3473 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3474 | uint32_t dex_pc, |
| 3475 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3476 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3477 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3478 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3479 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3480 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3481 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3482 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3483 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3484 | } |
| 3485 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3486 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3487 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3488 | |
| 3489 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3490 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3491 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3492 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3493 | bool CanThrow() const OVERRIDE { return true; } |
| 3494 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3495 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3496 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3497 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3498 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3499 | DECLARE_INSTRUCTION(NewArray); |
| 3500 | |
| 3501 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3502 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3503 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3504 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3505 | |
| 3506 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3507 | }; |
| 3508 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3509 | class HAdd : public HBinaryOperation { |
| 3510 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3511 | HAdd(Primitive::Type result_type, |
| 3512 | HInstruction* left, |
| 3513 | HInstruction* right, |
| 3514 | uint32_t dex_pc = kNoDexPc) |
| 3515 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3516 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3517 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3518 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3519 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3520 | |
| 3521 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3522 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3523 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3524 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3525 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3526 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3527 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3528 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3529 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3530 | DECLARE_INSTRUCTION(Add); |
| 3531 | |
| 3532 | private: |
| 3533 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3534 | }; |
| 3535 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3536 | class HSub : public HBinaryOperation { |
| 3537 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3538 | HSub(Primitive::Type result_type, |
| 3539 | HInstruction* left, |
| 3540 | HInstruction* right, |
| 3541 | uint32_t dex_pc = kNoDexPc) |
| 3542 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3543 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3544 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3545 | |
| 3546 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3547 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3548 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3549 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3550 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3551 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3552 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3553 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3554 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3555 | DECLARE_INSTRUCTION(Sub); |
| 3556 | |
| 3557 | private: |
| 3558 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3559 | }; |
| 3560 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3561 | class HMul : public HBinaryOperation { |
| 3562 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3563 | HMul(Primitive::Type result_type, |
| 3564 | HInstruction* left, |
| 3565 | HInstruction* right, |
| 3566 | uint32_t dex_pc = kNoDexPc) |
| 3567 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3568 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3569 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3570 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3571 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3572 | |
| 3573 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3574 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3575 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3576 | } |
| 3577 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3578 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3579 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3580 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3581 | |
| 3582 | DECLARE_INSTRUCTION(Mul); |
| 3583 | |
| 3584 | private: |
| 3585 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3586 | }; |
| 3587 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3588 | class HDiv : public HBinaryOperation { |
| 3589 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3590 | HDiv(Primitive::Type result_type, |
| 3591 | HInstruction* left, |
| 3592 | HInstruction* right, |
| 3593 | uint32_t dex_pc) |
| 3594 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3595 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3596 | template <typename T> |
| 3597 | T Compute(T x, T y) const { |
| 3598 | // Our graph structure ensures we never have 0 for `y` during |
| 3599 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3600 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3601 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3602 | return (y == -1) ? -x : x / y; |
| 3603 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3604 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3605 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3606 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3607 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3608 | } |
| 3609 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3610 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3611 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3612 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3613 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3614 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3615 | // The generated code can use a runtime call. |
| 3616 | return SideEffects::CanTriggerGC(); |
| 3617 | } |
| 3618 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3619 | DECLARE_INSTRUCTION(Div); |
| 3620 | |
| 3621 | private: |
| 3622 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3623 | }; |
| 3624 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3625 | class HRem : public HBinaryOperation { |
| 3626 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3627 | HRem(Primitive::Type result_type, |
| 3628 | HInstruction* left, |
| 3629 | HInstruction* right, |
| 3630 | uint32_t dex_pc) |
| 3631 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3632 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3633 | template <typename T> |
| 3634 | T Compute(T x, T y) const { |
| 3635 | // Our graph structure ensures we never have 0 for `y` during |
| 3636 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3637 | DCHECK_NE(y, 0); |
| 3638 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3639 | return (y == -1) ? 0 : x % y; |
| 3640 | } |
| 3641 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3642 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3643 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3644 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3645 | } |
| 3646 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3647 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3648 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3649 | } |
| 3650 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3651 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3652 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3653 | return SideEffects::CanTriggerGC(); |
| 3654 | } |
| 3655 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3656 | DECLARE_INSTRUCTION(Rem); |
| 3657 | |
| 3658 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3659 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3660 | }; |
| 3661 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3662 | class HDivZeroCheck : public HExpression<1> { |
| 3663 | public: |
| 3664 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3665 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3666 | SetRawInputAt(0, value); |
| 3667 | } |
| 3668 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3669 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3670 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3671 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3672 | |
| 3673 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3674 | UNUSED(other); |
| 3675 | return true; |
| 3676 | } |
| 3677 | |
| 3678 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3679 | bool CanThrow() const OVERRIDE { return true; } |
| 3680 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3681 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3682 | |
| 3683 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3684 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3685 | }; |
| 3686 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3687 | class HShl : public HBinaryOperation { |
| 3688 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3689 | HShl(Primitive::Type result_type, |
| 3690 | HInstruction* left, |
| 3691 | HInstruction* right, |
| 3692 | uint32_t dex_pc = kNoDexPc) |
| 3693 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3694 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3695 | template <typename T, typename U, typename V> |
| 3696 | T Compute(T x, U y, V max_shift_value) const { |
| 3697 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3698 | "V is not the unsigned integer type corresponding to T"); |
| 3699 | return x << (y & max_shift_value); |
| 3700 | } |
| 3701 | |
| 3702 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3703 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3704 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3705 | } |
| 3706 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3707 | // case is handled as `x << static_cast<int>(y)`. |
| 3708 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3709 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3710 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3711 | } |
| 3712 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3713 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3714 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3715 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3716 | |
| 3717 | DECLARE_INSTRUCTION(Shl); |
| 3718 | |
| 3719 | private: |
| 3720 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3721 | }; |
| 3722 | |
| 3723 | class HShr : public HBinaryOperation { |
| 3724 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3725 | HShr(Primitive::Type result_type, |
| 3726 | HInstruction* left, |
| 3727 | HInstruction* right, |
| 3728 | uint32_t dex_pc = kNoDexPc) |
| 3729 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3730 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3731 | template <typename T, typename U, typename V> |
| 3732 | T Compute(T x, U y, V max_shift_value) const { |
| 3733 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3734 | "V is not the unsigned integer type corresponding to T"); |
| 3735 | return x >> (y & max_shift_value); |
| 3736 | } |
| 3737 | |
| 3738 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3739 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3740 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3741 | } |
| 3742 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3743 | // case is handled as `x >> static_cast<int>(y)`. |
| 3744 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3745 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3746 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3747 | } |
| 3748 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3749 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3750 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3751 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3752 | |
| 3753 | DECLARE_INSTRUCTION(Shr); |
| 3754 | |
| 3755 | private: |
| 3756 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3757 | }; |
| 3758 | |
| 3759 | class HUShr : public HBinaryOperation { |
| 3760 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3761 | HUShr(Primitive::Type result_type, |
| 3762 | HInstruction* left, |
| 3763 | HInstruction* right, |
| 3764 | uint32_t dex_pc = kNoDexPc) |
| 3765 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3766 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3767 | template <typename T, typename U, typename V> |
| 3768 | T Compute(T x, U y, V max_shift_value) const { |
| 3769 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3770 | "V is not the unsigned integer type corresponding to T"); |
| 3771 | V ux = static_cast<V>(x); |
| 3772 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3773 | } |
| 3774 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3775 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3776 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3777 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3778 | } |
| 3779 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3780 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3781 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3782 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3783 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3784 | } |
| 3785 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3786 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3787 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3788 | } |
| 3789 | |
| 3790 | DECLARE_INSTRUCTION(UShr); |
| 3791 | |
| 3792 | private: |
| 3793 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3794 | }; |
| 3795 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3796 | class HAnd : public HBinaryOperation { |
| 3797 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3798 | HAnd(Primitive::Type result_type, |
| 3799 | HInstruction* left, |
| 3800 | HInstruction* right, |
| 3801 | uint32_t dex_pc = kNoDexPc) |
| 3802 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3803 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3804 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3805 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3806 | template <typename T, typename U> |
| 3807 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3808 | |
| 3809 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3810 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3811 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3812 | } |
| 3813 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3814 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3815 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3816 | } |
| 3817 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3818 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3819 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3820 | } |
| 3821 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3822 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3823 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3824 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3825 | |
| 3826 | DECLARE_INSTRUCTION(And); |
| 3827 | |
| 3828 | private: |
| 3829 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 3830 | }; |
| 3831 | |
| 3832 | class HOr : public HBinaryOperation { |
| 3833 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3834 | HOr(Primitive::Type result_type, |
| 3835 | HInstruction* left, |
| 3836 | HInstruction* right, |
| 3837 | uint32_t dex_pc = kNoDexPc) |
| 3838 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3839 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3840 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3841 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3842 | template <typename T, typename U> |
| 3843 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 3844 | |
| 3845 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3846 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3847 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3848 | } |
| 3849 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3850 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3851 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3852 | } |
| 3853 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3854 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3855 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3856 | } |
| 3857 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3858 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3859 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3860 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3861 | |
| 3862 | DECLARE_INSTRUCTION(Or); |
| 3863 | |
| 3864 | private: |
| 3865 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 3866 | }; |
| 3867 | |
| 3868 | class HXor : public HBinaryOperation { |
| 3869 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3870 | HXor(Primitive::Type result_type, |
| 3871 | HInstruction* left, |
| 3872 | HInstruction* right, |
| 3873 | uint32_t dex_pc = kNoDexPc) |
| 3874 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3875 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3876 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3877 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3878 | template <typename T, typename U> |
| 3879 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 3880 | |
| 3881 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3882 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3883 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3884 | } |
| 3885 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3886 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3887 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3888 | } |
| 3889 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3890 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3891 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3892 | } |
| 3893 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3894 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3895 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3896 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3897 | |
| 3898 | DECLARE_INSTRUCTION(Xor); |
| 3899 | |
| 3900 | private: |
| 3901 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 3902 | }; |
| 3903 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3904 | // The value of a parameter in this method. Its location depends on |
| 3905 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3906 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3907 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3908 | HParameterValue(uint8_t index, |
| 3909 | Primitive::Type parameter_type, |
| 3910 | bool is_this = false) |
| 3911 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3912 | index_(index), |
| 3913 | is_this_(is_this), |
| 3914 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3915 | |
| 3916 | uint8_t GetIndex() const { return index_; } |
| 3917 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3918 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 3919 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3920 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 3921 | bool IsThis() const { return is_this_; } |
| 3922 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3923 | DECLARE_INSTRUCTION(ParameterValue); |
| 3924 | |
| 3925 | private: |
| 3926 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3927 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3928 | const uint8_t index_; |
| 3929 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3930 | // Whether or not the parameter value corresponds to 'this' argument. |
| 3931 | const bool is_this_; |
| 3932 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 3933 | bool can_be_null_; |
| 3934 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3935 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 3936 | }; |
| 3937 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3938 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3939 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3940 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3941 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3942 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3943 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3944 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 3945 | UNUSED(other); |
| 3946 | return true; |
| 3947 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3948 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3949 | template <typename T> T Compute(T x) const { return ~x; } |
| 3950 | |
| 3951 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3952 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3953 | } |
| 3954 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3955 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3956 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 3957 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 3958 | DECLARE_INSTRUCTION(Not); |
| 3959 | |
| 3960 | private: |
| 3961 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 3962 | }; |
| 3963 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3964 | class HBooleanNot : public HUnaryOperation { |
| 3965 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3966 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3967 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3968 | |
| 3969 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3970 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3971 | UNUSED(other); |
| 3972 | return true; |
| 3973 | } |
| 3974 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3975 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3976 | DCHECK(IsUint<1>(x)); |
| 3977 | return !x; |
| 3978 | } |
| 3979 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3980 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3981 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3982 | } |
| 3983 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 3984 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 3985 | UNREACHABLE(); |
| 3986 | } |
| 3987 | |
| 3988 | DECLARE_INSTRUCTION(BooleanNot); |
| 3989 | |
| 3990 | private: |
| 3991 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 3992 | }; |
| 3993 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 3994 | class HTypeConversion : public HExpression<1> { |
| 3995 | public: |
| 3996 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 3997 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3998 | : HExpression(result_type, |
| 3999 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4000 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4001 | SetRawInputAt(0, input); |
| 4002 | DCHECK_NE(input->GetType(), result_type); |
| 4003 | } |
| 4004 | |
| 4005 | HInstruction* GetInput() const { return InputAt(0); } |
| 4006 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4007 | Primitive::Type GetResultType() const { return GetType(); } |
| 4008 | |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4009 | // Required by the x86 and ARM code generators when producing calls |
| 4010 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4011 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4012 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4013 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4014 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4015 | // Try to statically evaluate the conversion and return a HConstant |
| 4016 | // containing the result. If the input cannot be converted, return nullptr. |
| 4017 | HConstant* TryStaticEvaluation() const; |
| 4018 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4019 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4020 | Primitive::Type result_type) { |
| 4021 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4022 | // in the compilation process we do not know what architecture we will |
| 4023 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4024 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4025 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4026 | return SideEffects::CanTriggerGC(); |
| 4027 | } |
| 4028 | return SideEffects::None(); |
| 4029 | } |
| 4030 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4031 | DECLARE_INSTRUCTION(TypeConversion); |
| 4032 | |
| 4033 | private: |
| 4034 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4035 | }; |
| 4036 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4037 | static constexpr uint32_t kNoRegNumber = -1; |
| 4038 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4039 | class HPhi : public HInstruction { |
| 4040 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4041 | HPhi(ArenaAllocator* arena, |
| 4042 | uint32_t reg_number, |
| 4043 | size_t number_of_inputs, |
| 4044 | Primitive::Type type, |
| 4045 | uint32_t dex_pc = kNoDexPc) |
| 4046 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4047 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4048 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4049 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4050 | is_live_(false), |
| 4051 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4052 | } |
| 4053 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4054 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4055 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4056 | switch (type) { |
| 4057 | case Primitive::kPrimBoolean: |
| 4058 | case Primitive::kPrimByte: |
| 4059 | case Primitive::kPrimShort: |
| 4060 | case Primitive::kPrimChar: |
| 4061 | return Primitive::kPrimInt; |
| 4062 | default: |
| 4063 | return type; |
| 4064 | } |
| 4065 | } |
| 4066 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4067 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4068 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4069 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4070 | |
| 4071 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4072 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4073 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4074 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4075 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4076 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4077 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4078 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4079 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4080 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4081 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4082 | void SetDead() { is_live_ = false; } |
| 4083 | void SetLive() { is_live_ = true; } |
| 4084 | bool IsDead() const { return !is_live_; } |
| 4085 | bool IsLive() const { return is_live_; } |
| 4086 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4087 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4088 | return other != nullptr |
| 4089 | && other->IsPhi() |
| 4090 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4091 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4092 | } |
| 4093 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4094 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4095 | // An equivalent phi is a phi having the same dex register and type. |
| 4096 | // It assumes that phis with the same dex register are adjacent. |
| 4097 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4098 | HInstruction* next = GetNext(); |
| 4099 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4100 | if (next->GetType() == GetType()) { |
| 4101 | return next->AsPhi(); |
| 4102 | } |
| 4103 | next = next->GetNext(); |
| 4104 | } |
| 4105 | return nullptr; |
| 4106 | } |
| 4107 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4108 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4109 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4110 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4111 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4112 | return inputs_[index]; |
| 4113 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4114 | |
| 4115 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4116 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4117 | } |
| 4118 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4119 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4120 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4121 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4122 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4123 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4124 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4125 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4126 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4127 | }; |
| 4128 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4129 | class HNullCheck : public HExpression<1> { |
| 4130 | public: |
| 4131 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4132 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4133 | SetRawInputAt(0, value); |
| 4134 | } |
| 4135 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4136 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4137 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4138 | UNUSED(other); |
| 4139 | return true; |
| 4140 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4141 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4142 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4143 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4144 | bool CanThrow() const OVERRIDE { return true; } |
| 4145 | |
| 4146 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4147 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4148 | |
| 4149 | DECLARE_INSTRUCTION(NullCheck); |
| 4150 | |
| 4151 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4152 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4153 | }; |
| 4154 | |
| 4155 | class FieldInfo : public ValueObject { |
| 4156 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4157 | FieldInfo(MemberOffset field_offset, |
| 4158 | Primitive::Type field_type, |
| 4159 | bool is_volatile, |
| 4160 | uint32_t index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4161 | const DexFile& dex_file, |
| 4162 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4163 | : field_offset_(field_offset), |
| 4164 | field_type_(field_type), |
| 4165 | is_volatile_(is_volatile), |
| 4166 | index_(index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4167 | dex_file_(dex_file), |
| 4168 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4169 | |
| 4170 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4171 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4172 | uint32_t GetFieldIndex() const { return index_; } |
| 4173 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4174 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4175 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4176 | |
| 4177 | private: |
| 4178 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4179 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4180 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4181 | const uint32_t index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4182 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4183 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4184 | }; |
| 4185 | |
| 4186 | class HInstanceFieldGet : public HExpression<1> { |
| 4187 | public: |
| 4188 | HInstanceFieldGet(HInstruction* value, |
| 4189 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4190 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4191 | bool is_volatile, |
| 4192 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4193 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4194 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4195 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4196 | : HExpression( |
| 4197 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4198 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4199 | 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] | 4200 | SetRawInputAt(0, value); |
| 4201 | } |
| 4202 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4203 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4204 | |
| 4205 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4206 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4207 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4208 | } |
| 4209 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4210 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4211 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4212 | } |
| 4213 | |
| 4214 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4215 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4216 | } |
| 4217 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4218 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4219 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4220 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4221 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4222 | |
| 4223 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4224 | |
| 4225 | private: |
| 4226 | const FieldInfo field_info_; |
| 4227 | |
| 4228 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4229 | }; |
| 4230 | |
| 4231 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4232 | public: |
| 4233 | HInstanceFieldSet(HInstruction* object, |
| 4234 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4235 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4236 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4237 | bool is_volatile, |
| 4238 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4239 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4240 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4241 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4242 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4243 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4244 | 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] | 4245 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4246 | SetRawInputAt(0, object); |
| 4247 | SetRawInputAt(1, value); |
| 4248 | } |
| 4249 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4250 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4251 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4252 | } |
| 4253 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4254 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4255 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4256 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4257 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4258 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4259 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4260 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4261 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4262 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4263 | |
| 4264 | private: |
| 4265 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4266 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4267 | |
| 4268 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4269 | }; |
| 4270 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4271 | class HArrayGet : public HExpression<2> { |
| 4272 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4273 | HArrayGet(HInstruction* array, |
| 4274 | HInstruction* index, |
| 4275 | Primitive::Type type, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4276 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4277 | : HExpression(type, SideEffects::ArrayReadOfType(type), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4278 | SetRawInputAt(0, array); |
| 4279 | SetRawInputAt(1, index); |
| 4280 | } |
| 4281 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4282 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4283 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4284 | UNUSED(other); |
| 4285 | return true; |
| 4286 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4287 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4288 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4289 | // TODO: We can be smarter here. |
| 4290 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4291 | // which generates the implicit null check. There are cases when these can be removed |
| 4292 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4293 | // implicit check here (as long as the address falls in the first page). |
| 4294 | return false; |
| 4295 | } |
| 4296 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4297 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4298 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4299 | HInstruction* GetArray() const { return InputAt(0); } |
| 4300 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4301 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4302 | DECLARE_INSTRUCTION(ArrayGet); |
| 4303 | |
| 4304 | private: |
| 4305 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4306 | }; |
| 4307 | |
| 4308 | class HArraySet : public HTemplateInstruction<3> { |
| 4309 | public: |
| 4310 | HArraySet(HInstruction* array, |
| 4311 | HInstruction* index, |
| 4312 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4313 | Primitive::Type expected_component_type, |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4314 | uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4315 | : HTemplateInstruction( |
| 4316 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4317 | SideEffectsForArchRuntimeCalls(value->GetType())), dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4318 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4319 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4320 | value_can_be_null_(true), |
| 4321 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4322 | SetRawInputAt(0, array); |
| 4323 | SetRawInputAt(1, index); |
| 4324 | SetRawInputAt(2, value); |
| 4325 | } |
| 4326 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4327 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4328 | // We currently always call a runtime method to catch array store |
| 4329 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4330 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4331 | } |
| 4332 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4333 | // Can throw ArrayStoreException. |
| 4334 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4335 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4336 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4337 | UNUSED(obj); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4338 | // TODO: Same as for ArrayGet. |
| 4339 | return false; |
| 4340 | } |
| 4341 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4342 | void ClearNeedsTypeCheck() { |
| 4343 | needs_type_check_ = false; |
| 4344 | } |
| 4345 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4346 | void ClearValueCanBeNull() { |
| 4347 | value_can_be_null_ = false; |
| 4348 | } |
| 4349 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4350 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4351 | static_type_of_array_is_object_array_ = true; |
| 4352 | } |
| 4353 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4354 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4355 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4356 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4357 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4358 | HInstruction* GetArray() const { return InputAt(0); } |
| 4359 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4360 | HInstruction* GetValue() const { return InputAt(2); } |
| 4361 | |
| 4362 | Primitive::Type GetComponentType() const { |
| 4363 | // The Dex format does not type floating point index operations. Since the |
| 4364 | // `expected_component_type_` is set during building and can therefore not |
| 4365 | // be correct, we also check what is the value type. If it is a floating |
| 4366 | // point type, we must use that type. |
| 4367 | Primitive::Type value_type = GetValue()->GetType(); |
| 4368 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4369 | ? value_type |
| 4370 | : expected_component_type_; |
| 4371 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4372 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4373 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4374 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4375 | } |
| 4376 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4377 | DECLARE_INSTRUCTION(ArraySet); |
| 4378 | |
| 4379 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4380 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4381 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4382 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4383 | // Cached information for the reference_type_info_ so that codegen |
| 4384 | // does not need to inspect the static type. |
| 4385 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4386 | |
| 4387 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4388 | }; |
| 4389 | |
| 4390 | class HArrayLength : public HExpression<1> { |
| 4391 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4392 | explicit HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4393 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4394 | // Note that arrays do not change length, so the instruction does not |
| 4395 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4396 | SetRawInputAt(0, array); |
| 4397 | } |
| 4398 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4399 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4400 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4401 | UNUSED(other); |
| 4402 | return true; |
| 4403 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4404 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4405 | return obj == InputAt(0); |
| 4406 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4407 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4408 | DECLARE_INSTRUCTION(ArrayLength); |
| 4409 | |
| 4410 | private: |
| 4411 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4412 | }; |
| 4413 | |
| 4414 | class HBoundsCheck : public HExpression<2> { |
| 4415 | public: |
| 4416 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4417 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4418 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4419 | SetRawInputAt(0, index); |
| 4420 | SetRawInputAt(1, length); |
| 4421 | } |
| 4422 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4423 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4424 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4425 | UNUSED(other); |
| 4426 | return true; |
| 4427 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4428 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4429 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4430 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4431 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4432 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4433 | |
| 4434 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4435 | |
| 4436 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4437 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4438 | }; |
| 4439 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4440 | /** |
| 4441 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4442 | * to stay live until the last HInstruction. This class |
| 4443 | * 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] | 4444 | * HInstruction stays live. `index` represents the stack location index of the |
| 4445 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4446 | */ |
| 4447 | class HTemporary : public HTemplateInstruction<0> { |
| 4448 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4449 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4450 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4451 | |
| 4452 | size_t GetIndex() const { return index_; } |
| 4453 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4454 | Primitive::Type GetType() const OVERRIDE { |
| 4455 | // The previous instruction is the one that will be stored in the temporary location. |
| 4456 | DCHECK(GetPrevious() != nullptr); |
| 4457 | return GetPrevious()->GetType(); |
| 4458 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4459 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4460 | DECLARE_INSTRUCTION(Temporary); |
| 4461 | |
| 4462 | private: |
| 4463 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4464 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4465 | }; |
| 4466 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4467 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4468 | public: |
| 4469 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4470 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4471 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4472 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4473 | return true; |
| 4474 | } |
| 4475 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4476 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4477 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4478 | |
| 4479 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4480 | |
| 4481 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4482 | // Only used for code generation, in order to share the same slow path between back edges |
| 4483 | // of a same loop. |
| 4484 | SlowPathCode* slow_path_; |
| 4485 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4486 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4487 | }; |
| 4488 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4489 | /** |
| 4490 | * Instruction to load a Class object. |
| 4491 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4492 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4493 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4494 | HLoadClass(HCurrentMethod* current_method, |
| 4495 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4496 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4497 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4498 | uint32_t dex_pc, |
| 4499 | bool needs_access_check) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4500 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4501 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4502 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4503 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4504 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4505 | needs_access_check_(needs_access_check), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4506 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4507 | SetRawInputAt(0, current_method); |
| 4508 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4509 | |
| 4510 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4511 | |
| 4512 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4513 | // Note that we don't need to test for generate_clinit_check_. |
| 4514 | // Whether or not we need to generate the clinit check is processed in |
| 4515 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4516 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4517 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4518 | } |
| 4519 | |
| 4520 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4521 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4522 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4523 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4524 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4525 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4526 | bool NeedsEnvironment() const OVERRIDE { |
| 4527 | // Will call runtime and load the class if the class is not loaded yet. |
| 4528 | // TODO: finer grain decision. |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4529 | return !is_referrers_class_ || needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4530 | } |
| 4531 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4532 | bool MustGenerateClinitCheck() const { |
| 4533 | return generate_clinit_check_; |
| 4534 | } |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4535 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4536 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4537 | } |
| 4538 | |
| 4539 | bool CanCallRuntime() const { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4540 | return MustGenerateClinitCheck() || !is_referrers_class_ || needs_access_check_; |
| 4541 | } |
| 4542 | |
| 4543 | bool NeedsAccessCheck() const { |
| 4544 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4545 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4546 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4547 | bool CanThrow() const OVERRIDE { |
| 4548 | // May call runtime and and therefore can throw. |
| 4549 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4550 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4551 | } |
| 4552 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4553 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4554 | return loaded_class_rti_; |
| 4555 | } |
| 4556 | |
| 4557 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4558 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4559 | DCHECK(rti.IsExact()); |
| 4560 | loaded_class_rti_ = rti; |
| 4561 | } |
| 4562 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4563 | const DexFile& GetDexFile() { return dex_file_; } |
| 4564 | |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4565 | bool NeedsDexCache() const OVERRIDE { return !is_referrers_class_; } |
| 4566 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4567 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4568 | return SideEffects::CanTriggerGC(); |
| 4569 | } |
| 4570 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4571 | DECLARE_INSTRUCTION(LoadClass); |
| 4572 | |
| 4573 | private: |
| 4574 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4575 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4576 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4577 | // Whether this instruction must generate the initialization check. |
| 4578 | // Used for code generation. |
| 4579 | bool generate_clinit_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4580 | bool needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4581 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4582 | ReferenceTypeInfo loaded_class_rti_; |
| 4583 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4584 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4585 | }; |
| 4586 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4587 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4588 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4589 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4590 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4591 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4592 | SetRawInputAt(0, current_method); |
| 4593 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4594 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4595 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4596 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4597 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4598 | return other->AsLoadString()->string_index_ == string_index_; |
| 4599 | } |
| 4600 | |
| 4601 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4602 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4603 | uint32_t GetStringIndex() const { return string_index_; } |
| 4604 | |
| 4605 | // TODO: Can we deopt or debug when we resolve a string? |
| 4606 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4607 | bool NeedsDexCache() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4608 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4609 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4610 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4611 | return SideEffects::CanTriggerGC(); |
| 4612 | } |
| 4613 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4614 | DECLARE_INSTRUCTION(LoadString); |
| 4615 | |
| 4616 | private: |
| 4617 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4618 | |
| 4619 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4620 | }; |
| 4621 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4622 | /** |
| 4623 | * Performs an initialization check on its Class object input. |
| 4624 | */ |
| 4625 | class HClinitCheck : public HExpression<1> { |
| 4626 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4627 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4628 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4629 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4630 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4631 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4632 | SetRawInputAt(0, constant); |
| 4633 | } |
| 4634 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4635 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4636 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4637 | UNUSED(other); |
| 4638 | return true; |
| 4639 | } |
| 4640 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4641 | bool NeedsEnvironment() const OVERRIDE { |
| 4642 | // May call runtime to initialize the class. |
| 4643 | return true; |
| 4644 | } |
| 4645 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4646 | |
| 4647 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4648 | |
| 4649 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4650 | |
| 4651 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4652 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4653 | }; |
| 4654 | |
| 4655 | class HStaticFieldGet : public HExpression<1> { |
| 4656 | public: |
| 4657 | HStaticFieldGet(HInstruction* cls, |
| 4658 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4659 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4660 | bool is_volatile, |
| 4661 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4662 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4663 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4664 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4665 | : HExpression( |
| 4666 | field_type, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4667 | SideEffects::FieldReadOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4668 | 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] | 4669 | SetRawInputAt(0, cls); |
| 4670 | } |
| 4671 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4672 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4673 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4674 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4675 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4676 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4677 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4678 | } |
| 4679 | |
| 4680 | size_t ComputeHashCode() const OVERRIDE { |
| 4681 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4682 | } |
| 4683 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4684 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4685 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4686 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4687 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4688 | |
| 4689 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4690 | |
| 4691 | private: |
| 4692 | const FieldInfo field_info_; |
| 4693 | |
| 4694 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4695 | }; |
| 4696 | |
| 4697 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4698 | public: |
| 4699 | HStaticFieldSet(HInstruction* cls, |
| 4700 | HInstruction* value, |
| 4701 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4702 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4703 | bool is_volatile, |
| 4704 | uint32_t field_idx, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4705 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4706 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4707 | uint32_t dex_pc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 4708 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4709 | SideEffects::FieldWriteOfType(field_type, is_volatile), dex_pc), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4710 | field_info_(field_offset, field_type, is_volatile, field_idx, dex_file, dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4711 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4712 | SetRawInputAt(0, cls); |
| 4713 | SetRawInputAt(1, value); |
| 4714 | } |
| 4715 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4716 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4717 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4718 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4719 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4720 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4721 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4722 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4723 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4724 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4725 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4726 | |
| 4727 | private: |
| 4728 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4729 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4730 | |
| 4731 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4732 | }; |
| 4733 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4734 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 4735 | public: |
| 4736 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 4737 | Primitive::Type field_type, |
| 4738 | uint32_t field_index, |
| 4739 | uint32_t dex_pc) |
| 4740 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 4741 | field_index_(field_index) { |
| 4742 | SetRawInputAt(0, obj); |
| 4743 | } |
| 4744 | |
| 4745 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4746 | bool CanThrow() const OVERRIDE { return true; } |
| 4747 | |
| 4748 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4749 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4750 | |
| 4751 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 4752 | |
| 4753 | private: |
| 4754 | const uint32_t field_index_; |
| 4755 | |
| 4756 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 4757 | }; |
| 4758 | |
| 4759 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 4760 | public: |
| 4761 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 4762 | HInstruction* value, |
| 4763 | Primitive::Type field_type, |
| 4764 | uint32_t field_index, |
| 4765 | uint32_t dex_pc) |
| 4766 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 4767 | field_type_(field_type), |
| 4768 | field_index_(field_index) { |
| 4769 | DCHECK_EQ(field_type, value->GetType()); |
| 4770 | SetRawInputAt(0, obj); |
| 4771 | SetRawInputAt(1, value); |
| 4772 | } |
| 4773 | |
| 4774 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4775 | bool CanThrow() const OVERRIDE { return true; } |
| 4776 | |
| 4777 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4778 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4779 | |
| 4780 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 4781 | |
| 4782 | private: |
| 4783 | const Primitive::Type field_type_; |
| 4784 | const uint32_t field_index_; |
| 4785 | |
| 4786 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 4787 | }; |
| 4788 | |
| 4789 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 4790 | public: |
| 4791 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 4792 | uint32_t field_index, |
| 4793 | uint32_t dex_pc) |
| 4794 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 4795 | field_index_(field_index) { |
| 4796 | } |
| 4797 | |
| 4798 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4799 | bool CanThrow() const OVERRIDE { return true; } |
| 4800 | |
| 4801 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4802 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4803 | |
| 4804 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 4805 | |
| 4806 | private: |
| 4807 | const uint32_t field_index_; |
| 4808 | |
| 4809 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 4810 | }; |
| 4811 | |
| 4812 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 4813 | public: |
| 4814 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 4815 | Primitive::Type field_type, |
| 4816 | uint32_t field_index, |
| 4817 | uint32_t dex_pc) |
| 4818 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 4819 | field_type_(field_type), |
| 4820 | field_index_(field_index) { |
| 4821 | DCHECK_EQ(field_type, value->GetType()); |
| 4822 | SetRawInputAt(0, value); |
| 4823 | } |
| 4824 | |
| 4825 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4826 | bool CanThrow() const OVERRIDE { return true; } |
| 4827 | |
| 4828 | Primitive::Type GetFieldType() const { return field_type_; } |
| 4829 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4830 | |
| 4831 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 4832 | |
| 4833 | private: |
| 4834 | const Primitive::Type field_type_; |
| 4835 | const uint32_t field_index_; |
| 4836 | |
| 4837 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 4838 | }; |
| 4839 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4840 | // Implement the move-exception DEX instruction. |
| 4841 | class HLoadException : public HExpression<0> { |
| 4842 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4843 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 4844 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4845 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 4846 | bool CanBeNull() const OVERRIDE { return false; } |
| 4847 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4848 | DECLARE_INSTRUCTION(LoadException); |
| 4849 | |
| 4850 | private: |
| 4851 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 4852 | }; |
| 4853 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4854 | // Implicit part of move-exception which clears thread-local exception storage. |
| 4855 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 4856 | class HClearException : public HTemplateInstruction<0> { |
| 4857 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4858 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 4859 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 4860 | |
| 4861 | DECLARE_INSTRUCTION(ClearException); |
| 4862 | |
| 4863 | private: |
| 4864 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 4865 | }; |
| 4866 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4867 | class HThrow : public HTemplateInstruction<1> { |
| 4868 | public: |
| 4869 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4870 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4871 | SetRawInputAt(0, exception); |
| 4872 | } |
| 4873 | |
| 4874 | bool IsControlFlow() const OVERRIDE { return true; } |
| 4875 | |
| 4876 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4877 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4878 | bool CanThrow() const OVERRIDE { return true; } |
| 4879 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4880 | |
| 4881 | DECLARE_INSTRUCTION(Throw); |
| 4882 | |
| 4883 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 4884 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 4885 | }; |
| 4886 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4887 | /** |
| 4888 | * Implementation strategies for the code generator of a HInstanceOf |
| 4889 | * or `HCheckCast`. |
| 4890 | */ |
| 4891 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4892 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4893 | kExactCheck, // Can do a single class compare. |
| 4894 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 4895 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 4896 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 4897 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 4898 | kArrayCheck // No optimization yet when checking against a generic array. |
| 4899 | }; |
| 4900 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4901 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4902 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4903 | HInstanceOf(HInstruction* object, |
| 4904 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4905 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4906 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4907 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4908 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4909 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4910 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4911 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4912 | SetRawInputAt(0, object); |
| 4913 | SetRawInputAt(1, constant); |
| 4914 | } |
| 4915 | |
| 4916 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4917 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4918 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4919 | return true; |
| 4920 | } |
| 4921 | |
| 4922 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4923 | return false; |
| 4924 | } |
| 4925 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4926 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 4927 | |
| 4928 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4929 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4930 | // Used only in code generation. |
| 4931 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 4932 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 4933 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4934 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 4935 | return (check_kind == TypeCheckKind::kExactCheck) |
| 4936 | ? SideEffects::None() |
| 4937 | // Mips currently does runtime calls for any other checks. |
| 4938 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4939 | } |
| 4940 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4941 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4942 | |
| 4943 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 4944 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 4945 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 4946 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4947 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 4948 | }; |
| 4949 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4950 | class HBoundType : public HExpression<1> { |
| 4951 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4952 | // Constructs an HBoundType with the given upper_bound. |
| 4953 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4954 | HBoundType(HInstruction* input, |
| 4955 | ReferenceTypeInfo upper_bound, |
| 4956 | bool upper_can_be_null, |
| 4957 | uint32_t dex_pc = kNoDexPc) |
| 4958 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4959 | upper_bound_(upper_bound), |
| 4960 | upper_can_be_null_(upper_can_be_null), |
| 4961 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 4962 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4963 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4964 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4965 | } |
| 4966 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4967 | // GetUpper* should only be used in reference type propagation. |
| 4968 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 4969 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4970 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4971 | void SetCanBeNull(bool can_be_null) { |
| 4972 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 4973 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4974 | } |
| 4975 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 4976 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4977 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4978 | DECLARE_INSTRUCTION(BoundType); |
| 4979 | |
| 4980 | private: |
| 4981 | // 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] | 4982 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 4983 | // It is used to bound the type in cases like: |
| 4984 | // if (x instanceof ClassX) { |
| 4985 | // // uper_bound_ will be ClassX |
| 4986 | // } |
| 4987 | const ReferenceTypeInfo upper_bound_; |
| 4988 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 4989 | // is false then can_be_null_ cannot be true). |
| 4990 | const bool upper_can_be_null_; |
| 4991 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4992 | |
| 4993 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 4994 | }; |
| 4995 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 4996 | class HCheckCast : public HTemplateInstruction<2> { |
| 4997 | public: |
| 4998 | HCheckCast(HInstruction* object, |
| 4999 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5000 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5001 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5002 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5003 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5004 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5005 | SetRawInputAt(0, object); |
| 5006 | SetRawInputAt(1, constant); |
| 5007 | } |
| 5008 | |
| 5009 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5010 | |
| 5011 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5012 | return true; |
| 5013 | } |
| 5014 | |
| 5015 | bool NeedsEnvironment() const OVERRIDE { |
| 5016 | // Instruction may throw a CheckCastError. |
| 5017 | return true; |
| 5018 | } |
| 5019 | |
| 5020 | bool CanThrow() const OVERRIDE { return true; } |
| 5021 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5022 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5023 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5024 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5025 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5026 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5027 | |
| 5028 | DECLARE_INSTRUCTION(CheckCast); |
| 5029 | |
| 5030 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5031 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5032 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5033 | |
| 5034 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5035 | }; |
| 5036 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5037 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5038 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5039 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5040 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5041 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5042 | barrier_kind_(barrier_kind) {} |
| 5043 | |
| 5044 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5045 | |
| 5046 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5047 | |
| 5048 | private: |
| 5049 | const MemBarrierKind barrier_kind_; |
| 5050 | |
| 5051 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5052 | }; |
| 5053 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5054 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5055 | public: |
| 5056 | enum OperationKind { |
| 5057 | kEnter, |
| 5058 | kExit, |
| 5059 | }; |
| 5060 | |
| 5061 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5062 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5063 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5064 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5065 | SetRawInputAt(0, object); |
| 5066 | } |
| 5067 | |
| 5068 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5069 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5070 | |
| 5071 | bool CanThrow() const OVERRIDE { |
| 5072 | // Verifier guarantees that monitor-exit cannot throw. |
| 5073 | // This is important because it allows the HGraphBuilder to remove |
| 5074 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5075 | return IsEnter(); |
| 5076 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5077 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5078 | |
| 5079 | bool IsEnter() const { return kind_ == kEnter; } |
| 5080 | |
| 5081 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5082 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5083 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5084 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5085 | |
| 5086 | private: |
| 5087 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5088 | }; |
| 5089 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5090 | /** |
| 5091 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5092 | * of a String to a call to a StringFactory. Only baseline will see |
| 5093 | * the node at code generation, where it will be be treated as null. |
| 5094 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5095 | * in the instruction simplifier. |
| 5096 | */ |
| 5097 | class HFakeString : public HTemplateInstruction<0> { |
| 5098 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5099 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5100 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5101 | |
| 5102 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5103 | |
| 5104 | DECLARE_INSTRUCTION(FakeString); |
| 5105 | |
| 5106 | private: |
| 5107 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5108 | }; |
| 5109 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5110 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5111 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5112 | MoveOperands(Location source, |
| 5113 | Location destination, |
| 5114 | Primitive::Type type, |
| 5115 | HInstruction* instruction) |
| 5116 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5117 | |
| 5118 | Location GetSource() const { return source_; } |
| 5119 | Location GetDestination() const { return destination_; } |
| 5120 | |
| 5121 | void SetSource(Location value) { source_ = value; } |
| 5122 | void SetDestination(Location value) { destination_ = value; } |
| 5123 | |
| 5124 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5125 | // destination (but not the source). |
| 5126 | Location MarkPending() { |
| 5127 | DCHECK(!IsPending()); |
| 5128 | Location dest = destination_; |
| 5129 | destination_ = Location::NoLocation(); |
| 5130 | return dest; |
| 5131 | } |
| 5132 | |
| 5133 | void ClearPending(Location dest) { |
| 5134 | DCHECK(IsPending()); |
| 5135 | destination_ = dest; |
| 5136 | } |
| 5137 | |
| 5138 | bool IsPending() const { |
| 5139 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5140 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5141 | } |
| 5142 | |
| 5143 | // True if this blocks a move from the given location. |
| 5144 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5145 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | // A move is redundant if it's been eliminated, if its source and |
| 5149 | // destination are the same, or if its destination is unneeded. |
| 5150 | bool IsRedundant() const { |
| 5151 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5152 | } |
| 5153 | |
| 5154 | // We clear both operands to indicate move that's been eliminated. |
| 5155 | void Eliminate() { |
| 5156 | source_ = destination_ = Location::NoLocation(); |
| 5157 | } |
| 5158 | |
| 5159 | bool IsEliminated() const { |
| 5160 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5161 | return source_.IsInvalid(); |
| 5162 | } |
| 5163 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5164 | Primitive::Type GetType() const { return type_; } |
| 5165 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5166 | bool Is64BitMove() const { |
| 5167 | return Primitive::Is64BitType(type_); |
| 5168 | } |
| 5169 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5170 | HInstruction* GetInstruction() const { return instruction_; } |
| 5171 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5172 | private: |
| 5173 | Location source_; |
| 5174 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5175 | // The type this move is for. |
| 5176 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5177 | // The instruction this move is assocatied with. Null when this move is |
| 5178 | // for moving an input in the expected locations of user (including a phi user). |
| 5179 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5180 | // in the same parallel move. |
| 5181 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5182 | }; |
| 5183 | |
| 5184 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5185 | |
| 5186 | class HParallelMove : public HTemplateInstruction<0> { |
| 5187 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5188 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5189 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5190 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5191 | moves_.reserve(kDefaultNumberOfMoves); |
| 5192 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5193 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5194 | void AddMove(Location source, |
| 5195 | Location destination, |
| 5196 | Primitive::Type type, |
| 5197 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5198 | DCHECK(source.IsValid()); |
| 5199 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5200 | if (kIsDebugBuild) { |
| 5201 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5202 | for (const MoveOperands& move : moves_) { |
| 5203 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5204 | // Special case the situation where the move is for the spill slot |
| 5205 | // of the instruction. |
| 5206 | if ((GetPrevious() == instruction) |
| 5207 | || ((GetPrevious() == nullptr) |
| 5208 | && instruction->IsPhi() |
| 5209 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5210 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5211 | << "Doing parallel moves for the same instruction."; |
| 5212 | } else { |
| 5213 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5214 | } |
| 5215 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5216 | } |
| 5217 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5218 | for (const MoveOperands& move : moves_) { |
| 5219 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5220 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5221 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5222 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5223 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5224 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5225 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5226 | } |
| 5227 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5228 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5229 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5230 | } |
| 5231 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5232 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5233 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5234 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5235 | |
| 5236 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5237 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5238 | |
| 5239 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5240 | }; |
| 5241 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5242 | } // namespace art |
| 5243 | |
| 5244 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5245 | #include "nodes_x86.h" |
| 5246 | #endif |
| 5247 | |
| 5248 | namespace art { |
| 5249 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5250 | class HGraphVisitor : public ValueObject { |
| 5251 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5252 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5253 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5254 | |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 5255 | virtual void VisitInstruction(HInstruction* instruction) { UNUSED(instruction); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5256 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5257 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5258 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5259 | void VisitInsertionOrder(); |
| 5260 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5261 | // Visit the graph following dominator tree reverse post-order. |
| 5262 | void VisitReversePostOrder(); |
| 5263 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5264 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5265 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5266 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5267 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5268 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5269 | |
| 5270 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5271 | |
| 5272 | #undef DECLARE_VISIT_INSTRUCTION |
| 5273 | |
| 5274 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5275 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5276 | |
| 5277 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5278 | }; |
| 5279 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5280 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5281 | public: |
| 5282 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5283 | virtual ~HGraphDelegateVisitor() {} |
| 5284 | |
| 5285 | // Visit functions that delegate to to super class. |
| 5286 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5287 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5288 | |
| 5289 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5290 | |
| 5291 | #undef DECLARE_VISIT_INSTRUCTION |
| 5292 | |
| 5293 | private: |
| 5294 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5295 | }; |
| 5296 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5297 | class HInsertionOrderIterator : public ValueObject { |
| 5298 | public: |
| 5299 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5300 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5301 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5302 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5303 | void Advance() { ++index_; } |
| 5304 | |
| 5305 | private: |
| 5306 | const HGraph& graph_; |
| 5307 | size_t index_; |
| 5308 | |
| 5309 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5310 | }; |
| 5311 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5312 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5313 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5314 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5315 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5316 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5317 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5318 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5319 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5320 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5321 | void Advance() { ++index_; } |
| 5322 | |
| 5323 | private: |
| 5324 | const HGraph& graph_; |
| 5325 | size_t index_; |
| 5326 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5327 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5328 | }; |
| 5329 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5330 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5331 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5332 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5333 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5334 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5335 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5336 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5337 | |
| 5338 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5339 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5340 | void Advance() { --index_; } |
| 5341 | |
| 5342 | private: |
| 5343 | const HGraph& graph_; |
| 5344 | size_t index_; |
| 5345 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5346 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5347 | }; |
| 5348 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5349 | class HLinearPostOrderIterator : public ValueObject { |
| 5350 | public: |
| 5351 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5352 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5353 | |
| 5354 | bool Done() const { return index_ == 0; } |
| 5355 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5356 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5357 | |
| 5358 | void Advance() { |
| 5359 | --index_; |
| 5360 | DCHECK_GE(index_, 0U); |
| 5361 | } |
| 5362 | |
| 5363 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5364 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5365 | size_t index_; |
| 5366 | |
| 5367 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5368 | }; |
| 5369 | |
| 5370 | class HLinearOrderIterator : public ValueObject { |
| 5371 | public: |
| 5372 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5373 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5374 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5375 | bool Done() const { return index_ == order_.size(); } |
| 5376 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5377 | void Advance() { ++index_; } |
| 5378 | |
| 5379 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5380 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5381 | size_t index_; |
| 5382 | |
| 5383 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5384 | }; |
| 5385 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5386 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5387 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5388 | // block id. |
| 5389 | class HBlocksInLoopIterator : public ValueObject { |
| 5390 | public: |
| 5391 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5392 | : blocks_in_loop_(info.GetBlocks()), |
| 5393 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5394 | index_(0) { |
| 5395 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5396 | Advance(); |
| 5397 | } |
| 5398 | } |
| 5399 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5400 | bool Done() const { return index_ == blocks_.size(); } |
| 5401 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5402 | void Advance() { |
| 5403 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5404 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5405 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5406 | break; |
| 5407 | } |
| 5408 | } |
| 5409 | } |
| 5410 | |
| 5411 | private: |
| 5412 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5413 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5414 | size_t index_; |
| 5415 | |
| 5416 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5417 | }; |
| 5418 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5419 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5420 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5421 | // post order. |
| 5422 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5423 | public: |
| 5424 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5425 | : blocks_in_loop_(info.GetBlocks()), |
| 5426 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5427 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5428 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5429 | Advance(); |
| 5430 | } |
| 5431 | } |
| 5432 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5433 | bool Done() const { return index_ == blocks_.size(); } |
| 5434 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5435 | void Advance() { |
| 5436 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5437 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5438 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5439 | break; |
| 5440 | } |
| 5441 | } |
| 5442 | } |
| 5443 | |
| 5444 | private: |
| 5445 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5446 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5447 | size_t index_; |
| 5448 | |
| 5449 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5450 | }; |
| 5451 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5452 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5453 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5454 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5455 | : constant->AsLongConstant()->GetValue(); |
| 5456 | } |
| 5457 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5458 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5459 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5460 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5461 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5462 | // times and provide different class resolution but no two class loaders should ever |
| 5463 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5464 | // all sorts of weird failures. |
| 5465 | return &lhs == &rhs; |
| 5466 | } |
| 5467 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5468 | } // namespace art |
| 5469 | |
| 5470 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |