blob: 6c14888293195d8a12b38d29a777cbec6b2b7601 [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
23#include "arm/assembler_arm32.h"
24#include "arm/assembler_thumb2.h"
25#endif
26#ifdef ART_ENABLE_CODEGEN_arm64
27#include "arm64/assembler_arm64.h"
28#endif
29#ifdef ART_ENABLE_CODEGEN_mips
30#include "mips/assembler_mips.h"
31#endif
32#ifdef ART_ENABLE_CODEGEN_mips64
33#include "mips64/assembler_mips64.h"
34#endif
35#ifdef ART_ENABLE_CODEGEN_x86
36#include "x86/assembler_x86.h"
37#endif
38#ifdef ART_ENABLE_CODEGEN_x86_64
39#include "x86_64/assembler_x86_64.h"
40#endif
41#include "base/casts.h"
42#include "globals.h"
43#include "memory_region.h"
44
45namespace art {
46
47using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>;
48
49template <>
50MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create(
51 ArenaAllocator* arena,
52 InstructionSet instruction_set,
53 const InstructionSetFeatures* instruction_set_features) {
54#ifndef ART_ENABLE_CODEGEN_mips
55 UNUSED(instruction_set_features);
56#endif
57
58 switch (instruction_set) {
59#ifdef ART_ENABLE_CODEGEN_arm
60 case kArm:
61 return MacroAsm32UniquePtr(new (arena) arm::Arm32Assembler(arena));
62 case kThumb2:
63 return MacroAsm32UniquePtr(new (arena) arm::Thumb2Assembler(arena));
64#endif
65#ifdef ART_ENABLE_CODEGEN_mips
66 case kMips:
67 return MacroAsm32UniquePtr(new (arena) mips::MipsAssembler(
68 arena,
69 instruction_set_features != nullptr
70 ? instruction_set_features->AsMipsInstructionSetFeatures()
71 : nullptr));
72#endif
73#ifdef ART_ENABLE_CODEGEN_x86
74 case kX86:
75 return MacroAsm32UniquePtr(new (arena) x86::X86Assembler(arena));
76#endif
77 default:
78 LOG(FATAL) << "Unknown/unsupported 4B InstructionSet: " << instruction_set;
79 UNREACHABLE();
80 }
81}
82
83using MacroAsm64UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k64>>;
84
85template <>
86MacroAsm64UniquePtr JNIMacroAssembler<PointerSize::k64>::Create(
87 ArenaAllocator* arena,
88 InstructionSet instruction_set,
89 const InstructionSetFeatures* instruction_set_features ATTRIBUTE_UNUSED) {
90 switch (instruction_set) {
91#ifdef ART_ENABLE_CODEGEN_arm64
92 case kArm64:
93 return MacroAsm64UniquePtr(new (arena) arm64::Arm64Assembler(arena));
94#endif
95#ifdef ART_ENABLE_CODEGEN_mips64
96 case kMips64:
97 return MacroAsm64UniquePtr(new (arena) mips64::Mips64Assembler(arena));
98#endif
99#ifdef ART_ENABLE_CODEGEN_x86_64
100 case kX86_64:
101 return MacroAsm64UniquePtr(new (arena) x86_64::X86_64Assembler(arena));
102#endif
103 default:
104 LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set;
105 UNREACHABLE();
106 }
107}
108
109} // namespace art