Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 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_MIPS_H_ |
| 18 | #define ART_COMPILER_OPTIMIZING_NODES_MIPS_H_ |
| 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | // Compute the address of the method for MIPS Constant area support. |
| 23 | class HMipsComputeBaseMethodAddress : public HExpression<0> { |
| 24 | public: |
| 25 | // Treat the value as an int32_t, but it is really a 32 bit native pointer. |
| 26 | HMipsComputeBaseMethodAddress() |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 27 | : HExpression(kMipsComputeBaseMethodAddress, |
| 28 | DataType::Type::kInt32, |
| 29 | SideEffects::None(), |
| 30 | kNoDexPc) { |
| 31 | } |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 32 | |
| 33 | bool CanBeMoved() const OVERRIDE { return true; } |
| 34 | |
| 35 | DECLARE_INSTRUCTION(MipsComputeBaseMethodAddress); |
| 36 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 37 | protected: |
| 38 | DEFAULT_COPY_CONSTRUCTOR(MipsComputeBaseMethodAddress); |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 41 | // Mips version of HPackedSwitch that holds a pointer to the base method address. |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 42 | class HMipsPackedSwitch FINAL : public HExpression<2> { |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 43 | public: |
| 44 | HMipsPackedSwitch(int32_t start_value, |
| 45 | int32_t num_entries, |
| 46 | HInstruction* input, |
| 47 | HMipsComputeBaseMethodAddress* method_base, |
| 48 | uint32_t dex_pc) |
Vladimir Marko | bd78567 | 2018-05-03 17:09:09 +0100 | [diff] [blame] | 49 | : HExpression(kMipsPackedSwitch, SideEffects::None(), dex_pc), |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 50 | start_value_(start_value), |
| 51 | num_entries_(num_entries) { |
| 52 | SetRawInputAt(0, input); |
| 53 | SetRawInputAt(1, method_base); |
| 54 | } |
| 55 | |
| 56 | bool IsControlFlow() const OVERRIDE { return true; } |
| 57 | |
| 58 | int32_t GetStartValue() const { return start_value_; } |
| 59 | |
| 60 | int32_t GetNumEntries() const { return num_entries_; } |
| 61 | |
| 62 | HBasicBlock* GetDefaultBlock() const { |
| 63 | // Last entry is the default block. |
| 64 | return GetBlock()->GetSuccessors()[num_entries_]; |
| 65 | } |
| 66 | |
| 67 | DECLARE_INSTRUCTION(MipsPackedSwitch); |
| 68 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 69 | protected: |
| 70 | DEFAULT_COPY_CONSTRUCTOR(MipsPackedSwitch); |
| 71 | |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 72 | private: |
| 73 | const int32_t start_value_; |
| 74 | const int32_t num_entries_; |
Alexey Frunze | 96b6682 | 2016-09-10 02:32:44 -0700 | [diff] [blame] | 75 | }; |
| 76 | |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 77 | // This instruction computes part of the array access offset (index offset). |
| 78 | // |
| 79 | // For array accesses the element address has the following structure: |
| 80 | // Address = CONST_OFFSET + base_addr + index << ELEM_SHIFT. The address part |
| 81 | // (index << ELEM_SHIFT) can be shared across array accesses with |
| 82 | // the same data type and index. For example, in the following loop 5 accesses can share address |
| 83 | // computation: |
| 84 | // |
| 85 | // void foo(int[] a, int[] b, int[] c) { |
| 86 | // for (i...) { |
| 87 | // a[i] = a[i] + 5; |
| 88 | // b[i] = b[i] + c[i]; |
| 89 | // } |
| 90 | // } |
| 91 | // |
| 92 | // Note: as the instruction doesn't involve base array address into computations it has no side |
| 93 | // effects. |
| 94 | class HIntermediateArrayAddressIndex FINAL : public HExpression<2> { |
| 95 | public: |
| 96 | HIntermediateArrayAddressIndex(HInstruction* index, HInstruction* shift, uint32_t dex_pc) |
Gupta Kumar, Sanjiv | d9e4d73 | 2018-02-05 13:35:03 +0530 | [diff] [blame] | 97 | : HExpression(kIntermediateArrayAddressIndex, |
| 98 | DataType::Type::kInt32, |
| 99 | SideEffects::None(), |
| 100 | dex_pc) { |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 101 | SetRawInputAt(0, index); |
| 102 | SetRawInputAt(1, shift); |
| 103 | } |
| 104 | |
| 105 | bool CanBeMoved() const OVERRIDE { return true; } |
| 106 | bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE { |
| 107 | return true; |
| 108 | } |
| 109 | bool IsActualObject() const OVERRIDE { return false; } |
| 110 | |
| 111 | HInstruction* GetIndex() const { return InputAt(0); } |
| 112 | HInstruction* GetShift() const { return InputAt(1); } |
| 113 | |
| 114 | DECLARE_INSTRUCTION(IntermediateArrayAddressIndex); |
| 115 | |
Artem Serov | cced8ba | 2017-07-19 18:18:09 +0100 | [diff] [blame] | 116 | protected: |
| 117 | DEFAULT_COPY_CONSTRUCTOR(IntermediateArrayAddressIndex); |
Lena Djokic | a290160 | 2017-09-21 13:50:52 +0200 | [diff] [blame] | 118 | }; |
| 119 | |
Alexey Frunze | e3fb245 | 2016-05-10 16:08:05 -0700 | [diff] [blame] | 120 | } // namespace art |
| 121 | |
| 122 | #endif // ART_COMPILER_OPTIMIZING_NODES_MIPS_H_ |