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 | |
Mathieu Chartier | e5d80f8 | 2015-10-15 17:47:48 -0700 | [diff] [blame] | 24 | #include "base/arena_bit_vector.h" |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 25 | #include "base/arena_containers.h" |
Mathieu Chartier | b666f48 | 2015-02-18 14:33:14 -0800 | [diff] [blame] | 26 | #include "base/arena_object.h" |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 27 | #include "base/stl_util.h" |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 28 | #include "dex/compiler_enums.h" |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 29 | #include "entrypoints/quick/quick_entrypoints_enum.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 30 | #include "handle.h" |
| 31 | #include "handle_scope.h" |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 32 | #include "invoke_type.h" |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 33 | #include "locations.h" |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 34 | #include "method_reference.h" |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 35 | #include "mirror/class.h" |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 36 | #include "offsets.h" |
Ian Rogers | e63db27 | 2014-07-15 15:36:11 -0700 | [diff] [blame] | 37 | #include "primitive.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); |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 78 | static constexpr uint16_t kUnknownClassDefIndex = static_cast<uint16_t>(-1); |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 79 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 80 | static constexpr InvokeType kInvalidInvokeType = static_cast<InvokeType>(-1); |
| 81 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 82 | static constexpr uint32_t kNoDexPc = -1; |
| 83 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 84 | enum IfCondition { |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 85 | // All types. |
| 86 | kCondEQ, // == |
| 87 | kCondNE, // != |
| 88 | // Signed integers and floating-point numbers. |
| 89 | kCondLT, // < |
| 90 | kCondLE, // <= |
| 91 | kCondGT, // > |
| 92 | kCondGE, // >= |
| 93 | // Unsigned integers. |
| 94 | kCondB, // < |
| 95 | kCondBE, // <= |
| 96 | kCondA, // > |
| 97 | kCondAE, // >= |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 98 | }; |
| 99 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 100 | class HInstructionList : public ValueObject { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 101 | public: |
| 102 | HInstructionList() : first_instruction_(nullptr), last_instruction_(nullptr) {} |
| 103 | |
| 104 | void AddInstruction(HInstruction* instruction); |
| 105 | void RemoveInstruction(HInstruction* instruction); |
| 106 | |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 107 | // Insert `instruction` before/after an existing instruction `cursor`. |
| 108 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
| 109 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
| 110 | |
Roland Levillain | 6b46923 | 2014-09-25 10:10:38 +0100 | [diff] [blame] | 111 | // Return true if this list contains `instruction`. |
| 112 | bool Contains(HInstruction* instruction) const; |
| 113 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 114 | // Return true if `instruction1` is found before `instruction2` in |
| 115 | // this instruction list and false otherwise. Abort if none |
| 116 | // of these instructions is found. |
| 117 | bool FoundBefore(const HInstruction* instruction1, |
| 118 | const HInstruction* instruction2) const; |
| 119 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 120 | bool IsEmpty() const { return first_instruction_ == nullptr; } |
| 121 | void Clear() { first_instruction_ = last_instruction_ = nullptr; } |
| 122 | |
| 123 | // Update the block of all instructions to be `block`. |
| 124 | void SetBlockOfInstructions(HBasicBlock* block) const; |
| 125 | |
| 126 | void AddAfter(HInstruction* cursor, const HInstructionList& instruction_list); |
| 127 | void Add(const HInstructionList& instruction_list); |
| 128 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 129 | // Return the number of instructions in the list. This is an expensive operation. |
| 130 | size_t CountSize() const; |
| 131 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 132 | private: |
| 133 | HInstruction* first_instruction_; |
| 134 | HInstruction* last_instruction_; |
| 135 | |
| 136 | friend class HBasicBlock; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 137 | friend class HGraph; |
| 138 | friend class HInstruction; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 139 | friend class HInstructionIterator; |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 140 | friend class HBackwardInstructionIterator; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 141 | |
| 142 | DISALLOW_COPY_AND_ASSIGN(HInstructionList); |
| 143 | }; |
| 144 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 145 | // Control-flow graph of a method. Contains a list of basic blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 146 | class HGraph : public ArenaObject<kArenaAllocGraph> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 147 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 148 | HGraph(ArenaAllocator* arena, |
| 149 | const DexFile& dex_file, |
| 150 | uint32_t method_idx, |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 151 | bool should_generate_constructor_barrier, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 152 | InstructionSet instruction_set, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 153 | InvokeType invoke_type = kInvalidInvokeType, |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 154 | bool debuggable = false, |
| 155 | int start_instruction_id = 0) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 156 | : arena_(arena), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 157 | blocks_(arena->Adapter(kArenaAllocBlockList)), |
| 158 | reverse_post_order_(arena->Adapter(kArenaAllocReversePostOrder)), |
| 159 | linear_order_(arena->Adapter(kArenaAllocLinearOrder)), |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 160 | entry_block_(nullptr), |
| 161 | exit_block_(nullptr), |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 162 | maximum_number_of_out_vregs_(0), |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 163 | number_of_vregs_(0), |
| 164 | number_of_in_vregs_(0), |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 165 | temporaries_vreg_slots_(0), |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 166 | has_bounds_checks_(false), |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 167 | has_try_catch_(false), |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 168 | debuggable_(debuggable), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 169 | current_instruction_id_(start_instruction_id), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 170 | dex_file_(dex_file), |
| 171 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 172 | invoke_type_(invoke_type), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 173 | in_ssa_form_(false), |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 174 | should_generate_constructor_barrier_(should_generate_constructor_barrier), |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 175 | instruction_set_(instruction_set), |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 176 | cached_null_constant_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 177 | cached_int_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 178 | cached_float_constants_(std::less<int32_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 179 | cached_long_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 180 | cached_double_constants_(std::less<int64_t>(), arena->Adapter(kArenaAllocConstantsMap)), |
| 181 | cached_current_method_(nullptr) { |
| 182 | blocks_.reserve(kDefaultNumberOfBlocks); |
| 183 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 184 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 185 | ArenaAllocator* GetArena() const { return arena_; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 186 | const ArenaVector<HBasicBlock*>& GetBlocks() const { return blocks_; } |
| 187 | |
David Brazdil | 69ba7b7 | 2015-06-23 18:27:30 +0100 | [diff] [blame] | 188 | bool IsInSsaForm() const { return in_ssa_form_; } |
| 189 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 190 | HBasicBlock* GetEntryBlock() const { return entry_block_; } |
| 191 | HBasicBlock* GetExitBlock() const { return exit_block_; } |
David Brazdil | c7af85d | 2015-05-26 12:05:55 +0100 | [diff] [blame] | 192 | bool HasExitBlock() const { return exit_block_ != nullptr; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 193 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 194 | void SetEntryBlock(HBasicBlock* block) { entry_block_ = block; } |
| 195 | void SetExitBlock(HBasicBlock* block) { exit_block_ = block; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 196 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 197 | void AddBlock(HBasicBlock* block); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 198 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 199 | // Try building the SSA form of this graph, with dominance computation and loop |
| 200 | // recognition. Returns whether it was successful in doing all these steps. |
| 201 | bool TryBuildingSsa() { |
| 202 | BuildDominatorTree(); |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 203 | // The SSA builder requires loops to all be natural. Specifically, the dead phi |
| 204 | // elimination phase checks the consistency of the graph when doing a post-order |
| 205 | // visit for eliminating dead phis: a dead phi can only have loop header phi |
| 206 | // users remaining when being visited. |
| 207 | if (!AnalyzeNaturalLoops()) return false; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 208 | // Precompute per-block try membership before entering the SSA builder, |
| 209 | // which needs the information to build catch block phis from values of |
| 210 | // locals at throwing instructions inside try blocks. |
| 211 | ComputeTryBlockInformation(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 212 | TransformToSsa(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 213 | in_ssa_form_ = true; |
Nicolas Geoffray | d335083 | 2015-03-12 11:16:23 +0000 | [diff] [blame] | 214 | return true; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 215 | } |
| 216 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 217 | void ComputeDominanceInformation(); |
| 218 | void ClearDominanceInformation(); |
| 219 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 220 | void BuildDominatorTree(); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 221 | void TransformToSsa(); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 222 | void SimplifyCFG(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 223 | void SimplifyCatchBlocks(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 224 | |
Nicolas Geoffray | f537012 | 2014-12-02 11:51:19 +0000 | [diff] [blame] | 225 | // Analyze all natural loops in this graph. Returns false if one |
| 226 | // loop is not natural, that is the header does not dominate the |
| 227 | // back edge. |
| 228 | bool AnalyzeNaturalLoops() const; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 229 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 230 | // Iterate over blocks to compute try block membership. Needs reverse post |
| 231 | // order and loop information. |
| 232 | void ComputeTryBlockInformation(); |
| 233 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 234 | // Inline this graph in `outer_graph`, replacing the given `invoke` instruction. |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 235 | // Returns the instruction used to replace the invoke expression or null if the |
| 236 | // invoke is for a void method. |
| 237 | HInstruction* InlineInto(HGraph* outer_graph, HInvoke* invoke); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 238 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 239 | // Need to add a couple of blocks to test if the loop body is entered and |
| 240 | // put deoptimization instructions, etc. |
| 241 | void TransformLoopHeaderForBCE(HBasicBlock* header); |
| 242 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 243 | // Removes `block` from the graph. |
| 244 | void DeleteDeadBlock(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 245 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 246 | // Splits the edge between `block` and `successor` while preserving the |
| 247 | // indices in the predecessor/successor lists. If there are multiple edges |
| 248 | // between the blocks, the lowest indices are used. |
| 249 | // Returns the new block which is empty and has the same dex pc as `successor`. |
| 250 | HBasicBlock* SplitEdge(HBasicBlock* block, HBasicBlock* successor); |
| 251 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 252 | void SplitCriticalEdge(HBasicBlock* block, HBasicBlock* successor); |
| 253 | void SimplifyLoop(HBasicBlock* header); |
| 254 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 255 | int32_t GetNextInstructionId() { |
| 256 | DCHECK_NE(current_instruction_id_, INT32_MAX); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 257 | return current_instruction_id_++; |
| 258 | } |
| 259 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 260 | int32_t GetCurrentInstructionId() const { |
| 261 | return current_instruction_id_; |
| 262 | } |
| 263 | |
| 264 | void SetCurrentInstructionId(int32_t id) { |
| 265 | current_instruction_id_ = id; |
| 266 | } |
| 267 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 268 | uint16_t GetMaximumNumberOfOutVRegs() const { |
| 269 | return maximum_number_of_out_vregs_; |
| 270 | } |
| 271 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 272 | void SetMaximumNumberOfOutVRegs(uint16_t new_value) { |
| 273 | maximum_number_of_out_vregs_ = new_value; |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 274 | } |
| 275 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 276 | void UpdateMaximumNumberOfOutVRegs(uint16_t other_value) { |
| 277 | maximum_number_of_out_vregs_ = std::max(maximum_number_of_out_vregs_, other_value); |
| 278 | } |
| 279 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 280 | void UpdateTemporariesVRegSlots(size_t slots) { |
| 281 | temporaries_vreg_slots_ = std::max(slots, temporaries_vreg_slots_); |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 282 | } |
| 283 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 284 | size_t GetTemporariesVRegSlots() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 285 | DCHECK(!in_ssa_form_); |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 286 | return temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 287 | } |
| 288 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 289 | void SetNumberOfVRegs(uint16_t number_of_vregs) { |
| 290 | number_of_vregs_ = number_of_vregs; |
| 291 | } |
| 292 | |
| 293 | uint16_t GetNumberOfVRegs() const { |
| 294 | return number_of_vregs_; |
| 295 | } |
| 296 | |
| 297 | void SetNumberOfInVRegs(uint16_t value) { |
| 298 | number_of_in_vregs_ = value; |
| 299 | } |
| 300 | |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 301 | uint16_t GetNumberOfLocalVRegs() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 302 | DCHECK(!in_ssa_form_); |
Nicolas Geoffray | ab032bc | 2014-07-15 12:55:21 +0100 | [diff] [blame] | 303 | return number_of_vregs_ - number_of_in_vregs_; |
| 304 | } |
| 305 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 306 | const ArenaVector<HBasicBlock*>& GetReversePostOrder() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 307 | return reverse_post_order_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 308 | } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 309 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 310 | const ArenaVector<HBasicBlock*>& GetLinearOrder() const { |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 311 | return linear_order_; |
| 312 | } |
| 313 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 314 | bool HasBoundsChecks() const { |
| 315 | return has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 316 | } |
| 317 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 318 | void SetHasBoundsChecks(bool value) { |
| 319 | has_bounds_checks_ = value; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 322 | bool ShouldGenerateConstructorBarrier() const { |
| 323 | return should_generate_constructor_barrier_; |
| 324 | } |
| 325 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 326 | bool IsDebuggable() const { return debuggable_; } |
| 327 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 328 | // 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] | 329 | // already, it is created and inserted into the graph. This method is only for |
| 330 | // integral types. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 331 | 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] | 332 | |
| 333 | // TODO: This is problematic for the consistency of reference type propagation |
| 334 | // because it can be created anytime after the pass and thus it will be left |
| 335 | // with an invalid type. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 336 | HNullConstant* GetNullConstant(uint32_t dex_pc = kNoDexPc); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 337 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 338 | HIntConstant* GetIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) { |
| 339 | return CreateConstant(value, &cached_int_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 340 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 341 | HLongConstant* GetLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) { |
| 342 | return CreateConstant(value, &cached_long_constants_, dex_pc); |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 343 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 344 | HFloatConstant* GetFloatConstant(float value, uint32_t dex_pc = kNoDexPc) { |
| 345 | 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] | 346 | } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 347 | HDoubleConstant* GetDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) { |
| 348 | 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] | 349 | } |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 350 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 351 | HCurrentMethod* GetCurrentMethod(); |
| 352 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 353 | HBasicBlock* FindCommonDominator(HBasicBlock* first, HBasicBlock* second) const; |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 354 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 355 | const DexFile& GetDexFile() const { |
| 356 | return dex_file_; |
| 357 | } |
| 358 | |
| 359 | uint32_t GetMethodIdx() const { |
| 360 | return method_idx_; |
| 361 | } |
| 362 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 363 | InvokeType GetInvokeType() const { |
| 364 | return invoke_type_; |
| 365 | } |
| 366 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 367 | InstructionSet GetInstructionSet() const { |
| 368 | return instruction_set_; |
| 369 | } |
| 370 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 371 | bool HasTryCatch() const { return has_try_catch_; } |
| 372 | void SetHasTryCatch(bool value) { has_try_catch_ = value; } |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 373 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 374 | private: |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 375 | void FindBackEdges(ArenaBitVector* visited); |
Roland Levillain | fc600dc | 2014-12-02 17:16:31 +0000 | [diff] [blame] | 376 | void RemoveInstructionsAsUsersFromDeadBlocks(const ArenaBitVector& visited) const; |
Nicolas Geoffray | f776b92 | 2015-04-15 18:22:45 +0100 | [diff] [blame] | 377 | void RemoveDeadBlocks(const ArenaBitVector& visited); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 378 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 379 | template <class InstructionType, typename ValueType> |
| 380 | InstructionType* CreateConstant(ValueType value, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 381 | ArenaSafeMap<ValueType, InstructionType*>* cache, |
| 382 | uint32_t dex_pc = kNoDexPc) { |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 383 | // Try to find an existing constant of the given value. |
| 384 | InstructionType* constant = nullptr; |
| 385 | auto cached_constant = cache->find(value); |
| 386 | if (cached_constant != cache->end()) { |
| 387 | constant = cached_constant->second; |
| 388 | } |
| 389 | |
| 390 | // If not found or previously deleted, create and cache a new instruction. |
Nicolas Geoffray | f78848f | 2015-06-17 11:57:56 +0100 | [diff] [blame] | 391 | // Don't bother reviving a previously deleted instruction, for simplicity. |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 392 | if (constant == nullptr || constant->GetBlock() == nullptr) { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 393 | constant = new (arena_) InstructionType(value, dex_pc); |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 394 | cache->Overwrite(value, constant); |
| 395 | InsertConstant(constant); |
| 396 | } |
| 397 | return constant; |
| 398 | } |
| 399 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 400 | void InsertConstant(HConstant* instruction); |
| 401 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 402 | // Cache a float constant into the graph. This method should only be |
| 403 | // called by the SsaBuilder when creating "equivalent" instructions. |
| 404 | void CacheFloatConstant(HFloatConstant* constant); |
| 405 | |
| 406 | // See CacheFloatConstant comment. |
| 407 | void CacheDoubleConstant(HDoubleConstant* constant); |
| 408 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 409 | ArenaAllocator* const arena_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 410 | |
| 411 | // List of blocks in insertion order. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 412 | ArenaVector<HBasicBlock*> blocks_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 413 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 414 | // List of blocks to perform a reverse post order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 415 | ArenaVector<HBasicBlock*> reverse_post_order_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 416 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 417 | // List of blocks to perform a linear order tree traversal. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 418 | ArenaVector<HBasicBlock*> linear_order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 419 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 420 | HBasicBlock* entry_block_; |
| 421 | HBasicBlock* exit_block_; |
| 422 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 423 | // 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] | 424 | uint16_t maximum_number_of_out_vregs_; |
| 425 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 426 | // The number of virtual registers in this method. Contains the parameters. |
| 427 | uint16_t number_of_vregs_; |
| 428 | |
| 429 | // The number of virtual registers used by parameters of this method. |
| 430 | uint16_t number_of_in_vregs_; |
| 431 | |
Calin Juravle | f97f9fb | 2014-11-11 15:38:19 +0000 | [diff] [blame] | 432 | // Number of vreg size slots that the temporaries use (used in baseline compiler). |
| 433 | size_t temporaries_vreg_slots_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 434 | |
Mark Mendell | 1152c92 | 2015-04-24 17:06:35 -0400 | [diff] [blame] | 435 | // Has bounds checks. We can totally skip BCE if it's false. |
| 436 | bool has_bounds_checks_; |
Mingyao Yang | e4335eb | 2015-03-02 15:14:13 -0800 | [diff] [blame] | 437 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 438 | // Flag whether there are any try/catch blocks in the graph. We will skip |
| 439 | // try/catch-related passes if false. |
| 440 | bool has_try_catch_; |
| 441 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 442 | // Indicates whether the graph should be compiled in a way that |
| 443 | // ensures full debuggability. If false, we can apply more |
| 444 | // aggressive optimizations that may limit the level of debugging. |
| 445 | const bool debuggable_; |
| 446 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 447 | // 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] | 448 | int32_t current_instruction_id_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 449 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 450 | // The dex file from which the method is from. |
| 451 | const DexFile& dex_file_; |
| 452 | |
| 453 | // The method index in the dex file. |
| 454 | const uint32_t method_idx_; |
| 455 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 456 | // If inlined, this encodes how the callee is being invoked. |
| 457 | const InvokeType invoke_type_; |
| 458 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 459 | // Whether the graph has been transformed to SSA form. Only used |
| 460 | // in debug mode to ensure we are not using properties only valid |
| 461 | // for non-SSA form (like the number of temporaries). |
| 462 | bool in_ssa_form_; |
| 463 | |
Calin Juravle | 3cd4fc8 | 2015-05-14 15:15:42 +0100 | [diff] [blame] | 464 | const bool should_generate_constructor_barrier_; |
| 465 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 466 | const InstructionSet instruction_set_; |
| 467 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 468 | // Cached constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 469 | HNullConstant* cached_null_constant_; |
| 470 | ArenaSafeMap<int32_t, HIntConstant*> cached_int_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 471 | ArenaSafeMap<int32_t, HFloatConstant*> cached_float_constants_; |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 472 | ArenaSafeMap<int64_t, HLongConstant*> cached_long_constants_; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 473 | ArenaSafeMap<int64_t, HDoubleConstant*> cached_double_constants_; |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 474 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 475 | HCurrentMethod* cached_current_method_; |
| 476 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 477 | friend class SsaBuilder; // For caching constants. |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 478 | friend class SsaLivenessAnalysis; // For the linear order. |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 479 | ART_FRIEND_TEST(GraphTest, IfSuccessorSimpleJoinBlock1); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 480 | DISALLOW_COPY_AND_ASSIGN(HGraph); |
| 481 | }; |
| 482 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 483 | class HLoopInformation : public ArenaObject<kArenaAllocLoopInfo> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 484 | public: |
| 485 | HLoopInformation(HBasicBlock* header, HGraph* graph) |
| 486 | : header_(header), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 487 | suspend_check_(nullptr), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 488 | back_edges_(graph->GetArena()->Adapter(kArenaAllocLoopInfoBackEdges)), |
Nicolas Geoffray | b09aacb | 2014-09-17 18:21:53 +0100 | [diff] [blame] | 489 | // Make bit vector growable, as the number of blocks may change. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 490 | blocks_(graph->GetArena(), graph->GetBlocks().size(), true) { |
| 491 | back_edges_.reserve(kDefaultNumberOfBackEdges); |
| 492 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 493 | |
| 494 | HBasicBlock* GetHeader() const { |
| 495 | return header_; |
| 496 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 497 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 498 | void SetHeader(HBasicBlock* block) { |
| 499 | header_ = block; |
| 500 | } |
| 501 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 502 | HSuspendCheck* GetSuspendCheck() const { return suspend_check_; } |
| 503 | void SetSuspendCheck(HSuspendCheck* check) { suspend_check_ = check; } |
| 504 | bool HasSuspendCheck() const { return suspend_check_ != nullptr; } |
| 505 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 506 | void AddBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 507 | back_edges_.push_back(back_edge); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 508 | } |
| 509 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 510 | void RemoveBackEdge(HBasicBlock* back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 511 | RemoveElement(back_edges_, back_edge); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 512 | } |
| 513 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 514 | bool IsBackEdge(const HBasicBlock& block) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 515 | return ContainsElement(back_edges_, &block); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Nicolas Geoffray | a8eed3a | 2014-11-24 17:47:10 +0000 | [diff] [blame] | 518 | size_t NumberOfBackEdges() const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 519 | return back_edges_.size(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 520 | } |
| 521 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 522 | HBasicBlock* GetPreHeader() const; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 523 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 524 | const ArenaVector<HBasicBlock*>& GetBackEdges() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 525 | return back_edges_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 528 | // Returns the lifetime position of the back edge that has the |
| 529 | // greatest lifetime position. |
| 530 | size_t GetLifetimeEnd() const; |
| 531 | |
| 532 | void ReplaceBackEdge(HBasicBlock* existing, HBasicBlock* new_back_edge) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 533 | ReplaceElement(back_edges_, existing, new_back_edge); |
Nicolas Geoffray | 5790260 | 2015-04-21 14:28:41 +0100 | [diff] [blame] | 534 | } |
| 535 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 536 | // 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] | 537 | // that is the header dominates the back edge. |
| 538 | bool Populate(); |
| 539 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 540 | // Reanalyzes the loop by removing loop info from its blocks and re-running |
| 541 | // Populate(). If there are no back edges left, the loop info is completely |
| 542 | // removed as well as its SuspendCheck instruction. It must be run on nested |
| 543 | // inner loops first. |
| 544 | void Update(); |
| 545 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 546 | // Returns whether this loop information contains `block`. |
| 547 | // Note that this loop information *must* be populated before entering this function. |
| 548 | bool Contains(const HBasicBlock& block) const; |
| 549 | |
| 550 | // Returns whether this loop information is an inner loop of `other`. |
| 551 | // Note that `other` *must* be populated before entering this function. |
| 552 | bool IsIn(const HLoopInformation& other) const; |
| 553 | |
| 554 | const ArenaBitVector& GetBlocks() const { return blocks_; } |
| 555 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 556 | void Add(HBasicBlock* block); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 557 | void Remove(HBasicBlock* block); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 558 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 559 | private: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 560 | // Internal recursive implementation of `Populate`. |
| 561 | void PopulateRecursive(HBasicBlock* block); |
| 562 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 563 | HBasicBlock* header_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 564 | HSuspendCheck* suspend_check_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 565 | ArenaVector<HBasicBlock*> back_edges_; |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 566 | ArenaBitVector blocks_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 567 | |
| 568 | DISALLOW_COPY_AND_ASSIGN(HLoopInformation); |
| 569 | }; |
| 570 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 571 | // Stores try/catch information for basic blocks. |
| 572 | // Note that HGraph is constructed so that catch blocks cannot simultaneously |
| 573 | // be try blocks. |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 574 | class TryCatchInformation : public ArenaObject<kArenaAllocTryCatchInfo> { |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 575 | public: |
| 576 | // Try block information constructor. |
| 577 | explicit TryCatchInformation(const HTryBoundary& try_entry) |
| 578 | : try_entry_(&try_entry), |
| 579 | catch_dex_file_(nullptr), |
| 580 | catch_type_index_(DexFile::kDexNoIndex16) { |
| 581 | DCHECK(try_entry_ != nullptr); |
| 582 | } |
| 583 | |
| 584 | // Catch block information constructor. |
| 585 | TryCatchInformation(uint16_t catch_type_index, const DexFile& dex_file) |
| 586 | : try_entry_(nullptr), |
| 587 | catch_dex_file_(&dex_file), |
| 588 | catch_type_index_(catch_type_index) {} |
| 589 | |
| 590 | bool IsTryBlock() const { return try_entry_ != nullptr; } |
| 591 | |
| 592 | const HTryBoundary& GetTryEntry() const { |
| 593 | DCHECK(IsTryBlock()); |
| 594 | return *try_entry_; |
| 595 | } |
| 596 | |
| 597 | bool IsCatchBlock() const { return catch_dex_file_ != nullptr; } |
| 598 | |
| 599 | bool IsCatchAllTypeIndex() const { |
| 600 | DCHECK(IsCatchBlock()); |
| 601 | return catch_type_index_ == DexFile::kDexNoIndex16; |
| 602 | } |
| 603 | |
| 604 | uint16_t GetCatchTypeIndex() const { |
| 605 | DCHECK(IsCatchBlock()); |
| 606 | return catch_type_index_; |
| 607 | } |
| 608 | |
| 609 | const DexFile& GetCatchDexFile() const { |
| 610 | DCHECK(IsCatchBlock()); |
| 611 | return *catch_dex_file_; |
| 612 | } |
| 613 | |
| 614 | private: |
| 615 | // One of possibly several TryBoundary instructions entering the block's try. |
| 616 | // Only set for try blocks. |
| 617 | const HTryBoundary* try_entry_; |
| 618 | |
| 619 | // Exception type information. Only set for catch blocks. |
| 620 | const DexFile* catch_dex_file_; |
| 621 | const uint16_t catch_type_index_; |
| 622 | }; |
| 623 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 624 | static constexpr size_t kNoLifetime = -1; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 625 | static constexpr uint32_t kInvalidBlockId = static_cast<uint32_t>(-1); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 626 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 627 | // A block in a method. Contains the list of instructions represented |
| 628 | // as a double linked list. Each block knows its predecessors and |
| 629 | // successors. |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 630 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 631 | class HBasicBlock : public ArenaObject<kArenaAllocBasicBlock> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 632 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 633 | HBasicBlock(HGraph* graph, uint32_t dex_pc = kNoDexPc) |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 634 | : graph_(graph), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 635 | predecessors_(graph->GetArena()->Adapter(kArenaAllocPredecessors)), |
| 636 | successors_(graph->GetArena()->Adapter(kArenaAllocSuccessors)), |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 637 | loop_information_(nullptr), |
| 638 | dominator_(nullptr), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 639 | dominated_blocks_(graph->GetArena()->Adapter(kArenaAllocDominated)), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 640 | block_id_(kInvalidBlockId), |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 641 | dex_pc_(dex_pc), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 642 | lifetime_start_(kNoLifetime), |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 643 | lifetime_end_(kNoLifetime), |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 644 | try_catch_information_(nullptr) { |
| 645 | predecessors_.reserve(kDefaultNumberOfPredecessors); |
| 646 | successors_.reserve(kDefaultNumberOfSuccessors); |
| 647 | dominated_blocks_.reserve(kDefaultNumberOfDominatedBlocks); |
| 648 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 649 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 650 | const ArenaVector<HBasicBlock*>& GetPredecessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 651 | return predecessors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 652 | } |
| 653 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 654 | const ArenaVector<HBasicBlock*>& GetSuccessors() const { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 655 | return successors_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 658 | bool HasSuccessor(const HBasicBlock* block, size_t start_from = 0u) { |
| 659 | return ContainsElement(successors_, block, start_from); |
| 660 | } |
| 661 | |
| 662 | const ArenaVector<HBasicBlock*>& GetDominatedBlocks() const { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 663 | return dominated_blocks_; |
| 664 | } |
| 665 | |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 666 | bool IsEntryBlock() const { |
| 667 | return graph_->GetEntryBlock() == this; |
| 668 | } |
| 669 | |
| 670 | bool IsExitBlock() const { |
| 671 | return graph_->GetExitBlock() == this; |
| 672 | } |
| 673 | |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 674 | bool IsSingleGoto() const; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 675 | bool IsSingleTryBoundary() const; |
| 676 | |
| 677 | // Returns true if this block emits nothing but a jump. |
| 678 | bool IsSingleJump() const { |
| 679 | HLoopInformation* loop_info = GetLoopInformation(); |
| 680 | return (IsSingleGoto() || IsSingleTryBoundary()) |
| 681 | // Back edges generate a suspend check. |
| 682 | && (loop_info == nullptr || !loop_info->IsBackEdge(*this)); |
| 683 | } |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 684 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 685 | void AddBackEdge(HBasicBlock* back_edge) { |
| 686 | if (loop_information_ == nullptr) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 687 | loop_information_ = new (graph_->GetArena()) HLoopInformation(this, graph_); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 688 | } |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 689 | DCHECK_EQ(loop_information_->GetHeader(), this); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 690 | loop_information_->AddBackEdge(back_edge); |
| 691 | } |
| 692 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 693 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 694 | void SetGraph(HGraph* graph) { graph_ = graph; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 695 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 696 | uint32_t GetBlockId() const { return block_id_; } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 697 | void SetBlockId(int id) { block_id_ = id; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 698 | uint32_t GetDexPc() const { return dex_pc_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 699 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 700 | HBasicBlock* GetDominator() const { return dominator_; } |
| 701 | void SetDominator(HBasicBlock* dominator) { dominator_ = dominator; } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 702 | void AddDominatedBlock(HBasicBlock* block) { dominated_blocks_.push_back(block); } |
| 703 | |
| 704 | void RemoveDominatedBlock(HBasicBlock* block) { |
| 705 | RemoveElement(dominated_blocks_, block); |
Vladimir Marko | 91e11c0 | 2015-09-02 17:03:22 +0100 | [diff] [blame] | 706 | } |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 707 | |
| 708 | void ReplaceDominatedBlock(HBasicBlock* existing, HBasicBlock* new_block) { |
| 709 | ReplaceElement(dominated_blocks_, existing, new_block); |
| 710 | } |
| 711 | |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 712 | void ClearDominanceInformation(); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 713 | |
| 714 | int NumberOfBackEdges() const { |
Nicolas Geoffray | 1f82ecc | 2015-06-24 12:20:24 +0100 | [diff] [blame] | 715 | return IsLoopHeader() ? loop_information_->NumberOfBackEdges() : 0; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 716 | } |
| 717 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 718 | HInstruction* GetFirstInstruction() const { return instructions_.first_instruction_; } |
| 719 | HInstruction* GetLastInstruction() const { return instructions_.last_instruction_; } |
Nicolas Geoffray | f635e63 | 2014-05-14 09:43:38 +0100 | [diff] [blame] | 720 | const HInstructionList& GetInstructions() const { return instructions_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 721 | HInstruction* GetFirstPhi() const { return phis_.first_instruction_; } |
David Brazdil | c3d743f | 2015-04-22 13:40:50 +0100 | [diff] [blame] | 722 | HInstruction* GetLastPhi() const { return phis_.last_instruction_; } |
| 723 | const HInstructionList& GetPhis() const { return phis_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 724 | |
| 725 | void AddSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 726 | successors_.push_back(block); |
| 727 | block->predecessors_.push_back(this); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 728 | } |
| 729 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 730 | void ReplaceSuccessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 731 | size_t successor_index = GetSuccessorIndexOf(existing); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 732 | existing->RemovePredecessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 733 | new_block->predecessors_.push_back(this); |
| 734 | successors_[successor_index] = new_block; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 735 | } |
| 736 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 737 | void ReplacePredecessor(HBasicBlock* existing, HBasicBlock* new_block) { |
| 738 | size_t predecessor_index = GetPredecessorIndexOf(existing); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 739 | existing->RemoveSuccessor(this); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 740 | new_block->successors_.push_back(this); |
| 741 | predecessors_[predecessor_index] = new_block; |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 744 | // Insert `this` between `predecessor` and `successor. This method |
| 745 | // preserves the indicies, and will update the first edge found between |
| 746 | // `predecessor` and `successor`. |
| 747 | void InsertBetween(HBasicBlock* predecessor, HBasicBlock* successor) { |
| 748 | size_t predecessor_index = successor->GetPredecessorIndexOf(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 749 | size_t successor_index = predecessor->GetSuccessorIndexOf(successor); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 750 | successor->predecessors_[predecessor_index] = this; |
| 751 | predecessor->successors_[successor_index] = this; |
| 752 | successors_.push_back(successor); |
| 753 | predecessors_.push_back(predecessor); |
Nicolas Geoffray | 8b20f88 | 2015-06-19 16:17:05 +0100 | [diff] [blame] | 754 | } |
| 755 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 756 | void RemovePredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 757 | predecessors_.erase(predecessors_.begin() + GetPredecessorIndexOf(block)); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 758 | } |
| 759 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 760 | void RemoveSuccessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 761 | successors_.erase(successors_.begin() + GetSuccessorIndexOf(block)); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 762 | } |
| 763 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 764 | void ClearAllPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 765 | predecessors_.clear(); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | void AddPredecessor(HBasicBlock* block) { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 769 | predecessors_.push_back(block); |
| 770 | block->successors_.push_back(this); |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 771 | } |
| 772 | |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 773 | void SwapPredecessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 774 | DCHECK_EQ(predecessors_.size(), 2u); |
| 775 | std::swap(predecessors_[0], predecessors_[1]); |
Nicolas Geoffray | 604c6e4 | 2014-09-17 12:08:44 +0100 | [diff] [blame] | 776 | } |
| 777 | |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 778 | void SwapSuccessors() { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 779 | DCHECK_EQ(successors_.size(), 2u); |
| 780 | std::swap(successors_[0], successors_[1]); |
David Brazdil | 769c9e5 | 2015-04-27 13:54:09 +0100 | [diff] [blame] | 781 | } |
| 782 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 783 | size_t GetPredecessorIndexOf(HBasicBlock* predecessor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 784 | return IndexOfElement(predecessors_, predecessor); |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 785 | } |
| 786 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 787 | size_t GetSuccessorIndexOf(HBasicBlock* successor) const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 788 | return IndexOfElement(successors_, successor); |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 789 | } |
| 790 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 791 | HBasicBlock* GetSinglePredecessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 792 | DCHECK_EQ(GetPredecessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 793 | return GetPredecessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 794 | } |
| 795 | |
| 796 | HBasicBlock* GetSingleSuccessor() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 797 | DCHECK_EQ(GetSuccessors().size(), 1u); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 798 | return GetSuccessors()[0]; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 799 | } |
| 800 | |
| 801 | // Returns whether the first occurrence of `predecessor` in the list of |
| 802 | // predecessors is at index `idx`. |
| 803 | bool IsFirstIndexOfPredecessor(HBasicBlock* predecessor, size_t idx) const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 804 | DCHECK_EQ(GetPredecessors()[idx], predecessor); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 805 | return GetPredecessorIndexOf(predecessor) == idx; |
| 806 | } |
| 807 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 808 | // Returns the number of non-exceptional successors. SsaChecker ensures that |
| 809 | // these are stored at the beginning of the successor list. |
| 810 | size_t NumberOfNormalSuccessors() const { |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 811 | return EndsWithTryBoundary() ? 1 : GetSuccessors().size(); |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 812 | } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 813 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 814 | // Create a new block between this block and its predecessors. The new block |
| 815 | // is added to the graph, all predecessor edges are relinked to it and an edge |
| 816 | // is created to `this`. Returns the new empty block. Reverse post order or |
| 817 | // loop and try/catch information are not updated. |
| 818 | HBasicBlock* CreateImmediateDominator(); |
| 819 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 820 | // Split the block into two blocks just before `cursor`. Returns the newly |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 821 | // created, latter block. Note that this method will add the block to the |
| 822 | // graph, create a Goto at the end of the former block and will create an edge |
| 823 | // 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] | 824 | // loop and try/catch information. |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 825 | HBasicBlock* SplitBefore(HInstruction* cursor); |
| 826 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 827 | // Split the block into two blocks just after `cursor`. Returns the newly |
| 828 | // created block. Note that this method just updates raw block information, |
| 829 | // like predecessors, successors, dominators, and instruction list. It does not |
| 830 | // update the graph, reverse post order, loop information, nor make sure the |
| 831 | // blocks are consistent (for example ending with a control flow instruction). |
| 832 | HBasicBlock* SplitAfter(HInstruction* cursor); |
| 833 | |
| 834 | // Merge `other` at the end of `this`. Successors and dominated blocks of |
| 835 | // `other` are changed to be successors and dominated blocks of `this`. Note |
| 836 | // that this method does not update the graph, reverse post order, loop |
| 837 | // information, nor make sure the blocks are consistent (for example ending |
| 838 | // with a control flow instruction). |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 839 | void MergeWithInlined(HBasicBlock* other); |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 840 | |
| 841 | // Replace `this` with `other`. Predecessors, successors, and dominated blocks |
| 842 | // of `this` are moved to `other`. |
| 843 | // Note that this method does not update the graph, reverse post order, loop |
| 844 | // information, nor make sure the blocks are consistent (for example ending |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 845 | // with a control flow instruction). |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 846 | void ReplaceWith(HBasicBlock* other); |
| 847 | |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 848 | // Merge `other` at the end of `this`. This method updates loops, reverse post |
| 849 | // order, links to predecessors, successors, dominators and deletes the block |
| 850 | // from the graph. The two blocks must be successive, i.e. `this` the only |
| 851 | // predecessor of `other` and vice versa. |
| 852 | void MergeWith(HBasicBlock* other); |
| 853 | |
| 854 | // Disconnects `this` from all its predecessors, successors and dominator, |
| 855 | // removes it from all loops it is included in and eventually from the graph. |
| 856 | // The block must not dominate any other block. Predecessors and successors |
| 857 | // are safely updated. |
| 858 | void DisconnectAndDelete(); |
David Brazdil | 46e2a39 | 2015-03-16 17:31:52 +0000 | [diff] [blame] | 859 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 860 | void AddInstruction(HInstruction* instruction); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 861 | // Insert `instruction` before/after an existing instruction `cursor`. |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 862 | void InsertInstructionBefore(HInstruction* instruction, HInstruction* cursor); |
Guillaume "Vermeille" Sanchez | 2967ec6 | 2015-04-24 16:36:52 +0100 | [diff] [blame] | 863 | void InsertInstructionAfter(HInstruction* instruction, HInstruction* cursor); |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 864 | // Replace instruction `initial` with `replacement` within this block. |
| 865 | void ReplaceAndRemoveInstructionWith(HInstruction* initial, |
| 866 | HInstruction* replacement); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 867 | void AddPhi(HPhi* phi); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 868 | void InsertPhiAfter(HPhi* instruction, HPhi* cursor); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 869 | // RemoveInstruction and RemovePhi delete a given instruction from the respective |
| 870 | // instruction list. With 'ensure_safety' set to true, it verifies that the |
| 871 | // instruction is not in use and removes it from the use lists of its inputs. |
| 872 | void RemoveInstruction(HInstruction* instruction, bool ensure_safety = true); |
| 873 | void RemovePhi(HPhi* phi, bool ensure_safety = true); |
David Brazdil | c7508e9 | 2015-04-27 13:28:57 +0100 | [diff] [blame] | 874 | void RemoveInstructionOrPhi(HInstruction* instruction, bool ensure_safety = true); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 875 | |
| 876 | bool IsLoopHeader() const { |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 877 | return IsInLoop() && (loop_information_->GetHeader() == this); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 878 | } |
| 879 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 880 | bool IsLoopPreHeaderFirstPredecessor() const { |
| 881 | DCHECK(IsLoopHeader()); |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 882 | return GetPredecessors()[0] == GetLoopInformation()->GetPreHeader(); |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 883 | } |
| 884 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 885 | HLoopInformation* GetLoopInformation() const { |
| 886 | return loop_information_; |
| 887 | } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 888 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 889 | // Set the loop_information_ on this block. Overrides the current |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 890 | // 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] | 891 | // Note that this method is called while creating the loop information. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 892 | void SetInLoop(HLoopInformation* info) { |
| 893 | if (IsLoopHeader()) { |
| 894 | // Nothing to do. This just means `info` is an outer loop. |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 895 | } else if (!IsInLoop()) { |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 896 | loop_information_ = info; |
| 897 | } else if (loop_information_->Contains(*info->GetHeader())) { |
| 898 | // Block is currently part of an outer loop. Make it part of this inner loop. |
| 899 | // Note that a non loop header having a loop information means this loop information |
| 900 | // has already been populated |
| 901 | loop_information_ = info; |
| 902 | } else { |
| 903 | // Block is part of an inner loop. Do not update the loop information. |
| 904 | // Note that we cannot do the check `info->Contains(loop_information_)->GetHeader()` |
| 905 | // at this point, because this method is being called while populating `info`. |
| 906 | } |
| 907 | } |
| 908 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 909 | // Raw update of the loop information. |
| 910 | void SetLoopInformation(HLoopInformation* info) { |
| 911 | loop_information_ = info; |
| 912 | } |
| 913 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 914 | bool IsInLoop() const { return loop_information_ != nullptr; } |
| 915 | |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 916 | TryCatchInformation* GetTryCatchInformation() const { return try_catch_information_; } |
| 917 | |
| 918 | void SetTryCatchInformation(TryCatchInformation* try_catch_information) { |
| 919 | try_catch_information_ = try_catch_information; |
| 920 | } |
| 921 | |
| 922 | bool IsTryBlock() const { |
| 923 | return try_catch_information_ != nullptr && try_catch_information_->IsTryBlock(); |
| 924 | } |
| 925 | |
| 926 | bool IsCatchBlock() const { |
| 927 | return try_catch_information_ != nullptr && try_catch_information_->IsCatchBlock(); |
| 928 | } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 929 | |
| 930 | // Returns the try entry that this block's successors should have. They will |
| 931 | // be in the same try, unless the block ends in a try boundary. In that case, |
| 932 | // the appropriate try entry will be returned. |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 933 | const HTryBoundary* ComputeTryEntryOfSuccessors() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 934 | |
David Brazdil | d7558da | 2015-09-22 13:04:14 +0100 | [diff] [blame] | 935 | bool HasThrowingInstructions() const; |
| 936 | |
David Brazdil | a4b8c21 | 2015-05-07 09:59:30 +0100 | [diff] [blame] | 937 | // Returns whether this block dominates the blocked passed as parameter. |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 938 | bool Dominates(HBasicBlock* block) const; |
| 939 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 940 | size_t GetLifetimeStart() const { return lifetime_start_; } |
| 941 | size_t GetLifetimeEnd() const { return lifetime_end_; } |
| 942 | |
| 943 | void SetLifetimeStart(size_t start) { lifetime_start_ = start; } |
| 944 | void SetLifetimeEnd(size_t end) { lifetime_end_ = end; } |
| 945 | |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 946 | bool EndsWithControlFlowInstruction() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 947 | bool EndsWithIf() const; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 948 | bool EndsWithTryBoundary() const; |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 949 | bool HasSinglePhi() const; |
| 950 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 951 | private: |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 952 | HGraph* graph_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 953 | ArenaVector<HBasicBlock*> predecessors_; |
| 954 | ArenaVector<HBasicBlock*> successors_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 955 | HInstructionList instructions_; |
| 956 | HInstructionList phis_; |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 957 | HLoopInformation* loop_information_; |
| 958 | HBasicBlock* dominator_; |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 959 | ArenaVector<HBasicBlock*> dominated_blocks_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 960 | uint32_t block_id_; |
Nicolas Geoffray | 3c04974 | 2014-09-24 18:10:46 +0100 | [diff] [blame] | 961 | // The dex program counter of the first instruction of this block. |
| 962 | const uint32_t dex_pc_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 963 | size_t lifetime_start_; |
| 964 | size_t lifetime_end_; |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 965 | TryCatchInformation* try_catch_information_; |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 966 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 967 | friend class HGraph; |
| 968 | friend class HInstruction; |
| 969 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 970 | DISALLOW_COPY_AND_ASSIGN(HBasicBlock); |
| 971 | }; |
| 972 | |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 973 | // Iterates over the LoopInformation of all loops which contain 'block' |
| 974 | // from the innermost to the outermost. |
| 975 | class HLoopInformationOutwardIterator : public ValueObject { |
| 976 | public: |
| 977 | explicit HLoopInformationOutwardIterator(const HBasicBlock& block) |
| 978 | : current_(block.GetLoopInformation()) {} |
| 979 | |
| 980 | bool Done() const { return current_ == nullptr; } |
| 981 | |
| 982 | void Advance() { |
| 983 | DCHECK(!Done()); |
David Brazdil | 69a2804 | 2015-04-29 17:16:07 +0100 | [diff] [blame] | 984 | current_ = current_->GetPreHeader()->GetLoopInformation(); |
David Brazdil | b2bd1c5 | 2015-03-25 11:17:37 +0000 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | HLoopInformation* Current() const { |
| 988 | DCHECK(!Done()); |
| 989 | return current_; |
| 990 | } |
| 991 | |
| 992 | private: |
| 993 | HLoopInformation* current_; |
| 994 | |
| 995 | DISALLOW_COPY_AND_ASSIGN(HLoopInformationOutwardIterator); |
| 996 | }; |
| 997 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 998 | #define FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 999 | M(Above, Condition) \ |
| 1000 | M(AboveOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1001 | M(Add, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1002 | M(And, BinaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1003 | M(ArrayGet, Instruction) \ |
| 1004 | M(ArrayLength, Instruction) \ |
| 1005 | M(ArraySet, Instruction) \ |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 1006 | M(Below, Condition) \ |
| 1007 | M(BelowOrEqual, Condition) \ |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 1008 | M(BooleanNot, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1009 | M(BoundsCheck, Instruction) \ |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1010 | M(BoundType, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1011 | M(CheckCast, Instruction) \ |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 1012 | M(ClearException, Instruction) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1013 | M(ClinitCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1014 | M(Compare, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1015 | M(Condition, BinaryOperation) \ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 1016 | M(CurrentMethod, Instruction) \ |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 1017 | M(Deoptimize, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1018 | M(Div, BinaryOperation) \ |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 1019 | M(DivZeroCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1020 | M(DoubleConstant, Constant) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1021 | M(Equal, Condition) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1022 | M(Exit, Instruction) \ |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1023 | M(FakeString, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1024 | M(FloatConstant, Constant) \ |
| 1025 | M(Goto, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1026 | M(GreaterThan, Condition) \ |
| 1027 | M(GreaterThanOrEqual, Condition) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1028 | M(If, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1029 | M(InstanceFieldGet, Instruction) \ |
| 1030 | M(InstanceFieldSet, Instruction) \ |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 1031 | M(InstanceOf, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1032 | M(IntConstant, Constant) \ |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 1033 | M(InvokeUnresolved, Invoke) \ |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 1034 | M(InvokeInterface, Invoke) \ |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1035 | M(InvokeStaticOrDirect, Invoke) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1036 | M(InvokeVirtual, Invoke) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1037 | M(LessThan, Condition) \ |
| 1038 | M(LessThanOrEqual, Condition) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1039 | M(LoadClass, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1040 | M(LoadException, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1041 | M(LoadLocal, Instruction) \ |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 1042 | M(LoadString, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1043 | M(Local, Instruction) \ |
| 1044 | M(LongConstant, Constant) \ |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 1045 | M(MemoryBarrier, Instruction) \ |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 1046 | M(MonitorOperation, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1047 | M(Mul, BinaryOperation) \ |
| 1048 | M(Neg, UnaryOperation) \ |
| 1049 | M(NewArray, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1050 | M(NewInstance, Instruction) \ |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 1051 | M(Not, UnaryOperation) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1052 | M(NotEqual, Condition) \ |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1053 | M(NullConstant, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1054 | M(NullCheck, Instruction) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1055 | M(Or, BinaryOperation) \ |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 1056 | M(PackedSwitch, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1057 | M(ParallelMove, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1058 | M(ParameterValue, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1059 | M(Phi, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1060 | M(Rem, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1061 | M(Return, Instruction) \ |
| 1062 | M(ReturnVoid, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1063 | M(Shl, BinaryOperation) \ |
| 1064 | M(Shr, BinaryOperation) \ |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 1065 | M(StaticFieldGet, Instruction) \ |
| 1066 | M(StaticFieldSet, Instruction) \ |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1067 | M(UnresolvedInstanceFieldGet, Instruction) \ |
| 1068 | M(UnresolvedInstanceFieldSet, Instruction) \ |
| 1069 | M(UnresolvedStaticFieldGet, Instruction) \ |
| 1070 | M(UnresolvedStaticFieldSet, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1071 | M(StoreLocal, Instruction) \ |
| 1072 | M(Sub, BinaryOperation) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1073 | M(SuspendCheck, Instruction) \ |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 1074 | M(Temporary, Instruction) \ |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 1075 | M(Throw, Instruction) \ |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 1076 | M(TryBoundary, Instruction) \ |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 1077 | M(TypeConversion, Instruction) \ |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1078 | M(UShr, BinaryOperation) \ |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 1079 | M(Xor, BinaryOperation) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1080 | |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1081 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) |
| 1082 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1083 | #ifndef ART_ENABLE_CODEGEN_arm64 |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1084 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1085 | #else |
| 1086 | #define FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
| 1087 | M(Arm64IntermediateAddress, Instruction) |
| 1088 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1089 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1090 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) |
| 1091 | |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1092 | #define FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) |
| 1093 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1094 | #ifndef ART_ENABLE_CODEGEN_x86 |
| 1095 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) |
| 1096 | #else |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 1097 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1098 | M(X86ComputeBaseMethodAddress, Instruction) \ |
Mark Mendell | 805b3b5 | 2015-09-18 14:10:29 -0400 | [diff] [blame] | 1099 | M(X86LoadFromConstantTable, Instruction) \ |
| 1100 | M(X86PackedSwitch, Instruction) |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1101 | #endif |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1102 | |
| 1103 | #define FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1104 | |
| 1105 | #define FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1106 | FOR_EACH_CONCRETE_INSTRUCTION_COMMON(M) \ |
| 1107 | FOR_EACH_CONCRETE_INSTRUCTION_ARM(M) \ |
| 1108 | FOR_EACH_CONCRETE_INSTRUCTION_ARM64(M) \ |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 1109 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS(M) \ |
Alexandre Rames | f39e064 | 2015-06-23 11:33:45 +0100 | [diff] [blame] | 1110 | FOR_EACH_CONCRETE_INSTRUCTION_MIPS64(M) \ |
Alexandre Rames | ef20f71 | 2015-06-09 10:29:30 +0100 | [diff] [blame] | 1111 | FOR_EACH_CONCRETE_INSTRUCTION_X86(M) \ |
| 1112 | FOR_EACH_CONCRETE_INSTRUCTION_X86_64(M) |
| 1113 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1114 | #define FOR_EACH_INSTRUCTION(M) \ |
| 1115 | FOR_EACH_CONCRETE_INSTRUCTION(M) \ |
| 1116 | M(Constant, Instruction) \ |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 1117 | M(UnaryOperation, Instruction) \ |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 1118 | M(BinaryOperation, Instruction) \ |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1119 | M(Invoke, Instruction) |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1120 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1121 | #define FORWARD_DECLARATION(type, super) class H##type; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1122 | FOR_EACH_INSTRUCTION(FORWARD_DECLARATION) |
| 1123 | #undef FORWARD_DECLARATION |
| 1124 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1125 | #define DECLARE_INSTRUCTION(type) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1126 | InstructionKind GetKind() const OVERRIDE { return k##type; } \ |
| 1127 | const char* DebugName() const OVERRIDE { return #type; } \ |
| 1128 | const H##type* As##type() const OVERRIDE { return this; } \ |
| 1129 | H##type* As##type() OVERRIDE { return this; } \ |
| 1130 | bool InstructionTypeEquals(HInstruction* other) const OVERRIDE { \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1131 | return other->Is##type(); \ |
| 1132 | } \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 1133 | void Accept(HGraphVisitor* visitor) OVERRIDE |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1134 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1135 | template <typename T> class HUseList; |
| 1136 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1137 | template <typename T> |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1138 | class HUseListNode : public ArenaObject<kArenaAllocUseListNode> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1139 | public: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1140 | HUseListNode* GetPrevious() const { return prev_; } |
| 1141 | HUseListNode* GetNext() const { return next_; } |
| 1142 | T GetUser() const { return user_; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1143 | size_t GetIndex() const { return index_; } |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1144 | void SetIndex(size_t index) { index_ = index; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1145 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1146 | private: |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1147 | HUseListNode(T user, size_t index) |
| 1148 | : user_(user), index_(index), prev_(nullptr), next_(nullptr) {} |
| 1149 | |
| 1150 | T const user_; |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1151 | size_t index_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1152 | HUseListNode<T>* prev_; |
| 1153 | HUseListNode<T>* next_; |
| 1154 | |
| 1155 | friend class HUseList<T>; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1156 | |
| 1157 | DISALLOW_COPY_AND_ASSIGN(HUseListNode); |
| 1158 | }; |
| 1159 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1160 | template <typename T> |
| 1161 | class HUseList : public ValueObject { |
| 1162 | public: |
| 1163 | HUseList() : first_(nullptr) {} |
| 1164 | |
| 1165 | void Clear() { |
| 1166 | first_ = nullptr; |
| 1167 | } |
| 1168 | |
| 1169 | // Adds a new entry at the beginning of the use list and returns |
| 1170 | // the newly created node. |
| 1171 | HUseListNode<T>* AddUse(T user, size_t index, ArenaAllocator* arena) { |
David Brazdil | ea55b93 | 2015-01-27 17:12:29 +0000 | [diff] [blame] | 1172 | HUseListNode<T>* new_node = new (arena) HUseListNode<T>(user, index); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1173 | if (IsEmpty()) { |
| 1174 | first_ = new_node; |
| 1175 | } else { |
| 1176 | first_->prev_ = new_node; |
| 1177 | new_node->next_ = first_; |
| 1178 | first_ = new_node; |
| 1179 | } |
| 1180 | return new_node; |
| 1181 | } |
| 1182 | |
| 1183 | HUseListNode<T>* GetFirst() const { |
| 1184 | return first_; |
| 1185 | } |
| 1186 | |
| 1187 | void Remove(HUseListNode<T>* node) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1188 | DCHECK(node != nullptr); |
| 1189 | DCHECK(Contains(node)); |
| 1190 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1191 | if (node->prev_ != nullptr) { |
| 1192 | node->prev_->next_ = node->next_; |
| 1193 | } |
| 1194 | if (node->next_ != nullptr) { |
| 1195 | node->next_->prev_ = node->prev_; |
| 1196 | } |
| 1197 | if (node == first_) { |
| 1198 | first_ = node->next_; |
| 1199 | } |
| 1200 | } |
| 1201 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1202 | bool Contains(const HUseListNode<T>* node) const { |
| 1203 | if (node == nullptr) { |
| 1204 | return false; |
| 1205 | } |
| 1206 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1207 | if (current == node) { |
| 1208 | return true; |
| 1209 | } |
| 1210 | } |
| 1211 | return false; |
| 1212 | } |
| 1213 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1214 | bool IsEmpty() const { |
| 1215 | return first_ == nullptr; |
| 1216 | } |
| 1217 | |
| 1218 | bool HasOnlyOneUse() const { |
| 1219 | return first_ != nullptr && first_->next_ == nullptr; |
| 1220 | } |
| 1221 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1222 | size_t SizeSlow() const { |
| 1223 | size_t count = 0; |
| 1224 | for (HUseListNode<T>* current = first_; current != nullptr; current = current->GetNext()) { |
| 1225 | ++count; |
| 1226 | } |
| 1227 | return count; |
| 1228 | } |
| 1229 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1230 | private: |
| 1231 | HUseListNode<T>* first_; |
| 1232 | }; |
| 1233 | |
| 1234 | template<typename T> |
| 1235 | class HUseIterator : public ValueObject { |
| 1236 | public: |
| 1237 | explicit HUseIterator(const HUseList<T>& uses) : current_(uses.GetFirst()) {} |
| 1238 | |
| 1239 | bool Done() const { return current_ == nullptr; } |
| 1240 | |
| 1241 | void Advance() { |
| 1242 | DCHECK(!Done()); |
| 1243 | current_ = current_->GetNext(); |
| 1244 | } |
| 1245 | |
| 1246 | HUseListNode<T>* Current() const { |
| 1247 | DCHECK(!Done()); |
| 1248 | return current_; |
| 1249 | } |
| 1250 | |
| 1251 | private: |
| 1252 | HUseListNode<T>* current_; |
| 1253 | |
| 1254 | friend class HValue; |
| 1255 | }; |
| 1256 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1257 | // This class is used by HEnvironment and HInstruction classes to record the |
| 1258 | // instructions they use and pointers to the corresponding HUseListNodes kept |
| 1259 | // by the used instructions. |
| 1260 | template <typename T> |
Vladimir Marko | 76c92ac | 2015-09-17 15:39:16 +0100 | [diff] [blame] | 1261 | class HUserRecord : public ValueObject { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1262 | public: |
| 1263 | HUserRecord() : instruction_(nullptr), use_node_(nullptr) {} |
| 1264 | explicit HUserRecord(HInstruction* instruction) : instruction_(instruction), use_node_(nullptr) {} |
| 1265 | |
| 1266 | HUserRecord(const HUserRecord<T>& old_record, HUseListNode<T>* use_node) |
| 1267 | : instruction_(old_record.instruction_), use_node_(use_node) { |
| 1268 | DCHECK(instruction_ != nullptr); |
| 1269 | DCHECK(use_node_ != nullptr); |
| 1270 | DCHECK(old_record.use_node_ == nullptr); |
| 1271 | } |
| 1272 | |
| 1273 | HInstruction* GetInstruction() const { return instruction_; } |
| 1274 | HUseListNode<T>* GetUseNode() const { return use_node_; } |
| 1275 | |
| 1276 | private: |
| 1277 | // Instruction used by the user. |
| 1278 | HInstruction* instruction_; |
| 1279 | |
| 1280 | // Corresponding entry in the use list kept by 'instruction_'. |
| 1281 | HUseListNode<T>* use_node_; |
| 1282 | }; |
| 1283 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1284 | /** |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1285 | * Side-effects representation. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1286 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1287 | * For write/read dependences on fields/arrays, the dependence analysis uses |
| 1288 | * type disambiguation (e.g. a float field write cannot modify the value of an |
| 1289 | * integer field read) and the access type (e.g. a reference array write cannot |
| 1290 | * modify the value of a reference field read [although it may modify the |
| 1291 | * reference fetch prior to reading the field, which is represented by its own |
| 1292 | * write/read dependence]). The analysis makes conservative points-to |
| 1293 | * assumptions on reference types (e.g. two same typed arrays are assumed to be |
| 1294 | * the same, and any reference read depends on any reference read without |
| 1295 | * further regard of its type). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1296 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1297 | * The internal representation uses 38-bit and is described in the table below. |
| 1298 | * The first line indicates the side effect, and for field/array accesses the |
| 1299 | * second line indicates the type of the access (in the order of the |
| 1300 | * Primitive::Type enum). |
| 1301 | * The two numbered lines below indicate the bit position in the bitfield (read |
| 1302 | * vertically). |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1303 | * |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1304 | * |Depends on GC|ARRAY-R |FIELD-R |Can trigger GC|ARRAY-W |FIELD-W | |
| 1305 | * +-------------+---------+---------+--------------+---------+---------+ |
| 1306 | * | |DFJISCBZL|DFJISCBZL| |DFJISCBZL|DFJISCBZL| |
| 1307 | * | 3 |333333322|222222221| 1 |111111110|000000000| |
| 1308 | * | 7 |654321098|765432109| 8 |765432109|876543210| |
| 1309 | * |
| 1310 | * Note that, to ease the implementation, 'changes' bits are least significant |
| 1311 | * bits, while 'dependency' bits are most significant bits. |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1312 | */ |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1313 | class SideEffects : public ValueObject { |
| 1314 | public: |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1315 | SideEffects() : flags_(0) {} |
| 1316 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1317 | static SideEffects None() { |
| 1318 | return SideEffects(0); |
| 1319 | } |
| 1320 | |
| 1321 | static SideEffects All() { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1322 | return SideEffects(kAllChangeBits | kAllDependOnBits); |
| 1323 | } |
| 1324 | |
| 1325 | static SideEffects AllChanges() { |
| 1326 | return SideEffects(kAllChangeBits); |
| 1327 | } |
| 1328 | |
| 1329 | static SideEffects AllDependencies() { |
| 1330 | return SideEffects(kAllDependOnBits); |
| 1331 | } |
| 1332 | |
| 1333 | static SideEffects AllExceptGCDependency() { |
| 1334 | return AllWritesAndReads().Union(SideEffects::CanTriggerGC()); |
| 1335 | } |
| 1336 | |
| 1337 | static SideEffects AllWritesAndReads() { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1338 | return SideEffects(kAllWrites | kAllReads); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1339 | } |
| 1340 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1341 | static SideEffects AllWrites() { |
| 1342 | return SideEffects(kAllWrites); |
| 1343 | } |
| 1344 | |
| 1345 | static SideEffects AllReads() { |
| 1346 | return SideEffects(kAllReads); |
| 1347 | } |
| 1348 | |
| 1349 | static SideEffects FieldWriteOfType(Primitive::Type type, bool is_volatile) { |
| 1350 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1351 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1352 | : SideEffects(TypeFlagWithAlias(type, kFieldWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1353 | } |
| 1354 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1355 | static SideEffects ArrayWriteOfType(Primitive::Type type) { |
| 1356 | return SideEffects(TypeFlagWithAlias(type, kArrayWriteOffset)); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1357 | } |
| 1358 | |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1359 | static SideEffects FieldReadOfType(Primitive::Type type, bool is_volatile) { |
| 1360 | return is_volatile |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1361 | ? AllWritesAndReads() |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 1362 | : SideEffects(TypeFlagWithAlias(type, kFieldReadOffset)); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1363 | } |
| 1364 | |
| 1365 | static SideEffects ArrayReadOfType(Primitive::Type type) { |
| 1366 | return SideEffects(TypeFlagWithAlias(type, kArrayReadOffset)); |
| 1367 | } |
| 1368 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1369 | static SideEffects CanTriggerGC() { |
| 1370 | return SideEffects(1ULL << kCanTriggerGCBit); |
| 1371 | } |
| 1372 | |
| 1373 | static SideEffects DependsOnGC() { |
| 1374 | return SideEffects(1ULL << kDependsOnGCBit); |
| 1375 | } |
| 1376 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1377 | // Combines the side-effects of this and the other. |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1378 | SideEffects Union(SideEffects other) const { |
| 1379 | return SideEffects(flags_ | other.flags_); |
| 1380 | } |
| 1381 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1382 | SideEffects Exclusion(SideEffects other) const { |
| 1383 | return SideEffects(flags_ & ~other.flags_); |
| 1384 | } |
| 1385 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1386 | void Add(SideEffects other) { |
| 1387 | flags_ |= other.flags_; |
| 1388 | } |
| 1389 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1390 | bool Includes(SideEffects other) const { |
| 1391 | return (other.flags_ & flags_) == other.flags_; |
| 1392 | } |
| 1393 | |
| 1394 | bool HasSideEffects() const { |
| 1395 | return (flags_ & kAllChangeBits); |
| 1396 | } |
| 1397 | |
| 1398 | bool HasDependencies() const { |
| 1399 | return (flags_ & kAllDependOnBits); |
| 1400 | } |
| 1401 | |
| 1402 | // Returns true if there are no side effects or dependencies. |
| 1403 | bool DoesNothing() const { |
| 1404 | return flags_ == 0; |
| 1405 | } |
| 1406 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1407 | // Returns true if something is written. |
| 1408 | bool DoesAnyWrite() const { |
| 1409 | return (flags_ & kAllWrites); |
Roland Levillain | 72bceff | 2014-09-15 18:29:00 +0100 | [diff] [blame] | 1410 | } |
| 1411 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1412 | // Returns true if something is read. |
| 1413 | bool DoesAnyRead() const { |
| 1414 | return (flags_ & kAllReads); |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1415 | } |
| 1416 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1417 | // Returns true if potentially everything is written and read |
| 1418 | // (every type and every kind of access). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1419 | bool DoesAllReadWrite() const { |
| 1420 | return (flags_ & (kAllWrites | kAllReads)) == (kAllWrites | kAllReads); |
| 1421 | } |
| 1422 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1423 | bool DoesAll() const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1424 | return flags_ == (kAllChangeBits | kAllDependOnBits); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1425 | } |
| 1426 | |
| 1427 | // Returns true if this may read something written by other. |
| 1428 | bool MayDependOn(SideEffects other) const { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1429 | const uint64_t depends_on_flags = (flags_ & kAllDependOnBits) >> kChangeBits; |
| 1430 | return (other.flags_ & depends_on_flags); |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1431 | } |
| 1432 | |
| 1433 | // Returns string representation of flags (for debugging only). |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1434 | // Format: |x|DFJISCBZL|DFJISCBZL|y|DFJISCBZL|DFJISCBZL| |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1435 | std::string ToString() const { |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1436 | std::string flags = "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1437 | for (int s = kLastBit; s >= 0; s--) { |
| 1438 | bool current_bit_is_set = ((flags_ >> s) & 1) != 0; |
| 1439 | if ((s == kDependsOnGCBit) || (s == kCanTriggerGCBit)) { |
| 1440 | // This is a bit for the GC side effect. |
| 1441 | if (current_bit_is_set) { |
| 1442 | flags += "GC"; |
| 1443 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1444 | flags += "|"; |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1445 | } else { |
| 1446 | // This is a bit for the array/field analysis. |
| 1447 | // The underscore character stands for the 'can trigger GC' bit. |
| 1448 | static const char *kDebug = "LZBCSIJFDLZBCSIJFD_LZBCSIJFDLZBCSIJFD"; |
| 1449 | if (current_bit_is_set) { |
| 1450 | flags += kDebug[s]; |
| 1451 | } |
| 1452 | if ((s == kFieldWriteOffset) || (s == kArrayWriteOffset) || |
| 1453 | (s == kFieldReadOffset) || (s == kArrayReadOffset)) { |
| 1454 | flags += "|"; |
| 1455 | } |
| 1456 | } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1457 | } |
| 1458 | return flags; |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1459 | } |
| 1460 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1461 | bool Equals(const SideEffects& other) const { return flags_ == other.flags_; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1462 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1463 | private: |
| 1464 | static constexpr int kFieldArrayAnalysisBits = 9; |
| 1465 | |
| 1466 | static constexpr int kFieldWriteOffset = 0; |
| 1467 | static constexpr int kArrayWriteOffset = kFieldWriteOffset + kFieldArrayAnalysisBits; |
| 1468 | static constexpr int kLastBitForWrites = kArrayWriteOffset + kFieldArrayAnalysisBits - 1; |
| 1469 | static constexpr int kCanTriggerGCBit = kLastBitForWrites + 1; |
| 1470 | |
| 1471 | static constexpr int kChangeBits = kCanTriggerGCBit + 1; |
| 1472 | |
| 1473 | static constexpr int kFieldReadOffset = kCanTriggerGCBit + 1; |
| 1474 | static constexpr int kArrayReadOffset = kFieldReadOffset + kFieldArrayAnalysisBits; |
| 1475 | static constexpr int kLastBitForReads = kArrayReadOffset + kFieldArrayAnalysisBits - 1; |
| 1476 | static constexpr int kDependsOnGCBit = kLastBitForReads + 1; |
| 1477 | |
| 1478 | static constexpr int kLastBit = kDependsOnGCBit; |
| 1479 | static constexpr int kDependOnBits = kLastBit + 1 - kChangeBits; |
| 1480 | |
| 1481 | // Aliases. |
| 1482 | |
| 1483 | static_assert(kChangeBits == kDependOnBits, |
| 1484 | "the 'change' bits should match the 'depend on' bits."); |
| 1485 | |
| 1486 | static constexpr uint64_t kAllChangeBits = ((1ULL << kChangeBits) - 1); |
| 1487 | static constexpr uint64_t kAllDependOnBits = ((1ULL << kDependOnBits) - 1) << kChangeBits; |
| 1488 | static constexpr uint64_t kAllWrites = |
| 1489 | ((1ULL << (kLastBitForWrites + 1 - kFieldWriteOffset)) - 1) << kFieldWriteOffset; |
| 1490 | static constexpr uint64_t kAllReads = |
| 1491 | ((1ULL << (kLastBitForReads + 1 - kFieldReadOffset)) - 1) << kFieldReadOffset; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1492 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1493 | // Work around the fact that HIR aliases I/F and J/D. |
| 1494 | // TODO: remove this interceptor once HIR types are clean |
| 1495 | static uint64_t TypeFlagWithAlias(Primitive::Type type, int offset) { |
| 1496 | switch (type) { |
| 1497 | case Primitive::kPrimInt: |
| 1498 | case Primitive::kPrimFloat: |
| 1499 | return TypeFlag(Primitive::kPrimInt, offset) | |
| 1500 | TypeFlag(Primitive::kPrimFloat, offset); |
| 1501 | case Primitive::kPrimLong: |
| 1502 | case Primitive::kPrimDouble: |
| 1503 | return TypeFlag(Primitive::kPrimLong, offset) | |
| 1504 | TypeFlag(Primitive::kPrimDouble, offset); |
| 1505 | default: |
| 1506 | return TypeFlag(type, offset); |
| 1507 | } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1508 | } |
| 1509 | |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1510 | // Translates type to bit flag. |
| 1511 | static uint64_t TypeFlag(Primitive::Type type, int offset) { |
| 1512 | CHECK_NE(type, Primitive::kPrimVoid); |
| 1513 | const uint64_t one = 1; |
| 1514 | const int shift = type; // 0-based consecutive enum |
| 1515 | DCHECK_LE(kFieldWriteOffset, shift); |
| 1516 | DCHECK_LT(shift, kArrayWriteOffset); |
| 1517 | return one << (type + offset); |
| 1518 | } |
| 1519 | |
| 1520 | // Private constructor on direct flags value. |
| 1521 | explicit SideEffects(uint64_t flags) : flags_(flags) {} |
| 1522 | |
| 1523 | uint64_t flags_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1524 | }; |
| 1525 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1526 | // 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] | 1527 | class HEnvironment : public ArenaObject<kArenaAllocEnvironment> { |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1528 | public: |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1529 | HEnvironment(ArenaAllocator* arena, |
| 1530 | size_t number_of_vregs, |
| 1531 | const DexFile& dex_file, |
| 1532 | uint32_t method_idx, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1533 | uint32_t dex_pc, |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1534 | InvokeType invoke_type, |
| 1535 | HInstruction* holder) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1536 | : vregs_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentVRegs)), |
| 1537 | locations_(number_of_vregs, arena->Adapter(kArenaAllocEnvironmentLocations)), |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1538 | parent_(nullptr), |
| 1539 | dex_file_(dex_file), |
| 1540 | method_idx_(method_idx), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1541 | dex_pc_(dex_pc), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1542 | invoke_type_(invoke_type), |
| 1543 | holder_(holder) { |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1544 | } |
| 1545 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1546 | HEnvironment(ArenaAllocator* arena, const HEnvironment& to_copy, HInstruction* holder) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1547 | : HEnvironment(arena, |
| 1548 | to_copy.Size(), |
| 1549 | to_copy.GetDexFile(), |
| 1550 | to_copy.GetMethodIdx(), |
| 1551 | to_copy.GetDexPc(), |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1552 | to_copy.GetInvokeType(), |
| 1553 | holder) {} |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1554 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1555 | void SetAndCopyParentChain(ArenaAllocator* allocator, HEnvironment* parent) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1556 | if (parent_ != nullptr) { |
| 1557 | parent_->SetAndCopyParentChain(allocator, parent); |
| 1558 | } else { |
| 1559 | parent_ = new (allocator) HEnvironment(allocator, *parent, holder_); |
| 1560 | parent_->CopyFrom(parent); |
| 1561 | if (parent->GetParent() != nullptr) { |
| 1562 | parent_->SetAndCopyParentChain(allocator, parent->GetParent()); |
| 1563 | } |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1564 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1565 | } |
| 1566 | |
Vladimir Marko | 71bf809 | 2015-09-15 15:33:14 +0100 | [diff] [blame] | 1567 | void CopyFrom(const ArenaVector<HInstruction*>& locals); |
Nicolas Geoffray | 8c0c91a | 2015-05-07 11:46:05 +0100 | [diff] [blame] | 1568 | void CopyFrom(HEnvironment* environment); |
| 1569 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1570 | // Copy from `env`. If it's a loop phi for `loop_header`, copy the first |
| 1571 | // input to the loop phi instead. This is for inserting instructions that |
| 1572 | // require an environment (like HDeoptimization) in the loop pre-header. |
| 1573 | void CopyFromWithLoopPhiAdjustment(HEnvironment* env, HBasicBlock* loop_header); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1574 | |
| 1575 | void SetRawEnvAt(size_t index, HInstruction* instruction) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1576 | vregs_[index] = HUserRecord<HEnvironment*>(instruction); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
| 1579 | HInstruction* GetInstructionAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1580 | return vregs_[index].GetInstruction(); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1581 | } |
| 1582 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1583 | void RemoveAsUserOfInput(size_t index) const; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1584 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1585 | size_t Size() const { return vregs_.size(); } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1586 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1587 | HEnvironment* GetParent() const { return parent_; } |
| 1588 | |
| 1589 | void SetLocationAt(size_t index, Location location) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1590 | locations_[index] = location; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1591 | } |
| 1592 | |
| 1593 | Location GetLocationAt(size_t index) const { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1594 | return locations_[index]; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1595 | } |
| 1596 | |
| 1597 | uint32_t GetDexPc() const { |
| 1598 | return dex_pc_; |
| 1599 | } |
| 1600 | |
| 1601 | uint32_t GetMethodIdx() const { |
| 1602 | return method_idx_; |
| 1603 | } |
| 1604 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1605 | InvokeType GetInvokeType() const { |
| 1606 | return invoke_type_; |
| 1607 | } |
| 1608 | |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1609 | const DexFile& GetDexFile() const { |
| 1610 | return dex_file_; |
| 1611 | } |
| 1612 | |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1613 | HInstruction* GetHolder() const { |
| 1614 | return holder_; |
| 1615 | } |
| 1616 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1617 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1618 | // Record instructions' use entries of this environment for constant-time removal. |
| 1619 | // It should only be called by HInstruction when a new environment use is added. |
| 1620 | void RecordEnvUse(HUseListNode<HEnvironment*>* env_use) { |
| 1621 | DCHECK(env_use->GetUser() == this); |
| 1622 | size_t index = env_use->GetIndex(); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1623 | vregs_[index] = HUserRecord<HEnvironment*>(vregs_[index], env_use); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1624 | } |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1625 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 1626 | ArenaVector<HUserRecord<HEnvironment*>> vregs_; |
| 1627 | ArenaVector<Location> locations_; |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1628 | HEnvironment* parent_; |
| 1629 | const DexFile& dex_file_; |
| 1630 | const uint32_t method_idx_; |
| 1631 | const uint32_t dex_pc_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1632 | const InvokeType invoke_type_; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1633 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 1634 | // The instruction that holds this environment. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1635 | HInstruction* const holder_; |
| 1636 | |
Nicolas Geoffray | 5d7b7f8 | 2015-04-28 00:52:43 +0100 | [diff] [blame] | 1637 | friend class HInstruction; |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1638 | |
| 1639 | DISALLOW_COPY_AND_ASSIGN(HEnvironment); |
| 1640 | }; |
| 1641 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1642 | class ReferenceTypeInfo : ValueObject { |
| 1643 | public: |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1644 | typedef Handle<mirror::Class> TypeHandle; |
| 1645 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1646 | static ReferenceTypeInfo Create(TypeHandle type_handle, bool is_exact) { |
| 1647 | // The constructor will check that the type_handle is valid. |
| 1648 | return ReferenceTypeInfo(type_handle, is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1651 | static ReferenceTypeInfo CreateInvalid() { return ReferenceTypeInfo(); } |
| 1652 | |
| 1653 | static bool IsValidHandle(TypeHandle handle) SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1654 | return handle.GetReference() != nullptr; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1657 | bool IsValid() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1658 | return IsValidHandle(type_handle_); |
| 1659 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1660 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1661 | bool IsExact() const { return is_exact_; } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1662 | |
| 1663 | bool IsObjectClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1664 | DCHECK(IsValid()); |
| 1665 | return GetTypeHandle()->IsObjectClass(); |
| 1666 | } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1667 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1668 | bool IsStringClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1669 | DCHECK(IsValid()); |
| 1670 | return GetTypeHandle()->IsStringClass(); |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 1671 | } |
| 1672 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1673 | bool IsObjectArray() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1674 | DCHECK(IsValid()); |
| 1675 | return IsArrayClass() && GetTypeHandle()->GetComponentType()->IsObjectClass(); |
| 1676 | } |
| 1677 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1678 | bool IsInterface() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1679 | DCHECK(IsValid()); |
| 1680 | return GetTypeHandle()->IsInterface(); |
Guillaume Sanchez | 222862c | 2015-06-09 18:33:02 +0100 | [diff] [blame] | 1681 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1682 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1683 | bool IsArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1684 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1685 | return GetTypeHandle()->IsArrayClass(); |
| 1686 | } |
| 1687 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1688 | bool IsPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1689 | DCHECK(IsValid()); |
| 1690 | return GetTypeHandle()->IsPrimitiveArray(); |
| 1691 | } |
| 1692 | |
| 1693 | bool IsNonPrimitiveArrayClass() const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1694 | DCHECK(IsValid()); |
| 1695 | return GetTypeHandle()->IsArrayClass() && !GetTypeHandle()->IsPrimitiveArray(); |
| 1696 | } |
| 1697 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1698 | bool CanArrayHold(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1699 | DCHECK(IsValid()); |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 1700 | if (!IsExact()) return false; |
| 1701 | if (!IsArrayClass()) return false; |
| 1702 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1703 | } |
| 1704 | |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 1705 | bool CanArrayHoldValuesOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
| 1706 | DCHECK(IsValid()); |
| 1707 | if (!IsExact()) return false; |
| 1708 | if (!IsArrayClass()) return false; |
| 1709 | if (!rti.IsArrayClass()) return false; |
| 1710 | return GetTypeHandle()->GetComponentType()->IsAssignableFrom( |
| 1711 | rti.GetTypeHandle()->GetComponentType()); |
| 1712 | } |
| 1713 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1714 | Handle<mirror::Class> GetTypeHandle() const { return type_handle_; } |
| 1715 | |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1716 | bool IsSupertypeOf(ReferenceTypeInfo rti) const SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1717 | DCHECK(IsValid()); |
| 1718 | DCHECK(rti.IsValid()); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1719 | return GetTypeHandle()->IsAssignableFrom(rti.GetTypeHandle().Get()); |
| 1720 | } |
| 1721 | |
| 1722 | // Returns true if the type information provide the same amount of details. |
| 1723 | // 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] | 1724 | // (because the type can be the result of a merge). |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 1725 | bool IsEqual(ReferenceTypeInfo rti) SHARED_REQUIRES(Locks::mutator_lock_) { |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1726 | if (!IsValid() && !rti.IsValid()) { |
| 1727 | // Invalid types are equal. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1728 | return true; |
| 1729 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1730 | if (!IsValid() || !rti.IsValid()) { |
| 1731 | // One is valid, the other not. |
Calin Juravle | 7733bd6 | 2015-07-22 17:14:50 +0000 | [diff] [blame] | 1732 | return false; |
| 1733 | } |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1734 | return IsExact() == rti.IsExact() |
| 1735 | && GetTypeHandle().Get() == rti.GetTypeHandle().Get(); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1736 | } |
| 1737 | |
| 1738 | private: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1739 | ReferenceTypeInfo(); |
| 1740 | ReferenceTypeInfo(TypeHandle type_handle, bool is_exact); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1741 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1742 | // The class of the object. |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1743 | TypeHandle type_handle_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1744 | // 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] | 1745 | // Whether or not we have any information about this type. |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1746 | bool is_exact_; |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1747 | }; |
| 1748 | |
| 1749 | std::ostream& operator<<(std::ostream& os, const ReferenceTypeInfo& rhs); |
| 1750 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 1751 | class HInstruction : public ArenaObject<kArenaAllocInstruction> { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1752 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 1753 | HInstruction(SideEffects side_effects, uint32_t dex_pc) |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1754 | : previous_(nullptr), |
| 1755 | next_(nullptr), |
| 1756 | block_(nullptr), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1757 | dex_pc_(dex_pc), |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1758 | id_(-1), |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1759 | ssa_index_(-1), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1760 | environment_(nullptr), |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1761 | locations_(nullptr), |
| 1762 | live_interval_(nullptr), |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1763 | lifetime_position_(kNoLifetime), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 1764 | side_effects_(side_effects), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1765 | reference_type_info_(ReferenceTypeInfo::CreateInvalid()) {} |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1766 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 1767 | virtual ~HInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1768 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1769 | #define DECLARE_KIND(type, super) k##type, |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1770 | enum InstructionKind { |
| 1771 | FOR_EACH_INSTRUCTION(DECLARE_KIND) |
| 1772 | }; |
| 1773 | #undef DECLARE_KIND |
| 1774 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1775 | HInstruction* GetNext() const { return next_; } |
| 1776 | HInstruction* GetPrevious() const { return previous_; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1777 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1778 | HInstruction* GetNextDisregardingMoves() const; |
| 1779 | HInstruction* GetPreviousDisregardingMoves() const; |
| 1780 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1781 | HBasicBlock* GetBlock() const { return block_; } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1782 | ArenaAllocator* GetArena() const { return block_->GetGraph()->GetArena(); } |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1783 | void SetBlock(HBasicBlock* block) { block_ = block; } |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 1784 | bool IsInBlock() const { return block_ != nullptr; } |
| 1785 | bool IsInLoop() const { return block_->IsInLoop(); } |
Nicolas Geoffray | 3ac17fc | 2014-08-06 23:02:54 +0100 | [diff] [blame] | 1786 | bool IsLoopHeaderPhi() { return IsPhi() && block_->IsLoopHeader(); } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 1787 | |
Roland Levillain | 6b879dd | 2014-09-22 17:13:44 +0100 | [diff] [blame] | 1788 | virtual size_t InputCount() const = 0; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1789 | HInstruction* InputAt(size_t i) const { return InputRecordAt(i).GetInstruction(); } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1790 | |
| 1791 | virtual void Accept(HGraphVisitor* visitor) = 0; |
| 1792 | virtual const char* DebugName() const = 0; |
| 1793 | |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1794 | virtual Primitive::Type GetType() const { return Primitive::kPrimVoid; } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1795 | void SetRawInputAt(size_t index, HInstruction* input) { |
| 1796 | SetRawInputRecordAt(index, HUserRecord<HInstruction*>(input)); |
| 1797 | } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 1798 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1799 | virtual bool NeedsEnvironment() const { return false; } |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 1800 | |
| 1801 | uint32_t GetDexPc() const { return dex_pc_; } |
| 1802 | |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 1803 | virtual bool IsControlFlow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1804 | |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 1805 | virtual bool CanThrow() const { return false; } |
David Brazdil | ec16f79 | 2015-08-19 15:04:01 +0100 | [diff] [blame] | 1806 | bool CanThrowIntoCatchBlock() const { return CanThrow() && block_->IsTryBlock(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1807 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 1808 | bool HasSideEffects() const { return side_effects_.HasSideEffects(); } |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 1809 | bool DoesAnyWrite() const { return side_effects_.DoesAnyWrite(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1810 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1811 | // Does not apply for all instructions, but having this at top level greatly |
| 1812 | // simplifies the null check elimination. |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 1813 | // TODO: Consider merging can_be_null into ReferenceTypeInfo. |
Nicolas Geoffray | d6138ef | 2015-02-18 14:48:53 +0000 | [diff] [blame] | 1814 | virtual bool CanBeNull() const { |
| 1815 | DCHECK_EQ(GetType(), Primitive::kPrimNot) << "CanBeNull only applies to reference types"; |
| 1816 | return true; |
| 1817 | } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 1818 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1819 | virtual bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const { |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 1820 | return false; |
| 1821 | } |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 1822 | |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 1823 | void SetReferenceTypeInfo(ReferenceTypeInfo rti); |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1824 | |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 1825 | ReferenceTypeInfo GetReferenceTypeInfo() const { |
| 1826 | DCHECK_EQ(GetType(), Primitive::kPrimNot); |
| 1827 | return reference_type_info_; |
| 1828 | } |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 1829 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1830 | void AddUseAt(HInstruction* user, size_t index) { |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1831 | DCHECK(user != nullptr); |
| 1832 | HUseListNode<HInstruction*>* use = |
| 1833 | uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1834 | user->SetRawInputRecordAt(index, HUserRecord<HInstruction*>(user->InputRecordAt(index), use)); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1835 | } |
| 1836 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1837 | void AddEnvUseAt(HEnvironment* user, size_t index) { |
Nicolas Geoffray | 724c963 | 2014-09-22 12:27:27 +0100 | [diff] [blame] | 1838 | DCHECK(user != nullptr); |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1839 | HUseListNode<HEnvironment*>* env_use = |
| 1840 | env_uses_.AddUse(user, index, GetBlock()->GetGraph()->GetArena()); |
| 1841 | user->RecordEnvUse(env_use); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1842 | } |
| 1843 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1844 | void RemoveAsUserOfInput(size_t input) { |
| 1845 | HUserRecord<HInstruction*> input_use = InputRecordAt(input); |
| 1846 | input_use.GetInstruction()->uses_.Remove(input_use.GetUseNode()); |
| 1847 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1848 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1849 | const HUseList<HInstruction*>& GetUses() const { return uses_; } |
| 1850 | const HUseList<HEnvironment*>& GetEnvUses() const { return env_uses_; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1851 | |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 1852 | bool HasUses() const { return !uses_.IsEmpty() || !env_uses_.IsEmpty(); } |
| 1853 | bool HasEnvironmentUses() const { return !env_uses_.IsEmpty(); } |
Nicolas Geoffray | 915b9d0 | 2015-03-11 15:11:19 +0000 | [diff] [blame] | 1854 | bool HasNonEnvironmentUses() const { return !uses_.IsEmpty(); } |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1855 | bool HasOnlyOneNonEnvironmentUse() const { |
| 1856 | return !HasEnvironmentUses() && GetUses().HasOnlyOneUse(); |
| 1857 | } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1858 | |
Roland Levillain | 6c82d40 | 2014-10-13 16:10:27 +0100 | [diff] [blame] | 1859 | // Does this instruction strictly dominate `other_instruction`? |
| 1860 | // Returns false if this instruction and `other_instruction` are the same. |
| 1861 | // Aborts if this instruction and `other_instruction` are both phis. |
| 1862 | bool StrictlyDominates(HInstruction* other_instruction) const; |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1863 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1864 | int GetId() const { return id_; } |
| 1865 | void SetId(int id) { id_ = id; } |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 1866 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 1867 | int GetSsaIndex() const { return ssa_index_; } |
| 1868 | void SetSsaIndex(int ssa_index) { ssa_index_ = ssa_index; } |
| 1869 | bool HasSsaIndex() const { return ssa_index_ != -1; } |
| 1870 | |
| 1871 | bool HasEnvironment() const { return environment_ != nullptr; } |
| 1872 | HEnvironment* GetEnvironment() const { return environment_; } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1873 | // Set the `environment_` field. Raw because this method does not |
| 1874 | // update the uses lists. |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1875 | void SetRawEnvironment(HEnvironment* environment) { |
| 1876 | DCHECK(environment_ == nullptr); |
| 1877 | DCHECK_EQ(environment->GetHolder(), this); |
| 1878 | environment_ = environment; |
| 1879 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1880 | |
| 1881 | // Set the environment of this instruction, copying it from `environment`. While |
| 1882 | // copying, the uses lists are being updated. |
| 1883 | void CopyEnvironmentFrom(HEnvironment* environment) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1884 | DCHECK(environment_ == nullptr); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1885 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1886 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1887 | environment_->CopyFrom(environment); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1888 | if (environment->GetParent() != nullptr) { |
| 1889 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1890 | } |
Nicolas Geoffray | 3dcd58c | 2015-04-03 11:02:38 +0100 | [diff] [blame] | 1891 | } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1892 | |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1893 | void CopyEnvironmentFromWithLoopPhiAdjustment(HEnvironment* environment, |
| 1894 | HBasicBlock* block) { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1895 | DCHECK(environment_ == nullptr); |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1896 | ArenaAllocator* allocator = GetBlock()->GetGraph()->GetArena(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 1897 | environment_ = new (allocator) HEnvironment(allocator, *environment, this); |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 1898 | environment_->CopyFromWithLoopPhiAdjustment(environment, block); |
Nicolas Geoffray | 0a23d74 | 2015-05-07 11:57:35 +0100 | [diff] [blame] | 1899 | if (environment->GetParent() != nullptr) { |
| 1900 | environment_->SetAndCopyParentChain(allocator, environment->GetParent()); |
| 1901 | } |
Mingyao Yang | 206d6fd | 2015-04-13 16:46:28 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 1904 | // Returns the number of entries in the environment. Typically, that is the |
| 1905 | // number of dex registers in a method. It could be more in case of inlining. |
| 1906 | size_t EnvironmentSize() const; |
| 1907 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 1908 | LocationSummary* GetLocations() const { return locations_; } |
| 1909 | void SetLocations(LocationSummary* locations) { locations_ = locations; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1910 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1911 | void ReplaceWith(HInstruction* instruction); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 1912 | void ReplaceInput(HInstruction* replacement, size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 1913 | |
Alexandre Rames | 188d431 | 2015-04-09 18:30:21 +0100 | [diff] [blame] | 1914 | // This is almost the same as doing `ReplaceWith()`. But in this helper, the |
| 1915 | // uses of this instruction by `other` are *not* updated. |
| 1916 | void ReplaceWithExceptInReplacementAtIndex(HInstruction* other, size_t use_index) { |
| 1917 | ReplaceWith(other); |
| 1918 | other->ReplaceInput(this, use_index); |
| 1919 | } |
| 1920 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 1921 | // Move `this` instruction before `cursor`. |
| 1922 | void MoveBefore(HInstruction* cursor); |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 1923 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 1924 | #define INSTRUCTION_TYPE_CHECK(type, super) \ |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 1925 | bool Is##type() const { return (As##type() != nullptr); } \ |
| 1926 | virtual const H##type* As##type() const { return nullptr; } \ |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 1927 | virtual H##type* As##type() { return nullptr; } |
| 1928 | |
| 1929 | FOR_EACH_INSTRUCTION(INSTRUCTION_TYPE_CHECK) |
| 1930 | #undef INSTRUCTION_TYPE_CHECK |
| 1931 | |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1932 | // Returns whether the instruction can be moved within the graph. |
| 1933 | virtual bool CanBeMoved() const { return false; } |
| 1934 | |
| 1935 | // Returns whether the two instructions are of the same kind. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1936 | virtual bool InstructionTypeEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1937 | return false; |
| 1938 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1939 | |
| 1940 | // Returns whether any data encoded in the two instructions is equal. |
| 1941 | // This method does not look at the inputs. Both instructions must be |
| 1942 | // of the same type, otherwise the method has undefined behavior. |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1943 | virtual bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1944 | return false; |
| 1945 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1946 | |
| 1947 | // Returns whether two instructions are equal, that is: |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 1948 | // 1) They have the same type and contain the same data (InstructionDataEquals). |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 1949 | // 2) Their inputs are identical. |
| 1950 | bool Equals(HInstruction* other) const; |
| 1951 | |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1952 | virtual InstructionKind GetKind() const = 0; |
| 1953 | |
| 1954 | virtual size_t ComputeHashCode() const { |
| 1955 | size_t result = GetKind(); |
| 1956 | for (size_t i = 0, e = InputCount(); i < e; ++i) { |
| 1957 | result = (result * 31) + InputAt(i)->GetId(); |
| 1958 | } |
| 1959 | return result; |
| 1960 | } |
| 1961 | |
| 1962 | SideEffects GetSideEffects() const { return side_effects_; } |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 1963 | void AddSideEffects(SideEffects other) { side_effects_.Add(other); } |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 1964 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 1965 | size_t GetLifetimePosition() const { return lifetime_position_; } |
| 1966 | void SetLifetimePosition(size_t position) { lifetime_position_ = position; } |
| 1967 | LiveInterval* GetLiveInterval() const { return live_interval_; } |
| 1968 | void SetLiveInterval(LiveInterval* interval) { live_interval_ = interval; } |
| 1969 | bool HasLiveInterval() const { return live_interval_ != nullptr; } |
| 1970 | |
Nicolas Geoffray | c0572a4 | 2015-02-06 14:35:25 +0000 | [diff] [blame] | 1971 | bool IsSuspendCheckEntry() const { return IsSuspendCheck() && GetBlock()->IsEntryBlock(); } |
| 1972 | |
| 1973 | // Returns whether the code generation of the instruction will require to have access |
| 1974 | // to the current method. Such instructions are: |
| 1975 | // (1): Instructions that require an environment, as calling the runtime requires |
| 1976 | // to walk the stack and have the current method stored at a specific stack address. |
| 1977 | // (2): Object literals like classes and strings, that are loaded from the dex cache |
| 1978 | // fields of the current method. |
| 1979 | bool NeedsCurrentMethod() const { |
| 1980 | return NeedsEnvironment() || IsLoadClass() || IsLoadString(); |
| 1981 | } |
| 1982 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 1983 | // Returns whether the code generation of the instruction will require to have access |
| 1984 | // to the dex cache of the current method's declaring class via the current method. |
| 1985 | virtual bool NeedsDexCacheOfDeclaringClass() const { return false; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 1986 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 1987 | // Does this instruction have any use in an environment before |
| 1988 | // control flow hits 'other'? |
| 1989 | bool HasAnyEnvironmentUseBefore(HInstruction* other); |
| 1990 | |
| 1991 | // Remove all references to environment uses of this instruction. |
| 1992 | // The caller must ensure that this is safe to do. |
| 1993 | void RemoveEnvironmentUsers(); |
| 1994 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 1995 | protected: |
| 1996 | virtual const HUserRecord<HInstruction*> InputRecordAt(size_t i) const = 0; |
| 1997 | virtual void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) = 0; |
| 1998 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 1999 | private: |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2000 | void RemoveEnvironmentUser(HUseListNode<HEnvironment*>* use_node) { env_uses_.Remove(use_node); } |
| 2001 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2002 | HInstruction* previous_; |
| 2003 | HInstruction* next_; |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2004 | HBasicBlock* block_; |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2005 | const uint32_t dex_pc_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2006 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2007 | // An instruction gets an id when it is added to the graph. |
| 2008 | // It reflects creation order. A negative id means the instruction |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2009 | // has not been added to the graph. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2010 | int id_; |
| 2011 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2012 | // When doing liveness analysis, instructions that have uses get an SSA index. |
| 2013 | int ssa_index_; |
| 2014 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2015 | // List of instructions that have this instruction as input. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2016 | HUseList<HInstruction*> uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2017 | |
| 2018 | // List of environments that contain this instruction. |
David Brazdil | ed59619 | 2015-01-23 10:39:45 +0000 | [diff] [blame] | 2019 | HUseList<HEnvironment*> env_uses_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2020 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 2021 | // The environment associated with this instruction. Not null if the instruction |
| 2022 | // might jump out of the method. |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2023 | HEnvironment* environment_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2024 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2025 | // Set by the code generator. |
| 2026 | LocationSummary* locations_; |
| 2027 | |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2028 | // Set by the liveness analysis. |
| 2029 | LiveInterval* live_interval_; |
| 2030 | |
| 2031 | // Set by the liveness analysis, this is the position in a linear |
| 2032 | // order of blocks where this instruction's live interval start. |
| 2033 | size_t lifetime_position_; |
| 2034 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 2035 | SideEffects side_effects_; |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2036 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 2037 | // TODO: for primitive types this should be marked as invalid. |
| 2038 | ReferenceTypeInfo reference_type_info_; |
| 2039 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2040 | friend class GraphChecker; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2041 | friend class HBasicBlock; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2042 | friend class HEnvironment; |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 2043 | friend class HGraph; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2044 | friend class HInstructionList; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2045 | |
| 2046 | DISALLOW_COPY_AND_ASSIGN(HInstruction); |
| 2047 | }; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2048 | std::ostream& operator<<(std::ostream& os, const HInstruction::InstructionKind& rhs); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2049 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2050 | class HInputIterator : public ValueObject { |
| 2051 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2052 | explicit HInputIterator(HInstruction* instruction) : instruction_(instruction), index_(0) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2053 | |
| 2054 | bool Done() const { return index_ == instruction_->InputCount(); } |
| 2055 | HInstruction* Current() const { return instruction_->InputAt(index_); } |
| 2056 | void Advance() { index_++; } |
| 2057 | |
| 2058 | private: |
| 2059 | HInstruction* instruction_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2060 | size_t index_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2061 | |
| 2062 | DISALLOW_COPY_AND_ASSIGN(HInputIterator); |
| 2063 | }; |
| 2064 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2065 | class HInstructionIterator : public ValueObject { |
| 2066 | public: |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2067 | explicit HInstructionIterator(const HInstructionList& instructions) |
| 2068 | : instruction_(instructions.first_instruction_) { |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2069 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2072 | bool Done() const { return instruction_ == nullptr; } |
| 2073 | HInstruction* Current() const { return instruction_; } |
| 2074 | void Advance() { |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2075 | instruction_ = next_; |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 2076 | next_ = Done() ? nullptr : instruction_->GetNext(); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2077 | } |
| 2078 | |
| 2079 | private: |
| 2080 | HInstruction* instruction_; |
| 2081 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2082 | |
| 2083 | DISALLOW_COPY_AND_ASSIGN(HInstructionIterator); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2084 | }; |
| 2085 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2086 | class HBackwardInstructionIterator : public ValueObject { |
| 2087 | public: |
| 2088 | explicit HBackwardInstructionIterator(const HInstructionList& instructions) |
| 2089 | : instruction_(instructions.last_instruction_) { |
| 2090 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2091 | } |
| 2092 | |
| 2093 | bool Done() const { return instruction_ == nullptr; } |
| 2094 | HInstruction* Current() const { return instruction_; } |
| 2095 | void Advance() { |
| 2096 | instruction_ = next_; |
| 2097 | next_ = Done() ? nullptr : instruction_->GetPrevious(); |
| 2098 | } |
| 2099 | |
| 2100 | private: |
| 2101 | HInstruction* instruction_; |
| 2102 | HInstruction* next_; |
Nicolas Geoffray | ddb311f | 2014-05-16 09:28:54 +0100 | [diff] [blame] | 2103 | |
| 2104 | DISALLOW_COPY_AND_ASSIGN(HBackwardInstructionIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 2105 | }; |
| 2106 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2107 | template<size_t N> |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2108 | class HTemplateInstruction: public HInstruction { |
| 2109 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2110 | HTemplateInstruction<N>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2111 | : HInstruction(side_effects, dex_pc), inputs_() {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2112 | virtual ~HTemplateInstruction() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2113 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2114 | size_t InputCount() const OVERRIDE { return N; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2115 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2116 | protected: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2117 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 2118 | DCHECK_LT(i, N); |
| 2119 | return inputs_[i]; |
| 2120 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2121 | |
| 2122 | void SetRawInputRecordAt(size_t i, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2123 | DCHECK_LT(i, N); |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 2124 | inputs_[i] = input; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2125 | } |
| 2126 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2127 | private: |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2128 | std::array<HUserRecord<HInstruction*>, N> inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 2129 | |
| 2130 | friend class SsaBuilder; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2131 | }; |
| 2132 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2133 | // HTemplateInstruction specialization for N=0. |
| 2134 | template<> |
| 2135 | class HTemplateInstruction<0>: public HInstruction { |
| 2136 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2137 | explicit HTemplateInstruction<0>(SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2138 | : HInstruction(side_effects, dex_pc) {} |
| 2139 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 2140 | virtual ~HTemplateInstruction() {} |
| 2141 | |
| 2142 | size_t InputCount() const OVERRIDE { return 0; } |
| 2143 | |
| 2144 | protected: |
| 2145 | const HUserRecord<HInstruction*> InputRecordAt(size_t i ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2146 | LOG(FATAL) << "Unreachable"; |
| 2147 | UNREACHABLE(); |
| 2148 | } |
| 2149 | |
| 2150 | void SetRawInputRecordAt(size_t i ATTRIBUTE_UNUSED, |
| 2151 | const HUserRecord<HInstruction*>& input ATTRIBUTE_UNUSED) OVERRIDE { |
| 2152 | LOG(FATAL) << "Unreachable"; |
| 2153 | UNREACHABLE(); |
| 2154 | } |
| 2155 | |
| 2156 | private: |
| 2157 | friend class SsaBuilder; |
| 2158 | }; |
| 2159 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2160 | template<intptr_t N> |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2161 | class HExpression : public HTemplateInstruction<N> { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2162 | public: |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 2163 | HExpression<N>(Primitive::Type type, SideEffects side_effects, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2164 | : HTemplateInstruction<N>(side_effects, dex_pc), type_(type) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2165 | virtual ~HExpression() {} |
| 2166 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2167 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2168 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 2169 | protected: |
| 2170 | Primitive::Type type_; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2171 | }; |
| 2172 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2173 | // Represents dex's RETURN_VOID opcode. A HReturnVoid is a control flow |
| 2174 | // instruction that branches to the exit block. |
| 2175 | class HReturnVoid : public HTemplateInstruction<0> { |
| 2176 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2177 | explicit HReturnVoid(uint32_t dex_pc = kNoDexPc) |
| 2178 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2179 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2180 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2181 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2182 | DECLARE_INSTRUCTION(ReturnVoid); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2183 | |
| 2184 | private: |
| 2185 | DISALLOW_COPY_AND_ASSIGN(HReturnVoid); |
| 2186 | }; |
| 2187 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2188 | // Represents dex's RETURN opcodes. A HReturn is a control flow |
| 2189 | // instruction that branches to the exit block. |
| 2190 | class HReturn : public HTemplateInstruction<1> { |
| 2191 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2192 | explicit HReturn(HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 2193 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2194 | SetRawInputAt(0, value); |
| 2195 | } |
| 2196 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2197 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2198 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2199 | DECLARE_INSTRUCTION(Return); |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2200 | |
| 2201 | private: |
| 2202 | DISALLOW_COPY_AND_ASSIGN(HReturn); |
| 2203 | }; |
| 2204 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2205 | // The exit instruction is the only instruction of the exit block. |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2206 | // Instructions aborting the method (HThrow and HReturn) must branch to the |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2207 | // exit block. |
| 2208 | class HExit : public HTemplateInstruction<0> { |
| 2209 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2210 | explicit HExit(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | ec7e472 | 2014-06-06 11:24:33 +0100 | [diff] [blame] | 2211 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2212 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2213 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2214 | DECLARE_INSTRUCTION(Exit); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2215 | |
| 2216 | private: |
| 2217 | DISALLOW_COPY_AND_ASSIGN(HExit); |
| 2218 | }; |
| 2219 | |
| 2220 | // Jumps from one block to another. |
| 2221 | class HGoto : public HTemplateInstruction<0> { |
| 2222 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2223 | explicit HGoto(uint32_t dex_pc = kNoDexPc) : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2224 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2225 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2226 | |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2227 | HBasicBlock* GetSuccessor() const { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2228 | return GetBlock()->GetSingleSuccessor(); |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 2229 | } |
| 2230 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2231 | DECLARE_INSTRUCTION(Goto); |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 2232 | |
| 2233 | private: |
| 2234 | DISALLOW_COPY_AND_ASSIGN(HGoto); |
| 2235 | }; |
| 2236 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2237 | class HConstant : public HExpression<0> { |
| 2238 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2239 | explicit HConstant(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2240 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2241 | |
| 2242 | bool CanBeMoved() const OVERRIDE { return true; } |
| 2243 | |
| 2244 | virtual bool IsMinusOne() const { return false; } |
| 2245 | virtual bool IsZero() const { return false; } |
| 2246 | virtual bool IsOne() const { return false; } |
| 2247 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2248 | virtual uint64_t GetValueAsUint64() const = 0; |
| 2249 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2250 | DECLARE_INSTRUCTION(Constant); |
| 2251 | |
| 2252 | private: |
| 2253 | DISALLOW_COPY_AND_ASSIGN(HConstant); |
| 2254 | }; |
| 2255 | |
| 2256 | class HNullConstant : public HConstant { |
| 2257 | public: |
| 2258 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 2259 | return true; |
| 2260 | } |
| 2261 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2262 | uint64_t GetValueAsUint64() const OVERRIDE { return 0; } |
| 2263 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2264 | size_t ComputeHashCode() const OVERRIDE { return 0; } |
| 2265 | |
| 2266 | DECLARE_INSTRUCTION(NullConstant); |
| 2267 | |
| 2268 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2269 | explicit HNullConstant(uint32_t dex_pc = kNoDexPc) : HConstant(Primitive::kPrimNot, dex_pc) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2270 | |
| 2271 | friend class HGraph; |
| 2272 | DISALLOW_COPY_AND_ASSIGN(HNullConstant); |
| 2273 | }; |
| 2274 | |
| 2275 | // Constants of the type int. Those can be from Dex instructions, or |
| 2276 | // synthesized (for example with the if-eqz instruction). |
| 2277 | class HIntConstant : public HConstant { |
| 2278 | public: |
| 2279 | int32_t GetValue() const { return value_; } |
| 2280 | |
David Brazdil | 9f389d4 | 2015-10-01 14:32:56 +0100 | [diff] [blame] | 2281 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 2282 | return static_cast<uint64_t>(static_cast<uint32_t>(value_)); |
| 2283 | } |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2284 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2285 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2286 | DCHECK(other->IsIntConstant()); |
| 2287 | return other->AsIntConstant()->value_ == value_; |
| 2288 | } |
| 2289 | |
| 2290 | size_t ComputeHashCode() const OVERRIDE { return GetValue(); } |
| 2291 | |
| 2292 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2293 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2294 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2295 | |
| 2296 | DECLARE_INSTRUCTION(IntConstant); |
| 2297 | |
| 2298 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2299 | explicit HIntConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 2300 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value) {} |
| 2301 | explicit HIntConstant(bool value, uint32_t dex_pc = kNoDexPc) |
| 2302 | : HConstant(Primitive::kPrimInt, dex_pc), value_(value ? 1 : 0) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2303 | |
| 2304 | const int32_t value_; |
| 2305 | |
| 2306 | friend class HGraph; |
| 2307 | ART_FRIEND_TEST(GraphTest, InsertInstructionBefore); |
| 2308 | ART_FRIEND_TYPED_TEST(ParallelMoveTest, ConstantLast); |
| 2309 | DISALLOW_COPY_AND_ASSIGN(HIntConstant); |
| 2310 | }; |
| 2311 | |
| 2312 | class HLongConstant : public HConstant { |
| 2313 | public: |
| 2314 | int64_t GetValue() const { return value_; } |
| 2315 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 2316 | uint64_t GetValueAsUint64() const OVERRIDE { return value_; } |
| 2317 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2318 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2319 | DCHECK(other->IsLongConstant()); |
| 2320 | return other->AsLongConstant()->value_ == value_; |
| 2321 | } |
| 2322 | |
| 2323 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
| 2324 | |
| 2325 | bool IsMinusOne() const OVERRIDE { return GetValue() == -1; } |
| 2326 | bool IsZero() const OVERRIDE { return GetValue() == 0; } |
| 2327 | bool IsOne() const OVERRIDE { return GetValue() == 1; } |
| 2328 | |
| 2329 | DECLARE_INSTRUCTION(LongConstant); |
| 2330 | |
| 2331 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2332 | explicit HLongConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 2333 | : HConstant(Primitive::kPrimLong, dex_pc), value_(value) {} |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2334 | |
| 2335 | const int64_t value_; |
| 2336 | |
| 2337 | friend class HGraph; |
| 2338 | DISALLOW_COPY_AND_ASSIGN(HLongConstant); |
| 2339 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2340 | |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2341 | // Conditional branch. A block ending with an HIf instruction must have |
| 2342 | // two successors. |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2343 | class HIf : public HTemplateInstruction<1> { |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2344 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2345 | explicit HIf(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2346 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2347 | SetRawInputAt(0, input); |
| 2348 | } |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2349 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 2350 | bool IsControlFlow() const OVERRIDE { return true; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2351 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2352 | HBasicBlock* IfTrueSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2353 | return GetBlock()->GetSuccessors()[0]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | HBasicBlock* IfFalseSuccessor() const { |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2357 | return GetBlock()->GetSuccessors()[1]; |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 2358 | } |
| 2359 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2360 | DECLARE_INSTRUCTION(If); |
Nicolas Geoffray | be9a92a | 2014-02-25 14:22:56 +0000 | [diff] [blame] | 2361 | |
| 2362 | private: |
| 2363 | DISALLOW_COPY_AND_ASSIGN(HIf); |
| 2364 | }; |
| 2365 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2366 | |
| 2367 | // Abstract instruction which marks the beginning and/or end of a try block and |
| 2368 | // links it to the respective exception handlers. Behaves the same as a Goto in |
| 2369 | // non-exceptional control flow. |
| 2370 | // Normal-flow successor is stored at index zero, exception handlers under |
| 2371 | // higher indices in no particular order. |
| 2372 | class HTryBoundary : public HTemplateInstruction<0> { |
| 2373 | public: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2374 | enum BoundaryKind { |
| 2375 | kEntry, |
| 2376 | kExit, |
| 2377 | }; |
| 2378 | |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2379 | explicit HTryBoundary(BoundaryKind kind, uint32_t dex_pc = kNoDexPc) |
| 2380 | : HTemplateInstruction(SideEffects::None(), dex_pc), kind_(kind) {} |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2381 | |
| 2382 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2383 | |
| 2384 | // Returns the block's non-exceptional successor (index zero). |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2385 | HBasicBlock* GetNormalFlowSuccessor() const { return GetBlock()->GetSuccessors()[0]; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2386 | |
| 2387 | // Returns whether `handler` is among its exception handlers (non-zero index |
| 2388 | // successors). |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2389 | bool HasExceptionHandler(const HBasicBlock& handler) const { |
| 2390 | DCHECK(handler.IsCatchBlock()); |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2391 | return GetBlock()->HasSuccessor(&handler, 1u /* Skip first successor. */); |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | // If not present already, adds `handler` to its block's list of exception |
| 2395 | // handlers. |
| 2396 | void AddExceptionHandler(HBasicBlock* handler) { |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2397 | if (!HasExceptionHandler(*handler)) { |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2398 | GetBlock()->AddSuccessor(handler); |
| 2399 | } |
| 2400 | } |
| 2401 | |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2402 | bool IsEntry() const { return kind_ == BoundaryKind::kEntry; } |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2403 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2404 | bool HasSameExceptionHandlersAs(const HTryBoundary& other) const; |
| 2405 | |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2406 | DECLARE_INSTRUCTION(TryBoundary); |
| 2407 | |
| 2408 | private: |
David Brazdil | 56e1acc | 2015-06-30 15:41:36 +0100 | [diff] [blame] | 2409 | const BoundaryKind kind_; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2410 | |
| 2411 | DISALLOW_COPY_AND_ASSIGN(HTryBoundary); |
| 2412 | }; |
| 2413 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2414 | // Iterator over exception handlers of a given HTryBoundary, i.e. over |
| 2415 | // exceptional successors of its basic block. |
| 2416 | class HExceptionHandlerIterator : public ValueObject { |
| 2417 | public: |
| 2418 | explicit HExceptionHandlerIterator(const HTryBoundary& try_boundary) |
| 2419 | : block_(*try_boundary.GetBlock()), index_(block_.NumberOfNormalSuccessors()) {} |
| 2420 | |
Vladimir Marko | 6058455 | 2015-09-03 13:35:12 +0000 | [diff] [blame] | 2421 | bool Done() const { return index_ == block_.GetSuccessors().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2422 | HBasicBlock* Current() const { return block_.GetSuccessors()[index_]; } |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 2423 | size_t CurrentSuccessorIndex() const { return index_; } |
| 2424 | void Advance() { ++index_; } |
| 2425 | |
| 2426 | private: |
| 2427 | const HBasicBlock& block_; |
| 2428 | size_t index_; |
| 2429 | |
| 2430 | DISALLOW_COPY_AND_ASSIGN(HExceptionHandlerIterator); |
| 2431 | }; |
David Brazdil | fc6a86a | 2015-06-26 10:33:45 +0000 | [diff] [blame] | 2432 | |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2433 | // Deoptimize to interpreter, upon checking a condition. |
| 2434 | class HDeoptimize : public HTemplateInstruction<1> { |
| 2435 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2436 | explicit HDeoptimize(HInstruction* cond, uint32_t dex_pc) |
| 2437 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2438 | SetRawInputAt(0, cond); |
| 2439 | } |
| 2440 | |
| 2441 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 2442 | bool CanThrow() const OVERRIDE { return true; } |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2443 | |
| 2444 | DECLARE_INSTRUCTION(Deoptimize); |
| 2445 | |
| 2446 | private: |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2447 | DISALLOW_COPY_AND_ASSIGN(HDeoptimize); |
| 2448 | }; |
| 2449 | |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2450 | // Represents the ArtMethod that was passed as a first argument to |
| 2451 | // the method. It is used by instructions that depend on it, like |
| 2452 | // instructions that work with the dex cache. |
| 2453 | class HCurrentMethod : public HExpression<0> { |
| 2454 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2455 | explicit HCurrentMethod(Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 2456 | : HExpression(type, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 2457 | |
| 2458 | DECLARE_INSTRUCTION(CurrentMethod); |
| 2459 | |
| 2460 | private: |
| 2461 | DISALLOW_COPY_AND_ASSIGN(HCurrentMethod); |
| 2462 | }; |
| 2463 | |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2464 | // PackedSwitch (jump table). A block ending with a PackedSwitch instruction will |
| 2465 | // have one successor for each entry in the switch table, and the final successor |
| 2466 | // will be the block containing the next Dex opcode. |
| 2467 | class HPackedSwitch : public HTemplateInstruction<1> { |
| 2468 | public: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2469 | HPackedSwitch(int32_t start_value, |
| 2470 | uint32_t num_entries, |
| 2471 | HInstruction* input, |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2472 | uint32_t dex_pc = kNoDexPc) |
| 2473 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 2474 | start_value_(start_value), |
| 2475 | num_entries_(num_entries) { |
| 2476 | SetRawInputAt(0, input); |
| 2477 | } |
| 2478 | |
| 2479 | bool IsControlFlow() const OVERRIDE { return true; } |
| 2480 | |
| 2481 | int32_t GetStartValue() const { return start_value_; } |
| 2482 | |
Vladimir Marko | 211c211 | 2015-09-24 16:52:33 +0100 | [diff] [blame] | 2483 | uint32_t GetNumEntries() const { return num_entries_; } |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2484 | |
| 2485 | HBasicBlock* GetDefaultBlock() const { |
| 2486 | // Last entry is the default block. |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 2487 | return GetBlock()->GetSuccessors()[num_entries_]; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2488 | } |
| 2489 | DECLARE_INSTRUCTION(PackedSwitch); |
| 2490 | |
| 2491 | private: |
Mark Mendell | 3b9f304 | 2015-09-24 08:43:40 -0400 | [diff] [blame] | 2492 | const int32_t start_value_; |
| 2493 | const uint32_t num_entries_; |
Mark Mendell | fe57faa | 2015-09-18 09:26:15 -0400 | [diff] [blame] | 2494 | |
| 2495 | DISALLOW_COPY_AND_ASSIGN(HPackedSwitch); |
| 2496 | }; |
| 2497 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2498 | class HUnaryOperation : public HExpression<1> { |
| 2499 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2500 | HUnaryOperation(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 2501 | : HExpression(result_type, SideEffects::None(), dex_pc) { |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2502 | SetRawInputAt(0, input); |
| 2503 | } |
| 2504 | |
| 2505 | HInstruction* GetInput() const { return InputAt(0); } |
| 2506 | Primitive::Type GetResultType() const { return GetType(); } |
| 2507 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2508 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2509 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2510 | return true; |
| 2511 | } |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2512 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2513 | // Try to statically evaluate `operation` and return a HConstant |
| 2514 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2515 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2516 | HConstant* TryStaticEvaluation() const; |
| 2517 | |
| 2518 | // Apply this operation to `x`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2519 | virtual HConstant* Evaluate(HIntConstant* x) const = 0; |
| 2520 | virtual HConstant* Evaluate(HLongConstant* x) const = 0; |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2521 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 2522 | DECLARE_INSTRUCTION(UnaryOperation); |
| 2523 | |
| 2524 | private: |
| 2525 | DISALLOW_COPY_AND_ASSIGN(HUnaryOperation); |
| 2526 | }; |
| 2527 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2528 | class HBinaryOperation : public HExpression<2> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2529 | public: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2530 | HBinaryOperation(Primitive::Type result_type, |
| 2531 | HInstruction* left, |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 2532 | HInstruction* right, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2533 | SideEffects side_effects = SideEffects::None(), |
| 2534 | uint32_t dex_pc = kNoDexPc) |
| 2535 | : HExpression(result_type, side_effects, dex_pc) { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2536 | SetRawInputAt(0, left); |
| 2537 | SetRawInputAt(1, right); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2540 | HInstruction* GetLeft() const { return InputAt(0); } |
| 2541 | HInstruction* GetRight() const { return InputAt(1); } |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2542 | Primitive::Type GetResultType() const { return GetType(); } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2543 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2544 | virtual bool IsCommutative() const { return false; } |
| 2545 | |
| 2546 | // Put constant on the right. |
| 2547 | // Returns whether order is changed. |
| 2548 | bool OrderInputsWithConstantOnTheRight() { |
| 2549 | HInstruction* left = InputAt(0); |
| 2550 | HInstruction* right = InputAt(1); |
| 2551 | if (left->IsConstant() && !right->IsConstant()) { |
| 2552 | ReplaceInput(right, 0); |
| 2553 | ReplaceInput(left, 1); |
| 2554 | return true; |
| 2555 | } |
| 2556 | return false; |
| 2557 | } |
| 2558 | |
| 2559 | // Order inputs by instruction id, but favor constant on the right side. |
| 2560 | // This helps GVN for commutative ops. |
| 2561 | void OrderInputs() { |
| 2562 | DCHECK(IsCommutative()); |
| 2563 | HInstruction* left = InputAt(0); |
| 2564 | HInstruction* right = InputAt(1); |
| 2565 | if (left == right || (!left->IsConstant() && right->IsConstant())) { |
| 2566 | return; |
| 2567 | } |
| 2568 | if (OrderInputsWithConstantOnTheRight()) { |
| 2569 | return; |
| 2570 | } |
| 2571 | // Order according to instruction id. |
| 2572 | if (left->GetId() > right->GetId()) { |
| 2573 | ReplaceInput(right, 0); |
| 2574 | ReplaceInput(left, 1); |
| 2575 | } |
| 2576 | } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2577 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2578 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 2579 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2580 | return true; |
| 2581 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 2582 | |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2583 | // Try to statically evaluate `operation` and return a HConstant |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2584 | // containing the result of this evaluation. If `operation` cannot |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2585 | // be evaluated as a constant, return null. |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 2586 | HConstant* TryStaticEvaluation() const; |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2587 | |
| 2588 | // Apply this operation to `x` and `y`. |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2589 | virtual HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const = 0; |
| 2590 | virtual HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const = 0; |
| 2591 | virtual HConstant* Evaluate(HIntConstant* x ATTRIBUTE_UNUSED, |
| 2592 | HLongConstant* y ATTRIBUTE_UNUSED) const { |
| 2593 | VLOG(compiler) << DebugName() << " is not defined for the (int, long) case."; |
| 2594 | return nullptr; |
| 2595 | } |
| 2596 | virtual HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED, |
| 2597 | HIntConstant* y ATTRIBUTE_UNUSED) const { |
| 2598 | VLOG(compiler) << DebugName() << " is not defined for the (long, int) case."; |
| 2599 | return nullptr; |
| 2600 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2601 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2602 | // 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] | 2603 | // constant, or null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2604 | HConstant* GetConstantRight() const; |
| 2605 | |
| 2606 | // If `GetConstantRight()` returns one of the input, this returns the other |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 2607 | // one. Otherwise it returns null. |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 2608 | HInstruction* GetLeastConstantLeft() const; |
| 2609 | |
Roland Levillain | ccc07a9 | 2014-09-16 14:48:16 +0100 | [diff] [blame] | 2610 | DECLARE_INSTRUCTION(BinaryOperation); |
| 2611 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2612 | private: |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2613 | DISALLOW_COPY_AND_ASSIGN(HBinaryOperation); |
| 2614 | }; |
| 2615 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2616 | // The comparison bias applies for floating point operations and indicates how NaN |
| 2617 | // comparisons are treated: |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2618 | enum class ComparisonBias { |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2619 | kNoBias, // bias is not applicable (i.e. for long operation) |
| 2620 | kGtBias, // return 1 for NaN comparisons |
| 2621 | kLtBias, // return -1 for NaN comparisons |
| 2622 | }; |
| 2623 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2624 | class HCondition : public HBinaryOperation { |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2625 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2626 | HCondition(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2627 | : HBinaryOperation(Primitive::kPrimBoolean, first, second, SideEffects::None(), dex_pc), |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2628 | needs_materialization_(true), |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2629 | bias_(ComparisonBias::kNoBias) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2630 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2631 | bool NeedsMaterialization() const { return needs_materialization_; } |
| 2632 | void ClearNeedsMaterialization() { needs_materialization_ = false; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 2633 | |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2634 | // For code generation purposes, returns whether this instruction is just before |
Mingyao Yang | d43b3ac | 2015-04-01 14:03:04 -0700 | [diff] [blame] | 2635 | // `instruction`, and disregard moves in between. |
| 2636 | bool IsBeforeWhenDisregardMoves(HInstruction* instruction) const; |
Nicolas Geoffray | 18efde5 | 2014-09-22 15:51:11 +0100 | [diff] [blame] | 2637 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2638 | DECLARE_INSTRUCTION(Condition); |
| 2639 | |
| 2640 | virtual IfCondition GetCondition() const = 0; |
| 2641 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2642 | virtual IfCondition GetOppositeCondition() const = 0; |
| 2643 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2644 | bool IsGtBias() const { return bias_ == ComparisonBias::kGtBias; } |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2645 | |
| 2646 | void SetBias(ComparisonBias bias) { bias_ = bias; } |
| 2647 | |
| 2648 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 2649 | return bias_ == other->AsCondition()->bias_; |
| 2650 | } |
| 2651 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 2652 | bool IsFPConditionTrueIfNaN() const { |
| 2653 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2654 | IfCondition if_cond = GetCondition(); |
| 2655 | return IsGtBias() ? ((if_cond == kCondGT) || (if_cond == kCondGE)) : (if_cond == kCondNE); |
| 2656 | } |
| 2657 | |
| 2658 | bool IsFPConditionFalseIfNaN() const { |
| 2659 | DCHECK(Primitive::IsFloatingPointType(InputAt(0)->GetType())); |
| 2660 | IfCondition if_cond = GetCondition(); |
| 2661 | return IsGtBias() ? ((if_cond == kCondLT) || (if_cond == kCondLE)) : (if_cond == kCondEQ); |
| 2662 | } |
| 2663 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2664 | private: |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 2665 | // For register allocation purposes, returns whether this instruction needs to be |
| 2666 | // materialized (that is, not just be in the processor flags). |
| 2667 | bool needs_materialization_; |
| 2668 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2669 | // Needed if we merge a HCompare into a HCondition. |
| 2670 | ComparisonBias bias_; |
| 2671 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2672 | DISALLOW_COPY_AND_ASSIGN(HCondition); |
| 2673 | }; |
| 2674 | |
| 2675 | // Instruction to check if two inputs are equal to each other. |
| 2676 | class HEqual : public HCondition { |
| 2677 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2678 | HEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2679 | : HCondition(first, second, dex_pc) {} |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 2680 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2681 | bool IsCommutative() const OVERRIDE { return true; } |
| 2682 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2683 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2684 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2685 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2686 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2687 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2688 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2689 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2690 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2691 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 2692 | DECLARE_INSTRUCTION(Equal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2693 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2694 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2695 | return kCondEQ; |
| 2696 | } |
| 2697 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2698 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2699 | return kCondNE; |
| 2700 | } |
| 2701 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2702 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2703 | template <typename T> bool Compute(T x, T y) const { return x == y; } |
| 2704 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 2705 | DISALLOW_COPY_AND_ASSIGN(HEqual); |
| 2706 | }; |
| 2707 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2708 | class HNotEqual : public HCondition { |
| 2709 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2710 | HNotEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2711 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2712 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 2713 | bool IsCommutative() const OVERRIDE { return true; } |
| 2714 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2715 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2716 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2717 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2718 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2719 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2720 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2721 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2722 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2723 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2724 | DECLARE_INSTRUCTION(NotEqual); |
| 2725 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2726 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2727 | return kCondNE; |
| 2728 | } |
| 2729 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2730 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2731 | return kCondEQ; |
| 2732 | } |
| 2733 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2734 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2735 | template <typename T> bool Compute(T x, T y) const { return x != y; } |
| 2736 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2737 | DISALLOW_COPY_AND_ASSIGN(HNotEqual); |
| 2738 | }; |
| 2739 | |
| 2740 | class HLessThan : public HCondition { |
| 2741 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2742 | HLessThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2743 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2744 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2745 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2746 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2747 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2748 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2749 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2750 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2751 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2752 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2753 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2754 | DECLARE_INSTRUCTION(LessThan); |
| 2755 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2756 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2757 | return kCondLT; |
| 2758 | } |
| 2759 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2760 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2761 | return kCondGE; |
| 2762 | } |
| 2763 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2764 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2765 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2766 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2767 | DISALLOW_COPY_AND_ASSIGN(HLessThan); |
| 2768 | }; |
| 2769 | |
| 2770 | class HLessThanOrEqual : public HCondition { |
| 2771 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2772 | HLessThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2773 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2774 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2775 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2776 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2777 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2778 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2779 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2780 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2781 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2782 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2783 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2784 | DECLARE_INSTRUCTION(LessThanOrEqual); |
| 2785 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2786 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2787 | return kCondLE; |
| 2788 | } |
| 2789 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2790 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2791 | return kCondGT; |
| 2792 | } |
| 2793 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2794 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2795 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2796 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2797 | DISALLOW_COPY_AND_ASSIGN(HLessThanOrEqual); |
| 2798 | }; |
| 2799 | |
| 2800 | class HGreaterThan : public HCondition { |
| 2801 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2802 | HGreaterThan(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2803 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2804 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2805 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2806 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2807 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2808 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2809 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2810 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2811 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2812 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2813 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2814 | DECLARE_INSTRUCTION(GreaterThan); |
| 2815 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2816 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2817 | return kCondGT; |
| 2818 | } |
| 2819 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2820 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2821 | return kCondLE; |
| 2822 | } |
| 2823 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2824 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2825 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2826 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2827 | DISALLOW_COPY_AND_ASSIGN(HGreaterThan); |
| 2828 | }; |
| 2829 | |
| 2830 | class HGreaterThanOrEqual : public HCondition { |
| 2831 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2832 | HGreaterThanOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2833 | : HCondition(first, second, dex_pc) {} |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2834 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2835 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2836 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2837 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2838 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 2839 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2840 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2841 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 2842 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 2843 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2844 | DECLARE_INSTRUCTION(GreaterThanOrEqual); |
| 2845 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 2846 | IfCondition GetCondition() const OVERRIDE { |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2847 | return kCondGE; |
| 2848 | } |
| 2849 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2850 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2851 | return kCondLT; |
| 2852 | } |
| 2853 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2854 | private: |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2855 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2856 | |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2857 | DISALLOW_COPY_AND_ASSIGN(HGreaterThanOrEqual); |
| 2858 | }; |
| 2859 | |
Aart Bik | e9f3760 | 2015-10-09 11:15:55 -0700 | [diff] [blame] | 2860 | class HBelow : public HCondition { |
| 2861 | public: |
| 2862 | HBelow(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2863 | : HCondition(first, second, dex_pc) {} |
| 2864 | |
| 2865 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2866 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2867 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2868 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2869 | } |
| 2870 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2871 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2872 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2873 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2874 | } |
| 2875 | |
| 2876 | DECLARE_INSTRUCTION(Below); |
| 2877 | |
| 2878 | IfCondition GetCondition() const OVERRIDE { |
| 2879 | return kCondB; |
| 2880 | } |
| 2881 | |
| 2882 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2883 | return kCondAE; |
| 2884 | } |
| 2885 | |
| 2886 | private: |
| 2887 | template <typename T> bool Compute(T x, T y) const { return x < y; } |
| 2888 | |
| 2889 | DISALLOW_COPY_AND_ASSIGN(HBelow); |
| 2890 | }; |
| 2891 | |
| 2892 | class HBelowOrEqual : public HCondition { |
| 2893 | public: |
| 2894 | HBelowOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2895 | : HCondition(first, second, dex_pc) {} |
| 2896 | |
| 2897 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2898 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2899 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2900 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2901 | } |
| 2902 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2903 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2904 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2905 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2906 | } |
| 2907 | |
| 2908 | DECLARE_INSTRUCTION(BelowOrEqual); |
| 2909 | |
| 2910 | IfCondition GetCondition() const OVERRIDE { |
| 2911 | return kCondBE; |
| 2912 | } |
| 2913 | |
| 2914 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2915 | return kCondA; |
| 2916 | } |
| 2917 | |
| 2918 | private: |
| 2919 | template <typename T> bool Compute(T x, T y) const { return x <= y; } |
| 2920 | |
| 2921 | DISALLOW_COPY_AND_ASSIGN(HBelowOrEqual); |
| 2922 | }; |
| 2923 | |
| 2924 | class HAbove : public HCondition { |
| 2925 | public: |
| 2926 | HAbove(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2927 | : HCondition(first, second, dex_pc) {} |
| 2928 | |
| 2929 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2930 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2931 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2932 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2933 | } |
| 2934 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2935 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2936 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2937 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2938 | } |
| 2939 | |
| 2940 | DECLARE_INSTRUCTION(Above); |
| 2941 | |
| 2942 | IfCondition GetCondition() const OVERRIDE { |
| 2943 | return kCondA; |
| 2944 | } |
| 2945 | |
| 2946 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2947 | return kCondBE; |
| 2948 | } |
| 2949 | |
| 2950 | private: |
| 2951 | template <typename T> bool Compute(T x, T y) const { return x > y; } |
| 2952 | |
| 2953 | DISALLOW_COPY_AND_ASSIGN(HAbove); |
| 2954 | }; |
| 2955 | |
| 2956 | class HAboveOrEqual : public HCondition { |
| 2957 | public: |
| 2958 | HAboveOrEqual(HInstruction* first, HInstruction* second, uint32_t dex_pc = kNoDexPc) |
| 2959 | : HCondition(first, second, dex_pc) {} |
| 2960 | |
| 2961 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 2962 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2963 | Compute(static_cast<uint32_t>(x->GetValue()), |
| 2964 | static_cast<uint32_t>(y->GetValue())), GetDexPc()); |
| 2965 | } |
| 2966 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 2967 | return GetBlock()->GetGraph()->GetIntConstant( |
| 2968 | Compute(static_cast<uint64_t>(x->GetValue()), |
| 2969 | static_cast<uint64_t>(y->GetValue())), GetDexPc()); |
| 2970 | } |
| 2971 | |
| 2972 | DECLARE_INSTRUCTION(AboveOrEqual); |
| 2973 | |
| 2974 | IfCondition GetCondition() const OVERRIDE { |
| 2975 | return kCondAE; |
| 2976 | } |
| 2977 | |
| 2978 | IfCondition GetOppositeCondition() const OVERRIDE { |
| 2979 | return kCondB; |
| 2980 | } |
| 2981 | |
| 2982 | private: |
| 2983 | template <typename T> bool Compute(T x, T y) const { return x >= y; } |
| 2984 | |
| 2985 | DISALLOW_COPY_AND_ASSIGN(HAboveOrEqual); |
| 2986 | }; |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 2987 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 2988 | // Instruction to check how two inputs compare to each other. |
| 2989 | // Result is 0 if input0 == input1, 1 if input0 > input1, or -1 if input0 < input1. |
| 2990 | class HCompare : public HBinaryOperation { |
| 2991 | public: |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2992 | HCompare(Primitive::Type type, |
| 2993 | HInstruction* first, |
| 2994 | HInstruction* second, |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 2995 | ComparisonBias bias, |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 2996 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 2997 | : HBinaryOperation(Primitive::kPrimInt, |
| 2998 | first, |
| 2999 | second, |
| 3000 | SideEffectsForArchRuntimeCalls(type), |
| 3001 | dex_pc), |
| 3002 | bias_(bias) { |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3003 | DCHECK_EQ(type, first->GetType()); |
| 3004 | DCHECK_EQ(type, second->GetType()); |
| 3005 | } |
| 3006 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3007 | template <typename T> |
| 3008 | 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] | 3009 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3010 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3011 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3012 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3013 | } |
| 3014 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3015 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3016 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3017 | } |
| 3018 | |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3019 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 3020 | return bias_ == other->AsCompare()->bias_; |
| 3021 | } |
| 3022 | |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3023 | ComparisonBias GetBias() const { return bias_; } |
| 3024 | |
Roland Levillain | 4fa13f6 | 2015-07-06 18:11:54 +0100 | [diff] [blame] | 3025 | bool IsGtBias() { return bias_ == ComparisonBias::kGtBias; } |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3026 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3027 | |
| 3028 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type type) { |
| 3029 | // MIPS64 uses a runtime call for FP comparisons. |
| 3030 | return Primitive::IsFloatingPointType(type) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 3031 | } |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 3032 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3033 | DECLARE_INSTRUCTION(Compare); |
| 3034 | |
| 3035 | private: |
Mark Mendell | c470193 | 2015-04-10 13:18:51 -0400 | [diff] [blame] | 3036 | const ComparisonBias bias_; |
Calin Juravle | ddb7df2 | 2014-11-25 20:56:51 +0000 | [diff] [blame] | 3037 | |
Nicolas Geoffray | 412f10c | 2014-06-19 10:00:34 +0100 | [diff] [blame] | 3038 | DISALLOW_COPY_AND_ASSIGN(HCompare); |
| 3039 | }; |
| 3040 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3041 | // A local in the graph. Corresponds to a Dex register. |
| 3042 | class HLocal : public HTemplateInstruction<0> { |
| 3043 | public: |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 3044 | explicit HLocal(uint16_t reg_number) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3045 | : HTemplateInstruction(SideEffects::None(), kNoDexPc), reg_number_(reg_number) {} |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3046 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3047 | DECLARE_INSTRUCTION(Local); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3048 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 3049 | uint16_t GetRegNumber() const { return reg_number_; } |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3050 | |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3051 | private: |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3052 | // The Dex register number. |
| 3053 | const uint16_t reg_number_; |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3054 | |
| 3055 | DISALLOW_COPY_AND_ASSIGN(HLocal); |
| 3056 | }; |
| 3057 | |
| 3058 | // Load a given local. The local is an input of this instruction. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 3059 | class HLoadLocal : public HExpression<1> { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3060 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3061 | HLoadLocal(HLocal* local, Primitive::Type type, uint32_t dex_pc = kNoDexPc) |
| 3062 | : HExpression(type, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3063 | SetRawInputAt(0, local); |
| 3064 | } |
| 3065 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3066 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3067 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3068 | DECLARE_INSTRUCTION(LoadLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3069 | |
| 3070 | private: |
| 3071 | DISALLOW_COPY_AND_ASSIGN(HLoadLocal); |
| 3072 | }; |
| 3073 | |
| 3074 | // Store a value in a given local. This instruction has two inputs: the value |
| 3075 | // and the local. |
| 3076 | class HStoreLocal : public HTemplateInstruction<2> { |
| 3077 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3078 | HStoreLocal(HLocal* local, HInstruction* value, uint32_t dex_pc = kNoDexPc) |
| 3079 | : HTemplateInstruction(SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3080 | SetRawInputAt(0, local); |
| 3081 | SetRawInputAt(1, value); |
| 3082 | } |
| 3083 | |
Nicolas Geoffray | bab4ed7 | 2014-03-11 17:53:17 +0000 | [diff] [blame] | 3084 | HLocal* GetLocal() const { return reinterpret_cast<HLocal*>(InputAt(0)); } |
| 3085 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3086 | DECLARE_INSTRUCTION(StoreLocal); |
Nicolas Geoffray | 3ff386a | 2014-03-04 14:46:47 +0000 | [diff] [blame] | 3087 | |
| 3088 | private: |
| 3089 | DISALLOW_COPY_AND_ASSIGN(HStoreLocal); |
| 3090 | }; |
| 3091 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3092 | class HFloatConstant : public HConstant { |
| 3093 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3094 | float GetValue() const { return value_; } |
| 3095 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3096 | uint64_t GetValueAsUint64() const OVERRIDE { |
| 3097 | return static_cast<uint64_t>(bit_cast<uint32_t, float>(value_)); |
| 3098 | } |
| 3099 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3100 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3101 | DCHECK(other->IsFloatConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3102 | return other->AsFloatConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3103 | } |
| 3104 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3105 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3106 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3107 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3108 | 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] | 3109 | } |
| 3110 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3111 | return value_ == 0.0f; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3112 | } |
| 3113 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3114 | return bit_cast<uint32_t, float>(value_) == bit_cast<uint32_t, float>(1.0f); |
| 3115 | } |
| 3116 | bool IsNaN() const { |
| 3117 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3118 | } |
| 3119 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3120 | DECLARE_INSTRUCTION(FloatConstant); |
| 3121 | |
| 3122 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3123 | explicit HFloatConstant(float value, uint32_t dex_pc = kNoDexPc) |
| 3124 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(value) {} |
| 3125 | explicit HFloatConstant(int32_t value, uint32_t dex_pc = kNoDexPc) |
| 3126 | : HConstant(Primitive::kPrimFloat, dex_pc), value_(bit_cast<float, int32_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3127 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3128 | const float value_; |
| 3129 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3130 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3131 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3132 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3133 | DISALLOW_COPY_AND_ASSIGN(HFloatConstant); |
| 3134 | }; |
| 3135 | |
| 3136 | class HDoubleConstant : public HConstant { |
| 3137 | public: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3138 | double GetValue() const { return value_; } |
| 3139 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3140 | uint64_t GetValueAsUint64() const OVERRIDE { return bit_cast<uint64_t, double>(value_); } |
| 3141 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3142 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3143 | DCHECK(other->IsDoubleConstant()); |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 3144 | return other->AsDoubleConstant()->GetValueAsUint64() == GetValueAsUint64(); |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3145 | } |
| 3146 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3147 | size_t ComputeHashCode() const OVERRIDE { return static_cast<size_t>(GetValue()); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3148 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3149 | bool IsMinusOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3150 | 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] | 3151 | } |
| 3152 | bool IsZero() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3153 | return value_ == 0.0; |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3154 | } |
| 3155 | bool IsOne() const OVERRIDE { |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 3156 | return bit_cast<uint64_t, double>(value_) == bit_cast<uint64_t, double>(1.0); |
| 3157 | } |
| 3158 | bool IsNaN() const { |
| 3159 | return std::isnan(value_); |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 3160 | } |
| 3161 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3162 | DECLARE_INSTRUCTION(DoubleConstant); |
| 3163 | |
| 3164 | private: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3165 | explicit HDoubleConstant(double value, uint32_t dex_pc = kNoDexPc) |
| 3166 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(value) {} |
| 3167 | explicit HDoubleConstant(int64_t value, uint32_t dex_pc = kNoDexPc) |
| 3168 | : HConstant(Primitive::kPrimDouble, dex_pc), value_(bit_cast<double, int64_t>(value)) {} |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3169 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3170 | const double value_; |
| 3171 | |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3172 | // Only the SsaBuilder and HGraph can create floating-point constants. |
David Brazdil | 8d5b8b2 | 2015-03-24 10:51:52 +0000 | [diff] [blame] | 3173 | friend class SsaBuilder; |
Nicolas Geoffray | f213e05 | 2015-04-27 08:53:46 +0000 | [diff] [blame] | 3174 | friend class HGraph; |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 3175 | DISALLOW_COPY_AND_ASSIGN(HDoubleConstant); |
| 3176 | }; |
| 3177 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3178 | enum class Intrinsics { |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3179 | #define OPTIMIZING_INTRINSICS(Name, IsStatic, NeedsEnvironmentOrCache) k ## Name, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3180 | #include "intrinsics_list.h" |
| 3181 | kNone, |
| 3182 | INTRINSICS_LIST(OPTIMIZING_INTRINSICS) |
| 3183 | #undef INTRINSICS_LIST |
| 3184 | #undef OPTIMIZING_INTRINSICS |
| 3185 | }; |
| 3186 | std::ostream& operator<<(std::ostream& os, const Intrinsics& intrinsic); |
| 3187 | |
Agi Csaki | 05f2056 | 2015-08-19 14:58:14 -0700 | [diff] [blame] | 3188 | enum IntrinsicNeedsEnvironmentOrCache { |
| 3189 | kNoEnvironmentOrCache, // Intrinsic does not require an environment or dex cache. |
| 3190 | kNeedsEnvironmentOrCache // Intrinsic requires an environment or requires a dex cache. |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3191 | }; |
| 3192 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3193 | class HInvoke : public HInstruction { |
| 3194 | public: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3195 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3196 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3197 | bool NeedsEnvironment() const OVERRIDE; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3198 | |
Nicolas Geoffray | 4a34a42 | 2014-04-03 10:38:37 +0100 | [diff] [blame] | 3199 | void SetArgumentAt(size_t index, HInstruction* argument) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3200 | SetRawInputAt(index, argument); |
| 3201 | } |
| 3202 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3203 | // Return the number of arguments. This number can be lower than |
| 3204 | // the number of inputs returned by InputCount(), as some invoke |
| 3205 | // instructions (e.g. HInvokeStaticOrDirect) can have non-argument |
| 3206 | // inputs at the end of their list of inputs. |
| 3207 | uint32_t GetNumberOfArguments() const { return number_of_arguments_; } |
| 3208 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3209 | Primitive::Type GetType() const OVERRIDE { return return_type_; } |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3210 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3211 | |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3212 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3213 | const DexFile& GetDexFile() const { return GetEnvironment()->GetDexFile(); } |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3214 | |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3215 | InvokeType GetOriginalInvokeType() const { return original_invoke_type_; } |
| 3216 | |
Nicolas Geoffray | 1ba1981 | 2015-04-21 09:12:40 +0100 | [diff] [blame] | 3217 | Intrinsics GetIntrinsic() const { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3218 | return intrinsic_; |
| 3219 | } |
| 3220 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3221 | void SetIntrinsic(Intrinsics intrinsic, IntrinsicNeedsEnvironmentOrCache needs_env_or_cache); |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3222 | |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 3223 | bool IsFromInlinedInvoke() const { |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 3224 | return GetEnvironment()->GetParent() != nullptr; |
| 3225 | } |
| 3226 | |
| 3227 | bool CanThrow() const OVERRIDE { return true; } |
| 3228 | |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3229 | uint32_t* GetIntrinsicOptimizations() { |
| 3230 | return &intrinsic_optimizations_; |
| 3231 | } |
| 3232 | |
| 3233 | const uint32_t* GetIntrinsicOptimizations() const { |
| 3234 | return &intrinsic_optimizations_; |
| 3235 | } |
| 3236 | |
| 3237 | bool IsIntrinsic() const { return intrinsic_ != Intrinsics::kNone; } |
| 3238 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 3239 | DECLARE_INSTRUCTION(Invoke); |
| 3240 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3241 | protected: |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3242 | HInvoke(ArenaAllocator* arena, |
| 3243 | uint32_t number_of_arguments, |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3244 | uint32_t number_of_other_inputs, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3245 | Primitive::Type return_type, |
| 3246 | uint32_t dex_pc, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3247 | uint32_t dex_method_index, |
| 3248 | InvokeType original_invoke_type) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3249 | : HInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3250 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3251 | number_of_arguments_(number_of_arguments), |
Vladimir Marko | b7d8e8c | 2015-09-17 15:47:05 +0100 | [diff] [blame] | 3252 | inputs_(number_of_arguments + number_of_other_inputs, |
| 3253 | arena->Adapter(kArenaAllocInvokeInputs)), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3254 | return_type_(return_type), |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3255 | dex_method_index_(dex_method_index), |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3256 | original_invoke_type_(original_invoke_type), |
agicsaki | 57b81ec | 2015-08-11 17:39:37 -0700 | [diff] [blame] | 3257 | intrinsic_(Intrinsics::kNone), |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3258 | intrinsic_optimizations_(0) { |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3259 | } |
| 3260 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3261 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3262 | return inputs_[index]; |
| 3263 | } |
| 3264 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3265 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3266 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 3267 | } |
| 3268 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3269 | uint32_t number_of_arguments_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3270 | ArenaVector<HUserRecord<HInstruction*>> inputs_; |
Nicolas Geoffray | 01bc96d | 2014-04-11 17:43:50 +0100 | [diff] [blame] | 3271 | const Primitive::Type return_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3272 | const uint32_t dex_method_index_; |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3273 | const InvokeType original_invoke_type_; |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3274 | Intrinsics intrinsic_; |
Nicolas Geoffray | a83a54d | 2015-10-02 17:30:26 +0100 | [diff] [blame] | 3275 | |
| 3276 | // A magic word holding optimizations for intrinsics. See intrinsics.h. |
| 3277 | uint32_t intrinsic_optimizations_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3278 | |
| 3279 | private: |
| 3280 | DISALLOW_COPY_AND_ASSIGN(HInvoke); |
| 3281 | }; |
| 3282 | |
Calin Juravle | 175dc73 | 2015-08-25 15:42:32 +0100 | [diff] [blame] | 3283 | class HInvokeUnresolved : public HInvoke { |
| 3284 | public: |
| 3285 | HInvokeUnresolved(ArenaAllocator* arena, |
| 3286 | uint32_t number_of_arguments, |
| 3287 | Primitive::Type return_type, |
| 3288 | uint32_t dex_pc, |
| 3289 | uint32_t dex_method_index, |
| 3290 | InvokeType invoke_type) |
| 3291 | : HInvoke(arena, |
| 3292 | number_of_arguments, |
| 3293 | 0u /* number_of_other_inputs */, |
| 3294 | return_type, |
| 3295 | dex_pc, |
| 3296 | dex_method_index, |
| 3297 | invoke_type) { |
| 3298 | } |
| 3299 | |
| 3300 | DECLARE_INSTRUCTION(InvokeUnresolved); |
| 3301 | |
| 3302 | private: |
| 3303 | DISALLOW_COPY_AND_ASSIGN(HInvokeUnresolved); |
| 3304 | }; |
| 3305 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3306 | class HInvokeStaticOrDirect : public HInvoke { |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3307 | public: |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3308 | // Requirements of this method call regarding the class |
| 3309 | // initialization (clinit) check of its declaring class. |
| 3310 | enum class ClinitCheckRequirement { |
| 3311 | kNone, // Class already initialized. |
| 3312 | kExplicit, // Static call having explicit clinit check as last input. |
| 3313 | kImplicit, // Static call implicitly requiring a clinit check. |
| 3314 | }; |
| 3315 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3316 | // Determines how to load the target ArtMethod*. |
| 3317 | enum class MethodLoadKind { |
| 3318 | // Use a String init ArtMethod* loaded from Thread entrypoints. |
| 3319 | kStringInit, |
| 3320 | |
| 3321 | // Use the method's own ArtMethod* loaded by the register allocator. |
| 3322 | kRecursive, |
| 3323 | |
| 3324 | // Use ArtMethod* at a known address, embed the direct address in the code. |
| 3325 | // Used for app->boot calls with non-relocatable image and for JIT-compiled calls. |
| 3326 | kDirectAddress, |
| 3327 | |
| 3328 | // Use ArtMethod* at an address that will be known at link time, embed the direct |
| 3329 | // address in the code. If the image is relocatable, emit .patch_oat entry. |
| 3330 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3331 | // the image relocatable or not. |
| 3332 | kDirectAddressWithFixup, |
| 3333 | |
| 3334 | // Load from resoved methods array in the dex cache using a PC-relative load. |
| 3335 | // Used when we need to use the dex cache, for example for invoke-static that |
| 3336 | // may cause class initialization (the entry may point to a resolution method), |
| 3337 | // and we know that we can access the dex cache arrays using a PC-relative load. |
| 3338 | kDexCachePcRelative, |
| 3339 | |
| 3340 | // Use ArtMethod* from the resolved methods of the compiled method's own ArtMethod*. |
| 3341 | // Used for JIT when we need to use the dex cache. This is also the last-resort-kind |
| 3342 | // used when other kinds are unavailable (say, dex cache arrays are not PC-relative) |
| 3343 | // or unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3344 | kDexCacheViaMethod, |
| 3345 | }; |
| 3346 | |
| 3347 | // Determines the location of the code pointer. |
| 3348 | enum class CodePtrLocation { |
| 3349 | // Recursive call, use local PC-relative call instruction. |
| 3350 | kCallSelf, |
| 3351 | |
| 3352 | // Use PC-relative call instruction patched at link time. |
| 3353 | // Used for calls within an oat file, boot->boot or app->app. |
| 3354 | kCallPCRelative, |
| 3355 | |
| 3356 | // Call to a known target address, embed the direct address in code. |
| 3357 | // Used for app->boot call with non-relocatable image and for JIT-compiled calls. |
| 3358 | kCallDirect, |
| 3359 | |
| 3360 | // Call to a target address that will be known at link time, embed the direct |
| 3361 | // address in code. If the image is relocatable, emit .patch_oat entry. |
| 3362 | // Used for app->boot calls with relocatable image and boot->boot calls, whether |
| 3363 | // the image relocatable or not. |
| 3364 | kCallDirectWithFixup, |
| 3365 | |
| 3366 | // Use code pointer from the ArtMethod*. |
| 3367 | // Used when we don't know the target code. This is also the last-resort-kind used when |
| 3368 | // other kinds are unimplemented or impractical (i.e. slow) on a particular architecture. |
| 3369 | kCallArtMethod, |
| 3370 | }; |
| 3371 | |
| 3372 | struct DispatchInfo { |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3373 | MethodLoadKind method_load_kind; |
| 3374 | CodePtrLocation code_ptr_location; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3375 | // The method load data holds |
| 3376 | // - thread entrypoint offset for kStringInit method if this is a string init invoke. |
| 3377 | // Note that there are multiple string init methods, each having its own offset. |
| 3378 | // - the method address for kDirectAddress |
| 3379 | // - the dex cache arrays offset for kDexCachePcRel. |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3380 | uint64_t method_load_data; |
| 3381 | uint64_t direct_code_ptr; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3382 | }; |
| 3383 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3384 | HInvokeStaticOrDirect(ArenaAllocator* arena, |
| 3385 | uint32_t number_of_arguments, |
| 3386 | Primitive::Type return_type, |
| 3387 | uint32_t dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3388 | uint32_t method_index, |
| 3389 | MethodReference target_method, |
| 3390 | DispatchInfo dispatch_info, |
Nicolas Geoffray | 7904129 | 2015-03-26 10:05:54 +0000 | [diff] [blame] | 3391 | InvokeType original_invoke_type, |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3392 | InvokeType invoke_type, |
| 3393 | ClinitCheckRequirement clinit_check_requirement) |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3394 | : HInvoke(arena, |
| 3395 | number_of_arguments, |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3396 | // There is one extra argument for the HCurrentMethod node, and |
| 3397 | // potentially one other if the clinit check is explicit, and one other |
| 3398 | // if the method is a string factory. |
| 3399 | 1u + (clinit_check_requirement == ClinitCheckRequirement::kExplicit ? 1u : 0u) |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3400 | + (dispatch_info.method_load_kind == MethodLoadKind::kStringInit ? 1u : 0u), |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3401 | return_type, |
| 3402 | dex_pc, |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3403 | method_index, |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3404 | original_invoke_type), |
Nicolas Geoffray | 1cf9528 | 2014-12-12 19:22:03 +0000 | [diff] [blame] | 3405 | invoke_type_(invoke_type), |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 3406 | clinit_check_requirement_(clinit_check_requirement), |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3407 | target_method_(target_method), |
| 3408 | dispatch_info_(dispatch_info) {} |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3409 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3410 | void SetDispatchInfo(const DispatchInfo& dispatch_info) { |
| 3411 | dispatch_info_ = dispatch_info; |
| 3412 | } |
| 3413 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3414 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3415 | // We access the method via the dex cache so we can't do an implicit null check. |
| 3416 | // TODO: for intrinsics we can generate implicit null checks. |
| 3417 | return false; |
| 3418 | } |
| 3419 | |
Nicolas Geoffray | efa8468 | 2015-08-12 18:28:14 -0700 | [diff] [blame] | 3420 | bool CanBeNull() const OVERRIDE { |
| 3421 | return return_type_ == Primitive::kPrimNot && !IsStringInit(); |
| 3422 | } |
| 3423 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3424 | InvokeType GetInvokeType() const { return invoke_type_; } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3425 | MethodLoadKind GetMethodLoadKind() const { return dispatch_info_.method_load_kind; } |
| 3426 | CodePtrLocation GetCodePtrLocation() const { return dispatch_info_.code_ptr_location; } |
| 3427 | bool IsRecursive() const { return GetMethodLoadKind() == MethodLoadKind::kRecursive; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3428 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3429 | bool IsStringInit() const { return GetMethodLoadKind() == MethodLoadKind::kStringInit; } |
Nicolas Geoffray | 38207af | 2015-06-01 15:46:22 +0100 | [diff] [blame] | 3430 | uint32_t GetCurrentMethodInputIndex() const { return GetNumberOfArguments(); } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3431 | bool HasMethodAddress() const { return GetMethodLoadKind() == MethodLoadKind::kDirectAddress; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 3432 | bool HasPcRelDexCache() const { |
| 3433 | return GetMethodLoadKind() == MethodLoadKind::kDexCachePcRelative; |
| 3434 | } |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3435 | bool HasDirectCodePtr() const { return GetCodePtrLocation() == CodePtrLocation::kCallDirect; } |
| 3436 | MethodReference GetTargetMethod() const { return target_method_; } |
| 3437 | |
| 3438 | int32_t GetStringInitOffset() const { |
| 3439 | DCHECK(IsStringInit()); |
| 3440 | return dispatch_info_.method_load_data; |
| 3441 | } |
| 3442 | |
| 3443 | uint64_t GetMethodAddress() const { |
| 3444 | DCHECK(HasMethodAddress()); |
| 3445 | return dispatch_info_.method_load_data; |
| 3446 | } |
| 3447 | |
| 3448 | uint32_t GetDexCacheArrayOffset() const { |
| 3449 | DCHECK(HasPcRelDexCache()); |
| 3450 | return dispatch_info_.method_load_data; |
| 3451 | } |
| 3452 | |
| 3453 | uint64_t GetDirectCodePtr() const { |
| 3454 | DCHECK(HasDirectCodePtr()); |
| 3455 | return dispatch_info_.direct_code_ptr; |
| 3456 | } |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3457 | |
Calin Juravle | 68ad649 | 2015-08-18 17:08:12 +0100 | [diff] [blame] | 3458 | ClinitCheckRequirement GetClinitCheckRequirement() const { return clinit_check_requirement_; } |
| 3459 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3460 | // Is this instruction a call to a static method? |
| 3461 | bool IsStatic() const { |
| 3462 | return GetInvokeType() == kStatic; |
| 3463 | } |
| 3464 | |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3465 | // Remove the art::HLoadClass instruction set as last input by |
| 3466 | // art::PrepareForRegisterAllocation::VisitClinitCheck in lieu of |
| 3467 | // the initial art::HClinitCheck instruction (only relevant for |
| 3468 | // static calls with explicit clinit check). |
| 3469 | void RemoveLoadClassAsLastInput() { |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3470 | DCHECK(IsStaticWithExplicitClinitCheck()); |
| 3471 | size_t last_input_index = InputCount() - 1; |
| 3472 | HInstruction* last_input = InputAt(last_input_index); |
| 3473 | DCHECK(last_input != nullptr); |
Roland Levillain | 3e3d733 | 2015-04-28 11:00:54 +0100 | [diff] [blame] | 3474 | DCHECK(last_input->IsLoadClass()) << last_input->DebugName(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3475 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3476 | inputs_.pop_back(); |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3477 | clinit_check_requirement_ = ClinitCheckRequirement::kImplicit; |
| 3478 | DCHECK(IsStaticWithImplicitClinitCheck()); |
| 3479 | } |
| 3480 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3481 | bool IsStringFactoryFor(HFakeString* str) const { |
| 3482 | if (!IsStringInit()) return false; |
| 3483 | // +1 for the current method. |
| 3484 | if (InputCount() == (number_of_arguments_ + 1)) return false; |
| 3485 | return InputAt(InputCount() - 1)->AsFakeString() == str; |
| 3486 | } |
| 3487 | |
| 3488 | void RemoveFakeStringArgumentAsLastInput() { |
| 3489 | DCHECK(IsStringInit()); |
| 3490 | size_t last_input_index = InputCount() - 1; |
| 3491 | HInstruction* last_input = InputAt(last_input_index); |
| 3492 | DCHECK(last_input != nullptr); |
| 3493 | DCHECK(last_input->IsFakeString()) << last_input->DebugName(); |
| 3494 | RemoveAsUserOfInput(last_input_index); |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 3495 | inputs_.pop_back(); |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 3496 | } |
| 3497 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3498 | // Is this a call to a static method whose declaring class has an |
| 3499 | // explicit intialization check in the graph? |
| 3500 | bool IsStaticWithExplicitClinitCheck() const { |
| 3501 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kExplicit); |
| 3502 | } |
| 3503 | |
| 3504 | // Is this a call to a static method whose declaring class has an |
| 3505 | // implicit intialization check requirement? |
| 3506 | bool IsStaticWithImplicitClinitCheck() const { |
| 3507 | return IsStatic() && (clinit_check_requirement_ == ClinitCheckRequirement::kImplicit); |
| 3508 | } |
| 3509 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3510 | DECLARE_INSTRUCTION(InvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3511 | |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3512 | protected: |
| 3513 | const HUserRecord<HInstruction*> InputRecordAt(size_t i) const OVERRIDE { |
| 3514 | const HUserRecord<HInstruction*> input_record = HInvoke::InputRecordAt(i); |
| 3515 | if (kIsDebugBuild && IsStaticWithExplicitClinitCheck() && (i == InputCount() - 1)) { |
| 3516 | HInstruction* input = input_record.GetInstruction(); |
| 3517 | // `input` is the last input of a static invoke marked as having |
| 3518 | // an explicit clinit check. It must either be: |
| 3519 | // - an art::HClinitCheck instruction, set by art::HGraphBuilder; or |
| 3520 | // - an art::HLoadClass instruction, set by art::PrepareForRegisterAllocation. |
| 3521 | DCHECK(input != nullptr); |
| 3522 | DCHECK(input->IsClinitCheck() || input->IsLoadClass()) << input->DebugName(); |
| 3523 | } |
| 3524 | return input_record; |
| 3525 | } |
| 3526 | |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3527 | private: |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3528 | const InvokeType invoke_type_; |
Roland Levillain | 4c0eb42 | 2015-04-24 16:43:49 +0100 | [diff] [blame] | 3529 | ClinitCheckRequirement clinit_check_requirement_; |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 3530 | // The target method may refer to different dex file or method index than the original |
| 3531 | // invoke. This happens for sharpened calls and for calls where a method was redeclared |
| 3532 | // in derived class to increase visibility. |
| 3533 | MethodReference target_method_; |
| 3534 | DispatchInfo dispatch_info_; |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3535 | |
Nicolas Geoffray | e53798a | 2014-12-01 10:31:54 +0000 | [diff] [blame] | 3536 | DISALLOW_COPY_AND_ASSIGN(HInvokeStaticOrDirect); |
Nicolas Geoffray | 8ccc3f5 | 2014-03-19 10:34:11 +0000 | [diff] [blame] | 3537 | }; |
| 3538 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3539 | class HInvokeVirtual : public HInvoke { |
| 3540 | public: |
| 3541 | HInvokeVirtual(ArenaAllocator* arena, |
| 3542 | uint32_t number_of_arguments, |
| 3543 | Primitive::Type return_type, |
| 3544 | uint32_t dex_pc, |
Andreas Gampe | 71fb52f | 2014-12-29 17:43:08 -0800 | [diff] [blame] | 3545 | uint32_t dex_method_index, |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3546 | uint32_t vtable_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3547 | : 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] | 3548 | vtable_index_(vtable_index) {} |
| 3549 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3550 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3551 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3552 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3553 | } |
| 3554 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 3555 | uint32_t GetVTableIndex() const { return vtable_index_; } |
| 3556 | |
| 3557 | DECLARE_INSTRUCTION(InvokeVirtual); |
| 3558 | |
| 3559 | private: |
| 3560 | const uint32_t vtable_index_; |
| 3561 | |
| 3562 | DISALLOW_COPY_AND_ASSIGN(HInvokeVirtual); |
| 3563 | }; |
| 3564 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3565 | class HInvokeInterface : public HInvoke { |
| 3566 | public: |
| 3567 | HInvokeInterface(ArenaAllocator* arena, |
| 3568 | uint32_t number_of_arguments, |
| 3569 | Primitive::Type return_type, |
| 3570 | uint32_t dex_pc, |
| 3571 | uint32_t dex_method_index, |
| 3572 | uint32_t imt_index) |
Nicolas Geoffray | b176d7c | 2015-05-20 18:48:31 +0100 | [diff] [blame] | 3573 | : 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] | 3574 | imt_index_(imt_index) {} |
| 3575 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3576 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3577 | // TODO: Add implicit null checks in intrinsics. |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 3578 | return (obj == InputAt(0)) && !GetLocations()->Intrinsified(); |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 3579 | } |
| 3580 | |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3581 | uint32_t GetImtIndex() const { return imt_index_; } |
| 3582 | uint32_t GetDexMethodIndex() const { return dex_method_index_; } |
| 3583 | |
| 3584 | DECLARE_INSTRUCTION(InvokeInterface); |
| 3585 | |
| 3586 | private: |
Nicolas Geoffray | 52839d1 | 2014-11-07 17:47:25 +0000 | [diff] [blame] | 3587 | const uint32_t imt_index_; |
| 3588 | |
| 3589 | DISALLOW_COPY_AND_ASSIGN(HInvokeInterface); |
| 3590 | }; |
| 3591 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3592 | class HNewInstance : public HExpression<1> { |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3593 | public: |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3594 | HNewInstance(HCurrentMethod* current_method, |
| 3595 | uint32_t dex_pc, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3596 | uint16_t type_index, |
| 3597 | const DexFile& dex_file, |
| 3598 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3599 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3600 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3601 | dex_file_(dex_file), |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3602 | entrypoint_(entrypoint) { |
| 3603 | SetRawInputAt(0, current_method); |
| 3604 | } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3605 | |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3606 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3607 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3608 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3609 | // Calls runtime so needs an environment. |
Calin Juravle | 92a6ed2 | 2014-12-02 18:58:03 +0000 | [diff] [blame] | 3610 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Andreas Gampe | 55d02cf | 2015-10-29 02:59:50 +0000 | [diff] [blame^] | 3611 | // It may throw when called on: |
| 3612 | // - interfaces |
| 3613 | // - abstract/innaccessible/unknown classes |
| 3614 | // TODO: optimize when possible. |
| 3615 | bool CanThrow() const OVERRIDE { return true; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 3616 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3617 | bool CanBeNull() const OVERRIDE { return false; } |
| 3618 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3619 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3620 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 3621 | DECLARE_INSTRUCTION(NewInstance); |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3622 | |
| 3623 | private: |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3624 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 3625 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3626 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | 2e7038a | 2014-04-03 18:49:58 +0100 | [diff] [blame] | 3627 | |
| 3628 | DISALLOW_COPY_AND_ASSIGN(HNewInstance); |
| 3629 | }; |
| 3630 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3631 | class HNeg : public HUnaryOperation { |
| 3632 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3633 | HNeg(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 3634 | : HUnaryOperation(result_type, input, dex_pc) {} |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3635 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3636 | template <typename T> T Compute(T x) const { return -x; } |
| 3637 | |
| 3638 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3639 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3640 | } |
| 3641 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3642 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3643 | } |
Roland Levillain | 9240d6a | 2014-10-20 16:47:04 +0100 | [diff] [blame] | 3644 | |
Roland Levillain | 88cb175 | 2014-10-20 16:36:47 +0100 | [diff] [blame] | 3645 | DECLARE_INSTRUCTION(Neg); |
| 3646 | |
| 3647 | private: |
| 3648 | DISALLOW_COPY_AND_ASSIGN(HNeg); |
| 3649 | }; |
| 3650 | |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3651 | class HNewArray : public HExpression<2> { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3652 | public: |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3653 | HNewArray(HInstruction* length, |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3654 | HCurrentMethod* current_method, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3655 | uint32_t dex_pc, |
| 3656 | uint16_t type_index, |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3657 | const DexFile& dex_file, |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3658 | QuickEntrypointEnum entrypoint) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3659 | : HExpression(Primitive::kPrimNot, SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3660 | type_index_(type_index), |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3661 | dex_file_(dex_file), |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3662 | entrypoint_(entrypoint) { |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3663 | SetRawInputAt(0, length); |
Nicolas Geoffray | 69aa601 | 2015-06-09 10:34:25 +0100 | [diff] [blame] | 3664 | SetRawInputAt(1, current_method); |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3665 | } |
| 3666 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3667 | uint16_t GetTypeIndex() const { return type_index_; } |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3668 | const DexFile& GetDexFile() const { return dex_file_; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3669 | |
| 3670 | // Calls runtime so needs an environment. |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3671 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3672 | |
Mingyao Yang | 0c365e6 | 2015-03-31 15:09:29 -0700 | [diff] [blame] | 3673 | // May throw NegativeArraySizeException, OutOfMemoryError, etc. |
| 3674 | bool CanThrow() const OVERRIDE { return true; } |
| 3675 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 3676 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3677 | |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3678 | QuickEntrypointEnum GetEntrypoint() const { return entrypoint_; } |
| 3679 | |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3680 | DECLARE_INSTRUCTION(NewArray); |
| 3681 | |
| 3682 | private: |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3683 | const uint16_t type_index_; |
Guillaume "Vermeille" Sanchez | 81d804a | 2015-05-20 12:42:25 +0100 | [diff] [blame] | 3684 | const DexFile& dex_file_; |
Nicolas Geoffray | cb1b00a | 2015-01-28 14:50:01 +0000 | [diff] [blame] | 3685 | const QuickEntrypointEnum entrypoint_; |
Nicolas Geoffray | a3d05a4 | 2014-10-20 17:41:32 +0100 | [diff] [blame] | 3686 | |
| 3687 | DISALLOW_COPY_AND_ASSIGN(HNewArray); |
| 3688 | }; |
| 3689 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3690 | class HAdd : public HBinaryOperation { |
| 3691 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3692 | HAdd(Primitive::Type result_type, |
| 3693 | HInstruction* left, |
| 3694 | HInstruction* right, |
| 3695 | uint32_t dex_pc = kNoDexPc) |
| 3696 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3697 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3698 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3699 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3700 | template <typename T> T Compute(T x, T y) const { return x + y; } |
| 3701 | |
| 3702 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3703 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3704 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3705 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3706 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3707 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3708 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3709 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3710 | |
Nicolas Geoffray | d8ee737 | 2014-03-28 15:43:40 +0000 | [diff] [blame] | 3711 | DECLARE_INSTRUCTION(Add); |
| 3712 | |
| 3713 | private: |
| 3714 | DISALLOW_COPY_AND_ASSIGN(HAdd); |
| 3715 | }; |
| 3716 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3717 | class HSub : public HBinaryOperation { |
| 3718 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3719 | HSub(Primitive::Type result_type, |
| 3720 | HInstruction* left, |
| 3721 | HInstruction* right, |
| 3722 | uint32_t dex_pc = kNoDexPc) |
| 3723 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3724 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3725 | template <typename T> T Compute(T x, T y) const { return x - y; } |
| 3726 | |
| 3727 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3728 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3729 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3730 | } |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3731 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3732 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3733 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9344568 | 2014-10-06 19:24:02 +0100 | [diff] [blame] | 3734 | } |
Roland Levillain | 556c3d1 | 2014-09-18 15:25:07 +0100 | [diff] [blame] | 3735 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 3736 | DECLARE_INSTRUCTION(Sub); |
| 3737 | |
| 3738 | private: |
| 3739 | DISALLOW_COPY_AND_ASSIGN(HSub); |
| 3740 | }; |
| 3741 | |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3742 | class HMul : public HBinaryOperation { |
| 3743 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3744 | HMul(Primitive::Type result_type, |
| 3745 | HInstruction* left, |
| 3746 | HInstruction* right, |
| 3747 | uint32_t dex_pc = kNoDexPc) |
| 3748 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3749 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 3750 | bool IsCommutative() const OVERRIDE { return true; } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3751 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3752 | template <typename T> T Compute(T x, T y) const { return x * y; } |
| 3753 | |
| 3754 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3755 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3756 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3757 | } |
| 3758 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3759 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3760 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3761 | } |
Calin Juravle | 34bacdf | 2014-10-07 20:23:36 +0100 | [diff] [blame] | 3762 | |
| 3763 | DECLARE_INSTRUCTION(Mul); |
| 3764 | |
| 3765 | private: |
| 3766 | DISALLOW_COPY_AND_ASSIGN(HMul); |
| 3767 | }; |
| 3768 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3769 | class HDiv : public HBinaryOperation { |
| 3770 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3771 | HDiv(Primitive::Type result_type, |
| 3772 | HInstruction* left, |
| 3773 | HInstruction* right, |
| 3774 | uint32_t dex_pc) |
| 3775 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3776 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3777 | template <typename T> |
| 3778 | T Compute(T x, T y) const { |
| 3779 | // Our graph structure ensures we never have 0 for `y` during |
| 3780 | // constant folding. |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3781 | DCHECK_NE(y, 0); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3782 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
Nicolas Geoffray | cd2de0c | 2014-11-06 15:59:38 +0000 | [diff] [blame] | 3783 | return (y == -1) ? -x : x / y; |
| 3784 | } |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3785 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3786 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3787 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3788 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3789 | } |
| 3790 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3791 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3792 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3793 | } |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3794 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3795 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3796 | // The generated code can use a runtime call. |
| 3797 | return SideEffects::CanTriggerGC(); |
| 3798 | } |
| 3799 | |
Calin Juravle | 7c4954d | 2014-10-28 16:57:40 +0000 | [diff] [blame] | 3800 | DECLARE_INSTRUCTION(Div); |
| 3801 | |
| 3802 | private: |
| 3803 | DISALLOW_COPY_AND_ASSIGN(HDiv); |
| 3804 | }; |
| 3805 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3806 | class HRem : public HBinaryOperation { |
| 3807 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3808 | HRem(Primitive::Type result_type, |
| 3809 | HInstruction* left, |
| 3810 | HInstruction* right, |
| 3811 | uint32_t dex_pc) |
| 3812 | : HBinaryOperation(result_type, left, right, SideEffectsForArchRuntimeCalls(), dex_pc) {} |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3813 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3814 | template <typename T> |
| 3815 | T Compute(T x, T y) const { |
| 3816 | // Our graph structure ensures we never have 0 for `y` during |
| 3817 | // constant folding. |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3818 | DCHECK_NE(y, 0); |
| 3819 | // Special case -1 to avoid getting a SIGFPE on x86(_64). |
| 3820 | return (y == -1) ? 0 : x % y; |
| 3821 | } |
| 3822 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3823 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3824 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3825 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3826 | } |
| 3827 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3828 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3829 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3830 | } |
| 3831 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3832 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 3833 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 3834 | return SideEffects::CanTriggerGC(); |
| 3835 | } |
| 3836 | |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3837 | DECLARE_INSTRUCTION(Rem); |
| 3838 | |
| 3839 | private: |
Calin Juravle | bacfec3 | 2014-11-14 15:54:36 +0000 | [diff] [blame] | 3840 | DISALLOW_COPY_AND_ASSIGN(HRem); |
| 3841 | }; |
| 3842 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3843 | class HDivZeroCheck : public HExpression<1> { |
| 3844 | public: |
| 3845 | HDivZeroCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3846 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3847 | SetRawInputAt(0, value); |
| 3848 | } |
| 3849 | |
Serguei Katkov | 8c0676c | 2015-08-03 13:55:33 +0600 | [diff] [blame] | 3850 | Primitive::Type GetType() const OVERRIDE { return InputAt(0)->GetType(); } |
| 3851 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3852 | bool CanBeMoved() const OVERRIDE { return true; } |
| 3853 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 3854 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3855 | return true; |
| 3856 | } |
| 3857 | |
| 3858 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 3859 | bool CanThrow() const OVERRIDE { return true; } |
| 3860 | |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3861 | DECLARE_INSTRUCTION(DivZeroCheck); |
| 3862 | |
| 3863 | private: |
Calin Juravle | d0d4852 | 2014-11-04 16:40:20 +0000 | [diff] [blame] | 3864 | DISALLOW_COPY_AND_ASSIGN(HDivZeroCheck); |
| 3865 | }; |
| 3866 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3867 | class HShl : public HBinaryOperation { |
| 3868 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3869 | HShl(Primitive::Type result_type, |
| 3870 | HInstruction* left, |
| 3871 | HInstruction* right, |
| 3872 | uint32_t dex_pc = kNoDexPc) |
| 3873 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3874 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3875 | template <typename T, typename U, typename V> |
| 3876 | T Compute(T x, U y, V max_shift_value) const { |
| 3877 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3878 | "V is not the unsigned integer type corresponding to T"); |
| 3879 | return x << (y & max_shift_value); |
| 3880 | } |
| 3881 | |
| 3882 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3883 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3884 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3885 | } |
| 3886 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3887 | // case is handled as `x << static_cast<int>(y)`. |
| 3888 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3889 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3890 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3891 | } |
| 3892 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3893 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3894 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3895 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3896 | |
| 3897 | DECLARE_INSTRUCTION(Shl); |
| 3898 | |
| 3899 | private: |
| 3900 | DISALLOW_COPY_AND_ASSIGN(HShl); |
| 3901 | }; |
| 3902 | |
| 3903 | class HShr : public HBinaryOperation { |
| 3904 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3905 | HShr(Primitive::Type result_type, |
| 3906 | HInstruction* left, |
| 3907 | HInstruction* right, |
| 3908 | uint32_t dex_pc = kNoDexPc) |
| 3909 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3910 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3911 | template <typename T, typename U, typename V> |
| 3912 | T Compute(T x, U y, V max_shift_value) const { |
| 3913 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3914 | "V is not the unsigned integer type corresponding to T"); |
| 3915 | return x >> (y & max_shift_value); |
| 3916 | } |
| 3917 | |
| 3918 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3919 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3920 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3921 | } |
| 3922 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3923 | // case is handled as `x >> static_cast<int>(y)`. |
| 3924 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3925 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3926 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3927 | } |
| 3928 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3929 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3930 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3931 | } |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3932 | |
| 3933 | DECLARE_INSTRUCTION(Shr); |
| 3934 | |
| 3935 | private: |
| 3936 | DISALLOW_COPY_AND_ASSIGN(HShr); |
| 3937 | }; |
| 3938 | |
| 3939 | class HUShr : public HBinaryOperation { |
| 3940 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3941 | HUShr(Primitive::Type result_type, |
| 3942 | HInstruction* left, |
| 3943 | HInstruction* right, |
| 3944 | uint32_t dex_pc = kNoDexPc) |
| 3945 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3946 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3947 | template <typename T, typename U, typename V> |
| 3948 | T Compute(T x, U y, V max_shift_value) const { |
| 3949 | static_assert(std::is_same<V, typename std::make_unsigned<T>::type>::value, |
| 3950 | "V is not the unsigned integer type corresponding to T"); |
| 3951 | V ux = static_cast<V>(x); |
| 3952 | return static_cast<T>(ux >> (y & max_shift_value)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3953 | } |
| 3954 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3955 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
| 3956 | return GetBlock()->GetGraph()->GetIntConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3957 | Compute(x->GetValue(), y->GetValue(), kMaxIntShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3958 | } |
| 3959 | // There is no `Evaluate(HIntConstant* x, HLongConstant* y)`, as this |
| 3960 | // case is handled as `x >>> static_cast<int>(y)`. |
| 3961 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
| 3962 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3963 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3964 | } |
| 3965 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
| 3966 | return GetBlock()->GetGraph()->GetLongConstant( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3967 | Compute(x->GetValue(), y->GetValue(), kMaxLongShiftValue), GetDexPc()); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 3968 | } |
| 3969 | |
| 3970 | DECLARE_INSTRUCTION(UShr); |
| 3971 | |
| 3972 | private: |
| 3973 | DISALLOW_COPY_AND_ASSIGN(HUShr); |
| 3974 | }; |
| 3975 | |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3976 | class HAnd : public HBinaryOperation { |
| 3977 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3978 | HAnd(Primitive::Type result_type, |
| 3979 | HInstruction* left, |
| 3980 | HInstruction* right, |
| 3981 | uint32_t dex_pc = kNoDexPc) |
| 3982 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3983 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 3984 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 3985 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3986 | template <typename T, typename U> |
| 3987 | auto Compute(T x, U y) const -> decltype(x & y) { return x & y; } |
| 3988 | |
| 3989 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3990 | return GetBlock()->GetGraph()->GetIntConstant( |
| 3991 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3992 | } |
| 3993 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3994 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3995 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 3996 | } |
| 3997 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 3998 | return GetBlock()->GetGraph()->GetLongConstant( |
| 3999 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4000 | } |
| 4001 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4002 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4003 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4004 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4005 | |
| 4006 | DECLARE_INSTRUCTION(And); |
| 4007 | |
| 4008 | private: |
| 4009 | DISALLOW_COPY_AND_ASSIGN(HAnd); |
| 4010 | }; |
| 4011 | |
| 4012 | class HOr : public HBinaryOperation { |
| 4013 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4014 | HOr(Primitive::Type result_type, |
| 4015 | HInstruction* left, |
| 4016 | HInstruction* right, |
| 4017 | uint32_t dex_pc = kNoDexPc) |
| 4018 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4019 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4020 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4021 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4022 | template <typename T, typename U> |
| 4023 | auto Compute(T x, U y) const -> decltype(x | y) { return x | y; } |
| 4024 | |
| 4025 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4026 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4027 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4028 | } |
| 4029 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4030 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4031 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4032 | } |
| 4033 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4034 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4035 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4036 | } |
| 4037 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4038 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4039 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4040 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4041 | |
| 4042 | DECLARE_INSTRUCTION(Or); |
| 4043 | |
| 4044 | private: |
| 4045 | DISALLOW_COPY_AND_ASSIGN(HOr); |
| 4046 | }; |
| 4047 | |
| 4048 | class HXor : public HBinaryOperation { |
| 4049 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4050 | HXor(Primitive::Type result_type, |
| 4051 | HInstruction* left, |
| 4052 | HInstruction* right, |
| 4053 | uint32_t dex_pc = kNoDexPc) |
| 4054 | : HBinaryOperation(result_type, left, right, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4055 | |
Mingyao Yang | dc5ac73 | 2015-02-25 11:28:05 -0800 | [diff] [blame] | 4056 | bool IsCommutative() const OVERRIDE { return true; } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4057 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4058 | template <typename T, typename U> |
| 4059 | auto Compute(T x, U y) const -> decltype(x ^ y) { return x ^ y; } |
| 4060 | |
| 4061 | HConstant* Evaluate(HIntConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4062 | return GetBlock()->GetGraph()->GetIntConstant( |
| 4063 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4064 | } |
| 4065 | HConstant* Evaluate(HIntConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4066 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4067 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4068 | } |
| 4069 | HConstant* Evaluate(HLongConstant* x, HIntConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4070 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4071 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4072 | } |
| 4073 | HConstant* Evaluate(HLongConstant* x, HLongConstant* y) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4074 | return GetBlock()->GetGraph()->GetLongConstant( |
| 4075 | Compute(x->GetValue(), y->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4076 | } |
Nicolas Geoffray | 9574c4b | 2014-11-12 13:19:37 +0000 | [diff] [blame] | 4077 | |
| 4078 | DECLARE_INSTRUCTION(Xor); |
| 4079 | |
| 4080 | private: |
| 4081 | DISALLOW_COPY_AND_ASSIGN(HXor); |
| 4082 | }; |
| 4083 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4084 | // The value of a parameter in this method. Its location depends on |
| 4085 | // the calling convention. |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 4086 | class HParameterValue : public HExpression<0> { |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4087 | public: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4088 | HParameterValue(const DexFile& dex_file, |
| 4089 | uint16_t type_index, |
| 4090 | uint8_t index, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4091 | Primitive::Type parameter_type, |
| 4092 | bool is_this = false) |
| 4093 | : HExpression(parameter_type, SideEffects::None(), kNoDexPc), |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4094 | dex_file_(dex_file), |
| 4095 | type_index_(type_index), |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4096 | index_(index), |
| 4097 | is_this_(is_this), |
| 4098 | can_be_null_(!is_this) {} |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4099 | |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4100 | const DexFile& GetDexFile() const { return dex_file_; } |
| 4101 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4102 | uint8_t GetIndex() const { return index_; } |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4103 | bool IsThis() const { return is_this_; } |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4104 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4105 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4106 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4107 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4108 | DECLARE_INSTRUCTION(ParameterValue); |
| 4109 | |
| 4110 | private: |
Calin Juravle | e6e3bea | 2015-10-14 13:53:10 +0000 | [diff] [blame] | 4111 | const DexFile& dex_file_; |
| 4112 | const uint16_t type_index_; |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4113 | // The index of this parameter in the parameters list. Must be less |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4114 | // than HGraph::number_of_in_vregs_. |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4115 | const uint8_t index_; |
| 4116 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4117 | // Whether or not the parameter value corresponds to 'this' argument. |
| 4118 | const bool is_this_; |
| 4119 | |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4120 | bool can_be_null_; |
| 4121 | |
Nicolas Geoffray | f583e59 | 2014-04-07 13:20:42 +0100 | [diff] [blame] | 4122 | DISALLOW_COPY_AND_ASSIGN(HParameterValue); |
| 4123 | }; |
| 4124 | |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4125 | class HNot : public HUnaryOperation { |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4126 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4127 | HNot(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4128 | : HUnaryOperation(result_type, input, dex_pc) {} |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4129 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4130 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4131 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4132 | return true; |
| 4133 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4134 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4135 | template <typename T> T Compute(T x) const { return ~x; } |
| 4136 | |
| 4137 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4138 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4139 | } |
| 4140 | HConstant* Evaluate(HLongConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4141 | return GetBlock()->GetGraph()->GetLongConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4142 | } |
Roland Levillain | 1cc5f251 | 2014-10-22 18:06:21 +0100 | [diff] [blame] | 4143 | |
Nicolas Geoffray | b55f835 | 2014-04-07 15:26:35 +0100 | [diff] [blame] | 4144 | DECLARE_INSTRUCTION(Not); |
| 4145 | |
| 4146 | private: |
| 4147 | DISALLOW_COPY_AND_ASSIGN(HNot); |
| 4148 | }; |
| 4149 | |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4150 | class HBooleanNot : public HUnaryOperation { |
| 4151 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4152 | explicit HBooleanNot(HInstruction* input, uint32_t dex_pc = kNoDexPc) |
| 4153 | : HUnaryOperation(Primitive::Type::kPrimBoolean, input, dex_pc) {} |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4154 | |
| 4155 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4156 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4157 | return true; |
| 4158 | } |
| 4159 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4160 | template <typename T> bool Compute(T x) const { |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4161 | DCHECK(IsUint<1>(x)); |
| 4162 | return !x; |
| 4163 | } |
| 4164 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4165 | HConstant* Evaluate(HIntConstant* x) const OVERRIDE { |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4166 | return GetBlock()->GetGraph()->GetIntConstant(Compute(x->GetValue()), GetDexPc()); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 4167 | } |
| 4168 | HConstant* Evaluate(HLongConstant* x ATTRIBUTE_UNUSED) const OVERRIDE { |
| 4169 | LOG(FATAL) << DebugName() << " is not defined for long values"; |
David Brazdil | 66d126e | 2015-04-03 16:02:44 +0100 | [diff] [blame] | 4170 | UNREACHABLE(); |
| 4171 | } |
| 4172 | |
| 4173 | DECLARE_INSTRUCTION(BooleanNot); |
| 4174 | |
| 4175 | private: |
| 4176 | DISALLOW_COPY_AND_ASSIGN(HBooleanNot); |
| 4177 | }; |
| 4178 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4179 | class HTypeConversion : public HExpression<1> { |
| 4180 | public: |
| 4181 | // Instantiate a type conversion of `input` to `result_type`. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4182 | HTypeConversion(Primitive::Type result_type, HInstruction* input, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4183 | : HExpression(result_type, |
| 4184 | SideEffectsForArchRuntimeCalls(input->GetType(), result_type), |
| 4185 | dex_pc) { |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4186 | SetRawInputAt(0, input); |
| 4187 | DCHECK_NE(input->GetType(), result_type); |
| 4188 | } |
| 4189 | |
| 4190 | HInstruction* GetInput() const { return InputAt(0); } |
| 4191 | Primitive::Type GetInputType() const { return GetInput()->GetType(); } |
| 4192 | Primitive::Type GetResultType() const { return GetType(); } |
| 4193 | |
Goran Jakovljevic | f652cec | 2015-08-25 16:11:42 +0200 | [diff] [blame] | 4194 | // Required by the x86, ARM, MIPS and MIPS64 code generators when producing calls |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4195 | // to the runtime. |
Roland Levillain | 624279f | 2014-12-04 11:54:28 +0000 | [diff] [blame] | 4196 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4197 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | ed9b195 | 2014-11-06 11:10:17 +0000 | [diff] [blame] | 4198 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { return true; } |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4199 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 4200 | // Try to statically evaluate the conversion and return a HConstant |
| 4201 | // containing the result. If the input cannot be converted, return nullptr. |
| 4202 | HConstant* TryStaticEvaluation() const; |
| 4203 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4204 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type input_type, |
| 4205 | Primitive::Type result_type) { |
| 4206 | // Some architectures may not require the 'GC' side effects, but at this point |
| 4207 | // in the compilation process we do not know what architecture we will |
| 4208 | // generate code for, so we must be conservative. |
Roland Levillain | df3f822 | 2015-08-13 12:31:44 +0100 | [diff] [blame] | 4209 | if ((Primitive::IsFloatingPointType(input_type) && Primitive::IsIntegralType(result_type)) |
| 4210 | || (input_type == Primitive::kPrimLong && Primitive::IsFloatingPointType(result_type))) { |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4211 | return SideEffects::CanTriggerGC(); |
| 4212 | } |
| 4213 | return SideEffects::None(); |
| 4214 | } |
| 4215 | |
Roland Levillain | dff1f28 | 2014-11-05 14:15:05 +0000 | [diff] [blame] | 4216 | DECLARE_INSTRUCTION(TypeConversion); |
| 4217 | |
| 4218 | private: |
| 4219 | DISALLOW_COPY_AND_ASSIGN(HTypeConversion); |
| 4220 | }; |
| 4221 | |
Nicolas Geoffray | 276d9da | 2015-02-02 18:24:11 +0000 | [diff] [blame] | 4222 | static constexpr uint32_t kNoRegNumber = -1; |
| 4223 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4224 | class HPhi : public HInstruction { |
| 4225 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4226 | HPhi(ArenaAllocator* arena, |
| 4227 | uint32_t reg_number, |
| 4228 | size_t number_of_inputs, |
| 4229 | Primitive::Type type, |
| 4230 | uint32_t dex_pc = kNoDexPc) |
| 4231 | : HInstruction(SideEffects::None(), dex_pc), |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4232 | inputs_(number_of_inputs, arena->Adapter(kArenaAllocPhiInputs)), |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4233 | reg_number_(reg_number), |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4234 | type_(type), |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4235 | is_live_(false), |
| 4236 | can_be_null_(true) { |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4237 | } |
| 4238 | |
Nicolas Geoffray | e0fe7ae | 2015-03-09 10:02:49 +0000 | [diff] [blame] | 4239 | // Returns a type equivalent to the given `type`, but that a `HPhi` can hold. |
| 4240 | static Primitive::Type ToPhiType(Primitive::Type type) { |
| 4241 | switch (type) { |
| 4242 | case Primitive::kPrimBoolean: |
| 4243 | case Primitive::kPrimByte: |
| 4244 | case Primitive::kPrimShort: |
| 4245 | case Primitive::kPrimChar: |
| 4246 | return Primitive::kPrimInt; |
| 4247 | default: |
| 4248 | return type; |
| 4249 | } |
| 4250 | } |
| 4251 | |
David Brazdil | ffee3d3 | 2015-07-06 11:48:53 +0100 | [diff] [blame] | 4252 | bool IsCatchPhi() const { return GetBlock()->IsCatchBlock(); } |
| 4253 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4254 | size_t InputCount() const OVERRIDE { return inputs_.size(); } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4255 | |
| 4256 | void AddInput(HInstruction* input); |
David Brazdil | 2d7352b | 2015-04-20 14:52:42 +0100 | [diff] [blame] | 4257 | void RemoveInputAt(size_t index); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4258 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4259 | Primitive::Type GetType() const OVERRIDE { return type_; } |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4260 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4261 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4262 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 4263 | void SetCanBeNull(bool can_be_null) { can_be_null_ = can_be_null; } |
| 4264 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4265 | uint32_t GetRegNumber() const { return reg_number_; } |
| 4266 | |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4267 | void SetDead() { is_live_ = false; } |
| 4268 | void SetLive() { is_live_ = true; } |
| 4269 | bool IsDead() const { return !is_live_; } |
| 4270 | bool IsLive() const { return is_live_; } |
| 4271 | |
David Brazdil | 77a48ae | 2015-09-15 12:34:04 +0000 | [diff] [blame] | 4272 | bool IsVRegEquivalentOf(HInstruction* other) const { |
| 4273 | return other != nullptr |
| 4274 | && other->IsPhi() |
| 4275 | && other->AsPhi()->GetBlock() == GetBlock() |
| 4276 | && other->AsPhi()->GetRegNumber() == GetRegNumber(); |
| 4277 | } |
| 4278 | |
Calin Juravle | a4f8831 | 2015-04-16 12:57:19 +0100 | [diff] [blame] | 4279 | // Returns the next equivalent phi (starting from the current one) or null if there is none. |
| 4280 | // An equivalent phi is a phi having the same dex register and type. |
| 4281 | // It assumes that phis with the same dex register are adjacent. |
| 4282 | HPhi* GetNextEquivalentPhiWithSameType() { |
| 4283 | HInstruction* next = GetNext(); |
| 4284 | while (next != nullptr && next->AsPhi()->GetRegNumber() == reg_number_) { |
| 4285 | if (next->GetType() == GetType()) { |
| 4286 | return next->AsPhi(); |
| 4287 | } |
| 4288 | next = next->GetNext(); |
| 4289 | } |
| 4290 | return nullptr; |
| 4291 | } |
| 4292 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4293 | DECLARE_INSTRUCTION(Phi); |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4294 | |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4295 | protected: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4296 | const HUserRecord<HInstruction*> InputRecordAt(size_t index) const OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4297 | return inputs_[index]; |
| 4298 | } |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4299 | |
| 4300 | void SetRawInputRecordAt(size_t index, const HUserRecord<HInstruction*>& input) OVERRIDE { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4301 | inputs_[index] = input; |
David Brazdil | 1abb419 | 2015-02-17 18:33:36 +0000 | [diff] [blame] | 4302 | } |
| 4303 | |
Nicolas Geoffray | 96f89a2 | 2014-07-11 10:57:49 +0100 | [diff] [blame] | 4304 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 4305 | ArenaVector<HUserRecord<HInstruction*> > inputs_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4306 | const uint32_t reg_number_; |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 4307 | Primitive::Type type_; |
Nicolas Geoffray | 7dc206a | 2014-07-11 09:49:49 +0100 | [diff] [blame] | 4308 | bool is_live_; |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4309 | bool can_be_null_; |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4310 | |
Nicolas Geoffray | c32e770 | 2014-04-24 12:43:16 +0100 | [diff] [blame] | 4311 | DISALLOW_COPY_AND_ASSIGN(HPhi); |
| 4312 | }; |
| 4313 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4314 | class HNullCheck : public HExpression<1> { |
| 4315 | public: |
| 4316 | HNullCheck(HInstruction* value, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4317 | : HExpression(value->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4318 | SetRawInputAt(0, value); |
| 4319 | } |
| 4320 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4321 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4322 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4323 | return true; |
| 4324 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4325 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4326 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4327 | |
Calin Juravle | 10e244f | 2015-01-26 18:54:32 +0000 | [diff] [blame] | 4328 | bool CanThrow() const OVERRIDE { return true; } |
| 4329 | |
| 4330 | bool CanBeNull() const OVERRIDE { return false; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4331 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4332 | |
| 4333 | DECLARE_INSTRUCTION(NullCheck); |
| 4334 | |
| 4335 | private: |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4336 | DISALLOW_COPY_AND_ASSIGN(HNullCheck); |
| 4337 | }; |
| 4338 | |
| 4339 | class FieldInfo : public ValueObject { |
| 4340 | public: |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4341 | FieldInfo(MemberOffset field_offset, |
| 4342 | Primitive::Type field_type, |
| 4343 | bool is_volatile, |
| 4344 | uint32_t index, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4345 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4346 | const DexFile& dex_file, |
| 4347 | Handle<mirror::DexCache> dex_cache) |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4348 | : field_offset_(field_offset), |
| 4349 | field_type_(field_type), |
| 4350 | is_volatile_(is_volatile), |
| 4351 | index_(index), |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4352 | declaring_class_def_index_(declaring_class_def_index), |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4353 | dex_file_(dex_file), |
| 4354 | dex_cache_(dex_cache) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4355 | |
| 4356 | MemberOffset GetFieldOffset() const { return field_offset_; } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4357 | Primitive::Type GetFieldType() const { return field_type_; } |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4358 | uint32_t GetFieldIndex() const { return index_; } |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4359 | uint16_t GetDeclaringClassDefIndex() const { return declaring_class_def_index_;} |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4360 | const DexFile& GetDexFile() const { return dex_file_; } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4361 | bool IsVolatile() const { return is_volatile_; } |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4362 | Handle<mirror::DexCache> GetDexCache() const { return dex_cache_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4363 | |
| 4364 | private: |
| 4365 | const MemberOffset field_offset_; |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4366 | const Primitive::Type field_type_; |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4367 | const bool is_volatile_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4368 | const uint32_t index_; |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4369 | const uint16_t declaring_class_def_index_; |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4370 | const DexFile& dex_file_; |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4371 | const Handle<mirror::DexCache> dex_cache_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4372 | }; |
| 4373 | |
| 4374 | class HInstanceFieldGet : public HExpression<1> { |
| 4375 | public: |
| 4376 | HInstanceFieldGet(HInstruction* value, |
| 4377 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4378 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4379 | bool is_volatile, |
| 4380 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4381 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4382 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4383 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4384 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4385 | : HExpression(field_type, |
| 4386 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4387 | dex_pc), |
| 4388 | field_info_(field_offset, |
| 4389 | field_type, |
| 4390 | is_volatile, |
| 4391 | field_idx, |
| 4392 | declaring_class_def_index, |
| 4393 | dex_file, |
| 4394 | dex_cache) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4395 | SetRawInputAt(0, value); |
| 4396 | } |
| 4397 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4398 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4399 | |
| 4400 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4401 | HInstanceFieldGet* other_get = other->AsInstanceFieldGet(); |
| 4402 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4403 | } |
| 4404 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4405 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4406 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4407 | } |
| 4408 | |
| 4409 | size_t ComputeHashCode() const OVERRIDE { |
Nicolas Geoffray | d31cf3d | 2014-09-08 17:30:24 +0100 | [diff] [blame] | 4410 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4411 | } |
| 4412 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4413 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4414 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4415 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4416 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4417 | |
| 4418 | DECLARE_INSTRUCTION(InstanceFieldGet); |
| 4419 | |
| 4420 | private: |
| 4421 | const FieldInfo field_info_; |
| 4422 | |
| 4423 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldGet); |
| 4424 | }; |
| 4425 | |
| 4426 | class HInstanceFieldSet : public HTemplateInstruction<2> { |
| 4427 | public: |
| 4428 | HInstanceFieldSet(HInstruction* object, |
| 4429 | HInstruction* value, |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4430 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4431 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4432 | bool is_volatile, |
| 4433 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4434 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4435 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4436 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4437 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4438 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4439 | dex_pc), |
| 4440 | field_info_(field_offset, |
| 4441 | field_type, |
| 4442 | is_volatile, |
| 4443 | field_idx, |
| 4444 | declaring_class_def_index, |
| 4445 | dex_file, |
| 4446 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4447 | value_can_be_null_(true) { |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4448 | SetRawInputAt(0, object); |
| 4449 | SetRawInputAt(1, value); |
| 4450 | } |
| 4451 | |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4452 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4453 | return (obj == InputAt(0)) && GetFieldOffset().Uint32Value() < kPageSize; |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4454 | } |
| 4455 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4456 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4457 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4458 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4459 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4460 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4461 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4462 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4463 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4464 | DECLARE_INSTRUCTION(InstanceFieldSet); |
| 4465 | |
| 4466 | private: |
| 4467 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4468 | bool value_can_be_null_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4469 | |
| 4470 | DISALLOW_COPY_AND_ASSIGN(HInstanceFieldSet); |
| 4471 | }; |
| 4472 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4473 | class HArrayGet : public HExpression<2> { |
| 4474 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4475 | HArrayGet(HInstruction* array, |
| 4476 | HInstruction* index, |
| 4477 | Primitive::Type type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4478 | uint32_t dex_pc, |
| 4479 | SideEffects additional_side_effects = SideEffects::None()) |
| 4480 | : HExpression(type, |
| 4481 | SideEffects::ArrayReadOfType(type).Union(additional_side_effects), |
| 4482 | dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4483 | SetRawInputAt(0, array); |
| 4484 | SetRawInputAt(1, index); |
| 4485 | } |
| 4486 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4487 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4488 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4489 | return true; |
| 4490 | } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4491 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4492 | // TODO: We can be smarter here. |
| 4493 | // Currently, the array access is always preceded by an ArrayLength or a NullCheck |
| 4494 | // which generates the implicit null check. There are cases when these can be removed |
| 4495 | // to produce better code. If we ever add optimizations to do so we should allow an |
| 4496 | // implicit check here (as long as the address falls in the first page). |
| 4497 | return false; |
| 4498 | } |
| 4499 | |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4500 | void SetType(Primitive::Type type) { type_ = type; } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4501 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4502 | HInstruction* GetArray() const { return InputAt(0); } |
| 4503 | HInstruction* GetIndex() const { return InputAt(1); } |
| 4504 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4505 | DECLARE_INSTRUCTION(ArrayGet); |
| 4506 | |
| 4507 | private: |
| 4508 | DISALLOW_COPY_AND_ASSIGN(HArrayGet); |
| 4509 | }; |
| 4510 | |
| 4511 | class HArraySet : public HTemplateInstruction<3> { |
| 4512 | public: |
| 4513 | HArraySet(HInstruction* array, |
| 4514 | HInstruction* index, |
| 4515 | HInstruction* value, |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4516 | Primitive::Type expected_component_type, |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4517 | uint32_t dex_pc, |
| 4518 | SideEffects additional_side_effects = SideEffects::None()) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4519 | : HTemplateInstruction( |
| 4520 | SideEffects::ArrayWriteOfType(expected_component_type).Union( |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4521 | SideEffectsForArchRuntimeCalls(value->GetType())).Union( |
| 4522 | additional_side_effects), |
| 4523 | dex_pc), |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4524 | expected_component_type_(expected_component_type), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4525 | needs_type_check_(value->GetType() == Primitive::kPrimNot), |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4526 | value_can_be_null_(true), |
| 4527 | static_type_of_array_is_object_array_(false) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4528 | SetRawInputAt(0, array); |
| 4529 | SetRawInputAt(1, index); |
| 4530 | SetRawInputAt(2, value); |
| 4531 | } |
| 4532 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4533 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4534 | // We currently always call a runtime method to catch array store |
| 4535 | // exceptions. |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4536 | return needs_type_check_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4537 | } |
| 4538 | |
Mingyao Yang | 81014cb | 2015-06-02 03:16:27 -0700 | [diff] [blame] | 4539 | // Can throw ArrayStoreException. |
| 4540 | bool CanThrow() const OVERRIDE { return needs_type_check_; } |
| 4541 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4542 | bool CanDoImplicitNullCheckOn(HInstruction* obj ATTRIBUTE_UNUSED) const OVERRIDE { |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4543 | // TODO: Same as for ArrayGet. |
| 4544 | return false; |
| 4545 | } |
| 4546 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4547 | void ClearNeedsTypeCheck() { |
| 4548 | needs_type_check_ = false; |
| 4549 | } |
| 4550 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4551 | void ClearValueCanBeNull() { |
| 4552 | value_can_be_null_ = false; |
| 4553 | } |
| 4554 | |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4555 | void SetStaticTypeOfArrayIsObjectArray() { |
| 4556 | static_type_of_array_is_object_array_ = true; |
| 4557 | } |
| 4558 | |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4559 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4560 | bool NeedsTypeCheck() const { return needs_type_check_; } |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4561 | bool StaticTypeOfArrayIsObjectArray() const { return static_type_of_array_is_object_array_; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4562 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4563 | HInstruction* GetArray() const { return InputAt(0); } |
| 4564 | HInstruction* GetIndex() const { return InputAt(1); } |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4565 | HInstruction* GetValue() const { return InputAt(2); } |
| 4566 | |
| 4567 | Primitive::Type GetComponentType() const { |
| 4568 | // The Dex format does not type floating point index operations. Since the |
| 4569 | // `expected_component_type_` is set during building and can therefore not |
| 4570 | // be correct, we also check what is the value type. If it is a floating |
| 4571 | // point type, we must use that type. |
| 4572 | Primitive::Type value_type = GetValue()->GetType(); |
| 4573 | return ((value_type == Primitive::kPrimFloat) || (value_type == Primitive::kPrimDouble)) |
| 4574 | ? value_type |
| 4575 | : expected_component_type_; |
| 4576 | } |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 4577 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4578 | Primitive::Type GetRawExpectedComponentType() const { |
| 4579 | return expected_component_type_; |
| 4580 | } |
| 4581 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4582 | static SideEffects SideEffectsForArchRuntimeCalls(Primitive::Type value_type) { |
| 4583 | return (value_type == Primitive::kPrimNot) ? SideEffects::CanTriggerGC() : SideEffects::None(); |
| 4584 | } |
| 4585 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4586 | DECLARE_INSTRUCTION(ArraySet); |
| 4587 | |
| 4588 | private: |
Nicolas Geoffray | 102cbed | 2014-10-15 18:31:05 +0100 | [diff] [blame] | 4589 | const Primitive::Type expected_component_type_; |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4590 | bool needs_type_check_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4591 | bool value_can_be_null_; |
Nicolas Geoffray | e0395dd | 2015-09-25 11:04:45 +0100 | [diff] [blame] | 4592 | // Cached information for the reference_type_info_ so that codegen |
| 4593 | // does not need to inspect the static type. |
| 4594 | bool static_type_of_array_is_object_array_; |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4595 | |
| 4596 | DISALLOW_COPY_AND_ASSIGN(HArraySet); |
| 4597 | }; |
| 4598 | |
| 4599 | class HArrayLength : public HExpression<1> { |
| 4600 | public: |
Nicolas Geoffray | ee3cf07 | 2015-10-06 11:45:02 +0100 | [diff] [blame] | 4601 | HArrayLength(HInstruction* array, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4602 | : HExpression(Primitive::kPrimInt, SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4603 | // Note that arrays do not change length, so the instruction does not |
| 4604 | // depend on any write. |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4605 | SetRawInputAt(0, array); |
| 4606 | } |
| 4607 | |
Calin Juravle | 77520bc | 2015-01-12 18:45:46 +0000 | [diff] [blame] | 4608 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4609 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4610 | return true; |
| 4611 | } |
Calin Juravle | 641547a | 2015-04-21 22:08:51 +0100 | [diff] [blame] | 4612 | bool CanDoImplicitNullCheckOn(HInstruction* obj) const OVERRIDE { |
| 4613 | return obj == InputAt(0); |
| 4614 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4615 | |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4616 | DECLARE_INSTRUCTION(ArrayLength); |
| 4617 | |
| 4618 | private: |
| 4619 | DISALLOW_COPY_AND_ASSIGN(HArrayLength); |
| 4620 | }; |
| 4621 | |
| 4622 | class HBoundsCheck : public HExpression<2> { |
| 4623 | public: |
| 4624 | HBoundsCheck(HInstruction* index, HInstruction* length, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4625 | : HExpression(index->GetType(), SideEffects::None(), dex_pc) { |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4626 | DCHECK(index->GetType() == Primitive::kPrimInt); |
| 4627 | SetRawInputAt(0, index); |
| 4628 | SetRawInputAt(1, length); |
| 4629 | } |
| 4630 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4631 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4632 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 4633 | return true; |
| 4634 | } |
Nicolas Geoffray | 065bf77 | 2014-09-03 14:51:22 +0100 | [diff] [blame] | 4635 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4636 | bool NeedsEnvironment() const OVERRIDE { return true; } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4637 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4638 | bool CanThrow() const OVERRIDE { return true; } |
Roland Levillain | e161a2a | 2014-10-03 12:45:18 +0100 | [diff] [blame] | 4639 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 4640 | HInstruction* GetIndex() const { return InputAt(0); } |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4641 | |
| 4642 | DECLARE_INSTRUCTION(BoundsCheck); |
| 4643 | |
| 4644 | private: |
Nicolas Geoffray | 3c7bb98 | 2014-07-23 16:04:16 +0100 | [diff] [blame] | 4645 | DISALLOW_COPY_AND_ASSIGN(HBoundsCheck); |
| 4646 | }; |
| 4647 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4648 | /** |
| 4649 | * Some DEX instructions are folded into multiple HInstructions that need |
| 4650 | * to stay live until the last HInstruction. This class |
| 4651 | * 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] | 4652 | * HInstruction stays live. `index` represents the stack location index of the |
| 4653 | * instruction (the actual offset is computed as index * vreg_size). |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4654 | */ |
| 4655 | class HTemporary : public HTemplateInstruction<0> { |
| 4656 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4657 | explicit HTemporary(size_t index, uint32_t dex_pc = kNoDexPc) |
| 4658 | : HTemplateInstruction(SideEffects::None(), dex_pc), index_(index) {} |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4659 | |
| 4660 | size_t GetIndex() const { return index_; } |
| 4661 | |
Nicolas Geoffray | 421e9f9 | 2014-11-11 18:21:53 +0000 | [diff] [blame] | 4662 | Primitive::Type GetType() const OVERRIDE { |
| 4663 | // The previous instruction is the one that will be stored in the temporary location. |
| 4664 | DCHECK(GetPrevious() != nullptr); |
| 4665 | return GetPrevious()->GetType(); |
| 4666 | } |
Nicolas Geoffray | f43083d | 2014-11-07 10:48:10 +0000 | [diff] [blame] | 4667 | |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4668 | DECLARE_INSTRUCTION(Temporary); |
| 4669 | |
| 4670 | private: |
| 4671 | const size_t index_; |
Nicolas Geoffray | e503832 | 2014-07-04 09:41:32 +0100 | [diff] [blame] | 4672 | DISALLOW_COPY_AND_ASSIGN(HTemporary); |
| 4673 | }; |
| 4674 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4675 | class HSuspendCheck : public HTemplateInstruction<0> { |
| 4676 | public: |
| 4677 | explicit HSuspendCheck(uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4678 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), slow_path_(nullptr) {} |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4679 | |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 4680 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4681 | return true; |
| 4682 | } |
| 4683 | |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4684 | void SetSlowPath(SlowPathCode* slow_path) { slow_path_ = slow_path; } |
| 4685 | SlowPathCode* GetSlowPath() const { return slow_path_; } |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4686 | |
| 4687 | DECLARE_INSTRUCTION(SuspendCheck); |
| 4688 | |
| 4689 | private: |
Nicolas Geoffray | db216f4 | 2015-05-05 17:02:20 +0100 | [diff] [blame] | 4690 | // Only used for code generation, in order to share the same slow path between back edges |
| 4691 | // of a same loop. |
| 4692 | SlowPathCode* slow_path_; |
| 4693 | |
Nicolas Geoffray | fbc695f | 2014-09-15 15:33:30 +0000 | [diff] [blame] | 4694 | DISALLOW_COPY_AND_ASSIGN(HSuspendCheck); |
| 4695 | }; |
| 4696 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4697 | /** |
| 4698 | * Instruction to load a Class object. |
| 4699 | */ |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4700 | class HLoadClass : public HExpression<1> { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4701 | public: |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4702 | HLoadClass(HCurrentMethod* current_method, |
| 4703 | uint16_t type_index, |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4704 | const DexFile& dex_file, |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4705 | bool is_referrers_class, |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4706 | uint32_t dex_pc, |
| 4707 | bool needs_access_check) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4708 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4709 | type_index_(type_index), |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4710 | dex_file_(dex_file), |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4711 | is_referrers_class_(is_referrers_class), |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 4712 | generate_clinit_check_(false), |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4713 | needs_access_check_(needs_access_check), |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 4714 | loaded_class_rti_(ReferenceTypeInfo::CreateInvalid()) { |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4715 | // Referrers class should not need access check. We never inline unverified |
| 4716 | // methods so we can't possibly end up in this situation. |
| 4717 | DCHECK(!is_referrers_class_ || !needs_access_check_); |
Nicolas Geoffray | 76b1e17 | 2015-05-27 17:18:33 +0100 | [diff] [blame] | 4718 | SetRawInputAt(0, current_method); |
| 4719 | } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4720 | |
| 4721 | bool CanBeMoved() const OVERRIDE { return true; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4722 | |
| 4723 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | a9a306d | 2015-10-08 16:48:31 +0100 | [diff] [blame] | 4724 | // Note that we don't need to test for generate_clinit_check_. |
| 4725 | // Whether or not we need to generate the clinit check is processed in |
| 4726 | // prepare_for_register_allocator based on existing HInvokes and HClinitChecks. |
Calin Juravle | 386062d | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4727 | return other->AsLoadClass()->type_index_ == type_index_ && |
| 4728 | other->AsLoadClass()->needs_access_check_ == needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4729 | } |
| 4730 | |
| 4731 | size_t ComputeHashCode() const OVERRIDE { return type_index_; } |
| 4732 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4733 | uint16_t GetTypeIndex() const { return type_index_; } |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4734 | bool IsReferrersClass() const { return is_referrers_class_; } |
Nicolas Geoffray | 7d5ea03 | 2015-07-02 15:48:27 +0100 | [diff] [blame] | 4735 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4736 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4737 | bool NeedsEnvironment() const OVERRIDE { |
| 4738 | // Will call runtime and load the class if the class is not loaded yet. |
| 4739 | // TODO: finer grain decision. |
Calin Juravle | 4e2a557 | 2015-10-07 18:55:43 +0100 | [diff] [blame] | 4740 | return !is_referrers_class_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4741 | } |
| 4742 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4743 | bool MustGenerateClinitCheck() const { |
| 4744 | return generate_clinit_check_; |
| 4745 | } |
Calin Juravle | 0ba218d | 2015-05-19 18:46:01 +0100 | [diff] [blame] | 4746 | void SetMustGenerateClinitCheck(bool generate_clinit_check) { |
| 4747 | generate_clinit_check_ = generate_clinit_check; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4748 | } |
| 4749 | |
| 4750 | bool CanCallRuntime() const { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4751 | return MustGenerateClinitCheck() || !is_referrers_class_ || needs_access_check_; |
| 4752 | } |
| 4753 | |
| 4754 | bool NeedsAccessCheck() const { |
| 4755 | return needs_access_check_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4756 | } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4757 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4758 | bool CanThrow() const OVERRIDE { |
| 4759 | // May call runtime and and therefore can throw. |
| 4760 | // TODO: finer grain decision. |
Nicolas Geoffray | 78f4fa7 | 2015-06-12 09:35:05 +0100 | [diff] [blame] | 4761 | return CanCallRuntime(); |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 4762 | } |
| 4763 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4764 | ReferenceTypeInfo GetLoadedClassRTI() { |
| 4765 | return loaded_class_rti_; |
| 4766 | } |
| 4767 | |
| 4768 | void SetLoadedClassRTI(ReferenceTypeInfo rti) { |
| 4769 | // Make sure we only set exact types (the loaded class should never be merged). |
| 4770 | DCHECK(rti.IsExact()); |
| 4771 | loaded_class_rti_ = rti; |
| 4772 | } |
| 4773 | |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4774 | const DexFile& GetDexFile() { return dex_file_; } |
| 4775 | |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4776 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return !is_referrers_class_; } |
Nicolas Geoffray | 9437b78 | 2015-03-25 10:08:51 +0000 | [diff] [blame] | 4777 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4778 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4779 | return SideEffects::CanTriggerGC(); |
| 4780 | } |
| 4781 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4782 | DECLARE_INSTRUCTION(LoadClass); |
| 4783 | |
| 4784 | private: |
| 4785 | const uint16_t type_index_; |
Nicolas Geoffray | d5111bf | 2015-05-22 15:37:09 +0100 | [diff] [blame] | 4786 | const DexFile& dex_file_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4787 | const bool is_referrers_class_; |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4788 | // Whether this instruction must generate the initialization check. |
| 4789 | // Used for code generation. |
| 4790 | bool generate_clinit_check_; |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 4791 | bool needs_access_check_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4792 | |
Calin Juravle | acf735c | 2015-02-12 15:25:22 +0000 | [diff] [blame] | 4793 | ReferenceTypeInfo loaded_class_rti_; |
| 4794 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4795 | DISALLOW_COPY_AND_ASSIGN(HLoadClass); |
| 4796 | }; |
| 4797 | |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4798 | class HLoadString : public HExpression<1> { |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4799 | public: |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4800 | HLoadString(HCurrentMethod* current_method, uint32_t string_index, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4801 | : HExpression(Primitive::kPrimNot, SideEffectsForArchRuntimeCalls(), dex_pc), |
| 4802 | string_index_(string_index) { |
Nicolas Geoffray | fbdaa30 | 2015-05-29 12:06:56 +0100 | [diff] [blame] | 4803 | SetRawInputAt(0, current_method); |
| 4804 | } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4805 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4806 | bool CanBeMoved() const OVERRIDE { return true; } |
| 4807 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4808 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
| 4809 | return other->AsLoadString()->string_index_ == string_index_; |
| 4810 | } |
| 4811 | |
| 4812 | size_t ComputeHashCode() const OVERRIDE { return string_index_; } |
| 4813 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4814 | uint32_t GetStringIndex() const { return string_index_; } |
| 4815 | |
| 4816 | // TODO: Can we deopt or debug when we resolve a string? |
| 4817 | bool NeedsEnvironment() const OVERRIDE { return false; } |
Vladimir Marko | dc151b2 | 2015-10-15 18:02:30 +0100 | [diff] [blame] | 4818 | bool NeedsDexCacheOfDeclaringClass() const OVERRIDE { return true; } |
Nicolas Geoffray | e418dda | 2015-08-11 20:03:09 -0700 | [diff] [blame] | 4819 | bool CanBeNull() const OVERRIDE { return false; } |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4820 | |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4821 | static SideEffects SideEffectsForArchRuntimeCalls() { |
| 4822 | return SideEffects::CanTriggerGC(); |
| 4823 | } |
| 4824 | |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4825 | DECLARE_INSTRUCTION(LoadString); |
| 4826 | |
| 4827 | private: |
| 4828 | const uint32_t string_index_; |
Nicolas Geoffray | b5f62b3 | 2014-10-30 10:58:41 +0000 | [diff] [blame] | 4829 | |
| 4830 | DISALLOW_COPY_AND_ASSIGN(HLoadString); |
| 4831 | }; |
| 4832 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4833 | /** |
| 4834 | * Performs an initialization check on its Class object input. |
| 4835 | */ |
| 4836 | class HClinitCheck : public HExpression<1> { |
| 4837 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 4838 | HClinitCheck(HLoadClass* constant, uint32_t dex_pc) |
Aart Bik | 854a02b | 2015-07-14 16:07:00 -0700 | [diff] [blame] | 4839 | : HExpression( |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 4840 | Primitive::kPrimNot, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4841 | SideEffects::AllChanges(), // Assume write/read on all fields/arrays. |
| 4842 | dex_pc) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4843 | SetRawInputAt(0, constant); |
| 4844 | } |
| 4845 | |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4846 | bool CanBeMoved() const OVERRIDE { return true; } |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 4847 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 424f676 | 2014-11-03 14:51:25 +0000 | [diff] [blame] | 4848 | return true; |
| 4849 | } |
| 4850 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4851 | bool NeedsEnvironment() const OVERRIDE { |
| 4852 | // May call runtime to initialize the class. |
| 4853 | return true; |
| 4854 | } |
| 4855 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4856 | |
| 4857 | HLoadClass* GetLoadClass() const { return InputAt(0)->AsLoadClass(); } |
| 4858 | |
| 4859 | DECLARE_INSTRUCTION(ClinitCheck); |
| 4860 | |
| 4861 | private: |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4862 | DISALLOW_COPY_AND_ASSIGN(HClinitCheck); |
| 4863 | }; |
| 4864 | |
| 4865 | class HStaticFieldGet : public HExpression<1> { |
| 4866 | public: |
| 4867 | HStaticFieldGet(HInstruction* cls, |
| 4868 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4869 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4870 | bool is_volatile, |
| 4871 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4872 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4873 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4874 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4875 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4876 | : HExpression(field_type, |
| 4877 | SideEffects::FieldReadOfType(field_type, is_volatile), |
| 4878 | dex_pc), |
| 4879 | field_info_(field_offset, |
| 4880 | field_type, |
| 4881 | is_volatile, |
| 4882 | field_idx, |
| 4883 | declaring_class_def_index, |
| 4884 | dex_file, |
| 4885 | dex_cache) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4886 | SetRawInputAt(0, cls); |
| 4887 | } |
| 4888 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4889 | |
Calin Juravle | 10c9cbe | 2014-12-19 10:50:19 +0000 | [diff] [blame] | 4890 | bool CanBeMoved() const OVERRIDE { return !IsVolatile(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4891 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4892 | bool InstructionDataEquals(HInstruction* other) const OVERRIDE { |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4893 | HStaticFieldGet* other_get = other->AsStaticFieldGet(); |
| 4894 | return GetFieldOffset().SizeValue() == other_get->GetFieldOffset().SizeValue(); |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | size_t ComputeHashCode() const OVERRIDE { |
| 4898 | return (HInstruction::ComputeHashCode() << 7) | GetFieldOffset().SizeValue(); |
| 4899 | } |
| 4900 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4901 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4902 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4903 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4904 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4905 | |
| 4906 | DECLARE_INSTRUCTION(StaticFieldGet); |
| 4907 | |
| 4908 | private: |
| 4909 | const FieldInfo field_info_; |
| 4910 | |
| 4911 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldGet); |
| 4912 | }; |
| 4913 | |
| 4914 | class HStaticFieldSet : public HTemplateInstruction<2> { |
| 4915 | public: |
| 4916 | HStaticFieldSet(HInstruction* cls, |
| 4917 | HInstruction* value, |
| 4918 | Primitive::Type field_type, |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4919 | MemberOffset field_offset, |
Guillaume "Vermeille" Sanchez | 104fd8a | 2015-05-20 17:52:13 +0100 | [diff] [blame] | 4920 | bool is_volatile, |
| 4921 | uint32_t field_idx, |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4922 | uint16_t declaring_class_def_index, |
Mathieu Chartier | 736b560 | 2015-09-02 14:54:11 -0700 | [diff] [blame] | 4923 | const DexFile& dex_file, |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 4924 | Handle<mirror::DexCache> dex_cache, |
Calin Juravle | 154746b | 2015-10-06 15:46:54 +0100 | [diff] [blame] | 4925 | uint32_t dex_pc) |
Mingyao Yang | 8df69d4 | 2015-10-22 15:40:58 -0700 | [diff] [blame] | 4926 | : HTemplateInstruction(SideEffects::FieldWriteOfType(field_type, is_volatile), |
| 4927 | dex_pc), |
| 4928 | field_info_(field_offset, |
| 4929 | field_type, |
| 4930 | is_volatile, |
| 4931 | field_idx, |
| 4932 | declaring_class_def_index, |
| 4933 | dex_file, |
| 4934 | dex_cache), |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4935 | value_can_be_null_(true) { |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4936 | SetRawInputAt(0, cls); |
| 4937 | SetRawInputAt(1, value); |
| 4938 | } |
| 4939 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4940 | const FieldInfo& GetFieldInfo() const { return field_info_; } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4941 | MemberOffset GetFieldOffset() const { return field_info_.GetFieldOffset(); } |
| 4942 | Primitive::Type GetFieldType() const { return field_info_.GetFieldType(); } |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 4943 | bool IsVolatile() const { return field_info_.IsVolatile(); } |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4944 | |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4945 | HInstruction* GetValue() const { return InputAt(1); } |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4946 | bool GetValueCanBeNull() const { return value_can_be_null_; } |
| 4947 | void ClearValueCanBeNull() { value_can_be_null_ = false; } |
Nicolas Geoffray | af07bc1 | 2014-11-12 18:08:09 +0000 | [diff] [blame] | 4948 | |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4949 | DECLARE_INSTRUCTION(StaticFieldSet); |
| 4950 | |
| 4951 | private: |
| 4952 | const FieldInfo field_info_; |
Nicolas Geoffray | 07276db | 2015-05-18 14:22:09 +0100 | [diff] [blame] | 4953 | bool value_can_be_null_; |
Nicolas Geoffray | 19a19cf | 2014-10-22 16:07:05 +0100 | [diff] [blame] | 4954 | |
| 4955 | DISALLOW_COPY_AND_ASSIGN(HStaticFieldSet); |
| 4956 | }; |
| 4957 | |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 4958 | class HUnresolvedInstanceFieldGet : public HExpression<1> { |
| 4959 | public: |
| 4960 | HUnresolvedInstanceFieldGet(HInstruction* obj, |
| 4961 | Primitive::Type field_type, |
| 4962 | uint32_t field_index, |
| 4963 | uint32_t dex_pc) |
| 4964 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 4965 | field_index_(field_index) { |
| 4966 | SetRawInputAt(0, obj); |
| 4967 | } |
| 4968 | |
| 4969 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4970 | bool CanThrow() const OVERRIDE { return true; } |
| 4971 | |
| 4972 | Primitive::Type GetFieldType() const { return GetType(); } |
| 4973 | uint32_t GetFieldIndex() const { return field_index_; } |
| 4974 | |
| 4975 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldGet); |
| 4976 | |
| 4977 | private: |
| 4978 | const uint32_t field_index_; |
| 4979 | |
| 4980 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldGet); |
| 4981 | }; |
| 4982 | |
| 4983 | class HUnresolvedInstanceFieldSet : public HTemplateInstruction<2> { |
| 4984 | public: |
| 4985 | HUnresolvedInstanceFieldSet(HInstruction* obj, |
| 4986 | HInstruction* value, |
| 4987 | Primitive::Type field_type, |
| 4988 | uint32_t field_index, |
| 4989 | uint32_t dex_pc) |
| 4990 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 4991 | field_type_(field_type), |
| 4992 | field_index_(field_index) { |
| 4993 | DCHECK_EQ(field_type, value->GetType()); |
| 4994 | SetRawInputAt(0, obj); |
| 4995 | SetRawInputAt(1, value); |
| 4996 | } |
| 4997 | |
| 4998 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 4999 | bool CanThrow() const OVERRIDE { return true; } |
| 5000 | |
| 5001 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5002 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5003 | |
| 5004 | DECLARE_INSTRUCTION(UnresolvedInstanceFieldSet); |
| 5005 | |
| 5006 | private: |
| 5007 | const Primitive::Type field_type_; |
| 5008 | const uint32_t field_index_; |
| 5009 | |
| 5010 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedInstanceFieldSet); |
| 5011 | }; |
| 5012 | |
| 5013 | class HUnresolvedStaticFieldGet : public HExpression<0> { |
| 5014 | public: |
| 5015 | HUnresolvedStaticFieldGet(Primitive::Type field_type, |
| 5016 | uint32_t field_index, |
| 5017 | uint32_t dex_pc) |
| 5018 | : HExpression(field_type, SideEffects::AllExceptGCDependency(), dex_pc), |
| 5019 | field_index_(field_index) { |
| 5020 | } |
| 5021 | |
| 5022 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5023 | bool CanThrow() const OVERRIDE { return true; } |
| 5024 | |
| 5025 | Primitive::Type GetFieldType() const { return GetType(); } |
| 5026 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5027 | |
| 5028 | DECLARE_INSTRUCTION(UnresolvedStaticFieldGet); |
| 5029 | |
| 5030 | private: |
| 5031 | const uint32_t field_index_; |
| 5032 | |
| 5033 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldGet); |
| 5034 | }; |
| 5035 | |
| 5036 | class HUnresolvedStaticFieldSet : public HTemplateInstruction<1> { |
| 5037 | public: |
| 5038 | HUnresolvedStaticFieldSet(HInstruction* value, |
| 5039 | Primitive::Type field_type, |
| 5040 | uint32_t field_index, |
| 5041 | uint32_t dex_pc) |
| 5042 | : HTemplateInstruction(SideEffects::AllExceptGCDependency(), dex_pc), |
| 5043 | field_type_(field_type), |
| 5044 | field_index_(field_index) { |
| 5045 | DCHECK_EQ(field_type, value->GetType()); |
| 5046 | SetRawInputAt(0, value); |
| 5047 | } |
| 5048 | |
| 5049 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5050 | bool CanThrow() const OVERRIDE { return true; } |
| 5051 | |
| 5052 | Primitive::Type GetFieldType() const { return field_type_; } |
| 5053 | uint32_t GetFieldIndex() const { return field_index_; } |
| 5054 | |
| 5055 | DECLARE_INSTRUCTION(UnresolvedStaticFieldSet); |
| 5056 | |
| 5057 | private: |
| 5058 | const Primitive::Type field_type_; |
| 5059 | const uint32_t field_index_; |
| 5060 | |
| 5061 | DISALLOW_COPY_AND_ASSIGN(HUnresolvedStaticFieldSet); |
| 5062 | }; |
| 5063 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5064 | // Implement the move-exception DEX instruction. |
| 5065 | class HLoadException : public HExpression<0> { |
| 5066 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5067 | explicit HLoadException(uint32_t dex_pc = kNoDexPc) |
| 5068 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5069 | |
David Brazdil | bbd733e | 2015-08-18 17:48:17 +0100 | [diff] [blame] | 5070 | bool CanBeNull() const OVERRIDE { return false; } |
| 5071 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5072 | DECLARE_INSTRUCTION(LoadException); |
| 5073 | |
| 5074 | private: |
| 5075 | DISALLOW_COPY_AND_ASSIGN(HLoadException); |
| 5076 | }; |
| 5077 | |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5078 | // Implicit part of move-exception which clears thread-local exception storage. |
| 5079 | // Must not be removed because the runtime expects the TLS to get cleared. |
| 5080 | class HClearException : public HTemplateInstruction<0> { |
| 5081 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5082 | explicit HClearException(uint32_t dex_pc = kNoDexPc) |
| 5083 | : HTemplateInstruction(SideEffects::AllWrites(), dex_pc) {} |
David Brazdil | cb1c055 | 2015-08-04 16:22:25 +0100 | [diff] [blame] | 5084 | |
| 5085 | DECLARE_INSTRUCTION(ClearException); |
| 5086 | |
| 5087 | private: |
| 5088 | DISALLOW_COPY_AND_ASSIGN(HClearException); |
| 5089 | }; |
| 5090 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5091 | class HThrow : public HTemplateInstruction<1> { |
| 5092 | public: |
| 5093 | HThrow(HInstruction* exception, uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5094 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc) { |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5095 | SetRawInputAt(0, exception); |
| 5096 | } |
| 5097 | |
| 5098 | bool IsControlFlow() const OVERRIDE { return true; } |
| 5099 | |
| 5100 | bool NeedsEnvironment() const OVERRIDE { return true; } |
| 5101 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5102 | bool CanThrow() const OVERRIDE { return true; } |
| 5103 | |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5104 | |
| 5105 | DECLARE_INSTRUCTION(Throw); |
| 5106 | |
| 5107 | private: |
Nicolas Geoffray | de58ab2 | 2014-11-05 12:46:03 +0000 | [diff] [blame] | 5108 | DISALLOW_COPY_AND_ASSIGN(HThrow); |
| 5109 | }; |
| 5110 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5111 | /** |
| 5112 | * Implementation strategies for the code generator of a HInstanceOf |
| 5113 | * or `HCheckCast`. |
| 5114 | */ |
| 5115 | enum class TypeCheckKind { |
Calin Juravle | 98893e1 | 2015-10-02 21:05:03 +0100 | [diff] [blame] | 5116 | kUnresolvedCheck, // Check against an unresolved type. |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5117 | kExactCheck, // Can do a single class compare. |
| 5118 | kClassHierarchyCheck, // Can just walk the super class chain. |
| 5119 | kAbstractClassCheck, // Can just walk the super class chain, starting one up. |
| 5120 | kInterfaceCheck, // No optimization yet when checking against an interface. |
| 5121 | kArrayObjectCheck, // Can just check if the array is not primitive. |
| 5122 | kArrayCheck // No optimization yet when checking against a generic array. |
| 5123 | }; |
| 5124 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5125 | class HInstanceOf : public HExpression<2> { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5126 | public: |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5127 | HInstanceOf(HInstruction* object, |
| 5128 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5129 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5130 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5131 | : HExpression(Primitive::kPrimBoolean, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5132 | SideEffectsForArchRuntimeCalls(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5133 | dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5134 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5135 | must_do_null_check_(true) { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5136 | SetRawInputAt(0, object); |
| 5137 | SetRawInputAt(1, constant); |
| 5138 | } |
| 5139 | |
| 5140 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5141 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5142 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5143 | return true; |
| 5144 | } |
| 5145 | |
| 5146 | bool NeedsEnvironment() const OVERRIDE { |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5147 | return false; |
| 5148 | } |
| 5149 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5150 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
| 5151 | |
| 5152 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5153 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5154 | // Used only in code generation. |
| 5155 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5156 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
| 5157 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5158 | static SideEffects SideEffectsForArchRuntimeCalls(TypeCheckKind check_kind) { |
| 5159 | return (check_kind == TypeCheckKind::kExactCheck) |
| 5160 | ? SideEffects::None() |
| 5161 | // Mips currently does runtime calls for any other checks. |
| 5162 | : SideEffects::CanTriggerGC(); |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5163 | } |
| 5164 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5165 | DECLARE_INSTRUCTION(InstanceOf); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5166 | |
| 5167 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5168 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5169 | bool must_do_null_check_; |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5170 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5171 | DISALLOW_COPY_AND_ASSIGN(HInstanceOf); |
| 5172 | }; |
| 5173 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5174 | class HBoundType : public HExpression<1> { |
| 5175 | public: |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5176 | // Constructs an HBoundType with the given upper_bound. |
| 5177 | // Ensures that the upper_bound is valid. |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5178 | HBoundType(HInstruction* input, |
| 5179 | ReferenceTypeInfo upper_bound, |
| 5180 | bool upper_can_be_null, |
| 5181 | uint32_t dex_pc = kNoDexPc) |
| 5182 | : HExpression(Primitive::kPrimNot, SideEffects::None(), dex_pc), |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5183 | upper_bound_(upper_bound), |
| 5184 | upper_can_be_null_(upper_can_be_null), |
| 5185 | can_be_null_(upper_can_be_null) { |
Calin Juravle | 61d544b | 2015-02-23 16:46:57 +0000 | [diff] [blame] | 5186 | DCHECK_EQ(input->GetType(), Primitive::kPrimNot); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5187 | SetRawInputAt(0, input); |
Calin Juravle | 2e76830 | 2015-07-28 14:41:11 +0000 | [diff] [blame] | 5188 | SetReferenceTypeInfo(upper_bound_); |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5189 | } |
| 5190 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5191 | // GetUpper* should only be used in reference type propagation. |
| 5192 | const ReferenceTypeInfo& GetUpperBound() const { return upper_bound_; } |
| 5193 | bool GetUpperCanBeNull() const { return upper_can_be_null_; } |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5194 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5195 | void SetCanBeNull(bool can_be_null) { |
| 5196 | DCHECK(upper_can_be_null_ || !can_be_null); |
| 5197 | can_be_null_ = can_be_null; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5198 | } |
| 5199 | |
Calin Juravle | a5ae3c3 | 2015-07-28 14:40:50 +0000 | [diff] [blame] | 5200 | bool CanBeNull() const OVERRIDE { return can_be_null_; } |
| 5201 | |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5202 | DECLARE_INSTRUCTION(BoundType); |
| 5203 | |
| 5204 | private: |
| 5205 | // 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] | 5206 | // it is always the case that GetUpperBound().IsSupertypeOf(GetReferenceType()). |
| 5207 | // It is used to bound the type in cases like: |
| 5208 | // if (x instanceof ClassX) { |
| 5209 | // // uper_bound_ will be ClassX |
| 5210 | // } |
| 5211 | const ReferenceTypeInfo upper_bound_; |
| 5212 | // Represents the top constraint that can_be_null_ cannot exceed (i.e. if this |
| 5213 | // is false then can_be_null_ cannot be true). |
| 5214 | const bool upper_can_be_null_; |
| 5215 | bool can_be_null_; |
Calin Juravle | b1498f6 | 2015-02-16 13:13:29 +0000 | [diff] [blame] | 5216 | |
| 5217 | DISALLOW_COPY_AND_ASSIGN(HBoundType); |
| 5218 | }; |
| 5219 | |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5220 | class HCheckCast : public HTemplateInstruction<2> { |
| 5221 | public: |
| 5222 | HCheckCast(HInstruction* object, |
| 5223 | HLoadClass* constant, |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5224 | TypeCheckKind check_kind, |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5225 | uint32_t dex_pc) |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5226 | : HTemplateInstruction(SideEffects::CanTriggerGC(), dex_pc), |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5227 | check_kind_(check_kind), |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5228 | must_do_null_check_(true) { |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5229 | SetRawInputAt(0, object); |
| 5230 | SetRawInputAt(1, constant); |
| 5231 | } |
| 5232 | |
| 5233 | bool CanBeMoved() const OVERRIDE { return true; } |
| 5234 | |
| 5235 | bool InstructionDataEquals(HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 5236 | return true; |
| 5237 | } |
| 5238 | |
| 5239 | bool NeedsEnvironment() const OVERRIDE { |
| 5240 | // Instruction may throw a CheckCastError. |
| 5241 | return true; |
| 5242 | } |
| 5243 | |
| 5244 | bool CanThrow() const OVERRIDE { return true; } |
| 5245 | |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5246 | bool MustDoNullCheck() const { return must_do_null_check_; } |
| 5247 | void ClearMustDoNullCheck() { must_do_null_check_ = false; } |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5248 | TypeCheckKind GetTypeCheckKind() const { return check_kind_; } |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5249 | |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5250 | bool IsExactCheck() const { return check_kind_ == TypeCheckKind::kExactCheck; } |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5251 | |
| 5252 | DECLARE_INSTRUCTION(CheckCast); |
| 5253 | |
| 5254 | private: |
Nicolas Geoffray | 85c7bab | 2015-09-18 13:40:46 +0000 | [diff] [blame] | 5255 | const TypeCheckKind check_kind_; |
Guillaume "Vermeille" Sanchez | af88835 | 2015-04-20 14:41:30 +0100 | [diff] [blame] | 5256 | bool must_do_null_check_; |
Nicolas Geoffray | 57a88d4 | 2014-11-10 15:09:21 +0000 | [diff] [blame] | 5257 | |
| 5258 | DISALLOW_COPY_AND_ASSIGN(HCheckCast); |
Nicolas Geoffray | 6f5c41f | 2014-11-06 08:59:20 +0000 | [diff] [blame] | 5259 | }; |
| 5260 | |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5261 | class HMemoryBarrier : public HTemplateInstruction<0> { |
| 5262 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5263 | explicit HMemoryBarrier(MemBarrierKind barrier_kind, uint32_t dex_pc = kNoDexPc) |
Aart Bik | 34c3ba9 | 2015-07-20 14:08:59 -0700 | [diff] [blame] | 5264 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5265 | SideEffects::AllWritesAndReads(), dex_pc), // Assume write/read on all fields/arrays. |
Calin Juravle | 27df758 | 2015-04-17 19:12:31 +0100 | [diff] [blame] | 5266 | barrier_kind_(barrier_kind) {} |
| 5267 | |
| 5268 | MemBarrierKind GetBarrierKind() { return barrier_kind_; } |
| 5269 | |
| 5270 | DECLARE_INSTRUCTION(MemoryBarrier); |
| 5271 | |
| 5272 | private: |
| 5273 | const MemBarrierKind barrier_kind_; |
| 5274 | |
| 5275 | DISALLOW_COPY_AND_ASSIGN(HMemoryBarrier); |
| 5276 | }; |
| 5277 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5278 | class HMonitorOperation : public HTemplateInstruction<1> { |
| 5279 | public: |
| 5280 | enum OperationKind { |
| 5281 | kEnter, |
| 5282 | kExit, |
| 5283 | }; |
| 5284 | |
| 5285 | HMonitorOperation(HInstruction* object, OperationKind kind, uint32_t dex_pc) |
Alexandre Rames | 78e3ef6 | 2015-08-12 13:43:29 +0100 | [diff] [blame] | 5286 | : HTemplateInstruction( |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5287 | SideEffects::AllExceptGCDependency(), dex_pc), // Assume write/read on all fields/arrays. |
| 5288 | kind_(kind) { |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5289 | SetRawInputAt(0, object); |
| 5290 | } |
| 5291 | |
| 5292 | // Instruction may throw a Java exception, so we need an environment. |
David Brazdil | bff7503 | 2015-07-08 17:26:51 +0000 | [diff] [blame] | 5293 | bool NeedsEnvironment() const OVERRIDE { return CanThrow(); } |
| 5294 | |
| 5295 | bool CanThrow() const OVERRIDE { |
| 5296 | // Verifier guarantees that monitor-exit cannot throw. |
| 5297 | // This is important because it allows the HGraphBuilder to remove |
| 5298 | // a dead throw-catch loop generated for `synchronized` blocks/methods. |
| 5299 | return IsEnter(); |
| 5300 | } |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5301 | |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5302 | |
| 5303 | bool IsEnter() const { return kind_ == kEnter; } |
| 5304 | |
| 5305 | DECLARE_INSTRUCTION(MonitorOperation); |
| 5306 | |
Calin Juravle | 52c4896 | 2014-12-16 17:02:57 +0000 | [diff] [blame] | 5307 | private: |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5308 | const OperationKind kind_; |
Nicolas Geoffray | b7baf5c | 2014-11-11 16:29:44 +0000 | [diff] [blame] | 5309 | |
| 5310 | private: |
| 5311 | DISALLOW_COPY_AND_ASSIGN(HMonitorOperation); |
| 5312 | }; |
| 5313 | |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5314 | /** |
| 5315 | * A HInstruction used as a marker for the replacement of new + <init> |
| 5316 | * of a String to a call to a StringFactory. Only baseline will see |
| 5317 | * the node at code generation, where it will be be treated as null. |
| 5318 | * When compiling non-baseline, `HFakeString` instructions are being removed |
| 5319 | * in the instruction simplifier. |
| 5320 | */ |
| 5321 | class HFakeString : public HTemplateInstruction<0> { |
| 5322 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5323 | explicit HFakeString(uint32_t dex_pc = kNoDexPc) |
| 5324 | : HTemplateInstruction(SideEffects::None(), dex_pc) {} |
Nicolas Geoffray | 2e7cd75 | 2015-07-10 11:38:52 +0100 | [diff] [blame] | 5325 | |
| 5326 | Primitive::Type GetType() const OVERRIDE { return Primitive::kPrimNot; } |
| 5327 | |
| 5328 | DECLARE_INSTRUCTION(FakeString); |
| 5329 | |
| 5330 | private: |
| 5331 | DISALLOW_COPY_AND_ASSIGN(HFakeString); |
| 5332 | }; |
| 5333 | |
Vladimir Marko | f9f6441 | 2015-09-02 14:05:49 +0100 | [diff] [blame] | 5334 | class MoveOperands : public ArenaObject<kArenaAllocMoveOperands> { |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5335 | public: |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5336 | MoveOperands(Location source, |
| 5337 | Location destination, |
| 5338 | Primitive::Type type, |
| 5339 | HInstruction* instruction) |
| 5340 | : source_(source), destination_(destination), type_(type), instruction_(instruction) {} |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5341 | |
| 5342 | Location GetSource() const { return source_; } |
| 5343 | Location GetDestination() const { return destination_; } |
| 5344 | |
| 5345 | void SetSource(Location value) { source_ = value; } |
| 5346 | void SetDestination(Location value) { destination_ = value; } |
| 5347 | |
| 5348 | // The parallel move resolver marks moves as "in-progress" by clearing the |
| 5349 | // destination (but not the source). |
| 5350 | Location MarkPending() { |
| 5351 | DCHECK(!IsPending()); |
| 5352 | Location dest = destination_; |
| 5353 | destination_ = Location::NoLocation(); |
| 5354 | return dest; |
| 5355 | } |
| 5356 | |
| 5357 | void ClearPending(Location dest) { |
| 5358 | DCHECK(IsPending()); |
| 5359 | destination_ = dest; |
| 5360 | } |
| 5361 | |
| 5362 | bool IsPending() const { |
| 5363 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5364 | return destination_.IsInvalid() && !source_.IsInvalid(); |
| 5365 | } |
| 5366 | |
| 5367 | // True if this blocks a move from the given location. |
| 5368 | bool Blocks(Location loc) const { |
Zheng Xu | ad4450e | 2015-04-17 18:48:56 +0800 | [diff] [blame] | 5369 | return !IsEliminated() && source_.OverlapsWith(loc); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5370 | } |
| 5371 | |
| 5372 | // A move is redundant if it's been eliminated, if its source and |
| 5373 | // destination are the same, or if its destination is unneeded. |
| 5374 | bool IsRedundant() const { |
| 5375 | return IsEliminated() || destination_.IsInvalid() || source_.Equals(destination_); |
| 5376 | } |
| 5377 | |
| 5378 | // We clear both operands to indicate move that's been eliminated. |
| 5379 | void Eliminate() { |
| 5380 | source_ = destination_ = Location::NoLocation(); |
| 5381 | } |
| 5382 | |
| 5383 | bool IsEliminated() const { |
| 5384 | DCHECK(!source_.IsInvalid() || destination_.IsInvalid()); |
| 5385 | return source_.IsInvalid(); |
| 5386 | } |
| 5387 | |
Alexey Frunze | 4dda337 | 2015-06-01 18:31:49 -0700 | [diff] [blame] | 5388 | Primitive::Type GetType() const { return type_; } |
| 5389 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5390 | bool Is64BitMove() const { |
| 5391 | return Primitive::Is64BitType(type_); |
| 5392 | } |
| 5393 | |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5394 | HInstruction* GetInstruction() const { return instruction_; } |
| 5395 | |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5396 | private: |
| 5397 | Location source_; |
| 5398 | Location destination_; |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5399 | // The type this move is for. |
| 5400 | Primitive::Type type_; |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5401 | // The instruction this move is assocatied with. Null when this move is |
| 5402 | // for moving an input in the expected locations of user (including a phi user). |
| 5403 | // This is only used in debug mode, to ensure we do not connect interval siblings |
| 5404 | // in the same parallel move. |
| 5405 | HInstruction* instruction_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5406 | }; |
| 5407 | |
| 5408 | static constexpr size_t kDefaultNumberOfMoves = 4; |
| 5409 | |
| 5410 | class HParallelMove : public HTemplateInstruction<0> { |
| 5411 | public: |
Yevgeny Rouban | 3ecfd65 | 2015-09-07 17:57:00 +0600 | [diff] [blame] | 5412 | explicit HParallelMove(ArenaAllocator* arena, uint32_t dex_pc = kNoDexPc) |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5413 | : HTemplateInstruction(SideEffects::None(), dex_pc), |
| 5414 | moves_(arena->Adapter(kArenaAllocMoveOperands)) { |
| 5415 | moves_.reserve(kDefaultNumberOfMoves); |
| 5416 | } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5417 | |
Nicolas Geoffray | 9021825 | 2015-04-15 11:56:51 +0100 | [diff] [blame] | 5418 | void AddMove(Location source, |
| 5419 | Location destination, |
| 5420 | Primitive::Type type, |
| 5421 | HInstruction* instruction) { |
Nicolas Geoffray | 42d1f5f | 2015-01-16 09:14:18 +0000 | [diff] [blame] | 5422 | DCHECK(source.IsValid()); |
| 5423 | DCHECK(destination.IsValid()); |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5424 | if (kIsDebugBuild) { |
| 5425 | if (instruction != nullptr) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5426 | for (const MoveOperands& move : moves_) { |
| 5427 | if (move.GetInstruction() == instruction) { |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5428 | // Special case the situation where the move is for the spill slot |
| 5429 | // of the instruction. |
| 5430 | if ((GetPrevious() == instruction) |
| 5431 | || ((GetPrevious() == nullptr) |
| 5432 | && instruction->IsPhi() |
| 5433 | && instruction->GetBlock() == GetBlock())) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5434 | DCHECK_NE(destination.GetKind(), move.GetDestination().GetKind()) |
Nicolas Geoffray | 234d69d | 2015-03-09 10:28:50 +0000 | [diff] [blame] | 5435 | << "Doing parallel moves for the same instruction."; |
| 5436 | } else { |
| 5437 | DCHECK(false) << "Doing parallel moves for the same instruction."; |
| 5438 | } |
| 5439 | } |
Nicolas Geoffray | dd8f887 | 2015-01-15 15:37:37 +0000 | [diff] [blame] | 5440 | } |
| 5441 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5442 | for (const MoveOperands& move : moves_) { |
| 5443 | DCHECK(!destination.OverlapsWith(move.GetDestination())) |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5444 | << "Overlapped destination for two moves in a parallel move: " |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5445 | << move.GetSource() << " ==> " << move.GetDestination() << " and " |
Guillaume "Vermeille" Sanchez | 8909baf | 2015-04-23 21:35:11 +0100 | [diff] [blame] | 5446 | << source << " ==> " << destination; |
Nicolas Geoffray | f7a0c4e | 2015-02-10 17:08:47 +0000 | [diff] [blame] | 5447 | } |
Nicolas Geoffray | 740475d | 2014-09-29 10:33:25 +0100 | [diff] [blame] | 5448 | } |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5449 | moves_.emplace_back(source, destination, type, instruction); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5450 | } |
| 5451 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5452 | MoveOperands* MoveOperandsAt(size_t index) { |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5453 | return &moves_[index]; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5454 | } |
| 5455 | |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5456 | size_t NumMoves() const { return moves_.size(); } |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5457 | |
Nicolas Geoffray | a7062e0 | 2014-05-22 12:50:17 +0100 | [diff] [blame] | 5458 | DECLARE_INSTRUCTION(ParallelMove); |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5459 | |
| 5460 | private: |
Vladimir Marko | 225b646 | 2015-09-28 12:17:40 +0100 | [diff] [blame] | 5461 | ArenaVector<MoveOperands> moves_; |
Nicolas Geoffray | 4e3d23a | 2014-05-22 18:32:45 +0100 | [diff] [blame] | 5462 | |
| 5463 | DISALLOW_COPY_AND_ASSIGN(HParallelMove); |
| 5464 | }; |
| 5465 | |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5466 | } // namespace art |
| 5467 | |
Alexandre Rames | e6dbf48 | 2015-10-19 10:10:41 +0100 | [diff] [blame] | 5468 | #ifdef ART_ENABLE_CODEGEN_arm64 |
| 5469 | #include "nodes_arm64.h" |
| 5470 | #endif |
Mark Mendell | 0616ae0 | 2015-04-17 12:49:27 -0400 | [diff] [blame] | 5471 | #ifdef ART_ENABLE_CODEGEN_x86 |
| 5472 | #include "nodes_x86.h" |
| 5473 | #endif |
| 5474 | |
| 5475 | namespace art { |
| 5476 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5477 | class HGraphVisitor : public ValueObject { |
| 5478 | public: |
Dave Allison | 20dfc79 | 2014-06-16 20:44:29 -0700 | [diff] [blame] | 5479 | explicit HGraphVisitor(HGraph* graph) : graph_(graph) {} |
| 5480 | virtual ~HGraphVisitor() {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5481 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 5482 | virtual void VisitInstruction(HInstruction* instruction ATTRIBUTE_UNUSED) {} |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5483 | virtual void VisitBasicBlock(HBasicBlock* block); |
| 5484 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5485 | // Visit the graph following basic block insertion order. |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5486 | void VisitInsertionOrder(); |
| 5487 | |
Roland Levillain | 633021e | 2014-10-01 14:12:25 +0100 | [diff] [blame] | 5488 | // Visit the graph following dominator tree reverse post-order. |
| 5489 | void VisitReversePostOrder(); |
| 5490 | |
Nicolas Geoffray | 787c307 | 2014-03-17 10:20:19 +0000 | [diff] [blame] | 5491 | HGraph* GetGraph() const { return graph_; } |
Nicolas Geoffray | d4dd255 | 2014-02-28 10:23:58 +0000 | [diff] [blame] | 5492 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5493 | // Visit functions for instruction classes. |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5494 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5495 | virtual void Visit##name(H##name* instr) { VisitInstruction(instr); } |
| 5496 | |
| 5497 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5498 | |
| 5499 | #undef DECLARE_VISIT_INSTRUCTION |
| 5500 | |
| 5501 | private: |
Ian Rogers | cf7f191 | 2014-10-22 22:06:39 -0700 | [diff] [blame] | 5502 | HGraph* const graph_; |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5503 | |
| 5504 | DISALLOW_COPY_AND_ASSIGN(HGraphVisitor); |
| 5505 | }; |
| 5506 | |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5507 | class HGraphDelegateVisitor : public HGraphVisitor { |
| 5508 | public: |
| 5509 | explicit HGraphDelegateVisitor(HGraph* graph) : HGraphVisitor(graph) {} |
| 5510 | virtual ~HGraphDelegateVisitor() {} |
| 5511 | |
| 5512 | // Visit functions that delegate to to super class. |
| 5513 | #define DECLARE_VISIT_INSTRUCTION(name, super) \ |
Alexandre Rames | 2ed20af | 2015-03-06 13:55:35 +0000 | [diff] [blame] | 5514 | void Visit##name(H##name* instr) OVERRIDE { Visit##super(instr); } |
Nicolas Geoffray | 360231a | 2014-10-08 21:07:48 +0100 | [diff] [blame] | 5515 | |
| 5516 | FOR_EACH_INSTRUCTION(DECLARE_VISIT_INSTRUCTION) |
| 5517 | |
| 5518 | #undef DECLARE_VISIT_INSTRUCTION |
| 5519 | |
| 5520 | private: |
| 5521 | DISALLOW_COPY_AND_ASSIGN(HGraphDelegateVisitor); |
| 5522 | }; |
| 5523 | |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5524 | class HInsertionOrderIterator : public ValueObject { |
| 5525 | public: |
| 5526 | explicit HInsertionOrderIterator(const HGraph& graph) : graph_(graph), index_(0) {} |
| 5527 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5528 | bool Done() const { return index_ == graph_.GetBlocks().size(); } |
Vladimir Marko | ec7802a | 2015-10-01 20:57:57 +0100 | [diff] [blame] | 5529 | HBasicBlock* Current() const { return graph_.GetBlocks()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5530 | void Advance() { ++index_; } |
| 5531 | |
| 5532 | private: |
| 5533 | const HGraph& graph_; |
| 5534 | size_t index_; |
| 5535 | |
| 5536 | DISALLOW_COPY_AND_ASSIGN(HInsertionOrderIterator); |
| 5537 | }; |
| 5538 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5539 | class HReversePostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5540 | public: |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5541 | explicit HReversePostOrderIterator(const HGraph& graph) : graph_(graph), index_(0) { |
| 5542 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5543 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5544 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5545 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5546 | bool Done() const { return index_ == graph_.GetReversePostOrder().size(); } |
| 5547 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5548 | void Advance() { ++index_; } |
| 5549 | |
| 5550 | private: |
| 5551 | const HGraph& graph_; |
| 5552 | size_t index_; |
| 5553 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5554 | DISALLOW_COPY_AND_ASSIGN(HReversePostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5555 | }; |
| 5556 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5557 | class HPostOrderIterator : public ValueObject { |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5558 | public: |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5559 | explicit HPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5560 | : graph_(graph), index_(graph_.GetReversePostOrder().size()) { |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5561 | // Check that reverse post order of the graph has been built. |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5562 | DCHECK(!graph.GetReversePostOrder().empty()); |
David Brazdil | 10f56cb | 2015-03-24 18:49:14 +0000 | [diff] [blame] | 5563 | } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5564 | |
| 5565 | bool Done() const { return index_ == 0; } |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5566 | HBasicBlock* Current() const { return graph_.GetReversePostOrder()[index_ - 1u]; } |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5567 | void Advance() { --index_; } |
| 5568 | |
| 5569 | private: |
| 5570 | const HGraph& graph_; |
| 5571 | size_t index_; |
| 5572 | |
Nicolas Geoffray | 622d9c3 | 2014-05-12 16:11:02 +0100 | [diff] [blame] | 5573 | DISALLOW_COPY_AND_ASSIGN(HPostOrderIterator); |
Nicolas Geoffray | 804d093 | 2014-05-02 08:46:00 +0100 | [diff] [blame] | 5574 | }; |
| 5575 | |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5576 | class HLinearPostOrderIterator : public ValueObject { |
| 5577 | public: |
| 5578 | explicit HLinearPostOrderIterator(const HGraph& graph) |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5579 | : order_(graph.GetLinearOrder()), index_(graph.GetLinearOrder().size()) {} |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5580 | |
| 5581 | bool Done() const { return index_ == 0; } |
| 5582 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5583 | HBasicBlock* Current() const { return order_[index_ - 1u]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5584 | |
| 5585 | void Advance() { |
| 5586 | --index_; |
| 5587 | DCHECK_GE(index_, 0U); |
| 5588 | } |
| 5589 | |
| 5590 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5591 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5592 | size_t index_; |
| 5593 | |
| 5594 | DISALLOW_COPY_AND_ASSIGN(HLinearPostOrderIterator); |
| 5595 | }; |
| 5596 | |
| 5597 | class HLinearOrderIterator : public ValueObject { |
| 5598 | public: |
| 5599 | explicit HLinearOrderIterator(const HGraph& graph) |
| 5600 | : order_(graph.GetLinearOrder()), index_(0) {} |
| 5601 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5602 | bool Done() const { return index_ == order_.size(); } |
| 5603 | HBasicBlock* Current() const { return order_[index_]; } |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5604 | void Advance() { ++index_; } |
| 5605 | |
| 5606 | private: |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5607 | const ArenaVector<HBasicBlock*>& order_; |
Nicolas Geoffray | 0d9f17d | 2015-04-15 14:17:44 +0100 | [diff] [blame] | 5608 | size_t index_; |
| 5609 | |
| 5610 | DISALLOW_COPY_AND_ASSIGN(HLinearOrderIterator); |
| 5611 | }; |
| 5612 | |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5613 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5614 | // of an inner loop. The order in which the blocks are iterated is on their |
| 5615 | // block id. |
| 5616 | class HBlocksInLoopIterator : public ValueObject { |
| 5617 | public: |
| 5618 | explicit HBlocksInLoopIterator(const HLoopInformation& info) |
| 5619 | : blocks_in_loop_(info.GetBlocks()), |
| 5620 | blocks_(info.GetHeader()->GetGraph()->GetBlocks()), |
| 5621 | index_(0) { |
| 5622 | if (!blocks_in_loop_.IsBitSet(index_)) { |
| 5623 | Advance(); |
| 5624 | } |
| 5625 | } |
| 5626 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5627 | bool Done() const { return index_ == blocks_.size(); } |
| 5628 | HBasicBlock* Current() const { return blocks_[index_]; } |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5629 | void Advance() { |
| 5630 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5631 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5632 | if (blocks_in_loop_.IsBitSet(index_)) { |
| 5633 | break; |
| 5634 | } |
| 5635 | } |
| 5636 | } |
| 5637 | |
| 5638 | private: |
| 5639 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5640 | const ArenaVector<HBasicBlock*>& blocks_; |
Nicolas Geoffray | 82091da | 2015-01-26 10:02:45 +0000 | [diff] [blame] | 5641 | size_t index_; |
| 5642 | |
| 5643 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopIterator); |
| 5644 | }; |
| 5645 | |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5646 | // Iterator over the blocks that art part of the loop. Includes blocks part |
| 5647 | // of an inner loop. The order in which the blocks are iterated is reverse |
| 5648 | // post order. |
| 5649 | class HBlocksInLoopReversePostOrderIterator : public ValueObject { |
| 5650 | public: |
| 5651 | explicit HBlocksInLoopReversePostOrderIterator(const HLoopInformation& info) |
| 5652 | : blocks_in_loop_(info.GetBlocks()), |
| 5653 | blocks_(info.GetHeader()->GetGraph()->GetReversePostOrder()), |
| 5654 | index_(0) { |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5655 | if (!blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5656 | Advance(); |
| 5657 | } |
| 5658 | } |
| 5659 | |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5660 | bool Done() const { return index_ == blocks_.size(); } |
| 5661 | HBasicBlock* Current() const { return blocks_[index_]; } |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5662 | void Advance() { |
| 5663 | ++index_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5664 | for (size_t e = blocks_.size(); index_ < e; ++index_) { |
| 5665 | if (blocks_in_loop_.IsBitSet(blocks_[index_]->GetBlockId())) { |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5666 | break; |
| 5667 | } |
| 5668 | } |
| 5669 | } |
| 5670 | |
| 5671 | private: |
| 5672 | const BitVector& blocks_in_loop_; |
Vladimir Marko | fa6b93c | 2015-09-15 10:15:55 +0100 | [diff] [blame] | 5673 | const ArenaVector<HBasicBlock*>& blocks_; |
Mingyao Yang | 3584bce | 2015-05-19 16:01:59 -0700 | [diff] [blame] | 5674 | size_t index_; |
| 5675 | |
| 5676 | DISALLOW_COPY_AND_ASSIGN(HBlocksInLoopReversePostOrderIterator); |
| 5677 | }; |
| 5678 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 5679 | inline int64_t Int64FromConstant(HConstant* constant) { |
| 5680 | DCHECK(constant->IsIntConstant() || constant->IsLongConstant()); |
| 5681 | return constant->IsIntConstant() ? constant->AsIntConstant()->GetValue() |
| 5682 | : constant->AsLongConstant()->GetValue(); |
| 5683 | } |
| 5684 | |
Vladimir Marko | 5815501 | 2015-08-19 12:49:41 +0000 | [diff] [blame] | 5685 | inline bool IsSameDexFile(const DexFile& lhs, const DexFile& rhs) { |
| 5686 | // For the purposes of the compiler, the dex files must actually be the same object |
| 5687 | // if we want to safely treat them as the same. This is especially important for JIT |
| 5688 | // as custom class loaders can open the same underlying file (or memory) multiple |
| 5689 | // times and provide different class resolution but no two class loaders should ever |
| 5690 | // use the same DexFile object - doing so is an unsupported hack that can lead to |
| 5691 | // all sorts of weird failures. |
| 5692 | return &lhs == &rhs; |
| 5693 | } |
| 5694 | |
Nicolas Geoffray | 818f210 | 2014-02-18 16:43:35 +0000 | [diff] [blame] | 5695 | } // namespace art |
| 5696 | |
| 5697 | #endif // ART_COMPILER_OPTIMIZING_NODES_H_ |