Home | History | Annotate | Download | only in utils
      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_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
     35 #include "x86/jni_macro_assembler_x86.h"
     36 #endif
     37 #ifdef ART_ENABLE_CODEGEN_x86_64
     38 #include "x86_64/jni_macro_assembler_x86_64.h"
     39 #endif
     40 #include "base/casts.h"
     41 #include "base/globals.h"
     42 #include "base/memory_region.h"
     43 
     44 namespace art {
     45 
     46 using MacroAsm32UniquePtr = std::unique_ptr<JNIMacroAssembler<PointerSize::k32>>;
     47 
     48 template <>
     49 MacroAsm32UniquePtr JNIMacroAssembler<PointerSize::k32>::Create(
     50     ArenaAllocator* allocator,
     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 InstructionSet::kArm:
     60     case InstructionSet::kThumb2:
     61       return MacroAsm32UniquePtr(new (allocator) arm::ArmVIXLJNIMacroAssembler(allocator));
     62 #endif
     63 #ifdef ART_ENABLE_CODEGEN_mips
     64     case InstructionSet::kMips:
     65       return MacroAsm32UniquePtr(new (allocator) mips::MipsAssembler(
     66           allocator,
     67           instruction_set_features != nullptr
     68               ? instruction_set_features->AsMipsInstructionSetFeatures()
     69               : nullptr));
     70 #endif
     71 #ifdef ART_ENABLE_CODEGEN_x86
     72     case InstructionSet::kX86:
     73       return MacroAsm32UniquePtr(new (allocator) x86::X86JNIMacroAssembler(allocator));
     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(
     85     ArenaAllocator* allocator,
     86     InstructionSet instruction_set,
     87     const InstructionSetFeatures* instruction_set_features) {
     88 #ifndef ART_ENABLE_CODEGEN_mips64
     89   UNUSED(instruction_set_features);
     90 #endif
     91 
     92   switch (instruction_set) {
     93 #ifdef ART_ENABLE_CODEGEN_arm64
     94     case InstructionSet::kArm64:
     95       return MacroAsm64UniquePtr(new (allocator) arm64::Arm64JNIMacroAssembler(allocator));
     96 #endif
     97 #ifdef ART_ENABLE_CODEGEN_mips64
     98     case InstructionSet::kMips64:
     99       return MacroAsm64UniquePtr(new (allocator) mips64::Mips64Assembler(
    100           allocator,
    101           instruction_set_features != nullptr
    102               ? instruction_set_features->AsMips64InstructionSetFeatures()
    103               : nullptr));
    104 #endif
    105 #ifdef ART_ENABLE_CODEGEN_x86_64
    106     case InstructionSet::kX86_64:
    107       return MacroAsm64UniquePtr(new (allocator) x86_64::X86_64JNIMacroAssembler(allocator));
    108 #endif
    109     default:
    110       UNUSED(allocator);
    111       LOG(FATAL) << "Unknown/unsupported 8B InstructionSet: " << instruction_set;
    112       UNREACHABLE();
    113   }
    114 }
    115 
    116 }  // namespace art
    117