blob: 2c0595e3d880c6aaa1b280f721c48ee15f36d901 [file] [log] [blame]
Alexey Frunzee3fb2452016-05-10 16:08:05 -07001/*
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
20namespace art {
21
22// Compute the address of the method for MIPS Constant area support.
23class 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()
Vladimir Marko0ebe0d82017-09-21 22:50:39 +010027 : HExpression(DataType::Type::kInt32, SideEffects::None(), kNoDexPc) {}
Alexey Frunzee3fb2452016-05-10 16:08:05 -070028
29 bool CanBeMoved() const OVERRIDE { return true; }
30
31 DECLARE_INSTRUCTION(MipsComputeBaseMethodAddress);
32
Artem Serovcced8ba2017-07-19 18:18:09 +010033 protected:
34 DEFAULT_COPY_CONSTRUCTOR(MipsComputeBaseMethodAddress);
Alexey Frunzee3fb2452016-05-10 16:08:05 -070035};
36
Alexey Frunze96b66822016-09-10 02:32:44 -070037// Mips version of HPackedSwitch that holds a pointer to the base method address.
38class HMipsPackedSwitch FINAL : public HTemplateInstruction<2> {
39 public:
40 HMipsPackedSwitch(int32_t start_value,
41 int32_t num_entries,
42 HInstruction* input,
43 HMipsComputeBaseMethodAddress* method_base,
44 uint32_t dex_pc)
45 : HTemplateInstruction(SideEffects::None(), dex_pc),
46 start_value_(start_value),
47 num_entries_(num_entries) {
48 SetRawInputAt(0, input);
49 SetRawInputAt(1, method_base);
50 }
51
52 bool IsControlFlow() const OVERRIDE { return true; }
53
54 int32_t GetStartValue() const { return start_value_; }
55
56 int32_t GetNumEntries() const { return num_entries_; }
57
58 HBasicBlock* GetDefaultBlock() const {
59 // Last entry is the default block.
60 return GetBlock()->GetSuccessors()[num_entries_];
61 }
62
63 DECLARE_INSTRUCTION(MipsPackedSwitch);
64
Artem Serovcced8ba2017-07-19 18:18:09 +010065 protected:
66 DEFAULT_COPY_CONSTRUCTOR(MipsPackedSwitch);
67
Alexey Frunze96b66822016-09-10 02:32:44 -070068 private:
69 const int32_t start_value_;
70 const int32_t num_entries_;
Alexey Frunze96b66822016-09-10 02:32:44 -070071};
72
Lena Djokica2901602017-09-21 13:50:52 +020073// This instruction computes part of the array access offset (index offset).
74//
75// For array accesses the element address has the following structure:
76// Address = CONST_OFFSET + base_addr + index << ELEM_SHIFT. The address part
77// (index << ELEM_SHIFT) can be shared across array accesses with
78// the same data type and index. For example, in the following loop 5 accesses can share address
79// computation:
80//
81// void foo(int[] a, int[] b, int[] c) {
82// for (i...) {
83// a[i] = a[i] + 5;
84// b[i] = b[i] + c[i];
85// }
86// }
87//
88// Note: as the instruction doesn't involve base array address into computations it has no side
89// effects.
90class HIntermediateArrayAddressIndex FINAL : public HExpression<2> {
91 public:
92 HIntermediateArrayAddressIndex(HInstruction* index, HInstruction* shift, uint32_t dex_pc)
93 : HExpression(DataType::Type::kInt32, SideEffects::None(), dex_pc) {
94 SetRawInputAt(0, index);
95 SetRawInputAt(1, shift);
96 }
97
98 bool CanBeMoved() const OVERRIDE { return true; }
99 bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE {
100 return true;
101 }
102 bool IsActualObject() const OVERRIDE { return false; }
103
104 HInstruction* GetIndex() const { return InputAt(0); }
105 HInstruction* GetShift() const { return InputAt(1); }
106
107 DECLARE_INSTRUCTION(IntermediateArrayAddressIndex);
108
Artem Serovcced8ba2017-07-19 18:18:09 +0100109 protected:
110 DEFAULT_COPY_CONSTRUCTOR(IntermediateArrayAddressIndex);
Lena Djokica2901602017-09-21 13:50:52 +0200111};
112
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700113} // namespace art
114
115#endif // ART_COMPILER_OPTIMIZING_NODES_MIPS_H_