blob: ef388c30d508076ba1fe5ffff7af55ac3af1b2b9 [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
33 private:
34 DISALLOW_COPY_AND_ASSIGN(HMipsComputeBaseMethodAddress);
35};
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
65 private:
66 const int32_t start_value_;
67 const int32_t num_entries_;
68
69 DISALLOW_COPY_AND_ASSIGN(HMipsPackedSwitch);
70};
71
Lena Djokica2901602017-09-21 13:50:52 +020072// This instruction computes part of the array access offset (index offset).
73//
74// For array accesses the element address has the following structure:
75// Address = CONST_OFFSET + base_addr + index << ELEM_SHIFT. The address part
76// (index << ELEM_SHIFT) can be shared across array accesses with
77// the same data type and index. For example, in the following loop 5 accesses can share address
78// computation:
79//
80// void foo(int[] a, int[] b, int[] c) {
81// for (i...) {
82// a[i] = a[i] + 5;
83// b[i] = b[i] + c[i];
84// }
85// }
86//
87// Note: as the instruction doesn't involve base array address into computations it has no side
88// effects.
89class HIntermediateArrayAddressIndex FINAL : public HExpression<2> {
90 public:
91 HIntermediateArrayAddressIndex(HInstruction* index, HInstruction* shift, uint32_t dex_pc)
92 : HExpression(DataType::Type::kInt32, SideEffects::None(), dex_pc) {
93 SetRawInputAt(0, index);
94 SetRawInputAt(1, shift);
95 }
96
97 bool CanBeMoved() const OVERRIDE { return true; }
98 bool InstructionDataEquals(const HInstruction* other ATTRIBUTE_UNUSED) const OVERRIDE {
99 return true;
100 }
101 bool IsActualObject() const OVERRIDE { return false; }
102
103 HInstruction* GetIndex() const { return InputAt(0); }
104 HInstruction* GetShift() const { return InputAt(1); }
105
106 DECLARE_INSTRUCTION(IntermediateArrayAddressIndex);
107
108 private:
109 DISALLOW_COPY_AND_ASSIGN(HIntermediateArrayAddressIndex);
110};
111
Alexey Frunzee3fb2452016-05-10 16:08:05 -0700112} // namespace art
113
114#endif // ART_COMPILER_OPTIMIZING_NODES_MIPS_H_