1 /* 2 * Copyright (C) 2016 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 #ifndef ART_COMPILER_OPTIMIZING_NODES_MIPS_H_ 18 #define ART_COMPILER_OPTIMIZING_NODES_MIPS_H_ 19 20 namespace art { 21 22 // Compute the address of the method for MIPS Constant area support. 23 class HMipsComputeBaseMethodAddress : public HExpression<0> { 24 public: 25 // Treat the value as an int32_t, but it is really a 32 bit native pointer. HMipsComputeBaseMethodAddress()26 HMipsComputeBaseMethodAddress() 27 : HExpression(Primitive::kPrimInt, SideEffects::None(), kNoDexPc) {} 28 CanBeMoved()29 bool CanBeMoved() const OVERRIDE { return true; } 30 31 DECLARE_INSTRUCTION(MipsComputeBaseMethodAddress); 32 33 private: 34 DISALLOW_COPY_AND_ASSIGN(HMipsComputeBaseMethodAddress); 35 }; 36 37 class HMipsDexCacheArraysBase : public HExpression<0> { 38 public: HMipsDexCacheArraysBase(const DexFile & dex_file)39 explicit HMipsDexCacheArraysBase(const DexFile& dex_file) 40 : HExpression(Primitive::kPrimInt, SideEffects::None(), kNoDexPc), 41 dex_file_(&dex_file), 42 element_offset_(static_cast<size_t>(-1)) { } 43 CanBeMoved()44 bool CanBeMoved() const OVERRIDE { return true; } 45 UpdateElementOffset(size_t element_offset)46 void UpdateElementOffset(size_t element_offset) { 47 // We'll maximize the range of a single load instruction for dex cache array accesses 48 // by aligning offset -32768 with the offset of the first used element. 49 element_offset_ = std::min(element_offset_, element_offset); 50 } 51 GetDexFile()52 const DexFile& GetDexFile() const { 53 return *dex_file_; 54 } 55 GetElementOffset()56 size_t GetElementOffset() const { 57 return element_offset_; 58 } 59 60 DECLARE_INSTRUCTION(MipsDexCacheArraysBase); 61 62 private: 63 const DexFile* dex_file_; 64 size_t element_offset_; 65 66 DISALLOW_COPY_AND_ASSIGN(HMipsDexCacheArraysBase); 67 }; 68 69 // Mips version of HPackedSwitch that holds a pointer to the base method address. 70 class HMipsPackedSwitch FINAL : public HTemplateInstruction<2> { 71 public: HMipsPackedSwitch(int32_t start_value,int32_t num_entries,HInstruction * input,HMipsComputeBaseMethodAddress * method_base,uint32_t dex_pc)72 HMipsPackedSwitch(int32_t start_value, 73 int32_t num_entries, 74 HInstruction* input, 75 HMipsComputeBaseMethodAddress* method_base, 76 uint32_t dex_pc) 77 : HTemplateInstruction(SideEffects::None(), dex_pc), 78 start_value_(start_value), 79 num_entries_(num_entries) { 80 SetRawInputAt(0, input); 81 SetRawInputAt(1, method_base); 82 } 83 IsControlFlow()84 bool IsControlFlow() const OVERRIDE { return true; } 85 GetStartValue()86 int32_t GetStartValue() const { return start_value_; } 87 GetNumEntries()88 int32_t GetNumEntries() const { return num_entries_; } 89 GetDefaultBlock()90 HBasicBlock* GetDefaultBlock() const { 91 // Last entry is the default block. 92 return GetBlock()->GetSuccessors()[num_entries_]; 93 } 94 95 DECLARE_INSTRUCTION(MipsPackedSwitch); 96 97 private: 98 const int32_t start_value_; 99 const int32_t num_entries_; 100 101 DISALLOW_COPY_AND_ASSIGN(HMipsPackedSwitch); 102 }; 103 104 } // namespace art 105 106 #endif // ART_COMPILER_OPTIMIZING_NODES_MIPS_H_ 107