1 /*
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
23 #include "arm/jni_macro_assembler_arm_vixl.h"
24 #endif
25 #ifdef ART_ENABLE_CODEGEN_arm64
26 #include "arm64/jni_macro_assembler_arm64.h"
27 #endif
28 #ifdef ART_ENABLE_CODEGEN_x86
29 #include "x86/jni_macro_assembler_x86.h"
30 #endif
31 #ifdef ART_ENABLE_CODEGEN_x86_64
32 #include "x86_64/jni_macro_assembler_x86_64.h"
33 #endif
34 #include "base/casts.h"
35 #include "base/globals.h"
36 #include "base/memory_region.h"
37
38 namespace art {
39
40 using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>;
41
42 template <>
Create(ArenaAllocator * allocator,InstructionSet instruction_set,const InstructionSetFeatures * instruction_set_features)43 MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create(
44 ArenaAllocator* allocator,
45 InstructionSet instruction_set,
46 const InstructionSetFeatures* instruction_set_features) {
47 // TODO: Remove the parameter from API (not needed after Mips target was removed).
48 UNUSED(instruction_set_features);
49
50 switch (instruction_set) {
51 #ifdef ART_ENABLE_CODEGEN_arm
52 case InstructionSet::kArm:
53 case InstructionSet::kThumb2:
54 return MacroAsm32UniquePtr(new (allocator) arm::ArmVIXLJNIMacroAssembler(allocator));
55 #endif
56 #ifdef ART_ENABLE_CODEGEN_x86
57 case InstructionSet::kX86:
58 return MacroAsm32UniquePtr(new (allocator) x86::X86JNIMacroAssembler(allocator));
59 #endif
60 default:
61 LOG(FATAL) << "Unknown/unsupported 4B InstructionSet: " << instruction_set;
62 UNREACHABLE();
63 }
64 }
65
66 using MacroAsm64UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k64>>;
67
68 template <>
Create(ArenaAllocator * allocator,InstructionSet instruction_set,const InstructionSetFeatures * instruction_set_features)69 MacroAsm64UniquePtr JNIMacroAssembler<PointerSize::k64>::Create(
70 ArenaAllocator* allocator,
71 InstructionSet instruction_set,
72 const InstructionSetFeatures* instruction_set_features) {
73 // TODO: Remove the parameter from API (not needed after Mips64 target was removed).
74 UNUSED(instruction_set_features);
75
76 switch (instruction_set) {
77 #ifdef ART_ENABLE_CODEGEN_arm64
78 case InstructionSet::kArm64:
79 return MacroAsm64UniquePtr(new (allocator) arm64::Arm64JNIMacroAssembler(allocator));
80 #endif
81 #ifdef ART_ENABLE_CODEGEN_x86_64
82 case InstructionSet::kX86_64:
83 return MacroAsm64UniquePtr(new (allocator) x86_64::X86_64JNIMacroAssembler(allocator));
84 #endif
85 default:
86 UNUSED(allocator);
87 LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set;
88 UNREACHABLE();
89 }
90 }
91
92 } // namespace art
93