blob: 2f154fb862769507b2702be35454346c19600c9c [file] [log] [blame]
Andreas Gampe3b165bc2016-08-01 22:07:04 -07001/*
2 * Copyright (C) 2011 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 "jni_macro_assembler.h"
18
19#include <algorithm>
20#include <vector>
21
22#ifdef ART_ENABLE_CODEGEN_arm
Artem Serovf77d1562016-08-08 15:14:18 +010023#include "arm/jni_macro_assembler_arm_vixl.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070024#endif
25#ifdef ART_ENABLE_CODEGEN_arm64
Andreas Gampedcf30142016-08-08 16:06:34 -070026#include "arm64/jni_macro_assembler_arm64.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070027#endif
28#ifdef ART_ENABLE_CODEGEN_mips
29#include "mips/assembler_mips.h"
30#endif
31#ifdef ART_ENABLE_CODEGEN_mips64
32#include "mips64/assembler_mips64.h"
33#endif
34#ifdef ART_ENABLE_CODEGEN_x86
Andreas Gampe9954e3b2016-08-05 20:34:39 -070035#include "x86/jni_macro_assembler_x86.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070036#endif
37#ifdef ART_ENABLE_CODEGEN_x86_64
Andreas Gampe1ace16b2016-08-05 09:01:50 -070038#include "x86_64/jni_macro_assembler_x86_64.h"
Andreas Gampe3b165bc2016-08-01 22:07:04 -070039#endif
40#include "base/casts.h"
41#include "globals.h"
42#include "memory_region.h"
43
44namespace art {
45
46using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>;
47
48template <>
49MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create(
50 ArenaAllocator* arena,
51 InstructionSet instruction_set,
52 const InstructionSetFeatures* instruction_set_features) {
53#ifndef ART_ENABLE_CODEGEN_mips
54 UNUSED(instruction_set_features);
55#endif
56
57 switch (instruction_set) {
58#ifdef ART_ENABLE_CODEGEN_arm
59 case kArm:
Andreas Gampe3b165bc2016-08-01 22:07:04 -070060 case kThumb2:
Artem Serovf77d1562016-08-08 15:14:18 +010061 return MacroAsm32UniquePtr(new (arena) arm::ArmVIXLJNIMacroAssembler(arena));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070062#endif
63#ifdef ART_ENABLE_CODEGEN_mips
64 case kMips:
65 return MacroAsm32UniquePtr(new (arena) mips::MipsAssembler(
66 arena,
67 instruction_set_features != nullptr
68 ? instruction_set_features->AsMipsInstructionSetFeatures()
69 : nullptr));
70#endif
71#ifdef ART_ENABLE_CODEGEN_x86
72 case kX86:
Andreas Gampe9954e3b2016-08-05 20:34:39 -070073 return MacroAsm32UniquePtr(new (arena) x86::X86JNIMacroAssembler(arena));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070074#endif
75 default:
76 LOG(FATAL) << "Unknown/unsupported 4B InstructionSet: " << instruction_set;
77 UNREACHABLE();
78 }
79}
80
81using MacroAsm64UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k64>>;
82
83template <>
84MacroAsm64UniquePtr JNIMacroAssembler<PointerSize::k64>::Create(
85 ArenaAllocator* arena,
86 InstructionSet instruction_set,
87 const InstructionSetFeatures* instruction_set_features ATTRIBUTE_UNUSED) {
88 switch (instruction_set) {
89#ifdef ART_ENABLE_CODEGEN_arm64
90 case kArm64:
Andreas Gampedcf30142016-08-08 16:06:34 -070091 return MacroAsm64UniquePtr(new (arena) arm64::Arm64JNIMacroAssembler(arena));
Andreas Gampe3b165bc2016-08-01 22:07:04 -070092#endif
93#ifdef ART_ENABLE_CODEGEN_mips64
94 case kMips64:
95 return MacroAsm64UniquePtr(new (arena) mips64::Mips64Assembler(arena));
96#endif
97#ifdef ART_ENABLE_CODEGEN_x86_64
98 case kX86_64:
Andreas Gampe1ace16b2016-08-05 09:01:50 -070099 return MacroAsm64UniquePtr(new (arena) x86_64::X86_64JNIMacroAssembler(arena));
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700100#endif
101 default:
Colin Crossa75b01a2016-08-18 13:45:24 -0700102 UNUSED(arena);
Andreas Gampe3b165bc2016-08-01 22:07:04 -0700103 LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set;
104 UNREACHABLE();
105 }
106}
107
108} // namespace art