Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 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 |
Artem Serov | 6287c23 | 2016-11-29 13:31:33 +0000 | [diff] [blame] | 23 | #include "arm/jni_macro_assembler_arm_vixl.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 24 | #endif |
| 25 | #ifdef ART_ENABLE_CODEGEN_arm64 |
Andreas Gampe | dcf3014 | 2016-08-08 16:06:34 -0700 | [diff] [blame] | 26 | #include "arm64/jni_macro_assembler_arm64.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 27 | #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 Gampe | 9954e3b | 2016-08-05 20:34:39 -0700 | [diff] [blame] | 35 | #include "x86/jni_macro_assembler_x86.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 36 | #endif |
| 37 | #ifdef ART_ENABLE_CODEGEN_x86_64 |
Andreas Gampe | 1ace16b | 2016-08-05 09:01:50 -0700 | [diff] [blame] | 38 | #include "x86_64/jni_macro_assembler_x86_64.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 39 | #endif |
| 40 | #include "base/casts.h" |
David Sehr | 1ce2b3b | 2018-04-05 11:02:03 -0700 | [diff] [blame^] | 41 | #include "base/memory_region.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 42 | #include "globals.h" |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 43 | |
| 44 | namespace art { |
| 45 | |
| 46 | using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>; |
| 47 | |
| 48 | template <> |
| 49 | MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create( |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 50 | ArenaAllocator* allocator, |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 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 |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 59 | case InstructionSet::kArm: |
| 60 | case InstructionSet::kThumb2: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 61 | return MacroAsm32UniquePtr(new (allocator) arm::ArmVIXLJNIMacroAssembler(allocator)); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 62 | #endif |
| 63 | #ifdef ART_ENABLE_CODEGEN_mips |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 64 | case InstructionSet::kMips: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 65 | return MacroAsm32UniquePtr(new (allocator) mips::MipsAssembler( |
| 66 | allocator, |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 67 | instruction_set_features != nullptr |
| 68 | ? instruction_set_features->AsMipsInstructionSetFeatures() |
| 69 | : nullptr)); |
| 70 | #endif |
| 71 | #ifdef ART_ENABLE_CODEGEN_x86 |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 72 | case InstructionSet::kX86: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 73 | return MacroAsm32UniquePtr(new (allocator) x86::X86JNIMacroAssembler(allocator)); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 74 | #endif |
| 75 | default: |
| 76 | LOG(FATAL) << "Unknown/unsupported 4B InstructionSet: " << instruction_set; |
| 77 | UNREACHABLE(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | using MacroAsm64UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k64>>; |
| 82 | |
| 83 | template <> |
| 84 | MacroAsm64UniquePtr JNIMacroAssembler<PointerSize::k64>::Create( |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 85 | ArenaAllocator* allocator, |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 86 | InstructionSet instruction_set, |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 87 | const InstructionSetFeatures* instruction_set_features) { |
| 88 | #ifndef ART_ENABLE_CODEGEN_mips64 |
| 89 | UNUSED(instruction_set_features); |
| 90 | #endif |
| 91 | |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 92 | switch (instruction_set) { |
| 93 | #ifdef ART_ENABLE_CODEGEN_arm64 |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 94 | case InstructionSet::kArm64: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 95 | return MacroAsm64UniquePtr(new (allocator) arm64::Arm64JNIMacroAssembler(allocator)); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 96 | #endif |
| 97 | #ifdef ART_ENABLE_CODEGEN_mips64 |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 98 | case InstructionSet::kMips64: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 99 | return MacroAsm64UniquePtr(new (allocator) mips64::Mips64Assembler( |
| 100 | allocator, |
Goran Jakovljevic | 27af937 | 2017-03-15 15:31:34 +0100 | [diff] [blame] | 101 | instruction_set_features != nullptr |
| 102 | ? instruction_set_features->AsMips64InstructionSetFeatures() |
| 103 | : nullptr)); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 104 | #endif |
| 105 | #ifdef ART_ENABLE_CODEGEN_x86_64 |
Vladimir Marko | 33bff25 | 2017-11-01 14:35:42 +0000 | [diff] [blame] | 106 | case InstructionSet::kX86_64: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 107 | return MacroAsm64UniquePtr(new (allocator) x86_64::X86_64JNIMacroAssembler(allocator)); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 108 | #endif |
| 109 | default: |
Vladimir Marko | e764d2e | 2017-10-05 14:35:55 +0100 | [diff] [blame] | 110 | UNUSED(allocator); |
Andreas Gampe | 3b165bc | 2016-08-01 22:07:04 -0700 | [diff] [blame] | 111 | LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set; |
| 112 | UNREACHABLE(); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | } // namespace art |