blob: eb79f469ebe58c7fd66c29282932215bba152703 [file] [log] [blame]
Alexandre Rames44b9cf92015-08-19 15:39:06 +01001/*
2 * Copyright (C) 2015 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#include "instruction_simplifier_arm64.h"
18
Alexandre Ramese6dbf482015-10-19 10:10:41 +010019#include "mirror/array-inl.h"
20
Alexandre Rames44b9cf92015-08-19 15:39:06 +010021namespace art {
22namespace arm64 {
23
Alexandre Ramese6dbf482015-10-19 10:10:41 +010024void InstructionSimplifierArm64Visitor::TryExtractArrayAccessAddress(HInstruction* access,
25 HInstruction* array,
26 HInstruction* index,
27 int access_size) {
28 if (index->IsConstant() ||
29 (index->IsBoundsCheck() && index->AsBoundsCheck()->GetIndex()->IsConstant())) {
30 // When the index is a constant all the addressing can be fitted in the
31 // memory access instruction, so do not split the access.
32 return;
33 }
34 if (access->IsArraySet() &&
35 access->AsArraySet()->GetValue()->GetType() == Primitive::kPrimNot) {
36 // The access may require a runtime call or the original array pointer.
37 return;
38 }
39
40 // Proceed to extract the base address computation.
41 ArenaAllocator* arena = GetGraph()->GetArena();
42
43 HIntConstant* offset =
44 GetGraph()->GetIntConstant(mirror::Array::DataOffset(access_size).Uint32Value());
45 HArm64IntermediateAddress* address =
46 new (arena) HArm64IntermediateAddress(array, offset, kNoDexPc);
47 access->GetBlock()->InsertInstructionBefore(address, access);
48 access->ReplaceInput(address, 0);
49 // Both instructions must depend on GC to prevent any instruction that can
50 // trigger GC to be inserted between the two.
51 access->AddSideEffects(SideEffects::DependsOnGC());
52 DCHECK(address->GetSideEffects().Includes(SideEffects::DependsOnGC()));
53 DCHECK(access->GetSideEffects().Includes(SideEffects::DependsOnGC()));
54 // TODO: Code generation for HArrayGet and HArraySet will check whether the input address
55 // is an HArm64IntermediateAddress and generate appropriate code.
56 // We would like to replace the `HArrayGet` and `HArraySet` with custom instructions (maybe
57 // `HArm64Load` and `HArm64Store`). We defer these changes because these new instructions would
58 // not bring any advantages yet.
59 // Also see the comments in
60 // `InstructionCodeGeneratorARM64::VisitArrayGet()` and
61 // `InstructionCodeGeneratorARM64::VisitArraySet()`.
62 RecordSimplification();
63}
64
65void InstructionSimplifierArm64Visitor::VisitArrayGet(HArrayGet* instruction) {
66 TryExtractArrayAccessAddress(instruction,
67 instruction->GetArray(),
68 instruction->GetIndex(),
69 Primitive::ComponentSize(instruction->GetType()));
70}
71
72void InstructionSimplifierArm64Visitor::VisitArraySet(HArraySet* instruction) {
73 TryExtractArrayAccessAddress(instruction,
74 instruction->GetArray(),
75 instruction->GetIndex(),
76 Primitive::ComponentSize(instruction->GetComponentType()));
77}
78
Alexandre Rames44b9cf92015-08-19 15:39:06 +010079} // namespace arm64
80} // namespace art